source: issm/trunk-jpl/src/c/kml/KML_Point.cpp@ 15099

Last change on this file since 15099 was 15099, checked in by Eric.Larour, 12 years ago

CHG: greatly simplified the shared/io/Print routines. Replaced
_printf_ by _pprintString_ , then replaced all _printLine_ by _printString_
and _pprintLine_ by _pprintString_
We will then replace the _printString_ by _printf_ and _pprintString_ by _printf0_

File size: 4.4 KB
Line 
1/*!\file KML_Point.cpp
2 * \brief: implementation of the kml_point 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 "./KML_Point.h"
14#include "./KMLFileReadUtils.h"
15#include "../shared/shared.h"
16/*}}}*/
17
18/*Constructors/destructor/copy*/
19/*FUNCTION KML_Point::KML_Point(){{{*/
20KML_Point::KML_Point(){
21
22 extrude =false;
23 memcpy(altmode,"clampToGround",(strlen("clampToGround")+1)*sizeof(char));
24
25 coords[0] = 0.;
26 coords[1] = 0.;
27 coords[2] = 0.;
28
29}
30/*}}}*/
31/*FUNCTION KML_Point::~KML_Point(){{{*/
32KML_Point::~KML_Point(){
33
34 ;
35
36}
37/*}}}*/
38
39/*Other*/
40/*FUNCTION KML_Point::Echo {{{*/
41void KML_Point::Echo(){
42
43 bool flag=true;
44
45 if(flag) _pprintString_("KML_Point:" << "\n");
46 KML_Geometry::Echo();
47
48 if(flag) _pprintString_(" extrude: " << (extrude ? "true" : "false") << "\n");
49 if(flag) _pprintString_(" altmode: \"" << altmode << "\"" << "\n");
50 if(flag) _pprintString_(" coords: (" << coords[0] << "," << coords[1] << "," << coords[2] << ")" << "\n");
51
52 return;
53}
54/*}}}*/
55/*FUNCTION KML_Point::DeepEcho {{{*/
56void KML_Point::DeepEcho(){
57
58 char indent[81]="";
59
60 KML_Point::DeepEcho(indent);
61
62 return;
63}
64/*}}}*/
65/*FUNCTION KML_Point::DeepEcho {{{*/
66void KML_Point::DeepEcho(const char* indent){
67
68 bool flag=true;
69
70 if(flag) _pprintString_(indent << "KML_Point:" << "\n");
71 KML_Geometry::DeepEcho(indent);
72
73 if(flag) _pprintString_(indent << " extrude: " << (extrude ? "true" : "false") << "\n");
74 if(flag) _pprintString_(indent << " altmode: \"" << altmode << "\"" << "\n");
75 if(flag) _pprintString_(indent << " coords: (" << coords[0] << "," << coords[1] << "," << coords[2] << ")" << "\n");
76
77 return;
78}
79/*}}}*/
80/*FUNCTION KML_Point::Write {{{*/
81void KML_Point::Write(FILE* filout,const char* indent){
82
83 fprintf(filout,"%s<Point",indent);
84 WriteAttrib(filout," ");
85 fprintf(filout,">\n");
86 WriteCommnt(filout,indent);
87
88 KML_Geometry::Write(filout,indent);
89
90 fprintf(filout,"%s <extrude>%d</extrude>\n",indent,(extrude ? 1 : 0));
91 fprintf(filout,"%s <altitudeMode>%s</altitudeMode>\n",indent,altmode);
92 fprintf(filout,"%s <coordinates>%0.16g,%0.16g,%0.16g</coordinates>\n",
93 indent,coords[0],coords[1],coords[2]);
94
95 fprintf(filout,"%s</Point>\n",indent);
96
97 return;
98}
99/*}}}*/
100/*FUNCTION KML_Point::Read {{{*/
101void KML_Point::Read(FILE* fid,char* kstr){
102
103 double* pcoords=&coords[0];
104 char* kstri;
105 int ncom=0;
106 char** pcom=NULL;
107
108/* get object attributes and check for solo tag */
109
110 if (KMLFileTagAttrib(this,
111 kstr))
112 return;
113
114/* loop over and process fields within opening and closing tags */
115
116 while (kstri=KMLFileToken(fid,
117 &ncom,&pcom)) {
118 if (!strncmp(kstri,"</Point", 7)) {
119 xDelete<char>(kstri);
120 break;
121 }
122 else if (!strncmp(kstri,"</",2))
123 {_error_("KML_Point::Read -- Unexpected closing tag " << kstri << ".\n");}
124 else if (strncmp(kstri,"<",1))
125 {_error_("KML_Point::Read -- Unexpected field \"" << kstri << "\".\n");}
126
127 else if (!strcmp(kstri,"<extrude>"))
128 KMLFileTokenParse(&extrude , kstri, fid);
129 else if (!strcmp(kstri,"<altitudeMode>"))
130 KMLFileTokenParse( altmode ,NULL,KML_POINT_ALTMODE_LENGTH, kstri, fid);
131 else if (!strcmp(kstri,"<coordinates>"))
132 KMLFileTokenParse(&pcoords ,NULL,3, kstri, fid);
133
134 else if (!strncmp(kstri,"<",1))
135 KML_Geometry::Read(fid,kstri);
136
137 xDelete<char>(kstri);
138 }
139
140 this->AddCommnt(ncom,pcom);
141
142 for (ncom; ncom>0; ncom--)
143 xDelete<char>(pcom[ncom-1]);
144 xDelete<char*>(pcom);
145
146 return;
147}
148/*}}}*/
149/*FUNCTION KML_Point::WriteExp {{{*/
150void KML_Point::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
151
152 int i;
153 double lat,lon,x,y;
154 char nstr2[81];
155
156/* extract latitude and longitude */
157
158 lon=coords[0];
159 lat=coords[1];
160
161/* convert latitude and longitude to x and y */
162
163 if (sgn) {
164 Ll2xyx(&x,&y,&lat,&lon,1,sgn,cm,sp);
165 }
166 else {
167 memcpy(&x,&lon,1*sizeof(IssmDouble));
168 memcpy(&y,&lat,1*sizeof(IssmDouble));
169 }
170
171/* write header */
172
173 memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char));
174
175 for (i=0; i<strlen(nstr2); i++)
176 if ((nstr2[i] == ' ') || (nstr2[i] == '\t'))
177 nstr2[i]='_';
178 fprintf(fid,"## Name:%s\n",nstr2);
179 fprintf(fid,"## Icon:0\n");
180 fprintf(fid,"# Points Count Value\n");
181 fprintf(fid,"%u %s\n",1,"1.");
182 fprintf(fid,"# X pos Y pos\n");
183
184/* write vertex */
185
186 fprintf(fid,"%lf\t%lf\n",x,y);
187
188/* write blank line */
189
190 fprintf(fid,"\n");
191
192 return;
193}
194/*}}}*/
Note: See TracBrowser for help on using the repository browser.