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