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