source: issm/trunk/src/c/kml/KML_Object.cpp

Last change on this file was 18301, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 18299

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