Changeset 8461


Ignore:
Timestamp:
06/01/11 09:13:35 (14 years ago)
Author:
jschierm
Message:

KML: Addition of KMLFileRead module and KML_Attribute class, along with many other changes during freeze.

Location:
issm/trunk/src/c
Files:
4 added
29 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/Makefile.am

    r8429 r8461  
    7777                                        ./objects/Bamg/Mesh.cpp\
    7878                                        ./objects/Bamg/Mesh.h\
     79                                        ./objects/KML/KML_Attribute.cpp\
     80                                        ./objects/KML/KML_Attribute.h\
    7981                                        ./objects/KML/KML_ColorStyle.cpp\
    8082                                        ./objects/KML/KML_ColorStyle.h\
     
    508510                                        ./modules/MinVzx/MinVzx.h\
    509511                                        ./modules/MinVzx/MinVzx.cpp\
     512                                        ./modules/KMLMeshWritex/KMLFileReadx.h\
     513                                        ./modules/KMLMeshWritex/KMLFileReadx.cpp\
    510514                                        ./modules/KMLMeshWritex/KMLMeshWritex.h\
    511515                                        ./modules/KMLMeshWritex/KMLMeshWritex.cpp\
     
    730734                                        ./objects/Gauss/GaussPenta.h\
    731735                                        ./objects/Gauss/GaussPenta.cpp\
     736                                        ./objects/KML/KML_Attribute.cpp\
     737                                        ./objects/KML/KML_Attribute.h\
    732738                                        ./objects/KML/KML_ColorStyle.cpp\
    733739                                        ./objects/KML/KML_ColorStyle.h\
     
    11491155                                        ./modules/MinVzx/MinVzx.h\
    11501156                                        ./modules/MinVzx/MinVzx.cpp\
     1157                                        ./modules/KMLMeshWritex/KMLFileReadx.h\
     1158                                        ./modules/KMLMeshWritex/KMLFileReadx.cpp\
    11511159                                        ./modules/KMLMeshWritex/KMLMeshWritex.h\
    11521160                                        ./modules/KMLMeshWritex/KMLMeshWritex.cpp\
  • issm/trunk/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp

    r8303 r8461  
    2424        double  popac=0.50;
    2525        char    indent[81]="  ";
     26        char    cstr[81];
    2627        double* edata=NULL;
    2728        bool    ncfree=false,
     
    5960        sprintf(kpsty->colormode ,"random");
    6061        kstyle=new KML_Style();
    61         sprintf(kstyle->id        ,"BlackLineRandomPoly");
     62        kstyle->AddAttrib("id","BlackLineRandomPoly");
    6263        kstyle->line      =klsty;
    6364        kstyle->poly      =kpsty;
     
    7273        sprintf(kpsty->colormode ,"random");
    7374        kstyle=new KML_Style();
    74         sprintf(kstyle->id        ,"BlackLineEmptyPoly");
     75        kstyle->AddAttrib("id","BlackLineEmptyPoly");
    7576        kstyle->line      =klsty;
    7677        kstyle->poly      =kpsty;
     
    8586        sprintf(kpsty->colormode ,"random");
    8687        kstyle=new KML_Style();
    87         sprintf(kstyle->id        ,"RedLineRedPoly");
     88        kstyle->AddAttrib("id","RedLineRedPoly");
    8889        kstyle->line      =klsty;
    8990        kstyle->poly      =kpsty;
     
    106107                        sprintf(kpsty->colormode ,"normal");
    107108                        kstyle=new KML_Style();
    108                         sprintf(kstyle->id        ,"MatlabColor%d",i+1);
     109                        sprintf(cstr,"MatlabColor%d",i+1);
     110                        kstyle->AddAttrib("id",cstr);
    109111                        kstyle->line      =klsty;
    110112                        kstyle->poly      =kpsty;
  • issm/trunk/src/c/modules/KMLMeshWritex/KMLMeshWritex.h

    r7670 r8461  
    33 */
    44
    5 #ifndef _KMLMeshWriteX_H
    6 #define _KMLMeshWriteX_H
     5#ifndef _KMLMESHWRITEX_H
     6#define _KMLMESHWRITEX_H
    77
    88#include <float.h>    /*  DBL_MAX  */
     
    2828                                                double* cmap, int mcmap, int ncmap);
    2929
    30 #endif  /* _KMLMeshWriteX_H */
     30#endif  /* _KMLMESHWRITEX_H */
  • issm/trunk/src/c/modules/modules.h

    r8404 r8461  
    4949#include "./InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.h"
    5050#include "./InputArtificialNoisex/InputArtificialNoisex.h"
     51#include "./KMLMeshWritex/KMLFileReadx.h"
    5152#include "./KMLMeshWritex/KMLMeshWritex.h"
    5253#include "./MassFluxx/MassFluxx.h"
  • issm/trunk/src/c/objects/KML/KMLFileReadUtils.cpp

    r8206 r8461  
    9494                }
    9595
    96         if      (itag)
    97                 _printf_(true,"tag buffer (length=%d):\n",ibuf);
    98         else if (ifield)
    99                 _printf_(true,"field buffer (length=%d):\n",ibuf);
    100         _printf_(true,"%s\n",buffer);
     96//      if      (itag)
     97//              _printf_(true,"tag buffer (length=%d):\n",ibuf);
     98//      else if (ifield)
     99//              _printf_(true,"field buffer (length=%d):\n",ibuf);
     100//      _printf_(true,"%s\n",buffer);
    101101
    102102        if (!ibuf)
     
    131131
    132132/*FUNCTION  KMLFileTagAttrib {{{1*/
    133 char* KMLFileTagAttrib(char* pstr,int *m,int maxlen,
    134                                            char* ktag,
    135                                            char* att){
     133void KMLFileTagAttrib(KML_Object* kobj,
     134                                          char* ktag){
    136135
    137136        char*   ktagi;
    138         char*   ktok;
     137        char*   ktokn;
     138        char*   ktokv;
    139139        char    quote[]={'\"','\0'};
    140         char*   pstro=NULL;
    141 
    142         if (pstr)
    143                 (pstr)[0]='\0';
    144 
    145 /*  ktok modifies ktag, so work on copy  */
     140
     141/*  strtok modifies ktag, so work on copy  */
    146142
    147143        ktagi=(char *) xmalloc((strlen(ktag)+1)*sizeof(char));
     
    150146/*  loop through tag to find all attributes  */
    151147
    152         ktok=strtok(ktagi," ");
    153         while (ktok=strtok(NULL," =?>")) {
    154                 _printf_(true,"KMLFileTagAttrib -- attribute %s",ktok);
    155 
    156 /*  check if it's the specified attribute  */
    157 
    158                 if (!strcmp(ktok,att)) {
    159                         ktok=strtok(NULL,quote);
    160                         _printf_(true,"=\"%s\" found.\n",ktok);
    161 
    162                         if (!pstr) {
    163                                 pstr=(char *) xmalloc((strlen(ktok)+1)*sizeof(char));
    164                                 pstro=pstr;
    165                         }
    166 
    167                         if (maxlen && (maxlen < strlen(ktok))) {
    168                                 _printf_(true,"KMLFileTagAttrib -- string field too short for attribute \"%s\".\n",att);
    169                                 _printf_(true,"KMLFileTagAttrib -- \"%s\" truncated to %d characters.\n",ktok,maxlen);
    170                                 strncpy(pstr,ktok,maxlen);
    171                         }
    172                         else
    173                                 strcpy(pstr,ktok);
    174                 }
    175                 else {
    176                         ktok=strtok(NULL,quote);
    177                         _printf_(true,"=\"%s\" skipped.\n",ktok);
    178                 }
     148        ktokn=strtok(ktagi," ");
     149        while (ktokn=strtok(NULL," =?>")) {
     150
     151                ktokv=strtok(NULL,quote);
     152                _printf_(true,"KMLFileTagAttrib -- attribute %s=\"%s\".\n",ktokn,ktokv);
     153
     154/*  add the attribute to the dataset  */
     155
     156                if (kobj)
     157                        kobj->AddAttrib(ktokn,ktokv);
    179158        }
    180159
    181160        xfree((void**)&ktagi);
    182161
    183         if (pstr && m)
    184                 *m=strlen(pstr);
    185 
    186         if (pstr)
    187                 _printf_(true,"KMLFileTagAttrib -- attribute %s=\"%s\".\n",att,pstr);
    188         else
    189                 _printf_(true,"KMLFileTagAttrib -- attribute \"%s\" not found.\n",att);
    190 
    191         return(pstro);
     162        return;
    192163}
    193164/*}}}*/
     
    220191                        xfree((void**)&kstr);
    221192
    222         _printf_(true,"KMLFileTokenParse -- %s=%d.\n",ktag,*pival);
     193//      _printf_(true,"KMLFileTokenParse -- %s=%d.\n",ktag,*pival);
    223194
    224195        return(0);
     
    255226                        xfree((void**)&kstr);
    256227
    257         _printf_(true,"KMLFileTokenParse -- %s=%s.\n",ktag,(*pbval ? "true" : "false"));
     228//      _printf_(true,"KMLFileTokenParse -- %s=%s.\n",ktag,(*pbval ? "true" : "false"));
    258229
    259230        return(0);
     
    306277                        xfree((void**)&kstr);
    307278
    308         _printf_(true,"KMLFileTokenParse -- %s=\"%s\".\n",ktag,pstr);
     279//      _printf_(true,"KMLFileTokenParse -- %s=\"%s\".\n",ktag,pstr);
    309280
    310281        return(pstro);
     282}
     283/*}}}*/
     284
     285/*FUNCTION  KMLFileTokenParse {{{1*/
     286int KMLFileTokenParse(float* pfval,
     287                                          char* ktag,
     288                                          FILE* fid){
     289
     290        char*   kstr;
     291
     292/*  get next token and convert to appropriate format  */
     293
     294        if (!(kstr=KMLFileToken(fid)) ||
     295                (kstr[0] == '<'))
     296                _error_("KMLFileTokenParse -- Missing integer field for %s.\n",ktag);
     297
     298        sscanf(kstr,"%g",pfval);
     299        xfree((void**)&kstr);
     300
     301/*  get additional token and compare to closing tag  */
     302
     303        if (ktag)
     304                if (!(kstr=KMLFileToken(fid)) ||
     305                        (kstr[0] != '<') ||
     306                        (kstr[1] != '/') ||
     307                        (strncmp(&(kstr[2]),&(ktag[1]),strlen(ktag)-1)))
     308                        _error_("KMLFileTokenParse -- Missing closing tag for %s.\n",ktag);
     309                else
     310                        xfree((void**)&kstr);
     311
     312//      _printf_(true,"KMLFileTokenParse -- %s=%g.\n",ktag,*pfval);
     313
     314        return(0);
    311315}
    312316/*}}}*/
     
    370374                        xfree((void**)&kstr);
    371375
    372         _printf_(true,"KMLFileTokenParse -- %s=...\n",ktag);
    373         for (j=0; j<=i; j++)
    374                 _printf_(true,"   [%d][0-2]: %g,%g,%g\n",j,(*pdval3)[j][0],(*pdval3)[j][1],(*pdval3)[j][2]);
     376//      _printf_(true,"KMLFileTokenParse -- %s=...\n",ktag);
     377//      for (j=0; j<=i; j++)
     378//              _printf_(true,"   [%d][0-2]: %g,%g,%g\n",j,(*pdval3)[j][0],(*pdval3)[j][1],(*pdval3)[j][2]);
    375379
    376380        return(0);
  • issm/trunk/src/c/objects/KML/KMLFileReadUtils.h

    r8206 r8461  
    1919                                                int c,
    2020                                                int bufblk);
    21 char* KMLFileTagAttrib(char* pstr,int *m,int maxlen,
    22                                            char* ktag,
    23                                            char* att);
     21void KMLFileTagAttrib(KML_Object* kobj,
     22                                          char* ktag);
    2423int KMLFileTokenParse(int* pint,
    2524                                          char* ktag,
     
    2928                                          FILE* fid);
    3029char* KMLFileTokenParse(char* pstr,int *m,int maxlen,
     30                                          char* ktag,
     31                                          FILE* fid);
     32int KMLFileTokenParse(float* pfl,
    3133                                          char* ktag,
    3234                                          FILE* fid);
  • issm/trunk/src/c/objects/KML/KML_ColorStyle.cpp

    r8293 r8461  
    9595/*  process field within opening and closing tags  */
    9696
    97         if      (!strncmp(kstr,"</ColorStyle",11))
     97        if      (!strncmp(kstr,"</ColorStyle",12))
    9898                return;
    9999        else if (!strncmp(kstr,"</",2))
  • issm/trunk/src/c/objects/KML/KML_Container.cpp

    r8293 r8461  
    7979        if (feature->Size())
    8080                for (i=0; i<feature->Size(); i++) {
    81                         _printf_(flag,"%s       feature: [%d] begin\n" ,indent,i);
     81                        _printf_(flag,"%s       feature: -------- begin [%d] --------\n" ,indent,i);
    8282                        ((KML_Feature *)feature->GetObjectByOffset(i))->DeepEcho(indent2);
    83                         _printf_(flag,"%s       feature: [%d] end\n"  ,indent,i);
     83                        _printf_(flag,"%s       feature: --------  end  [%d] --------\n" ,indent,i);
    8484                }
    8585        else
  • issm/trunk/src/c/objects/KML/KML_Container.h

    r8293 r8461  
    1313
    1414#include "./KML_Feature.h"
     15class DataSet;
    1516/*}}}*/
    1617
  • issm/trunk/src/c/objects/KML/KML_Document.cpp

    r8293 r8461  
    7474void  KML_Document::Write(FILE* filout,char* indent){
    7575
    76         if (this->id && strlen(this->id))
    77                 fprintf(filout,"%s<Document id=\"%s\">\n",indent,this->id);
    78         else
    79                 fprintf(filout,"%s<Document>\n",indent);
     76        fprintf(filout,"%s<Document",indent);
     77        WriteAttrib(filout," ");
     78        fprintf(filout,">\n");
    8079
    8180        KML_Container::Write(filout,indent);
     
    9291        char*        kstri;
    9392
    94 /*  check for id attribute  */
     93/*  get object attributes  */
    9594
    96 //      KML_Object::Read(fid,kstr);
    97         KMLFileTagAttrib( id        ,NULL,KML_OBJECT_ID_LENGTH,
    98                                          kstr,
    99                                          "id");
     95        KMLFileTagAttrib(this,
     96                                         kstr);
    10097
    10198/*  loop over and process fields within opening and closing tags  */
  • issm/trunk/src/c/objects/KML/KML_Document.h

    r8293 r8461  
    1414#include "./KML_Container.h"
    1515class KML_Feature;
    16 class DataSet;
    1716/*}}}*/
    1817
  • issm/trunk/src/c/objects/KML/KML_Feature.cpp

    r8293 r8461  
    9898        if (style->Size())
    9999                for (i=0; i<style->Size(); i++) {
    100                         _printf_(flag,"%s         style: [%d] begin\n" ,indent,i);
     100                        _printf_(flag,"%s         style: -------- begin [%d] --------\n" ,indent,i);
    101101                        ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2);
    102                         _printf_(flag,"%s         style: [%d] end\n"  ,indent,i);
     102                        _printf_(flag,"%s         style: --------  end  [%d] --------\n" ,indent,i);
    103103                }
    104104        else
  • issm/trunk/src/c/objects/KML/KML_Folder.cpp

    r8293 r8461  
    7474void  KML_Folder::Write(FILE* filout,char* indent){
    7575
    76         int   i;
    77 
    78         if (this->id && strlen(this->id))
    79                 fprintf(filout,"%s<Folder id=\"%s\">\n",indent,this->id);
    80         else
    81                 fprintf(filout,"%s<Folder>\n",indent);
     76        fprintf(filout,"%s<Folder",indent);
     77        WriteAttrib(filout," ");
     78        fprintf(filout,">\n");
    8279
    8380        KML_Container::Write(filout,indent);
     
    9491        char*        kstri;
    9592
    96 /*  check for id attribute  */
     93/*  get object attributes  */
    9794
    98 //      KML_Object::Read(fid,kstr);
    99         KMLFileTagAttrib( id        ,NULL,KML_OBJECT_ID_LENGTH,
    100                                          kstr,
    101                                          "id");
     95        KMLFileTagAttrib(this,
     96                                         kstr);
    10297
    10398/*  loop over and process fields within opening and closing tags  */
  • issm/trunk/src/c/objects/KML/KML_Folder.h

    r8293 r8461  
    1414#include "./KML_Container.h"
    1515class KML_Feature;
    16 class DataSet;
    1716/*}}}*/
    1817
  • issm/trunk/src/c/objects/KML/KML_Geometry.cpp

    r8293 r8461  
    7777void  KML_Geometry::Read(FILE* fid,char* kstr){
    7878
    79         KML_Object::Read(fid,kstr);
     79/*  process field within opening and closing tags  */
     80
     81        if      (!strncmp(kstr,"</Geometry",10))
     82                return;
     83        else if (!strncmp(kstr,"</",2))
     84                _error_("KML_Geometry::Read -- Unexpected closing tag %s.\n",kstr);
     85        else if (strncmp(kstr,"<",1))
     86                _error_("KML_Geometry::Read -- Unexpected field \"%s\".\n",kstr);
     87
     88        else if (!strncmp(kstr,"<",1))
     89                KML_Object::Read(fid,kstr);
    8090
    8191        return;
  • issm/trunk/src/c/objects/KML/KML_LineString.cpp

    r8293 r8461  
    9797        int   i;
    9898
    99         if (this->id && strlen(this->id))
    100                 fprintf(filout,"%s<LineString id=\"%s\">\n",indent,this->id);
    101         else
    102                 fprintf(filout,"%s<LineString>\n",indent);
     99        fprintf(filout,"%s<LineString",indent);
     100        WriteAttrib(filout," ");
     101        fprintf(filout,">\n");
    103102
    104103        KML_Geometry::Write(filout,indent);
     
    125124void  KML_LineString::Read(FILE* fid,char* kstr){
    126125
     126        char*        kstri;
     127
     128/*  get object attributes  */
     129
     130        KMLFileTagAttrib(this,
     131                                         kstr);
     132
     133/*  loop over and process fields within opening and closing tags  */
     134
     135        while (kstri=KMLFileToken(fid)) {
     136                if      (!strncmp(kstri,"</LineString",12)) {
     137                        xfree((void**)&kstri);
     138                        break;
     139                }
     140                else if (!strncmp(kstri,"</",2))
     141                        _error_("KML_LineString::Read -- Unexpected closing tag %s.\n",kstri);
     142                else if (strncmp(kstri,"<",1))
     143                        _error_("KML_LineString::Read -- Unexpected field \"%s\".\n",kstri);
     144
     145                else if (!strcmp(kstri,"<extrude>"))
     146                        KMLFileTokenParse(&extrude   ,
     147                                                          kstri,
     148                                                          fid);
     149                else if (!strcmp(kstri,"<tessellate>"))
     150                        KMLFileTokenParse(&tessellate,
     151                                                          kstri,
     152                                                          fid);
     153                else if (!strcmp(kstri,"<altitudeMode>"))
     154                        KMLFileTokenParse( altmode   ,NULL,KML_LINESTRING_ALTMODE_LENGTH,
     155                                                          kstri,
     156                                                          fid);
     157                else if (!strcmp(kstri,"<coordinates>"))
     158                        KMLFileTokenParse(&coords    ,&ncoord    ,0,
     159                                                          kstri,
     160                                                          fid);
     161
     162                else if (!strncmp(kstri,"<",1))
     163                        KML_Geometry::Read(fid,kstri);
     164
     165                xfree((void**)&kstri);
     166        }
    127167
    128168        return;
  • issm/trunk/src/c/objects/KML/KML_LineStyle.cpp

    r8293 r8461  
    2323KML_LineStyle::KML_LineStyle(){
    2424
    25         width     =1;
     25        width     =1.;
    2626
    2727}
     
    4444        KML_ColorStyle::Echo();
    4545
    46         _printf_(flag,"         width: %d\n"          ,width);
     46        _printf_(flag,"         width: %g\n"          ,width);
    4747
    4848        return;
     
    7070        KML_ColorStyle::DeepEcho(indent);
    7171
    72         _printf_(flag,"%s         width: %d\n"          ,indent,width);
     72        _printf_(flag,"%s         width: %g\n"          ,indent,width);
    7373
    7474        return;
     
    7979void  KML_LineStyle::Write(FILE* filout,char* indent){
    8080
    81         int   i;
    82 
    83         if (this->id && strlen(this->id))
    84                 fprintf(filout,"%s<LineStyle id=\"%s\">\n",indent,this->id);
    85         else
    86                 fprintf(filout,"%s<LineStyle>\n",indent);
     81        fprintf(filout,"%s<LineStyle",indent);
     82        WriteAttrib(filout," ");
     83        fprintf(filout,">\n");
    8784
    8885        KML_ColorStyle::Write(filout,indent);
    8986
    90         fprintf(filout,"%s  <width>%d</width>\n",indent,width);
     87        fprintf(filout,"%s  <width>%g</width>\n",indent,width);
    9188
    9289        fprintf(filout,"%s</LineStyle>\n",indent);
     
    9996void  KML_LineStyle::Read(FILE* fid,char* kstr){
    10097
     98        char*        kstri;
     99
     100/*  get object attributes  */
     101
     102        KMLFileTagAttrib(this,
     103                                         kstr);
     104
     105/*  loop over and process fields within opening and closing tags  */
     106
     107        while (kstri=KMLFileToken(fid)) {
     108                if      (!strncmp(kstri,"</LineStyle",11)) {
     109                        xfree((void**)&kstri);
     110                        break;
     111                }
     112                else if (!strncmp(kstri,"</",2))
     113                        _error_("KML_LineStyle::Read -- Unexpected closing tag %s.\n",kstri);
     114                else if (strncmp(kstri,"<",1))
     115                        _error_("KML_LineStyle::Read -- Unexpected field \"%s\".\n",kstri);
     116
     117                else if (!strcmp(kstri,"<width>"))
     118                        KMLFileTokenParse(&width     ,
     119                                                          kstri,
     120                                                          fid);
     121
     122                else if (!strncmp(kstri,"<",1))
     123                        KML_ColorStyle::Read(fid,kstri);
     124
     125                xfree((void**)&kstri);
     126        }
    101127
    102128        return;
  • issm/trunk/src/c/objects/KML/KML_LineStyle.h

    r8293 r8461  
    1919        public:
    2020
    21                 int  width;
     21                float width;
    2222
    2323                /*KML_LineStyle constructors, destructors {{{1*/
  • issm/trunk/src/c/objects/KML/KML_LinearRing.cpp

    r8293 r8461  
    9797        int   i;
    9898
    99         if (this->id && strlen(this->id))
    100                 fprintf(filout,"%s<LinearRing id=\"%s\">\n",indent,this->id);
    101         else
    102                 fprintf(filout,"%s<LinearRing>\n",indent);
     99        fprintf(filout,"%s<LinearRing",indent);
     100        WriteAttrib(filout," ");
     101        fprintf(filout,">\n");
    103102
    104103        KML_Geometry::Write(filout,indent);
     
    125124void  KML_LinearRing::Read(FILE* fid,char* kstr){
    126125
     126        char*        kstri;
     127
     128/*  get object attributes  */
     129
     130        KMLFileTagAttrib(this,
     131                                         kstr);
     132
     133/*  loop over and process fields within opening and closing tags  */
     134
     135        while (kstri=KMLFileToken(fid)) {
     136                if      (!strncmp(kstri,"</LinearRing",12)) {
     137                        xfree((void**)&kstri);
     138                        break;
     139                }
     140                else if (!strncmp(kstri,"</",2))
     141                        _error_("KML_LinearRing::Read -- Unexpected closing tag %s.\n",kstri);
     142                else if (strncmp(kstri,"<",1))
     143                        _error_("KML_LinearRing::Read -- Unexpected field \"%s\".\n",kstri);
     144
     145                else if (!strcmp(kstri,"<extrude>"))
     146                        KMLFileTokenParse(&extrude   ,
     147                                                          kstri,
     148                                                          fid);
     149                else if (!strcmp(kstri,"<tessellate>"))
     150                        KMLFileTokenParse(&tessellate,
     151                                                          kstri,
     152                                                          fid);
     153                else if (!strcmp(kstri,"<altitudeMode>"))
     154                        KMLFileTokenParse( altmode   ,NULL,KML_LINEARRING_ALTMODE_LENGTH,
     155                                                          kstri,
     156                                                          fid);
     157                else if (!strcmp(kstri,"<coordinates>"))
     158                        KMLFileTokenParse(&coords    ,&ncoord    ,0,
     159                                                          kstri,
     160                                                          fid);
     161
     162                else if (!strncmp(kstri,"<",1))
     163                        KML_Geometry::Read(fid,kstri);
     164
     165                xfree((void**)&kstri);
     166        }
    127167
    128168        return;
  • issm/trunk/src/c/objects/KML/KML_MultiGeometry.cpp

    r8293 r8461  
    8181        if (geometry->Size())
    8282                for (i=0; i<geometry->Size(); i++) {
    83                         _printf_(flag,"%s      geometry: [%d] begin\n" ,indent,i);
     83                        _printf_(flag,"%s      geometry: -------- begin [%d] --------\n" ,indent,i);
    8484                        ((KML_Geometry *)geometry->GetObjectByOffset(i))->DeepEcho(indent2);
    85                         _printf_(flag,"%s      geometry: [%d] end\n"  ,indent,i);
     85                        _printf_(flag,"%s      geometry: --------  end  [%d] --------\n" ,indent,i);
    8686                }
    8787        else
     
    9898        char  indent2[81];
    9999
    100         if (this->id && strlen(this->id))
    101                 fprintf(filout,"%s<MultiGeometry id=\"%s\">\n",indent,this->id);
    102         else
    103                 fprintf(filout,"%s<MultiGeometry>\n",indent);
     100        fprintf(filout,"%s<MultiGeometry",indent);
     101        WriteAttrib(filout," ");
     102        fprintf(filout,">\n");
    104103
    105104        KML_Geometry::Write(filout,indent);
     
    122121void  KML_MultiGeometry::Read(FILE* fid,char* kstr){
    123122
     123        char*        kstri;
     124        KML_Object*  kobj;
     125
     126/*  get object attributes  */
     127
     128        KMLFileTagAttrib(this,
     129                                         kstr);
     130
     131/*  loop over and process fields within opening and closing tags  */
     132
     133        while (kstri=KMLFileToken(fid)) {
     134                if      (!strncmp(kstri,"</MultiGeometry",15)) {
     135                        xfree((void**)&kstri);
     136                        break;
     137                }
     138                else if (!strncmp(kstri,"</",2))
     139                        _error_("KML_MultiGeometry::Read -- Unexpected closing tag %s.\n",kstri);
     140                else if (strncmp(kstri,"<",1))
     141                        _error_("KML_MultiGeometry::Read -- Unexpected field \"%s\".\n",kstri);
     142
     143//              else if (!strncmp(kstri,"<Point", 6)) {
     144//                      kobj=(KML_Object*)new KML_Point();
     145//                      kobj->Read(fid,kstri);
     146//                      geometry  ->AddObject((Object*)kobj);
     147//              }
     148
     149                else if (!strncmp(kstri,"<LineString",11)) {
     150                        kobj=(KML_Object*)new KML_LineString();
     151                        kobj->Read(fid,kstri);
     152                        geometry  ->AddObject((Object*)kobj);
     153                }
     154
     155                else if (!strncmp(kstri,"<LinearRing",11)) {
     156                        kobj=(KML_Object*)new KML_LinearRing();
     157                        kobj->Read(fid,kstri);
     158                        geometry  ->AddObject((Object*)kobj);
     159                }
     160
     161                else if (!strncmp(kstri,"<Polygon", 8)) {
     162                        kobj=(KML_Object*)new KML_Polygon();
     163                        kobj->Read(fid,kstri);
     164                        geometry  ->AddObject((Object*)kobj);
     165                }
     166
     167                else if (!strncmp(kstri,"<MultiGeometry",14)) {
     168                        kobj=(KML_Object*)new KML_MultiGeometry();
     169                        kobj->Read(fid,kstri);
     170                        geometry  ->AddObject((Object*)kobj);
     171                }
     172
     173                else if (!strncmp(kstri,"<",1))
     174                        KML_Geometry::Read(fid,kstri);
     175
     176                xfree((void**)&kstri);
     177        }
    124178
    125179        return;
  • issm/trunk/src/c/objects/KML/KML_Object.cpp

    r8293 r8461  
    2323KML_Object::KML_Object(){
    2424
    25         strcpy(id        ,"");
     25        attrib    =new DataSet;
    2626
    2727}
     
    3030KML_Object::~KML_Object(){
    3131
    32         ;
     32        if (attrib) {
     33                delete attrib;
     34                attrib    =NULL;
     35        }
    3336
    3437}
     
    4144        bool  flag=true;
    4245
    43         _printf_(flag,"            id: \"%s\"\n"      ,id);
     46        _printf_(flag,"        attrib: (size=%d)\n" ,attrib->Size());
    4447
    4548        return;
     
    6164void  KML_Object::DeepEcho(char* indent){
    6265
     66        int   i;
    6367        bool  flag=true;
    6468
    65         _printf_(flag,"%s            id: \"%s\"\n"      ,indent,id);
     69/*  loop over the attributes for the object  */
     70
     71        if (attrib->Size())
     72                for (i=0; i<attrib->Size(); i++) {
     73                        ((KML_Attribute *)attrib->GetObjectByOffset(i))->DeepEcho(indent);
     74                }
     75        else
     76                _printf_(flag,"%s        attrib: [empty]\n"    ,indent);
    6677
    6778        return;
     
    7283void  KML_Object::Write(FILE* filout,char* indent){
    7384
    74 //  id is always written in keyword line of derived classes
     85//  attributes always written in keyword line of derived classes
    7586
    7687        ;
     
    102113/*}}}*/
    103114
     115/*FUNCTION KML_Object::AddAttrib {{{1*/
     116void  KML_Object::AddAttrib(char* name,char* value){
     117
     118        KML_Attribute* katt=NULL;
     119
     120        katt=new KML_Attribute();
     121        katt->Alloc(name,value);
     122        katt->Add(attrib);
     123
     124        return;
     125}
     126/*}}}*/
     127
     128/*FUNCTION KML_Object::FindAttrib {{{1*/
     129void  KML_Object::FindAttrib(char** pvalue,char* name,char* deflt){
     130
     131        int   i;
     132        KML_Attribute* katt=NULL;
     133
     134/*  loop over any attributes for the object  */
     135
     136        if (attrib->Size())
     137                for (i=0; i<attrib->Size(); i++)
     138                        if (!strcmp(((KML_Attribute *)attrib->GetObjectByOffset(i))->name,name)) {
     139                                katt=(KML_Attribute *)attrib->GetObjectByOffset(i);
     140                                break;
     141                        }
     142
     143        if (katt)
     144                katt->Get(pvalue,deflt);
     145        else {
     146                *pvalue=(char *) xmalloc((strlen(deflt)+1)*sizeof(char));
     147                strcpy(*pvalue,deflt);
     148        }
     149
     150        return;
     151}
     152/*}}}*/
     153
     154/*FUNCTION KML_Object::WriteAttrib {{{1*/
     155void  KML_Object::WriteAttrib(FILE* filout,char* indent){
     156
     157        int   i;
     158
     159//  attributes always written in keyword line of kml_object
     160
     161/*  loop over any attributes for the object  */
     162
     163        if (attrib->Size())
     164                for (i=0; i<attrib->Size(); i++)
     165                        ((KML_Attribute *)attrib->GetObjectByOffset(i))->Write(filout,indent);
     166
     167        return;
     168}
     169/*}}}*/
     170
  • issm/trunk/src/c/objects/KML/KML_Object.h

    r8293 r8461  
    66#define _KML_OBJECT_H_
    77
    8 #define KML_OBJECT_ID_LENGTH         80
    9 
    108/*Headers:{{{1*/
    119#include "../../include/include.h"
     
    1412
    1513#include "../Object.h"
     14class DataSet;
    1615/*}}}*/
    1716
     
    2019        public:
    2120
    22                 char  id[KML_OBJECT_ID_LENGTH+1];
     21                DataSet* attrib;
    2322
    2423                /*KML_Object constructors, destructors {{{1*/
     
    4241                virtual void  Write(FILE* fid,char* indent)=0;
    4342                virtual void  Read(FILE* fid,char* kstr)=0;
    44 
     43                virtual void  AddAttrib(char* name,char* value);
     44                virtual void  FindAttrib(char** pvalue,char* name,char* deflt);
     45                virtual void  WriteAttrib(FILE* fid,char* indent);
    4546
    4647};
  • issm/trunk/src/c/objects/KML/KML_Placemark.cpp

    r8293 r8461  
    8181        if (geometry->Size())
    8282                for (i=0; i<geometry->Size(); i++) {
    83                         _printf_(flag,"%s      geometry: [%d] begin\n" ,indent,i);
     83                        _printf_(flag,"%s      geometry: -------- begin [%d] --------\n" ,indent,i);
    8484                        ((KML_Geometry *)geometry->GetObjectByOffset(i))->DeepEcho(indent2);
    85                         _printf_(flag,"%s      geometry: [%d] end\n"  ,indent,i);
     85                        _printf_(flag,"%s      geometry: --------  end  [%d] --------\n" ,indent,i);
    8686                }
    8787        else
     
    9898        char  indent2[81];
    9999
    100         if (this->id && strlen(this->id))
    101                 fprintf(filout,"%s<Placemark id=\"%s\">\n",indent,this->id);
    102         else
    103                 fprintf(filout,"%s<Placemark>\n",indent);
     100        fprintf(filout,"%s<Placemark",indent);
     101        WriteAttrib(filout," ");
     102        fprintf(filout,">\n");
    104103
    105104        KML_Feature::Write(filout,indent);
     
    125124        KML_Object*  kobj;
    126125
    127 /*  check for id attribute  */
     126/*  get object attributes  */
    128127
    129 //      KML_Object::Read(fid,kstr);
    130         KMLFileTagAttrib( id        ,NULL,KML_OBJECT_ID_LENGTH,
    131                                          kstr,
    132                                          "id");
     128        KMLFileTagAttrib(this,
     129                                         kstr);
    133130
    134131/*  loop over and process fields within opening and closing tags  */
     
    144141                        _error_("KML_Placemark::Read -- Unexpected field \"%s\".\n",kstri);
    145142
     143//              else if (!strncmp(kstri,"<Point", 6)) {
     144//                      kobj=(KML_Object*)new KML_Point();
     145//                      kobj->Read(fid,kstri);
     146//                      geometry  ->AddObject((Object*)kobj);
     147//              }
     148
    146149                else if (!strncmp(kstri,"<LineString",11)) {
    147150                        kobj=(KML_Object*)new KML_LineString();
    148                         kobj->Read(fid,kstr);
     151                        kobj->Read(fid,kstri);
    149152                        geometry  ->AddObject((Object*)kobj);
    150153                }
     
    152155                else if (!strncmp(kstri,"<LinearRing",11)) {
    153156                        kobj=(KML_Object*)new KML_LinearRing();
    154                         kobj->Read(fid,kstr);
     157                        kobj->Read(fid,kstri);
    155158                        geometry  ->AddObject((Object*)kobj);
    156159                }
     
    158161                else if (!strncmp(kstri,"<Polygon", 8)) {
    159162                        kobj=(KML_Object*)new KML_Polygon();
    160                         kobj->Read(fid,kstr);
     163                        kobj->Read(fid,kstri);
    161164                        geometry  ->AddObject((Object*)kobj);
    162165                }
     
    164167                else if (!strncmp(kstri,"<MultiGeometry",14)) {
    165168                        kobj=(KML_Object*)new KML_MultiGeometry();
    166                         kobj->Read(fid,kstr);
     169                        kobj->Read(fid,kstri);
    167170                        geometry  ->AddObject((Object*)kobj);
    168171                }
  • issm/trunk/src/c/objects/KML/KML_PolyStyle.cpp

    r8293 r8461  
    8282void  KML_PolyStyle::Write(FILE* filout,char* indent){
    8383
    84         int   i;
    85 
    86         if (this->id && strlen(this->id))
    87                 fprintf(filout,"%s<PolyStyle id=\"%s\">\n",indent,this->id);
    88         else
    89                 fprintf(filout,"%s<PolyStyle>\n",indent);
     84        fprintf(filout,"%s<PolyStyle",indent);
     85        WriteAttrib(filout," ");
     86        fprintf(filout,">\n");
    9087
    9188        KML_ColorStyle::Write(filout,indent);
     
    103100void  KML_PolyStyle::Read(FILE* fid,char* kstr){
    104101
     102        char*        kstri;
     103
     104/*  get object attributes  */
     105
     106        KMLFileTagAttrib(this,
     107                                         kstr);
     108
     109/*  loop over and process fields within opening and closing tags  */
     110
     111        while (kstri=KMLFileToken(fid)) {
     112                if      (!strncmp(kstri,"</PolyStyle",11)) {
     113                        xfree((void**)&kstri);
     114                        break;
     115                }
     116                else if (!strncmp(kstri,"</",2))
     117                        _error_("KML_PolyStyle::Read -- Unexpected closing tag %s.\n",kstri);
     118                else if (strncmp(kstri,"<",1))
     119                        _error_("KML_PolyStyle::Read -- Unexpected field \"%s\".\n",kstri);
     120
     121                else if (!strcmp(kstri,"<fill>"))
     122                        KMLFileTokenParse(&fill      ,
     123                                                          kstri,
     124                                                          fid);
     125                else if (!strcmp(kstri,"<outline>"))
     126                        KMLFileTokenParse(&outline   ,
     127                                                          kstri,
     128                                                          fid);
     129
     130                else if (!strncmp(kstri,"<",1))
     131                        KML_ColorStyle::Read(fid,kstri);
     132
     133                xfree((void**)&kstri);
     134        }
    105135
    106136        return;
  • issm/trunk/src/c/objects/KML/KML_Polygon.cpp

    r8293 r8461  
    9696        if (outer->Size())
    9797                for (i=0; i<outer->Size(); i++) {
    98                         _printf_(flag,"%s         outer: [%d] begin\n" ,indent,i);
     98                        _printf_(flag,"%s         outer: -------- begin [%d] --------\n" ,indent,i);
    9999                        ((KML_LinearRing *)outer->GetObjectByOffset(i))->DeepEcho(indent2);
    100                         _printf_(flag,"%s         outer: [%d] end\n"  ,indent,i);
     100                        _printf_(flag,"%s         outer: --------  end  [%d] --------\n" ,indent,i);
    101101                }
    102102        else
     
    105105        if (inner->Size())
    106106                for (i=0; i<inner->Size(); i++) {
    107                         _printf_(flag,"%s         inner: [%d] begin\n" ,indent,i);
     107                        _printf_(flag,"%s         inner: -------- begin [%d] --------\n" ,indent,i);
    108108                        ((KML_LinearRing *)inner->GetObjectByOffset(i))->DeepEcho(indent2);
    109                         _printf_(flag,"%s         inner: [%d] end\n"  ,indent,i);
     109                        _printf_(flag,"%s         inner: --------  end  [%d] --------\n" ,indent,i);
    110110                }
    111111        else
     
    122122        char  indent4[81];
    123123
    124         if (this->id && strlen(this->id))
    125                 fprintf(filout,"%s<Polygon id=\"%s\">\n",indent,this->id);
    126         else
    127                 fprintf(filout,"%s<Polygon>\n",indent);
     124        fprintf(filout,"%s<Polygon",indent);
     125        WriteAttrib(filout," ");
     126        fprintf(filout,">\n");
    128127
    129128        KML_Geometry::Write(filout,indent);
     
    158157void  KML_Polygon::Read(FILE* fid,char* kstr){
    159158
    160 
    161         return;
    162 }
    163 /*}}}*/
    164 
     159        char*        kstri;
     160        char*        kstrj;
     161        KML_Object*  kobj;
     162
     163/*  get object attributes  */
     164
     165        KMLFileTagAttrib(this,
     166                                         kstr);
     167
     168/*  loop over and process fields within opening and closing tags  */
     169
     170        while (kstri=KMLFileToken(fid)) {
     171                if      (!strncmp(kstri,"</Polygon", 9)) {
     172                        xfree((void**)&kstri);
     173                        break;
     174                }
     175                else if (!strncmp(kstri,"</",2))
     176                        _error_("KML_Polygon::Read -- Unexpected closing tag %s.\n",kstri);
     177                else if (strncmp(kstri,"<",1))
     178                        _error_("KML_Polygon::Read -- Unexpected field \"%s\".\n",kstri);
     179
     180                else if (!strcmp(kstri,"<extrude>"))
     181                        KMLFileTokenParse(&extrude   ,
     182                                                          kstri,
     183                                                          fid);
     184                else if (!strcmp(kstri,"<tessellate>"))
     185                        KMLFileTokenParse(&tessellate,
     186                                                          kstri,
     187                                                          fid);
     188                else if (!strcmp(kstri,"<altitudeMode>"))
     189                        KMLFileTokenParse( altmode   ,NULL,KML_POLYGON_ALTMODE_LENGTH,
     190                                                          kstri,
     191                                                          fid);
     192
     193                else if (!strcmp(kstri,"<outerBoundaryIs>"))
     194
     195/*  loop over and process fields within outer boundary  */
     196
     197                        while (kstrj=KMLFileToken(fid)) {
     198                                if      (!strncmp(kstrj,"</outerBoundaryIs",17)) {
     199                                        xfree((void**)&kstrj);
     200                                        break;
     201                                }
     202                                else if (!strncmp(kstrj,"</",2))
     203                                        _error_("KML_Polygon::Read -- Unexpected closing tag %s.\n",kstrj);
     204                                else if (strncmp(kstrj,"<",1))
     205                                        _error_("KML_Polygon::Read -- Unexpected field \"%s\".\n",kstrj);
     206
     207                                else if (!strncmp(kstrj,"<LinearRing",11)) {
     208                                        kobj=(KML_Object*)new KML_LinearRing();
     209                                        kobj->Read(fid,kstrj);
     210                                        outer     ->AddObject((Object*)kobj);
     211                                }
     212
     213                                else if (!strncmp(kstrj,"<",1))
     214                                        KML_Geometry::Read(fid,kstrj);
     215
     216                                xfree((void**)&kstrj);
     217                        }
     218
     219                else if (!strcmp(kstri,"<innerBoundaryIs>"))
     220
     221/*  loop over and process fields within inner boundaries  */
     222
     223                        while (kstrj=KMLFileToken(fid)) {
     224                                if      (!strncmp(kstrj,"</innerBoundaryIs",17)) {
     225                                        xfree((void**)&kstrj);
     226                                        break;
     227                                }
     228                                else if (!strncmp(kstrj,"</",2))
     229                                        _error_("KML_Polygon::Read -- Unexpected closing tag %s.\n",kstrj);
     230                                else if (strncmp(kstrj,"<",1))
     231                                        _error_("KML_Polygon::Read -- Unexpected field \"%s\".\n",kstrj);
     232
     233                                else if (!strncmp(kstrj,"<LinearRing",11)) {
     234                                        kobj=(KML_Object*)new KML_LinearRing();
     235                                        kobj->Read(fid,kstrj);
     236                                        inner     ->AddObject((Object*)kobj);
     237                                }
     238
     239                                else if (!strncmp(kstrj,"<",1))
     240                                        KML_Geometry::Read(fid,kstrj);
     241
     242                                xfree((void**)&kstrj);
     243                        }
     244
     245
     246                else if (!strncmp(kstri,"<",1))
     247                        KML_Geometry::Read(fid,kstri);
     248
     249                xfree((void**)&kstri);
     250        }
     251
     252        return;
     253}
     254/*}}}*/
     255
  • issm/trunk/src/c/objects/KML/KML_Style.cpp

    r8293 r8461  
    101101void  KML_Style::DeepEcho(char* indent){
    102102
    103         int   i;
    104103        char  indent2[81];
    105104        bool  flag=true;
     
    143142void  KML_Style::Write(FILE* filout,char* indent){
    144143
    145         int   i;
    146144        char  indent2[81];
    147145
    148         if (this->id && strlen(this->id))
    149                 fprintf(filout,"%s<Style id=\"%s\">\n",indent,this->id);
    150         else
    151                 fprintf(filout,"%s<Style>\n",indent);
     146        fprintf(filout,"%s<Style",indent);
     147        WriteAttrib(filout," ");
     148        fprintf(filout,">\n");
    152149
    153150        KML_StyleSelector::Write(filout,indent);
     
    178175void  KML_Style::Read(FILE* fid,char* kstr){
    179176
    180 
    181         return;
    182 }
    183 /*}}}*/
    184 
     177        char*        kstri;
     178
     179/*  get object attributes  */
     180
     181        KMLFileTagAttrib(this,
     182                                         kstr);
     183
     184/*  loop over and process fields within opening and closing tags  */
     185
     186        while (kstri=KMLFileToken(fid)) {
     187                if      (!strncmp(kstri,"</Style", 7)) {
     188                        xfree((void**)&kstri);
     189                        break;
     190                }
     191                else if (!strncmp(kstri,"</",2))
     192                        _error_("KML_Style::Read -- Unexpected closing tag %s.\n",kstri);
     193                else if (strncmp(kstri,"<",1))
     194                        _error_("KML_Style::Read -- Unexpected field \"%s\".\n",kstri);
     195
     196//              else if (!strncmp(kstri,"<IconStyle",10)) {
     197//                      icon      =new KML_IconStyle();
     198//                      icon      ->Read(fid,kstri);
     199//              }
     200
     201//              else if (!strncmp(kstri,"<LabelStyle",11)) {
     202//                      label     =new KML_LabelStyle();
     203//                      label     ->Read(fid,kstri);
     204//              }
     205
     206                else if (!strncmp(kstri,"<LineStyle",10)) {
     207                        line      =new KML_LineStyle();
     208                        line      ->Read(fid,kstri);
     209                }
     210
     211                else if (!strncmp(kstri,"<PolyStyle",10)) {
     212                        poly      =new KML_PolyStyle();
     213                        poly      ->Read(fid,kstri);
     214                }
     215
     216//              else if (!strncmp(kstri,"<BalloonStyle",13)) {
     217//                      balloon   =new KML_BalloonStyle();
     218//                      balloon   ->Read(fid,kstri);
     219//              }
     220
     221//              else if (!strncmp(kstri,"<ListStyle",10)) {
     222//                      list      =new KML_ListStyle();
     223//                      list      ->Read(fid,kstri);
     224//              }
     225
     226                else if (!strncmp(kstri,"<",1))
     227                        KML_StyleSelector::Read(fid,kstri);
     228
     229                xfree((void**)&kstri);
     230        }
     231
     232        return;
     233}
     234/*}}}*/
     235
  • issm/trunk/src/c/objects/KML/KML_StyleSelector.cpp

    r8293 r8461  
    7777void  KML_StyleSelector::Read(FILE* fid,char* kstr){
    7878
    79         KML_Object::Read(fid,kstr);
     79/*  process field within opening and closing tags  */
     80
     81        if      (!strncmp(kstr,"</StyleSelector",15))
     82                return;
     83        else if (!strncmp(kstr,"</",2))
     84                _error_("KML_StyleSelector::Read -- Unexpected closing tag %s.\n",kstr);
     85        else if (strncmp(kstr,"<",1))
     86                _error_("KML_StyleSelector::Read -- Unexpected field \"%s\".\n",kstr);
     87
     88        else if (!strncmp(kstr,"<",1))
     89                KML_Object::Read(fid,kstr);
    8090
    8191        return;
  • issm/trunk/src/c/objects/KML/KML_SubStyle.cpp

    r8293 r8461  
    7777void  KML_SubStyle::Read(FILE* fid,char* kstr){
    7878
    79         KML_Object::Read(fid,kstr);
     79/*  process field within opening and closing tags  */
     80
     81        if      (!strncmp(kstr,"</SubStyle",10))
     82                return;
     83        else if (!strncmp(kstr,"</",2))
     84                _error_("KML_SubStyle::Read -- Unexpected closing tag %s.\n",kstr);
     85        else if (strncmp(kstr,"<",1))
     86                _error_("KML_SubStyle::Read -- Unexpected field \"%s\".\n",kstr);
     87
     88        else if (!strncmp(kstr,"<",1))
     89                KML_Object::Read(fid,kstr);
    8090
    8191        return;
  • issm/trunk/src/c/objects/objects.h

    r8376 r8461  
    4545
    4646/*KML parsing objects: */
     47#include "./KML/KML_Attribute.h"
    4748#include "./KML/KML_ColorStyle.h"
    4849#include "./KML/KML_Container.h"
Note: See TracChangeset for help on using the changeset viewer.