00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00042
00043
00044
00045
00046
00047 typedef enum ogr_style_tool_param_vector_id
00048 {
00049 OGRSTVectorId = 0,
00050 OGRSTVectorNoCompress = 1,
00051 OGRSTVectorSprain = 2,
00052 OGRSTVectorNoSlope = 3,
00053 OGRSTVectorMirroring = 4,
00054 OGRSTVectorCentering = 5,
00055 OGRSTVectorPriority = 6,
00056 OGRSTVectorPlacement = 7,
00057 OGRSTVectorLength = 8,
00058 OGRSTVectorEven = 9,
00059 OGRSTVectorLast = 10
00060
00061 } OGRSTVectorParam;
00062
00063 typedef enum ogr_style_type
00064 {
00065 OGRSTypeString,
00066 OGRSTypeDouble,
00067 OGRSTypeInteger,
00068 OGRSTypeBoolean
00069 } OGRSType;
00070
00071 typedef struct ogr_style_param
00072 {
00073 int eParam;
00074 const char *pszToken;
00075 GBool bGeoref;
00076 OGRSType eType;
00077 } OGRStyleParamId;
00078
00079
00080 typedef struct ogr_style_value
00081 {
00082 char *pszValue;
00083 double dfValue;
00084 int nValue;
00085 GBool bValid;
00086 OGRSTUnitId eUnit;
00087 } OGRStyleValue;
00088
00089
00090
00091
00092
00093 class CPL_DLL OGRStyleTable
00094 {
00095 private:
00096 char **m_papszStyleTable;
00097
00098 CPLString osLastRequestedStyleName;
00099
00100 public:
00101 OGRStyleTable();
00102 ~OGRStyleTable();
00103 GBool AddStyle(const char *pszName,const char *pszStyleString);
00104 GBool RemoveStyle(const char *pszName);
00105 GBool ModifyStyle(const char *pszName, const char *pszStyleString);
00106
00107 GBool SaveStyleTable(const char *pszFilename);
00108 GBool LoadStyleTable(const char *pszFilename);
00109 const char *Find(const char *pszStyleString);
00110 GBool IsExist(const char *pszName);
00111 const char *GetStyleName(const char *pszName);
00112 void Print(FILE *fpOut);
00113 void Clear();
00114 OGRStyleTable *Clone();
00115 };
00116
00117
00118 class OGRStyleTool;
00119
00120 class CPL_DLL OGRStyleMgr
00121 {
00122 private:
00123 OGRStyleTable *m_poDataSetStyleTable;
00124 char *m_pszStyleString;
00125
00126 public:
00127 OGRStyleMgr(OGRStyleTable *poDataSetStyleTable = NULL);
00128 ~OGRStyleMgr();
00129
00130 GBool SetFeatureStyleString(OGRFeature *,const char *pszStyleString=NULL,
00131 GBool bNoMatching = FALSE);
00132
00133
00134
00135
00136 const char *InitFromFeature(OGRFeature *);
00137 GBool InitStyleString(const char *pszStyleString = NULL);
00138
00139 const char *GetStyleName(const char *pszStyleString= NULL);
00140 const char *GetStyleByName(const char *pszStyleName);
00141
00142 GBool AddStyle(const char *pszStyleName, const char *pszStyleString=NULL);
00143
00144 const char *GetStyleString(OGRFeature * = NULL);
00145
00146 GBool AddPart(OGRStyleTool *);
00147 GBool AddPart(const char *);
00148
00149 int GetPartCount(const char *pszStyleString = NULL);
00150 OGRStyleTool *GetPart(int hPartId, const char *pszStyleString = NULL);
00151
00152
00153
00154
00155 OGRStyleTable *GetDataSetStyleTable(){return m_poDataSetStyleTable;}
00156
00157 OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString);
00158
00159 };
00160
00161 class CPL_DLL OGRStyleTool
00162 {
00163 private:
00164 GBool m_bModified;
00165 GBool m_bParsed;
00166 double m_dfScale;
00167 OGRSTUnitId m_eUnit;
00168 OGRSTClassId m_eClassId;
00169 char *m_pszStyleString;
00170
00171 virtual GBool Parse() = 0;
00172
00173 protected:
00174 GBool Parse(const OGRStyleParamId* pasStyle,
00175 OGRStyleValue* pasValue,
00176 int nCount);
00177
00178 public:
00179
00180 OGRStyleTool(){}
00181 OGRStyleTool(OGRSTClassId eClassId);
00182 virtual ~OGRStyleTool();
00183
00184 GBool GetRGBFromString(const char *pszColor, int &nRed, int &nGreen,
00185 int &nBlue, int &nTransparence);
00186 int GetSpecificId(const char *pszId, const char *pszWanted);
00187
00188 GBool IsStyleModified() {return m_bModified;}
00189 void StyleModified() {m_bModified = TRUE;}
00190
00191 GBool IsStyleParsed() {return m_bParsed;}
00192 void StyleParsed() {m_bParsed = TRUE;}
00193
00194 OGRSTClassId GetType();
00195
00196 void SetInternalInputUnitFromParam(char *pszString);
00197
00198 void SetUnit(OGRSTUnitId,double dfScale = 1.0);
00199
00200
00201 OGRSTUnitId GetUnit(){return m_eUnit;}
00202
00203
00204
00205
00206
00207 virtual const char *GetStyleString() = 0;
00208 void SetStyleString(const char *pszStyleString);
00209 const char *GetStyleString(const OGRStyleParamId *pasStyleParam ,
00210 OGRStyleValue *pasStyleValue, int nSize);
00211
00212 const char *GetParamStr(const OGRStyleParamId &sStyleParam ,
00213 OGRStyleValue &sStyleValue,
00214 GBool &bValueIsNull);
00215
00216 int GetParamNum(const OGRStyleParamId &sStyleParam ,
00217 OGRStyleValue &sStyleValue,
00218 GBool &bValueIsNull);
00219
00220 double GetParamDbl(const OGRStyleParamId &sStyleParam ,
00221 OGRStyleValue &sStyleValue,
00222 GBool &bValueIsNull);
00223
00224 void SetParamStr(const OGRStyleParamId &sStyleParam ,
00225 OGRStyleValue &sStyleValue,
00226 const char *pszParamString);
00227
00228 void SetParamNum(const OGRStyleParamId &sStyleParam ,
00229 OGRStyleValue &sStyleValue,
00230 int nParam);
00231
00232 void SetParamDbl(const OGRStyleParamId &sStyleParam ,
00233 OGRStyleValue &sStyleValue,
00234 double dfParam);
00235
00236 double ComputeWithUnit(double, OGRSTUnitId);
00237 int ComputeWithUnit(int , OGRSTUnitId);
00238
00239 };
00240
00241 class CPL_DLL OGRStylePen : public OGRStyleTool
00242 {
00243 private:
00244
00245 OGRStyleValue *m_pasStyleValue;
00246
00247 GBool Parse();
00248
00249 public:
00250
00251 OGRStylePen();
00252 virtual ~OGRStylePen();
00253
00254
00255
00256
00257
00258 const char *Color(GBool &bDefault){return GetParamStr(OGRSTPenColor,bDefault);}
00259 void SetColor(const char *pszColor){SetParamStr(OGRSTPenColor,pszColor);}
00260 double Width(GBool &bDefault){return GetParamDbl(OGRSTPenWidth,bDefault);}
00261 void SetWidth(double dfWidth){SetParamDbl(OGRSTPenWidth,dfWidth);}
00262 const char *Pattern(GBool &bDefault){return (char *)GetParamStr(OGRSTPenPattern,bDefault);}
00263 void SetPattern(const char *pszPattern){SetParamStr(OGRSTPenPattern,pszPattern);}
00264 const char *Id(GBool &bDefault){return GetParamStr(OGRSTPenId,bDefault);}
00265 void SetId(const char *pszId){SetParamStr(OGRSTPenId,pszId);}
00266 double PerpendicularOffset(GBool &bDefault){return GetParamDbl(OGRSTPenPerOffset,bDefault);}
00267 void SetPerpendicularOffset(double dfPerp){SetParamDbl(OGRSTPenPerOffset,dfPerp);}
00268 const char *Cap(GBool &bDefault){return GetParamStr(OGRSTPenCap,bDefault);}
00269 void SetCap(const char *pszCap){SetParamStr(OGRSTPenCap,pszCap);}
00270 const char *Join(GBool &bDefault){return GetParamStr(OGRSTPenJoin,bDefault);}
00271 void SetJoin(const char *pszJoin){SetParamStr(OGRSTPenJoin,pszJoin);}
00272 int Priority(GBool &bDefault){return GetParamNum(OGRSTPenPriority,bDefault);}
00273 void SetPriority(int nPriority){SetParamNum(OGRSTPenPriority,nPriority);}
00274
00275
00276
00277 const char *GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull);
00278 int GetParamNum(OGRSTPenParam eParam,GBool &bValueIsNull);
00279 double GetParamDbl(OGRSTPenParam eParam,GBool &bValueIsNull);
00280 void SetParamStr(OGRSTPenParam eParam, const char *pszParamString);
00281 void SetParamNum(OGRSTPenParam eParam, int nParam);
00282 void SetParamDbl(OGRSTPenParam eParam, double dfParam);
00283 const char *GetStyleString();
00284 };
00285
00286 class CPL_DLL OGRStyleBrush : public OGRStyleTool
00287 {
00288 private:
00289
00290 OGRStyleValue *m_pasStyleValue;
00291
00292 GBool Parse();
00293
00294 public:
00295
00296 OGRStyleBrush();
00297 virtual ~OGRStyleBrush();
00298
00299
00300
00301 const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTBrushFColor,bDefault);}
00302 void SetForeColor(const char *pszColor){SetParamStr(OGRSTBrushFColor,pszColor);}
00303 const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTBrushBColor,bDefault);}
00304 void SetBackColor(const char *pszColor){SetParamStr(OGRSTBrushBColor,pszColor);}
00305 const char *Id(GBool &bDefault){ return GetParamStr(OGRSTBrushId,bDefault);}
00306 void SetId(const char *pszId){SetParamStr(OGRSTBrushId,pszId);}
00307 double Angle(GBool &bDefault){return GetParamDbl(OGRSTBrushAngle,bDefault);}
00308 void SetAngle(double dfAngle){SetParamDbl(OGRSTBrushAngle,dfAngle );}
00309 double Size(GBool &bDefault){return GetParamDbl(OGRSTBrushSize,bDefault);}
00310 void SetSize(double dfSize){SetParamDbl(OGRSTBrushSize,dfSize );}
00311 double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTBrushDx,bDefault);}
00312 void SetSpacingX(double dfX){SetParamDbl(OGRSTBrushDx,dfX );}
00313 double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTBrushDy,bDefault);}
00314 void SetSpacingY(double dfY){SetParamDbl(OGRSTBrushDy,dfY );}
00315 int Priority(GBool &bDefault){ return GetParamNum(OGRSTBrushPriority,bDefault);}
00316 void SetPriority(int nPriority){ SetParamNum(OGRSTBrushPriority,nPriority);}
00317
00318
00319
00320
00321 const char *GetParamStr(OGRSTBrushParam eParam, GBool &bValueIsNull);
00322 int GetParamNum(OGRSTBrushParam eParam,GBool &bValueIsNull);
00323 double GetParamDbl(OGRSTBrushParam eParam,GBool &bValueIsNull);
00324 void SetParamStr(OGRSTBrushParam eParam, const char *pszParamString);
00325 void SetParamNum(OGRSTBrushParam eParam, int nParam);
00326 void SetParamDbl(OGRSTBrushParam eParam, double dfParam);
00327 const char *GetStyleString();
00328 };
00329
00330 class CPL_DLL OGRStyleSymbol : public OGRStyleTool
00331 {
00332 private:
00333
00334 OGRStyleValue *m_pasStyleValue;
00335
00336 GBool Parse();
00337
00338 public:
00339
00340 OGRStyleSymbol();
00341 virtual ~OGRStyleSymbol();
00342
00343
00344
00345
00346
00347 const char *Id(GBool &bDefault){return GetParamStr(OGRSTSymbolId,bDefault);}
00348 void SetId(const char *pszId){ SetParamStr(OGRSTSymbolId,pszId);}
00349 double Angle(GBool &bDefault){ return GetParamDbl(OGRSTSymbolAngle,bDefault);}
00350 void SetAngle(double dfAngle){SetParamDbl(OGRSTSymbolAngle,dfAngle );}
00351 const char *Color(GBool &bDefault){return GetParamStr(OGRSTSymbolColor,bDefault);}
00352 void SetColor(const char *pszColor){SetParamStr(OGRSTSymbolColor,pszColor);}
00353 double Size(GBool &bDefault){ return GetParamDbl(OGRSTSymbolSize,bDefault);}
00354 void SetSize(double dfSize){ SetParamDbl(OGRSTSymbolSize,dfSize );}
00355 double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTSymbolDx,bDefault);}
00356 void SetSpacingX(double dfX){SetParamDbl(OGRSTSymbolDx,dfX );}
00357 double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTSymbolDy,bDefault);}
00358 void SetSpacingY(double dfY){SetParamDbl(OGRSTSymbolDy,dfY );}
00359 double Step(GBool &bDefault){return GetParamDbl(OGRSTSymbolStep,bDefault);}
00360 void SetStep(double dfStep){SetParamDbl(OGRSTSymbolStep,dfStep );}
00361 double Offset(GBool &bDefault){return GetParamDbl(OGRSTSymbolOffset,bDefault);}
00362 void SetOffset(double dfOffset){SetParamDbl(OGRSTSymbolOffset,dfOffset );}
00363 double Perp(GBool &bDefault){return GetParamDbl(OGRSTSymbolPerp,bDefault);}
00364 void SetPerp(double dfPerp){SetParamDbl(OGRSTSymbolPerp,dfPerp );}
00365 int Priority(GBool &bDefault){return GetParamNum(OGRSTSymbolPriority,bDefault);}
00366 void SetPriority(int nPriority){SetParamNum(OGRSTSymbolPriority,nPriority);}
00367 const char *FontName(GBool &bDefault)
00368 {return GetParamStr(OGRSTSymbolFontName,bDefault);}
00369 void SetFontName(const char *pszFontName)
00370 {SetParamStr(OGRSTSymbolFontName,pszFontName);}
00371
00372
00373
00374 const char *GetParamStr(OGRSTSymbolParam eParam, GBool &bValueIsNull);
00375 int GetParamNum(OGRSTSymbolParam eParam,GBool &bValueIsNull);
00376 double GetParamDbl(OGRSTSymbolParam eParam,GBool &bValueIsNull);
00377 void SetParamStr(OGRSTSymbolParam eParam, const char *pszParamString);
00378 void SetParamNum(OGRSTSymbolParam eParam, int nParam);
00379 void SetParamDbl(OGRSTSymbolParam eParam, double dfParam);
00380 const char *GetStyleString();
00381 };
00382
00383 class CPL_DLL OGRStyleLabel : public OGRStyleTool
00384 {
00385 private:
00386
00387 OGRStyleValue *m_pasStyleValue;
00388
00389 GBool Parse();
00390
00391 public:
00392
00393 OGRStyleLabel();
00394 virtual ~OGRStyleLabel();
00395
00396
00397
00398
00399
00400 const char *FontName(GBool &bDefault){return GetParamStr(OGRSTLabelFontName,bDefault);}
00401 void SetFontName(const char *pszFontName){SetParamStr(OGRSTLabelFontName,pszFontName);}
00402 double Size(GBool &bDefault){return GetParamDbl(OGRSTLabelSize,bDefault);}
00403 void SetSize(double dfSize){SetParamDbl(OGRSTLabelSize,dfSize);}
00404 const char *TextString(GBool &bDefault){return GetParamStr(OGRSTLabelTextString,bDefault);}
00405 void SetTextString(const char *pszTextString){SetParamStr(OGRSTLabelTextString,pszTextString);}
00406 double Angle(GBool &bDefault){return GetParamDbl(OGRSTLabelAngle,bDefault);}
00407 void SetAngle(double dfAngle){SetParamDbl(OGRSTLabelAngle,dfAngle);}
00408 const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTLabelFColor,bDefault);}
00409 void SetForColor(const char *pszForColor){SetParamStr(OGRSTLabelFColor,pszForColor);}
00410 const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTLabelBColor,bDefault);}
00411 void SetBackColor(const char *pszBackColor){SetParamStr(OGRSTLabelBColor,pszBackColor);}
00412 const char *Placement(GBool &bDefault){return GetParamStr(OGRSTLabelPlacement,bDefault);}
00413 void SetPlacement(const char *pszPlacement){SetParamStr(OGRSTLabelPlacement,pszPlacement);}
00414 int Anchor(GBool &bDefault){return GetParamNum(OGRSTLabelAnchor,bDefault);}
00415 void SetAnchor(int nAnchor){SetParamNum(OGRSTLabelAnchor,nAnchor);}
00416 double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTLabelDx,bDefault);}
00417 void SetSpacingX(double dfX){SetParamDbl(OGRSTLabelDx,dfX);}
00418 double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTLabelDy,bDefault);}
00419 void SetSpacingY(double dfY){SetParamDbl(OGRSTLabelDy,dfY);}
00420 double Perp(GBool &bDefault){return GetParamDbl(OGRSTLabelPerp,bDefault);}
00421 void SetPerp(double dfPerp){SetParamDbl(OGRSTLabelPerp,dfPerp);}
00422 GBool Bold(GBool &bDefault){return GetParamNum(OGRSTLabelBold,bDefault);}
00423 void SetBold(GBool bBold){SetParamNum(OGRSTLabelBold,bBold);}
00424 GBool Italic(GBool &bDefault){return GetParamNum(OGRSTLabelItalic,bDefault);}
00425 void SetItalic(GBool bItalic){SetParamNum(OGRSTLabelItalic,bItalic);}
00426 GBool Underline(GBool &bDefault){return GetParamNum(OGRSTLabelUnderline,bDefault);}
00427 void SetUnderline(GBool bUnderline){SetParamNum(OGRSTLabelUnderline,bUnderline);}
00428 int Priority(GBool &bDefault){return GetParamNum(OGRSTLabelPriority,bDefault);}
00429 void SetPriority(int nPriority){SetParamNum(OGRSTLabelPriority,nPriority);}
00430 GBool Strikeout(GBool &bDefault){return GetParamNum(OGRSTLabelStrikeout,bDefault);}
00431 void SetStrikeout(GBool bStrikeout){SetParamNum(OGRSTLabelStrikeout,bStrikeout);}
00432 double Stretch(GBool &bDefault){return GetParamDbl(OGRSTLabelStretch,bDefault);}
00433 void SetStretch(double dfStretch){SetParamDbl(OGRSTLabelStretch,dfStretch);}
00434 const char *AdjustmentHor(GBool &bDefault){return GetParamStr(OGRSTLabelAdjHor,bDefault);}
00435 void SetAdjustmentHor(const char *pszAdjustmentHor){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentHor);}
00436 const char *AdjustmentVert(GBool &bDefault){return GetParamStr(OGRSTLabelAdjVert,bDefault);}
00437 void SetAdjustmentVert(const char *pszAdjustmentVert){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentVert);}
00438 const char *ShadowColor(GBool &bDefault){return GetParamStr(OGRSTLabelHColor,bDefault);}
00439 void SetShadowColor(const char *pszShadowColor){SetParamStr(OGRSTLabelHColor,pszShadowColor);}
00440
00441
00442
00443 const char *GetParamStr(OGRSTLabelParam eParam, GBool &bValueIsNull);
00444 int GetParamNum(OGRSTLabelParam eParam,GBool &bValueIsNull);
00445 double GetParamDbl(OGRSTLabelParam eParam,GBool &bValueIsNull);
00446 void SetParamStr(OGRSTLabelParam eParam, const char *pszParamString);
00447 void SetParamNum(OGRSTLabelParam eParam, int nParam);
00448 void SetParamDbl(OGRSTLabelParam eParam, double dfParam);
00449 const char *GetStyleString();
00450 };
00451
00452
00453
00454
00455
00456
00457
00458 class CPL_DLL OGRStyleVector : public OGRStyleTool
00459 {
00460 private:
00461
00462 OGRStyleValue *m_pasStyleValue;
00463
00464 GBool Parse();
00465
00466 public:
00467
00468 OGRStyleVector();
00469 virtual ~OGRStyleVector();
00470
00471
00472
00473
00474
00475 const char *Id(GBool &bDefault){return GetParamStr(OGRSTVectorId,bDefault);}
00476 void SetId(const char *pszId){ SetParamStr(OGRSTVectorId,pszId);}
00477 int Priority(GBool &bDefault){return GetParamNum(OGRSTVectorPriority,bDefault);}
00478 void SetPriority(int nPriority){SetParamNum(OGRSTVectorPriority,nPriority);}
00479
00480
00481 GBool NoCompress(GBool &bDefault){return GetParamNum(OGRSTVectorNoCompress,bDefault);}
00482 void SetNoCompress(GBool bNoCompress){SetParamNum(OGRSTVectorNoCompress,bNoCompress);}
00483 GBool Sprain(GBool &bDefault){return GetParamNum(OGRSTVectorSprain,bDefault);}
00484 void SetSprain(GBool bSprain){SetParamNum(OGRSTVectorSprain,bSprain);}
00485 GBool NoSlope(GBool &bDefault){return GetParamNum(OGRSTVectorNoSlope,bDefault);}
00486 void SetNoSlope(GBool bNoSlope){SetParamNum(OGRSTVectorNoSlope,bNoSlope);}
00487 GBool Mirroring(GBool &bDefault){return GetParamNum(OGRSTVectorMirroring,bDefault);}
00488 void SetMirroring(GBool bMirroring){SetParamNum(OGRSTVectorMirroring,bMirroring);}
00489 GBool Centering(GBool &bDefault){return GetParamNum(OGRSTVectorCentering,bDefault);}
00490 void SetCentering(GBool bCentering){SetParamNum(OGRSTVectorCentering,bCentering);}
00491 const char *Placement(GBool &bDefault){return GetParamStr(OGRSTVectorPlacement,bDefault);}
00492 void SetPlacement(const char *pszPlacement){SetParamStr(OGRSTVectorPlacement,pszPlacement);}
00493 double Length(GBool &bDefault){return GetParamDbl(OGRSTVectorLength,bDefault);}
00494 void SetLength(double dfLength){SetParamDbl(OGRSTVectorLength,dfLength);}
00495 GBool Even(GBool &bDefault){return GetParamNum(OGRSTVectorEven,bDefault);}
00496 void SetEven(GBool bEven){SetParamNum(OGRSTVectorEven,bEven);}
00497
00498
00499
00500 const char *GetParamStr(OGRSTVectorParam eParam, GBool &bValueIsNull);
00501 int GetParamNum(OGRSTVectorParam eParam,GBool &bValueIsNull);
00502 double GetParamDbl(OGRSTVectorParam eParam,GBool &bValueIsNull);
00503 void SetParamStr(OGRSTVectorParam eParam, const char *pszParamString);
00504 void SetParamNum(OGRSTVectorParam eParam, int nParam);
00505 void SetParamDbl(OGRSTVectorParam eParam, double dfParam);
00506 const char *GetStyleString();
00507 };
00508
00509 #endif