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_PROJECT_BOARD_H
21 #define LIBREPCB_PROJECT_BOARD_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../erc/if_ercmsgprovider.h"
27 
35 #include <librepcb/common/uuid.h>
36 
37 #include <QPrinter>
38 #include <QtCore>
39 #include <QtWidgets>
40 
41 #include <memory>
42 
43 /*******************************************************************************
44  * Namespace / Forward Declarations
45  ******************************************************************************/
46 namespace librepcb {
47 
48 class GridProperties;
49 class GraphicsView;
50 class GraphicsScene;
51 class GraphicsLayer;
52 class BoardDesignRules;
53 
54 namespace project {
55 
56 class NetSignal;
57 class Project;
58 class BI_Device;
59 class BI_Base;
60 class BI_FootprintPad;
61 class BI_Via;
62 class BI_NetSegment;
63 class BI_NetPoint;
64 class BI_NetLine;
65 class BI_Polygon;
66 class BI_StrokeText;
67 class BI_Hole;
68 class BI_Plane;
69 class BI_AirWire;
70 class BoardLayerStack;
71 class BoardFabricationOutputSettings;
72 class BoardUserSettings;
73 class BoardSelectionQuery;
74 
75 /*******************************************************************************
76  * Class Board
77  ******************************************************************************/
78 
83 class Board final : public QObject,
84  public AttributeProvider,
85  public IF_ErcMsgProvider,
86  public SerializableObject {
87  Q_OBJECT
89 
90 public:
91  // Types
92 
103  enum ItemZValue {
120  };
121 
122  // Constructors / Destructor
123  Board() = delete;
124  Board(const Board& other) = delete;
125  Board(const Board& other, std::unique_ptr<TransactionalDirectory> directory,
126  const ElementName& name);
127  Board(Project& project, std::unique_ptr<TransactionalDirectory> directory)
128  : Board(project, std::move(directory), false, QString()) {}
129  ~Board() noexcept;
130 
131  // Getters: General
132  Project& getProject() const noexcept { return mProject; }
133  FilePath getFilePath() const noexcept;
134  const GridProperties& getGridProperties() const noexcept {
135  return *mGridProperties;
136  }
137  GraphicsScene& getGraphicsScene() const noexcept { return *mGraphicsScene; }
138  BoardLayerStack& getLayerStack() noexcept { return *mLayerStack; }
139  const BoardLayerStack& getLayerStack() const noexcept { return *mLayerStack; }
141  const BoardDesignRules& getDesignRules() const noexcept {
142  return *mDesignRules;
143  }
146  }
148  noexcept {
150  }
151  bool isEmpty() const noexcept;
152  QList<BI_Base*> getItemsAtScenePos(const Point& pos) const noexcept;
153  QList<BI_Via*> getViasAtScenePos(const Point& pos,
154  const NetSignal* netsignal = nullptr) const
155  noexcept;
156  QList<BI_NetPoint*> getNetPointsAtScenePos(
157  const Point& pos, const GraphicsLayer* layer = nullptr,
158  const NetSignal* netsignal = nullptr) const noexcept;
159  QList<BI_NetLine*> getNetLinesAtScenePos(
160  const Point& pos, const GraphicsLayer* layer = nullptr,
161  const NetSignal* netsignal = nullptr) const noexcept;
162  QList<BI_FootprintPad*> getPadsAtScenePos(
163  const Point& pos, const GraphicsLayer* layer = nullptr,
164  const NetSignal* netsignal = nullptr) const noexcept;
165 
167  const Point& pos, UnsignedLength& maxDistance,
168  const GraphicsLayer* layer = nullptr,
169  const NetSignal* netsignal = nullptr) const;
170  BI_Via* getViaNextToScenePos(const Point& pos, UnsignedLength& maxDistance,
171  const NetSignal* netsignal = nullptr) const;
173  const Point& pos, UnsignedLength& maxDistance,
174  const GraphicsLayer* layer = nullptr,
175  const NetSignal* netsignal = nullptr) const;
176  QList<BI_Base*> getAllItems() const noexcept;
177 
178  // Setters: General
179  void setGridProperties(const GridProperties& grid) noexcept;
180 
181  // Getters: Attributes
182  const Uuid& getUuid() const noexcept { return mUuid; }
183  const ElementName& getName() const noexcept { return mName; }
184  const QIcon& getIcon() const noexcept { return mIcon; }
185  const QString& getDefaultFontName() const noexcept {
186  return mDefaultFontFileName;
187  }
188 
189  // DeviceInstance Methods
190  const QMap<Uuid, BI_Device*>& getDeviceInstances() const noexcept {
191  return mDeviceInstances;
192  }
193  BI_Device* getDeviceInstanceByComponentUuid(const Uuid& uuid) const noexcept;
194  void addDeviceInstance(BI_Device& instance);
195  void removeDeviceInstance(BI_Device& instance);
196 
197  // NetSegment Methods
198  const QList<BI_NetSegment*>& getNetSegments() const noexcept {
199  return mNetSegments;
200  }
201  BI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
202  void addNetSegment(BI_NetSegment& netsegment);
203  void removeNetSegment(BI_NetSegment& netsegment);
204 
205  // Plane Methods
206  const QList<BI_Plane*>& getPlanes() const noexcept { return mPlanes; }
207  void addPlane(BI_Plane& plane);
208  void removePlane(BI_Plane& plane);
209  void rebuildAllPlanes() noexcept;
210 
211  // Polygon Methods
212  const QList<BI_Polygon*>& getPolygons() const noexcept { return mPolygons; }
213  void addPolygon(BI_Polygon& polygon);
214  void removePolygon(BI_Polygon& polygon);
215 
216  // StrokeText Methods
217  const QList<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 QList<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  void addToProject();
238  void removeFromProject();
239  void save();
255  void print(QPrinter& printer);
256  void renderToQPainter(QPainter& painter, int dpi) const;
257  void showInView(GraphicsView& view) noexcept;
258  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
259  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
260  void selectAll() noexcept;
261  void setSelectionRect(const Point& p1, const Point& p2,
262  bool updateItems) noexcept;
263  void clearSelection() const noexcept;
264  std::unique_ptr<BoardSelectionQuery> createSelectionQuery() const noexcept;
265 
266  // Inherited from AttributeProvider
268  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
270  QVector<const AttributeProvider*> getAttributeProviderParents() const
271  noexcept override;
272 
273  // Operator Overloadings
274  Board& operator=(const Board& rhs) = delete;
275  bool operator==(const Board& rhs) noexcept { return (this == &rhs); }
276  bool operator!=(const Board& rhs) noexcept { return (this != &rhs); }
277 
278  // Static Methods
279  static Board* create(Project& project,
280  std::unique_ptr<TransactionalDirectory> directory,
281  const ElementName& name);
282 
283 signals:
284 
286  void attributesChanged() override;
287 
288  void deviceAdded(BI_Device& comp);
289  void deviceRemoved(BI_Device& comp);
290 
291 private:
292  Board(Project& project, std::unique_ptr<TransactionalDirectory> directory,
293  bool create, const QString& newName);
294  void updateIcon() noexcept;
295  void updateErcMessages() noexcept;
296 
298  void serialize(SExpression& root) const override;
299 
300  // General
302  std::unique_ptr<TransactionalDirectory> mDirectory;
304 
305  QScopedPointer<GraphicsScene> mGraphicsScene;
306  QScopedPointer<BoardLayerStack> mLayerStack;
307  QScopedPointer<GridProperties> mGridProperties;
308  QScopedPointer<BoardDesignRules> mDesignRules;
309  QScopedPointer<BoardFabricationOutputSettings> mFabricationOutputSettings;
310  QScopedPointer<BoardUserSettings> mUserSettings;
311  QRectF mViewRect;
313 
314  // Attributes
317  QIcon mIcon;
319 
320  // items
321  QMap<Uuid, BI_Device*> mDeviceInstances;
322  QList<BI_NetSegment*> mNetSegments;
323  QList<BI_Plane*> mPlanes;
324  QList<BI_Polygon*> mPolygons;
325  QList<BI_StrokeText*> mStrokeTexts;
326  QList<BI_Hole*> mHoles;
327  QMultiHash<NetSignal*, BI_AirWire*> mAirWires;
328 
329  // ERC messages
331 };
332 
333 /*******************************************************************************
334  * End of File
335  ******************************************************************************/
336 
337 } // namespace project
338 } // namespace librepcb
339 
340 #endif // LIBREPCB_PROJECT_BOARD_H
void deviceAdded(BI_Device &comp)
QScopedPointer< BoardDesignRules > mDesignRules
Definition: board.h:308
const QString & getDefaultFontName() const noexcept
Definition: board.h:185
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
const QList< BI_Polygon * > & getPolygons() const noexcept
Definition: board.h:212
#define DECLARE_ERC_MSG_CLASS_NAME(msgOwnerClassName)
Definition: if_ercmsgprovider.h:44
QRectF mViewRect
Definition: board.h:311
QString getBuiltInAttributeValue(const QString &key) const noexcept override
Get the value of a built-in attribute (if available)
Definition: board.cpp:1010
ItemZValue
Z Values of all items in a board scene (to define the stacking order)
Definition: board.h:103
The BI_NetPoint class.
Definition: bi_netpoint.h:49
QList< BI_NetLine * > getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer=nullptr, const NetSignal *netsignal=nullptr) const noexcept
Definition: board.cpp:514
void renderToQPainter(QPainter &painter, int dpi) const
Definition: board.cpp:911
void scheduleAirWiresRebuild(NetSignal *netsignal) noexcept
Definition: board.h:230
const QRectF & restoreViewSceneRect() const noexcept
Definition: board.h:259
std::unique_ptr< BoardSelectionQuery > createSelectionQuery() const noexcept
Definition: board.cpp:999
The BI_StrokeText class.
Definition: bi_stroketext.h:56
The BoardFabricationOutputSettings class.
Definition: boardfabricationoutputsettings.h:43
BoardFabricationOutputSettings & getFabricationOutputSettings() noexcept
Definition: board.h:144
GraphicsScene & getGraphicsScene() const noexcept
Definition: board.h:137
Project & getProject() const noexcept
Definition: board.h:132
void attributesChanged() override
This signal is emited when the value of attributes has changed.
Board & operator=(const Board &rhs)=delete
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: board.cpp:1031
BI_Via * getViaNextToScenePos(const Point &pos, UnsignedLength &maxDistance, const NetSignal *netsignal=nullptr) const
Definition: board.cpp:557
Definition: airwiresbuilder.cpp:32
QList< BI_StrokeText * > mStrokeTexts
Definition: board.h:325
QList< BI_FootprintPad * > getPadsAtScenePos(const Point &pos, const GraphicsLayer *layer=nullptr, const NetSignal *netsignal=nullptr) const noexcept
Definition: board.cpp:526
const BoardLayerStack & getLayerStack() const noexcept
Definition: board.h:139
The BoardDesignRules class.
Definition: boarddesignrules.h:45
void rebuildAllPlanes() noexcept
Definition: board.cpp:722
The GraphicsView class.
Definition: graphicsview.h:47
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:59
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition: board.h:312
The Project class represents a whole (opened) project with all its content.
Definition: project.h:80
void deviceRemoved(BI_Device &comp)
The GridProperties class.
Definition: gridproperties.h:43
QScopedPointer< BoardUserSettings > mUserSettings
Definition: board.h:310
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: board.h:258
QList< BI_Base * > getAllItems() const noexcept
Definition: board.cpp:597
void print(QPrinter &printer)
Print board to a QPrinter (printer or file)
Definition: board.cpp:892
QScopedPointer< BoardLayerStack > mLayerStack
Definition: board.h:306
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: board.h:305
void addNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:675
const QList< BI_NetSegment * > & getNetSegments() const noexcept
Definition: board.h:198
QList< BI_AirWire * > getAirWires() const noexcept
Definition: board.h:229
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:628
const QIcon & getIcon() const noexcept
Definition: board.h:184
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
QList< BI_Polygon * > mPolygons
Definition: board.h:324
void clearSelection() const noexcept
Definition: board.cpp:989
BoardDesignRules & getDesignRules() noexcept
Definition: board.h:140
void removeStrokeText(BI_StrokeText &text)
Definition: board.cpp:765
Uuid mUuid
Definition: board.h:315
The BI_Plane class.
Definition: bi_plane.h:53
QList< BI_Via * > getViasAtScenePos(const Point &pos, const NetSignal *netsignal=nullptr) const noexcept
Definition: board.cpp:490
QList< BI_NetSegment * > mNetSegments
Definition: board.h:322
static Board * create(Project &project, std::unique_ptr< TransactionalDirectory > directory, const ElementName &name)
Definition: board.cpp:1094
The BI_NetSegment class.
Definition: bi_netsegment.h:57
bool operator!=(const Board &rhs) noexcept
Definition: board.h:276
void removePolygon(BI_Polygon &polygon)
Definition: board.cpp:744
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void addToProject()
Definition: board.cpp:843
const QList< BI_Plane * > & getPlanes() const noexcept
Definition: board.h:206
void addHole(BI_Hole &hole)
Definition: board.cpp:777
FilePath getFilePath() const noexcept
Definition: board.cpp:401
ElementName mName
Definition: board.h:316
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: board.cpp:942
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
The BI_Polygon class.
Definition: bi_polygon.h:56
void updateErcMessages() noexcept
Definition: board.cpp:1056
The BI_Hole class.
Definition: bi_hole.h:52
void removeDeviceInstance(BI_Device &instance)
Definition: board.cpp:652
void showInView(GraphicsView &view) noexcept
Definition: board.cpp:921
bool isEmpty() const noexcept
Definition: board.cpp:405
const BoardDesignRules & getDesignRules() const noexcept
Definition: board.h:141
void setGridProperties(const GridProperties &grid) noexcept
Definition: board.cpp:620
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: board.h:302
QList< BI_Hole * > mHoles
Definition: board.h:326
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
BI_NetPoint * getNetPointNextToScenePos(const Point &pos, UnsignedLength &maxDistance, const GraphicsLayer *layer=nullptr, const NetSignal *netsignal=nullptr) const
Definition: board.cpp:543
QString mDefaultFontFileName
Definition: board.h:318
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition: board.h:147
bool operator==(const Board &rhs) noexcept
Definition: board.h:275
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:116
The BoardLayerStack class provides and manages all available layers of a board.
Definition: boardlayerstack.h:48
QList< BI_Base * > getItemsAtScenePos(const Point &pos) const noexcept
Definition: board.cpp:411
void removeFromProject()
Definition: board.cpp:860
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition: board.h:190
void removeHole(BI_Hole &hole)
Definition: board.cpp:786
QScopedPointer< GridProperties > mGridProperties
Definition: board.h:307
Z value for librepcb::project::BI_Via items.
Definition: board.h:117
void updateIcon() noexcept
Definition: board.cpp:1027
The BI_Device class.
Definition: bi_device.h:62
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:118
void addDeviceInstance(BI_Device &instance)
Definition: board.cpp:633
Board(Project &project, std::unique_ptr< TransactionalDirectory > directory)
Definition: board.h:127
void addStrokeText(BI_StrokeText &text)
Definition: board.cpp:756
QList< BI_Plane * > mPlanes
Definition: board.h:323
QMap< Uuid, BI_Device * > mDeviceInstances
Definition: board.h:321
QIcon mIcon
Definition: board.h:317
const QList< BI_Hole * > & getHoles() const noexcept
Definition: board.h:224
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:105
const GridProperties & getGridProperties() const noexcept
Definition: board.h:134
void removePlane(BI_Plane &plane)
Definition: board.cpp:714
this is the default value (behind all other items)
Definition: board.h:104
void addPlane(BI_Plane &plane)
Definition: board.cpp:705
The NetSignal class.
Definition: netsignal.h:56
QList< BI_NetPoint * > getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer=nullptr, const NetSignal *netsignal=nullptr) const noexcept
Definition: board.cpp:502
BI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:668
QHash< Uuid, ErcMsg * > mErcMsgListUnplacedComponentInstances
Definition: board.h:330
void addPolygon(BI_Polygon &polygon)
Definition: board.cpp:735
const ElementName & getName() const noexcept
Definition: board.h:183
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:83
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The GraphicsScene class.
Definition: graphicsscene.h:43
Project & mProject
A reference to the Project object (from the ctor)
Definition: board.h:301
const Uuid & getUuid() const noexcept
Definition: board.h:182
void triggerAirWiresRebuild() noexcept
Definition: board.cpp:798
void forceAirWiresRebuild() noexcept
Definition: board.cpp:832
Z value for librepcb::project::BI_AirWire items.
Definition: board.h:119
QVector< const AttributeProvider * > getAttributeProviderParents() const noexcept override
Get all parent attribute providers (fallback if attribute not found)
Definition: board.cpp:1018
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition: board.h:327
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition: board.h:309
const QList< BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: board.h:217
void removeNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:692
void selectAll() noexcept
Definition: board.cpp:925
The SExpression class.
Definition: sexpression.h:57
bool mIsAddedToProject
Definition: board.h:303
void save()
Definition: board.cpp:876
BI_FootprintPad * getPadNextToScenePos(const Point &pos, UnsignedLength &maxDistance, const GraphicsLayer *layer=nullptr, const NetSignal *netsignal=nullptr) const
Definition: board.cpp:570
~Board() noexcept
Definition: board.cpp:367
The BI_Via class.
Definition: bi_via.h:49
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:673
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
BoardLayerStack & getLayerStack() noexcept
Definition: board.h:138