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  ******************************************************************************/
41 namespace librepcb {
42 
43 class BI_AirWire;
44 class BI_Base;
45 class BI_Device;
46 class BI_FootprintPad;
47 class BI_Hole;
48 class BI_NetLine;
49 class BI_NetPoint;
50 class BI_NetSegment;
51 class BI_Plane;
52 class BI_Polygon;
53 class BI_StrokeText;
54 class BI_Via;
55 class BI_Zone;
56 class BoardDesignRuleCheckSettings;
57 class BoardDesignRules;
58 class BoardFabricationOutputSettings;
59 class Layer;
60 class NetSignal;
61 class PcbColor;
62 class Project;
63 class SceneData3D;
64 
65 /*******************************************************************************
66  * Class Board
67  ******************************************************************************/
68 
73 class Board final : public QObject {
74  Q_OBJECT
75 
76 public:
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  }
92  const BoardDesignRuleCheckSettings& getDrcSettings() const noexcept {
93  return *mDrcSettings;
94  }
97  }
99  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 {
111  return mDefaultFontFileName;
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 {
135  return mSilkscreenLayersTop;
136  }
137  const QVector<const Layer*>& getSilkscreenLayersBot() const noexcept {
138  return mSilkscreenLayersBot;
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 {
147  mDefaultFontFileName = name;
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 {
171  return mDrcMessageApprovals;
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;
201  QSet<const Layer*> takeScheduledLayersForPlanesRebuild(
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);
221  void removeStrokeText(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 {
231  mScheduledNetSignalsForAirWireRebuild.insert(netsignal);
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 
249 signals:
250  void attributesChanged();
251  void designRulesModified();
252  void innerLayerCountChanged();
253 
254  void deviceAdded(BI_Device& device);
255  void deviceRemoved(BI_Device& device);
256  void netSegmentAdded(BI_NetSegment& netSegment);
257  void netSegmentRemoved(BI_NetSegment& netSegment);
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);
263  void polygonRemoved(BI_Polygon& polygon);
264  void strokeTextAdded(BI_StrokeText& strokeText);
265  void strokeTextRemoved(BI_StrokeText& strokeText);
266  void holeAdded(BI_Hole& hole);
267  void holeRemoved(BI_Hole& hole);
268  void airWireAdded(BI_AirWire& airWire);
269  void airWireRemoved(BI_AirWire& airWire);
270 
271 private:
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;
306  QSet<SExpression> mSupportedDrcMessageApprovals;
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
bool mIsAddedToProject
Definition: board.h:276
~Board() noexcept
Definition: board.cpp:111
void airWireRemoved(BI_AirWire &airWire)
QList< BI_AirWire * > getAirWires() const noexcept
Definition: board.h:229
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
const ElementName & getName() const noexcept
Definition: board.h:109
const Uuid & getUuid() const noexcept
Definition: board.h:108
Predefined colors relevant for PCB fabrication.
Definition: pcbcolor.h:41
void setInnerLayerCount(int count) noexcept
Definition: board.cpp:280
void attributesChanged()
void loadDrcMessageApprovals(const Version &version, const QSet< SExpression > &approvals) noexcept
Definition: board.cpp:314
void removePolygon(BI_Polygon &polygon)
Definition: board.cpp:539
bool operator!=(const Board &rhs) noexcept
Definition: board.h:247
TransactionalDirectory & getDirectory() noexcept
Definition: board.h:88
const QMap< Uuid, BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: board.h:217
void setPcbThickness(const PositiveLength &t) noexcept
Definition: board.h:154
ElementName mName
Definition: board.h:286
QMap< Uuid, BI_Plane * > mPlanes
Definition: board.h:311
Uuid mUuid
Definition: board.h:285
void netSegmentAdded(BI_NetSegment &netSegment)
void removeZone(BI_Zone &zone)
Definition: board.cpp:506
void innerLayerCountChanged()
bool isEmpty() const noexcept
Definition: board.cpp:141
void deviceRemoved(BI_Device &device)
Definition: occmodel.cpp:76
The BI_Device class.
Definition: bi_device.h:57
The BI_Hole class.
Definition: bi_hole.h:46
QSet< SExpression > mSupportedDrcMessageApprovals
Definition: board.h:306
void removeStrokeText(BI_StrokeText &text)
Definition: board.cpp:571
The BI_AirWire class.
Definition: bi_airwire.h:45
QMap< Uuid, BI_Device * > mDeviceInstances
Definition: board.h:309
Project & mProject
A reference to the Project object (from the ctor)
Definition: board.h:273
The Layer class provides all supported geometry layers.
Definition: layer.h:40
std::shared_ptr< SceneData3D > buildScene3D(const tl::optional< Uuid > &assemblyVariant) const noexcept
Definition: board.cpp:168
void setDesignRules(const BoardDesignRules &rules) noexcept
Definition: board.cpp:296
The BoardDesignRules class.
Definition: boarddesignrules.h:45
void removeDeviceInstance(BI_Device &instance)
Definition: board.cpp:387
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition: board.h:98
void designRulesModified()
void setSolderResist(const PcbColor *c) noexcept
Definition: board.h:155
QSet< SExpression > mDrcMessageApprovals
Definition: board.h:305
void strokeTextAdded(BI_StrokeText &strokeText)
void removeFromProject()
Definition: board.cpp:869
const QMap< Uuid, BI_Zone * > & getZones() const noexcept
Definition: board.h:205
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:51
void airWireAdded(BI_AirWire &airWire)
const QSet< SExpression > & getDrcMessageApprovals() const noexcept
Definition: board.h:170
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: board.h:275
const QString & getDefaultFontName() const noexcept
Definition: board.h:110
bool updateDrcMessageApprovals(QSet< SExpression > approvals, bool partialRun) noexcept
Definition: board.cpp:320
LengthUnit mGridUnit
Definition: board.h:289
const BoardDesignRules & getDesignRules() const noexcept
Definition: board.h:89
QList< BI_Base * > getAllItems() const noexcept
Definition: board.cpp:147
void zoneRemoved(BI_Zone &zone)
QMap< Uuid, BI_Polygon * > mPolygons
Definition: board.h:313
QSet< const Layer * > takeScheduledLayersForPlanesRebuild(const QSet< const Layer *> &layers) noexcept
Definition: board.cpp:479
void addHole(BI_Hole &hole)
Definition: board.cpp:586
void planeAdded(BI_Plane &plane)
const PcbColor * getSilkscreenColorTop() const noexcept
Definition: board.h:128
QString mDefaultFontFileName
Definition: board.h:287
const QMap< QString, bool > & getLayersVisibility() const noexcept
Definition: board.h:140
void strokeTextRemoved(BI_StrokeText &strokeText)
QMap< QString, bool > mLayersVisibility
Definition: board.h:301
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:364
void addToProject()
Definition: board.cpp:844
void zoneAdded(BI_Zone &zone)
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition: board.h:316
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition: board.h:280
void scheduleAirWiresRebuild(NetSignal *netsignal) noexcept
Definition: board.h:230
QMap< Uuid, BI_Zone * > mZones
Definition: board.h:312
const QMap< Uuid, BI_Plane * > & getPlanes() const noexcept
Definition: board.h:196
QSet< const Layer * > mScheduledLayersForPlanesRebuild
Definition: board.h:282
void copyFrom(const Board &other)
Definition: board.cpp:712
const PcbColor * mSolderResist
nullptr means no solder resist!
Definition: board.h:295
void forceAirWiresRebuild() noexcept
Definition: board.cpp:654
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
void addStrokeText(BI_StrokeText &text)
Definition: board.cpp:554
void polygonAdded(BI_Polygon &polygon)
const QString mDirectoryName
Definition: board.h:274
const PositiveLength & getPcbThickness() const noexcept
Definition: board.h:121
int mInnerLayerCount
Definition: board.h:292
void triggerAirWiresRebuild() noexcept
Definition: board.cpp:617
void setSilkscreenColor(const PcbColor &c) noexcept
Definition: board.h:156
void addPlane(BI_Plane &plane)
Definition: board.cpp:436
Version mDrcMessageApprovalsVersion
Definition: board.h:304
The BI_NetSegment class.
Definition: bi_netsegment.h:52
bool operator==(const Board &rhs) noexcept
Definition: board.h:246
QMap< Uuid, BI_StrokeText * > mStrokeTexts
Definition: board.h:314
const QSet< const Layer * > getCopperLayers() const noexcept
Definition: board.h:118
void holeAdded(BI_Hole &hole)
void planeRemoved(BI_Plane &plane)
const PositiveLength & getGridInterval() const noexcept
Definition: board.h:113
void invalidatePlanes(const Layer *layer=nullptr) noexcept
Definition: board.cpp:463
const QMap< Uuid, BI_Polygon * > & getPolygons() const noexcept
Definition: board.h:210
void removePlane(BI_Plane &plane)
Definition: board.cpp:452
The BI_StrokeText class.
Definition: bi_stroketext.h:49
QScopedPointer< BoardDesignRules > mDesignRules
Definition: board.h:278
QMap< Uuid, BI_NetSegment * > mNetSegments
Definition: board.h:310
void addNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:403
void addDefaultContent()
Definition: board.cpp:702
void removeNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:421
const PcbColor * getSolderResist() const noexcept
Definition: board.h:124
The BI_Plane class.
Definition: bi_plane.h:52
Project & getProject() const noexcept
Definition: board.h:86
const QMap< Uuid, BI_Hole * > & getHoles() const noexcept
Definition: board.h:224
void addDeviceInstance(BI_Device &instance)
Definition: board.cpp:369
const PcbColor * mSilkscreenColor
Must never be nullptr!
Definition: board.h:296
The NetSignal class.
Definition: netsignal.h:50
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
QScopedPointer< BoardDesignRuleCheckSettings > mDrcSettings
Definition: board.h:279
const QVector< const Layer * > & getSilkscreenLayersBot() const noexcept
Definition: board.h:137
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition: board.h:281
BoardFabricationOutputSettings & getFabricationOutputSettings() noexcept
Definition: board.h:95
const PcbColor & getSilkscreenColor() const noexcept
Definition: board.h:125
void addPolygon(BI_Polygon &polygon)
Definition: board.cpp:521
QVector< const Layer * > mSilkscreenLayersTop
Definition: board.h:297
void removeHole(BI_Hole &hole)
Definition: board.cpp:602
PositiveLength mGridInterval
Definition: board.h:288
const PcbColor * getSilkscreenColorBot() const noexcept
Definition: board.h:131
const BoardDesignRuleCheckSettings & getDrcSettings() const noexcept
Definition: board.h:92
void setSilkscreenLayersTop(const QVector< const Layer *> &l) noexcept
Definition: board.h:157
void addZone(BI_Zone &zone)
Definition: board.cpp:490
void setDrcMessageApproved(const SExpression &approval, bool approved) noexcept
Definition: board.cpp:351
void setDrcSettings(const BoardDesignRuleCheckSettings &settings) noexcept
Definition: board.cpp:305
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:785
The BI_Polygon class.
Definition: bi_polygon.h:46
The BoardFabricationOutputSettings class.
Definition: boardfabricationoutputsettings.h:43
tl::optional< std::pair< Point, Point > > calculateBoundingRect() const noexcept
Definition: board.cpp:665
void setDefaultFontName(const QString &name) noexcept
Definition: board.h:146
The BI_Zone class.
Definition: bi_zone.h:46
PositiveLength mPcbThickness
Total PCB thickness (all layers)
Definition: board.h:294
const QVector< const Layer * > & getSilkscreenLayersTop() const noexcept
Definition: board.h:134
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
void deviceAdded(BI_Device &device)
QMap< Uuid, BI_Hole * > mHoles
Definition: board.h:315
void setGridInterval(const PositiveLength &interval) noexcept
Definition: board.h:149
void save()
Definition: board.cpp:890
void setGridUnit(const LengthUnit &unit) noexcept
Definition: board.h:152
const LengthUnit & getGridUnit() const noexcept
Definition: board.h:116
The BoardDesignRuleCheckSettings class.
Definition: boarddesignrulechecksettings.h:44
void holeRemoved(BI_Hole &hole)
void polygonRemoved(BI_Polygon &polygon)
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition: board.h:181
void netSegmentRemoved(BI_NetSegment &netSegment)
QVector< const Layer * > mSilkscreenLayersBot
Definition: board.h:298
void setSilkscreenLayersBot(const QVector< const Layer *> &l) noexcept
Definition: board.h:160
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The SExpression class.
Definition: sexpression.h:66
const QString & getDirectoryName() const noexcept
Definition: board.h:87
void setLayersVisibility(const QMap< QString, bool > &visibility) noexcept
Definition: board.h:163
const QMap< Uuid, BI_NetSegment * > & getNetSegments() const noexcept
Definition: board.h:189
QSet< const Layer * > mCopperLayers
Derived from mInnerLayerCount.
Definition: board.h:293
void setName(const ElementName &name) noexcept
Definition: board.h:145
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:83
Board & operator=(const Board &rhs)=delete
int getInnerLayerCount() const noexcept
Definition: board.h:117