QGIS API Documentation  2.99.0-Master (9fdd060)
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 
89  class CORE_EXPORT Pal
90  {
91  friend class Problem;
92  friend class FeaturePart;
93  friend class Layer;
94 
95  public:
96 
100  Pal();
101 
102  ~Pal();
103 
105  Pal( const Pal &other ) = delete;
107  Pal &operator=( const Pal &other ) = delete;
108 
124  Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll = false );
125 
131  void removeLayer( Layer *layer );
132 
143  QList<LabelPosition *> *labeller( double bbox[4], PalStat **stats, bool displayAll );
144 
145  typedef bool ( *FnIsCanceled )( void *ctx );
146 
148  void registerCancelationCallback( FnIsCanceled fnCanceled, void *context );
149 
151  inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
152 
153  Problem *extractProblem( double bbox[4] );
154 
155  QList<LabelPosition *> *solveProblem( Problem *prob, bool displayAll );
156 
162  void setShowPartial( bool show );
163 
169  bool getShowPartial();
170 
177  void setPointP( int point_p );
178 
185  void setLineP( int line_p );
186 
193  void setPolyP( int poly_p );
194 
198  int getPointP();
199 
203  int getLineP();
204 
208  int getPolyP();
209 
218  void setSearch( SearchMethod method );
219 
225  SearchMethod getSearch();
226 
227  private:
228 
229  QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
230 
231  QMutex mMutex;
232 
236  int point_p;
237 
241  int line_p;
242 
246  int poly_p;
247 
248  SearchMethod searchMethod;
249 
250  /*
251  * POPMUSIC Tuning
252  */
253  int popmusic_r;
254 
255  int tabuMaxIt;
256  int tabuMinIt;
257 
258  int ejChainDeg;
259  int tenure;
260  double candListSize;
261 
265  bool showPartial;
266 
268  FnIsCanceled fnIsCanceled;
270  void *fnIsCanceledContext = nullptr;
271 
281  Problem *extract( double lambda_min, double phi_min,
282  double lambda_max, double phi_max );
283 
284 
289  void setPopmusicR( int r );
290 
295  void setMinIt( int min_it );
296 
301  void setMaxIt( int max_it );
302 
307  void setTenure( int tenure );
308 
313  void setEjChainDeg( int degree );
314 
319  void setCandListSize( double fact );
320 
321 
326  int getMinIt();
327 
332  int getMaxIt();
333 
334  };
335 
336 } // end namespace pal
337 
338 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
339 
340 #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:89
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:151
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:96
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:48
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