QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #ifndef PAL_H
31 #define PAL_H
32 
33 #include "qgsgeometry.h"
34 #include "qgspallabeling.h"
35 #include <QList>
36 #include <iostream>
37 #include <ctime>
38 #include <QMutex>
39 #include <QStringList>
40 
41 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
42 
44 
45 namespace pal
46 {
48  GEOSContextHandle_t geosContext();
49 
50  class Layer;
51  class LabelPosition;
52  class PalStat;
53  class Problem;
54  class PointSet;
55 
58  {
59  CHAIN = 0,
63  FALP = 4
64  };
65 
68  {
73  };
74  Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )
75 
76 
84  class CORE_EXPORT Pal
85  {
86  friend class Problem;
87  friend class FeaturePart;
88  friend class Layer;
89 
90  public:
91 
95  Pal();
96 
100  ~Pal();
101 
117  Layer* addLayer( QgsAbstractLabelProvider* provider, const QString& layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll = false );
118 
124  void removeLayer( Layer *layer );
125 
136  QList<LabelPosition*> *labeller( double bbox[4], PalStat **stats, bool displayAll );
137 
138  typedef bool ( *FnIsCancelled )( void* ctx );
139 
141  void registerCancellationCallback( FnIsCancelled fnCancelled, void* context );
142 
144  inline bool isCancelled() { return fnIsCancelled ? fnIsCancelled( fnIsCancelledContext ) : false; }
145 
146  Problem* extractProblem( double bbox[4] );
147 
148  QList<LabelPosition*>* solveProblem( Problem* prob, bool displayAll );
149 
155  void setShowPartial( bool show );
156 
162  bool getShowPartial();
163 
170  void setPointP( int point_p );
171 
178  void setLineP( int line_p );
179 
186  void setPolyP( int poly_p );
187 
191  int getPointP();
192 
196  int getLineP();
197 
201  int getPolyP();
202 
211  void setSearch( SearchMethod method );
212 
218  SearchMethod getSearch();
219 
220  private:
221 
223 
224  QMutex mMutex;
225 
229  int point_p;
230 
234  int line_p;
235 
239  int poly_p;
240 
241  SearchMethod searchMethod;
242 
243  /*
244  * POPMUSIC Tuning
245  */
246  int popmusic_r;
247 
248  int tabuMaxIt;
249  int tabuMinIt;
250 
251  int ejChainDeg;
252  int tenure;
253  double candListSize;
254 
258  bool showPartial;
259 
261  FnIsCancelled fnIsCancelled;
263  void* fnIsCancelledContext;
264 
274  Problem* extract( double lambda_min, double phi_min,
275  double lambda_max, double phi_max );
276 
277 
282  void setPopmusicR( int r );
283 
288  void setMinIt( int min_it );
289 
294  void setMaxIt( int max_it );
295 
300  void setTenure( int tenure );
301 
306  void setEjChainDeg( int degree );
307 
312  void setCandListSize( double fact );
313 
314 
319  int getMinIt();
324  int getMaxIt();
325  };
326 
327 } // end namespace pal
328 
329 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
330 
331 #endif
Definition: pal.h:63
A set of features which influence the labelling process.
Definition: layer.h:58
Main Pal labelling class.
Definition: pal.h:84
bool isCancelled()
Check whether the job has been cancelled.
Definition: pal.h:144
is slower and best than TABU, worse and faster than TABU_CHAIN
Definition: pal.h:62
is a little bit better than CHAIN but slower
Definition: pal.h:61
is the best but slowest
Definition: pal.h:60
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
Definition: pal.cpp:48
Main class to handle feature.
Definition: feature.h:91
The QgsAbstractLabelProvider class is an interface class.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
Summary statistics of labelling problem.
Definition: palstat.h:44
Representation of a labeling problem.
Definition: problem.h:101
LineArrangementFlag
Enumeration line arrangement flags.
Definition: pal.h:67
SearchMethod
Search method to use.
Definition: pal.h:57
is the worst but fastest method
Definition: pal.h:59