1 | /*!\file KML_Feature.cpp
|
---|
2 | * \brief: implementation of the kml_feature abstract 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 "../shared/shared.h"
|
---|
14 | /*}}}*/
|
---|
15 | /*{{{*/
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #else
|
---|
19 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | #include "./KML_Feature.h"
|
---|
23 | #include "./KML_Style.h"
|
---|
24 | #include "./KMLFileReadUtils.h"
|
---|
25 | #include "../shared/shared.h"
|
---|
26 | /*}}}*/
|
---|
27 |
|
---|
28 | /*Constructors/destructor/copy*/
|
---|
29 | KML_Feature::KML_Feature(){/*{{{*/
|
---|
30 |
|
---|
31 | memcpy(name,"",(strlen("")+1)*sizeof(char));
|
---|
32 |
|
---|
33 | visibility=true;
|
---|
34 | open =false;
|
---|
35 | memcpy(snippet,"",(strlen("")+1)*sizeof(char));
|
---|
36 | memcpy(descript,"",(strlen("")+1)*sizeof(char));
|
---|
37 | memcpy(styleurl,"",(strlen("")+1)*sizeof(char));
|
---|
38 | style =new DataSet;
|
---|
39 |
|
---|
40 | }
|
---|
41 | /*}}}*/
|
---|
42 | KML_Feature::~KML_Feature(){/*{{{*/
|
---|
43 |
|
---|
44 | if (style) {
|
---|
45 | delete style;
|
---|
46 | style =NULL;
|
---|
47 | }
|
---|
48 |
|
---|
49 | }
|
---|
50 | /*}}}*/
|
---|
51 |
|
---|
52 | /*Other*/
|
---|
53 | void KML_Feature::Echo(){/*{{{*/
|
---|
54 |
|
---|
55 | bool flag=true;
|
---|
56 |
|
---|
57 | KML_Object::Echo();
|
---|
58 |
|
---|
59 | if(flag) _printf0_(" name: \"" << name << "\"\n");
|
---|
60 | if(flag) _printf0_(" visibility: " << (visibility ? "true" : "false") << "\n");
|
---|
61 | if(flag) _printf0_(" open: " << (open ? "true" : "false") << "\n");
|
---|
62 | if(flag) _printf0_(" snippet: \"" << snippet << "\"\n");
|
---|
63 | if(flag) _printf0_(" descript: \"" << descript << "\"\n");
|
---|
64 | if(flag) _printf0_(" styleurl: \"" << styleurl << "\"\n");
|
---|
65 | if(flag) _printf0_(" style: (size=" << style->Size() << ")\n");
|
---|
66 |
|
---|
67 | return;
|
---|
68 | }
|
---|
69 | /*}}}*/
|
---|
70 | void KML_Feature::DeepEcho(){/*{{{*/
|
---|
71 |
|
---|
72 | char indent[81]="";
|
---|
73 |
|
---|
74 | KML_Feature::DeepEcho(indent);
|
---|
75 |
|
---|
76 | return;
|
---|
77 | }
|
---|
78 | /*}}}*/
|
---|
79 | void KML_Feature::DeepEcho(const char* indent){/*{{{*/
|
---|
80 |
|
---|
81 | int i;
|
---|
82 | char indent2[81];
|
---|
83 | bool flag=true;
|
---|
84 |
|
---|
85 | KML_Object::DeepEcho(indent);
|
---|
86 |
|
---|
87 | if(flag) _printf0_(indent << " name: \"" << name << "\"\n");
|
---|
88 | if(flag) _printf0_(indent << " visibility: " << (visibility ? "true" : "false") << "\n");
|
---|
89 | if(flag) _printf0_(indent << " open: " << (open ? "true" : "false") << "\n");
|
---|
90 | if(flag) _printf0_(indent << " snippet: \"" << snippet << "\"\n");
|
---|
91 | if(flag) _printf0_(indent << " descript: \"" << descript << "\"\n");
|
---|
92 | if(flag) _printf0_(indent << " styleurl: \"" << styleurl << "\"\n");
|
---|
93 |
|
---|
94 | /* loop over any styles for the feature */
|
---|
95 |
|
---|
96 | memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
|
---|
97 | strcat(indent2," ");
|
---|
98 |
|
---|
99 | if (style->Size())
|
---|
100 | for (i=0; i<style->Size(); i++) {
|
---|
101 | if(flag) _printf0_(indent << " style: -------- begin [" << i << "] --------\n");
|
---|
102 | ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2);
|
---|
103 | if(flag) _printf0_(indent << " style: -------- end [" << i << "] --------\n");
|
---|
104 | }
|
---|
105 | else
|
---|
106 | if(flag) _printf0_(indent << " style: [empty]\n");
|
---|
107 |
|
---|
108 | return;
|
---|
109 | }
|
---|
110 | /*}}}*/
|
---|
111 | void KML_Feature::Write(FILE* filout,const char* indent){/*{{{*/
|
---|
112 |
|
---|
113 | int i;
|
---|
114 | char indent2[81];
|
---|
115 |
|
---|
116 | KML_Object::Write(filout,indent);
|
---|
117 |
|
---|
118 | if (name && strlen(name))
|
---|
119 | fprintf(filout,"%s <name>%s</name>\n",indent,name);
|
---|
120 | fprintf(filout,"%s <visibility>%d</visibility>\n",indent,(visibility ? 1 : 0));
|
---|
121 | fprintf(filout,"%s <open>%d</open>\n",indent,(open ? 1 : 0));
|
---|
122 | if (snippet && strlen(snippet))
|
---|
123 | fprintf(filout,"%s <Snippet maxLines=\"2\">%s</Snippet>\n",indent,snippet);
|
---|
124 | if (descript && strlen(descript))
|
---|
125 | fprintf(filout,"%s <description>%s</description>\n",indent,descript);
|
---|
126 | if (styleurl && strlen(styleurl))
|
---|
127 | fprintf(filout,"%s <styleUrl>%s</styleUrl>\n",indent,styleurl);
|
---|
128 |
|
---|
129 | /* loop over any styles for the feature */
|
---|
130 |
|
---|
131 | memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
|
---|
132 |
|
---|
133 | strcat(indent2," ");
|
---|
134 |
|
---|
135 | for (i=0; i<style->Size(); i++)
|
---|
136 | ((KML_Style *)style->GetObjectByOffset(i))->Write(filout,indent2);
|
---|
137 |
|
---|
138 | return;
|
---|
139 | }
|
---|
140 | /*}}}*/
|
---|
141 | void KML_Feature::Read(FILE* fid,char* kstr){/*{{{*/
|
---|
142 |
|
---|
143 | KML_Object* kobj;
|
---|
144 |
|
---|
145 | /* process field within opening and closing tags */
|
---|
146 |
|
---|
147 | if (!strncmp(kstr,"</Feature", 9))
|
---|
148 | return;
|
---|
149 | else if (!strncmp(kstr,"</",2))
|
---|
150 | {_error_("KML_Feature::Read -- Unexpected closing tag " << kstr);}
|
---|
151 | else if (strncmp(kstr,"<",1))
|
---|
152 | {_error_("KML_Feature::Read -- Unexpected field \"" << kstr << "\"");}
|
---|
153 |
|
---|
154 | else if (!strncmp(kstr,"<Style", 6)) {
|
---|
155 | kobj=(KML_Object*)new KML_Style();
|
---|
156 | kobj->Read(fid,kstr);
|
---|
157 | style ->AddObject((Object*)kobj);
|
---|
158 | }
|
---|
159 |
|
---|
160 | else if (!strcmp(kstr,"<name>"))
|
---|
161 | KMLFileTokenParse( name ,NULL,KML_FEATURE_NAME_LENGTH, kstr, fid);
|
---|
162 | else if (!strcmp(kstr,"<visibility>"))
|
---|
163 | KMLFileTokenParse(&visibility, kstr, fid);
|
---|
164 | else if (!strcmp(kstr,"<open>"))
|
---|
165 | KMLFileTokenParse(&open , kstr, fid);
|
---|
166 | else if (!strncmp(kstr,"<snippet", 8))
|
---|
167 | KMLFileTokenParse( snippet ,NULL,KML_FEATURE_SNIPPET_LENGTH, kstr, fid);
|
---|
168 | else if (!strcmp(kstr,"<description>"))
|
---|
169 | KMLFileTokenParse( descript ,NULL,KML_FEATURE_DESCRIPT_LENGTH, kstr, fid);
|
---|
170 | else if (!strcmp(kstr,"<styleUrl>"))
|
---|
171 | KMLFileTokenParse( styleurl ,NULL,KML_FEATURE_STYLEURL_LENGTH, kstr, fid);
|
---|
172 |
|
---|
173 | else if (!strncmp(kstr,"<",1))
|
---|
174 | KML_Object::Read(fid,kstr);
|
---|
175 |
|
---|
176 | return;
|
---|
177 | }
|
---|
178 | /*}}}*/
|
---|