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

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

merged trunk-jpl and trunk for revision 16554

File size: 8.1 KB
Line 
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(){{{*/
35KML_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(){{{*/
44KML_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 {{{*/
64void 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 {{{*/
76void KML_Object::DeepEcho(){
77
78 char indent[81]="";
79
80 KML_Object::DeepEcho(indent);
81
82 return;
83}
84/*}}}*/
85/*FUNCTION KML_Object::DeepEcho {{{*/
86void 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 {{{*/
128void 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 {{{*/
150void 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 {{{*/
278void 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 {{{*/
286void 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::WriteAttrib {{{*/
298void KML_Object::WriteAttrib(FILE* filout,const char* indent){
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())
305 for (int i=0; i<attrib->Size(); i++)
306 ((KML_Attribute *)attrib->GetObjectByOffset(i))->Write(filout,indent);
307
308 return;
309}
310/*}}}*/
311/*FUNCTION KML_Object::AddCommnt {{{*/
312void 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/*}}}*/
326/*FUNCTION KML_Object::AddCommnt {{{*/
327void 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/*}}}*/
338/*FUNCTION KML_Object::WriteCommnt {{{*/
339void KML_Object::WriteCommnt(FILE* filout,const char* indent){
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/*}}}*/
Note: See TracBrowser for help on using the repository browser.