LibrePCB Developers Documentation
Loading...
Searching...
No Matches
boardplanefragmentsbuilder.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_BOARDPLANEFRAGMENTSBUILDER_H
21#define LIBREPCB_CORE_BOARDPLANEFRAGMENTSBUILDER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../geometry/path.h"
27#include "../../geometry/zone.h"
28#include "../../types/uuid.h"
29#include "../../utils/transform.h"
30#include "items/bi_plane.h"
31
32#include <polyclipping/clipper.hpp>
33
34#include <QtCore>
35
36#include <memory>
37
38/*******************************************************************************
39 * Namespace / Forward Declarations
40 ******************************************************************************/
41namespace librepcb {
42
43class Board;
44class Layer;
45class NetSignal;
46class PadGeometry;
47
48/*******************************************************************************
49 * Class BoardPlaneFragmentsBuilder
50 ******************************************************************************/
51
55class BoardPlaneFragmentsBuilder final : public QObject {
56 Q_OBJECT
57
58public:
59 // Types
60 struct Result {
61 QPointer<Board> board;
62 QSet<const Layer*> layers;
63 QHash<Uuid, QVector<Path>> planes;
64 QStringList errors;
65 bool finished = false;
66
68 void throwOnError() const;
69
73 bool applyToBoard() noexcept;
74 };
75
76 // Constructors / Destructor
77 explicit BoardPlaneFragmentsBuilder(QObject* parent = nullptr) noexcept;
80
81 // General Methods
82
96 QHash<Uuid, QVector<Path>> runAndApply(
97 Board& board, const QSet<const Layer*>* layers = nullptr);
98
115 bool start(Board& board, const QSet<const Layer*>* layers = nullptr) noexcept;
116
122 Result waitForFinished() const noexcept;
123
130 bool isBusy() const noexcept;
131
135 void cancel() noexcept;
136
137 // Operator Overloadings
139 delete;
140
141signals:
142 void started();
143 void finished(Result result);
144
145private: // Methods
159
161 Transform transform; // Applied to outline after preprocessing.
162 Zone::Layers layers; // Converted to boardLayers after preprocessing.
163 QSet<const Layer*> boardLayers;
165 };
166
167 struct PolygonData {
168 Transform transform; // Applied to path after preprocessing.
169 const Layer* layer;
170 std::optional<Uuid> netSignal;
173 bool filled;
174 };
175
183
184 struct PadData {
186 std::optional<Uuid> netSignal;
188 QHash<const Layer*, QList<PadGeometry>> geometries;
189 };
190
198
199 struct JobData {
200 // NOTE: We create a `const` copy of this structure for each thread to
201 // ensure thread-safety. For the implicitly shared Qt containers this is
202 // a lightweight operation, but for ClipperLib::Paths we share it with a
203 // shared_ptr to avoid deep copying the whole container. This is safe
204 // because the underlying std::vector is thread-safe for read-only
205 // operations.
206
207 QList<const Layer*> layers;
208 QList<PlaneData> planes;
209 QList<KeepoutZoneData> keepoutZones;
210 QList<PolygonData> polygons;
211 QList<ViaData> vias;
212 QList<PadData> pads;
213 QList<std::tuple<Transform, PositiveLength, NonEmptyPath>> holes;
214 QList<TraceData> traces; // Converted to polygons after preprocessing.
215 std::shared_ptr<ClipperLib::Paths> boardArea; // Populated in preprocessing
216 };
217
219 QHash<Uuid, QVector<Path>> planes;
220 QStringList errors; // Empty on success.
221 };
222
223 std::shared_ptr<JobData> createJob(Board& board,
224 const QSet<const Layer*>* filter) noexcept;
225 Result run(QPointer<Board> board, std::shared_ptr<JobData> data) noexcept;
226 LayerJobResult runLayer(std::shared_ptr<const JobData> data,
227 const Layer* layer) noexcept;
228 static QVector<std::pair<Point, Angle>> determineThermalSpokes(
229 const PadGeometry& geometry) noexcept;
230
236 static PositiveLength maxArcTolerance() noexcept {
237 return PositiveLength(5000);
238 }
239
240private: // Data
241 QFuture<Result> mFuture;
242 bool mAbort;
243};
244
245/*******************************************************************************
246 * End of File
247 ******************************************************************************/
248
249} // namespace librepcb
250
251#endif
ConnectStyle
Definition bi_plane.h:68
The Board class represents a PCB of a project and is always part of a circuit.
Definition board.h:73
Plane fragments builder working on a librepcb::Board.
Definition boardplanefragmentsbuilder.h:55
std::shared_ptr< JobData > createJob(Board &board, const QSet< const Layer * > *filter) noexcept
Definition boardplanefragmentsbuilder.cpp:147
void cancel() noexcept
Cancel the current asynchronous job.
Definition boardplanefragmentsbuilder.cpp:136
bool isBusy() const noexcept
Check if there is currently a build in progress.
Definition boardplanefragmentsbuilder.cpp:131
bool mAbort
Definition boardplanefragmentsbuilder.h:242
static PositiveLength maxArcTolerance() noexcept
Definition boardplanefragmentsbuilder.h:236
Result waitForFinished() const noexcept
Wait until the asynchronous operation is finished.
Definition boardplanefragmentsbuilder.cpp:126
LayerJobResult runLayer(std::shared_ptr< const JobData > data, const Layer *layer) noexcept
Definition boardplanefragmentsbuilder.cpp:403
QFuture< Result > mFuture
Definition boardplanefragmentsbuilder.h:241
bool start(Board &board, const QSet< const Layer * > *layers=nullptr) noexcept
Start building plane fragments asynchronously.
Definition boardplanefragmentsbuilder.cpp:114
Result run(QPointer< Board > board, std::shared_ptr< JobData > data) noexcept
Definition boardplanefragmentsbuilder.cpp:281
static QVector< std::pair< Point, Angle > > determineThermalSpokes(const PadGeometry &geometry) noexcept
Definition boardplanefragmentsbuilder.cpp:789
QHash< Uuid, QVector< Path > > runAndApply(Board &board, const QSet< const Layer * > *layers=nullptr)
Build and apply plane fragments (blocking)
Definition boardplanefragmentsbuilder.cpp:103
The Layer class provides all supported geometry layers.
Definition layer.h:42
The PadGeometry class describes the shape of a pad.
Definition padgeometry.h:46
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition path.h:57
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
Helper class to perform coordinate transformation with various types.
Definition transform.h:59
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
Definition occmodel.cpp:76
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
Definition boardplanefragmentsbuilder.h:199
std::shared_ptr< ClipperLib::Paths > boardArea
Definition boardplanefragmentsbuilder.h:215
QList< std::tuple< Transform, PositiveLength, NonEmptyPath > > holes
Definition boardplanefragmentsbuilder.h:213
QList< const Layer * > layers
Definition boardplanefragmentsbuilder.h:207
QList< PolygonData > polygons
Definition boardplanefragmentsbuilder.h:210
QList< TraceData > traces
Definition boardplanefragmentsbuilder.h:214
QList< KeepoutZoneData > keepoutZones
Definition boardplanefragmentsbuilder.h:209
QList< PlaneData > planes
Definition boardplanefragmentsbuilder.h:208
QList< ViaData > vias
Definition boardplanefragmentsbuilder.h:211
QList< PadData > pads
Definition boardplanefragmentsbuilder.h:212
Definition boardplanefragmentsbuilder.h:160
QSet< const Layer * > boardLayers
Definition boardplanefragmentsbuilder.h:163
Transform transform
Definition boardplanefragmentsbuilder.h:161
Zone::Layers layers
Definition boardplanefragmentsbuilder.h:162
Path outline
Definition boardplanefragmentsbuilder.h:164
Definition boardplanefragmentsbuilder.h:218
QHash< Uuid, QVector< Path > > planes
Definition boardplanefragmentsbuilder.h:219
QStringList errors
Definition boardplanefragmentsbuilder.h:220
Definition boardplanefragmentsbuilder.h:184
Transform transform
Definition boardplanefragmentsbuilder.h:185
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:186
QHash< const Layer *, QList< PadGeometry > > geometries
Definition boardplanefragmentsbuilder.h:188
UnsignedLength clearance
Definition boardplanefragmentsbuilder.h:187
Definition boardplanefragmentsbuilder.h:146
Uuid uuid
Definition boardplanefragmentsbuilder.h:147
bool keepIslands
Definition boardplanefragmentsbuilder.h:153
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:149
Path outline
Definition boardplanefragmentsbuilder.h:150
UnsignedLength minClearance
Definition boardplanefragmentsbuilder.h:152
UnsignedLength minWidth
Definition boardplanefragmentsbuilder.h:151
PositiveLength thermalSpokeWidth
Definition boardplanefragmentsbuilder.h:157
BI_Plane::ConnectStyle connectStyle
Definition boardplanefragmentsbuilder.h:155
int priority
Definition boardplanefragmentsbuilder.h:154
const Layer * layer
Definition boardplanefragmentsbuilder.h:148
PositiveLength thermalGap
Definition boardplanefragmentsbuilder.h:156
Definition boardplanefragmentsbuilder.h:167
UnsignedLength width
Definition boardplanefragmentsbuilder.h:172
bool filled
Definition boardplanefragmentsbuilder.h:173
Transform transform
Definition boardplanefragmentsbuilder.h:168
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:170
Path path
Definition boardplanefragmentsbuilder.h:171
const Layer * layer
Definition boardplanefragmentsbuilder.h:169
Definition boardplanefragmentsbuilder.h:60
bool applyToBoard() noexcept
Definition boardplanefragmentsbuilder.cpp:68
void throwOnError() const
Convenience error handling.
Definition boardplanefragmentsbuilder.cpp:58
QHash< Uuid, QVector< Path > > planes
The calculated plane fragments.
Definition boardplanefragmentsbuilder.h:63
bool finished
Whether the run completed or was aborted.
Definition boardplanefragmentsbuilder.h:65
QStringList errors
Any occurred errors (empty on success)
Definition boardplanefragmentsbuilder.h:64
QPointer< Board > board
The board of the calculated planes.
Definition boardplanefragmentsbuilder.h:61
QSet< const Layer * > layers
All processed layers.
Definition boardplanefragmentsbuilder.h:62
Definition boardplanefragmentsbuilder.h:191
Point startPos
Definition boardplanefragmentsbuilder.h:194
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:193
Point endPos
Definition boardplanefragmentsbuilder.h:195
const Layer * layer
Definition boardplanefragmentsbuilder.h:192
PositiveLength width
Definition boardplanefragmentsbuilder.h:196
Definition boardplanefragmentsbuilder.h:176
const Layer * endLayer
Definition boardplanefragmentsbuilder.h:181
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:177
PositiveLength diameter
Definition boardplanefragmentsbuilder.h:179
const Layer * startLayer
Definition boardplanefragmentsbuilder.h:180
Point position
Definition boardplanefragmentsbuilder.h:178