LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
si_netline.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_NETLINE_H
21 #define LIBREPCB_PROJECT_SI_NETLINE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../graphicsitems/sgi_netline.h"
27 #include "si_base.h"
28 
30 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 namespace project {
38 
39 class NetSignal;
40 class SI_NetSegment;
41 
42 /*******************************************************************************
43  * Class SI_NetLineAnchor
44  ******************************************************************************/
45 
47 public:
48  SI_NetLineAnchor() noexcept = default;
49  virtual ~SI_NetLineAnchor() noexcept = default;
50 
51  virtual void registerNetLine(SI_NetLine& netline) = 0;
52  virtual void unregisterNetLine(SI_NetLine& netline) = 0;
53  virtual const QSet<SI_NetLine*>& getNetLines() const noexcept = 0;
54  virtual const Point& getPosition() const noexcept = 0;
55 };
56 
57 /*******************************************************************************
58  * Class SI_NetLine
59  ******************************************************************************/
60 
64 class SI_NetLine final : public SI_Base, public SerializableObject {
65  Q_OBJECT
66 
67 public:
68  // Constructors / Destructor
69  SI_NetLine() = delete;
70  SI_NetLine(const SI_NetLine& other) = delete;
71  SI_NetLine(SI_NetSegment& segment, const SExpression& node,
72  const QHash<Uuid, SI_NetLineAnchor*>& netPointAnchorMap);
73  SI_NetLine(SI_NetSegment& segment, SI_NetLineAnchor& startPoint,
74  SI_NetLineAnchor& endPoint, const UnsignedLength& width);
75  ~SI_NetLine() noexcept;
76 
77  // Getters
78  SI_NetSegment& getNetSegment() const noexcept { return mNetSegment; }
79  const Uuid& getUuid() const noexcept { return mUuid; }
80  const UnsignedLength& getWidth() const noexcept { return mWidth; }
81  SI_NetLineAnchor& getStartPoint() const noexcept { return *mStartPoint; }
82  SI_NetLineAnchor& getEndPoint() const noexcept { return *mEndPoint; }
83  SI_NetLineAnchor* getOtherPoint(const SI_NetLineAnchor& firstPoint) const
84  noexcept;
85  NetSignal& getNetSignalOfNetSegment() const noexcept;
86 
87  // Setters
88  void setWidth(const UnsignedLength& width) noexcept;
89 
90  // General Methods
91  void addToSchematic() override;
92  void removeFromSchematic() override;
93  void updateLine() noexcept;
94 
96  void serialize(SExpression& root) const override;
97 
98  // Inherited from SI_Base
99  Type_t getType() const noexcept override { return SI_Base::Type_t::NetLine; }
100  const Point& getPosition() const noexcept override { return mPosition; }
101  QPainterPath getGrabAreaScenePx() const noexcept override;
102  void setSelected(bool selected) noexcept override;
103 
104  // Operator Overloadings
105  SI_NetLine& operator=(const SI_NetLine& rhs) = delete;
106 
107 private:
108  void init();
110  const SExpression& root, const QString& oldKey, const QString& newKey,
111  const QHash<Uuid, SI_NetLineAnchor*>& netPointAnchorMap) const;
112  void serializeAnchor(SExpression& root, SI_NetLineAnchor* anchor) const;
113 
114  // General
116  QScopedPointer<SGI_NetLine> mGraphicsItem;
118  QMetaObject::Connection mHighlightChangedConnection;
119 
120  // Attributes
121  Uuid mUuid;
125 };
126 
127 /*******************************************************************************
128  * End of File
129  ******************************************************************************/
130 
131 } // namespace project
132 } // namespace librepcb
133 
134 #endif // LIBREPCB_PROJECT_SI_NETLINE_H
QScopedPointer< SGI_NetLine > mGraphicsItem
Definition: si_netline.h:116
QMetaObject::Connection mHighlightChangedConnection
Definition: si_netline.h:118
virtual const QSet< SI_NetLine * > & getNetLines() const noexcept=0
SI_NetLineAnchor & getEndPoint() const noexcept
Definition: si_netline.h:82
virtual void registerNetLine(SI_NetLine &netline)=0
SI_NetLineAnchor * mEndPoint
Definition: si_netline.h:123
Uuid mUuid
Definition: si_netline.h:121
SI_NetLineAnchor * deserializeAnchor(const SExpression &root, const QString &oldKey, const QString &newKey, const QHash< Uuid, SI_NetLineAnchor * > &netPointAnchorMap) const
Definition: si_netline.cpp:169
librepcb::project::SI_NetLine
virtual ~SI_NetLineAnchor() noexcept=default
virtual void unregisterNetLine(SI_NetLine &netline)=0
The Schematic Item Base (SI_Base) class.
Definition: si_base.h:52
NetSignal & getNetSignalOfNetSegment() const noexcept
Definition: si_netline.cpp:108
Point mPosition
the center of startpoint and endpoint
Definition: si_netline.h:117
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
const Uuid & getUuid() const noexcept
Definition: si_netline.h:79
SI_NetSegment & getNetSegment() const noexcept
Definition: si_netline.h:78
void addToSchematic() override
Definition: si_netline.cpp:127
SI_NetLineAnchor * getOtherPoint(const SI_NetLineAnchor &firstPoint) const noexcept
Definition: si_netline.cpp:97
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: si_netline.cpp:162
void init()
Definition: si_netline.cpp:78
virtual const Point & getPosition() const noexcept=0
The SI_NetSegment class.
Definition: si_netsegment.h:55
void updateLine() noexcept
Definition: si_netline.cpp:157
void setSelected(bool selected) noexceptoverride
Definition: si_netline.cpp:214
const Point & getPosition() const noexceptoverride
Definition: si_netline.h:100
Type_t getType() const noexceptoverride
Definition: si_netline.h:99
void serializeAnchor(SExpression &root, SI_NetLineAnchor *anchor) const
Definition: si_netline.cpp:193
Type_t
Definition: si_base.h:57
SI_NetSegment & mNetSegment
Definition: si_netline.h:115
Definition: si_netline.h:46
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: si_netline.cpp:210
SI_NetLineAnchor & getStartPoint() const noexcept
Definition: si_netline.h:81
void removeFromSchematic() override
Definition: si_netline.cpp:143
SI_NetLineAnchor * mStartPoint
Definition: si_netline.h:122
The NetSignal class.
Definition: netsignal.h:56
void setWidth(const UnsignedLength &width) noexcept
Definition: si_netline.cpp:116
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The SI_NetLine class.
Definition: si_netline.h:64
~SI_NetLine() noexcept
Definition: si_netline.cpp:89
The SExpression class.
Definition: sexpression.h:60
The SGI_NetLine class.
Definition: sgi_netline.h:49
const UnsignedLength & getWidth() const noexcept
Definition: si_netline.h:80
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662
UnsignedLength mWidth
Definition: si_netline.h:124