LibrePCB Developers Documentation
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 
81  const GraphicsLayer* layer,
82  UnsignedLength& maxDistance) const
83  noexcept;
84  BI_Via* getViaNextToScenePos(const Point& pos,
85  UnsignedLength& maxDistance) const noexcept;
86 
87  // Setters
88  void setNetSignal(NetSignal& netsignal);
89 
90  // Via Methods
91  const QList<BI_Via*>& getVias() const noexcept { return mVias; }
92  BI_Via* getViaByUuid(const Uuid& uuid) const noexcept;
93 
94  // NetPoint Methods
95  const QList<BI_NetPoint*>& getNetPoints() const noexcept {
96  return mNetPoints;
97  }
98  BI_NetPoint* getNetPointByUuid(const Uuid& uuid) const noexcept;
99 
100  // NetLine Methods
101  const QList<BI_NetLine*>& getNetLines() const noexcept { return mNetLines; }
102  BI_NetLine* getNetLineByUuid(const Uuid& uuid) const noexcept;
103 
104  // NetPoint+NetLine Methods
105  void addElements(const QList<BI_Via*>& vias,
106  const QList<BI_NetPoint*>& netpoints,
107  const QList<BI_NetLine*>& netlines);
108  void removeElements(const QList<BI_Via*>& vias,
109  const QList<BI_NetPoint*>& netpoints,
110  const QList<BI_NetLine*>& netlines);
111 
112  // General Methods
113  void addToBoard() override;
114  void removeFromBoard() override;
115  void selectAll() noexcept;
116  void setSelectionRect(const QRectF rectPx) noexcept;
117  void clearSelection() const noexcept;
118 
120  void serialize(SExpression& root) const override;
121 
122  // Inherited from BI_Base
123  Type_t getType() const noexcept override {
125  }
126  const Point& getPosition() const noexcept override {
127  static Point p(0, 0);
128  return p;
129  }
130  bool getIsMirrored() const noexcept override { return false; }
131  QPainterPath getGrabAreaScenePx() const noexcept override;
132  bool isSelectable() const noexcept override { return false; }
133  bool isSelected() const noexcept override;
134  void setSelected(bool selected) noexcept override;
135 
136  // Operator Overloadings
137  BI_NetSegment& operator=(const BI_NetSegment& rhs) = delete;
138  bool operator==(const BI_NetSegment& rhs) noexcept { return (this == &rhs); }
139  bool operator!=(const BI_NetSegment& rhs) noexcept { return (this != &rhs); }
140 
141 private:
142  bool checkAttributesValidity() const noexcept;
143  bool areAllNetPointsConnectedTogether() const noexcept;
145  QSet<const BI_Via*>& vias,
146  QSet<const BI_FootprintPad*>& pads,
147  QSet<const BI_NetPoint*>& points) const
148  noexcept;
149 
150  // Attributes
153 
154  // Items
155  QList<BI_Via*> mVias;
156  QList<BI_NetPoint*> mNetPoints;
157  QList<BI_NetLine*> mNetLines;
158 };
159 
160 /*******************************************************************************
161  * End of File
162  ******************************************************************************/
163 
164 } // namespace project
165 } // namespace librepcb
166 
167 #endif // LIBREPCB_PROJECT_BI_NETSEGMENT_H
NetSignal & getNetSignal() const noexcept
Definition: bi_netsegment.h:72
void removeFromBoard() override
Definition: bi_netsegment.cpp:482
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
The BI_NetPoint class.
Definition: bi_netpoint.h:49
const QList< BI_Via * > & getVias() const noexcept
Definition: bi_netsegment.h:91
const Uuid & getUuid() const noexcept
Definition: bi_netsegment.h:71
bool getIsMirrored() const noexcept override
Definition: bi_netsegment.h:130
Definition: airwiresbuilder.cpp:32
bool isSelected() const noexcept override
Definition: bi_netsegment.cpp:555
Type_t getType() const noexcept override
Definition: bi_netsegment.h:123
void addToBoard() override
Definition: bi_netsegment.cpp:457
~BI_NetSegment() noexcept
Definition: bi_netsegment.cpp:165
Type_t
Definition: bi_base.h:57
QList< BI_NetLine * > mNetLines
Definition: bi_netsegment.h:157
bool isUsed() const noexcept
Definition: bi_netsegment.cpp:179
void removeElements(const QList< BI_Via *> &vias, const QList< BI_NetPoint *> &netpoints, const QList< BI_NetLine *> &netlines)
Definition: bi_netsegment.cpp:398
int getNetPointsAtScenePos(const Point &pos, const GraphicsLayer *layer, QList< BI_NetPoint *> &points) const noexcept
Definition: bi_netsegment.cpp:197
BI_Via * getViaByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:289
Uuid mUuid
Definition: bi_netsegment.h:151
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
QPainterPath getGrabAreaScenePx() const noexcept override
Definition: bi_netsegment.cpp:551
BI_NetPoint * getNetPointByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:300
The BI_NetSegment class.
Definition: bi_netsegment.h:57
int getViasAtScenePos(const Point &pos, QList< BI_Via *> &vias) const noexcept
Definition: bi_netsegment.cpp:184
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
BI_NetPoint * getNetPointNextToScenePos(const Point &pos, const GraphicsLayer *layer, UnsignedLength &maxDistance) const noexcept
Definition: bi_netsegment.cpp:229
librepcb::project::BI_NetSegment
const QList< BI_NetLine * > & getNetLines() const noexcept
Definition: bi_netsegment.h:101
QList< BI_Via * > mVias
Definition: bi_netsegment.h:155
bool operator!=(const BI_NetSegment &rhs) noexcept
Definition: bi_netsegment.h:139
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
bool checkAttributesValidity() const noexcept
Definition: bi_netsegment.cpp:577
int getNetLinesAtScenePos(const Point &pos, const GraphicsLayer *layer, QList< BI_NetLine *> &lines) const noexcept
Definition: bi_netsegment.cpp:213
void selectAll() noexcept
Definition: bi_netsegment.cpp:507
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_netsegment.cpp:537
QList< BI_NetPoint * > mNetPoints
Definition: bi_netsegment.h:156
Definition: bi_netline.h:51
const QList< BI_NetPoint * > & getNetPoints() const noexcept
Definition: bi_netsegment.h:95
The NetSignal class.
Definition: netsignal.h:56
bool isSelectable() const noexcept override
Definition: bi_netsegment.h:132
void setSelectionRect(const QRectF rectPx) noexcept
Definition: bi_netsegment.cpp:516
BI_NetLine * getNetLineByUuid(const Uuid &uuid) const noexcept
Definition: bi_netsegment.cpp:311
void addElements(const QList< BI_Via *> &vias, const QList< BI_NetPoint *> &netpoints, const QList< BI_NetLine *> &netlines)
Definition: bi_netsegment.cpp:322
void clearSelection() const noexcept
Definition: bi_netsegment.cpp:528
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
void setNetSignal(NetSignal &netsignal)
Definition: bi_netsegment.cpp:268
bool areAllNetPointsConnectedTogether() const noexcept
Definition: bi_netsegment.cpp:583
bool operator==(const BI_NetSegment &rhs) noexcept
Definition: bi_netsegment.h:138
void setSelected(bool selected) noexcept override
Definition: bi_netsegment.cpp:563
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:602
The BI_NetLine class.
Definition: bi_netline.h:76
The SExpression class.
Definition: sexpression.h:57
BI_Via * getViaNextToScenePos(const Point &pos, UnsignedLength &maxDistance) const noexcept
Definition: bi_netsegment.cpp:246
NetSignal * mNetSignal
Definition: bi_netsegment.h:152
const Point & getPosition() const noexcept override
Definition: bi_netsegment.h:126
BI_NetSegment & operator=(const BI_NetSegment &rhs)=delete
The BI_Via class.
Definition: bi_via.h:49
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:673