LibrePCB Developers Documentation
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_CORE_NETLINE_H
21#define LIBREPCB_CORE_NETLINE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../qtcompat.h"
27#include "../serialization/serializableobjectlist.h"
28#include "../types/length.h"
29
30#include <QtCore>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37/*******************************************************************************
38 * Class NetLineAnchor
39 ******************************************************************************/
40
44class NetLineAnchor final {
45 Q_DECLARE_TR_FUNCTIONS(NetLineAnchor)
46
47public:
48 // Types
49 struct PinAnchor {
52
53 bool operator==(const PinAnchor& rhs) const noexcept {
54 return (symbol == rhs.symbol) && (pin == rhs.pin);
55 }
56 };
57
58 // Constructors / Destructor
59 NetLineAnchor() = delete;
60 NetLineAnchor(const NetLineAnchor& other) noexcept;
61 explicit NetLineAnchor(const SExpression& node);
62 ~NetLineAnchor() noexcept;
63
64 // Getters
65 const tl::optional<Uuid>& tryGetJunction() const noexcept {
66 return mJunction;
67 }
68 const tl::optional<PinAnchor>& tryGetPin() const noexcept { return mPin; }
69
70 // General Methods
71
77 void serialize(SExpression& root) const;
78
79 // Operator Overloadings
80 bool operator==(const NetLineAnchor& rhs) const noexcept;
81 bool operator!=(const NetLineAnchor& rhs) const noexcept {
82 return !(*this == rhs);
83 }
84 NetLineAnchor& operator=(const NetLineAnchor& rhs) noexcept;
85
86 // Static Methods
87 static NetLineAnchor junction(const Uuid& junction) noexcept;
88 static NetLineAnchor pin(const Uuid& symbol, const Uuid& pin) noexcept;
89
90private: // Methods
91 NetLineAnchor(const tl::optional<Uuid>& junction,
92 const tl::optional<PinAnchor>& pin) noexcept;
93
94private: // Data
95 tl::optional<Uuid> mJunction;
96 tl::optional<PinAnchor> mPin;
97};
98
99/*******************************************************************************
100 * Class NetLine
101 ******************************************************************************/
102
109class NetLine final {
110 Q_DECLARE_TR_FUNCTIONS(NetLine)
111
112public:
113 // Signals
114 enum class Event {
115 UuidChanged,
116 WidthChanged,
117 StartPointChanged,
118 EndPointChanged,
119 };
122
123 // Constructors / Destructor
124 NetLine() = delete;
125 NetLine(const NetLine& other) noexcept;
126 NetLine(const Uuid& uuid, const NetLine& other) noexcept;
127 NetLine(const Uuid& uuid, const UnsignedLength& width,
128 const NetLineAnchor& start, const NetLineAnchor& end) noexcept;
129 explicit NetLine(const SExpression& node);
130 ~NetLine() noexcept;
131
132 // Getters
133 const Uuid& getUuid() const noexcept { return mUuid; }
134 const UnsignedLength& getWidth() const noexcept { return mWidth; }
135 const NetLineAnchor& getStartPoint() const noexcept { return mStart; }
136 const NetLineAnchor& getEndPoint() const noexcept { return mEnd; }
137
138 // Setters
139 bool setUuid(const Uuid& uuid) noexcept;
140 bool setWidth(const UnsignedLength& width) noexcept;
141 bool setStartPoint(const NetLineAnchor& start) noexcept;
142 bool setEndPoint(const NetLineAnchor& end) noexcept;
143
144 // General Methods
145
151 void serialize(SExpression& root) const;
152
153 // Operator Overloadings
154 bool operator==(const NetLine& rhs) const noexcept;
155 bool operator!=(const NetLine& rhs) const noexcept { return !(*this == rhs); }
156 NetLine& operator=(const NetLine& rhs) noexcept;
157
158private: // Data
163};
164
165/*******************************************************************************
166 * Class NetLineList
167 ******************************************************************************/
168
170 static constexpr const char* tagname = "line";
171};
174
175/*******************************************************************************
176 * Non-Member Functions
177 ******************************************************************************/
178
180 QtCompat::Hash seed = 0) noexcept {
181 QString s;
182 if (tl::optional<Uuid> anchor = key.tryGetJunction()) {
183 s += anchor->toStr();
184 }
185 if (tl::optional<NetLineAnchor::PinAnchor> anchor = key.tryGetPin()) {
186 s += anchor->symbol.toStr();
187 s += anchor->pin.toStr();
188 }
189 Q_ASSERT(!s.isEmpty());
190
191 return ::qHash(s, seed);
192}
193
194/*******************************************************************************
195 * End of File
196 ******************************************************************************/
197
198} // namespace librepcb
199
200#endif
The NetLineAnchor class.
Definition: netline.h:44
const tl::optional< PinAnchor > & tryGetPin() const noexcept
Definition: netline.h:68
const tl::optional< Uuid > & tryGetJunction() const noexcept
Definition: netline.h:65
bool operator!=(const NetLineAnchor &rhs) const noexcept
Definition: netline.h:81
NetLineAnchor & operator=(const NetLineAnchor &rhs) noexcept
Definition: netline.cpp:73
static NetLineAnchor pin(const Uuid &symbol, const Uuid &pin) noexcept
Definition: netline.cpp:83
~NetLineAnchor() noexcept
Definition: netline.cpp:55
tl::optional< PinAnchor > mPin
Definition: netline.h:96
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: netline.cpp:58
bool operator==(const NetLineAnchor &rhs) const noexcept
Definition: netline.cpp:69
tl::optional< Uuid > mJunction
Definition: netline.h:95
static NetLineAnchor junction(const Uuid &junction) noexcept
Definition: netline.cpp:79
The NetLine class represents a net line within a schematic.
Definition: netline.h:109
~NetLine() noexcept
Definition: netline.cpp:117
const NetLineAnchor & getEndPoint() const noexcept
Definition: netline.h:136
Signal< NetLine, Event > onEdited
Definition: netline.h:120
bool operator==(const NetLine &rhs) const noexcept
Definition: netline.cpp:182
bool setWidth(const UnsignedLength &width) noexcept
Definition: netline.cpp:134
Uuid mUuid
Definition: netline.h:159
bool operator!=(const NetLine &rhs) const noexcept
Definition: netline.h:155
Event
Definition: netline.h:114
NetLine & operator=(const NetLine &rhs) noexcept
Definition: netline.cpp:190
bool setEndPoint(const NetLineAnchor &end) noexcept
Definition: netline.cpp:154
UnsignedLength mWidth
Definition: netline.h:160
const UnsignedLength & getWidth() const noexcept
Definition: netline.h:134
NetLineAnchor mStart
Definition: netline.h:161
Slot< NetLine, Event > OnEditedSlot
Definition: netline.h:121
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: netline.cpp:168
const Uuid & getUuid() const noexcept
Definition: netline.h:133
bool setStartPoint(const NetLineAnchor &start) noexcept
Definition: netline.cpp:144
const NetLineAnchor & getStartPoint() const noexcept
Definition: netline.h:135
bool setUuid(const Uuid &uuid) noexcept
Definition: netline.cpp:124
NetLineAnchor mEnd
Definition: netline.h:162
uint Hash
Return type of Qt's qHash() function.
Definition: qtcompat.h:58
The SExpression class.
Definition: sexpression.h:69
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:170
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
QtCompat::Hash qHash(const NetLineAnchor &key, QtCompat::Hash seed=0) noexcept
Definition: netline.h:179
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
Definition: uuid.h:183
Definition: netline.h:49
Uuid pin
Definition: netline.h:51
Uuid symbol
Definition: netline.h:50
bool operator==(const PinAnchor &rhs) const noexcept
Definition: netline.h:53
Definition: netline.h:169
static constexpr const char * tagname
Definition: netline.h:170