GDAL
ogr_featurestyle.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_featurestyle.h 33631 2016-03-04 06:28:09Z goatbar $
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Define of Feature Representation
6  * Author: Stephane Villeneuve, stephane.v@videtron.ca
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Frank Warmerdam
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef OGR_FEATURESTYLE_INCLUDE
31 #define OGR_FEATURESTYLE_INCLUDE
32 
33 #include "cpl_conv.h"
34 #include "cpl_string.h"
35 #include "ogr_core.h"
36 
37 class OGRFeature;
38 
45 /*
46  * All OGRStyleTool param lists are defined in ogr_core.h.
47  */
48 
49 typedef enum ogr_style_type
50 {
51  OGRSTypeString,
52  OGRSTypeDouble,
53  OGRSTypeInteger,
54  OGRSTypeBoolean
55 } OGRSType;
56 
57 typedef struct ogr_style_param
58 {
59  int eParam;
60  const char *pszToken;
61  GBool bGeoref;
62  OGRSType eType;
64 
65 
66 typedef struct ogr_style_value
67 {
68  char *pszValue;
69  double dfValue;
70  int nValue; // Used for both integer and boolean types
71  GBool bValid;
72  OGRSTUnitId eUnit;
74 
75 
76 // Every time a pszStyleString given in parameter is NULL,
77 // the StyleString defined in the Mgr will be use.
78 
82 class CPL_DLL OGRStyleTable
83 {
84  private:
85  char **m_papszStyleTable;
86 
87  CPLString osLastRequestedStyleName;
88  int iNextStyle;
89 
90  public:
91  OGRStyleTable();
92  ~OGRStyleTable();
93  GBool AddStyle(const char *pszName,const char *pszStyleString);
94  GBool RemoveStyle(const char *pszName);
95  GBool ModifyStyle(const char *pszName, const char *pszStyleString);
96 
97  GBool SaveStyleTable(const char *pszFilename);
98  GBool LoadStyleTable(const char *pszFilename);
99  const char *Find(const char *pszStyleString);
100  GBool IsExist(const char *pszName);
101  const char *GetStyleName(const char *pszName);
102  void Print(FILE *fpOut);
103  void Clear();
104  OGRStyleTable *Clone();
105  void ResetStyleStringReading();
106  const char *GetNextStyle();
107  const char *GetLastStyleName();
108 };
109 
110 
111 class OGRStyleTool;
112 
116 class CPL_DLL OGRStyleMgr
117 {
118  private:
119  OGRStyleTable *m_poDataSetStyleTable;
120  char *m_pszStyleString;
121 
122  public:
123  OGRStyleMgr(OGRStyleTable *poDataSetStyleTable = NULL);
124  ~OGRStyleMgr();
125 
126  GBool SetFeatureStyleString(OGRFeature *,const char *pszStyleString=NULL,
127  GBool bNoMatching = FALSE);
128  /* It will set in the given feature the pszStyleString with
129  the style or will set the style name found in
130  dataset StyleTable (if bNoMatching == FALSE). */
131 
132  const char *InitFromFeature(OGRFeature *);
133  GBool InitStyleString(const char *pszStyleString = NULL);
134 
135  const char *GetStyleName(const char *pszStyleString= NULL);
136  const char *GetStyleByName(const char *pszStyleName);
137 
138  GBool AddStyle(const char *pszStyleName, const char *pszStyleString=NULL);
139 
140  const char *GetStyleString(OGRFeature * = NULL);
141 
142  GBool AddPart(OGRStyleTool *);
143  GBool AddPart(const char *);
144 
145  int GetPartCount(const char *pszStyleString = NULL);
146  OGRStyleTool *GetPart(int hPartId, const char *pszStyleString = NULL);
147 
148  /* It could have a reference counting process us for the OGRStyleTable, if
149  needed. */
150 
151  OGRStyleTable *GetDataSetStyleTable(){return m_poDataSetStyleTable;}
152 
153  OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString);
154 
155 };
156 
160 class CPL_DLL OGRStyleTool
161 {
162  private:
163  GBool m_bModified;
164  GBool m_bParsed;
165  double m_dfScale;
166  OGRSTUnitId m_eUnit;
167  OGRSTClassId m_eClassId;
168  char *m_pszStyleString;
169 
170  virtual GBool Parse() = 0;
171 
172  protected:
173  GBool Parse(const OGRStyleParamId* pasStyle,
174  OGRStyleValue* pasValue,
175  int nCount);
176 
177  public:
178 
179  OGRStyleTool(){}
180  OGRStyleTool(OGRSTClassId eClassId);
181  virtual ~OGRStyleTool();
182 
183  GBool GetRGBFromString(const char *pszColor, int &nRed, int &nGreen,
184  int &nBlue, int &nTransparence);
185  int GetSpecificId(const char *pszId, const char *pszWanted);
186 
187  GBool IsStyleModified() {return m_bModified;}
188  void StyleModified() {m_bModified = TRUE;}
189 
190  GBool IsStyleParsed() {return m_bParsed;}
191  void StyleParsed() {m_bParsed = TRUE;}
192 
193  OGRSTClassId GetType();
194 
195  void SetInternalInputUnitFromParam(char *pszString);
196 
197  void SetUnit(OGRSTUnitId,double dfScale = 1.0); //the dfScale will be
198  //used if we are working with Ground Unit ( ground = paper * scale);
199 
200  OGRSTUnitId GetUnit(){return m_eUnit;}
201 
202  // There are two way to set the parameters in the Style, with generic
203  // methods (using a defined enumeration) or with the reel method specific
204  // for Each style tools.
205 
206  virtual const char *GetStyleString() = 0;
207  void SetStyleString(const char *pszStyleString);
208  const char *GetStyleString(const OGRStyleParamId *pasStyleParam ,
209  OGRStyleValue *pasStyleValue, int nSize);
210 
211  const char *GetParamStr(const OGRStyleParamId &sStyleParam ,
212  OGRStyleValue &sStyleValue,
213  GBool &bValueIsNull);
214 
215  int GetParamNum(const OGRStyleParamId &sStyleParam ,
216  OGRStyleValue &sStyleValue,
217  GBool &bValueIsNull);
218 
219  double GetParamDbl(const OGRStyleParamId &sStyleParam ,
220  OGRStyleValue &sStyleValue,
221  GBool &bValueIsNull);
222 
223  void SetParamStr(const OGRStyleParamId &sStyleParam ,
224  OGRStyleValue &sStyleValue,
225  const char *pszParamString);
226 
227  void SetParamNum(const OGRStyleParamId &sStyleParam ,
228  OGRStyleValue &sStyleValue,
229  int nParam);
230 
231  void SetParamDbl(const OGRStyleParamId &sStyleParam ,
232  OGRStyleValue &sStyleValue,
233  double dfParam);
234 
235  double ComputeWithUnit(double, OGRSTUnitId);
236  int ComputeWithUnit(int , OGRSTUnitId);
237 
238 };
239 
243 class CPL_DLL OGRStylePen : public OGRStyleTool
244 {
245  private:
246 
247  OGRStyleValue *m_pasStyleValue;
248 
249  GBool Parse();
250 
251  public:
252 
253  OGRStylePen();
254  virtual ~OGRStylePen();
255 
256  /**********************************************************************/
257  /* Explicit fct for all parameters defined in the Drawing tools Pen */
258  /**********************************************************************/
259 
260  const char *Color(GBool &bDefault){return GetParamStr(OGRSTPenColor,bDefault);}
261  void SetColor(const char *pszColor){SetParamStr(OGRSTPenColor,pszColor);}
262  double Width(GBool &bDefault){return GetParamDbl(OGRSTPenWidth,bDefault);}
263  void SetWidth(double dfWidth){SetParamDbl(OGRSTPenWidth,dfWidth);}
264  const char *Pattern(GBool &bDefault){return (const char *)GetParamStr(OGRSTPenPattern,bDefault);}
265  void SetPattern(const char *pszPattern){SetParamStr(OGRSTPenPattern,pszPattern);}
266  const char *Id(GBool &bDefault){return GetParamStr(OGRSTPenId,bDefault);}
267  void SetId(const char *pszId){SetParamStr(OGRSTPenId,pszId);}
268  double PerpendicularOffset(GBool &bDefault){return GetParamDbl(OGRSTPenPerOffset,bDefault);}
269  void SetPerpendicularOffset(double dfPerp){SetParamDbl(OGRSTPenPerOffset,dfPerp);}
270  const char *Cap(GBool &bDefault){return GetParamStr(OGRSTPenCap,bDefault);}
271  void SetCap(const char *pszCap){SetParamStr(OGRSTPenCap,pszCap);}
272  const char *Join(GBool &bDefault){return GetParamStr(OGRSTPenJoin,bDefault);}
273  void SetJoin(const char *pszJoin){SetParamStr(OGRSTPenJoin,pszJoin);}
274  int Priority(GBool &bDefault){return GetParamNum(OGRSTPenPriority,bDefault);}
275  void SetPriority(int nPriority){SetParamNum(OGRSTPenPriority,nPriority);}
276 
277  /*****************************************************************/
278 
279  const char *GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull);
280  int GetParamNum(OGRSTPenParam eParam,GBool &bValueIsNull);
281  double GetParamDbl(OGRSTPenParam eParam,GBool &bValueIsNull);
282  void SetParamStr(OGRSTPenParam eParam, const char *pszParamString);
283  void SetParamNum(OGRSTPenParam eParam, int nParam);
284  void SetParamDbl(OGRSTPenParam eParam, double dfParam);
285  const char *GetStyleString();
286 };
287 
291 class CPL_DLL OGRStyleBrush : public OGRStyleTool
292 {
293  private:
294 
295  OGRStyleValue *m_pasStyleValue;
296 
297  GBool Parse();
298 
299  public:
300 
301  OGRStyleBrush();
302  virtual ~OGRStyleBrush();
303 
304  /* Explicit fct for all parameters defined in the Drawing tools Brush */
305 
306  const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTBrushFColor,bDefault);}
307  void SetForeColor(const char *pszColor){SetParamStr(OGRSTBrushFColor,pszColor);}
308  const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTBrushBColor,bDefault);}
309  void SetBackColor(const char *pszColor){SetParamStr(OGRSTBrushBColor,pszColor);}
310  const char *Id(GBool &bDefault){ return GetParamStr(OGRSTBrushId,bDefault);}
311  void SetId(const char *pszId){SetParamStr(OGRSTBrushId,pszId);}
312  double Angle(GBool &bDefault){return GetParamDbl(OGRSTBrushAngle,bDefault);}
313  void SetAngle(double dfAngle){SetParamDbl(OGRSTBrushAngle,dfAngle );}
314  double Size(GBool &bDefault){return GetParamDbl(OGRSTBrushSize,bDefault);}
315  void SetSize(double dfSize){SetParamDbl(OGRSTBrushSize,dfSize );}
316  double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTBrushDx,bDefault);}
317  void SetSpacingX(double dfX){SetParamDbl(OGRSTBrushDx,dfX );}
318  double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTBrushDy,bDefault);}
319  void SetSpacingY(double dfY){SetParamDbl(OGRSTBrushDy,dfY );}
320  int Priority(GBool &bDefault){ return GetParamNum(OGRSTBrushPriority,bDefault);}
321  void SetPriority(int nPriority){ SetParamNum(OGRSTBrushPriority,nPriority);}
322 
323  /*****************************************************************/
324 
325  const char *GetParamStr(OGRSTBrushParam eParam, GBool &bValueIsNull);
326  int GetParamNum(OGRSTBrushParam eParam,GBool &bValueIsNull);
327  double GetParamDbl(OGRSTBrushParam eParam,GBool &bValueIsNull);
328  void SetParamStr(OGRSTBrushParam eParam, const char *pszParamString);
329  void SetParamNum(OGRSTBrushParam eParam, int nParam);
330  void SetParamDbl(OGRSTBrushParam eParam, double dfParam);
331  const char *GetStyleString();
332 };
333 
337 class CPL_DLL OGRStyleSymbol : public OGRStyleTool
338 {
339  private:
340 
341  OGRStyleValue *m_pasStyleValue;
342 
343  GBool Parse();
344 
345  public:
346 
347  OGRStyleSymbol();
348  virtual ~OGRStyleSymbol();
349 
350  /*****************************************************************/
351  /* Explicit fct for all parameters defined in the Drawing tools */
352  /*****************************************************************/
353 
354  const char *Id(GBool &bDefault){return GetParamStr(OGRSTSymbolId,bDefault);}
355  void SetId(const char *pszId){ SetParamStr(OGRSTSymbolId,pszId);}
356  double Angle(GBool &bDefault){ return GetParamDbl(OGRSTSymbolAngle,bDefault);}
357  void SetAngle(double dfAngle){SetParamDbl(OGRSTSymbolAngle,dfAngle );}
358  const char *Color(GBool &bDefault){return GetParamStr(OGRSTSymbolColor,bDefault);}
359  void SetColor(const char *pszColor){SetParamStr(OGRSTSymbolColor,pszColor);}
360  double Size(GBool &bDefault){ return GetParamDbl(OGRSTSymbolSize,bDefault);}
361  void SetSize(double dfSize){ SetParamDbl(OGRSTSymbolSize,dfSize );}
362  double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTSymbolDx,bDefault);}
363  void SetSpacingX(double dfX){SetParamDbl(OGRSTSymbolDx,dfX );}
364  double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTSymbolDy,bDefault);}
365  void SetSpacingY(double dfY){SetParamDbl(OGRSTSymbolDy,dfY );}
366  double Step(GBool &bDefault){return GetParamDbl(OGRSTSymbolStep,bDefault);}
367  void SetStep(double dfStep){SetParamDbl(OGRSTSymbolStep,dfStep );}
368  double Offset(GBool &bDefault){return GetParamDbl(OGRSTSymbolOffset,bDefault);}
369  void SetOffset(double dfOffset){SetParamDbl(OGRSTSymbolOffset,dfOffset );}
370  double Perp(GBool &bDefault){return GetParamDbl(OGRSTSymbolPerp,bDefault);}
371  void SetPerp(double dfPerp){SetParamDbl(OGRSTSymbolPerp,dfPerp );}
372  int Priority(GBool &bDefault){return GetParamNum(OGRSTSymbolPriority,bDefault);}
373  void SetPriority(int nPriority){SetParamNum(OGRSTSymbolPriority,nPriority);}
374  const char *FontName(GBool &bDefault)
375  {return GetParamStr(OGRSTSymbolFontName,bDefault);}
376  void SetFontName(const char *pszFontName)
377  {SetParamStr(OGRSTSymbolFontName,pszFontName);}
378  const char *OColor(GBool &bDefault){return GetParamStr(OGRSTSymbolOColor,bDefault);}
379  void SetOColor(const char *pszColor){SetParamStr(OGRSTSymbolOColor,pszColor);}
380 
381  /*****************************************************************/
382 
383  const char *GetParamStr(OGRSTSymbolParam eParam, GBool &bValueIsNull);
384  int GetParamNum(OGRSTSymbolParam eParam,GBool &bValueIsNull);
385  double GetParamDbl(OGRSTSymbolParam eParam,GBool &bValueIsNull);
386  void SetParamStr(OGRSTSymbolParam eParam, const char *pszParamString);
387  void SetParamNum(OGRSTSymbolParam eParam, int nParam);
388  void SetParamDbl(OGRSTSymbolParam eParam, double dfParam);
389  const char *GetStyleString();
390 };
391 
395 class CPL_DLL OGRStyleLabel : public OGRStyleTool
396 {
397  private:
398 
399  OGRStyleValue *m_pasStyleValue;
400 
401  GBool Parse();
402 
403  public:
404 
405  OGRStyleLabel();
406  virtual ~OGRStyleLabel();
407 
408  /*****************************************************************/
409  /* Explicit fct for all parameters defined in the Drawing tools */
410  /*****************************************************************/
411 
412  const char *FontName(GBool &bDefault){return GetParamStr(OGRSTLabelFontName,bDefault);}
413  void SetFontName(const char *pszFontName){SetParamStr(OGRSTLabelFontName,pszFontName);}
414  double Size(GBool &bDefault){return GetParamDbl(OGRSTLabelSize,bDefault);}
415  void SetSize(double dfSize){SetParamDbl(OGRSTLabelSize,dfSize);}
416  const char *TextString(GBool &bDefault){return GetParamStr(OGRSTLabelTextString,bDefault);}
417  void SetTextString(const char *pszTextString){SetParamStr(OGRSTLabelTextString,pszTextString);}
418  double Angle(GBool &bDefault){return GetParamDbl(OGRSTLabelAngle,bDefault);}
419  void SetAngle(double dfAngle){SetParamDbl(OGRSTLabelAngle,dfAngle);}
420  const char *ForeColor(GBool &bDefault){return GetParamStr(OGRSTLabelFColor,bDefault);}
421  void SetForColor(const char *pszForColor){SetParamStr(OGRSTLabelFColor,pszForColor);}
422  const char *BackColor(GBool &bDefault){return GetParamStr(OGRSTLabelBColor,bDefault);}
423  void SetBackColor(const char *pszBackColor){SetParamStr(OGRSTLabelBColor,pszBackColor);}
424  const char *Placement(GBool &bDefault){return GetParamStr(OGRSTLabelPlacement,bDefault);}
425  void SetPlacement(const char *pszPlacement){SetParamStr(OGRSTLabelPlacement,pszPlacement);}
426  int Anchor(GBool &bDefault){return GetParamNum(OGRSTLabelAnchor,bDefault);}
427  void SetAnchor(int nAnchor){SetParamNum(OGRSTLabelAnchor,nAnchor);}
428  double SpacingX(GBool &bDefault){return GetParamDbl(OGRSTLabelDx,bDefault);}
429  void SetSpacingX(double dfX){SetParamDbl(OGRSTLabelDx,dfX);}
430  double SpacingY(GBool &bDefault){return GetParamDbl(OGRSTLabelDy,bDefault);}
431  void SetSpacingY(double dfY){SetParamDbl(OGRSTLabelDy,dfY);}
432  double Perp(GBool &bDefault){return GetParamDbl(OGRSTLabelPerp,bDefault);}
433  void SetPerp(double dfPerp){SetParamDbl(OGRSTLabelPerp,dfPerp);}
434  GBool Bold(GBool &bDefault){return GetParamNum(OGRSTLabelBold,bDefault);}
435  void SetBold(GBool bBold){SetParamNum(OGRSTLabelBold,bBold);}
436  GBool Italic(GBool &bDefault){return GetParamNum(OGRSTLabelItalic,bDefault);}
437  void SetItalic(GBool bItalic){SetParamNum(OGRSTLabelItalic,bItalic);}
438  GBool Underline(GBool &bDefault){return GetParamNum(OGRSTLabelUnderline,bDefault);}
439  void SetUnderline(GBool bUnderline){SetParamNum(OGRSTLabelUnderline,bUnderline);}
440  int Priority(GBool &bDefault){return GetParamNum(OGRSTLabelPriority,bDefault);}
441  void SetPriority(int nPriority){SetParamNum(OGRSTLabelPriority,nPriority);}
442  GBool Strikeout(GBool &bDefault){return GetParamNum(OGRSTLabelStrikeout,bDefault);}
443  void SetStrikeout(GBool bStrikeout){SetParamNum(OGRSTLabelStrikeout,bStrikeout);}
444  double Stretch(GBool &bDefault){return GetParamDbl(OGRSTLabelStretch,bDefault);}
445  void SetStretch(double dfStretch){SetParamDbl(OGRSTLabelStretch,dfStretch);}
446  const char *AdjustmentHor(GBool &bDefault){return GetParamStr(OGRSTLabelAdjHor,bDefault);}
447  void SetAdjustmentHor(const char *pszAdjustmentHor){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentHor);}
448  const char *AdjustmentVert(GBool &bDefault){return GetParamStr(OGRSTLabelAdjVert,bDefault);}
449  void SetAdjustmentVert(const char *pszAdjustmentVert){SetParamStr(OGRSTLabelAdjHor,pszAdjustmentVert);}
450  const char *ShadowColor(GBool &bDefault){return GetParamStr(OGRSTLabelHColor,bDefault);}
451  void SetShadowColor(const char *pszShadowColor){SetParamStr(OGRSTLabelHColor,pszShadowColor);}
452  const char *OutlineColor(GBool &bDefault){return GetParamStr(OGRSTLabelOColor,bDefault);}
453  void SetOutlineColor(const char *pszOutlineColor){SetParamStr(OGRSTLabelOColor,pszOutlineColor);}
454 
455  /*****************************************************************/
456 
457  const char *GetParamStr(OGRSTLabelParam eParam, GBool &bValueIsNull);
458  int GetParamNum(OGRSTLabelParam eParam,GBool &bValueIsNull);
459  double GetParamDbl(OGRSTLabelParam eParam,GBool &bValueIsNull);
460  void SetParamStr(OGRSTLabelParam eParam, const char *pszParamString);
461  void SetParamNum(OGRSTLabelParam eParam, int nParam);
462  void SetParamDbl(OGRSTLabelParam eParam, double dfParam);
463  const char *GetStyleString();
464 };
465 
466 #endif /* OGR_FEATURESTYLE_INCLUDE */
enum ogr_style_tool_param_symbol_id OGRSTSymbolParam
List of parameters for use with OGRStyleSymbol.
enum ogr_style_tool_param_brush_id OGRSTBrushParam
List of parameters for use with OGRStyleBrush.
enum ogr_style_tool_param_label_id OGRSTLabelParam
List of parameters for use with OGRStyleLabel.
Convenient string class based on std::string.
Definition: cpl_string.h:283
This class represents a style manager.
Definition: ogr_featurestyle.h:116
Various convenience functions for working with strings and string lists.
enum ogr_style_tool_class_id OGRSTClassId
OGRStyleTool derived class types (returned by GetType()).
This class represents a style pen.
Definition: ogr_featurestyle.h:243
enum ogr_style_tool_param_pen_id OGRSTPenParam
List of parameters for use with OGRStylePen.
enum ogr_style_tool_units_id OGRSTUnitId
List of units supported by OGRStyleTools.
This class represents a style label.
Definition: ogr_featurestyle.h:395
Core portability services for cross-platform OGR code.
Various convenience functions for CPL.
This class represents a style symbol.
Definition: ogr_featurestyle.h:337
This class represents a style tool.
Definition: ogr_featurestyle.h:160
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:274
This class represents a style table.
Definition: ogr_featurestyle.h:82
Definition: ogr_featurestyle.h:57
This class represents a style brush.
Definition: ogr_featurestyle.h:291
Definition: ogr_featurestyle.h:66

Generated for GDAL by doxygen 1.8.6.