QGIS API Documentation  3.0.2-Girona (307d082)
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 
133  typedef bool ( *FnIsCanceled )( void *ctx );
134 
136  void registerCancelationCallback( FnIsCanceled fnCanceled, void *context );
137 
139  inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
140 
148  std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
149 
150  QList<LabelPosition *> solveProblem( Problem *prob, bool displayAll );
151 
157  void setShowPartial( bool show );
158 
164  bool getShowPartial();
165 
172  void setPointP( int point_p );
173 
180  void setLineP( int line_p );
181 
188  void setPolyP( int poly_p );
189 
193  int getPointP();
194 
198  int getLineP();
199 
203  int getPolyP();
204 
213  void setSearch( SearchMethod method );
214 
220  SearchMethod getSearch();
221 
222  private:
223 
224  QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
225 
226  QMutex mMutex;
227 
231  int point_p;
232 
236  int line_p;
237 
241  int poly_p;
242 
243  SearchMethod searchMethod;
244 
245  /*
246  * POPMUSIC Tuning
247  */
248  int popmusic_r;
249 
250  int tabuMaxIt;
251  int tabuMinIt;
252 
253  int ejChainDeg;
254  int tenure;
255  double candListSize;
256 
260  bool showPartial;
261 
263  FnIsCanceled fnIsCanceled;
265  void *fnIsCanceledContext = nullptr;
266 
272  std::unique_ptr< Problem > extract( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
273 
278  void setPopmusicR( int r );
279 
284  void setMinIt( int min_it );
285 
290  void setMaxIt( int max_it );
291 
296  void setTenure( int tenure );
297 
302  void setEjChainDeg( int degree );
303 
308  void setCandListSize( double fact );
309 
310 
315  int getMinIt();
316 
321  int getMaxIt();
322 
323  };
324 
325 } // end namespace pal
326 
327 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
328 
329 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:39
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
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
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:139
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. ...
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