QGIS API Documentation 3.39.0-Master (8f4da32b6b8)
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 "qgis_core.h"
37#include "qgsgeometry.h"
38#include "qgsgeos.h"
39#include "qgssettingstree.h"
40
41#include <QList>
42#include <iostream>
43#include <ctime>
44#include <QMutex>
45#include <QStringList>
46#include <unordered_map>
47
49
50// TODO ${MAJOR} ${MINOR} etc instead of 0.2
51
55
56namespace pal
57{
58 class Layer;
59 class LabelPosition;
60 class PalStat;
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
123 typedef bool ( *FnIsCanceled )( void *ctx );
124
126 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
127
129 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
130
149 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
150
163 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
164
170 void setShowPartialLabels( bool show );
171
177 bool showPartialLabels() const;
178
184 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
185
191 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
192
198 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
199
205 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
206
212 Qgis::LabelPlacementEngineVersion placementVersion() const;
213
219 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
220
231 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
232
243 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
244
255 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
256
260 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
261
271 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
272
279 QList< QgsAbstractLabelingEngineRule * > rules() const { return mRules; }
280
281 private:
282
283 std::unordered_map< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > mLayers;
284
285 QList< QgsAbstractLabelingEngineRule * > mRules;
286
287 QMutex mMutex;
288
289 /*
290 * POPMUSIC Tuning
291 */
292 int mPopmusicR = 30;
293
294 int mTabuMaxIt = 4;
295 int mTabuMinIt = 2;
296
297 int mEjChainDeg = 50;
298 int mTenure = 10;
299 double mCandListSize = 0.2;
300
301 unsigned int mNextCandidateId = 1;
302 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
303
307 bool mShowPartialLabels = true;
308
309 double mMaxLineCandidatesPerMapUnit = 0;
310 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
311
312 int mGlobalCandidatesLimitPoint = 0;
313 int mGlobalCandidatesLimitLine = 0;
314 int mGlobalCandidatesLimitPolygon = 0;
315
317
319 FnIsCanceled fnIsCanceled = nullptr;
321 void *fnIsCanceledContext = nullptr;
322
327 void setPopmusicR( int r );
328
333 void setMinIt( int min_it );
334
339 void setMaxIt( int max_it );
340
345 void setTenure( int tenure );
346
351 void setEjChainDeg( int degree );
352
357 void setCandListSize( double fact );
358
359
364 int getMinIt() const;
365
370 int getMaxIt() const;
371
372 };
373
374} // end namespace pal
375
376#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:1125
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2668
@ Version2
Version 2 (default for new projects since QGIS 3.12)
The QgsAbstractLabelProvider class is an interface class.
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.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
static QgsSettingsTreeNode * sTreeRendering
Main class to handle feature.
Definition feature.h:65
LabelPosition is a candidate feature label position.
A set of features which influence the labeling process.
Definition layer.h:63
Main Pal labeling class.
Definition pal.h:84
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition pal.h:184
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:231
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:198
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:205
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:243
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:191
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:129
Pal(const Pal &other)=delete
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition pal.h:255
Pal & operator=(const Pal &other)=delete
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules which the labeling solution must satisify.
Definition pal.h:279
Representation of a labeling problem.
Definition problem.h:73
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