| 1 | /*!\file KML_Object.cpp
|
|---|
| 2 | * \brief: implementation of the kml_object abstract object
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | /*Headers:*/
|
|---|
| 6 | /*{{{*/
|
|---|
| 7 | #ifdef HAVE_CONFIG_H
|
|---|
| 8 | #include <config.h>
|
|---|
| 9 | #else
|
|---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "./KML_Object.h"
|
|---|
| 14 | #include "./KML_Attribute.h"
|
|---|
| 15 | #include "./KML_Comment.h"
|
|---|
| 16 | #include "./KML_Unknown.h"
|
|---|
| 17 | #include "./KML_LatLonBox.h"
|
|---|
| 18 | #include "./KML_Icon.h"
|
|---|
| 19 | #include "./KML_MultiGeometry.h"
|
|---|
| 20 | #include "./KML_Document.h"
|
|---|
| 21 | #include "./KML_LinearRing.h"
|
|---|
| 22 | #include "./KML_LineStyle.h"
|
|---|
| 23 | #include "./KML_LineString.h"
|
|---|
| 24 | #include "./KML_PolyStyle.h"
|
|---|
| 25 | #include "./KML_Polygon.h"
|
|---|
| 26 | #include "./KML_Point.h"
|
|---|
| 27 | #include "./KML_GroundOverlay.h"
|
|---|
| 28 | #include "./KML_Placemark.h"
|
|---|
| 29 | #include "./KML_Folder.h"
|
|---|
| 30 | #include "../shared/shared.h"
|
|---|
| 31 | /*}}}*/
|
|---|
| 32 |
|
|---|
| 33 | /*Constructors/destructor/copy*/
|
|---|
| 34 | /*FUNCTION KML_Object::KML_Object(){{{*/
|
|---|
| 35 | KML_Object::KML_Object(){
|
|---|
| 36 |
|
|---|
| 37 | attrib =new DataSet;
|
|---|
| 38 | commnt =new DataSet;
|
|---|
| 39 | kmlobj =new DataSet;
|
|---|
| 40 |
|
|---|
| 41 | }
|
|---|
| 42 | /*}}}*/
|
|---|
| 43 | /*FUNCTION KML_Object::~KML_Object(){{{*/
|
|---|
| 44 | KML_Object::~KML_Object(){
|
|---|
| 45 |
|
|---|
| 46 | if (attrib) {
|
|---|
| 47 | delete attrib;
|
|---|
| 48 | attrib =NULL;
|
|---|
| 49 | }
|
|---|
| 50 | if (commnt) {
|
|---|
| 51 | delete commnt;
|
|---|
| 52 | commnt =NULL;
|
|---|
| 53 | }
|
|---|
| 54 | if (kmlobj) {
|
|---|
| 55 | delete kmlobj;
|
|---|
| 56 | kmlobj =NULL;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 | /*}}}*/
|
|---|
| 61 |
|
|---|
| 62 | /*Other*/
|
|---|
| 63 | /*FUNCTION KML_Object::Echo {{{*/
|
|---|
| 64 | void KML_Object::Echo(){
|
|---|
| 65 |
|
|---|
| 66 | bool flag=true;
|
|---|
| 67 |
|
|---|
| 68 | if(flag) _printf0_(" attrib: (size=" << attrib->Size() << ")\n");
|
|---|
| 69 | if(flag) _printf0_(" commnt: (size=" << commnt->Size() << ")\n");
|
|---|
| 70 | if(flag) _printf0_(" kmlobj: (size=" << kmlobj->Size() << ")\n");
|
|---|
| 71 |
|
|---|
| 72 | return;
|
|---|
| 73 | }
|
|---|
| 74 | /*}}}*/
|
|---|
| 75 | /*FUNCTION KML_Object::DeepEcho {{{*/
|
|---|
| 76 | void KML_Object::DeepEcho(){
|
|---|
| 77 |
|
|---|
| 78 | char indent[81]="";
|
|---|
| 79 |
|
|---|
| 80 | KML_Object::DeepEcho(indent);
|
|---|
| 81 |
|
|---|
| 82 | return;
|
|---|
| 83 | }
|
|---|
| 84 | /*}}}*/
|
|---|
| 85 | /*FUNCTION KML_Object::DeepEcho {{{*/
|
|---|
| 86 | void KML_Object::DeepEcho(const char* indent){
|
|---|
| 87 |
|
|---|
| 88 | int i;
|
|---|
| 89 | char indent2[81];
|
|---|
| 90 | bool flag=true;
|
|---|
| 91 |
|
|---|
| 92 | /* loop over the attributes for the object */
|
|---|
| 93 |
|
|---|
| 94 | if (attrib->Size())
|
|---|
| 95 | for (i=0; i<attrib->Size(); i++) {
|
|---|
| 96 | ((KML_Attribute *)attrib->GetObjectByOffset(i))->DeepEcho(indent);
|
|---|
| 97 | }
|
|---|
| 98 | else
|
|---|
| 99 | if(flag) _printf0_(indent << " attrib: [empty]\n");
|
|---|
| 100 |
|
|---|
| 101 | /* loop over the comments for the object */
|
|---|
| 102 |
|
|---|
| 103 | if (commnt->Size())
|
|---|
| 104 | for (i=0; i<commnt->Size(); i++) {
|
|---|
| 105 | ((KML_Comment *)commnt->GetObjectByOffset(i))->DeepEcho(indent);
|
|---|
| 106 | }
|
|---|
| 107 | else
|
|---|
| 108 | if(flag) _printf0_(indent << " commnt: [empty]\n");
|
|---|
| 109 |
|
|---|
| 110 | /* loop over the unknown objects for the object */
|
|---|
| 111 |
|
|---|
| 112 | memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
|
|---|
| 113 | strcat(indent2," ");
|
|---|
| 114 |
|
|---|
| 115 | if (kmlobj->Size())
|
|---|
| 116 | for (i=0; i<kmlobj->Size(); i++) {
|
|---|
| 117 | if(flag) _printf0_(indent << " kmlobj: -------- begin [" << i << "] --------\n");
|
|---|
| 118 | ((KML_Unknown *)kmlobj->GetObjectByOffset(i))->DeepEcho(indent2);
|
|---|
| 119 | if(flag) _printf0_(indent << " kmlobj: -------- end [" << i << "] --------\n");
|
|---|
| 120 | }
|
|---|
| 121 | else
|
|---|
| 122 | if(flag) _printf0_(indent << " kmlobj: [empty]\n");
|
|---|
| 123 |
|
|---|
| 124 | return;
|
|---|
| 125 | }
|
|---|
| 126 | /*}}}*/
|
|---|
| 127 | /*FUNCTION KML_Object::Write {{{*/
|
|---|
| 128 | void KML_Object::Write(FILE* filout,const char* indent){
|
|---|
| 129 |
|
|---|
| 130 | int i;
|
|---|
| 131 | char indent2[81];
|
|---|
| 132 |
|
|---|
| 133 | // attributes always written in keyword line of derived classes
|
|---|
| 134 | // comments always written after keyword line of derived classes
|
|---|
| 135 |
|
|---|
| 136 | /* loop over the unknown objects for the object */
|
|---|
| 137 |
|
|---|
| 138 | memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
|
|---|
| 139 | strcat(indent2," ");
|
|---|
| 140 |
|
|---|
| 141 | if (kmlobj->Size())
|
|---|
| 142 | for (i=0; i<kmlobj->Size(); i++) {
|
|---|
| 143 | ((KML_Unknown *)kmlobj->GetObjectByOffset(i))->Write(filout,indent2);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | return;
|
|---|
| 147 | }
|
|---|
| 148 | /*}}}*/
|
|---|
| 149 | /*FUNCTION KML_Object::Read {{{*/
|
|---|
| 150 | void KML_Object::Read(FILE* fid,char* kstr){
|
|---|
| 151 |
|
|---|
| 152 | KML_Object* kobj;
|
|---|
| 153 |
|
|---|
| 154 | /* process field within opening and closing tags */
|
|---|
| 155 |
|
|---|
| 156 | if (!strncmp(kstr,"</Object", 8))
|
|---|
| 157 | return;
|
|---|
| 158 | else if (!strncmp(kstr,"</",2))
|
|---|
| 159 | {_error_("KML_Object::Read -- Unexpected closing tag " << kstr << ".\n");}
|
|---|
| 160 | else if (strncmp(kstr,"<",1))
|
|---|
| 161 | {_error_("KML_Object::Read -- Unexpected field \"" << kstr << "\".\n");}
|
|---|
| 162 |
|
|---|
| 163 | else if (!strncmp(kstr,"<Placemark",10)) {
|
|---|
| 164 | kobj=(KML_Object*)new KML_Placemark();
|
|---|
| 165 | kobj->Read(fid,kstr);
|
|---|
| 166 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | else if (!strncmp(kstr,"<Folder", 7)) {
|
|---|
| 170 | kobj=(KML_Object*)new KML_Folder();
|
|---|
| 171 | kobj->Read(fid,kstr);
|
|---|
| 172 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | else if (!strncmp(kstr,"<Document", 9)) {
|
|---|
| 176 | kobj=(KML_Object*)new KML_Document();
|
|---|
| 177 | kobj->Read(fid,kstr);
|
|---|
| 178 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | else if (!strncmp(kstr,"<GroundOverlay",14)) {
|
|---|
| 182 | kobj=(KML_Object*)new KML_GroundOverlay();
|
|---|
| 183 | kobj->Read(fid,kstr);
|
|---|
| 184 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | else if (!strncmp(kstr,"<LatLonBox",10)) {
|
|---|
| 188 | kobj=(KML_Object*)new KML_LatLonBox();
|
|---|
| 189 | kobj->Read(fid,kstr);
|
|---|
| 190 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | else if (!strncmp(kstr,"<Icon", 5)) {
|
|---|
| 194 | kobj=(KML_Object*)new KML_Icon();
|
|---|
| 195 | kobj->Read(fid,kstr);
|
|---|
| 196 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | else if (!strncmp(kstr,"<Point", 6)) {
|
|---|
| 200 | kobj=(KML_Object*)new KML_Point();
|
|---|
| 201 | kobj->Read(fid,kstr);
|
|---|
| 202 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | else if (!strncmp(kstr,"<LineString",11)) {
|
|---|
| 206 | kobj=(KML_Object*)new KML_LineString();
|
|---|
| 207 | kobj->Read(fid,kstr);
|
|---|
| 208 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | else if (!strncmp(kstr,"<LinearRing",11)) {
|
|---|
| 212 | kobj=(KML_Object*)new KML_LinearRing();
|
|---|
| 213 | kobj->Read(fid,kstr);
|
|---|
| 214 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | else if (!strncmp(kstr,"<Polygon", 8)) {
|
|---|
| 218 | kobj=(KML_Object*)new KML_Polygon();
|
|---|
| 219 | kobj->Read(fid,kstr);
|
|---|
| 220 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | else if (!strncmp(kstr,"<MultiGeometry",14)) {
|
|---|
| 224 | kobj=(KML_Object*)new KML_MultiGeometry();
|
|---|
| 225 | kobj->Read(fid,kstr);
|
|---|
| 226 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | // else if (!strncmp(kstr,"<IconStyle",10)) {
|
|---|
| 230 | // kobj=(KML_Object*)new KML_IconStyle();
|
|---|
| 231 | // kobj->Read(fid,kstr);
|
|---|
| 232 | // kmlobj ->AddObject((Object*)kobj);
|
|---|
| 233 | // }
|
|---|
| 234 |
|
|---|
| 235 | // else if (!strncmp(kstr,"<LabelStyle",11)) {
|
|---|
| 236 | // kobj=(KML_Object*)new KML_LabelStyle();
|
|---|
| 237 | // kobj->Read(fid,kstr);
|
|---|
| 238 | // kmlobj ->AddObject((Object*)kobj);
|
|---|
| 239 | // }
|
|---|
| 240 |
|
|---|
| 241 | else if (!strncmp(kstr,"<LineStyle",10)) {
|
|---|
| 242 | kobj=(KML_Object*)new KML_LineStyle();
|
|---|
| 243 | kobj->Read(fid,kstr);
|
|---|
| 244 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | else if (!strncmp(kstr,"<PolyStyle",10)) {
|
|---|
| 248 | kobj=(KML_Object*)new KML_PolyStyle();
|
|---|
| 249 | kobj->Read(fid,kstr);
|
|---|
| 250 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | // else if (!strncmp(kstr,"<BalloonStyle",13)) {
|
|---|
| 254 | // kobj=(KML_Object*)new KML_BalloonStyle();
|
|---|
| 255 | // kobj->Read(fid,kstr);
|
|---|
| 256 | // kmlobj ->AddObject((Object*)kobj);
|
|---|
| 257 | // }
|
|---|
| 258 |
|
|---|
| 259 | // else if (!strncmp(kstr,"<ListStyle",10)) {
|
|---|
| 260 | // kobj=(KML_Object*)new KML_ListStyle();
|
|---|
| 261 | // kobj->Read(fid,kstr);
|
|---|
| 262 | // kmlobj ->AddObject((Object*)kobj);
|
|---|
| 263 | // }
|
|---|
| 264 |
|
|---|
| 265 | else if (!strncmp(kstr,"<",1)) {
|
|---|
| 266 | _printf0_("KML_Object::Read -- Unrecognized opening tag " << kstr << ".\n");
|
|---|
| 267 | // KMLFileTagSkip(kstr,
|
|---|
| 268 | // fid);
|
|---|
| 269 | kobj=(KML_Object*)new KML_Unknown();
|
|---|
| 270 | kobj->Read(fid,kstr);
|
|---|
| 271 | kmlobj ->AddObject((Object*)kobj);
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | return;
|
|---|
| 275 | }
|
|---|
| 276 | /*}}}*/
|
|---|
| 277 | /*FUNCTION KML_Object::WriteExp {{{*/
|
|---|
| 278 | void KML_Object::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
|
|---|
| 279 |
|
|---|
| 280 | ;
|
|---|
| 281 |
|
|---|
| 282 | return;
|
|---|
| 283 | }
|
|---|
| 284 | /*}}}*/
|
|---|
| 285 | /*FUNCTION KML_Object::AddAttrib {{{*/
|
|---|
| 286 | void KML_Object::AddAttrib(const char* name,const char* value){
|
|---|
| 287 |
|
|---|
| 288 | KML_Attribute* katt=NULL;
|
|---|
| 289 |
|
|---|
| 290 | katt=new KML_Attribute();
|
|---|
| 291 | katt->Alloc(name,value);
|
|---|
| 292 | katt->Add(attrib);
|
|---|
| 293 |
|
|---|
| 294 | return;
|
|---|
| 295 | }
|
|---|
| 296 | /*}}}*/
|
|---|
| 297 | /*FUNCTION KML_Object::FindAttrib {{{*/
|
|---|
| 298 | void KML_Object::FindAttrib(char** pvalue,char* name,char* deflt){
|
|---|
| 299 |
|
|---|
| 300 | int i;
|
|---|
| 301 | KML_Attribute* katt=NULL;
|
|---|
| 302 |
|
|---|
| 303 | /* loop over any attributes for the object */
|
|---|
| 304 |
|
|---|
| 305 | if (attrib->Size())
|
|---|
| 306 | for (i=0; i<attrib->Size(); i++)
|
|---|
| 307 | if (!strcmp(((KML_Attribute *)attrib->GetObjectByOffset(i))->name,name)) {
|
|---|
| 308 | katt=(KML_Attribute *)attrib->GetObjectByOffset(i);
|
|---|
| 309 | break;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | /* if found, get the value; otherwise use the default */
|
|---|
| 313 |
|
|---|
| 314 | if (katt)
|
|---|
| 315 | katt->Get(pvalue,deflt);
|
|---|
| 316 | else {
|
|---|
| 317 | *pvalue=xNew<char>(strlen(deflt)+1);
|
|---|
| 318 | memcpy(*pvalue,deflt,(strlen(deflt)+1)*sizeof(char));
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | return;
|
|---|
| 322 | }
|
|---|
| 323 | /*}}}*/
|
|---|
| 324 | /*FUNCTION KML_Object::WriteAttrib {{{*/
|
|---|
| 325 | void KML_Object::WriteAttrib(FILE* filout,const char* indent){
|
|---|
| 326 |
|
|---|
| 327 | // attributes always written in keyword line of kml_object
|
|---|
| 328 |
|
|---|
| 329 | /* loop over any attributes for the object */
|
|---|
| 330 |
|
|---|
| 331 | if (attrib->Size())
|
|---|
| 332 | for (int i=0; i<attrib->Size(); i++)
|
|---|
| 333 | ((KML_Attribute *)attrib->GetObjectByOffset(i))->Write(filout,indent);
|
|---|
| 334 |
|
|---|
| 335 | return;
|
|---|
| 336 | }
|
|---|
| 337 | /*}}}*/
|
|---|
| 338 | /*FUNCTION KML_Object::AddCommnt {{{*/
|
|---|
| 339 | void KML_Object::AddCommnt(int ncom,char** pcom){
|
|---|
| 340 |
|
|---|
| 341 | int i;
|
|---|
| 342 | KML_Comment* kcom=NULL;
|
|---|
| 343 |
|
|---|
| 344 | for (i=0; i<ncom; i++) {
|
|---|
| 345 | kcom=new KML_Comment();
|
|---|
| 346 | kcom->Alloc(pcom[i]);
|
|---|
| 347 | kcom->Add(commnt);
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | return;
|
|---|
| 351 | }
|
|---|
| 352 | /*}}}*/
|
|---|
| 353 | /*FUNCTION KML_Object::AddCommnt {{{*/
|
|---|
| 354 | void KML_Object::AddCommnt(char* value){
|
|---|
| 355 |
|
|---|
| 356 | KML_Comment* kcom=NULL;
|
|---|
| 357 |
|
|---|
| 358 | kcom=new KML_Comment();
|
|---|
| 359 | kcom->Alloc(value);
|
|---|
| 360 | kcom->Add(commnt);
|
|---|
| 361 |
|
|---|
| 362 | return;
|
|---|
| 363 | }
|
|---|
| 364 | /*}}}*/
|
|---|
| 365 | /*FUNCTION KML_Object::FindCommnt {{{*/
|
|---|
| 366 | void KML_Object::FindCommnt(char** pvalue,int inum){
|
|---|
| 367 |
|
|---|
| 368 | KML_Comment* kcom=NULL;
|
|---|
| 369 |
|
|---|
| 370 | /* loop over any comments for the object */
|
|---|
| 371 |
|
|---|
| 372 | if (inum <= commnt->Size())
|
|---|
| 373 | kcom=(KML_Comment *)commnt->GetObjectByOffset(inum-1);
|
|---|
| 374 |
|
|---|
| 375 | /* if found, get the value; otherwise use the NULL */
|
|---|
| 376 |
|
|---|
| 377 | if (kcom)
|
|---|
| 378 | kcom->Get(pvalue);
|
|---|
| 379 |
|
|---|
| 380 | return;
|
|---|
| 381 | }
|
|---|
| 382 | /*}}}*/
|
|---|
| 383 | /*FUNCTION KML_Object::WriteCommnt {{{*/
|
|---|
| 384 | void KML_Object::WriteCommnt(FILE* filout,const char* indent){
|
|---|
| 385 |
|
|---|
| 386 | int i;
|
|---|
| 387 |
|
|---|
| 388 | // comments always written after keyword line of kml_object
|
|---|
| 389 |
|
|---|
| 390 | /* loop over any comments for the object */
|
|---|
| 391 |
|
|---|
| 392 | if (commnt->Size())
|
|---|
| 393 | for (i=0; i<commnt->Size(); i++)
|
|---|
| 394 | ((KML_Comment *)commnt->GetObjectByOffset(i))->Write(filout,indent);
|
|---|
| 395 |
|
|---|
| 396 | return;
|
|---|
| 397 | }
|
|---|
| 398 | /*}}}*/
|
|---|