LibrePCB Developers Documentation
board.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_BOARD_H
21#define LIBREPCB_CORE_BOARD_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../fileio/filepath.h"
27#include "../../fileio/transactionaldirectory.h"
28#include "../../types/elementname.h"
29#include "../../types/length.h"
30#include "../../types/lengthunit.h"
31#include "../../types/uuid.h"
32#include "../../types/version.h"
33
34#include <QtCore>
35
36#include <memory>
37
38/*******************************************************************************
39 * Namespace / Forward Declarations
40 ******************************************************************************/
41namespace librepcb {
42
43class BI_AirWire;
44class BI_Base;
45class BI_Device;
46class BI_FootprintPad;
47class BI_Hole;
48class BI_NetLine;
49class BI_NetPoint;
50class BI_NetSegment;
51class BI_Plane;
52class BI_Polygon;
53class BI_StrokeText;
54class BI_Via;
55class BI_Zone;
56class BoardDesignRuleCheckSettings;
57class BoardDesignRules;
58class BoardFabricationOutputSettings;
59class Layer;
60class NetSignal;
61class PcbColor;
62class Project;
63class SceneData3D;
64
65/*******************************************************************************
66 * Class Board
67 ******************************************************************************/
68
73class Board final : public QObject {
74 Q_OBJECT
75
76public:
77 // Constructors / Destructor
78 Board() = delete;
79 Board(const Board& other) = delete;
80 Board(Project& project, std::unique_ptr<TransactionalDirectory> directory,
81 const QString& directoryName, const Uuid& uuid,
82 const ElementName& name);
83 ~Board() noexcept;
84
85 // Getters: General
86 Project& getProject() const noexcept { return mProject; }
87 const QString& getDirectoryName() const noexcept { return mDirectoryName; }
89 const BoardDesignRules& getDesignRules() const noexcept {
90 return *mDesignRules;
91 }
93 return *mDrcSettings;
94 }
97 }
99 const noexcept {
101 }
102 bool isEmpty() const noexcept;
103 QList<BI_Base*> getAllItems() const noexcept;
104 std::shared_ptr<SceneData3D> buildScene3D(
105 const tl::optional<Uuid>& assemblyVariant) const noexcept;
106
107 // Getters: Attributes
108 const Uuid& getUuid() const noexcept { return mUuid; }
109 const ElementName& getName() const noexcept { return mName; }
110 const QString& getDefaultFontName() const noexcept {
112 }
113 const PositiveLength& getGridInterval() const noexcept {
114 return mGridInterval;
115 }
116 const LengthUnit& getGridUnit() const noexcept { return mGridUnit; }
117 int getInnerLayerCount() const noexcept { return mInnerLayerCount; }
118 const QSet<const Layer*> getCopperLayers() const noexcept {
119 return mCopperLayers;
120 }
121 const PositiveLength& getPcbThickness() const noexcept {
122 return mPcbThickness;
123 }
124 const PcbColor* getSolderResist() const noexcept { return mSolderResist; }
125 const PcbColor& getSilkscreenColor() const noexcept {
126 return *mSilkscreenColor;
127 }
128 const PcbColor* getSilkscreenColorTop() const noexcept {
129 return (!mSilkscreenLayersTop.isEmpty()) ? mSilkscreenColor : nullptr;
130 }
131 const PcbColor* getSilkscreenColorBot() const noexcept {
132 return (!mSilkscreenLayersBot.isEmpty()) ? mSilkscreenColor : nullptr;
133 }
134 const QVector<const Layer*>& getSilkscreenLayersTop() const noexcept {
136 }
137 const QVector<const Layer*>& getSilkscreenLayersBot() const noexcept {
139 }
140 const QMap<QString, bool>& getLayersVisibility() const noexcept {
141 return mLayersVisibility;
142 }
143
144 // Setters
145 void setName(const ElementName& name) noexcept { mName = name; }
146 void setDefaultFontName(const QString& name) noexcept {
148 }
149 void setGridInterval(const PositiveLength& interval) noexcept {
150 mGridInterval = interval;
151 }
152 void setGridUnit(const LengthUnit& unit) noexcept { mGridUnit = unit; }
153 void setInnerLayerCount(int count) noexcept;
154 void setPcbThickness(const PositiveLength& t) noexcept { mPcbThickness = t; }
155 void setSolderResist(const PcbColor* c) noexcept { mSolderResist = c; }
156 void setSilkscreenColor(const PcbColor& c) noexcept { mSilkscreenColor = &c; }
157 void setSilkscreenLayersTop(const QVector<const Layer*>& l) noexcept {
159 }
160 void setSilkscreenLayersBot(const QVector<const Layer*>& l) noexcept {
162 }
163 void setLayersVisibility(const QMap<QString, bool>& visibility) noexcept {
164 mLayersVisibility = visibility;
165 }
166 void setDesignRules(const BoardDesignRules& rules) noexcept;
167 void setDrcSettings(const BoardDesignRuleCheckSettings& settings) noexcept;
168
169 // DRC Message Approval Methods
170 const QSet<SExpression>& getDrcMessageApprovals() const noexcept {
172 }
173 void loadDrcMessageApprovals(const Version& version,
174 const QSet<SExpression>& approvals) noexcept;
175 bool updateDrcMessageApprovals(QSet<SExpression> approvals,
176 bool partialRun) noexcept;
177 void setDrcMessageApproved(const SExpression& approval,
178 bool approved) noexcept;
179
180 // DeviceInstance Methods
181 const QMap<Uuid, BI_Device*>& getDeviceInstances() const noexcept {
182 return mDeviceInstances;
183 }
184 BI_Device* getDeviceInstanceByComponentUuid(const Uuid& uuid) const noexcept;
185 void addDeviceInstance(BI_Device& instance);
186 void removeDeviceInstance(BI_Device& instance);
187
188 // NetSegment Methods
189 const QMap<Uuid, BI_NetSegment*>& getNetSegments() const noexcept {
190 return mNetSegments;
191 }
192 void addNetSegment(BI_NetSegment& netsegment);
193 void removeNetSegment(BI_NetSegment& netsegment);
194
195 // Plane Methods
196 const QMap<Uuid, BI_Plane*>& getPlanes() const noexcept { return mPlanes; }
197 void addPlane(BI_Plane& plane);
198 void removePlane(BI_Plane& plane);
199 void invalidatePlanes(const Layer* layer = nullptr) noexcept;
200 void invalidatePlanes(const QSet<const Layer*>& layers) noexcept;
202 const QSet<const Layer*>& layers) noexcept;
203
204 // Zone Methods
205 const QMap<Uuid, BI_Zone*>& getZones() const noexcept { return mZones; }
206 void addZone(BI_Zone& zone);
207 void removeZone(BI_Zone& zone);
208
209 // Polygon Methods
210 const QMap<Uuid, BI_Polygon*>& getPolygons() const noexcept {
211 return mPolygons;
212 }
213 void addPolygon(BI_Polygon& polygon);
214 void removePolygon(BI_Polygon& polygon);
215
216 // StrokeText Methods
217 const QMap<Uuid, BI_StrokeText*>& getStrokeTexts() const noexcept {
218 return mStrokeTexts;
219 }
220 void addStrokeText(BI_StrokeText& text);
222
223 // Hole Methods
224 const QMap<Uuid, BI_Hole*>& getHoles() const noexcept { return mHoles; }
225 void addHole(BI_Hole& hole);
226 void removeHole(BI_Hole& hole);
227
228 // AirWire Methods
229 QList<BI_AirWire*> getAirWires() const noexcept { return mAirWires.values(); }
230 void scheduleAirWiresRebuild(NetSignal* netsignal) noexcept {
232 }
233 void triggerAirWiresRebuild() noexcept;
234 void forceAirWiresRebuild() noexcept;
235
236 // General Methods
237 tl::optional<std::pair<Point, Point>> calculateBoundingRect() const noexcept;
238 void addDefaultContent();
239 void copyFrom(const Board& other);
240 void addToProject();
241 void removeFromProject();
242 void save();
243
244 // Operator Overloadings
245 Board& operator=(const Board& rhs) = delete;
246 bool operator==(const Board& rhs) noexcept { return (this == &rhs); }
247 bool operator!=(const Board& rhs) noexcept { return (this != &rhs); }
248
249signals:
253
254 void deviceAdded(BI_Device& device);
258 void planeAdded(BI_Plane& plane);
259 void planeRemoved(BI_Plane& plane);
260 void zoneAdded(BI_Zone& zone);
261 void zoneRemoved(BI_Zone& zone);
262 void polygonAdded(BI_Polygon& polygon);
266 void holeAdded(BI_Hole& hole);
267 void holeRemoved(BI_Hole& hole);
268 void airWireAdded(BI_AirWire& airWire);
270
271private:
272 // General
274 const QString mDirectoryName;
275 std::unique_ptr<TransactionalDirectory> mDirectory;
277
278 QScopedPointer<BoardDesignRules> mDesignRules;
279 QScopedPointer<BoardDesignRuleCheckSettings> mDrcSettings;
280 QScopedPointer<BoardFabricationOutputSettings> mFabricationOutputSettings;
283
284 // Attributes
290
291 // Board setup
293 QSet<const Layer*> mCopperLayers;
297 QVector<const Layer*> mSilkscreenLayersTop;
298 QVector<const Layer*> mSilkscreenLayersBot;
299
300 // User settings
301 QMap<QString, bool> mLayersVisibility;
302
303 // DRC
305 QSet<SExpression> mDrcMessageApprovals;
307
308 // items
309 QMap<Uuid, BI_Device*> mDeviceInstances;
310 QMap<Uuid, BI_NetSegment*> mNetSegments;
311 QMap<Uuid, BI_Plane*> mPlanes;
312 QMap<Uuid, BI_Zone*> mZones;
313 QMap<Uuid, BI_Polygon*> mPolygons;
314 QMap<Uuid, BI_StrokeText*> mStrokeTexts;
315 QMap<Uuid, BI_Hole*> mHoles;
316 QMultiHash<NetSignal*, BI_AirWire*> mAirWires;
317};
318
319/*******************************************************************************
320 * End of File
321 ******************************************************************************/
322
323} // namespace librepcb
324
325#endif
The BI_AirWire class.
Definition: bi_airwire.h:45
The Board Item Base (BI_Base) class.
Definition: bi_base.h:45
The BI_Device class.
Definition: bi_device.h:57
The BI_Hole class.
Definition: bi_hole.h:46
The BI_NetSegment class.
Definition: bi_netsegment.h:52
The BI_Plane class.
Definition: bi_plane.h:52
The BI_Polygon class.
Definition: bi_polygon.h:46
The BI_StrokeText class.
Definition: bi_stroketext.h:49
The BI_Zone class.
Definition: bi_zone.h:46
The BoardDesignRuleCheckSettings class.
Definition: boarddesignrulechecksettings.h:44
The BoardDesignRules class.
Definition: boarddesignrules.h:45
The BoardFabricationOutputSettings class.
Definition: boardfabricationoutputsettings.h:43
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
std::shared_ptr< SceneData3D > buildScene3D(const tl::optional< Uuid > &assemblyVariant) const noexcept
Definition: board.cpp:160
void setLayersVisibility(const QMap< QString, bool > &visibility) noexcept
Definition: board.h:163
TransactionalDirectory & getDirectory() noexcept
Definition: board.h:88
void setSilkscreenColor(const PcbColor &c) noexcept
Definition: board.h:156
void removeStrokeText(BI_StrokeText &text)
Definition: board.cpp:565
QMap< Uuid, BI_Polygon * > mPolygons
Definition: board.h:313
void setName(const ElementName &name) noexcept
Definition: board.h:145
void removeHole(BI_Hole &hole)
Definition: board.cpp:596
const BoardDesignRules & getDesignRules() const noexcept
Definition: board.h:89
void invalidatePlanes(const Layer *layer=nullptr) noexcept
Definition: board.cpp:455
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition: board.h:280
void addNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:395
void addHole(BI_Hole &hole)
Definition: board.cpp:580
const LengthUnit & getGridUnit() const noexcept
Definition: board.h:116
void removeZone(BI_Zone &zone)
Definition: board.cpp:500
const BoardDesignRuleCheckSettings & getDrcSettings() const noexcept
Definition: board.h:92
PositiveLength mGridInterval
Definition: board.h:288
void removePolygon(BI_Polygon &polygon)
Definition: board.cpp:533
BoardFabricationOutputSettings & getFabricationOutputSettings() noexcept
Definition: board.h:95
void removeDeviceInstance(BI_Device &instance)
Definition: board.cpp:379
const PositiveLength & getGridInterval() const noexcept
Definition: board.h:113
void removeNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:413
void forceAirWiresRebuild() noexcept
Definition: board.cpp:648
QSet< const Layer * > mScheduledLayersForPlanesRebuild
Definition: board.h:282
QSet< SExpression > mSupportedDrcMessageApprovals
Definition: board.h:306
tl::optional< std::pair< Point, Point > > calculateBoundingRect() const noexcept
Definition: board.cpp:659
const QMap< Uuid, BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: board.h:217
const QMap< Uuid, BI_Hole * > & getHoles() const noexcept
Definition: board.h:224
void copyFrom(const Board &other)
Definition: board.cpp:706
const PcbColor * getSilkscreenColorBot() const noexcept
Definition: board.h:131
QMap< Uuid, BI_Device * > mDeviceInstances
Definition: board.h:309
void netSegmentAdded(BI_NetSegment &netSegment)
void airWireRemoved(BI_AirWire &airWire)
const QString mDirectoryName
Definition: board.h:274
void setInnerLayerCount(int count) noexcept
Definition: board.cpp:272
QVector< const Layer * > mSilkscreenLayersTop
Definition: board.h:297
LengthUnit mGridUnit
Definition: board.h:289
const QSet< const Layer * > getCopperLayers() const noexcept
Definition: board.h:118
const PcbColor & getSilkscreenColor() const noexcept
Definition: board.h:125
const QMap< Uuid, BI_Plane * > & getPlanes() const noexcept
Definition: board.h:196
void addStrokeText(BI_StrokeText &text)
Definition: board.cpp:548
void strokeTextAdded(BI_StrokeText &strokeText)
const PcbColor * mSilkscreenColor
Must never be nullptr!
Definition: board.h:296
void polygonRemoved(BI_Polygon &polygon)
void strokeTextRemoved(BI_StrokeText &strokeText)
const PositiveLength & getPcbThickness() const noexcept
Definition: board.h:121
QSet< SExpression > mDrcMessageApprovals
Definition: board.h:305
void loadDrcMessageApprovals(const Version &version, const QSet< SExpression > &approvals) noexcept
Definition: board.cpp:306
const PcbColor * getSilkscreenColorTop() const noexcept
Definition: board.h:128
const ElementName & getName() const noexcept
Definition: board.h:109
Uuid mUuid
Definition: board.h:285
QMap< Uuid, BI_Hole * > mHoles
Definition: board.h:315
const QVector< const Layer * > & getSilkscreenLayersBot() const noexcept
Definition: board.h:137
void setDrcSettings(const BoardDesignRuleCheckSettings &settings) noexcept
Definition: board.cpp:297
QScopedPointer< BoardDesignRules > mDesignRules
Definition: board.h:278
~Board() noexcept
Definition: board.cpp:111
const QVector< const Layer * > & getSilkscreenLayersTop() const noexcept
Definition: board.h:134
void setDesignRules(const BoardDesignRules &rules) noexcept
Definition: board.cpp:288
void addPlane(BI_Plane &plane)
Definition: board.cpp:428
ElementName mName
Definition: board.h:286
void setDefaultFontName(const QString &name) noexcept
Definition: board.h:146
void addDeviceInstance(BI_Device &instance)
Definition: board.cpp:361
Version mDrcMessageApprovalsVersion
Definition: board.h:304
bool mIsAddedToProject
Definition: board.h:276
QMap< Uuid, BI_Plane * > mPlanes
Definition: board.h:311
QMap< Uuid, BI_Zone * > mZones
Definition: board.h:312
void polygonAdded(BI_Polygon &polygon)
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:356
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition: board.h:98
void addPolygon(BI_Polygon &polygon)
Definition: board.cpp:515
void airWireAdded(BI_AirWire &airWire)
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition: board.h:181
void attributesChanged()
void netSegmentRemoved(BI_NetSegment &netSegment)
Board(const Board &other)=delete
bool updateDrcMessageApprovals(QSet< SExpression > approvals, bool partialRun) noexcept
Definition: board.cpp:312
void setGridUnit(const LengthUnit &unit) noexcept
Definition: board.h:152
void scheduleAirWiresRebuild(NetSignal *netsignal) noexcept
Definition: board.h:230
const QSet< SExpression > & getDrcMessageApprovals() const noexcept
Definition: board.h:170
Project & getProject() const noexcept
Definition: board.h:86
PositiveLength mPcbThickness
Total PCB thickness (all layers)
Definition: board.h:294
QSet< const Layer * > mCopperLayers
Derived from mInnerLayerCount.
Definition: board.h:293
const QString & getDefaultFontName() const noexcept
Definition: board.h:110
QList< BI_Base * > getAllItems() const noexcept
Definition: board.cpp:147
void addToProject()
Definition: board.cpp:839
Project & mProject
A reference to the Project object (from the ctor)
Definition: board.h:273
int getInnerLayerCount() const noexcept
Definition: board.h:117
int mInnerLayerCount
Definition: board.h:292
void zoneRemoved(BI_Zone &zone)
void addDefaultContent()
Definition: board.cpp:696
void triggerAirWiresRebuild() noexcept
Definition: board.cpp:611
QScopedPointer< BoardDesignRuleCheckSettings > mDrcSettings
Definition: board.h:279
const QMap< Uuid, BI_NetSegment * > & getNetSegments() const noexcept
Definition: board.h:189
void deviceRemoved(BI_Device &device)
QString mDefaultFontFileName
Definition: board.h:287
QMap< QString, bool > mLayersVisibility
Definition: board.h:301
void planeAdded(BI_Plane &plane)
void designRulesModified()
QMap< Uuid, BI_NetSegment * > mNetSegments
Definition: board.h:310
void save()
Definition: board.cpp:885
const Uuid & getUuid() const noexcept
Definition: board.h:108
void removePlane(BI_Plane &plane)
Definition: board.cpp:444
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: board.h:275
void addZone(BI_Zone &zone)
Definition: board.cpp:484
QSet< const Layer * > takeScheduledLayersForPlanesRebuild(const QSet< const Layer * > &layers) noexcept
Definition: board.cpp:473
bool isEmpty() const noexcept
Definition: board.cpp:141
void setSilkscreenLayersTop(const QVector< const Layer * > &l) noexcept
Definition: board.h:157
void setPcbThickness(const PositiveLength &t) noexcept
Definition: board.h:154
void setSilkscreenLayersBot(const QVector< const Layer * > &l) noexcept
Definition: board.h:160
void planeRemoved(BI_Plane &plane)
const QMap< QString, bool > & getLayersVisibility() const noexcept
Definition: board.h:140
bool operator!=(const Board &rhs) noexcept
Definition: board.h:247
const PcbColor * mSolderResist
nullptr means no solder resist!
Definition: board.h:295
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition: board.h:281
void removeFromProject()
Definition: board.cpp:864
void innerLayerCountChanged()
const QMap< Uuid, BI_Zone * > & getZones() const noexcept
Definition: board.h:205
void holeAdded(BI_Hole &hole)
QMap< Uuid, BI_StrokeText * > mStrokeTexts
Definition: board.h:314
void zoneAdded(BI_Zone &zone)
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition: board.h:316
void deviceAdded(BI_Device &device)
const PcbColor * getSolderResist() const noexcept
Definition: board.h:124
const QMap< Uuid, BI_Polygon * > & getPolygons() const noexcept
Definition: board.h:210
QVector< const Layer * > mSilkscreenLayersBot
Definition: board.h:298
void holeRemoved(BI_Hole &hole)
void setGridInterval(const PositiveLength &interval) noexcept
Definition: board.h:149
void setSolderResist(const PcbColor *c) noexcept
Definition: board.h:155
QList< BI_AirWire * > getAirWires() const noexcept
Definition: board.h:229
void setDrcMessageApproved(const SExpression &approval, bool approved) noexcept
Definition: board.cpp:343
const QString & getDirectoryName() const noexcept
Definition: board.h:87
The Layer class provides all supported geometry layers.
Definition: layer.h:42
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The NetSignal class.
Definition: netsignal.h:50
Predefined colors relevant for PCB fabrication.
Definition: pcbcolor.h:41
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
The SExpression class.
Definition: sexpression.h:69
3D scene data representing a board with package models
Definition: scenedata3d.h:53
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:51
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84
Definition: uuid.h:183