LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
si_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_SI_NETSEGMENT_H
21 #define LIBREPCB_PROJECT_SI_NETSEGMENT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "si_base.h"
27 
29 #include <librepcb/common/uuid.h>
30 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 namespace project {
38 
39 class NetSignal;
40 class SI_NetPoint;
41 class SI_NetLine;
42 class SI_NetLabel;
43 class SI_NetLineAnchor;
44 class SI_SymbolPin;
45 
46 /*******************************************************************************
47  * Class SI_NetSegment
48  ******************************************************************************/
49 
55 class SI_NetSegment final : public SI_Base, public SerializableObject {
56  Q_OBJECT
57 
58 public:
59  // Constructors / Destructor
60  SI_NetSegment() = delete;
61  SI_NetSegment(const SI_NetSegment& other) = delete;
62  SI_NetSegment(Schematic& schematic, const SExpression& node);
63  SI_NetSegment(Schematic& schematic, NetSignal& signal);
64  ~SI_NetSegment() noexcept;
65 
66  // Getters
67  const Uuid& getUuid() const noexcept { return mUuid; }
68  NetSignal& getNetSignal() const noexcept { return *mNetSignal; }
69  bool isUsed() const noexcept;
70  int getNetPointsAtScenePos(const Point& pos,
71  QList<SI_NetPoint*>& points) const noexcept;
72  int getNetLinesAtScenePos(const Point& pos, QList<SI_NetLine*>& lines) const
73  noexcept;
74  int getNetLabelsAtScenePos(const Point& pos,
75  QList<SI_NetLabel*>& labels) const noexcept;
76  QSet<QString> getForcedNetNames() const noexcept;
77  QString getForcedNetName() const noexcept;
78  Point calcNearestPoint(const Point& p) const noexcept;
79  QSet<SI_SymbolPin*> getAllConnectedPins() const noexcept;
80 
81  // Setters
82  void setNetSignal(NetSignal& netsignal);
83 
84  // NetPoint Methods
85  const QList<SI_NetPoint*>& getNetPoints() const noexcept {
86  return mNetPoints;
87  }
88  SI_NetPoint* getNetPointByUuid(const Uuid& uuid) const noexcept;
89 
90  // NetLine Methods
91  const QList<SI_NetLine*>& getNetLines() const noexcept { return mNetLines; }
92  SI_NetLine* getNetLineByUuid(const Uuid& uuid) const noexcept;
93 
94  // NetPoint+NetLine Methods
95  void addNetPointsAndNetLines(const QList<SI_NetPoint*>& netpoints,
96  const QList<SI_NetLine*>& netlines);
97  void removeNetPointsAndNetLines(const QList<SI_NetPoint*>& netpoints,
98  const QList<SI_NetLine*>& netlines);
99 
100  // NetLabel Methods
101  const QList<SI_NetLabel*>& getNetLabels() const noexcept {
102  return mNetLabels;
103  }
104  SI_NetLabel* getNetLabelByUuid(const Uuid& uuid) const noexcept;
105  void addNetLabel(SI_NetLabel& netlabel);
106  void removeNetLabel(SI_NetLabel& netlabel);
107  void updateAllNetLabelAnchors() noexcept;
108 
109  // General Methods
110  void addToSchematic() override;
111  void removeFromSchematic() override;
112  void setSelectionRect(const QRectF rectPx) noexcept;
113  void clearSelection() const noexcept;
114 
116  void serialize(SExpression& root) const override;
117 
118  // Inherited from SI_Base
119  Type_t getType() const noexcept override {
121  }
122  const Point& getPosition() const noexcept override {
123  static Point p(0, 0);
124  return p;
125  }
126  QPainterPath getGrabAreaScenePx() const noexcept override;
127  bool isSelected() const noexcept override;
128  void setSelected(bool selected) noexcept override;
129 
130  // Operator Overloadings
131  SI_NetSegment& operator=(const SI_NetSegment& rhs) = delete;
132  bool operator==(const SI_NetSegment& rhs) noexcept { return (this == &rhs); }
133  bool operator!=(const SI_NetSegment& rhs) noexcept { return (this != &rhs); }
134 
135 private:
136  bool checkAttributesValidity() const noexcept;
137  bool areAllNetPointsConnectedTogether() const noexcept;
139  QSet<const SI_SymbolPin*>& pins,
140  QSet<const SI_NetPoint*>& points) const
141  noexcept;
142 
143  // Attributes
146 
147  // Items
151 };
152 
153 /*******************************************************************************
154  * End of File
155  ******************************************************************************/
156 
157 } // namespace project
158 } // namespace librepcb
159 
160 #endif // LIBREPCB_PROJECT_SI_NETSEGMENT_H
NetSignal & getNetSignal() const noexcept
Definition: si_netsegment.h:68
Point calcNearestPoint(const Point &p) const noexcept
Definition: si_netsegment.cpp:211
int getNetPointsAtScenePos(const Point &pos, QList< SI_NetPoint * > &points) const noexcept
Definition: si_netsegment.cpp:146
QSet< QString > getForcedNetNames() const noexcept
Definition: si_netsegment.cpp:185
void findAllConnectedNetPoints(const SI_NetLineAnchor &p, QSet< const SI_SymbolPin * > &pins, QSet< const SI_NetPoint * > &points) const noexcept
Definition: si_netsegment.cpp:564
The SI_NetPoint class.
Definition: si_netpoint.h:48
const Point & getPosition() const noexceptoverride
Definition: si_netsegment.h:122
const Uuid & getUuid() const noexcept
Definition: si_netsegment.h:67
bool operator!=(const SI_NetSegment &rhs) noexcept
Definition: si_netsegment.h:133
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:83
QList< SI_NetLine * > mNetLines
Definition: si_netsegment.h:149
The Schematic Item Base (SI_Base) class.
Definition: si_base.h:52
SI_NetLine * getNetLineByUuid(const Uuid &uuid) const noexcept
Definition: si_netsegment.cpp:282
bool isUsed() const noexcept
Definition: si_netsegment.cpp:141
int getNetLabelsAtScenePos(const Point &pos, QList< SI_NetLabel * > &labels) const noexcept
Definition: si_netsegment.cpp:172
QList< SI_NetLabel * > mNetLabels
Definition: si_netsegment.h:150
void updateAllNetLabelAnchors() noexcept
Definition: si_netsegment.cpp:433
Uuid mUuid
Definition: si_netsegment.h:144
~SI_NetSegment() noexcept
Definition: si_netsegment.cpp:127
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
SI_NetLabel * getNetLabelByUuid(const Uuid &uuid) const noexcept
Definition: si_netsegment.cpp:400
QSet< SI_SymbolPin * > getAllConnectedPins() const noexcept
Definition: si_netsegment.cpp:227
The SI_SymbolPin class.
Definition: si_symbolpin.h:58
void removeNetLabel(SI_NetLabel &netlabel)
Definition: si_netsegment.cpp:424
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
const QList< SI_NetPoint * > & getNetPoints() const noexcept
Definition: si_netsegment.h:85
void removeNetPointsAndNetLines(const QList< SI_NetPoint * > &netpoints, const QList< SI_NetLine * > &netlines)
Definition: si_netsegment.cpp:352
The SI_NetSegment class.
Definition: si_netsegment.h:55
librepcb::project::SI_NetSegment
const QList< SI_NetLabel * > & getNetLabels() const noexcept
Definition: si_netsegment.h:101
SI_NetPoint * getNetPointByUuid(const Uuid &uuid) const noexcept
Definition: si_netsegment.cpp:271
int getNetLinesAtScenePos(const Point &pos, QList< SI_NetLine * > &lines) const noexcept
Definition: si_netsegment.cpp:159
Type_t
Definition: si_base.h:57
QString getForcedNetName() const noexcept
Definition: si_netsegment.cpp:202
bool checkAttributesValidity() const noexcept
Definition: si_netsegment.cpp:545
Definition: si_netline.h:46
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: si_netsegment.cpp:511
void addToSchematic() override
Definition: si_netsegment.cpp:441
void addNetLabel(SI_NetLabel &netlabel)
Definition: si_netsegment.cpp:407
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: si_netsegment.cpp:525
The NetSignal class.
Definition: netsignal.h:56
void clearSelection() const noexcept
Definition: si_netsegment.cpp:502
bool isSelected() const noexceptoverride
Definition: si_netsegment.cpp:529
QList< SI_NetPoint * > mNetPoints
Definition: si_netsegment.h:148
void setNetSignal(NetSignal &netsignal)
Definition: si_netsegment.cpp:250
The SI_NetLabel class.
Definition: si_netlabel.h:51
void setSelectionRect(const QRectF rectPx) noexcept
Definition: si_netsegment.cpp:493
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
bool areAllNetPointsConnectedTogether() const noexcept
Definition: si_netsegment.cpp:551
The SI_NetLine class.
Definition: si_netline.h:64
void setSelected(bool selected) noexceptoverride
Definition: si_netsegment.cpp:537
Type_t getType() const noexceptoverride
Definition: si_netsegment.h:119
NetSignal * mNetSignal
Definition: si_netsegment.h:145
void addNetPointsAndNetLines(const QList< SI_NetPoint * > &netpoints, const QList< SI_NetLine * > &netlines)
Definition: si_netsegment.cpp:293
const QList< SI_NetLine * > & getNetLines() const noexcept
Definition: si_netsegment.h:91
The SExpression class.
Definition: sexpression.h:57
void removeFromSchematic() override
Definition: si_netsegment.cpp:467