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
161
163 Transform transform; // Applied to outline after preprocessing.
164 Zone::Layers layers; // Converted to boardLayers after preprocessing.
165 QSet<const Layer*> boardLayers;
167 };
168
169 struct PolygonData {
170 Transform transform; // Applied to path after preprocessing.
171 const Layer* layer;
172 std::optional<Uuid> netSignal;
175 bool filled;
176 };
177
185
186 struct PadData {
188 std::optional<Uuid> netSignal;
190 QHash<const Layer*, QList<PadGeometry>> geometries;
191 };
192
200
201 struct JobData {
202 // NOTE: We create a `const` copy of this structure for each thread to
203 // ensure thread-safety. For the implicitly shared Qt containers this is
204 // a lightweight operation, but for ClipperLib::Paths we share it with a
205 // shared_ptr to avoid deep copying the whole container. This is safe
206 // because the underlying std::vector is thread-safe for read-only
207 // operations.
208
209 QList<const Layer*> layers;
210 QList<PlaneData> planes;
211 QList<KeepoutZoneData> keepoutZones;
212 QList<PolygonData> polygons;
213 QList<ViaData> vias;
214 QList<PadData> pads;
215 QList<std::tuple<Transform, PositiveLength, NonEmptyPath>> holes;
216 QList<TraceData> traces; // Converted to polygons after preprocessing.
217 std::shared_ptr<ClipperLib::Paths> boardArea; // Populated in preprocessing
218 };
219
221 QHash<Uuid, QVector<Path>> planes;
222 QStringList errors; // Empty on success.
223 };
224
225 std::shared_ptr<JobData> createJob(Board& board,
226 const QSet<const Layer*>* filter) noexcept;
227 Result run(QPointer<Board> board, std::shared_ptr<JobData> data) noexcept;
228 LayerJobResult runLayer(std::shared_ptr<const JobData> data,
229 const Layer* layer) noexcept;
230 static QVector<std::pair<Point, Angle>> determineThermalSpokes(
231 const PadGeometry& geometry) noexcept;
232
238 static PositiveLength maxArcTolerance() noexcept {
239 return PositiveLength(5000);
240 }
241
242private: // Data
243 QFuture<Result> mFuture;
244 bool mAbort;
245};
246
247/*******************************************************************************
248 * End of File
249 ******************************************************************************/
250
251} // namespace librepcb
252
253#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:74
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:244
static PositiveLength maxArcTolerance() noexcept
Definition boardplanefragmentsbuilder.h:238
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:419
QFuture< Result > mFuture
Definition boardplanefragmentsbuilder.h:243
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:297
static QVector< std::pair< Point, Angle > > determineThermalSpokes(const PadGeometry &geometry) noexcept
Definition boardplanefragmentsbuilder.cpp:819
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:59
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:77
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:201
std::shared_ptr< ClipperLib::Paths > boardArea
Definition boardplanefragmentsbuilder.h:217
QList< std::tuple< Transform, PositiveLength, NonEmptyPath > > holes
Definition boardplanefragmentsbuilder.h:215
QList< const Layer * > layers
Definition boardplanefragmentsbuilder.h:209
QList< PolygonData > polygons
Definition boardplanefragmentsbuilder.h:212
QList< TraceData > traces
Definition boardplanefragmentsbuilder.h:216
QList< KeepoutZoneData > keepoutZones
Definition boardplanefragmentsbuilder.h:211
QList< PlaneData > planes
Definition boardplanefragmentsbuilder.h:210
QList< ViaData > vias
Definition boardplanefragmentsbuilder.h:213
QList< PadData > pads
Definition boardplanefragmentsbuilder.h:214
Definition boardplanefragmentsbuilder.h:162
QSet< const Layer * > boardLayers
Definition boardplanefragmentsbuilder.h:165
Transform transform
Definition boardplanefragmentsbuilder.h:163
Zone::Layers layers
Definition boardplanefragmentsbuilder.h:164
Path outline
Definition boardplanefragmentsbuilder.h:166
Definition boardplanefragmentsbuilder.h:220
QHash< Uuid, QVector< Path > > planes
Definition boardplanefragmentsbuilder.h:221
QStringList errors
Definition boardplanefragmentsbuilder.h:222
Definition boardplanefragmentsbuilder.h:186
Transform transform
Definition boardplanefragmentsbuilder.h:187
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:188
QHash< const Layer *, QList< PadGeometry > > geometries
Definition boardplanefragmentsbuilder.h:190
UnsignedLength clearance
Definition boardplanefragmentsbuilder.h:189
Definition boardplanefragmentsbuilder.h:146
UnsignedLength minClearanceToCopper
Definition boardplanefragmentsbuilder.h:152
Uuid uuid
Definition boardplanefragmentsbuilder.h:147
bool keepIslands
Definition boardplanefragmentsbuilder.h:155
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:149
Path outline
Definition boardplanefragmentsbuilder.h:150
UnsignedLength minWidth
Definition boardplanefragmentsbuilder.h:151
PositiveLength thermalSpokeWidth
Definition boardplanefragmentsbuilder.h:159
BI_Plane::ConnectStyle connectStyle
Definition boardplanefragmentsbuilder.h:157
std::optional< UnsignedLength > minClearanceToBoard
Definition boardplanefragmentsbuilder.h:153
std::optional< UnsignedLength > minClearanceToNpth
Definition boardplanefragmentsbuilder.h:154
int priority
Definition boardplanefragmentsbuilder.h:156
const Layer * layer
Definition boardplanefragmentsbuilder.h:148
PositiveLength thermalGap
Definition boardplanefragmentsbuilder.h:158
Definition boardplanefragmentsbuilder.h:169
UnsignedLength width
Definition boardplanefragmentsbuilder.h:174
bool filled
Definition boardplanefragmentsbuilder.h:175
Transform transform
Definition boardplanefragmentsbuilder.h:170
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:172
Path path
Definition boardplanefragmentsbuilder.h:173
const Layer * layer
Definition boardplanefragmentsbuilder.h:171
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:193
Point startPos
Definition boardplanefragmentsbuilder.h:196
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:195
Point endPos
Definition boardplanefragmentsbuilder.h:197
const Layer * layer
Definition boardplanefragmentsbuilder.h:194
PositiveLength width
Definition boardplanefragmentsbuilder.h:198
Definition boardplanefragmentsbuilder.h:178
const Layer * endLayer
Definition boardplanefragmentsbuilder.h:183
std::optional< Uuid > netSignal
Definition boardplanefragmentsbuilder.h:179
PositiveLength diameter
Definition boardplanefragmentsbuilder.h:181
const Layer * startLayer
Definition boardplanefragmentsbuilder.h:182
Point position
Definition boardplanefragmentsbuilder.h:180