QGIS API Documentation  3.9.0-Master (224899f119)
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 "qgsgeos.h"
39 #include "qgspallabeling.h"
40 #include <QList>
41 #include <iostream>
42 #include <ctime>
43 #include <QMutex>
44 #include <QStringList>
45 
46 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
47 
49 
50 namespace pal
51 {
52  class Layer;
53  class LabelPosition;
54  class PalStat;
55  class Problem;
56  class PointSet;
57 
60  {
61  CHAIN = 0,
65  FALP = 4
66  };
67 
70  {
75  };
76  Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )
77 
78 
87  class CORE_EXPORT Pal
88  {
89  friend class Problem;
90  friend class FeaturePart;
91  friend class Layer;
92 
93  public:
94 
98  Pal();
99 
100  ~Pal();
101 
103  Pal( const Pal &other ) = delete;
105  Pal &operator=( const Pal &other ) = delete;
106 
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 
129  typedef bool ( *FnIsCanceled )( void *ctx );
130 
132  void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
133 
135  inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
136 
144  std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
145 
158  QList<LabelPosition *> solveProblem( Problem *prob, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
159 
165  void setShowPartial( bool show );
166 
170  bool getShowPartial();
171 
178  void setPointP( int point_p );
179 
186  void setLineP( int line_p );
187 
194  void setPolyP( int poly_p );
195 
199  int getPointP();
200 
204  int getLineP();
205 
209  int getPolyP();
210 
211  private:
212 
213  QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
214 
215  QMutex mMutex;
216 
220  int point_p = 16;
221 
225  int line_p = 50;
226 
230  int poly_p = 30;
231 
232  /*
233  * POPMUSIC Tuning
234  */
235  int popmusic_r = 30;
236 
237  int tabuMaxIt = 4;
238  int tabuMinIt = 2;
239 
240  int ejChainDeg = 50;
241  int tenure = 10;
242  double candListSize = 0.2;
243 
247  bool showPartial = true;
248 
250  FnIsCanceled fnIsCanceled = nullptr;
252  void *fnIsCanceledContext = nullptr;
253 
259  std::unique_ptr< Problem > extract( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
260 
265  void setPopmusicR( int r );
266 
271  void setMinIt( int min_it );
272 
277  void setMaxIt( int max_it );
278 
283  void setTenure( int tenure );
284 
289  void setEjChainDeg( int degree );
290 
295  void setCandListSize( double fact );
296 
297 
302  int getMinIt();
303 
308  int getMaxIt();
309 
310  };
311 
312 } // end namespace pal
313 
314 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
315 
316 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Only initial solution.
Definition: pal.h:65
A set of features which influence the labeling process.
Definition: layer.h:63
Main Pal labeling class.
Definition: pal.h:87
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition: pal.h:64
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:121
Is a little bit better than CHAIN but slower.
Definition: pal.h:63
Is the best but slowest.
Definition: pal.h:62
bool isCanceled()
Check whether the job has been canceled.
Definition: pal.h:135
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:73
LineArrangementFlag
Enumeration line arrangement flags. Flags can be combined.
Definition: pal.h:69
SearchMethod
Search method to use.
Definition: pal.h:59
Is the worst but fastest method.
Definition: pal.h:61