QGIS API Documentation  2.6.0-Brighton
 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;
117 
119 
120  // indexes (spatial and id)
121  RTree<FeaturePart*, double, 2, double, 8, 4> *rtree;
122  HashTable<Feature*> *hashtable;
123 
124  HashTable< LinkedList<FeaturePart*>* > * connectedHashtable;
125  LinkedList< char* >* connectedTexts;
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