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