OGR
|
00001 /****************************************************************************** 00002 * $Id: ogr_featurestyle.h 16763 2009-04-14 09:57:15Z chaitanya $ 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 00045 /* 00046 * All OGRStyleTool param lists are defined in ogr_core.h. 00047 */ 00048 00049 typedef enum ogr_style_type 00050 { 00051 OGRSTypeString, 00052 OGRSTypeDouble, 00053 OGRSTypeInteger, 00054 OGRSTypeBoolean 00055 } OGRSType; 00056 00057 typedef struct ogr_style_param 00058 { 00059 int eParam; 00060 const char *pszToken; 00061 GBool bGeoref; 00062 OGRSType eType; 00063 } OGRStyleParamId; 00064 00065 00066 typedef struct ogr_style_value 00067 { 00068 char *pszValue; 00069 double dfValue; 00070 int nValue; // Used for both integer and boolean types 00071 GBool bValid; 00072 OGRSTUnitId eUnit; 00073 } OGRStyleValue; 00074 00075 00076 //Everytime a pszStyleString gived in parameter is NULL, 00077 // the StyleString defined in the Mgr will be use. 00081 class CPL_DLL OGRStyleTable 00082 { 00083 private: 00084 char **m_papszStyleTable; 00085 00086 CPLString osLastRequestedStyleName; 00087 int iNextStyle; 00088 00089 public: 00090 OGRStyleTable(); 00091 ~OGRStyleTable(); 00092 GBool AddStyle(const char *pszName,const char *pszStyleString); 00093 GBool RemoveStyle(const char *pszName); 00094 GBool ModifyStyle(const char *pszName, const char *pszStyleString); 00095 00096 GBool SaveStyleTable(const char *pszFilename); 00097 GBool LoadStyleTable(const char *pszFilename); 00098 const char *Find(const char *pszStyleString); 00099 GBool IsExist(const char *pszName); 00100 const char *GetStyleName(const char *pszName); 00101 void Print(FILE *fpOut); 00102 void Clear(); 00103 OGRStyleTable *Clone(); 00104 void ResetStyleStringReading(); 00105 const char *GetNextStyle(); 00106 const char *GetLastStyleName(); 00107 }; 00108 00109 00110 class OGRStyleTool; 00111 00115 class CPL_DLL OGRStyleMgr 00116 { 00117 private: 00118 OGRStyleTable *m_poDataSetStyleTable; 00119 char *m_pszStyleString; 00120 00121 public: 00122 OGRStyleMgr(OGRStyleTable *poDataSetStyleTable = NULL); 00123 ~OGRStyleMgr(); 00124 00125 GBool SetFeatureStyleString(OGRFeature *,const char *pszStyleString=NULL, 00126 GBool bNoMatching = FALSE); 00127 /*it will set in the gived feature the pszStyleString with 00128 the style or will set the style name found in 00129 dataset StyleTable (if bNoMatching == FALSE)*/ 00130 00131 const char *InitFromFeature(OGRFeature *); 00132 GBool InitStyleString(const char *pszStyleString = NULL); 00133 00134 const char *GetStyleName(const char *pszStyleString= NULL); 00135 const char *GetStyleByName(const char *pszStyleName); 00136 00137 GBool AddStyle(const char *pszStyleName, const char *pszStyleString=NULL); 00138 00139 const char *GetStyleString(OGRFeature * = NULL); 00140 00141 GBool AddPart(OGRStyleTool *); 00142 GBool AddPart(const char *); 00143 00144 int GetPartCount(const char *pszStyleString = NULL); 00145 OGRStyleTool *GetPart(int hPartId, const char *pszStyleString = NULL); 00146 00147 /*It could have a reference counting processus for the OGRStyleTable, if 00148 needed */ 00149 00150 OGRStyleTable *GetDataSetStyleTable(){return m_poDataSetStyleTable;} 00151 00152 OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString); 00153 00154 }; 00155 00159 class CPL_DLL OGRStyleTool 00160 { 00161 private: 00162 GBool m_bModified; 00163 GBool m_bParsed; 00164 double m_dfScale; 00165 OGRSTUnitId m_eUnit; 00166 OGRSTClassId m_eClassId; 00167 char *m_pszStyleString; 00168 00169 virtual GBool Parse() = 0; 00170 00171 protected: 00172 GBool Parse(const OGRStyleParamId* pasStyle, 00173 OGRStyleValue* pasValue, 00174 int nCount); 00175 00176 public: 00177 00178 OGRStyleTool(){} 00179 OGRStyleTool(OGRSTClassId eClassId); 00180 virtual ~OGRStyleTool(); 00181 00182 GBool GetRGBFromString(const char *pszColor, int &nRed, int &nGreen, 00183 int &nBlue, int &nTransparence); 00184 int GetSpecificId(const char *pszId, const char *pszWanted); 00185 00186 GBool IsStyleModified() {return m_bModified;} 00187 void StyleModified() {m_bModified = TRUE;} 00188 00189 GBool IsStyleParsed() {return m_bParsed;} 00190 void StyleParsed() {m_bParsed = TRUE;} 00191 00192 OGRSTClassId GetType(); 00193 00194 void SetInternalInputUnitFromParam(char *pszString); 00195 00196 void SetUnit(OGRSTUnitId,double dfScale = 1.0); //the dfScale will be 00197 //used if we are working with Ground Unit ( ground = paper * scale); 00198 00199 OGRSTUnitId GetUnit(){return m_eUnit;} 00200 00201 /* It's existe two way to set the parameters in the Style, with generic 00202 methodes (using a defined enumeration) or with the reel method specific 00203 for Each style tools.*/ 00204 00205 virtual const char *GetStyleString() = 0; 00206 void SetStyleString(const char *pszStyleString); 00207 const char *GetStyleString(const OGRStyleParamId *pasStyleParam , 00208 OGRStyleValue *pasStyleValue, int nSize); 00209 00210 const char *GetParamStr(const OGRStyleParamId &sStyleParam , 00211 OGRStyleValue &sStyleValue, 00212 GBool &bValueIsNull); 00213 00214 int GetParamNum(const OGRStyleParamId &sStyleParam , 00215 OGRStyleValue &sStyleValue, 00216 GBool &bValueIsNull); 00217 00218 double GetParamDbl(const OGRStyleParamId &sStyleParam , 00219 OGRStyleValue &sStyleValue, 00220 GBool &bValueIsNull); 00221 00222 void SetParamStr(const OGRStyleParamId &sStyleParam , 00223 OGRStyleValue &sStyleValue, 00224 const char *pszParamString); 00225 00226 void SetParamNum(const OGRStyleParamId &sStyleParam , 00227 OGRStyleValue &sStyleValue, 00228 int nParam); 00229 00230 void SetParamDbl(const OGRStyleParamId &sStyleParam , 00231 OGRStyleValue &sStyleValue, 00232 double dfParam); 00233 00234 double ComputeWithUnit(double, OGRSTUnitId); 00235 int ComputeWithUnit(int , OGRSTUnitId); 00236 00237 }; 00238 00242 class CPL_DLL OGRStylePen : public OGRStyleTool 00243 { 00244 private: 00245 00246 OGRStyleValue *m_pasStyleValue; 00247 00248 GBool Parse(); 00249 00250 public: 00251 00252 OGRStylePen(); 00253 virtual ~OGRStylePen(); 00254 00255 /**********************************************************************/ 00256 /* Explicit fct for all parameters defined in the Drawing tools Pen */ 00257 /**********************************************************************/ 00258 00259 const char *Color(GBool &bDefault){return GetParamStr(OGRSTPenColor,bDefault);} 00260 void SetColor(const char *pszColor){SetParamStr(OGRSTPenColor,pszColor);} 00261 double Width(GBool &bDefault){return GetParamDbl(OGRSTPenWidth,bDefault);} 00262 void SetWidth(double dfWidth){SetParamDbl(OGRSTPenWidth,dfWidth);} 00263 const char *Pattern(GBool &bDefault){return (char *)GetParamStr(OGRSTPenPattern,bDefault);} 00264 void SetPattern(const char *pszPattern){SetParamStr(OGRSTPenPattern,pszPattern);} 00265 const char *Id(GBool &bDefault){return GetParamStr(OGRSTPenId,bDefault);} 00266 void SetId(const char *pszId){SetParamStr(OGRSTPenId,pszId);} 00267 double PerpendicularOffset(GBool &bDefault){return GetParamDbl(OGRSTPenPerOffset,bDefault);} 00268 void SetPerpendicularOffset(double dfPerp){SetParamDbl(OGRSTPenPerOffset,dfPerp);} 00269 const char *Cap(GBool &bDefault){return GetParamStr(OGRSTPenCap,bDefault);} 00270 void SetCap(const char *pszCap){SetParamStr(OGRSTPenCap,pszCap);} 00271 const char *Join(GBool &bDefault){return GetParamStr(OGRSTPenJoin,bDefault);} 00272 void SetJoin(const char *pszJoin){SetParamStr(OGRSTPenJoin,pszJoin);} 00273 int Priority(GBool &bDefault){return GetParamNum(OGRSTPenPriority,bDefault);} 00274 void SetPriority(int nPriority){SetParamNum(OGRSTPenPriority,nPriority);} 00275 00276 /*****************************************************************/ 00277 00278 const char *GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull); 00279 int GetParamNum(OGRSTPenParam eParam,GBool &bValueIsNull); 00280 double GetParamDbl(OGRSTPenParam eParam,GBool &bValueIsNull); 00281 void SetParamStr(OGRSTPenParam eParam, const char *pszParamString); 00282 void SetParamNum(OGRSTPenParam eParam, int nParam); 00283 void SetParamDbl(OGRSTPenParam eParam, double dfParam); 00284 const char *GetStyleString(); 00285 }; 00286 00290 class CPL_DLL OGRStyleBrush : public OGRStyleTool 00291 { 00292 private: 00293 00294 OGRStyleValue *m_pasStyleValue; 00295 00296 GBool Parse(); 00297 00298 public: 00299 00300 OGRStyleBrush(); 00301 virtual ~OGRStyleBrush(); 00302 00303 /* Explicit fct for all parameters defined in the Drawing tools Brush */ 00304 00305 const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTBrushFColor,bDefault);} 00306 void SetForeColor(const char *pszColor){SetParamStr(OGRSTBrushFColor,pszColor);} 00307 const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTBrushBColor,bDefault);} 00308 void SetBackColor(const char *pszColor){SetParamStr(OGRSTBrushBColor,pszColor);} 00309 const char *Id(GBool &bDefault){ return GetParamStr(OGRSTBrushId,bDefault);} 00310 void SetId(const char *pszId){SetParamStr(OGRSTBrushId,pszId);} 00311 double Angle(GBool &bDefault){return GetParamDbl(OGRSTBrushAngle,bDefault);} 00312 void SetAngle(double dfAngle){SetParamDbl(OGRSTBrushAngle,dfAngle );} 00313 double Size(GBool &bDefault){return GetParamDbl(OGRSTBrushSize,bDefault);} 00314 void SetSize(double dfSize){SetParamDbl(OGRSTBrushSize,dfSize );} 00315 double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTBrushDx,bDefault);} 00316 void SetSpacingX(double dfX){SetParamDbl(OGRSTBrushDx,dfX );} 00317 double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTBrushDy,bDefault);} 00318 void SetSpacingY(double dfY){SetParamDbl(OGRSTBrushDy,dfY );} 00319 int Priority(GBool &bDefault){ return GetParamNum(OGRSTBrushPriority,bDefault);} 00320 void SetPriority(int nPriority){ SetParamNum(OGRSTBrushPriority,nPriority);} 00321 00322 00323 /*****************************************************************/ 00324 00325 const char *GetParamStr(OGRSTBrushParam eParam, GBool &bValueIsNull); 00326 int GetParamNum(OGRSTBrushParam eParam,GBool &bValueIsNull); 00327 double GetParamDbl(OGRSTBrushParam eParam,GBool &bValueIsNull); 00328 void SetParamStr(OGRSTBrushParam eParam, const char *pszParamString); 00329 void SetParamNum(OGRSTBrushParam eParam, int nParam); 00330 void SetParamDbl(OGRSTBrushParam eParam, double dfParam); 00331 const char *GetStyleString(); 00332 }; 00333 00337 class CPL_DLL OGRStyleSymbol : public OGRStyleTool 00338 { 00339 private: 00340 00341 OGRStyleValue *m_pasStyleValue; 00342 00343 GBool Parse(); 00344 00345 public: 00346 00347 OGRStyleSymbol(); 00348 virtual ~OGRStyleSymbol(); 00349 00350 /*****************************************************************/ 00351 /* Explicit fct for all parameters defined in the Drawing tools */ 00352 /*****************************************************************/ 00353 00354 const char *Id(GBool &bDefault){return GetParamStr(OGRSTSymbolId,bDefault);} 00355 void SetId(const char *pszId){ SetParamStr(OGRSTSymbolId,pszId);} 00356 double Angle(GBool &bDefault){ return GetParamDbl(OGRSTSymbolAngle,bDefault);} 00357 void SetAngle(double dfAngle){SetParamDbl(OGRSTSymbolAngle,dfAngle );} 00358 const char *Color(GBool &bDefault){return GetParamStr(OGRSTSymbolColor,bDefault);} 00359 void SetColor(const char *pszColor){SetParamStr(OGRSTSymbolColor,pszColor);} 00360 double Size(GBool &bDefault){ return GetParamDbl(OGRSTSymbolSize,bDefault);} 00361 void SetSize(double dfSize){ SetParamDbl(OGRSTSymbolSize,dfSize );} 00362 double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTSymbolDx,bDefault);} 00363 void SetSpacingX(double dfX){SetParamDbl(OGRSTSymbolDx,dfX );} 00364 double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTSymbolDy,bDefault);} 00365 void SetSpacingY(double dfY){SetParamDbl(OGRSTSymbolDy,dfY );} 00366 double Step(GBool &bDefault){return GetParamDbl(OGRSTSymbolStep,bDefault);} 00367 void SetStep(double dfStep){SetParamDbl(OGRSTSymbolStep,dfStep );} 00368 double Offset(GBool &bDefault){return GetParamDbl(OGRSTSymbolOffset,bDefault);} 00369 void SetOffset(double dfOffset){SetParamDbl(OGRSTSymbolOffset,dfOffset );} 00370 double Perp(GBool &bDefault){return GetParamDbl(OGRSTSymbolPerp,bDefault);} 00371 void SetPerp(double dfPerp){SetParamDbl(OGRSTSymbolPerp,dfPerp );} 00372 int Priority(GBool &bDefault){return GetParamNum(OGRSTSymbolPriority,bDefault);} 00373 void SetPriority(int nPriority){SetParamNum(OGRSTSymbolPriority,nPriority);} 00374 const char *FontName(GBool &bDefault) 00375 {return GetParamStr(OGRSTSymbolFontName,bDefault);} 00376 void SetFontName(const char *pszFontName) 00377 {SetParamStr(OGRSTSymbolFontName,pszFontName);} 00378 const char *OColor(GBool &bDefault){return GetParamStr(OGRSTSymbolOColor,bDefault);} 00379 void SetOColor(const char *pszColor){SetParamStr(OGRSTSymbolOColor,pszColor);} 00380 00381 /*****************************************************************/ 00382 00383 const char *GetParamStr(OGRSTSymbolParam eParam, GBool &bValueIsNull); 00384 int GetParamNum(OGRSTSymbolParam eParam,GBool &bValueIsNull); 00385 double GetParamDbl(OGRSTSymbolParam eParam,GBool &bValueIsNull); 00386 void SetParamStr(OGRSTSymbolParam eParam, const char *pszParamString); 00387 void SetParamNum(OGRSTSymbolParam eParam, int nParam); 00388 void SetParamDbl(OGRSTSymbolParam eParam, double dfParam); 00389 const char *GetStyleString(); 00390 }; 00391 00395 class CPL_DLL OGRStyleLabel : public OGRStyleTool 00396 { 00397 private: 00398 00399 OGRStyleValue *m_pasStyleValue; 00400 00401 GBool Parse(); 00402 00403 public: 00404 00405 OGRStyleLabel(); 00406 virtual ~OGRStyleLabel(); 00407 00408 /*****************************************************************/ 00409 /* Explicit fct for all parameters defined in the Drawing tools */ 00410 /*****************************************************************/ 00411 00412 const char *FontName(GBool &bDefault){return GetParamStr(OGRSTLabelFontName,bDefault);} 00413 void SetFontName(const char *pszFontName){SetParamStr(OGRSTLabelFontName,pszFontName);} 00414 double Size(GBool &bDefault){return GetParamDbl(OGRSTLabelSize,bDefault);} 00415 void SetSize(double dfSize){SetParamDbl(OGRSTLabelSize,dfSize);} 00416 const char *TextString(GBool &bDefault){return GetParamStr(OGRSTLabelTextString,bDefault);} 00417 void SetTextString(const char *pszTextString){SetParamStr(OGRSTLabelTextString,pszTextString);} 00418 double Angle(GBool &bDefault){return GetParamDbl(OGRSTLabelAngle,bDefault);} 00419 void SetAngle(double dfAngle){SetParamDbl(OGRSTLabelAngle,dfAngle);} 00420 const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTLabelFColor,bDefault);} 00421 void SetForColor(const char *pszForColor){SetParamStr(OGRSTLabelFColor,pszForColor);} 00422 const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTLabelBColor,bDefault);} 00423 void SetBackColor(const char *pszBackColor){SetParamStr(OGRSTLabelBColor,pszBackColor);} 00424 const char *Placement(GBool &bDefault){return GetParamStr(OGRSTLabelPlacement,bDefault);} 00425 void SetPlacement(const char *pszPlacement){SetParamStr(OGRSTLabelPlacement,pszPlacement);} 00426 int Anchor(GBool &bDefault){return GetParamNum(OGRSTLabelAnchor,bDefault);} 00427 void SetAnchor(int nAnchor){SetParamNum(OGRSTLabelAnchor,nAnchor);} 00428 double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTLabelDx,bDefault);} 00429 void SetSpacingX(double dfX){SetParamDbl(OGRSTLabelDx,dfX);} 00430 double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTLabelDy,bDefault);} 00431 void SetSpacingY(double dfY){SetParamDbl(OGRSTLabelDy,dfY);} 00432 double Perp(GBool &bDefault){return GetParamDbl(OGRSTLabelPerp,bDefault);} 00433 void SetPerp(double dfPerp){SetParamDbl(OGRSTLabelPerp,dfPerp);} 00434 GBool Bold(GBool &bDefault){return GetParamNum(OGRSTLabelBold,bDefault);} 00435 void SetBold(GBool bBold){SetParamNum(OGRSTLabelBold,bBold);} 00436 GBool Italic(GBool &bDefault){return GetParamNum(OGRSTLabelItalic,bDefault);} 00437 void SetItalic(GBool bItalic){SetParamNum(OGRSTLabelItalic,bItalic);} 00438 GBool Underline(GBool &bDefault){return GetParamNum(OGRSTLabelUnderline,bDefault);} 00439 void SetUnderline(GBool bUnderline){SetParamNum(OGRSTLabelUnderline,bUnderline);} 00440 int Priority(GBool &bDefault){return GetParamNum(OGRSTLabelPriority,bDefault);} 00441 void SetPriority(int nPriority){SetParamNum(OGRSTLabelPriority,nPriority);} 00442 GBool Strikeout(GBool &bDefault){return GetParamNum(OGRSTLabelStrikeout,bDefault);} 00443 void SetStrikeout(GBool bStrikeout){SetParamNum(OGRSTLabelStrikeout,bStrikeout);} 00444 double Stretch(GBool &bDefault){return GetParamDbl(OGRSTLabelStretch,bDefault);} 00445 void SetStretch(double dfStretch){SetParamDbl(OGRSTLabelStretch,dfStretch);} 00446 const char *AdjustmentHor(GBool &bDefault){return GetParamStr(OGRSTLabelAdjHor,bDefault);} 00447 void SetAdjustmentHor(const char *pszAdjustmentHor){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentHor);} 00448 const char *AdjustmentVert(GBool &bDefault){return GetParamStr(OGRSTLabelAdjVert,bDefault);} 00449 void SetAdjustmentVert(const char *pszAdjustmentVert){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentVert);} 00450 const char *ShadowColor(GBool &bDefault){return GetParamStr(OGRSTLabelHColor,bDefault);} 00451 void SetShadowColor(const char *pszShadowColor){SetParamStr(OGRSTLabelHColor,pszShadowColor);} 00452 const char *OutlineColor(GBool &bDefault){return GetParamStr(OGRSTLabelOColor,bDefault);} 00453 void SetOutlineColor(const char *pszOutlineColor){SetParamStr(OGRSTLabelOColor,pszOutlineColor);} 00454 00455 /*****************************************************************/ 00456 00457 const char *GetParamStr(OGRSTLabelParam eParam, GBool &bValueIsNull); 00458 int GetParamNum(OGRSTLabelParam eParam,GBool &bValueIsNull); 00459 double GetParamDbl(OGRSTLabelParam eParam,GBool &bValueIsNull); 00460 void SetParamStr(OGRSTLabelParam eParam, const char *pszParamString); 00461 void SetParamNum(OGRSTLabelParam eParam, int nParam); 00462 void SetParamDbl(OGRSTLabelParam eParam, double dfParam); 00463 const char *GetStyleString(); 00464 }; 00465 00466 #endif /* OGR_FEATURESTYLE_INCLUDE */