QGIS API Documentation  2.99.0-Master (f867b65)
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 #define SIP_NO_FILE
34 
35 
36 #include "qgis_core.h"
37 #include "qgsgeometry.h"
38 #include "qgspallabeling.h"
39 #include <QList>
40 #include <iostream>
41 #include <ctime>
42 #include <QMutex>
43 #include <QStringList>
44 
45 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
46 
48 
49 namespace pal
50 {
52  GEOSContextHandle_t geosContext();
53 
54  class Layer;
55  class LabelPosition;
56  class PalStat;
57  class Problem;
58  class PointSet;
59 
62  {
63  CHAIN = 0,
67  FALP = 4
68  };
69 
72  {
77  };
78  Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )
79 
80 
88  class CORE_EXPORT Pal
89  {
90  friend class Problem;
91  friend class FeaturePart;
92  friend class Layer;
93 
94  public:
95 
99  Pal();
100 
101  ~Pal();
102 
104  Pal( const Pal &other ) = delete;
106  Pal &operator=( const Pal &other ) = delete;
107 
123  Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll = false );
124 
130  void removeLayer( Layer *layer );
131 
142  QList<LabelPosition *> *labeller( double bbox[4], PalStat **stats, bool displayAll );
143 
144  typedef bool ( *FnIsCanceled )( void *ctx );
145 
147  void registerCancelationCallback( FnIsCanceled fnCanceled, void *context );
148 
150  inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
151 
152  Problem *extractProblem( double bbox[4] );
153 
154  QList<LabelPosition *> *solveProblem( Problem *prob, bool displayAll );
155 
161  void setShowPartial( bool show );
162 
168  bool getShowPartial();
169 
176  void setPointP( int point_p );
177 
184  void setLineP( int line_p );
185 
192  void setPolyP( int poly_p );
193 
197  int getPointP();
198 
202  int getLineP();
203 
207  int getPolyP();
208 
217  void setSearch( SearchMethod method );
218 
224  SearchMethod getSearch();
225 
226  private:
227 
228  QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
229 
230  QMutex mMutex;
231 
235  int point_p;
236 
240  int line_p;
241 
245  int poly_p;
246 
247  SearchMethod searchMethod;
248 
249  /*
250  * POPMUSIC Tuning
251  */
252  int popmusic_r;
253 
254  int tabuMaxIt;
255  int tabuMinIt;
256 
257  int ejChainDeg;
258  int tenure;
259  double candListSize;
260 
264  bool showPartial;
265 
267  FnIsCanceled fnIsCanceled;
269  void *fnIsCanceledContext = nullptr;
270 
280  Problem *extract( double lambda_min, double phi_min,
281  double lambda_max, double phi_max );
282 
283 
288  void setPopmusicR( int r );
289 
294  void setMinIt( int min_it );
295 
300  void setMaxIt( int max_it );
301 
306  void setTenure( int tenure );
307 
312  void setEjChainDeg( int degree );
313 
318  void setCandListSize( double fact );
319 
320 
325  int getMinIt();
326 
331  int getMaxIt();
332 
333  };
334 
335 } // end namespace pal
336 
337 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
338 
339 #endif
Definition: pal.h:67
A set of features which influence the labeling process.
Definition: layer.h:63
Main Pal labeling class.
Definition: pal.h:88
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition: pal.h:66
Is a little bit better than CHAIN but slower.
Definition: pal.h:65
Is the best but slowest.
Definition: pal.h:64
bool isCanceled()
Check whether the job has been canceled.
Definition: pal.h:150
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:95
The QgsAbstractLabelProvider class is an interface class.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
Summary statistics of labeling problem.
Definition: palstat.h:47
Representation of a labeling problem.
Definition: problem.h:107
LineArrangementFlag
Enumeration line arrangement flags. Flags can be combined.
Definition: pal.h:71
SearchMethod
Search method to use.
Definition: pal.h:61
Is the worst but fastest method.
Definition: pal.h:63