OGR

ogr_featurestyle.h

00001 /******************************************************************************
00002  * $Id: ogr_featurestyle.h 15073 2008-07-29 17:33:13Z dmorissette $
00003  *
00004  * Project:  OpenGIS Simple Features Reference Implementation
00005  * Purpose:  Define of Feature Representation
00006  * Author:   Stephane Villeneuve, stephane.v@videtron.ca
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 1999, Frank Warmerdam
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00027  * DEALINGS IN THE SOFTWARE.
00028  ****************************************************************************/
00029 
00030 #ifndef OGR_FEATURESTYLE_INCLUDE
00031 #define OGR_FEATURESTYLE_INCLUDE
00032 
00033 #include "cpl_conv.h"
00034 #include "cpl_string.h"
00035 #include "ogr_core.h"
00036 
00037 class OGRFeature;
00038 
00039 
00040 /*
00041  * All OGRStyleTool param lists are defined in ogr_core.h.
00042  */
00043 
00044 typedef enum ogr_style_type
00045 {
00046     OGRSTypeString,
00047     OGRSTypeDouble,
00048     OGRSTypeInteger,
00049     OGRSTypeBoolean
00050 }  OGRSType;
00051 
00052 typedef struct ogr_style_param
00053 {
00054     int              eParam;
00055     const char       *pszToken;
00056     GBool            bGeoref;
00057     OGRSType         eType;
00058 } OGRStyleParamId;
00059 
00060 
00061 typedef struct ogr_style_value
00062 {
00063     char            *pszValue;
00064     double           dfValue;
00065     int              nValue; // Used for both integer and boolean types
00066     GBool            bValid;
00067     OGRSTUnitId      eUnit;
00068 } OGRStyleValue;
00069 
00070 
00071 //Everytime a pszStyleString gived in parameter is NULL, 
00072 //    the StyleString defined in the Mgr will be use.
00073 
00074 class CPL_DLL OGRStyleTable
00075 {
00076   private:
00077     char **m_papszStyleTable;
00078 
00079     CPLString osLastRequestedStyleName;
00080 
00081   public:
00082     OGRStyleTable();
00083     ~OGRStyleTable();
00084     GBool AddStyle(const char *pszName,const char *pszStyleString);
00085     GBool RemoveStyle(const char *pszName);
00086     GBool ModifyStyle(const char *pszName, const char *pszStyleString);
00087     
00088     GBool SaveStyleTable(const char *pszFilename);
00089     GBool LoadStyleTable(const char *pszFilename);
00090     const char *Find(const char *pszStyleString);
00091     GBool IsExist(const char *pszName);
00092     const char *GetStyleName(const char *pszName);
00093     void  Print(FILE *fpOut);
00094     void  Clear();
00095     OGRStyleTable   *Clone();
00096 };
00097 
00098 
00099 class OGRStyleTool;
00100 
00101 class CPL_DLL OGRStyleMgr
00102 {
00103   private:
00104     OGRStyleTable   *m_poDataSetStyleTable;
00105     char            *m_pszStyleString;
00106 
00107   public:
00108     OGRStyleMgr(OGRStyleTable *poDataSetStyleTable = NULL);
00109     ~OGRStyleMgr();
00110 
00111     GBool SetFeatureStyleString(OGRFeature *,const char *pszStyleString=NULL,
00112                                 GBool bNoMatching = FALSE);
00113     /*it will set in the gived feature the pszStyleString with 
00114             the style or will set the style name found in 
00115             dataset StyleTable (if bNoMatching == FALSE)*/
00116               
00117     const char *InitFromFeature(OGRFeature *);
00118     GBool InitStyleString(const char *pszStyleString = NULL);
00119     
00120     const char *GetStyleName(const char *pszStyleString= NULL);
00121     const char *GetStyleByName(const char *pszStyleName);
00122     
00123     GBool AddStyle(const char *pszStyleName, const char *pszStyleString=NULL);
00124     
00125     const char *GetStyleString(OGRFeature * = NULL);
00126  
00127     GBool AddPart(OGRStyleTool *);
00128     GBool AddPart(const char *);
00129 
00130     int GetPartCount(const char *pszStyleString = NULL);
00131     OGRStyleTool *GetPart(int hPartId, const char *pszStyleString = NULL);
00132     
00133     /*It could have a reference counting processus for the OGRStyleTable, if
00134       needed */
00135       
00136     OGRStyleTable *GetDataSetStyleTable(){return m_poDataSetStyleTable;}
00137     
00138     OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString);
00139 
00140 };
00141 
00142 class CPL_DLL OGRStyleTool
00143 {
00144   private:
00145     GBool m_bModified;
00146     GBool m_bParsed;
00147     double m_dfScale;
00148     OGRSTUnitId m_eUnit;
00149     OGRSTClassId m_eClassId;
00150     char *m_pszStyleString;
00151 
00152     virtual GBool Parse() = 0;
00153 
00154   protected:
00155     GBool Parse(const OGRStyleParamId* pasStyle,
00156                 OGRStyleValue* pasValue,
00157                 int nCount);
00158 
00159   public:
00160     
00161     OGRStyleTool(){}
00162     OGRStyleTool(OGRSTClassId eClassId);
00163     virtual ~OGRStyleTool();
00164 
00165     GBool GetRGBFromString(const char *pszColor, int &nRed, int &nGreen, 
00166                            int &nBlue, int &nTransparence);
00167     int   GetSpecificId(const char *pszId, const char *pszWanted);
00168 
00169     GBool IsStyleModified() {return m_bModified;}
00170     void  StyleModified() {m_bModified = TRUE;}
00171 
00172     GBool IsStyleParsed() {return m_bParsed;}
00173     void  StyleParsed() {m_bParsed = TRUE;}
00174     
00175     OGRSTClassId GetType();
00176 
00177     void SetInternalInputUnitFromParam(char *pszString);
00178     
00179     void SetUnit(OGRSTUnitId,double dfScale = 1.0); //the dfScale will be
00180          //used if we are working with Ground Unit ( ground = paper * scale);
00181 
00182     OGRSTUnitId GetUnit(){return m_eUnit;}
00183     
00184     /* It's existe two way to set the parameters in the Style, with generic
00185 methodes (using a defined enumeration) or with the reel method specific
00186 for Each style tools.*/
00187     
00188     virtual const char *GetStyleString() = 0;
00189     void SetStyleString(const char *pszStyleString);
00190     const char *GetStyleString(const OGRStyleParamId *pasStyleParam ,
00191                             OGRStyleValue *pasStyleValue, int nSize);
00192 
00193     const char *GetParamStr(const OGRStyleParamId &sStyleParam ,
00194                             OGRStyleValue &sStyleValue,
00195                             GBool &bValueIsNull);
00196 
00197     int GetParamNum(const OGRStyleParamId &sStyleParam ,
00198                     OGRStyleValue &sStyleValue,
00199                     GBool &bValueIsNull);
00200 
00201     double GetParamDbl(const OGRStyleParamId &sStyleParam ,
00202                        OGRStyleValue &sStyleValue,
00203                        GBool &bValueIsNull);
00204     
00205     void SetParamStr(const OGRStyleParamId &sStyleParam ,
00206                      OGRStyleValue &sStyleValue,
00207                      const char *pszParamString);
00208     
00209     void SetParamNum(const OGRStyleParamId &sStyleParam ,
00210                      OGRStyleValue &sStyleValue,
00211                      int nParam);
00212 
00213     void SetParamDbl(const OGRStyleParamId &sStyleParam ,
00214                      OGRStyleValue &sStyleValue,
00215                      double dfParam);
00216 
00217     double ComputeWithUnit(double, OGRSTUnitId);
00218     int    ComputeWithUnit(int , OGRSTUnitId);
00219 
00220 };
00221 
00222 class CPL_DLL OGRStylePen : public OGRStyleTool
00223 {
00224   private:
00225 
00226     OGRStyleValue    *m_pasStyleValue;
00227 
00228     GBool Parse();
00229 
00230   public:
00231 
00232     OGRStylePen();
00233     virtual ~OGRStylePen(); 
00234 
00235     /**********************************************************************/
00236     /* Explicit fct for all parameters defined in the Drawing tools  Pen  */
00237     /**********************************************************************/
00238      
00239     const char *Color(GBool &bDefault){return GetParamStr(OGRSTPenColor,bDefault);}
00240     void SetColor(const char *pszColor){SetParamStr(OGRSTPenColor,pszColor);}
00241     double Width(GBool &bDefault){return GetParamDbl(OGRSTPenWidth,bDefault);}
00242     void SetWidth(double dfWidth){SetParamDbl(OGRSTPenWidth,dfWidth);}
00243     const char *Pattern(GBool &bDefault){return (char *)GetParamStr(OGRSTPenPattern,bDefault);}
00244     void SetPattern(const char *pszPattern){SetParamStr(OGRSTPenPattern,pszPattern);}
00245     const char *Id(GBool &bDefault){return GetParamStr(OGRSTPenId,bDefault);}
00246     void SetId(const char *pszId){SetParamStr(OGRSTPenId,pszId);}
00247     double PerpendicularOffset(GBool &bDefault){return GetParamDbl(OGRSTPenPerOffset,bDefault);}
00248     void SetPerpendicularOffset(double dfPerp){SetParamDbl(OGRSTPenPerOffset,dfPerp);}
00249     const char *Cap(GBool &bDefault){return GetParamStr(OGRSTPenCap,bDefault);}
00250     void SetCap(const char *pszCap){SetParamStr(OGRSTPenCap,pszCap);}
00251     const char *Join(GBool &bDefault){return GetParamStr(OGRSTPenJoin,bDefault);}
00252     void SetJoin(const char *pszJoin){SetParamStr(OGRSTPenJoin,pszJoin);}
00253     int  Priority(GBool &bDefault){return GetParamNum(OGRSTPenPriority,bDefault);}
00254     void SetPriority(int nPriority){SetParamNum(OGRSTPenPriority,nPriority);}
00255     
00256     /*****************************************************************/
00257     
00258     const char *GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull);
00259     int GetParamNum(OGRSTPenParam eParam,GBool &bValueIsNull);
00260     double GetParamDbl(OGRSTPenParam eParam,GBool &bValueIsNull);
00261     void SetParamStr(OGRSTPenParam eParam, const char *pszParamString);
00262     void SetParamNum(OGRSTPenParam eParam, int nParam);
00263     void SetParamDbl(OGRSTPenParam eParam, double dfParam);
00264     const char *GetStyleString();
00265 };
00266 
00267 class CPL_DLL OGRStyleBrush : public OGRStyleTool
00268 {
00269   private:
00270 
00271     OGRStyleValue    *m_pasStyleValue;
00272 
00273     GBool Parse();
00274 
00275   public:
00276 
00277     OGRStyleBrush();
00278     virtual ~OGRStyleBrush();
00279 
00280     /* Explicit fct for all parameters defined in the Drawing tools Brush */
00281 
00282     const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTBrushFColor,bDefault);}
00283     void SetForeColor(const char *pszColor){SetParamStr(OGRSTBrushFColor,pszColor);}
00284     const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTBrushBColor,bDefault);}
00285     void SetBackColor(const char *pszColor){SetParamStr(OGRSTBrushBColor,pszColor);}
00286     const char *Id(GBool &bDefault){ return GetParamStr(OGRSTBrushId,bDefault);}
00287     void  SetId(const char *pszId){SetParamStr(OGRSTBrushId,pszId);}
00288     double Angle(GBool &bDefault){return GetParamDbl(OGRSTBrushAngle,bDefault);}
00289     void SetAngle(double dfAngle){SetParamDbl(OGRSTBrushAngle,dfAngle );}
00290     double Size(GBool &bDefault){return GetParamDbl(OGRSTBrushSize,bDefault);}
00291     void SetSize(double dfSize){SetParamDbl(OGRSTBrushSize,dfSize  );}
00292     double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTBrushDx,bDefault);}
00293     void SetSpacingX(double dfX){SetParamDbl(OGRSTBrushDx,dfX );}
00294     double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTBrushDy,bDefault);}
00295     void SetSpacingY(double dfY){SetParamDbl(OGRSTBrushDy,dfY  );}
00296     int  Priority(GBool &bDefault){ return GetParamNum(OGRSTBrushPriority,bDefault);}
00297     void SetPriority(int nPriority){ SetParamNum(OGRSTBrushPriority,nPriority);}
00298     
00299 
00300     /*****************************************************************/
00301     
00302      const char *GetParamStr(OGRSTBrushParam eParam, GBool &bValueIsNull);
00303      int GetParamNum(OGRSTBrushParam eParam,GBool &bValueIsNull);
00304      double GetParamDbl(OGRSTBrushParam eParam,GBool &bValueIsNull);
00305      void SetParamStr(OGRSTBrushParam eParam, const char *pszParamString);
00306      void SetParamNum(OGRSTBrushParam eParam, int nParam);
00307      void SetParamDbl(OGRSTBrushParam eParam, double dfParam);
00308      const char *GetStyleString();
00309 };
00310 
00311 class CPL_DLL OGRStyleSymbol : public OGRStyleTool
00312 {
00313   private:
00314 
00315     OGRStyleValue    *m_pasStyleValue;
00316 
00317     GBool Parse();
00318 
00319   public:
00320 
00321     OGRStyleSymbol();
00322     virtual ~OGRStyleSymbol();
00323 
00324     /*****************************************************************/
00325     /* Explicit fct for all parameters defined in the Drawing tools  */
00326     /*****************************************************************/
00327     
00328     const char *Id(GBool &bDefault){return GetParamStr(OGRSTSymbolId,bDefault);}
00329     void  SetId(const char *pszId){ SetParamStr(OGRSTSymbolId,pszId);}
00330     double Angle(GBool &bDefault){ return GetParamDbl(OGRSTSymbolAngle,bDefault);}
00331     void SetAngle(double dfAngle){SetParamDbl(OGRSTSymbolAngle,dfAngle );}
00332     const char *Color(GBool &bDefault){return GetParamStr(OGRSTSymbolColor,bDefault);}
00333     void SetColor(const char *pszColor){SetParamStr(OGRSTSymbolColor,pszColor);}
00334     double Size(GBool &bDefault){  return GetParamDbl(OGRSTSymbolSize,bDefault);}
00335     void SetSize(double dfSize){  SetParamDbl(OGRSTSymbolSize,dfSize  );}
00336     double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTSymbolDx,bDefault);}
00337     void SetSpacingX(double dfX){SetParamDbl(OGRSTSymbolDx,dfX  );}
00338     double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTSymbolDy,bDefault);}
00339     void SetSpacingY(double dfY){SetParamDbl(OGRSTSymbolDy,dfY  );}
00340     double Step(GBool &bDefault){return GetParamDbl(OGRSTSymbolStep,bDefault);}
00341     void SetStep(double dfStep){SetParamDbl(OGRSTSymbolStep,dfStep  );}
00342     double Offset(GBool &bDefault){return GetParamDbl(OGRSTSymbolOffset,bDefault);}
00343     void SetOffset(double dfOffset){SetParamDbl(OGRSTSymbolOffset,dfOffset  );}
00344     double Perp(GBool &bDefault){return GetParamDbl(OGRSTSymbolPerp,bDefault);}
00345     void SetPerp(double dfPerp){SetParamDbl(OGRSTSymbolPerp,dfPerp  );}  
00346     int  Priority(GBool &bDefault){return GetParamNum(OGRSTSymbolPriority,bDefault);}
00347     void SetPriority(int nPriority){SetParamNum(OGRSTSymbolPriority,nPriority);}
00348     const char *FontName(GBool &bDefault)
00349         {return GetParamStr(OGRSTSymbolFontName,bDefault);}
00350     void SetFontName(const char *pszFontName)
00351         {SetParamStr(OGRSTSymbolFontName,pszFontName);}
00352     const char *OColor(GBool &bDefault){return GetParamStr(OGRSTSymbolOColor,bDefault);}
00353     void SetOColor(const char *pszColor){SetParamStr(OGRSTSymbolOColor,pszColor);}
00354 
00355     /*****************************************************************/
00356     
00357      const char *GetParamStr(OGRSTSymbolParam eParam, GBool &bValueIsNull);
00358      int GetParamNum(OGRSTSymbolParam eParam,GBool &bValueIsNull);
00359      double GetParamDbl(OGRSTSymbolParam eParam,GBool &bValueIsNull);
00360      void SetParamStr(OGRSTSymbolParam eParam, const char *pszParamString);
00361      void SetParamNum(OGRSTSymbolParam eParam, int nParam);
00362      void SetParamDbl(OGRSTSymbolParam eParam, double dfParam);
00363      const char *GetStyleString();
00364 };
00365 
00366 class CPL_DLL OGRStyleLabel : public OGRStyleTool
00367 {
00368   private:
00369 
00370     OGRStyleValue    *m_pasStyleValue;
00371 
00372     GBool Parse();
00373 
00374   public:
00375 
00376     OGRStyleLabel();
00377     virtual ~OGRStyleLabel();
00378 
00379     /*****************************************************************/
00380     /* Explicit fct for all parameters defined in the Drawing tools  */
00381     /*****************************************************************/
00382     
00383     const char *FontName(GBool &bDefault){return GetParamStr(OGRSTLabelFontName,bDefault);}
00384     void  SetFontName(const char *pszFontName){SetParamStr(OGRSTLabelFontName,pszFontName);}
00385     double Size(GBool &bDefault){return GetParamDbl(OGRSTLabelSize,bDefault);}
00386     void SetSize(double dfSize){SetParamDbl(OGRSTLabelSize,dfSize);}
00387     const char *TextString(GBool &bDefault){return GetParamStr(OGRSTLabelTextString,bDefault);}
00388     void SetTextString(const char *pszTextString){SetParamStr(OGRSTLabelTextString,pszTextString);}
00389     double Angle(GBool &bDefault){return GetParamDbl(OGRSTLabelAngle,bDefault);}
00390     void SetAngle(double dfAngle){SetParamDbl(OGRSTLabelAngle,dfAngle);}
00391     const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTLabelFColor,bDefault);}
00392     void SetForColor(const char *pszForColor){SetParamStr(OGRSTLabelFColor,pszForColor);}
00393     const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTLabelBColor,bDefault);}
00394     void SetBackColor(const char *pszBackColor){SetParamStr(OGRSTLabelBColor,pszBackColor);}
00395     const char *Placement(GBool &bDefault){return GetParamStr(OGRSTLabelPlacement,bDefault);}
00396     void SetPlacement(const char *pszPlacement){SetParamStr(OGRSTLabelPlacement,pszPlacement);}
00397     int  Anchor(GBool &bDefault){return GetParamNum(OGRSTLabelAnchor,bDefault);}
00398     void SetAnchor(int nAnchor){SetParamNum(OGRSTLabelAnchor,nAnchor);}
00399     double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTLabelDx,bDefault);}
00400     void SetSpacingX(double dfX){SetParamDbl(OGRSTLabelDx,dfX);}
00401     double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTLabelDy,bDefault);}
00402     void SetSpacingY(double dfY){SetParamDbl(OGRSTLabelDy,dfY);}
00403     double Perp(GBool &bDefault){return GetParamDbl(OGRSTLabelPerp,bDefault);}
00404     void SetPerp(double dfPerp){SetParamDbl(OGRSTLabelPerp,dfPerp);}  
00405     GBool Bold(GBool &bDefault){return GetParamNum(OGRSTLabelBold,bDefault);}
00406     void SetBold(GBool bBold){SetParamNum(OGRSTLabelBold,bBold);}
00407     GBool Italic(GBool &bDefault){return GetParamNum(OGRSTLabelItalic,bDefault);}
00408     void SetItalic(GBool bItalic){SetParamNum(OGRSTLabelItalic,bItalic);}
00409     GBool Underline(GBool &bDefault){return GetParamNum(OGRSTLabelUnderline,bDefault);}
00410     void SetUnderline(GBool bUnderline){SetParamNum(OGRSTLabelUnderline,bUnderline);}
00411     int  Priority(GBool &bDefault){return GetParamNum(OGRSTLabelPriority,bDefault);}
00412     void SetPriority(int nPriority){SetParamNum(OGRSTLabelPriority,nPriority);}
00413     GBool Strikeout(GBool &bDefault){return GetParamNum(OGRSTLabelStrikeout,bDefault);}
00414     void SetStrikeout(GBool bStrikeout){SetParamNum(OGRSTLabelStrikeout,bStrikeout);}
00415     double Stretch(GBool &bDefault){return GetParamDbl(OGRSTLabelStretch,bDefault);}
00416     void SetStretch(double dfStretch){SetParamDbl(OGRSTLabelStretch,dfStretch);}
00417     const char *AdjustmentHor(GBool &bDefault){return GetParamStr(OGRSTLabelAdjHor,bDefault);}
00418     void SetAdjustmentHor(const char *pszAdjustmentHor){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentHor);}
00419     const char *AdjustmentVert(GBool &bDefault){return GetParamStr(OGRSTLabelAdjVert,bDefault);}
00420     void SetAdjustmentVert(const char *pszAdjustmentVert){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentVert);}
00421     const char *ShadowColor(GBool &bDefault){return GetParamStr(OGRSTLabelHColor,bDefault);}
00422     void SetShadowColor(const char *pszShadowColor){SetParamStr(OGRSTLabelHColor,pszShadowColor);}
00423     const char *OutlineColor(GBool &bDefault){return GetParamStr(OGRSTLabelOColor,bDefault);}
00424     void SetOutlineColor(const char *pszOutlineColor){SetParamStr(OGRSTLabelOColor,pszOutlineColor);}
00425     
00426     /*****************************************************************/
00427     
00428      const char *GetParamStr(OGRSTLabelParam eParam, GBool &bValueIsNull);
00429      int GetParamNum(OGRSTLabelParam eParam,GBool &bValueIsNull);
00430      double GetParamDbl(OGRSTLabelParam eParam,GBool &bValueIsNull);
00431      void SetParamStr(OGRSTLabelParam eParam, const char *pszParamString);
00432      void SetParamNum(OGRSTLabelParam eParam, int nParam);
00433      void SetParamDbl(OGRSTLabelParam eParam, double dfParam);
00434      const char *GetStyleString();
00435 };
00436 
00437 #endif /* OGR_FEATURESTYLE_INCLUDE */

Generated for GDAL by doxygen 1.7.3.