source: issm/trunk/src/c/classes/objects/KML/KML_Polygon.cpp@ 13395

Last change on this file since 13395 was 13395, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 13393

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