QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
layer.h
Go to the documentation of this file.
1 /*
2  * libpal - Automated Placement of Labels Library
3  *
4  * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5  * University of Applied Sciences, Western Switzerland
6  * http://www.hes-so.ch
7  *
8  * Contact:
9  * maxence.laurent <at> heig-vd <dot> ch
10  * or
11  * eric.taillard <at> heig-vd <dot> ch
12  *
13  * This file is part of libpal.
14  *
15  * libpal is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * libpal is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #ifndef _LAYER_H_
35 #define _LAYER_H_
36 
37 #include <fstream>
38 
39 #include <pal/pal.h>
40 #include <pal/palgeometry.h>
41 
42 
43 namespace pal
44 {
45 
46  template <class Type> class LinkedList;
47  template <class Type> class Cell;
48  template <typename Data> class HashTable;
49 
50  template<class DATATYPE, class ELEMTYPE, int NUMDIMS, class ELEMTYPEREAL, int TMAXNODES, int TMINNODES> class RTree;
51 
52  class Feature;
53  class FeaturePart;
54  class Pal;
55  class SimpleMutex;
56  class LabelInfo;
57 
65  class CORE_EXPORT Layer
66  {
67  friend class Pal;
68  friend class FeaturePart;
69 
70  friend class Problem;
71 
72  friend class LabelPosition;
73  friend bool extractFeatCallback( FeaturePart *ft_ptr, void *ctx );
74  friend void toSVGPath( int nbPoints, double *x, double *y, int dpi, Layer *layer, int type, char *uid, std::ostream &out, double scale, int xmin, int ymax, bool exportInfo, char *color );
75 
76  public:
77  enum LabelMode { LabelPerFeature, LabelPerFeaturePart };
79  {
80  Upright, // upside-down labels (90 <= angle < 270) are shown upright
81  ShowDefined, // show upside down when rotation is layer- or data-defined
82  ShowAll // show upside down for all labels, including dynamic ones
83  };
84 
85  bool getDisplayAll() const { return displayAll; }
86 
87  protected:
88  char *name; /* unique */
89 
92 
95 
96  Pal *pal;
97 
99 
100  bool obstacle;
101  bool active;
102  bool toLabel;
105 
107 
108  double min_scale;
109  double max_scale;
110 
113  unsigned long arrangementFlags;
117 
119 
120  // indexes (spatial and id)
123 
126 
128 
145  Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll = false );
146 
150  virtual ~Layer();
151 
156  bool isScaleValid( double scale );
157 
159  void addFeaturePart( FeaturePart* fpart, const char* labelText = NULL );
160 
161  public:
165  int getNbFeatures();
166 
170  const char * getName();
171 
172 
176  Arrangement getArrangement();
177 
183  void setArrangement( Arrangement arrangement );
184 
185  unsigned long getArrangementFlags() const { return arrangementFlags; }
186  void setArrangementFlags( unsigned long flags ) { arrangementFlags = flags; }
187 
191  Units getLabelUnit();
192 
197  void setLabelUnit( Units label_unit );
198 
208  void setActive( bool active );
209 
213  bool isActive();
214 
215 
223  void setToLabel( bool toLabel );
224 
225 
229  bool isToLabel();
230 
231 
239  void setObstacle( bool obstacle );
240 
244  bool isObstacle();
245 
251  void setMinScale( double min_scale );
252 
256  double getMinScale();
257 
258 
264  void setMaxScale( double max_scale );
265 
266 
270  double getMaxScale();
271 
272 
279  void setPriority( double priority );
280 
281 
285  double getPriority();
286 
287  void setLabelMode( LabelMode m ) { mode = m; }
288  LabelMode getLabelMode() const { return mode; }
289 
290  void setMergeConnectedLines( bool m ) { mergeLines = m; }
291  bool getMergeConnectedLines() const { return mergeLines; }
292 
293  void setRepeatDistance( double distance ) { repeatDistance = distance; }
294  double getRepeatDistance() const { return repeatDistance; }
295 
296  void setUpsidedownLabels( UpsideDownLabels ud ) { upsidedownLabels = ud; }
297  UpsideDownLabels getUpsidedownLabels() const { return upsidedownLabels; }
298 
299  void setCentroidInside( bool forceInside ) { centroidInside = forceInside; }
300  bool getCentroidInside() const { return centroidInside; }
301 
326  bool registerFeature( const char *geom_id, PalGeometry *userGeom, double label_x = -1, double label_y = -1,
327  const char* labelText = NULL, double labelPosX = 0.0, double labelPosY = 0.0,
328  bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
329  int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
330  bool alwaysShow = false, double repeatDistance = 0 );
331 
333  Feature* getFeature( const char* geom_id );
334 
336  void joinConnectedFeatures();
337 
339  void chopFeaturesAtRepeatDistance();
340 
341  };
342 
343 } // end namespace pal
344 
345 #endif
Arrangement arrangement
optional flags used for some placement methods
Definition: layer.h:112
unsigned long arrangementFlags
Definition: layer.h:113
double max_scale
Definition: layer.h:109
Definition: layer.h:81
LabelMode mode
Definition: layer.h:114
bool toLabel
Definition: layer.h:102
bool displayAll
Definition: layer.h:103
bool obstacle
Definition: layer.h:100
Definition: layer.h:47
A layer of spacial entites.
Definition: layer.h:65
LinkedList< FeaturePart * > * featureParts
list of feature parts
Definition: layer.h:91
Pal main class.
Definition: pal.h:126
double defaultPriority
Definition: layer.h:98
UpsideDownLabels
Definition: layer.h:78
void setUpsidedownLabels(UpsideDownLabels ud)
Definition: layer.h:296
char * name
Definition: layer.h:88
LinkedList< char * > * connectedTexts
Definition: layer.h:125
void setRepeatDistance(double distance)
Definition: layer.h:293
void setCentroidInside(bool forceInside)
Definition: layer.h:299
bool getCentroidInside() const
Definition: layer.h:300
Definition: feature.h:82
double getRepeatDistance() const
Definition: layer.h:294
UpsideDownLabels getUpsidedownLabels() const
Definition: layer.h:297
Definition: layer.h:50
Units label_unit
Definition: layer.h:106
LabelMode getLabelMode() const
Definition: layer.h:288
Definition: simplemutex.h:64
bool getDisplayAll() const
Definition: layer.h:85
Definition: layer.h:80
optional additional info about label (for curved labels)
Definition: feature.h:52
bool getMergeConnectedLines() const
Definition: layer.h:291
HashTable< Feature * > * hashtable
Definition: layer.h:122
bool centroidInside
Definition: layer.h:104
Main class to handle feature.
Definition: feature.h:138
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
double repeatDistance
Definition: layer.h:116
bool extractFeatCallback(FeaturePart *ft_ptr, void *ctx)
Definition: pal.cpp:233
Definition: qgsdiagramrendererv2.h:37
static QgsFeature getFeature(const QVariant &value, QgsExpression *parent)
Definition: qgsexpression.cpp:324
enum _arrangement Arrangement
typedef for _arrangement enumeration
Definition: pal.h:107
double min_scale
Definition: layer.h:108
Pal * pal
Definition: layer.h:96
LabelMode
Definition: layer.h:77
LinkedList< Feature * > * features
list of features - for deletion
Definition: layer.h:94
UpsideDownLabels upsidedownLabels
Definition: layer.h:118
Definition: layer.h:46
Definition: layer.h:48
void setMergeConnectedLines(bool m)
Definition: layer.h:290
void setArrangementFlags(unsigned long flags)
Definition: layer.h:186
LabelPositon is a candidate feature label position.
Definition: labelposition.h:53
HashTable< LinkedList< FeaturePart * > * > * connectedHashtable
Definition: layer.h:124
Represent a problem.
Definition: problem.h:96
Interface that allows Pal to access user's geometries.
Definition: palgeometry.h:42
RTree< FeaturePart *, double, 2, double, 8, 4 > * rtree
Definition: layer.h:121
enum _Units Units
Typedef for _Units enumeration.
Definition: pal.h:77
bool mergeLines
Definition: layer.h:115
SimpleMutex * modMutex
Definition: layer.h:127
void setLabelMode(LabelMode m)
Definition: layer.h:287
bool active
Definition: layer.h:101
unsigned long getArrangementFlags() const
Definition: layer.h:185