source: issm/trunk-jpl/src/c/objects/KML/KML_File.cpp@ 11319

Last change on this file since 11319 was 11319, checked in by jschierm, 13 years ago

KML: Implemented KML_Unknown class to digest and regurgitate unknown KML elements.

File size: 6.2 KB
Line 
1/*!\file KML_File.cpp
2 * \brief: implementation of the kml_file object
3 */
4
5/*Headers:*/
6/*{{{1*/
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 "../../io/io.h"
18#include "../../Container/Container.h"
19#include "../../include/include.h"
20/*}}}*/
21
22/*Constructors/destructor/copy*/
23/*FUNCTION KML_File::KML_File(){{{1*/
24KML_File::KML_File(){
25
26 kmlobj =new DataSet;
27
28}
29/*}}}*/
30/*FUNCTION KML_File::~KML_File(){{{1*/
31KML_File::~KML_File(){
32
33 if (kmlobj) {
34 delete kmlobj;
35 kmlobj =NULL;
36 }
37
38}
39/*}}}*/
40
41/*Other*/
42/*FUNCTION KML_File::Echo {{{1*/
43void KML_File::Echo(){
44
45 bool flag=true;
46
47 _printf_(flag,"KML_File:\n");
48 KML_Object::Echo();
49
50 _printf_(flag," kmlobj: (size=%d)\n" ,kmlobj->Size());
51
52 return;
53}
54/*}}}*/
55/*FUNCTION KML_File::DeepEcho {{{1*/
56void KML_File::DeepEcho(){
57
58 char indent[81]="";
59
60 KML_File::DeepEcho(indent);
61
62 return;
63}
64/*}}}*/
65/*FUNCTION KML_File::DeepEcho {{{1*/
66void KML_File::DeepEcho(const char* indent){
67
68 int i;
69 char indent2[81];
70 bool flag=true;
71
72 _printf_(flag,"%sKML_File:\n",indent);
73 KML_Object::DeepEcho(indent);
74
75/* loop over the kml objects for the file */
76
77 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
78 strcat(indent2," ");
79
80 if (kmlobj->Size())
81 for (i=0; i<kmlobj->Size(); i++) {
82 _printf_(flag,"%s kmlobj: -------- begin [%d] --------\n" ,indent,i);
83 ((KML_Object *)kmlobj->GetObjectByOffset(i))->DeepEcho(indent2);
84 _printf_(flag,"%s kmlobj: -------- end [%d] --------\n" ,indent,i);
85 }
86 else
87 _printf_(flag,"%s kmlobj: [empty]\n" ,indent);
88
89 return;
90}
91/*}}}*/
92/*FUNCTION KML_File::Write {{{1*/
93void KML_File::Write(FILE* filout,const char* indent){
94
95 int i;
96 char indent2[81];
97
98 fprintf(filout,"%s<kml",indent);
99 WriteAttrib(filout," ");
100 fprintf(filout,">\n");
101 WriteCommnt(filout,indent);
102
103 KML_Object::Write(filout,indent);
104
105/* loop over the kml objects for the file */
106
107 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
108
109 strcat(indent2," ");
110
111 for (i=0; i<kmlobj->Size(); i++)
112 ((KML_Object *)kmlobj->GetObjectByOffset(i))->Write(filout,indent2);
113
114 fprintf(filout,"%s</kml>\n",indent);
115
116 return;
117}
118/*}}}*/
119/*FUNCTION KML_File::Read {{{1*/
120void KML_File::Read(FILE* fid,char* kstr){
121
122 char* kstri;
123 int ncom=0;
124 char** pcom=NULL;
125 KML_Object* kobj;
126
127/* get object attributes and check for solo tag */
128
129 if (KMLFileTagAttrib(this,
130 kstr))
131 return;
132
133/* loop over and process fields within opening and closing tags */
134
135 while (kstri=KMLFileToken(fid,
136 &ncom,&pcom)) {
137 if (!strncmp(kstri,"</kml", 5)) {
138 xfree((void**)&kstri);
139 break;
140 }
141 else if (!strncmp(kstri,"</",2))
142 _error_("KML_File::Read -- Unexpected closing tag %s.\n",kstri);
143 else if (strncmp(kstri,"<",1))
144 _error_("KML_File::Read -- Unexpected field \"%s\".\n",kstri);
145
146 else if (!strncmp(kstri,"<Placemark",10)) {
147 kobj=(KML_Object*)new KML_Placemark();
148 kobj->Read(fid,kstri);
149 kmlobj ->AddObject((Object*)kobj);
150 }
151
152 else if (!strncmp(kstri,"<Folder", 7)) {
153 kobj=(KML_Object*)new KML_Folder();
154 kobj->Read(fid,kstri);
155 kmlobj ->AddObject((Object*)kobj);
156 }
157
158 else if (!strncmp(kstri,"<Document", 9)) {
159 kobj=(KML_Object*)new KML_Document();
160 kobj->Read(fid,kstri);
161 kmlobj ->AddObject((Object*)kobj);
162 }
163
164 else if (!strncmp(kstri,"<GroundOverlay",14)) {
165 kobj=(KML_Object*)new KML_GroundOverlay();
166 kobj->Read(fid,kstri);
167 kmlobj ->AddObject((Object*)kobj);
168 }
169
170 else if (!strncmp(kstri,"<LatLonBox",10)) {
171 kobj=(KML_Object*)new KML_LatLonBox();
172 kobj->Read(fid,kstri);
173 kmlobj ->AddObject((Object*)kobj);
174 }
175
176 else if (!strncmp(kstri,"<Icon", 5)) {
177 kobj=(KML_Object*)new KML_Icon();
178 kobj->Read(fid,kstri);
179 kmlobj ->AddObject((Object*)kobj);
180 }
181
182 else if (!strncmp(kstri,"<Point", 6)) {
183 kobj=(KML_Object*)new KML_Point();
184 kobj->Read(fid,kstri);
185 kmlobj ->AddObject((Object*)kobj);
186 }
187
188 else if (!strncmp(kstri,"<LineString",11)) {
189 kobj=(KML_Object*)new KML_LineString();
190 kobj->Read(fid,kstri);
191 kmlobj ->AddObject((Object*)kobj);
192 }
193
194 else if (!strncmp(kstri,"<LinearRing",11)) {
195 kobj=(KML_Object*)new KML_LinearRing();
196 kobj->Read(fid,kstri);
197 kmlobj ->AddObject((Object*)kobj);
198 }
199
200 else if (!strncmp(kstri,"<Polygon", 8)) {
201 kobj=(KML_Object*)new KML_Polygon();
202 kobj->Read(fid,kstri);
203 kmlobj ->AddObject((Object*)kobj);
204 }
205
206 else if (!strncmp(kstri,"<MultiGeometry",14)) {
207 kobj=(KML_Object*)new KML_MultiGeometry();
208 kobj->Read(fid,kstri);
209 kmlobj ->AddObject((Object*)kobj);
210 }
211
212// else if (!strncmp(kstri,"<IconStyle",10)) {
213// kobj=(KML_Object*)new KML_IconStyle();
214// kobj->Read(fid,kstri);
215// kmlobj ->AddObject((Object*)kobj);
216// }
217
218// else if (!strncmp(kstri,"<LabelStyle",11)) {
219// kobj=(KML_Object*)new KML_LabelStyle();
220// kobj->Read(fid,kstri);
221// kmlobj ->AddObject((Object*)kobj);
222// }
223
224 else if (!strncmp(kstri,"<LineStyle",10)) {
225 kobj=(KML_Object*)new KML_LineStyle();
226 kobj->Read(fid,kstri);
227 kmlobj ->AddObject((Object*)kobj);
228 }
229
230 else if (!strncmp(kstri,"<PolyStyle",10)) {
231 kobj=(KML_Object*)new KML_PolyStyle();
232 kobj->Read(fid,kstri);
233 kmlobj ->AddObject((Object*)kobj);
234 }
235
236// else if (!strncmp(kstri,"<BalloonStyle",13)) {
237// kobj=(KML_Object*)new KML_BalloonStyle();
238// kobj->Read(fid,kstri);
239// kmlobj ->AddObject((Object*)kobj);
240// }
241
242// else if (!strncmp(kstri,"<ListStyle",10)) {
243// kobj=(KML_Object*)new KML_ListStyle();
244// kobj->Read(fid,kstri);
245// kmlobj ->AddObject((Object*)kobj);
246// }
247
248 else if (!strncmp(kstri,"<",1))
249 KML_Object::Read(fid,kstri);
250
251 xfree((void**)&kstri);
252 }
253
254 this->AddCommnt(ncom,pcom);
255
256 for (ncom; ncom>0; ncom--)
257 xfree((void**)&(pcom[ncom-1]));
258 xfree((void**)&pcom);
259
260 return;
261}
262/*}}}*/
263/*FUNCTION KML_File::WriteExp {{{1*/
264void KML_File::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
265
266 int i;
267
268/* loop over the kml objects for the file */
269
270 for (i=0; i<kmlobj->Size(); i++)
271 ((KML_Object *)kmlobj->GetObjectByOffset(i))->WriteExp(fid,nstr,sgn,cm,sp);
272
273 return;
274}
275/*}}}*/
Note: See TracBrowser for help on using the repository browser.