QGIS API Documentation  2.11.0-Master
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 #ifndef _LAYER_H_
31 #define _LAYER_H_
32 
33 #include <fstream>
34 
35 #include "pal.h"
36 #include "palgeometry.h"
37 #include <QMutex>
38 
39 namespace pal
40 {
41 
42  template <class Type> class LinkedList;
43  template <class Type> class Cell;
44  template <typename Data> class HashTable;
45 
46  template<class DATATYPE, class ELEMTYPE, int NUMDIMS, class ELEMTYPEREAL, int TMAXNODES, int TMINNODES> class RTree;
47 
48  class Feature;
49  class FeaturePart;
50  class Pal;
51  class LabelInfo;
52 
60  class CORE_EXPORT Layer
61  {
62  friend class Pal;
63  friend class FeaturePart;
64 
65  friend class Problem;
66 
67  friend class LabelPosition;
68  friend bool extractFeatCallback( FeaturePart *ft_ptr, void *ctx );
69  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 );
70 
71  public:
72  enum LabelMode { LabelPerFeature, LabelPerFeaturePart };
74  {
75  Upright, // upside-down labels (90 <= angle < 270) are shown upright
76  ShowDefined, // show upside down when rotation is layer- or data-defined
77  ShowAll // show upside down for all labels, including dynamic ones
78  };
79 
80  bool getDisplayAll() const { return displayAll; }
81 
85  int getNbFeatures();
86 
90  const char * getName();
91 
92 
96  Arrangement getArrangement();
97 
103  void setArrangement( Arrangement arrangement );
104 
105  unsigned long getArrangementFlags() const { return arrangementFlags; }
106  void setArrangementFlags( unsigned long flags ) { arrangementFlags = flags; }
107 
111  Units getLabelUnit();
112 
117  void setLabelUnit( Units label_unit );
118 
128  void setActive( bool active );
129 
133  bool isActive();
134 
135 
143  void setToLabel( bool toLabel );
144 
145 
149  bool isToLabel();
150 
151 
159  void setObstacle( bool obstacle );
160 
164  bool isObstacle();
165 
171  void setMinScale( double min_scale );
172 
176  double getMinScale();
177 
178 
184  void setMaxScale( double max_scale );
185 
186 
190  double getMaxScale();
191 
192 
199  void setPriority( double priority );
200 
201 
205  double getPriority();
206 
207  void setLabelMode( LabelMode m ) { mode = m; }
208  LabelMode getLabelMode() const { return mode; }
209 
210  void setMergeConnectedLines( bool m ) { mergeLines = m; }
211  bool getMergeConnectedLines() const { return mergeLines; }
212 
213  // void setRepeatDistance( double distance ) { repeatDistance = distance; }
214  // double getRepeatDistance() const { return repeatDistance; }
215 
216  void setUpsidedownLabels( UpsideDownLabels ud ) { upsidedownLabels = ud; }
217  UpsideDownLabels getUpsidedownLabels() const { return upsidedownLabels; }
218 
219  void setCentroidInside( bool forceInside ) { centroidInside = forceInside; }
220  bool getCentroidInside() const { return centroidInside; }
221 
246  bool registerFeature( const char *geom_id, PalGeometry *userGeom, double label_x = -1, double label_y = -1,
247  const char* labelText = NULL, double labelPosX = 0.0, double labelPosY = 0.0,
248  bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
249  int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
250  bool alwaysShow = false, double repeatDistance = 0 );
251 
253  Feature* getFeature( const char* geom_id );
254 
256  void joinConnectedFeatures();
257 
259  void chopFeaturesAtRepeatDistance();
260 
261  protected:
262  char *name; /* unique */
263 
266 
269 
271 
273 
274  bool obstacle;
275  bool active;
276  bool toLabel;
279 
281 
282  double min_scale;
283  double max_scale;
284 
287  unsigned long arrangementFlags;
290 
292 
293  // indexes (spatial and id)
296 
299 
301 
318  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 );
319 
323  virtual ~Layer();
324 
329  bool isScaleValid( double scale );
330 
332  void addFeaturePart( FeaturePart* fpart, const char* labelText = NULL );
333  };
334 
335 } // end namespace pal
336 
337 #endif
Arrangement arrangement
Optional flags used for some placement methods.
Definition: layer.h:286
unsigned long arrangementFlags
Definition: layer.h:287
double max_scale
Definition: layer.h:283
LabelMode mode
Definition: layer.h:288
bool toLabel
Definition: layer.h:276
bool displayAll
Definition: layer.h:277
bool obstacle
Definition: layer.h:274
A layer of spacial entites.
Definition: layer.h:60
LinkedList< FeaturePart * > * featureParts
List of feature parts.
Definition: layer.h:265
Pal main class.
Definition: pal.h:121
double defaultPriority
Definition: layer.h:272
UpsideDownLabels
Definition: layer.h:73
void setUpsidedownLabels(UpsideDownLabels ud)
Definition: layer.h:216
char * name
Definition: layer.h:262
LinkedList< char * > * connectedTexts
Definition: layer.h:298
void setCentroidInside(bool forceInside)
Definition: layer.h:219
bool getCentroidInside() const
Definition: layer.h:220
UpsideDownLabels getUpsidedownLabels() const
Definition: layer.h:217
Units label_unit
Definition: layer.h:280
LabelMode getLabelMode() const
Definition: layer.h:208
bool getDisplayAll() const
Definition: layer.h:80
Optional additional info about label (for curved labels)
Definition: feature.h:47
bool getMergeConnectedLines() const
Definition: layer.h:211
HashTable< Feature * > * hashtable
Definition: layer.h:295
bool centroidInside
Definition: layer.h:278
Main class to handle feature.
Definition: feature.h:133
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:222
static QgsFeature getFeature(const QVariant &value, QgsExpression *parent)
enum _arrangement Arrangement
Typedef for _arrangement enumeration.
Definition: pal.h:102
double min_scale
Definition: layer.h:282
Pal * pal
Definition: layer.h:270
LabelMode
Definition: layer.h:72
LinkedList< Feature * > * features
List of features - for deletion.
Definition: layer.h:268
UpsideDownLabels upsidedownLabels
Definition: layer.h:291
void setMergeConnectedLines(bool m)
Definition: layer.h:210
QMutex mMutex
Definition: layer.h:300
void setArrangementFlags(unsigned long flags)
Definition: layer.h:106
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
HashTable< LinkedList< FeaturePart * > * > * connectedHashtable
Definition: layer.h:297
Represent a problem.
Definition: problem.h:92
Interface that allows Pal to access user's geometries.
Definition: palgeometry.h:42
RTree< FeaturePart *, double, 2, double, 8, 4 > * rtree
Definition: layer.h:294
enum _Units Units
Typedef for _Units enumeration.
Definition: pal.h:72
bool mergeLines
Definition: layer.h:289
void setLabelMode(LabelMode m)
Definition: layer.h:207
bool active
Definition: layer.h:275
unsigned long getArrangementFlags() const
Definition: layer.h:105