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