QGIS API Documentation  2.99.0-Master (9f5e33a)
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 "qgis_core.h"
34 #include "qgsgeometry.h"
35 #include "qgspallabeling.h"
36 #include <QList>
37 #include <iostream>
38 #include <ctime>
39 #include <QMutex>
40 #include <QStringList>
41 
42 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
43 
45 
46 namespace pal
47 {
49  GEOSContextHandle_t geosContext();
50 
51  class Layer;
52  class LabelPosition;
53  class PalStat;
54  class Problem;
55  class PointSet;
56 
59  {
60  CHAIN = 0,
64  FALP = 4
65  };
66 
69  {
74  };
75  Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )
76 
77 
85  class CORE_EXPORT Pal
86  {
87  friend class Problem;
88  friend class FeaturePart;
89  friend class Layer;
90 
91  public:
92 
96  Pal();
97 
98  ~Pal();
99 
101  Pal( const Pal &other ) = delete;
103  Pal &operator=( const Pal &other ) = delete;
104 
120  Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll = false );
121 
127  void removeLayer( Layer *layer );
128 
139  QList<LabelPosition *> *labeller( double bbox[4], PalStat **stats, bool displayAll );
140 
141  typedef bool ( *FnIsCancelled )( void *ctx );
142 
144  void registerCancellationCallback( FnIsCancelled fnCancelled, void *context );
145 
147  inline bool isCancelled() { return fnIsCancelled ? fnIsCancelled( fnIsCancelledContext ) : false; }
148 
149  Problem *extractProblem( double bbox[4] );
150 
151  QList<LabelPosition *> *solveProblem( Problem *prob, bool displayAll );
152 
158  void setShowPartial( bool show );
159 
165  bool getShowPartial();
166 
173  void setPointP( int point_p );
174 
181  void setLineP( int line_p );
182 
189  void setPolyP( int poly_p );
190 
194  int getPointP();
195 
199  int getLineP();
200 
204  int getPolyP();
205 
214  void setSearch( SearchMethod method );
215 
221  SearchMethod getSearch();
222 
223  private:
224 
225  QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
226 
227  QMutex mMutex;
228 
232  int point_p;
233 
237  int line_p;
238 
242  int poly_p;
243 
244  SearchMethod searchMethod;
245 
246  /*
247  * POPMUSIC Tuning
248  */
249  int popmusic_r;
250 
251  int tabuMaxIt;
252  int tabuMinIt;
253 
254  int ejChainDeg;
255  int tenure;
256  double candListSize;
257 
261  bool showPartial;
262 
264  FnIsCancelled fnIsCancelled;
266  void *fnIsCancelledContext = nullptr;
267 
277  Problem *extract( double lambda_min, double phi_min,
278  double lambda_max, double phi_max );
279 
280 
285  void setPopmusicR( int r );
286 
291  void setMinIt( int min_it );
292 
297  void setMaxIt( int max_it );
298 
303  void setTenure( int tenure );
304 
309  void setEjChainDeg( int degree );
310 
315  void setCandListSize( double fact );
316 
317 
322  int getMinIt();
323 
328  int getMaxIt();
329 
330  };
331 
332 } // end namespace pal
333 
334 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
335 
336 #endif
Definition: pal.h:64
A set of features which influence the labeling process.
Definition: layer.h:60
Main Pal labeling class.
Definition: pal.h:85
bool isCancelled()
Check whether the job has been cancelled.
Definition: pal.h:147
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition: pal.h:63
Is a little bit better than CHAIN but slower.
Definition: pal.h:62
Is the best but slowest.
Definition: pal.h:61
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:92
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:44
Representation of a labeling problem.
Definition: problem.h:104
LineArrangementFlag
Enumeration line arrangement flags. Flags can be combined.
Definition: pal.h:68
SearchMethod
Search method to use.
Definition: pal.h:58
Is the worst but fastest method.
Definition: pal.h:60