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 PinAnchor {
51
52 bool operator==(const PinAnchor& rhs) const noexcept {
53 return (symbol == rhs.symbol) && (pin == rhs.pin);
54 }
55 };
56
57 // Constructors / Destructor
58 NetLineAnchor() = delete;
59 NetLineAnchor(const NetLineAnchor& other) noexcept;
60 explicit NetLineAnchor(const SExpression& node);
61 ~NetLineAnchor() noexcept;
62
63 // Getters
64 const std::optional<Uuid>& tryGetJunction() const noexcept {
65 return mJunction;
66 }
67 const std::optional<PinAnchor>& tryGetPin() const noexcept { return mPin; }
68
69 // General Methods
70
76 void serialize(SExpression& root) const;
77
78 // Operator Overloadings
79 bool operator==(const NetLineAnchor& rhs) const noexcept;
80 bool operator!=(const NetLineAnchor& rhs) const noexcept {
81 return !(*this == rhs);
82 }
83 NetLineAnchor& operator=(const NetLineAnchor& rhs) noexcept;
84
85 // Static Methods
86 static NetLineAnchor junction(const Uuid& junction) noexcept;
87 static NetLineAnchor pin(const Uuid& symbol, const Uuid& pin) noexcept;
88
89private: // Methods
90 NetLineAnchor(const std::optional<Uuid>& junction,
91 const std::optional<PinAnchor>& pin) noexcept;
92
93private: // Data
94 std::optional<Uuid> mJunction;
95 std::optional<PinAnchor> mPin;
96};
97
98/*******************************************************************************
99 * Class NetLine
100 ******************************************************************************/
101
108class NetLine final {
109 Q_DECLARE_TR_FUNCTIONS(NetLine)
110
111public:
112 // Signals
113 enum class Event {
118 };
121
122 // Constructors / Destructor
123 NetLine() = delete;
124 NetLine(const NetLine& other) noexcept;
125 NetLine(const Uuid& uuid, const NetLine& other) noexcept;
126 NetLine(const Uuid& uuid, const UnsignedLength& width,
127 const NetLineAnchor& start, const NetLineAnchor& end) noexcept;
128 explicit NetLine(const SExpression& node);
129 ~NetLine() noexcept;
130
131 // Getters
132 const Uuid& getUuid() const noexcept { return mUuid; }
133 const UnsignedLength& getWidth() const noexcept { return mWidth; }
134 const NetLineAnchor& getStartPoint() const noexcept { return mStart; }
135 const NetLineAnchor& getEndPoint() const noexcept { return mEnd; }
136
137 // Setters
138 bool setUuid(const Uuid& uuid) noexcept;
139 bool setWidth(const UnsignedLength& width) noexcept;
140 bool setStartPoint(const NetLineAnchor& start) noexcept;
141 bool setEndPoint(const NetLineAnchor& end) noexcept;
142
143 // General Methods
144
150 void serialize(SExpression& root) const;
151
152 // Operator Overloadings
153 bool operator==(const NetLine& rhs) const noexcept;
154 bool operator!=(const NetLine& rhs) const noexcept { return !(*this == rhs); }
155 NetLine& operator=(const NetLine& rhs) noexcept;
156
157private: // Data
162};
163
164/*******************************************************************************
165 * Class NetLineList
166 ******************************************************************************/
167
169 static constexpr const char* tagname = "line";
170};
173
174/*******************************************************************************
175 * Non-Member Functions
176 ******************************************************************************/
177
178inline std::size_t qHash(const NetLineAnchor& key,
179 std::size_t seed = 0) noexcept {
180 QString s;
181 if (std::optional<Uuid> anchor = key.tryGetJunction()) {
182 s += anchor->toStr();
183 }
184 if (std::optional<NetLineAnchor::PinAnchor> anchor = key.tryGetPin()) {
185 s += anchor->symbol.toStr();
186 s += anchor->pin.toStr();
187 }
188 Q_ASSERT(!s.isEmpty());
189
190 return ::qHash(s, seed);
191}
192
193/*******************************************************************************
194 * End of File
195 ******************************************************************************/
196
197} // namespace librepcb
198
199#endif
The NetLineAnchor class.
Definition netline.h:43
bool operator!=(const NetLineAnchor &rhs) const noexcept
Definition netline.h:80
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
std::optional< Uuid > mJunction
Definition netline.h:94
const std::optional< PinAnchor > & tryGetPin() const noexcept
Definition netline.h:67
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
std::optional< PinAnchor > mPin
Definition netline.h:95
const std::optional< Uuid > & tryGetJunction() const noexcept
Definition netline.h:64
static NetLineAnchor junction(const Uuid &junction) noexcept
Definition netline.cpp:79
The NetLine class represents a net line within a schematic.
Definition netline.h:108
~NetLine() noexcept
Definition netline.cpp:117
const NetLineAnchor & getEndPoint() const noexcept
Definition netline.h:135
Signal< NetLine, Event > onEdited
Definition netline.h:119
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:158
bool operator!=(const NetLine &rhs) const noexcept
Definition netline.h:154
Event
Definition netline.h:113
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:159
const UnsignedLength & getWidth() const noexcept
Definition netline.h:133
NetLineAnchor mStart
Definition netline.h:160
Slot< NetLine, Event > OnEditedSlot
Definition netline.h:120
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition netline.cpp:168
const Uuid & getUuid() const noexcept
Definition netline.h:132
bool setStartPoint(const NetLineAnchor &start) noexcept
Definition netline.cpp:144
const NetLineAnchor & getStartPoint() const noexcept
Definition netline.h:134
bool setUuid(const Uuid &uuid) noexcept
Definition netline.cpp:124
NetLineAnchor mEnd
Definition netline.h:161
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:76
std::size_t qHash(const AttributeKey &key, std::size_t seed=0) noexcept
Definition attributekey.h:118
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
Definition uuid.h:186
Definition netline.h:48
Uuid pin
Definition netline.h:50
Uuid symbol
Definition netline.h:49
bool operator==(const PinAnchor &rhs) const noexcept
Definition netline.h:52
Definition netline.h:168
static constexpr const char * tagname
Definition netline.h:169