LibrePCB Developers Documentation
boarddesignrulecheck.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_BOARDDESIGNRULECHECK_H
21#define LIBREPCB_CORE_BOARDDESIGNRULECHECK_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../../rulecheck/rulecheckmessage.h"
27#include "../../../utils/transform.h"
29
30#include <polyclipping/clipper.hpp>
31
32#include <QtCore>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38
39/*******************************************************************************
40 * Class BoardDesignRuleCheck
41 ******************************************************************************/
42
47class BoardDesignRuleCheck final : public QObject {
48 Q_OBJECT
49
50public:
51 // Types
54 // This structure is filled by stage 1 jobs and read by stage 2 jobs.
55 // Each stage 2 job gets a copy of this structure, so no synchronization
56 // is needed for thread-safety. Stage 1 jobs however all get the same
57 // instance, thus require to lock it with the contained mutex.
58
59 mutable QMutex mutex; // To be used by stage 1 jobs.
60
61 QHash<const Layer*, ClipperLib::Paths> copperPathsPerLayer;
62 };
63
64 struct Result {
66 QStringList errors; // Empty on success.
67 };
68
69 // Constructors / Destructor
70 explicit BoardDesignRuleCheck(QObject* parent = nullptr) noexcept;
71 ~BoardDesignRuleCheck() noexcept;
72
73 // General Methods
74 void start(Board& board, const BoardDesignRuleCheckSettings& settings,
75 bool quick) noexcept;
76
82 Result waitForFinished() const noexcept;
83
87 void cancel() noexcept;
88
89signals:
90 void started();
91 void progressPercent(int percent);
92 void progressStatus(const QString& msg);
93 void finished(Result result);
94
95private: // Methods
96 typedef std::function<RuleCheckMessageList()> JobFunc;
97 typedef std::function<void(const Data&, CalculatedJobData&)> Stage1Func;
99 const Data&, const CalculatedJobData&);
101 const Data&);
102
103 Result tryRunJob(JobFunc function, int weight) noexcept;
104 Result run(std::shared_ptr<const Data> data) noexcept;
105 void prepareCopperPaths(const Data& data, CalculatedJobData& calcData,
106 const Layer& layer);
110 const Data& data, const CalculatedJobData& calcData);
116 const Data& data, const CalculatedJobData& calcData);
134 static void checkMinimumWidth(RuleCheckMessageList& messages,
135 const Data& data,
136 const UnsignedLength& minWidth,
137 std::function<bool(const Layer&)> layerFilter);
138 static bool requiresHoleSlotWarning(
139 const Data::Hole& hole,
140 BoardDesignRuleCheckSettings::AllowedSlots allowed);
141 static ClipperLib::Paths getBoardClearanceArea(
142 const Data& data, const UnsignedLength& clearance);
143 static QVector<Path> getBoardOutlines(
144 const Data& data, const QSet<const Layer*>& layers) noexcept;
145 static ClipperLib::Paths getDeviceOutlinePaths(const Data::Device& device,
146 const Layer& layer);
147 static QVector<Path> getDeviceLocation(const Data::Device& device);
148 static QVector<Path> getViaLocation(const Data::Via& via) noexcept;
149 static QVector<Path> getTraceLocation(const Data::Trace& trace) noexcept;
150 static QVector<Path> getHoleLocation(
151 const Data::Hole& hole,
152 const Transform& transform = Transform()) noexcept;
153 void emitProgress(int percent) noexcept;
154 void emitStatus(const QString& status) noexcept;
155
159 static PositiveLength maxArcTolerance() noexcept {
160 return PositiveLength(5000);
161 }
162
163private: // Data
164 QMutex mMutex;
165 int mProgressTotal = 0; // Only for progress range 20..100%
166 int mProgressCounter = 0; // 0..mProgressTotal
167 QFuture<Result> mFuture;
168 bool mAbort = false;
169};
170
171/*******************************************************************************
172 * End of File
173 ******************************************************************************/
174
175} // namespace librepcb
176
177#endif
The BoardDesignRuleCheck class checks a librepcb::Board for design rule violations.
Definition: boarddesignrulecheck.h:47
int mProgressCounter
Definition: boarddesignrulecheck.h:166
QMutex mMutex
Definition: boarddesignrulecheck.h:164
RuleCheckMessageList checkVias(const Data &data)
Definition: boarddesignrulecheck.cpp:1641
RuleCheckMessageList checkCopperBoardClearances(const Data &data)
Definition: boarddesignrulecheck.cpp:658
RuleCheckMessageList checkBoardOutline(const Data &data)
Definition: boarddesignrulecheck.cpp:1802
RuleCheckMessageList checkMinimumSilkscreenWidth(const Data &data)
Definition: boarddesignrulecheck.cpp:1348
void cancel() noexcept
Cancel the current asynchronous job.
Definition: boarddesignrulecheck.cpp:111
BoardDesignRuleCheck(QObject *parent=nullptr) noexcept
Definition: boarddesignrulecheck.cpp:45
void emitProgress(int percent) noexcept
Definition: boarddesignrulecheck.cpp:2301
RuleCheckMessageList checkMinimumPthSlotWidth(const Data &data)
Definition: boarddesignrulecheck.cpp:1319
bool mAbort
Definition: boarddesignrulecheck.h:168
RuleCheckMessageList checkMinimumNpthDrillDiameter(const Data &data)
Definition: boarddesignrulecheck.cpp:1206
static ClipperLib::Paths getBoardClearanceArea(const Data &data, const UnsignedLength &clearance)
Definition: boarddesignrulecheck.cpp:2155
RuleCheckMessageList checkZones(const Data &data)
Definition: boarddesignrulecheck.cpp:1396
Result waitForFinished() const noexcept
Wait until the asynchronous operation is finished.
Definition: boarddesignrulecheck.cpp:99
void prepareCopperPaths(const Data &data, CalculatedJobData &calcData, const Layer &layer)
Definition: boarddesignrulecheck.cpp:338
RuleCheckMessageList checkCopperCopperClearances(const Data &data)
Definition: boarddesignrulecheck.cpp:348
static ClipperLib::Paths getDeviceOutlinePaths(const Data::Device &device, const Layer &layer)
Definition: boarddesignrulecheck.cpp:2202
RuleCheckMessageList checkMinimumPthDrillDiameter(const Data &data)
Definition: boarddesignrulecheck.cpp:1277
void emitStatus(const QString &status) noexcept
Definition: boarddesignrulecheck.cpp:2306
RuleCheckMessageList checkMinimumSilkscreenTextHeight(const Data &data)
Definition: boarddesignrulecheck.cpp:1366
void progressStatus(const QString &msg)
static PositiveLength maxArcTolerance() noexcept
Definition: boarddesignrulecheck.h:159
RuleCheckMessageList checkMinimumPthAnnularRing(const Data &data, const CalculatedJobData &calcData)
Definition: boarddesignrulecheck.cpp:1137
RuleCheckMessageList(BoardDesignRuleCheck::* Stage2Func)(const Data &, const CalculatedJobData &)
Definition: boarddesignrulecheck.h:98
static QVector< Path > getViaLocation(const Data::Via &via) noexcept
Definition: boarddesignrulecheck.cpp:2286
RuleCheckMessageList checkForMissingConnections(const Data &data)
Definition: boarddesignrulecheck.cpp:1952
std::function< void(const Data &, CalculatedJobData &)> Stage1Func
Definition: boarddesignrulecheck.h:97
RuleCheckMessageList checkDrillDrillClearances(const Data &data)
Definition: boarddesignrulecheck.cpp:864
void progressPercent(int percent)
RuleCheckMessageList checkUsedLayers(const Data &data)
Definition: boarddesignrulecheck.cpp:1879
RuleCheckMessageList(BoardDesignRuleCheck::* IndependentStageFunc)(const Data &)
Definition: boarddesignrulecheck.h:100
int mProgressTotal
Definition: boarddesignrulecheck.h:165
RuleCheckMessageList checkDrillBoardClearances(const Data &data)
Definition: boarddesignrulecheck.cpp:951
static QVector< Path > getDeviceLocation(const Data::Device &device)
Definition: boarddesignrulecheck.cpp:2232
RuleCheckMessageList checkForUnplacedComponents(const Data &data)
Definition: boarddesignrulecheck.cpp:1938
void finished(Result result)
static QVector< Path > getBoardOutlines(const Data &data, const QSet< const Layer * > &layers) noexcept
Definition: boarddesignrulecheck.cpp:2177
Result run(std::shared_ptr< const Data > data) noexcept
Definition: boarddesignrulecheck.cpp:143
QFuture< Result > mFuture
Definition: boarddesignrulecheck.h:167
RuleCheckMessageList checkMinimumCopperWidth(const Data &data)
Definition: boarddesignrulecheck.cpp:1121
std::function< RuleCheckMessageList()> JobFunc
Definition: boarddesignrulecheck.h:96
RuleCheckMessageList checkAllowedNpthSlots(const Data &data)
Definition: boarddesignrulecheck.cpp:1659
static QVector< Path > getTraceLocation(const Data::Trace &trace) noexcept
Definition: boarddesignrulecheck.cpp:2291
void start(Board &board, const BoardDesignRuleCheckSettings &settings, bool quick) noexcept
Definition: boarddesignrulecheck.cpp:57
RuleCheckMessageList checkDeviceClearances(const Data &data)
Definition: boarddesignrulecheck.cpp:1746
static void checkMinimumWidth(RuleCheckMessageList &messages, const Data &data, const UnsignedLength &minWidth, std::function< bool(const Layer &)> layerFilter)
Definition: boarddesignrulecheck.cpp:2015
RuleCheckMessageList checkSilkscreenStopmaskClearances(const Data &data)
Definition: boarddesignrulecheck.cpp:1028
RuleCheckMessageList checkForStaleObjects(const Data &data)
Definition: boarddesignrulecheck.cpp:1992
RuleCheckMessageList checkAllowedPthSlots(const Data &data)
Definition: boarddesignrulecheck.cpp:1692
static bool requiresHoleSlotWarning(const Data::Hole &hole, BoardDesignRuleCheckSettings::AllowedSlots allowed)
Definition: boarddesignrulecheck.cpp:2136
RuleCheckMessageList checkCopperHoleClearances(const Data &data, const CalculatedJobData &calcData)
Definition: boarddesignrulecheck.cpp:807
RuleCheckMessageList checkMinimumNpthSlotWidth(const Data &data)
Definition: boarddesignrulecheck.cpp:1242
RuleCheckMessageList checkInvalidPadConnections(const Data &data)
Definition: boarddesignrulecheck.cpp:1719
Result tryRunJob(JobFunc function, int weight) noexcept
Definition: boarddesignrulecheck.cpp:121
static QVector< Path > getHoleLocation(const Data::Hole &hole, const Transform &transform=Transform()) noexcept
Definition: boarddesignrulecheck.cpp:2296
The BoardDesignRuleCheckSettings class.
Definition: boarddesignrulechecksettings.h:44
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
The Device class represents an instance of a component (a "real" component)
Definition: device.h:55
The Hole class.
Definition: hole.h:45
The Layer class provides all supported geometry layers.
Definition: layer.h:42
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
The Trace class represents a trace within a board.
Definition: trace.h:113
Helper class to perform coordinate transformation with various types.
Definition: transform.h:59
The Via class represents a via of a board.
Definition: via.h:52
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
Definition: boarddesignrulecheck.h:53
QHash< const Layer *, ClipperLib::Paths > copperPathsPerLayer
Definition: boarddesignrulecheck.h:61
QMutex mutex
Definition: boarddesignrulecheck.h:59
Definition: boarddesignrulecheck.h:64
RuleCheckMessageList messages
Definition: boarddesignrulecheck.h:65
QStringList errors
Definition: boarddesignrulecheck.h:66
Input data structure for librepcb::BoardDesignRuleCheck.
Definition: boarddesignrulecheckdata.h:48