LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 "../serialization/serializableobjectlist.h"
27#include "../types/length.h"
28
29#include <QtCore>
30
31/*******************************************************************************
32 * Namespace / Forward Declarations
33 ******************************************************************************/
34namespace librepcb {
35
36/*******************************************************************************
37 * Class NetLineAnchor
38 ******************************************************************************/
39
43class NetLineAnchor final {
44 Q_DECLARE_TR_FUNCTIONS(NetLineAnchor)
45
46public:
47 // Types
48 struct BusAnchor {
51
52 bool operator==(const BusAnchor& rhs) const noexcept {
53 return (segment == rhs.segment) && (junction == rhs.junction);
54 }
55 };
56 struct PinAnchor {
59
60 bool operator==(const PinAnchor& rhs) const noexcept {
61 return (symbol == rhs.symbol) && (pin == rhs.pin);
62 }
63 };
64
65 // Constructors / Destructor
66 NetLineAnchor() = delete;
67 NetLineAnchor(const NetLineAnchor& other) noexcept;
68 explicit NetLineAnchor(const SExpression& node);
69 ~NetLineAnchor() noexcept;
70
71 // Getters
72 const std::optional<Uuid>& tryGetJunction() const noexcept {
73 return mJunction;
74 }
75 const std::optional<BusAnchor>& tryGetBusJunction() const noexcept {
76 return mBusJunction;
77 }
78 const std::optional<PinAnchor>& tryGetPin() const noexcept { return mPin; }
79
80 // General Methods
81
87 void serialize(SExpression& root) const;
88
89 // Operator Overloadings
90 bool operator==(const NetLineAnchor& rhs) const noexcept;
91 bool operator!=(const NetLineAnchor& rhs) const noexcept {
92 return !(*this == rhs);
93 }
94 bool operator<(const NetLineAnchor& rhs) const noexcept;
95 NetLineAnchor& operator=(const NetLineAnchor& rhs) noexcept;
96
97 // Static Methods
98 static NetLineAnchor junction(const Uuid& junction) noexcept;
99 static NetLineAnchor busJunction(const Uuid& segment,
100 const Uuid& junction) noexcept;
101 static NetLineAnchor pin(const Uuid& symbol, const Uuid& pin) noexcept;
102
103private: // Methods
104 NetLineAnchor(const std::optional<Uuid>& junction,
105 const std::optional<BusAnchor> bus,
106 const std::optional<PinAnchor>& pin) noexcept;
107
108private: // Data
109 std::optional<Uuid> mJunction;
110 std::optional<BusAnchor> mBusJunction;
111 std::optional<PinAnchor> mPin;
112};
113
114/*******************************************************************************
115 * Class NetLine
116 ******************************************************************************/
117
128class NetLine final {
129 Q_DECLARE_TR_FUNCTIONS(NetLine)
130
131public:
132 // Signals
133 enum class Event {
137 };
140
141 // Constructors / Destructor
142 NetLine() = delete;
143 NetLine(const NetLine& other) noexcept;
144 NetLine(const Uuid& uuid, const NetLine& other) noexcept;
145 NetLine(const Uuid& uuid, const UnsignedLength& width, const NetLineAnchor& a,
146 const NetLineAnchor& b) noexcept;
147 explicit NetLine(const SExpression& node);
148 ~NetLine() noexcept;
149
150 // Getters
151 const Uuid& getUuid() const noexcept { return mUuid; }
152 const UnsignedLength& getWidth() const noexcept { return mWidth; }
153 const NetLineAnchor& getP1() const noexcept { return mP1; }
154 const NetLineAnchor& getP2() const noexcept { return mP2; }
155
156 // Setters
157 bool setUuid(const Uuid& uuid) noexcept;
158 bool setWidth(const UnsignedLength& width) noexcept;
159 bool setAnchors(NetLineAnchor a, NetLineAnchor b) noexcept;
160
161 // General Methods
162
168 void serialize(SExpression& root) const;
169
170 // Operator Overloadings
171 bool operator==(const NetLine& rhs) const noexcept;
172 bool operator!=(const NetLine& rhs) const noexcept { return !(*this == rhs); }
173 NetLine& operator=(const NetLine& rhs) noexcept;
174
175private: // Methods
176 static void normalizeAnchors(NetLineAnchor& start,
177 NetLineAnchor& end) noexcept;
178
179private: // Data
184};
185
186/*******************************************************************************
187 * Class NetLineList
188 ******************************************************************************/
189
191 static constexpr const char* tagname = "line";
192};
195
196/*******************************************************************************
197 * Non-Member Functions
198 ******************************************************************************/
199
200inline std::size_t qHash(const NetLineAnchor& key,
201 std::size_t seed = 0) noexcept {
202 QString s;
203 if (std::optional<Uuid> anchor = key.tryGetJunction()) {
204 s += anchor->toStr();
205 }
206 if (std::optional<NetLineAnchor::BusAnchor> anchor =
207 key.tryGetBusJunction()) {
208 s += anchor->segment.toStr();
209 s += anchor->junction.toStr();
210 }
211 if (std::optional<NetLineAnchor::PinAnchor> anchor = key.tryGetPin()) {
212 s += anchor->symbol.toStr();
213 s += anchor->pin.toStr();
214 }
215 Q_ASSERT(!s.isEmpty());
216
217 return ::qHash(s, seed);
218}
219
220/*******************************************************************************
221 * End of File
222 ******************************************************************************/
223
224} // namespace librepcb
225
226#endif
The NetLineAnchor class.
Definition netline.h:43
static NetLineAnchor busJunction(const Uuid &segment, const Uuid &junction) noexcept
Definition netline.cpp:126
bool operator!=(const NetLineAnchor &rhs) const noexcept
Definition netline.h:91
NetLineAnchor & operator=(const NetLineAnchor &rhs) noexcept
Definition netline.cpp:115
static NetLineAnchor pin(const Uuid &symbol, const Uuid &pin) noexcept
Definition netline.cpp:132
~NetLineAnchor() noexcept
Definition netline.cpp:64
bool operator<(const NetLineAnchor &rhs) const noexcept
Definition netline.cpp:86
std::optional< Uuid > mJunction
Definition netline.h:109
const std::optional< PinAnchor > & tryGetPin() const noexcept
Definition netline.h:78
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition netline.cpp:67
bool operator==(const NetLineAnchor &rhs) const noexcept
Definition netline.cpp:81
std::optional< PinAnchor > mPin
Definition netline.h:111
const std::optional< Uuid > & tryGetJunction() const noexcept
Definition netline.h:72
static NetLineAnchor junction(const Uuid &junction) noexcept
Definition netline.cpp:122
const std::optional< BusAnchor > & tryGetBusJunction() const noexcept
Definition netline.h:75
std::optional< BusAnchor > mBusJunction
Definition netline.h:110
The NetLine class represents a net line within a schematic.
Definition netline.h:128
~NetLine() noexcept
Definition netline.cpp:168
Signal< NetLine, Event > onEdited
Definition netline.h:138
bool operator==(const NetLine &rhs) const noexcept
Definition netline.cpp:225
bool setWidth(const UnsignedLength &width) noexcept
Definition netline.cpp:185
const NetLineAnchor & getP1() const noexcept
Definition netline.h:153
Uuid mUuid
Definition netline.h:180
bool operator!=(const NetLine &rhs) const noexcept
Definition netline.h:172
Event
Definition netline.h:133
bool setAnchors(NetLineAnchor a, NetLineAnchor b) noexcept
Definition netline.cpp:195
NetLine & operator=(const NetLine &rhs) noexcept
Definition netline.cpp:233
UnsignedLength mWidth
Definition netline.h:181
const UnsignedLength & getWidth() const noexcept
Definition netline.h:152
Slot< NetLine, Event > OnEditedSlot
Definition netline.h:139
static void normalizeAnchors(NetLineAnchor &start, NetLineAnchor &end) noexcept
Definition netline.cpp:244
const NetLineAnchor & getP2() const noexcept
Definition netline.h:154
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition netline.cpp:211
const Uuid & getUuid() const noexcept
Definition netline.h:151
NetLineAnchor mP2
Definition netline.h:183
bool setUuid(const Uuid &uuid) noexcept
Definition netline.cpp:175
NetLineAnchor mP1
Definition netline.h:182
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:56
Definition occmodel.cpp:77
std::size_t qHash(const AttributeKey &key, std::size_t seed=0) noexcept
Definition attributekey.h:113
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
Definition uuid.h:186
Definition netline.h:48
Uuid junction
Definition netline.h:50
bool operator==(const BusAnchor &rhs) const noexcept
Definition netline.h:52
Uuid segment
Definition netline.h:49
Definition netline.h:56
Uuid pin
Definition netline.h:58
Uuid symbol
Definition netline.h:57
bool operator==(const PinAnchor &rhs) const noexcept
Definition netline.h:60
Definition netline.h:190
static constexpr const char * tagname
Definition netline.h:191