LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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) const noexcept;
155  QList<BI_NetPoint*> getNetPointsAtScenePos(const Point& pos,
156  const GraphicsLayer* layer,
157  const NetSignal* netsignal) const
158  noexcept;
159  QList<BI_NetLine*> getNetLinesAtScenePos(const Point& pos,
160  const GraphicsLayer* layer,
161  const NetSignal* netsignal) const
162  noexcept;
163  QList<BI_FootprintPad*> getPadsAtScenePos(const Point& pos,
164  const GraphicsLayer* layer,
165  const NetSignal* netsignal) const
166  noexcept;
167  QList<BI_Base*> getAllItems() const noexcept;
168 
169  // Setters: General
170  void setGridProperties(const GridProperties& grid) noexcept;
171 
172  // Getters: Attributes
173  const Uuid& getUuid() const noexcept { return mUuid; }
174  const ElementName& getName() const noexcept { return mName; }
175  const QIcon& getIcon() const noexcept { return mIcon; }
176  const QString& getDefaultFontName() const noexcept {
177  return mDefaultFontFileName;
178  }
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 QList<BI_NetSegment*>& getNetSegments() const noexcept {
190  return mNetSegments;
191  }
192  BI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
193  void addNetSegment(BI_NetSegment& netsegment);
194  void removeNetSegment(BI_NetSegment& netsegment);
195 
196  // Plane Methods
197  const QList<BI_Plane*>& getPlanes() const noexcept { return mPlanes; }
198  void addPlane(BI_Plane& plane);
199  void removePlane(BI_Plane& plane);
200  void rebuildAllPlanes() noexcept;
201 
202  // Polygon Methods
203  const QList<BI_Polygon*>& getPolygons() const noexcept { return mPolygons; }
204  void addPolygon(BI_Polygon& polygon);
205  void removePolygon(BI_Polygon& polygon);
206 
207  // StrokeText Methods
208  const QList<BI_StrokeText*>& getStrokeTexts() const noexcept {
209  return mStrokeTexts;
210  }
211  void addStrokeText(BI_StrokeText& text);
212  void removeStrokeText(BI_StrokeText& text);
213 
214  // Hole Methods
215  const QList<BI_Hole*>& getHoles() const noexcept { return mHoles; }
216  void addHole(BI_Hole& hole);
217  void removeHole(BI_Hole& hole);
218 
219  // AirWire Methods
220  QList<BI_AirWire*> getAirWires() const noexcept { return mAirWires.values(); }
221  void scheduleAirWiresRebuild(NetSignal* netsignal) noexcept {
222  mScheduledNetSignalsForAirWireRebuild.insert(netsignal);
223  }
224  void triggerAirWiresRebuild() noexcept;
225  void forceAirWiresRebuild() noexcept;
226 
227  // General Methods
228  void addToProject();
229  void removeFromProject();
230  void save();
246  void print(QPrinter& printer);
247  void renderToQPainter(QPainter& painter, int dpi) const;
248  void showInView(GraphicsView& view) noexcept;
249  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
250  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
251  void setSelectionRect(const Point& p1, const Point& p2,
252  bool updateItems) noexcept;
253  void clearSelection() const noexcept;
254  std::unique_ptr<BoardSelectionQuery> createSelectionQuery() const noexcept;
255 
256  // Inherited from AttributeProvider
258  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
260  QVector<const AttributeProvider*> getAttributeProviderParents() const
261  noexcept override;
262 
263  // Operator Overloadings
264  Board& operator=(const Board& rhs) = delete;
265  bool operator==(const Board& rhs) noexcept { return (this == &rhs); }
266  bool operator!=(const Board& rhs) noexcept { return (this != &rhs); }
267 
268  // Static Methods
269  static Board* create(Project& project,
270  std::unique_ptr<TransactionalDirectory> directory,
271  const ElementName& name);
272 
273 signals:
274 
276  void attributesChanged() override;
277 
278  void deviceAdded(BI_Device& comp);
279  void deviceRemoved(BI_Device& comp);
280 
281 private:
282  Board(Project& project, std::unique_ptr<TransactionalDirectory> directory,
283  bool create, const QString& newName);
284  void updateIcon() noexcept;
285  void updateErcMessages() noexcept;
286 
288  void serialize(SExpression& root) const override;
289 
290  // General
294 
295  QScopedPointer<GraphicsScene> mGraphicsScene;
296  QScopedPointer<BoardLayerStack> mLayerStack;
301  QRectF mViewRect;
303 
304  // Attributes
307  QIcon mIcon;
309 
310  // items
313  QList<BI_Plane*> mPlanes;
316  QList<BI_Hole*> mHoles;
318 
319  // ERC messages
321 };
322 
323 /*******************************************************************************
324  * End of File
325  ******************************************************************************/
326 
327 } // namespace project
328 } // namespace librepcb
329 
330 #endif // LIBREPCB_PROJECT_BOARD_H
void deviceAdded(BI_Device &comp)
QScopedPointer< BoardDesignRules > mDesignRules
Definition: board.h:298
const QString & getDefaultFontName() const noexcept
Definition: board.h:176
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:203
#define DECLARE_ERC_MSG_CLASS_NAME(msgOwnerClassName)
Definition: if_ercmsgprovider.h:44
The ErcMsg class represents a message in the ERC (Electrical Rule Check) list.
Definition: ercmsg.h:46
QRectF mViewRect
Definition: board.h:301
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:48
void scheduleAirWiresRebuild(NetSignal *netsignal) noexcept
Definition: board.h:221
const QRectF & restoreViewSceneRect() const noexcept
Definition: board.h:250
std::unique_ptr< BoardSelectionQuery > createSelectionQuery() const noexcept
Definition: board.cpp:928
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.
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: board.cpp:960
QList< BI_StrokeText * > mStrokeTexts
Definition: board.h:315
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: board.cpp:939
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: board.cpp:947
QList< BI_NetLine * > getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:513
QList< BI_NetPoint * > getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:501
const BoardLayerStack & getLayerStack() const noexcept
Definition: board.h:139
The BoardSelectionQuery class.
Definition: boardselectionquery.h:56
The BoardDesignRules class.
Definition: boarddesignrules.h:45
void rebuildAllPlanes() noexcept
Definition: board.cpp:668
The GraphicsView class.
Definition: graphicsview.h:47
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:59
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition: board.h:302
The Project class represents a whole (opened) project with all its content.
Definition: project.h:79
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:52
void deviceRemoved(BI_Device &comp)
The GridProperties class.
Definition: gridproperties.h:43
QScopedPointer< BoardUserSettings > mUserSettings
Definition: board.h:300
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: board.h:249
QList< BI_Base * > getAllItems() const noexcept
Definition: board.cpp:542
void print(QPrinter &printer)
Print board to a QPrinter (printer or file)
Definition: board.cpp:838
QScopedPointer< BoardLayerStack > mLayerStack
Definition: board.h:296
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: board.h:295
void addNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:621
const QList< BI_NetSegment * > & getNetSegments() const noexcept
Definition: board.h:189
QList< BI_AirWire * > getAirWires() const noexcept
Definition: board.h:220
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:573
const QIcon & getIcon() const noexcept
Definition: board.h:175
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:314
void clearSelection() const noexcept
Definition: board.cpp:918
BoardDesignRules & getDesignRules() noexcept
Definition: board.h:140
void removeStrokeText(BI_StrokeText &text)
Definition: board.cpp:711
Uuid mUuid
Definition: board.h:305
The BI_Plane class.
Definition: bi_plane.h:53
QList< BI_NetSegment * > mNetSegments
Definition: board.h:312
static Board * create(Project &project, std::unique_ptr< TransactionalDirectory > directory, const ElementName &name)
Definition: board.cpp:1023
The BI_NetSegment class.
Definition: bi_netsegment.h:57
bool operator!=(const Board &rhs) noexcept
Definition: board.h:266
void removePolygon(BI_Polygon &polygon)
Definition: board.cpp:690
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:789
const QList< BI_Plane * > & getPlanes() const noexcept
Definition: board.h:197
void addHole(BI_Hole &hole)
Definition: board.cpp:723
FilePath getFilePath() const noexcept
Definition: board.cpp:400
ElementName mName
Definition: board.h:306
The BoardUserSettings class.
Definition: boardusersettings.h:48
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: board.cpp:871
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
The BI_Polygon class.
Definition: bi_polygon.h:56
void updateErcMessages() noexcept
Definition: board.cpp:985
The BI_Hole class.
Definition: bi_hole.h:52
void removeDeviceInstance(BI_Device &instance)
Definition: board.cpp:598
QList< BI_Via * > getViasAtScenePos(const Point &pos, const NetSignal *netsignal) const noexcept
Definition: board.cpp:489
void showInView(GraphicsView &view) noexcept
Definition: board.cpp:867
bool isEmpty() const noexcept
Definition: board.cpp:404
const BoardDesignRules & getDesignRules() const noexcept
Definition: board.h:141
void setGridProperties(const GridProperties &grid) noexcept
Definition: board.cpp:565
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: board.h:292
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
QList< BI_Hole * > mHoles
Definition: board.h:316
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QString mDefaultFontFileName
Definition: board.h:308
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition: board.h:147
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:410
void removeFromProject()
Definition: board.cpp:806
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition: board.h:181
void removeHole(BI_Hole &hole)
Definition: board.cpp:732
QScopedPointer< GridProperties > mGridProperties
Definition: board.h:297
Z value for librepcb::project::BI_Via items.
Definition: board.h:117
void updateIcon() noexcept
Definition: board.cpp:956
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:578
void renderToQPainter(QPainter &painter, int dpi) const
Definition: board.cpp:857
Board(Project &project, std::unique_ptr< TransactionalDirectory > directory)
Definition: board.h:127
void addStrokeText(BI_StrokeText &text)
Definition: board.cpp:702
QList< BI_Plane * > mPlanes
Definition: board.h:313
QMap< Uuid, BI_Device * > mDeviceInstances
Definition: board.h:311
QIcon mIcon
Definition: board.h:307
const QList< BI_Hole * > & getHoles() const noexcept
Definition: board.h:215
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:660
this is the default value (behind all other items)
Definition: board.h:104
void addPlane(BI_Plane &plane)
Definition: board.cpp:651
The NetSignal class.
Definition: netsignal.h:56
BI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:614
QHash< Uuid, ErcMsg * > mErcMsgListUnplacedComponentInstances
Definition: board.h:320
void addPolygon(BI_Polygon &polygon)
Definition: board.cpp:681
const ElementName & getName() const noexcept
Definition: board.h:174
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:291
const Uuid & getUuid() const noexcept
Definition: board.h:173
void triggerAirWiresRebuild() noexcept
Definition: board.cpp:744
void forceAirWiresRebuild() noexcept
Definition: board.cpp:778
Z value for librepcb::project::BI_AirWire items.
Definition: board.h:119
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition: board.h:317
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition: board.h:299
const QList< BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: board.h:208
void removeNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:638
The BI_AirWire class.
Definition: bi_airwire.h:44
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:57
QList< BI_FootprintPad * > getPadsAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:525
bool mIsAddedToProject
Definition: board.h:293
void save()
Definition: board.cpp:822
~Board() noexcept
Definition: board.cpp:366
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< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
BoardLayerStack & getLayerStack() noexcept
Definition: board.h:138