LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bi_netsegment.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_BI_NETSEGMENT_H
21 #define LIBREPCB_PROJECT_BI_NETSEGMENT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "bi_base.h"
27 
29 #include <librepcb/common/uuid.h>
30 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 class GraphicsLayer;
39 
40 namespace project {
41 
42 class NetSignal;
43 class BI_Device;
44 class BI_Via;
45 class BI_FootprintPad;
46 class BI_NetPoint;
47 class BI_NetLine;
48 class BI_NetLineAnchor;
49 
50 /*******************************************************************************
51  * Class BI_NetSegment
52  ******************************************************************************/
53 
59 class BI_NetSegment final : public BI_Base, public SerializableObject {
60  Q_OBJECT
61 
62 public:
63  // Constructors / Destructor
64  BI_NetSegment() = delete;
65  BI_NetSegment(const BI_NetSegment& other) = delete;
66  BI_NetSegment(Board& board, const BI_NetSegment& other,
67  const QHash<const BI_Device*, BI_Device*>& devMap);
68  BI_NetSegment(Board& board, const SExpression& node);
69  BI_NetSegment(Board& board, NetSignal& signal);
70  ~BI_NetSegment() noexcept;
71 
72  // Getters
73  const Uuid& getUuid() const noexcept { return mUuid; }
74  NetSignal& getNetSignal() const noexcept { return *mNetSignal; }
75  bool isUsed() const noexcept;
76  int getViasAtScenePos(const Point& pos, QList<BI_Via*>& vias) const noexcept;
77  int getNetPointsAtScenePos(const Point& pos, const GraphicsLayer* layer,
78  QList<BI_NetPoint*>& points) const noexcept;
79  int getNetLinesAtScenePos(const Point& pos, const GraphicsLayer* layer,
80  QList<BI_NetLine*>& lines) const noexcept;
81 
82  // Setters
83  void setNetSignal(NetSignal& netsignal);
84 
85  // Via Methods
86  const QList<BI_Via*>& getVias() const noexcept { return mVias; }
87  BI_Via* getViaByUuid(const Uuid& uuid) const noexcept;
88 
89  // NetPoint Methods
90  const QList<BI_NetPoint*>& getNetPoints() const noexcept {
91  return mNetPoints;
92  }
93  BI_NetPoint* getNetPointByUuid(const Uuid& uuid) const noexcept;
94 
95  // NetLine Methods
96  const QList<BI_NetLine*>& getNetLines() const noexcept { return mNetLines; }
97  BI_NetLine* getNetLineByUuid(const Uuid& uuid) const noexcept;
98 
99  // NetPoint+NetLine Methods
100  void addElements(const QList<BI_Via*>& vias,
101  const QList<BI_NetPoint*>& netpoints,
102  const QList<BI_NetLine*>& netlines);
103  void removeElements(const QList<BI_Via*>& vias,
104  const QList<BI_NetPoint*>& netpoints,
105  const QList<BI_NetLine*>& netlines);
106 
107  // General Methods
108  void addToBoard() override;
109  void removeFromBoard() override;
110  void setSelectionRect(const QRectF rectPx) noexcept;
111  void clearSelection() const noexcept;
112 
114  void serialize(SExpression& root) const override;
115 
116  // Inherited from BI_Base
117  Type_t getType() const noexcept override {
119  }
120  const Point& getPosition() const noexcept override {
121  static Point p(0, 0);
122  return p;
123  }
124  bool getIsMirrored() const noexcept override { return false; }
125  QPainterPath getGrabAreaScenePx() const noexcept override;
126  bool isSelectable() const noexcept override { return false; }
127  bool isSelected() const noexcept override;
128  void setSelected(bool selected) noexcept override;
129 
130  // Operator Overloadings
131  BI_NetSegment& operator=(const BI_NetSegment& rhs) = delete;
132  bool operator==(const BI_NetSegment& rhs) noexcept { return (this == &rhs); }
133  bool operator!=(const BI_NetSegment& rhs) noexcept { return (this != &rhs); }
134 
135 private:
136  bool checkAttributesValidity() const noexcept;
137  bool areAllNetPointsConnectedTogether() const noexcept;
139  QSet<const BI_Via*>& vias,
140  QSet<const BI_FootprintPad*>& pads,
141  QSet<const BI_NetPoint*>& points) const
142  noexcept;
143 
144  // Attributes
147 
148  // Items
149  QList<BI_Via*> mVias;
152 };
153 
154 /*******************************************************************************
155  * End of File
156  ******************************************************************************/
157 
158 } // namespace project
159 } // namespace librepcb
160 
161 #endif // LIBREPCB_PROJECT_BI_NETSEGMENT_H
NetSignal & getNetSignal() const noexcept
Definition: bi_netsegment.h:74
void removeFromBoard() override
Definition: bi_netsegment.cpp:475
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
bool getIsMirrored() const noexceptoverride
Definition: bi_netsegment.h:124
The BI_NetPoint class.
Definition: bi_netpoint.h:48
const QList< BI_Via * > & getVias() const noexcept
Definition: bi_netsegment.h:86
const Point & getPosition() const noexceptoverride
Definition: bi_netsegment.h:120
const Uuid & getUuid() const noexcept
Definition: bi_netsegment.h:73
void findAllConnectedNetPoints(const BI_NetLineAnchor &p, QSet< const BI_Via * > &vias, QSet< const BI_FootprintPad * > &pads, QSet< const BI_NetPoint * > &points) const noexcept
Definition: bi_netsegment.cpp:586
void addToBoard() override
Definition: bi_netsegment.cpp:450
~BI_NetSegment() noexcept
Definition: bi_netsegment.cpp:192
Type_t
Definition: bi_base.h:57
QList< BI_NetLine * > mNetLines
Definition: bi_netsegment.h:151
bool isUsed() const noexcept
Definition: bi_netsegment.cpp:206
BI_Via * getViaByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:281
int getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer, QList< BI_NetLine * > &lines) const noexcept
Definition: bi_netsegment.cpp:240
int getViasAtScenePos(const Point &pos, QList< BI_Via * > &vias) const noexcept
Definition: bi_netsegment.cpp:211
Uuid mUuid
Definition: bi_netsegment.h:145
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
void addElements(const QList< BI_Via * > &vias, const QList< BI_NetPoint * > &netpoints, const QList< BI_NetLine * > &netlines)
Definition: bi_netsegment.cpp:314
BI_NetPoint * getNetPointByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:292
The BI_NetSegment class.
Definition: bi_netsegment.h:59
void removeElements(const QList< BI_Via * > &vias, const QList< BI_NetPoint * > &netpoints, const QList< BI_NetLine * > &netlines)
Definition: bi_netsegment.cpp:391
bool isSelectable() const noexceptoverride
Definition: bi_netsegment.h:126
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
librepcb::project::BI_NetSegment
const QList< BI_NetLine * > & getNetLines() const noexcept
Definition: bi_netsegment.h:96
QList< BI_Via * > mVias
Definition: bi_netsegment.h:149
bool operator!=(const BI_NetSegment &rhs) noexcept
Definition: bi_netsegment.h:133
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
bool checkAttributesValidity() const noexcept
Definition: bi_netsegment.cpp:561
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_netsegment.cpp:521
QList< BI_NetPoint * > mNetPoints
Definition: bi_netsegment.h:150
Definition: bi_netline.h:51
bool isSelected() const noexceptoverride
Definition: bi_netsegment.cpp:539
const QList< BI_NetPoint * > & getNetPoints() const noexcept
Definition: bi_netsegment.h:90
int getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer, QList< BI_NetPoint * > &points) const noexcept
Definition: bi_netsegment.cpp:224
The NetSignal class.
Definition: netsignal.h:56
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_netsegment.cpp:535
void setSelectionRect(const QRectF rectPx) noexcept
Definition: bi_netsegment.cpp:500
BI_NetLine * getNetLineByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:303
void clearSelection() const noexcept
Definition: bi_netsegment.cpp:512
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:82
Type_t getType() const noexceptoverride
Definition: bi_netsegment.h:117
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
void setNetSignal(NetSignal &netsignal)
Definition: bi_netsegment.cpp:260
bool areAllNetPointsConnectedTogether() const noexcept
Definition: bi_netsegment.cpp:567
void setSelected(bool selected) noexceptoverride
Definition: bi_netsegment.cpp:547
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:60
NetSignal * mNetSignal
Definition: bi_netsegment.h:146
The BI_Via class.
Definition: bi_via.h:49