[7653] | 1 | /*!\file KML_Feature.cpp
|
---|
| 2 | * \brief: implementation of the kml_feature abstract object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*Headers:*/
|
---|
[12365] | 6 | /*{{{*/
|
---|
[7653] | 7 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 8 | #include <config.h>
|
---|
[7653] | 9 | #else
|
---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[15068] | 13 | #include "../shared/shared.h"
|
---|
[7653] | 14 | /*}}}*/
|
---|
[15068] | 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
|
---|
[7653] | 21 |
|
---|
[15068] | 22 | #include "./KML_Feature.h"
|
---|
| 23 | #include "./KML_Style.h"
|
---|
| 24 | #include "./KMLFileReadUtils.h"
|
---|
| 25 | #include "../shared/shared.h"
|
---|
| 26 | /*}}}*/
|
---|
| 27 |
|
---|
[7653] | 28 | /*Constructors/destructor/copy*/
|
---|
[18063] | 29 | KML_Feature::KML_Feature(){/*{{{*/
|
---|
[7653] | 30 |
|
---|
[9336] | 31 | memcpy(name,"",(strlen("")+1)*sizeof(char));
|
---|
| 32 |
|
---|
[7653] | 33 | visibility=true;
|
---|
| 34 | open =false;
|
---|
[9336] | 35 | memcpy(snippet,"",(strlen("")+1)*sizeof(char));
|
---|
| 36 | memcpy(descript,"",(strlen("")+1)*sizeof(char));
|
---|
| 37 | memcpy(styleurl,"",(strlen("")+1)*sizeof(char));
|
---|
[7653] | 38 | style =new DataSet;
|
---|
| 39 |
|
---|
| 40 | }
|
---|
| 41 | /*}}}*/
|
---|
[18063] | 42 | KML_Feature::~KML_Feature(){/*{{{*/
|
---|
[7653] | 43 |
|
---|
| 44 | if (style) {
|
---|
| 45 | delete style;
|
---|
| 46 | style =NULL;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | }
|
---|
| 50 | /*}}}*/
|
---|
| 51 |
|
---|
| 52 | /*Other*/
|
---|
[18063] | 53 | void KML_Feature::Echo(){/*{{{*/
|
---|
[7653] | 54 |
|
---|
| 55 | bool flag=true;
|
---|
| 56 |
|
---|
| 57 | KML_Object::Echo();
|
---|
| 58 |
|
---|
[15104] | 59 | if(flag) _printf0_(" name: \"" << name << "\"\n");
|
---|
[15100] | 60 | if(flag) _printf0_(" visibility: " << (visibility ? "true" : "false") << "\n");
|
---|
| 61 | if(flag) _printf0_(" open: " << (open ? "true" : "false") << "\n");
|
---|
[15104] | 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");
|
---|
[7653] | 66 |
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
| 69 | /*}}}*/
|
---|
[18063] | 70 | void KML_Feature::DeepEcho(){/*{{{*/
|
---|
[7653] | 71 |
|
---|
| 72 | char indent[81]="";
|
---|
| 73 |
|
---|
| 74 | KML_Feature::DeepEcho(indent);
|
---|
| 75 |
|
---|
| 76 | return;
|
---|
| 77 | }
|
---|
| 78 | /*}}}*/
|
---|
[18063] | 79 | void KML_Feature::DeepEcho(const char* indent){/*{{{*/
|
---|
[7653] | 80 |
|
---|
| 81 | int i;
|
---|
| 82 | char indent2[81];
|
---|
| 83 | bool flag=true;
|
---|
| 84 |
|
---|
| 85 | KML_Object::DeepEcho(indent);
|
---|
| 86 |
|
---|
[15104] | 87 | if(flag) _printf0_(indent << " name: \"" << name << "\"\n");
|
---|
[15100] | 88 | if(flag) _printf0_(indent << " visibility: " << (visibility ? "true" : "false") << "\n");
|
---|
| 89 | if(flag) _printf0_(indent << " open: " << (open ? "true" : "false") << "\n");
|
---|
[15104] | 90 | if(flag) _printf0_(indent << " snippet: \"" << snippet << "\"\n");
|
---|
| 91 | if(flag) _printf0_(indent << " descript: \"" << descript << "\"\n");
|
---|
| 92 | if(flag) _printf0_(indent << " styleurl: \"" << styleurl << "\"\n");
|
---|
[7653] | 93 |
|
---|
| 94 | /* loop over any styles for the feature */
|
---|
| 95 |
|
---|
[9336] | 96 | memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
|
---|
[7653] | 97 | strcat(indent2," ");
|
---|
| 98 |
|
---|
| 99 | if (style->Size())
|
---|
| 100 | for (i=0; i<style->Size(); i++) {
|
---|
[15104] | 101 | if(flag) _printf0_(indent << " style: -------- begin [" << i << "] --------\n");
|
---|
[7653] | 102 | ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2);
|
---|
[15104] | 103 | if(flag) _printf0_(indent << " style: -------- end [" << i << "] --------\n");
|
---|
[7653] | 104 | }
|
---|
| 105 | else
|
---|
[15104] | 106 | if(flag) _printf0_(indent << " style: [empty]\n");
|
---|
[7653] | 107 |
|
---|
| 108 | return;
|
---|
| 109 | }
|
---|
| 110 | /*}}}*/
|
---|
[18063] | 111 | void KML_Feature::Write(FILE* filout,const char* indent){/*{{{*/
|
---|
[7653] | 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 |
|
---|
[9336] | 131 | memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
|
---|
| 132 |
|
---|
[7653] | 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 | /*}}}*/
|
---|
[18063] | 141 | void KML_Feature::Read(FILE* fid,char* kstr){/*{{{*/
|
---|
[8207] | 142 |
|
---|
| 143 | KML_Object* kobj;
|
---|
| 144 |
|
---|
| 145 | /* process field within opening and closing tags */
|
---|
| 146 |
|
---|
| 147 | if (!strncmp(kstr,"</Feature", 9))
|
---|
[8208] | 148 | return;
|
---|
[8207] | 149 | else if (!strncmp(kstr,"</",2))
|
---|
[13056] | 150 | {_error_("KML_Feature::Read -- Unexpected closing tag " << kstr);}
|
---|
[8207] | 151 | else if (strncmp(kstr,"<",1))
|
---|
[13056] | 152 | {_error_("KML_Feature::Read -- Unexpected field \"" << kstr << "\"");}
|
---|
[8207] | 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>"))
|
---|
[12493] | 161 | KMLFileTokenParse( name ,NULL,KML_FEATURE_NAME_LENGTH, kstr, fid);
|
---|
[8207] | 162 | else if (!strcmp(kstr,"<visibility>"))
|
---|
[12493] | 163 | KMLFileTokenParse(&visibility, kstr, fid);
|
---|
[8207] | 164 | else if (!strcmp(kstr,"<open>"))
|
---|
[12493] | 165 | KMLFileTokenParse(&open , kstr, fid);
|
---|
[8207] | 166 | else if (!strncmp(kstr,"<snippet", 8))
|
---|
[12493] | 167 | KMLFileTokenParse( snippet ,NULL,KML_FEATURE_SNIPPET_LENGTH, kstr, fid);
|
---|
[8207] | 168 | else if (!strcmp(kstr,"<description>"))
|
---|
[12493] | 169 | KMLFileTokenParse( descript ,NULL,KML_FEATURE_DESCRIPT_LENGTH, kstr, fid);
|
---|
[8207] | 170 | else if (!strcmp(kstr,"<styleUrl>"))
|
---|
[12493] | 171 | KMLFileTokenParse( styleurl ,NULL,KML_FEATURE_STYLEURL_LENGTH, kstr, fid);
|
---|
[8207] | 172 |
|
---|
| 173 | else if (!strncmp(kstr,"<",1))
|
---|
| 174 | KML_Object::Read(fid,kstr);
|
---|
| 175 |
|
---|
[8208] | 176 | return;
|
---|
[8207] | 177 | }
|
---|
| 178 | /*}}}*/
|
---|