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 
34 #include <librepcb/common/uuid.h>
35 
36 #include <QtCore>
37 #include <QtWidgets>
38 
39 #include <memory>
40 
41 /*******************************************************************************
42  * Namespace / Forward Declarations
43  ******************************************************************************/
44 namespace librepcb {
45 
46 class GridProperties;
47 class GraphicsView;
48 class GraphicsScene;
49 class SmartSExprFile;
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, const FilePath& filepath, const ElementName& name);
125  Board(Project& project, const FilePath& filepath, bool restore, bool readOnly)
126  : Board(project, filepath, restore, readOnly, false, QString()) {}
127  ~Board() noexcept;
128 
129  // Getters: General
130  Project& getProject() const noexcept { return mProject; }
131  const FilePath& getFilePath() const noexcept { return mFilePath; }
132  const GridProperties& getGridProperties() const noexcept {
133  return *mGridProperties;
134  }
135  GraphicsScene& getGraphicsScene() const noexcept { return *mGraphicsScene; }
136  BoardLayerStack& getLayerStack() noexcept { return *mLayerStack; }
137  const BoardLayerStack& getLayerStack() const noexcept { return *mLayerStack; }
139  const BoardDesignRules& getDesignRules() const noexcept {
140  return *mDesignRules;
141  }
144  }
146  noexcept {
148  }
149  bool isEmpty() const noexcept;
150  QList<BI_Base*> getItemsAtScenePos(const Point& pos) const noexcept;
151  QList<BI_Via*> getViasAtScenePos(const Point& pos,
152  const NetSignal* netsignal) const noexcept;
153  QList<BI_NetPoint*> getNetPointsAtScenePos(const Point& pos,
154  const GraphicsLayer* layer,
155  const NetSignal* netsignal) const
156  noexcept;
157  QList<BI_NetLine*> getNetLinesAtScenePos(const Point& pos,
158  const GraphicsLayer* layer,
159  const NetSignal* netsignal) const
160  noexcept;
161  QList<BI_FootprintPad*> getPadsAtScenePos(const Point& pos,
162  const GraphicsLayer* layer,
163  const NetSignal* netsignal) const
164  noexcept;
165  QList<BI_Base*> getAllItems() const noexcept;
166 
167  // Setters: General
168  void setGridProperties(const GridProperties& grid) noexcept;
169 
170  // Getters: Attributes
171  const Uuid& getUuid() const noexcept { return mUuid; }
172  const ElementName& getName() const noexcept { return mName; }
173  const QIcon& getIcon() const noexcept { return mIcon; }
174  const QString& getDefaultFontName() const noexcept {
175  return mDefaultFontFileName;
176  }
177 
178  // DeviceInstance Methods
179  const QMap<Uuid, BI_Device*>& getDeviceInstances() const noexcept {
180  return mDeviceInstances;
181  }
182  BI_Device* getDeviceInstanceByComponentUuid(const Uuid& uuid) const noexcept;
183  void addDeviceInstance(BI_Device& instance);
184  void removeDeviceInstance(BI_Device& instance);
185 
186  // NetSegment Methods
187  const QList<BI_NetSegment*>& getNetSegments() const noexcept {
188  return mNetSegments;
189  }
190  BI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
191  void addNetSegment(BI_NetSegment& netsegment);
192  void removeNetSegment(BI_NetSegment& netsegment);
193 
194  // Plane Methods
195  const QList<BI_Plane*>& getPlanes() const noexcept { return mPlanes; }
196  void addPlane(BI_Plane& plane);
197  void removePlane(BI_Plane& plane);
198  void rebuildAllPlanes() noexcept;
199 
200  // Polygon Methods
201  const QList<BI_Polygon*>& getPolygons() const noexcept { return mPolygons; }
202  void addPolygon(BI_Polygon& polygon);
203  void removePolygon(BI_Polygon& polygon);
204 
205  // StrokeText Methods
206  const QList<BI_StrokeText*>& getStrokeTexts() const noexcept {
207  return mStrokeTexts;
208  }
209  void addStrokeText(BI_StrokeText& text);
210  void removeStrokeText(BI_StrokeText& text);
211 
212  // Hole Methods
213  const QList<BI_Hole*>& getHoles() const noexcept { return mHoles; }
214  void addHole(BI_Hole& hole);
215  void removeHole(BI_Hole& hole);
216 
217  // AirWire Methods
218  void scheduleAirWiresRebuild(NetSignal* netsignal) noexcept {
219  mScheduledNetSignalsForAirWireRebuild.insert(netsignal);
220  }
221  void triggerAirWiresRebuild() noexcept;
222  void forceAirWiresRebuild() noexcept;
223 
224  // General Methods
225  void addToProject();
226  void removeFromProject();
227  bool save(bool toOriginal, QStringList& errors) noexcept;
228  void showInView(GraphicsView& view) noexcept;
229  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
230  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
231  void setSelectionRect(const Point& p1, const Point& p2,
232  bool updateItems) noexcept;
233  void clearSelection() const noexcept;
234  std::unique_ptr<BoardSelectionQuery> createSelectionQuery() const noexcept;
235 
236  // Inherited from AttributeProvider
238  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
240  QVector<const AttributeProvider*> getAttributeProviderParents() const
241  noexcept override;
242 
243  // Operator Overloadings
244  Board& operator=(const Board& rhs) = delete;
245  bool operator==(const Board& rhs) noexcept { return (this == &rhs); }
246  bool operator!=(const Board& rhs) noexcept { return (this != &rhs); }
247 
248  // Static Methods
249  static Board* create(Project& project, const FilePath& filepath,
250  const ElementName& name);
251 
252 signals:
253 
255  void attributesChanged() override;
256 
257  void deviceAdded(BI_Device& comp);
258  void deviceRemoved(BI_Device& comp);
259 
260 private:
261  Board(Project& project, const FilePath& filepath, bool restore, bool readOnly,
262  bool create, const QString& newName);
263  void updateIcon() noexcept;
264  void updateErcMessages() noexcept;
265 
267  void serialize(SExpression& root) const override;
268 
269  // General
272  QScopedPointer<SmartSExprFile> mFile;
274 
275  QScopedPointer<GraphicsScene> mGraphicsScene;
276  QScopedPointer<BoardLayerStack> mLayerStack;
281  QRectF mViewRect;
283 
284  // Attributes
287  QIcon mIcon;
289 
290  // items
293  QList<BI_Plane*> mPlanes;
296  QList<BI_Hole*> mHoles;
298 
299  // ERC messages
301 };
302 
303 /*******************************************************************************
304  * End of File
305  ******************************************************************************/
306 
307 } // namespace project
308 } // namespace librepcb
309 
310 #endif // LIBREPCB_PROJECT_BOARD_H
void deviceAdded(BI_Device &comp)
QScopedPointer< BoardDesignRules > mDesignRules
Definition: board.h:278
const QString & getDefaultFontName() const noexcept
Definition: board.h:174
bool save(bool toOriginal, QStringList &errors) noexcept
Definition: board.cpp:840
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:201
#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:281
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:218
const QRectF & restoreViewSceneRect() const noexcept
Definition: board.h:230
std::unique_ptr< BoardSelectionQuery > createSelectionQuery() const noexcept
Definition: board.cpp:925
The BI_StrokeText class.
Definition: bi_stroketext.h:56
The BoardFabricationOutputSettings class.
Definition: boardfabricationoutputsettings.h:43
BoardFabricationOutputSettings & getFabricationOutputSettings() noexcept
Definition: board.h:142
GraphicsScene & getGraphicsScene() const noexcept
Definition: board.h:135
Project & getProject() const noexcept
Definition: board.h:130
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:965
QList< BI_StrokeText * > mStrokeTexts
Definition: board.h:295
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: board.cpp:936
static Board * create(Project &project, const FilePath &filepath, const ElementName &name)
Definition: board.cpp:1028
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: board.cpp:944
QList< BI_NetLine * > getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:531
const FilePath & getFilePath() const noexcept
Definition: board.h:131
QList< BI_NetPoint * > getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer, const NetSignal *netsignal) const noexcept
Definition: board.cpp:519
const BoardLayerStack & getLayerStack() const noexcept
Definition: board.h:137
The BoardSelectionQuery class.
Definition: boardselectionquery.h:56
The BoardDesignRules class.
Definition: boarddesignrules.h:48
void rebuildAllPlanes() noexcept
Definition: board.cpp:686
The GraphicsView class.
Definition: graphicsview.h:47
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:62
QSet< NetSignal * > mScheduledNetSignalsForAirWireRebuild
Definition: board.h:282
The Project class represents a whole (opened) project with all its content.
Definition: project.h:84
void deviceRemoved(BI_Device &comp)
The GridProperties class.
Definition: gridproperties.h:43
QScopedPointer< BoardUserSettings > mUserSettings
Definition: board.h:280
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: board.h:229
QList< BI_Base * > getAllItems() const noexcept
Definition: board.cpp:560
QScopedPointer< BoardLayerStack > mLayerStack
Definition: board.h:276
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: board.h:275
QScopedPointer< SmartSExprFile > mFile
Definition: board.h:272
void addNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:639
FilePath mFilePath
the filepath of the board.lp file (from the ctor)
Definition: board.h:271
const QList< BI_NetSegment * > & getNetSegments() const noexcept
Definition: board.h:187
BI_Device * getDeviceInstanceByComponentUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:591
const QIcon & getIcon() const noexcept
Definition: board.h:173
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:294
void clearSelection() const noexcept
Definition: board.cpp:915
BoardDesignRules & getDesignRules() noexcept
Definition: board.h:138
void removeStrokeText(BI_StrokeText &text)
Definition: board.cpp:729
Uuid mUuid
Definition: board.h:285
The BI_Plane class.
Definition: bi_plane.h:56
QList< BI_NetSegment * > mNetSegments
Definition: board.h:292
Board(Project &project, const FilePath &filepath, bool restore, bool readOnly)
Definition: board.h:125
The BI_NetSegment class.
Definition: bi_netsegment.h:59
bool operator!=(const Board &rhs) noexcept
Definition: board.h:246
void removePolygon(BI_Polygon &polygon)
Definition: board.cpp:708
The SmartSExprFile class represents an S-Expressions file and provides methods to load/save DOM trees...
Definition: smartsexprfile.h:56
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:807
const QList< BI_Plane * > & getPlanes() const noexcept
Definition: board.h:195
void addHole(BI_Hole &hole)
Definition: board.cpp:741
ElementName mName
Definition: board.h:286
The BoardUserSettings class.
Definition: boardusersettings.h:50
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: board.cpp:868
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
The BI_Polygon class.
Definition: bi_polygon.h:59
void updateErcMessages() noexcept
Definition: board.cpp:990
The BI_Hole class.
Definition: bi_hole.h:52
void removeDeviceInstance(BI_Device &instance)
Definition: board.cpp:616
QList< BI_Via * > getViasAtScenePos(const Point &pos, const NetSignal *netsignal) const noexcept
Definition: board.cpp:507
void showInView(GraphicsView &view) noexcept
Definition: board.cpp:864
bool isEmpty() const noexcept
Definition: board.cpp:422
const BoardDesignRules & getDesignRules() const noexcept
Definition: board.h:139
void setGridProperties(const GridProperties &grid) noexcept
Definition: board.cpp:583
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
QList< BI_Hole * > mHoles
Definition: board.h:296
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
QString mDefaultFontFileName
Definition: board.h:288
const BoardFabricationOutputSettings & getFabricationOutputSettings() const noexcept
Definition: board.h:145
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:428
void removeFromProject()
Definition: board.cpp:824
const QMap< Uuid, BI_Device * > & getDeviceInstances() const noexcept
Definition: board.h:179
void removeHole(BI_Hole &hole)
Definition: board.cpp:750
QScopedPointer< GridProperties > mGridProperties
Definition: board.h:277
Z value for librepcb::project::BI_Via items.
Definition: board.h:116
void updateIcon() noexcept
Definition: board.cpp:953
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:596
void addStrokeText(BI_StrokeText &text)
Definition: board.cpp:720
QList< BI_Plane * > mPlanes
Definition: board.h:293
QMap< Uuid, BI_Device * > mDeviceInstances
Definition: board.h:291
QIcon mIcon
Definition: board.h:287
const QList< BI_Hole * > & getHoles() const noexcept
Definition: board.h:213
Z value for librepcb::project::BI_StrokeText items.
Definition: board.h:104
const GridProperties & getGridProperties() const noexcept
Definition: board.h:132
void removePlane(BI_Plane &plane)
Definition: board.cpp:678
this is the default value (behind all other items)
Definition: board.h:103
void addPlane(BI_Plane &plane)
Definition: board.cpp:669
The NetSignal class.
Definition: netsignal.h:56
BI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: board.cpp:632
QHash< Uuid, ErcMsg * > mErcMsgListUnplacedComponentInstances
Definition: board.h:300
void addPolygon(BI_Polygon &polygon)
Definition: board.cpp:699
const ElementName & getName() const noexcept
Definition: board.h:172
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:270
const Uuid & getUuid() const noexcept
Definition: board.h:171
void triggerAirWiresRebuild() noexcept
Definition: board.cpp:762
void forceAirWiresRebuild() noexcept
Definition: board.cpp:796
Z value for librepcb::project::BI_AirWire items.
Definition: board.h:118
QMultiHash< NetSignal *, BI_AirWire * > mAirWires
Definition: board.h:297
QScopedPointer< BoardFabricationOutputSettings > mFabricationOutputSettings
Definition: board.h:279
const QList< BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: board.h:206
void removeNetSegment(BI_NetSegment &netsegment)
Definition: board.cpp:656
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:543
bool mIsAddedToProject
Definition: board.h:273
~Board() noexcept
Definition: board.cpp:387
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:136