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

Last change on this file since 18063 was 18063, checked in by Mathieu Morlighem, 11 years ago

CHG: removed some FUNCTION folds, moved to function declaration

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