QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pal.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 _PAL_H
35 #define _PAL_H
36 
37 
38 #include <QList>
39 #include <iostream>
40 #include <ctime>
41 
42 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
43 
52 namespace pal
53 {
54 
55  template <class Type> class LinkedList;
56 
57  class Layer;
58  class LabelPosition;
59  class PalStat;
60  class Problem;
61  class PointSet;
62  class SimpleMutex;
63 
65  enum _Units
66  {
67  PIXEL = 0,
69  FOOT,
71  };
72 
74  typedef enum _Units Units;
75 
78  {
79  CHAIN = 0,
83  FALP = 4
84  };
85 
88 
94  {
95  P_POINT = 0,
101  };
102 
104  typedef enum _arrangement Arrangement;
105 
108  {
113  };
114 
123  class CORE_EXPORT Pal
124  {
125  friend class Problem;
126  friend class FeaturePart;
127  friend class Layer;
128  private:
129  QList<Layer*> *layers;
130 
131  SimpleMutex *lyrsMutex;
132 
133  // TODO remove after tests !!!
134  clock_t tmpTime;
135 
136  Units map_unit;
137 
141  int point_p;
142 
146  int line_p;
147 
151  int poly_p;
152 
153  SearchMethod searchMethod;
154 
155  /*
156  * POPMUSIC Tuning
157  */
158  int popmusic_r;
159 
160  int tabuMaxIt;
161  int tabuMinIt;
162 
163  int dpi;
164 
165  int ejChainDeg;
166  int tenure;
167  double candListSize;
168 
172  bool showPartial;
173 
174 
175  typedef bool ( *FnIsCancelled )( void* ctx );
177  FnIsCancelled fnIsCancelled;
179  void* fnIsCancelledContext;
180 
196  Problem* extract( int nbLayers, char **layersName, double *layersFactor,
197  double lambda_min, double phi_min,
198  double lambda_max, double phi_max,
199  double scale, std::ofstream *svgmap );
200 
201 
206  void setPopmusicR( int r );
207 
208 
209 
214  void setMinIt( int min_it );
215 
220  void setMaxIt( int max_it );
221 
226  void setTenure( int tenure );
227 
232  void setEjChainDeg( int degree );
233 
238  void setCandListSize( double fact );
239 
240 
245  int getMinIt();
250  int getMaxIt();
251 
252 
253  public:
254 
258  Pal();
259 
263  ~Pal();
264 
283  Layer * addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll = false );
284 
294  Layer *getLayer( const char *lyrName );
295 
301  QList<Layer*> *getLayers();
302 
308  void removeLayer( Layer *layer );
309 
321  std::list<LabelPosition*> *labeller( double scale, double bbox[4], PalStat **stats, bool displayAll );
322 
323 
341  std::list<LabelPosition*> *labeller( int nbLayers,
342  char **layersName,
343  double *layersFactor,
344  double scale, double bbox[4],
345  PalStat **stat,
346  bool displayAll );
347 
349  void registerCancellationCallback( FnIsCancelled fnCancelled, void* context );
350 
352  inline bool isCancelled() { return fnIsCancelled ? fnIsCancelled( fnIsCancelledContext ) : false; }
353 
354  Problem* extractProblem( double scale, double bbox[4] );
355 
356  std::list<LabelPosition*>* solveProblem( Problem* prob, bool displayAll );
357 
363  void setDpi( int dpi );
364 
370  int getDpi();
371 
377  void setShowPartial( bool show );
378 
384  bool getShowPartial();
385 
392  void setPointP( int point_p );
393 
400  void setLineP( int line_p );
401 
408  void setPolyP( int poly_p );
409 
413  int getPointP();
414 
418  int getLineP();
419 
423  int getPolyP();
424 
428  Units getMapUnit();
429 
433  void setMapUnit( Units map_unit );
434 
443  void setSearch( SearchMethod method );
444 
450  SearchMethod getSearch();
451  };
452 } // end namespace pal
453 #endif
foot [ft]
Definition: pal.h:69
Definition: pal.h:112
A layer of spacial entites.
Definition: layer.h:65
is the best but slowest
Definition: pal.h:80
degree [°]
Definition: pal.h:70
Pal main class.
Definition: pal.h:123
bool isCancelled()
Check whether the job has been cancelled.
Definition: pal.h:352
_arrangement
The way to arrange labels against spatial entities.
Definition: pal.h:93
arranges candidates around a point (centroid for polygon)
Definition: pal.h:95
_Units
Units for label sizes and distlabel.
Definition: pal.h:65
Definition: pal.h:111
Definition: simplemutex.h:64
arranges candidates over a point (centroid for polygon)
Definition: pal.h:97
Only for lines, labels along the line.
Definition: pal.h:99
Definition: pal.h:110
Main class to handle feature.
Definition: feature.h:138
pixel [px]
Definition: pal.h:67
LineArrangementFlags
enumeration line arrangement flags.
Definition: pal.h:107
enum _searchMethod SearchMethod
Typedef for _Units enumeration.
Definition: pal.h:87
is slower and best than TABU, worse and faster than TABU_CHAIN
Definition: pal.h:82
Definition: qgsdiagramrendererv2.h:37
enum _arrangement Arrangement
typedef for _arrangement enumeration
Definition: pal.h:104
meter [m]
Definition: pal.h:68
Definition: pal.h:83
_searchMethod
Search method to use.
Definition: pal.h:77
Summury of problem.
Definition: palstat.h:44
Only for polygon, arranges candidates with respect of polygon orientation.
Definition: pal.h:100
Definition: pal.h:109
Definition: pal.h:98
Represent a problem.
Definition: problem.h:96
enum _Units Units
Typedef for _Units enumeration.
Definition: pal.h:74
is a little bit better than CHAIN but slower
Definition: pal.h:81
Definition: pal.h:96
is the worst but fastest method
Definition: pal.h:79