QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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;
116 
118 
119  // indexes (spatial and id)
122 
125 
127 
144  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 );
145 
149  virtual ~Layer();
150 
155  bool isScaleValid( double scale );
156 
158  void addFeaturePart( FeaturePart* fpart, const char* labelText = NULL );
159 
160  public:
164  int getNbFeatures();
165 
169  const char * getName();
170 
171 
175  Arrangement getArrangement();
176 
182  void setArrangement( Arrangement arrangement );
183 
184  unsigned long getArrangementFlags() const { return arrangementFlags; }
185  void setArrangementFlags( unsigned long flags ) { arrangementFlags = flags; }
186 
190  Units getLabelUnit();
191 
196  void setLabelUnit( Units label_unit );
197 
207  void setActive( bool active );
208 
212  bool isActive();
213 
214 
222  void setToLabel( bool toLabel );
223 
224 
228  bool isToLabel();
229 
230 
238  void setObstacle( bool obstacle );
239 
243  bool isObstacle();
244 
250  void setMinScale( double min_scale );
251 
255  double getMinScale();
256 
257 
263  void setMaxScale( double max_scale );
264 
265 
269  double getMaxScale();
270 
271 
278  void setPriority( double priority );
279 
280 
284  double getPriority();
285 
286  void setLabelMode( LabelMode m ) { mode = m; }
287  LabelMode getLabelMode() const { return mode; }
288 
289  void setMergeConnectedLines( bool m ) { mergeLines = m; }
290  bool getMergeConnectedLines() const { return mergeLines; }
291 
292  // void setRepeatDistance( double distance ) { repeatDistance = distance; }
293  // double getRepeatDistance() const { return repeatDistance; }
294 
295  void setUpsidedownLabels( UpsideDownLabels ud ) { upsidedownLabels = ud; }
296  UpsideDownLabels getUpsidedownLabels() const { return upsidedownLabels; }
297 
298  void setCentroidInside( bool forceInside ) { centroidInside = forceInside; }
299  bool getCentroidInside() const { return centroidInside; }
300 
325  bool registerFeature( const char *geom_id, PalGeometry *userGeom, double label_x = -1, double label_y = -1,
326  const char* labelText = NULL, double labelPosX = 0.0, double labelPosY = 0.0,
327  bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
328  int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
329  bool alwaysShow = false, double repeatDistance = 0 );
330 
332  Feature* getFeature( const char* geom_id );
333 
335  void joinConnectedFeatures();
336 
338  void chopFeaturesAtRepeatDistance();
339 
340  };
341 
342 } // end namespace pal
343 
344 #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
LabelMode mode
Definition: layer.h:114
bool toLabel
Definition: layer.h:102
bool displayAll
Definition: layer.h:103
bool obstacle
Definition: layer.h:100
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:295
char * name
Definition: layer.h:88
LinkedList< char * > * connectedTexts
Definition: layer.h:124
void setCentroidInside(bool forceInside)
Definition: layer.h:298
bool getCentroidInside() const
Definition: layer.h:299
UpsideDownLabels getUpsidedownLabels() const
Definition: layer.h:296
Units label_unit
Definition: layer.h:106
LabelMode getLabelMode() const
Definition: layer.h:287
bool getDisplayAll() const
Definition: layer.h:85
optional additional info about label (for curved labels)
Definition: feature.h:52
bool getMergeConnectedLines() const
Definition: layer.h:290
HashTable< Feature * > * hashtable
Definition: layer.h:121
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)
bool extractFeatCallback(FeaturePart *ft_ptr, void *ctx)
Definition: pal.cpp:235
static QgsFeature getFeature(const QVariant &value, QgsExpression *parent)
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:117
void setMergeConnectedLines(bool m)
Definition: layer.h:289
void setArrangementFlags(unsigned long flags)
Definition: layer.h:185
LabelPosition is a candidate feature label position.
Definition: labelposition.h:54
HashTable< LinkedList< FeaturePart * > * > * connectedHashtable
Definition: layer.h:123
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:120
enum _Units Units
Typedef for _Units enumeration.
Definition: pal.h:77
bool mergeLines
Definition: layer.h:115
SimpleMutex * modMutex
Definition: layer.h:126
void setLabelMode(LabelMode m)
Definition: layer.h:286
bool active
Definition: layer.h:101
unsigned long getArrangementFlags() const
Definition: layer.h:184