source: issm/trunk/src/c/objects/KML/KML_MultiGeometry.cpp@ 11527

Last change on this file since 11527 was 11527, checked in by Mathieu Morlighem, 13 years ago

merged trunk-jpl and trunk for revision 11526

File size: 4.6 KB
Line 
1/*!\file KML_MultiGeometry.cpp
2 * \brief: implementation of the kml_multigeometry 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_MultiGeometry::KML_MultiGeometry(){{{1*/
24KML_MultiGeometry::KML_MultiGeometry(){
25
26 geometry =new DataSet;
27
28}
29/*}}}*/
30/*FUNCTION KML_MultiGeometry::~KML_MultiGeometry(){{{1*/
31KML_MultiGeometry::~KML_MultiGeometry(){
32
33 if (geometry) {
34 delete geometry;
35 geometry =NULL;
36 }
37
38}
39/*}}}*/
40
41/*Other*/
42/*FUNCTION KML_MultiGeometry::Echo {{{1*/
43void KML_MultiGeometry::Echo(){
44
45 bool flag=true;
46
47 _printf_(flag,"KML_Multigeometry:\n");
48 KML_Geometry::Echo();
49
50 _printf_(flag," geometry: (size=%d)\n" ,geometry->Size());
51
52 return;
53}
54/*}}}*/
55
56/*FUNCTION KML_MultiGeometry::DeepEcho {{{1*/
57void KML_MultiGeometry::DeepEcho(){
58
59 char indent[81]="";
60
61 KML_MultiGeometry::DeepEcho(indent);
62
63 return;
64}
65/*}}}*/
66
67/*FUNCTION KML_MultiGeometry::DeepEcho {{{1*/
68void KML_MultiGeometry::DeepEcho(const char* indent){
69
70 int i;
71 char indent2[81];
72 bool flag=true;
73
74 _printf_(flag,"%sKML_Multigeometry:\n",indent);
75 KML_Geometry::DeepEcho(indent);
76
77/* loop over the geometry elements for the multigeometry */
78
79 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
80 strcat(indent2," ");
81
82 if (geometry->Size())
83 for (i=0; i<geometry->Size(); i++) {
84 _printf_(flag,"%s geometry: -------- begin [%d] --------\n" ,indent,i);
85 ((KML_Geometry *)geometry->GetObjectByOffset(i))->DeepEcho(indent2);
86 _printf_(flag,"%s geometry: -------- end [%d] --------\n" ,indent,i);
87 }
88 else
89 _printf_(flag,"%s geometry: [empty]\n" ,indent);
90
91 return;
92}
93/*}}}*/
94
95/*FUNCTION KML_MultiGeometry::Write {{{1*/
96void KML_MultiGeometry::Write(FILE* filout,const char* indent){
97
98 int i;
99 char indent2[81];
100
101 fprintf(filout,"%s<MultiGeometry",indent);
102 WriteAttrib(filout," ");
103 fprintf(filout,">\n");
104 WriteCommnt(filout,indent);
105
106 KML_Geometry::Write(filout,indent);
107
108/* loop over the geometry elements for the multigeometry */
109
110 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
111
112 strcat(indent2," ");
113
114 for (i=0; i<geometry->Size(); i++)
115 ((KML_Geometry *)geometry->GetObjectByOffset(i))->Write(filout,indent2);
116
117 fprintf(filout,"%s</MultiGeometry>\n",indent);
118
119 return;
120}
121/*}}}*/
122
123/*FUNCTION KML_MultiGeometry::Read {{{1*/
124void KML_MultiGeometry::Read(FILE* fid,char* kstr){
125
126 char* kstri;
127 int ncom=0;
128 char** pcom=NULL;
129 KML_Object* kobj;
130
131/* get object attributes and check for solo tag */
132
133 if (KMLFileTagAttrib(this,
134 kstr))
135 return;
136
137/* loop over and process fields within opening and closing tags */
138
139 while (kstri=KMLFileToken(fid,
140 &ncom,&pcom)) {
141 if (!strncmp(kstri,"</MultiGeometry",15)) {
142 xfree((void**)&kstri);
143 break;
144 }
145 else if (!strncmp(kstri,"</",2))
146 _error_("KML_MultiGeometry::Read -- Unexpected closing tag %s.\n",kstri);
147 else if (strncmp(kstri,"<",1))
148 _error_("KML_MultiGeometry::Read -- Unexpected field \"%s\".\n",kstri);
149
150 else if (!strncmp(kstri,"<Point", 6)) {
151 kobj=(KML_Object*)new KML_Point();
152 kobj->Read(fid,kstri);
153 geometry ->AddObject((Object*)kobj);
154 }
155
156 else if (!strncmp(kstri,"<LineString",11)) {
157 kobj=(KML_Object*)new KML_LineString();
158 kobj->Read(fid,kstri);
159 geometry ->AddObject((Object*)kobj);
160 }
161
162 else if (!strncmp(kstri,"<LinearRing",11)) {
163 kobj=(KML_Object*)new KML_LinearRing();
164 kobj->Read(fid,kstri);
165 geometry ->AddObject((Object*)kobj);
166 }
167
168 else if (!strncmp(kstri,"<Polygon", 8)) {
169 kobj=(KML_Object*)new KML_Polygon();
170 kobj->Read(fid,kstri);
171 geometry ->AddObject((Object*)kobj);
172 }
173
174 else if (!strncmp(kstri,"<MultiGeometry",14)) {
175 kobj=(KML_Object*)new KML_MultiGeometry();
176 kobj->Read(fid,kstri);
177 geometry ->AddObject((Object*)kobj);
178 }
179
180 else if (!strncmp(kstri,"<",1))
181 KML_Geometry::Read(fid,kstri);
182
183 xfree((void**)&kstri);
184 }
185
186 this->AddCommnt(ncom,pcom);
187
188 for (ncom; ncom>0; ncom--)
189 xfree((void**)&(pcom[ncom-1]));
190 xfree((void**)&pcom);
191
192 return;
193}
194/*}}}*/
195
196/*FUNCTION KML_MultiGeometry::WriteExp {{{1*/
197void KML_MultiGeometry::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
198
199 int i;
200
201/* loop over the geometry elements for the multigeometry */
202
203 for (i=0; i<geometry->Size(); i++)
204 ((KML_Object *)geometry->GetObjectByOffset(i))->WriteExp(fid,nstr,sgn,cm,sp);
205
206 return;
207}
208/*}}}*/
209
Note: See TracBrowser for help on using the repository browser.