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 
57 class BI_NetSegment final : public BI_Base, public SerializableObject {
58  Q_OBJECT
59 
60 public:
61  // Constructors / Destructor
62  BI_NetSegment() = delete;
63  BI_NetSegment(const BI_NetSegment& other) = delete;
64  BI_NetSegment(Board& board, const BI_NetSegment& other,
65  const QHash<const BI_Device*, BI_Device*>& devMap);
66  BI_NetSegment(Board& board, const SExpression& node);
67  BI_NetSegment(Board& board, NetSignal& signal);
68  ~BI_NetSegment() noexcept;
69 
70  // Getters
71  const Uuid& getUuid() const noexcept { return mUuid; }
72  NetSignal& getNetSignal() const noexcept { return *mNetSignal; }
73  bool isUsed() const noexcept;
74  int getViasAtScenePos(const Point& pos, QList<BI_Via*>& vias) const noexcept;
75  int getNetPointsAtScenePos(const Point& pos, const GraphicsLayer* layer,
76  QList<BI_NetPoint*>& points) const noexcept;
77  int getNetLinesAtScenePos(const Point& pos, const GraphicsLayer* layer,
78  QList<BI_NetLine*>& lines) const noexcept;
79 
80  // Setters
81  void setNetSignal(NetSignal& netsignal);
82 
83  // Via Methods
84  const QList<BI_Via*>& getVias() const noexcept { return mVias; }
85  BI_Via* getViaByUuid(const Uuid& uuid) const noexcept;
86 
87  // NetPoint Methods
88  const QList<BI_NetPoint*>& getNetPoints() const noexcept {
89  return mNetPoints;
90  }
91  BI_NetPoint* getNetPointByUuid(const Uuid& uuid) const noexcept;
92 
93  // NetLine Methods
94  const QList<BI_NetLine*>& getNetLines() const noexcept { return mNetLines; }
95  BI_NetLine* getNetLineByUuid(const Uuid& uuid) const noexcept;
96 
97  // NetPoint+NetLine Methods
98  void addElements(const QList<BI_Via*>& vias,
99  const QList<BI_NetPoint*>& netpoints,
100  const QList<BI_NetLine*>& netlines);
101  void removeElements(const QList<BI_Via*>& vias,
102  const QList<BI_NetPoint*>& netpoints,
103  const QList<BI_NetLine*>& netlines);
104 
105  // General Methods
106  void addToBoard() override;
107  void removeFromBoard() override;
108  void setSelectionRect(const QRectF rectPx) noexcept;
109  void clearSelection() const noexcept;
110 
112  void serialize(SExpression& root) const override;
113 
114  // Inherited from BI_Base
115  Type_t getType() const noexcept override {
117  }
118  const Point& getPosition() const noexcept override {
119  static Point p(0, 0);
120  return p;
121  }
122  bool getIsMirrored() const noexcept override { return false; }
123  QPainterPath getGrabAreaScenePx() const noexcept override;
124  bool isSelectable() const noexcept override { return false; }
125  bool isSelected() const noexcept override;
126  void setSelected(bool selected) noexcept override;
127 
128  // Operator Overloadings
129  BI_NetSegment& operator=(const BI_NetSegment& rhs) = delete;
130  bool operator==(const BI_NetSegment& rhs) noexcept { return (this == &rhs); }
131  bool operator!=(const BI_NetSegment& rhs) noexcept { return (this != &rhs); }
132 
133 private:
134  bool checkAttributesValidity() const noexcept;
135  bool areAllNetPointsConnectedTogether() const noexcept;
137  QSet<const BI_Via*>& vias,
138  QSet<const BI_FootprintPad*>& pads,
139  QSet<const BI_NetPoint*>& points) const
140  noexcept;
141 
142  // Attributes
145 
146  // Items
147  QList<BI_Via*> mVias;
150 };
151 
152 /*******************************************************************************
153  * End of File
154  ******************************************************************************/
155 
156 } // namespace project
157 } // namespace librepcb
158 
159 #endif // LIBREPCB_PROJECT_BI_NETSEGMENT_H
NetSignal & getNetSignal() const noexcept
Definition: bi_netsegment.h:72
void removeFromBoard() override
Definition: bi_netsegment.cpp:448
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
bool getIsMirrored() const noexceptoverride
Definition: bi_netsegment.h:122
The BI_NetPoint class.
Definition: bi_netpoint.h:48
const QList< BI_Via * > & getVias() const noexcept
Definition: bi_netsegment.h:84
const Point & getPosition() const noexceptoverride
Definition: bi_netsegment.h:118
const Uuid & getUuid() const noexcept
Definition: bi_netsegment.h:71
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:559
void addToBoard() override
Definition: bi_netsegment.cpp:423
~BI_NetSegment() noexcept
Definition: bi_netsegment.cpp:165
Type_t
Definition: bi_base.h:57
QList< BI_NetLine * > mNetLines
Definition: bi_netsegment.h:149
bool isUsed() const noexcept
Definition: bi_netsegment.cpp:179
BI_Via * getViaByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:254
int getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer, QList< BI_NetLine * > &lines) const noexcept
Definition: bi_netsegment.cpp:213
int getViasAtScenePos(const Point &pos, QList< BI_Via * > &vias) const noexcept
Definition: bi_netsegment.cpp:184
Uuid mUuid
Definition: bi_netsegment.h:143
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
void addElements(const QList< BI_Via * > &vias, const QList< BI_NetPoint * > &netpoints, const QList< BI_NetLine * > &netlines)
Definition: bi_netsegment.cpp:287
BI_NetPoint * getNetPointByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:265
The BI_NetSegment class.
Definition: bi_netsegment.h:57
void removeElements(const QList< BI_Via * > &vias, const QList< BI_NetPoint * > &netpoints, const QList< BI_NetLine * > &netlines)
Definition: bi_netsegment.cpp:364
bool isSelectable() const noexceptoverride
Definition: bi_netsegment.h:124
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
librepcb::project::BI_NetSegment
const QList< BI_NetLine * > & getNetLines() const noexcept
Definition: bi_netsegment.h:94
QList< BI_Via * > mVias
Definition: bi_netsegment.h:147
bool operator!=(const BI_NetSegment &rhs) noexcept
Definition: bi_netsegment.h:131
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
bool checkAttributesValidity() const noexcept
Definition: bi_netsegment.cpp:534
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_netsegment.cpp:494
QList< BI_NetPoint * > mNetPoints
Definition: bi_netsegment.h:148
Definition: bi_netline.h:51
bool isSelected() const noexceptoverride
Definition: bi_netsegment.cpp:512
const QList< BI_NetPoint * > & getNetPoints() const noexcept
Definition: bi_netsegment.h:88
int getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer, QList< BI_NetPoint * > &points) const noexcept
Definition: bi_netsegment.cpp:197
The NetSignal class.
Definition: netsignal.h:56
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_netsegment.cpp:508
void setSelectionRect(const QRectF rectPx) noexcept
Definition: bi_netsegment.cpp:473
BI_NetLine * getNetLineByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:276
void clearSelection() const noexcept
Definition: bi_netsegment.cpp:485
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:83
Type_t getType() const noexceptoverride
Definition: bi_netsegment.h:115
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:233
bool areAllNetPointsConnectedTogether() const noexcept
Definition: bi_netsegment.cpp:540
void setSelected(bool selected) noexceptoverride
Definition: bi_netsegment.cpp:520
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:57
NetSignal * mNetSignal
Definition: bi_netsegment.h:144
The BI_Via class.
Definition: bi_via.h:49