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 <QtCore>
38 #include <QtWidgets>
39 
40 #include <memory>
41 
42 /*******************************************************************************
43  * Namespace / Forward Declarations
44  ******************************************************************************/
45 namespace librepcb {
46 
47 class GridProperties;
48 class GraphicsView;
49 class GraphicsScene;
50 class GraphicsLayer;
51 class BoardDesignRules;
52 
53 namespace project {
54 
55 class NetSignal;
56 class Project;
57 class BI_Device;
58 class BI_Base;
59 class BI_FootprintPad;
60 class BI_Via;
61 class BI_NetSegment;
62 class BI_NetPoint;
63 class BI_NetLine;
64 class BI_Polygon;
65 class BI_StrokeText;
66 class BI_Hole;
67 class BI_Plane;
68 class BI_AirWire;
69 class BoardLayerStack;
70 class BoardFabricationOutputSettings;
71 class BoardUserSettings;
72 class BoardSelectionQuery;
73 
74 /*******************************************************************************
75  * Class Board
76  ******************************************************************************/
77 
82 class Board final : public QObject,
83  public AttributeProvider,
84  public IF_ErcMsgProvider,
85  public SerializableObject {
86  Q_OBJECT
88 
89 public:
90  // Types
91 
102  enum ItemZValue {
119  };
120 
121  // Constructors / Destructor
122  Board() = delete;
123  Board(const Board& other) = delete;
124  Board(const Board& other, std::unique_ptr<TransactionalDirectory> directory,
125  const ElementName& name);
126  Board(Project& project, std::unique_ptr<TransactionalDirectory> directory)
127  : Board(project, std::move(directory), false, QString()) {}
128  ~Board() noexcept;
129 
130  // Getters: General
131  Project& getProject() const noexcept { return mProject; }
132  FilePath getFilePath() const noexcept;
133  const GridProperties& getGridProperties() const noexcept {
134  return *mGridProperties;
135  }
136  GraphicsScene& getGraphicsScene() const noexcept { return *mGraphicsScene; }
137  BoardLayerStack& getLayerStack() noexcept { return *mLayerStack; }
138  const BoardLayerStack& getLayerStack() const noexcept { return *mLayerStack; }
140  const BoardDesignRules& getDesignRules() const noexcept {
141  return *mDesignRules;
142  }
145  }
147  noexcept {
149  }
150  bool isEmpty() const noexcept;
151  QList<BI_Base*> getItemsAtScenePos(const Point& pos) const noexcept;
152  QList<BI_Via*> getViasAtScenePos(const Point& pos,
153  const NetSignal* netsignal) const noexcept;
154  QList<BI_NetPoint*> getNetPointsAtScenePos(const Point& pos,
155  const GraphicsLayer* layer,
156  const NetSignal* netsignal) const
157  noexcept;
158  QList<BI_NetLine*> getNetLinesAtScenePos(const Point& pos,
159  const GraphicsLayer* layer,
160  const NetSignal* netsignal) const
161  noexcept;
162  QList<BI_FootprintPad*> getPadsAtScenePos(const Point& pos,
163  const GraphicsLayer* layer,
164  const NetSignal* netsignal) const
165  noexcept;
166  QList<BI_Base*> getAllItems() const noexcept;
167 
168  // Setters: General
169  void setGridProperties(const GridProperties& grid) noexcept;
170 
171  // Getters: Attributes
172  const Uuid& getUuid() const noexcept { return mUuid; }
173  const ElementName& getName() const noexcept { return mName; }
174  const QIcon& getIcon() const noexcept { return mIcon; }
175  const QString& getDefaultFontName() const noexcept {
176  return mDefaultFontFileName;
177  }
178 
179  // DeviceInstance Methods
180  const QMap<Uuid, BI_Device*>& getDeviceInstances() const noexcept {
181  return mDeviceInstances;
182  }
183  BI_Device* getDeviceInstanceByComponentUuid(const Uuid& uuid) const noexcept;
184  void addDeviceInstance(BI_Device& instance);
185  void removeDeviceInstance(BI_Device& instance);
186 
187  // NetSegment Methods
188  const QList<BI_NetSegment*>& getNetSegments() const noexcept {
189  return mNetSegments;
190  }
191  BI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
192  void addNetSegment(BI_NetSegment& netsegment);
193  void removeNetSegment(BI_NetSegment& netsegment);
194 
195  // Plane Methods
196  const QList<BI_Plane*>& getPlanes() const noexcept { return mPlanes; }
197  void addPlane(BI_Plane& plane);
198  void removePlane(BI_Plane& plane);
199  void rebuildAllPlanes() noexcept;
200 
201  // Polygon Methods
202  const QList<BI_Polygon*>& getPolygons() const noexcept { return mPolygons; }
203  void addPolygon(BI_Polygon& polygon);
204  void removePolygon(BI_Polygon& polygon);
205 
206  // StrokeText Methods
207  const QList<BI_StrokeText*>& getStrokeTexts() const noexcept {
208  return mStrokeTexts;
209  }
210  void addStrokeText(BI_StrokeText& text);
211  void removeStrokeText(BI_StrokeText& text);
212 
213  // Hole Methods
214  const QList<BI_Hole*>& getHoles() const noexcept { return mHoles; }
215  void addHole(BI_Hole& hole);
216  void removeHole(BI_Hole& hole);
217 
218  // AirWire Methods
219  void scheduleAirWiresRebuild(NetSignal* netsignal) noexcept {
220  mScheduledNetSignalsForAirWireRebuild.insert(netsignal);
221  }
222  void triggerAirWiresRebuild() noexcept;
223  void forceAirWiresRebuild() noexcept;
224 
225  // General Methods
226  void addToProject();
227  void removeFromProject();
228  void save();
229  void showInView(GraphicsView& view) noexcept;
230  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
231  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
232  void setSelectionRect(const Point& p1, const Point& p2,
233  bool updateItems) noexcept;
234  void clearSelection() const noexcept;
235  std::unique_ptr<BoardSelectionQuery> createSelectionQuery() const noexcept;
236 
237  // Inherited from AttributeProvider
239  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
241  QVector<const AttributeProvider*> getAttributeProviderParents() const
242  noexcept override;
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  // Static Methods
250  static Board* create(Project& project,
251  std::unique_ptr<TransactionalDirectory> directory,
252  const ElementName& name);
253 
254 signals:
255 
257  void attributesChanged() override;
258 
259  void deviceAdded(BI_Device& comp);
260  void deviceRemoved(BI_Device& comp);
261 
262 private:
263  Board(Project& project, std::unique_ptr<TransactionalDirectory> directory,
264  bool create, const QString& newName);
265  void updateIcon() noexcept;
266  void updateErcMessages() noexcept;
267 
269  void serialize(SExpression& root) const override;
270 
271  // General
275 
276  QScopedPointer<GraphicsScene> mGraphicsScene;
277  QScopedPointer<BoardLayerStack> mLayerStack;
282  QRectF mViewRect;
284 
285  // Attributes
288  QIcon mIcon;
290 
291  // items
294  QList<BI_Plane*> mPlanes;
297  QList<BI_Hole*> mHoles;
299 
300  // ERC messages
302 };
303 
304 /*******************************************************************************
305  * End of File
306  ******************************************************************************/
307 
308 } // namespace project
309 } // namespace librepcb
310 
311 #endif // LIBREPCB_PROJECT_BOARD_H
void deviceAdded(BI_Device &comp)
QScopedPointer< BoardDesignRules > mDesignRules
Definition: board.h:279
const QString & getDefaultFontName() const noexcept
Definition: board.h:175
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
const QList< BI_Polygon * > & getPolygons() const noexcept
Definition: board.h:202
#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:282
ItemZValue
Z Values of all items in a board scene (to define the stacking order)
Definition: board.h:102
The BI_NetPoint class.
Definition: bi_netpoint.h:48
void scheduleAirWiresRebuild(NetSignal *netsignal) noexcept
Definition: board.h:219
const QRectF & restoreViewSceneRect() const noexcept
Definition: board.h:231
std::unique_ptr< BoardSelectionQuery > createSelectionQuery() const noexcept
Definition: board.cpp:897
The BI_StrokeText class.
Definition: bi_stroketext.h:56
The BoardFabricationOutputSettings class.
Definition: boardfabricationoutputsettings.h:43
BoardFabricationOutputSettings & getFabricationOutputSettings() noexcept
Definition: board.h:143
GraphicsScene & getGraphicsScene() const noexcept
Definition: board.h:136
Project & getProject() const noexcept
Definition: board.h:131
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:937
QList< BI_StrokeText * > mStrokeTexts
Definition: board.h:296
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: board.cpp:908
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: board.cpp:916
QList< BI_NetLine * > getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:511
QList< BI_NetPoint * > getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:499
const BoardLayerStack & getLayerStack() const noexcept
Definition: board.h:138
The BoardSelectionQuery class.
Definition: boardselectionquery.h:56
The BoardDesignRules class.
Definition: boarddesignrules.h:48
void rebuildAllPlanes() noexcept
Definition: board.cpp:666
The GraphicsView class.
Definition: graphicsview.h:47
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:62
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition: board.h:283
The Project class represents a whole (opened) project with all its content.
Definition: project.h:82
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:281
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: board.h:230
QList< BI_Base * > getAllItems() const noexcept
Definition: board.cpp:540
QScopedPointer< BoardLayerStack > mLayerStack
Definition: board.h:277
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: board.h:276
void addNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:619
const QList< BI_NetSegment * > & getNetSegments() const noexcept
Definition: board.h:188
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:571
const QIcon & getIcon() const noexcept
Definition: board.h:174
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
QList< BI_Polygon * > mPolygons
Definition: board.h:295
void clearSelection() const noexcept
Definition: board.cpp:887
BoardDesignRules & getDesignRules() noexcept
Definition: board.h:139
void removeStrokeText(BI_StrokeText &text)
Definition: board.cpp:709
Uuid mUuid
Definition: board.h:286
The BI_Plane class.
Definition: bi_plane.h:56
QList< BI_NetSegment * > mNetSegments
Definition: board.h:293
static Board * create(Project &project, std::unique_ptr< TransactionalDirectory > directory, const ElementName &name)
Definition: board.cpp:1000
The BI_NetSegment class.
Definition: bi_netsegment.h:59
bool operator!=(const Board &rhs) noexcept
Definition: board.h:247
void removePolygon(BI_Polygon &polygon)
Definition: board.cpp:688
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void addToProject()
Definition: board.cpp:787
const QList< BI_Plane * > & getPlanes() const noexcept
Definition: board.h:196
void addHole(BI_Hole &hole)
Definition: board.cpp:721
FilePath getFilePath() const noexcept
Definition: board.cpp:398
ElementName mName
Definition: board.h:287
The BoardUserSettings class.
Definition: boardusersettings.h:48
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: board.cpp:840
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
The BI_Polygon class.
Definition: bi_polygon.h:59
void updateErcMessages() noexcept
Definition: board.cpp:962
The BI_Hole class.
Definition: bi_hole.h:52
void removeDeviceInstance(BI_Device &instance)
Definition: board.cpp:596
QList< BI_Via * > getViasAtScenePos(const Point &pos, const NetSignal *netsignal) const noexcept
Definition: board.cpp:487
void showInView(GraphicsView &view) noexcept
Definition: board.cpp:836
bool isEmpty() const noexcept
Definition: board.cpp:402
const BoardDesignRules & getDesignRules() const noexcept
Definition: board.h:140
void setGridProperties(const GridProperties &grid) noexcept
Definition: board.cpp:563
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: board.h:273
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
QList< BI_Hole * > mHoles
Definition: board.h:297
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
QString mDefaultFontFileName
Definition: board.h:289
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition: board.h:146
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:115
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:408
void removeFromProject()
Definition: board.cpp:804
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition: board.h:180
void removeHole(BI_Hole &hole)
Definition: board.cpp:730
QScopedPointer< GridProperties > mGridProperties
Definition: board.h:278
Z value for librepcb::project::BI_Via items.
Definition: board.h:116
void updateIcon() noexcept
Definition: board.cpp:925
The BI_Device class.
Definition: bi_device.h:62
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:117
void addDeviceInstance(BI_Device &instance)
Definition: board.cpp:576
Board(Project &project, std::unique_ptr< TransactionalDirectory > directory)
Definition: board.h:126
void addStrokeText(BI_StrokeText &text)
Definition: board.cpp:700
QList< BI_Plane * > mPlanes
Definition: board.h:294
QMap< Uuid, BI_Device * > mDeviceInstances
Definition: board.h:292
QIcon mIcon
Definition: board.h:288
const QList< BI_Hole * > & getHoles() const noexcept
Definition: board.h:214
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:104
const GridProperties & getGridProperties() const noexcept
Definition: board.h:133
void removePlane(BI_Plane &plane)
Definition: board.cpp:658
this is the default value (behind all other items)
Definition: board.h:103
void addPlane(BI_Plane &plane)
Definition: board.cpp:649
The NetSignal class.
Definition: netsignal.h:56
BI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:612
QHash< Uuid, ErcMsg * > mErcMsgListUnplacedComponentInstances
Definition: board.h:301
void addPolygon(BI_Polygon &polygon)
Definition: board.cpp:679
const ElementName & getName() const noexcept
Definition: board.h:173
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:82
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:272
const Uuid & getUuid() const noexcept
Definition: board.h:172
void triggerAirWiresRebuild() noexcept
Definition: board.cpp:742
void forceAirWiresRebuild() noexcept
Definition: board.cpp:776
Z value for librepcb::project::BI_AirWire items.
Definition: board.h:118
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition: board.h:298
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition: board.h:280
const QList< BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: board.h:207
void removeNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:636
The BI_AirWire class.
Definition: bi_airwire.h:44
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:60
QList< BI_FootprintPad * > getPadsAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:523
bool mIsAddedToProject
Definition: board.h:274
void save()
Definition: board.cpp:820
~Board() noexcept
Definition: board.cpp:364
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:62
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
BoardLayerStack & getLayerStack() noexcept
Definition: board.h:137