QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 <ctime>
37#include <iostream>
38#include <unordered_map>
39
40#include "qgis_core.h"
41#include "qgsgeometry.h"
42#include "qgsgeos.h"
43#include "qgssettingstree.h"
44
45#include <QList>
46#include <QMutex>
47#include <QStringList>
48
50
51// TODO ${MAJOR} ${MINOR} etc instead of 0.2
52
56
57namespace pal
58{
59 class Layer;
60 class LabelPosition;
61 class Problem;
62 class PointSet;
63
73
83 class CORE_EXPORT Pal
84 {
85 friend class Problem;
86 friend class FeaturePart;
87 friend class Layer;
88
89 public:
90 static inline QgsSettingsTreeNode *sTreePal = QgsSettingsTree::sTreeRendering->createChildNode( QStringLiteral( "pal" ) );
91
95
96 Pal();
98
99 Pal( const Pal &other ) = delete;
100 Pal &operator=( const Pal &other ) = delete;
101
114 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
115
121 void removeLayer( Layer *layer );
122
124 typedef bool ( *FnIsCanceled )( void *ctx );
125
127 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
128
130 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
131
150 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
151
164 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
165
171 void setShowPartialLabels( bool show );
172
178 bool showPartialLabels() const;
179
185 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
186
192 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
193
199 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
200
206 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
207
213 Qgis::LabelPlacementEngineVersion placementVersion() const;
214
220 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
221
232 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
233
244 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
245
256 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
257
261 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
262
272 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
273
280 QList< QgsAbstractLabelingEngineRule * > rules() const { return mRules; }
281
282 private:
283
284 std::vector< std::pair< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > > mLayers;
285
286 QList< QgsAbstractLabelingEngineRule * > mRules;
287
288 QMutex mMutex;
289
290 /*
291 * POPMUSIC Tuning
292 */
293 int mPopmusicR = 30;
294
295 int mTabuMaxIt = 4;
296 int mTabuMinIt = 2;
297
298 int mEjChainDeg = 50;
299 int mTenure = 10;
300 double mCandListSize = 0.2;
301
302 unsigned int mNextCandidateId = 1;
303 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
304
308 bool mShowPartialLabels = true;
309
310 double mMaxLineCandidatesPerMapUnit = 0;
311 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
312
313 int mGlobalCandidatesLimitPoint = 0;
314 int mGlobalCandidatesLimitLine = 0;
315 int mGlobalCandidatesLimitPolygon = 0;
316
318
320 FnIsCanceled fnIsCanceled = nullptr;
322 void *fnIsCanceledContext = nullptr;
323
328 void setPopmusicR( int r );
329
334 void setMinIt( int min_it );
335
340 void setMaxIt( int max_it );
341
346 void setTenure( int tenure );
347
352 void setEjChainDeg( int degree );
353
358 void setCandListSize( double fact );
359
360
365 int getMinIt() const;
366
371 int getMaxIt() const;
372
373 };
374
375} // end namespace pal
376
377#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:1194
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2872
@ Version2
Version 2 (default for new projects since QGIS 3.12).
Definition qgis.h:2874
An abstract interface class for label providers.
Abstract base class for labeling engine rules.
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
An integer settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
static QgsSettingsTreeNode * sTreeRendering
LabelPosition is a candidate feature label position.
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition pal.h:185
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:232
static QgsSettingsTreeNode * sTreePal
Definition pal.h:90
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:199
void removeLayer(Layer *layer)
remove a layer
Definition pal.cpp:72
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:206
friend class Layer
Definition pal.h:87
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:244
bool(* FnIsCanceled)(void *ctx)
Cancellation check callback function.
Definition pal.h:124
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitLines
Definition pal.h:93
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPoints
Definition pal.h:92
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPolygons
Definition pal.h:94
void setMaximumLineCandidatesPerMapUnit(double candidates)
Sets the maximum number of line label candidates per map unit.
Definition pal.h:192
Pal()
Definition pal.cpp:63
friend class Problem
Definition pal.h:85
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:130
Pal(const Pal &other)=delete
friend class FeaturePart
Definition pal.h:86
void registerCancellationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
Definition pal.cpp:651
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition pal.h:256
Pal & operator=(const Pal &other)=delete
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules which the labeling solution must satisfy.
Definition pal.h:280
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel)
add a new layer
Definition pal.cpp:90
Representation of a labeling problem.
Definition problem.h:75
SearchMethod
Search method to use.
Definition pal.h:66
@ FALP
Only initial solution.
Definition pal.h:71
@ POPMUSIC_TABU
Is a little bit better than CHAIN but slower.
Definition pal.h:69
@ POPMUSIC_CHAIN
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition pal.h:70
@ CHAIN
Is the worst but fastest method.
Definition pal.h:67
@ POPMUSIC_TABU_CHAIN
Is the best but slowest.
Definition pal.h:68