QGIS API Documentation  2.8.2-Wien
 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 
91  LinkedList<FeaturePart*> *featureParts;
92 
94  LinkedList<Feature*> *features;
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)
120  RTree<FeaturePart*, double, 2, double, 8, 4> *rtree;
121  HashTable<Feature*> *hashtable;
122 
123  HashTable< LinkedList<FeaturePart*>* > * connectedHashtable;
124  LinkedList< char* >* connectedTexts;
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