LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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/tag.h"
32#include "../../types/uuid.h"
33#include "../../types/version.h"
34
35#include <QtCore>
36
37#include <memory>
38
39/*******************************************************************************
40 * Namespace / Forward Declarations
41 ******************************************************************************/
42namespace librepcb {
43
44class BI_AirWire;
45class BI_Base;
46class BI_Device;
47class BI_Hole;
48class BI_NetLine;
49class BI_NetPoint;
50class BI_NetSegment;
51class BI_Pad;
52class BI_Plane;
53class BI_Polygon;
54class BI_StrokeText;
55class BI_Via;
56class BI_Zone;
57class BoardDesignRuleCheckSettings;
58class BoardDesignRules;
59class BoardFabricationOutputSettings;
60class Layer;
61class NetSignal;
62class PcbColor;
63class Project;
64class SceneData3D;
65
66/*******************************************************************************
67 * Class Board
68 ******************************************************************************/
69
74class Board final : public QObject {
75 Q_OBJECT
76
77public:
79 QVector<Tag> thtTop;
80 QVector<Tag> thtBot;
81 QVector<Tag> smtTop;
82 QVector<Tag> smtBot;
83 QVector<Tag> common;
84
85 PreferredFootprintTags() noexcept;
87 bool isEmpty() const noexcept;
88 bool operator==(const PreferredFootprintTags& rhs) const noexcept = default;
89 bool operator!=(const PreferredFootprintTags& rhs) const noexcept = default;
95 void serialize(SExpression& root) const;
96 };
97
98 // Constructors / Destructor
99 Board() = delete;
100 Board(const Board& other) = delete;
101 Board(Project& project, std::unique_ptr<TransactionalDirectory> directory,
102 const QString& directoryName, const Uuid& uuid,
103 const ElementName& name);
104 ~Board() noexcept;
105
106 // Getters: General
107 Project& getProject() const noexcept { return mProject; }
108 const QString& getDirectoryName() const noexcept { return mDirectoryName; }
110 const BoardDesignRules& getDesignRules() const noexcept {
111 return *mDesignRules;
112 }
114 return *mDrcSettings;
115 }
123 bool isEmpty() const noexcept;
124 QList<BI_Base*> getAllItems() const noexcept;
125 std::shared_ptr<SceneData3D> buildScene3D(
126 const std::optional<Uuid>& assemblyVariant) const noexcept;
127
128 // Getters: Attributes
129 const Uuid& getUuid() const noexcept { return mUuid; }
130 const ElementName& getName() const noexcept { return mName; }
131 const QString& getDefaultFontName() const noexcept {
133 }
134 const PositiveLength& getGridInterval() const noexcept {
135 return mGridInterval;
136 }
137 const LengthUnit& getGridUnit() const noexcept { return mGridUnit; }
141 int getInnerLayerCount() const noexcept { return mInnerLayerCount; }
142 const QSet<const Layer*> getCopperLayers() const noexcept {
143 return mCopperLayers;
144 }
145 const PositiveLength& getPcbThickness() const noexcept {
146 return mPcbThickness;
147 }
148 const PcbColor* getSolderResist() const noexcept { return mSolderResist; }
149 const PcbColor& getSilkscreenColor() const noexcept {
150 return *mSilkscreenColor;
151 }
152 const PcbColor* getSilkscreenColorTop() const noexcept {
153 return (!mSilkscreenLayersTop.isEmpty()) ? mSilkscreenColor : nullptr;
154 }
155 const PcbColor* getSilkscreenColorBot() const noexcept {
156 return (!mSilkscreenLayersBot.isEmpty()) ? mSilkscreenColor : nullptr;
157 }
158 const QVector<const Layer*>& getSilkscreenLayersTop() const noexcept {
160 }
161 const QVector<const Layer*>& getSilkscreenLayersBot() const noexcept {
163 }
164 const QMap<QString, bool>& getLayersVisibility() const noexcept {
165 return mLayersVisibility;
166 }
167
168 // Setters
169 void setName(const ElementName& name) noexcept;
170 void setDefaultFontName(const QString& name) noexcept {
172 }
173 void setPreferredFootprintTags(const PreferredFootprintTags& tags) noexcept;
174 void setGridInterval(const PositiveLength& interval) noexcept {
175 mGridInterval = interval;
176 }
177 void setGridUnit(const LengthUnit& unit) noexcept { mGridUnit = unit; }
178 void setInnerLayerCount(int count) noexcept;
179 void setPcbThickness(const PositiveLength& t) noexcept { mPcbThickness = t; }
180 void setSolderResist(const PcbColor* c) noexcept { mSolderResist = c; }
181 void setSilkscreenColor(const PcbColor& c) noexcept { mSilkscreenColor = &c; }
182 void setSilkscreenLayersTop(const QVector<const Layer*>& l) noexcept {
184 }
185 void setSilkscreenLayersBot(const QVector<const Layer*>& l) noexcept {
187 }
188 void setLayersVisibility(const QMap<QString, bool>& visibility) noexcept {
189 mLayersVisibility = visibility;
190 }
191 void setDesignRules(const BoardDesignRules& rules) noexcept;
192 void setDrcSettings(const BoardDesignRuleCheckSettings& settings) noexcept;
193
194 // DRC Message Approval Methods
195 const QSet<SExpression>& getDrcMessageApprovals() const noexcept {
197 }
198 void loadDrcMessageApprovals(const Version& version,
199 const QSet<SExpression>& approvals) noexcept;
200 bool updateDrcMessageApprovals(QSet<SExpression> approvals,
201 bool partialRun) noexcept;
202 void setDrcMessageApproved(const SExpression& approval,
203 bool approved) noexcept;
204
205 // DeviceInstance Methods
206 const QMap<Uuid, BI_Device*>& getDeviceInstances() const noexcept {
207 return mDeviceInstances;
208 }
209 BI_Device* getDeviceInstanceByComponentUuid(const Uuid& uuid) const noexcept;
210 void addDeviceInstance(BI_Device& instance);
211 void removeDeviceInstance(BI_Device& instance);
212
213 // NetSegment Methods
214 const QMap<Uuid, BI_NetSegment*>& getNetSegments() const noexcept {
215 return mNetSegments;
216 }
217 void addNetSegment(BI_NetSegment& netsegment);
218 void removeNetSegment(BI_NetSegment& netsegment);
219
220 // Plane Methods
221 const QMap<Uuid, BI_Plane*>& getPlanes() const noexcept { return mPlanes; }
222 void addPlane(BI_Plane& plane);
223 void removePlane(BI_Plane& plane);
224 void invalidatePlanes(const Layer* layer = nullptr) noexcept;
225 void invalidatePlanes(const QSet<const Layer*>& layers) noexcept;
227 const QSet<const Layer*>& layers) noexcept;
228
229 // Zone Methods
230 const QMap<Uuid, BI_Zone*>& getZones() const noexcept { return mZones; }
231 void addZone(BI_Zone& zone);
232 void removeZone(BI_Zone& zone);
233
234 // Polygon Methods
235 const QMap<Uuid, BI_Polygon*>& getPolygons() const noexcept {
236 return mPolygons;
237 }
238 void addPolygon(BI_Polygon& polygon);
239 void removePolygon(BI_Polygon& polygon);
240
241 // StrokeText Methods
242 const QMap<Uuid, BI_StrokeText*>& getStrokeTexts() const noexcept {
243 return mStrokeTexts;
244 }
245 void addStrokeText(BI_StrokeText& text);
247
248 // Hole Methods
249 const QMap<Uuid, BI_Hole*>& getHoles() const noexcept { return mHoles; }
250 void addHole(BI_Hole& hole);
251 void removeHole(BI_Hole& hole);
252
253 // AirWire Methods
254 QList<BI_AirWire*> getAirWires() const noexcept { return mAirWires.values(); }
255 void scheduleAirWiresRebuild(NetSignal* netsignal) noexcept {
257 }
258 void triggerAirWiresRebuild() noexcept;
259 void forceAirWiresRebuild() noexcept;
260
261 // General Methods
262 std::optional<std::pair<Point, Point>> calculateBoundingRect() const noexcept;
263 void addDefaultContent();
264 void copyFrom(const Board& other);
265 void addToProject();
266 void removeFromProject();
267 void save();
268
269 // Operator Overloadings
270 Board& operator=(const Board& rhs) = delete;
271 bool operator==(const Board& rhs) const noexcept { return (this == &rhs); }
272 bool operator!=(const Board& rhs) const noexcept { return (this != &rhs); }
273
274signals:
275 void nameChanged(const ElementName& name);
280
281 void deviceAdded(BI_Device& device);
285 void planeAdded(BI_Plane& plane);
286 void planeRemoved(BI_Plane& plane);
287 void zoneAdded(BI_Zone& zone);
288 void zoneRemoved(BI_Zone& zone);
289 void polygonAdded(BI_Polygon& polygon);
293 void holeAdded(BI_Hole& hole);
294 void holeRemoved(BI_Hole& hole);
295 void airWireAdded(BI_AirWire& airWire);
297
298private:
299 // General
301 const QString mDirectoryName;
302 std::unique_ptr<TransactionalDirectory> mDirectory;
304
305 QScopedPointer<BoardDesignRules> mDesignRules;
306 QScopedPointer<BoardDesignRuleCheckSettings> mDrcSettings;
307 QScopedPointer<BoardFabricationOutputSettings> mFabricationOutputSettings;
310
311 // Attributes
318
319 // Board setup
321 QSet<const Layer*> mCopperLayers;
325 QVector<const Layer*> mSilkscreenLayersTop;
326 QVector<const Layer*> mSilkscreenLayersBot;
327
328 // User settings
329 // Those are stored in settings.user.lp and usually not under version control.
330 // Therefore it is allowed to add/remove settings without introducing a new
331 // file format version.
332 QMap<QString, bool> mLayersVisibility;
333
334 // DRC
336 QSet<SExpression> mDrcMessageApprovals;
338
339 // items
340 QMap<Uuid, BI_Device*> mDeviceInstances;
341 QMap<Uuid, BI_NetSegment*> mNetSegments;
342 QMap<Uuid, BI_Plane*> mPlanes;
343 QMap<Uuid, BI_Zone*> mZones;
344 QMap<Uuid, BI_Polygon*> mPolygons;
345 QMap<Uuid, BI_StrokeText*> mStrokeTexts;
346 QMap<Uuid, BI_Hole*> mHoles;
347 QMultiHash<NetSignal*, BI_AirWire*> mAirWires;
348};
349
350/*******************************************************************************
351 * End of File
352 ******************************************************************************/
353
354} // namespace librepcb
355
356#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:53
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:50
The BoardDesignRules class.
Definition boarddesignrules.h:46
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:74
void setLayersVisibility(const QMap< QString, bool > &visibility) noexcept
Definition board.h:188
TransactionalDirectory & getDirectory() noexcept
Definition board.h:109
void setSilkscreenColor(const PcbColor &c) noexcept
Definition board.h:181
void removeStrokeText(BI_StrokeText &text)
Definition board.cpp:651
QMap< Uuid, BI_Polygon * > mPolygons
Definition board.h:344
void setName(const ElementName &name) noexcept
Definition board.cpp:342
void removeHole(BI_Hole &hole)
Definition board.cpp:682
const BoardDesignRules & getDesignRules() const noexcept
Definition board.h:110
void invalidatePlanes(const Layer *layer=nullptr) noexcept
Definition board.cpp:541
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition board.h:307
void addNetSegment(BI_NetSegment &netsegment)
Definition board.cpp:481
void addHole(BI_Hole &hole)
Definition board.cpp:666
const LengthUnit & getGridUnit() const noexcept
Definition board.h:137
void removeZone(BI_Zone &zone)
Definition board.cpp:586
const BoardDesignRuleCheckSettings & getDrcSettings() const noexcept
Definition board.h:113
PositiveLength mGridInterval
Definition board.h:315
void removePolygon(BI_Polygon &polygon)
Definition board.cpp:619
BoardFabricationOutputSettings & getFabricationOutputSettings() noexcept
Definition board.h:116
void removeDeviceInstance(BI_Device &instance)
Definition board.cpp:465
const PositiveLength & getGridInterval() const noexcept
Definition board.h:134
void removeNetSegment(BI_NetSegment &netsegment)
Definition board.cpp:499
void forceAirWiresRebuild() noexcept
Definition board.cpp:734
QSet< const Layer * > mScheduledLayersForPlanesRebuild
Definition board.h:309
QSet< SExpression > mSupportedDrcMessageApprovals
Definition board.h:337
const QMap< Uuid, BI_StrokeText * > & getStrokeTexts() const noexcept
Definition board.h:242
const QMap< Uuid, BI_Hole * > & getHoles() const noexcept
Definition board.h:249
void copyFrom(const Board &other)
Definition board.cpp:792
const PcbColor * getSilkscreenColorBot() const noexcept
Definition board.h:155
QMap< Uuid, BI_Device * > mDeviceInstances
Definition board.h:340
void netSegmentAdded(BI_NetSegment &netSegment)
void airWireRemoved(BI_AirWire &airWire)
const QString mDirectoryName
Definition board.h:301
void setInnerLayerCount(int count) noexcept
Definition board.cpp:358
std::shared_ptr< SceneData3D > buildScene3D(const std::optional< Uuid > &assemblyVariant) const noexcept
Definition board.cpp:215
QVector< const Layer * > mSilkscreenLayersTop
Definition board.h:325
LengthUnit mGridUnit
Definition board.h:316
const QSet< const Layer * > getCopperLayers() const noexcept
Definition board.h:142
const PcbColor & getSilkscreenColor() const noexcept
Definition board.h:149
const QMap< Uuid, BI_Plane * > & getPlanes() const noexcept
Definition board.h:221
void nameChanged(const ElementName &name)
void addStrokeText(BI_StrokeText &text)
Definition board.cpp:634
void strokeTextAdded(BI_StrokeText &strokeText)
const PcbColor * mSilkscreenColor
Must never be nullptr!
Definition board.h:324
void polygonRemoved(BI_Polygon &polygon)
void strokeTextRemoved(BI_StrokeText &strokeText)
const PositiveLength & getPcbThickness() const noexcept
Definition board.h:145
QSet< SExpression > mDrcMessageApprovals
Definition board.h:336
void loadDrcMessageApprovals(const Version &version, const QSet< SExpression > &approvals) noexcept
Definition board.cpp:392
const PcbColor * getSilkscreenColorTop() const noexcept
Definition board.h:152
const ElementName & getName() const noexcept
Definition board.h:130
Uuid mUuid
Definition board.h:312
QMap< Uuid, BI_Hole * > mHoles
Definition board.h:346
const QVector< const Layer * > & getSilkscreenLayersBot() const noexcept
Definition board.h:161
void setDrcSettings(const BoardDesignRuleCheckSettings &settings) noexcept
Definition board.cpp:383
QScopedPointer< BoardDesignRules > mDesignRules
Definition board.h:305
const QVector< const Layer * > & getSilkscreenLayersTop() const noexcept
Definition board.h:158
void setDesignRules(const BoardDesignRules &rules) noexcept
Definition board.cpp:374
void addPlane(BI_Plane &plane)
Definition board.cpp:514
ElementName mName
Definition board.h:313
void setDefaultFontName(const QString &name) noexcept
Definition board.h:170
void preferredFootprintTagsChanged()
void addDeviceInstance(BI_Device &instance)
Definition board.cpp:447
Version mDrcMessageApprovalsVersion
Definition board.h:335
bool mIsAddedToProject
Definition board.h:303
QMap< Uuid, BI_Plane * > mPlanes
Definition board.h:342
QMap< Uuid, BI_Zone * > mZones
Definition board.h:343
void polygonAdded(BI_Polygon &polygon)
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition board.cpp:442
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition board.h:119
void addPolygon(BI_Polygon &polygon)
Definition board.cpp:601
void airWireAdded(BI_AirWire &airWire)
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition board.h:206
void attributesChanged()
void netSegmentRemoved(BI_NetSegment &netSegment)
bool updateDrcMessageApprovals(QSet< SExpression > approvals, bool partialRun) noexcept
Definition board.cpp:398
void setGridUnit(const LengthUnit &unit) noexcept
Definition board.h:177
void scheduleAirWiresRebuild(NetSignal *netsignal) noexcept
Definition board.h:255
const QSet< SExpression > & getDrcMessageApprovals() const noexcept
Definition board.h:195
Project & getProject() const noexcept
Definition board.h:107
PositiveLength mPcbThickness
Total PCB thickness (all layers)
Definition board.h:322
QSet< const Layer * > mCopperLayers
Derived from mInnerLayerCount.
Definition board.h:321
const QString & getDefaultFontName() const noexcept
Definition board.h:131
QList< BI_Base * > getAllItems() const noexcept
Definition board.cpp:202
void addToProject()
Definition board.cpp:937
Project & mProject
A reference to the Project object (from the ctor)
Definition board.h:300
int getInnerLayerCount() const noexcept
Definition board.h:141
bool operator!=(const Board &rhs) const noexcept
Definition board.h:272
int mInnerLayerCount
Definition board.h:320
void zoneRemoved(BI_Zone &zone)
void addDefaultContent()
Definition board.cpp:782
void triggerAirWiresRebuild() noexcept
Definition board.cpp:697
QScopedPointer< BoardDesignRuleCheckSettings > mDrcSettings
Definition board.h:306
const PreferredFootprintTags & getPreferredFootprintTags() const noexcept
Definition board.h:138
const QMap< Uuid, BI_NetSegment * > & getNetSegments() const noexcept
Definition board.h:214
void deviceRemoved(BI_Device &device)
QString mDefaultFontFileName
Definition board.h:314
QMap< QString, bool > mLayersVisibility
Definition board.h:332
void planeAdded(BI_Plane &plane)
void designRulesModified()
QMap< Uuid, BI_NetSegment * > mNetSegments
Definition board.h:341
PreferredFootprintTags mPreferredFootprintTags
Definition board.h:317
void save()
Definition board.cpp:983
void setPreferredFootprintTags(const PreferredFootprintTags &tags) noexcept
Definition board.cpp:350
const Uuid & getUuid() const noexcept
Definition board.h:129
std::optional< std::pair< Point, Point > > calculateBoundingRect() const noexcept
Definition board.cpp:745
void removePlane(BI_Plane &plane)
Definition board.cpp:530
std::unique_ptr< TransactionalDirectory > mDirectory
Definition board.h:302
void addZone(BI_Zone &zone)
Definition board.cpp:570
QSet< const Layer * > takeScheduledLayersForPlanesRebuild(const QSet< const Layer * > &layers) noexcept
Definition board.cpp:559
void setSilkscreenLayersTop(const QVector< const Layer * > &l) noexcept
Definition board.h:182
void setPcbThickness(const PositiveLength &t) noexcept
Definition board.h:179
void setSilkscreenLayersBot(const QVector< const Layer * > &l) noexcept
Definition board.h:185
void planeRemoved(BI_Plane &plane)
const QMap< QString, bool > & getLayersVisibility() const noexcept
Definition board.h:164
const PcbColor * mSolderResist
nullptr means no solder resist!
Definition board.h:323
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition board.h:308
void removeFromProject()
Definition board.cpp:962
void innerLayerCountChanged()
const QMap< Uuid, BI_Zone * > & getZones() const noexcept
Definition board.h:230
void holeAdded(BI_Hole &hole)
QMap< Uuid, BI_StrokeText * > mStrokeTexts
Definition board.h:345
void zoneAdded(BI_Zone &zone)
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition board.h:347
void deviceAdded(BI_Device &device)
const PcbColor * getSolderResist() const noexcept
Definition board.h:148
const QMap< Uuid, BI_Polygon * > & getPolygons() const noexcept
Definition board.h:235
QVector< const Layer * > mSilkscreenLayersBot
Definition board.h:326
void holeRemoved(BI_Hole &hole)
void setGridInterval(const PositiveLength &interval) noexcept
Definition board.h:174
void setSolderResist(const PcbColor *c) noexcept
Definition board.h:180
QList< BI_AirWire * > getAirWires() const noexcept
Definition board.h:254
void setDrcMessageApproved(const SExpression &approval, bool approved) noexcept
Definition board.cpp:429
const QString & getDirectoryName() const noexcept
Definition board.h:108
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:62
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:78
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:52
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:56
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:810
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition uuid.h:186
QVector< Tag > thtBot
Definition board.h:80
QVector< Tag > smtBot
Definition board.h:82
QVector< Tag > thtTop
Definition board.h:79
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition board.cpp:105
QVector< Tag > smtTop
Definition board.h:81
PreferredFootprintTags() noexcept
Definition board.cpp:88
bool isEmpty() const noexcept
Definition board.cpp:100
QVector< Tag > common
Definition board.h:83