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  SI_NetLine(SI_NetSegment& segment, SI_NetLineAnchor& startPoint,
73  SI_NetLineAnchor& endPoint, const UnsignedLength& width);
74  ~SI_NetLine() noexcept;
75 
76  // Getters
77  SI_NetSegment& getNetSegment() const noexcept { return mNetSegment; }
78  const Uuid& getUuid() const noexcept { return mUuid; }
79  const UnsignedLength& getWidth() const noexcept { return mWidth; }
80  SI_NetLineAnchor& getStartPoint() const noexcept { return *mStartPoint; }
81  SI_NetLineAnchor& getEndPoint() const noexcept { return *mEndPoint; }
82  SI_NetLineAnchor* getOtherPoint(const SI_NetLineAnchor& firstPoint) const
83  noexcept;
84  NetSignal& getNetSignalOfNetSegment() const noexcept;
85 
86  // Setters
87  void setWidth(const UnsignedLength& width) noexcept;
88 
89  // General Methods
90  void addToSchematic() override;
91  void removeFromSchematic() override;
92  void updateLine() noexcept;
93 
95  void serialize(SExpression& root) const override;
96 
97  // Inherited from SI_Base
98  Type_t getType() const noexcept override { return SI_Base::Type_t::NetLine; }
99  const Point& getPosition() const noexcept override { return mPosition; }
100  QPainterPath getGrabAreaScenePx() const noexcept override;
101  void setSelected(bool selected) noexcept override;
102 
103  // Operator Overloadings
104  SI_NetLine& operator=(const SI_NetLine& rhs) = delete;
105 
106 private:
107  void init();
109  const QString& key) const;
110  void serializeAnchor(SExpression& root, SI_NetLineAnchor* anchor) const;
111 
112  // General
114  QScopedPointer<SGI_NetLine> mGraphicsItem;
116  QMetaObject::Connection mHighlightChangedConnection;
117 
118  // Attributes
123 };
124 
125 /*******************************************************************************
126  * End of File
127  ******************************************************************************/
128 
129 } // namespace project
130 } // namespace librepcb
131 
132 #endif // LIBREPCB_PROJECT_SI_NETLINE_H
QScopedPointer< SGI_NetLine > mGraphicsItem
Definition: si_netline.h:114
QMetaObject::Connection mHighlightChangedConnection
Definition: si_netline.h:116
virtual const QSet< SI_NetLine * > & getNetLines() const noexcept=0
SI_NetLineAnchor & getEndPoint() const noexcept
Definition: si_netline.h:81
virtual void registerNetLine(SI_NetLine &netline)=0
SI_NetLineAnchor * mEndPoint
Definition: si_netline.h:121
Uuid mUuid
Definition: si_netline.h:119
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:107
Point mPosition
the center of startpoint and endpoint
Definition: si_netline.h:115
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:78
SI_NetSegment & getNetSegment() const noexcept
Definition: si_netline.h:77
void addToSchematic() override
Definition: si_netline.cpp:126
SI_NetLineAnchor * getOtherPoint(const SI_NetLineAnchor &firstPoint) const noexcept
Definition: si_netline.cpp:96
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:161
void init()
Definition: si_netline.cpp:77
virtual const Point & getPosition() const noexcept=0
The SI_NetSegment class.
Definition: si_netsegment.h:55
void updateLine() noexcept
Definition: si_netline.cpp:156
void setSelected(bool selected) noexceptoverride
Definition: si_netline.cpp:204
const Point & getPosition() const noexceptoverride
Definition: si_netline.h:99
Type_t getType() const noexceptoverride
Definition: si_netline.h:98
void serializeAnchor(SExpression &root, SI_NetLineAnchor *anchor) const
Definition: si_netline.cpp:183
Type_t
Definition: si_base.h:57
SI_NetLineAnchor * deserializeAnchor(const SExpression &root, const QString &key) const
Definition: si_netline.cpp:168
SI_NetSegment & mNetSegment
Definition: si_netline.h:113
Definition: si_netline.h:46
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: si_netline.cpp:200
SI_NetLineAnchor & getStartPoint() const noexcept
Definition: si_netline.h:80
void removeFromSchematic() override
Definition: si_netline.cpp:142
SI_NetLineAnchor * mStartPoint
Definition: si_netline.h:120
The NetSignal class.
Definition: netsignal.h:56
void setWidth(const UnsignedLength &width) noexcept
Definition: si_netline.cpp:115
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:88
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:79
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662
UnsignedLength mWidth
Definition: si_netline.h:122