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

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

KML: Addition of KML_Comment class to save and regurgitate KML comments.

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(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
81 strcat(indent2," ");
82
83 if (geometry->Size())
84 for (i=0; i<geometry->Size(); i++) {
85 _printf_(flag,"%s geometry: -------- begin [%d] --------\n" ,indent,i);
86 ((KML_Geometry *)geometry->GetObjectByOffset(i))->DeepEcho(indent2);
87 _printf_(flag,"%s geometry: -------- end [%d] --------\n" ,indent,i);
88 }
89 else
90 _printf_(flag,"%s geometry: [empty]\n" ,indent);
91
92 return;
93}
94/*}}}*/
95
96/*FUNCTION KML_MultiGeometry::Write {{{1*/
97void KML_MultiGeometry::Write(FILE* filout,char* indent){
98
99 int i;
100 char indent2[81];
101
102 fprintf(filout,"%s<MultiGeometry",indent);
103 WriteAttrib(filout," ");
104 fprintf(filout,">\n");
105 WriteCommnt(filout,indent);
106
107 KML_Geometry::Write(filout,indent);
108
109/* loop over the geometry elements for the multigeometry */
110
111 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
112
113 strcat(indent2," ");
114
115 for (i=0; i<geometry->Size(); i++)
116 ((KML_Geometry *)geometry->GetObjectByOffset(i))->Write(filout,indent2);
117
118 fprintf(filout,"%s</MultiGeometry>\n",indent);
119
120 return;
121}
122/*}}}*/
123
124/*FUNCTION KML_MultiGeometry::Read {{{1*/
125void KML_MultiGeometry::Read(FILE* fid,char* kstr){
126
127 char* kstri;
128 int ncom=0;
129 char** pcom=NULL;
130 KML_Object* kobj;
131
132/* get object attributes and check for solo tag */
133
134 if (KMLFileTagAttrib(this,
135 kstr))
136 return;
137
138/* loop over and process fields within opening and closing tags */
139
140 while (kstri=KMLFileToken(fid,
141 &ncom,&pcom)) {
142 if (!strncmp(kstri,"</MultiGeometry",15)) {
143 xfree((void**)&kstri);
144 break;
145 }
146 else if (!strncmp(kstri,"</",2))
147 _error_("KML_MultiGeometry::Read -- Unexpected closing tag %s.\n",kstri);
148 else if (strncmp(kstri,"<",1))
149 _error_("KML_MultiGeometry::Read -- Unexpected field \"%s\".\n",kstri);
150
151 else if (!strncmp(kstri,"<Point", 6)) {
152 kobj=(KML_Object*)new KML_Point();
153 kobj->Read(fid,kstri);
154 geometry ->AddObject((Object*)kobj);
155 }
156
157 else if (!strncmp(kstri,"<LineString",11)) {
158 kobj=(KML_Object*)new KML_LineString();
159 kobj->Read(fid,kstri);
160 geometry ->AddObject((Object*)kobj);
161 }
162
163 else if (!strncmp(kstri,"<LinearRing",11)) {
164 kobj=(KML_Object*)new KML_LinearRing();
165 kobj->Read(fid,kstri);
166 geometry ->AddObject((Object*)kobj);
167 }
168
169 else if (!strncmp(kstri,"<Polygon", 8)) {
170 kobj=(KML_Object*)new KML_Polygon();
171 kobj->Read(fid,kstri);
172 geometry ->AddObject((Object*)kobj);
173 }
174
175 else if (!strncmp(kstri,"<MultiGeometry",14)) {
176 kobj=(KML_Object*)new KML_MultiGeometry();
177 kobj->Read(fid,kstri);
178 geometry ->AddObject((Object*)kobj);
179 }
180
181 else if (!strncmp(kstri,"<",1))
182 KML_Geometry::Read(fid,kstri);
183
184 xfree((void**)&kstri);
185 }
186
187 this->AddCommnt(ncom,pcom);
188
189 for (ncom; ncom>0; ncom--)
190 xfree((void**)&(pcom[ncom-1]));
191 xfree((void**)&pcom);
192
193 return;
194}
195/*}}}*/
196
197/*FUNCTION KML_MultiGeometry::WriteExp {{{1*/
198void KML_MultiGeometry::WriteExp(FILE* fid,char* nstr,int sgn,double cm,double sp){
199
200 int i;
201
202/* loop over the geometry elements for the multigeometry */
203
204 for (i=0; i<geometry->Size(); i++)
205 ((KML_Object *)geometry->GetObjectByOffset(i))->WriteExp(fid,nstr,sgn,cm,sp);
206
207 return;
208}
209/*}}}*/
210
Note: See TracBrowser for help on using the repository browser.