LibrePCB Developers Documentation
Loading...
Searching...
No Matches
trace.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_TRACE_H
21#define LIBREPCB_CORE_TRACE_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
36class Layer;
37
38/*******************************************************************************
39 * Class TraceAnchor
40 ******************************************************************************/
41
45class TraceAnchor final {
46 Q_DECLARE_TR_FUNCTIONS(TraceAnchor)
47
48public:
49 // Types
50 struct PadAnchor {
53
54 bool operator==(const PadAnchor& rhs) const noexcept {
55 return (device == rhs.device) && (pad == rhs.pad);
56 }
57 };
58
59 // Constructors / Destructor
60 TraceAnchor() = delete;
61 TraceAnchor(const TraceAnchor& other) noexcept;
62 explicit TraceAnchor(const SExpression& node);
63 ~TraceAnchor() noexcept;
64
65 // Getters
66 const std::optional<Uuid>& tryGetJunction() const noexcept {
67 return mJunction;
68 }
69 const std::optional<Uuid>& tryGetVia() const noexcept { return mVia; }
70 const std::optional<Uuid>& tryGetPad() const noexcept { return mPad; }
71 const std::optional<PadAnchor>& tryGetFootprintPad() const noexcept {
72 return mFootprintPad;
73 }
74
75 // General Methods
76
82 void serialize(SExpression& root) const;
83
84 // Operator Overloadings
85 bool operator==(const TraceAnchor& rhs) const noexcept;
86 bool operator!=(const TraceAnchor& rhs) const noexcept {
87 return !(*this == rhs);
88 }
89 bool operator<(const TraceAnchor& rhs) const noexcept;
90 TraceAnchor& operator=(const TraceAnchor& rhs) noexcept;
91
92 // Static Methods
93 static TraceAnchor junction(const Uuid& junction) noexcept;
94 static TraceAnchor via(const Uuid& via) noexcept;
95 static TraceAnchor pad(const Uuid& pad) noexcept;
96 static TraceAnchor footprintPad(const Uuid& device, const Uuid& pad) noexcept;
97
98private: // Methods
99 TraceAnchor(const std::optional<Uuid>& junction,
100 const std::optional<Uuid>& via, const std::optional<Uuid>& pad,
101 const std::optional<PadAnchor>& footprintPad) noexcept;
102
103private: // Data
104 std::optional<Uuid> mJunction;
105 std::optional<Uuid> mVia;
106 std::optional<Uuid> mPad;
107 std::optional<PadAnchor> mFootprintPad;
108};
109
110/*******************************************************************************
111 * Class Trace
112 ******************************************************************************/
113
123class Trace final {
124 Q_DECLARE_TR_FUNCTIONS(Trace)
125
126public:
127 // Signals
128 enum class Event {
133 };
136
137 // Constructors / Destructor
138 Trace() = delete;
139 Trace(const Trace& other) noexcept;
140 Trace(const Uuid& uuid, const Trace& other) noexcept;
141 Trace(const Uuid& uuid, const Layer& layer, const PositiveLength& width,
142 const TraceAnchor& a, const TraceAnchor& b) noexcept;
143 explicit Trace(const SExpression& node);
144 ~Trace() noexcept;
145
146 // Getters
147 const Uuid& getUuid() const noexcept { return mUuid; }
148 const Layer& getLayer() const noexcept { return *mLayer; }
149 const PositiveLength& getWidth() const noexcept { return mWidth; }
150 const TraceAnchor& getP1() const noexcept { return mP1; }
151 const TraceAnchor& getP2() const noexcept { return mP2; }
152
153 // Setters
154 bool setUuid(const Uuid& uuid) noexcept;
155 bool setLayer(const Layer& layer) noexcept;
156 bool setWidth(const PositiveLength& width) noexcept;
157 bool setAnchors(TraceAnchor a, TraceAnchor b) noexcept;
158
159 // General Methods
160
166 void serialize(SExpression& root) const;
167
168 // Operator Overloadings
169 bool operator==(const Trace& rhs) const noexcept;
170 bool operator!=(const Trace& rhs) const noexcept { return !(*this == rhs); }
171 Trace& operator=(const Trace& rhs) noexcept;
172
173private: // Methods
174 static void normalizeAnchors(TraceAnchor& start, TraceAnchor& end) noexcept;
175
176private: // Data
178 const Layer* mLayer;
182};
183
184/*******************************************************************************
185 * Class TraceList
186 ******************************************************************************/
187
189 static constexpr const char* tagname = "trace";
190};
193
194/*******************************************************************************
195 * Non-Member Functions
196 ******************************************************************************/
197
198inline std::size_t qHash(const TraceAnchor& key,
199 std::size_t seed = 0) noexcept {
200 QString s;
201 if (std::optional<Uuid> anchor = key.tryGetJunction()) {
202 s += anchor->toStr();
203 }
204 if (std::optional<Uuid> anchor = key.tryGetVia()) {
205 s += anchor->toStr();
206 }
207 if (std::optional<Uuid> anchor = key.tryGetPad()) {
208 s += anchor->toStr();
209 }
210 if (std::optional<TraceAnchor::PadAnchor> anchor = key.tryGetFootprintPad()) {
211 s += anchor->device.toStr();
212 s += anchor->pad.toStr();
213 }
214 Q_ASSERT(!s.isEmpty());
215
216 return ::qHash(s, seed);
217}
218
219/*******************************************************************************
220 * End of File
221 ******************************************************************************/
222
223} // namespace librepcb
224
225#endif
The Layer class provides all supported geometry layers.
Definition layer.h:42
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 TraceAnchor class.
Definition trace.h:45
const std::optional< Uuid > & tryGetVia() const noexcept
Definition trace.h:69
static TraceAnchor pad(const Uuid &pad) noexcept
Definition trace.cpp:135
~TraceAnchor() noexcept
Definition trace.cpp:67
bool operator!=(const TraceAnchor &rhs) const noexcept
Definition trace.h:86
bool operator==(const TraceAnchor &rhs) const noexcept
Definition trace.cpp:85
static TraceAnchor footprintPad(const Uuid &device, const Uuid &pad) noexcept
Definition trace.cpp:139
static TraceAnchor via(const Uuid &via) noexcept
Definition trace.cpp:131
std::optional< PadAnchor > mFootprintPad
Definition trace.h:107
std::optional< Uuid > mJunction
Definition trace.h:104
std::optional< Uuid > mPad
Definition trace.h:106
static TraceAnchor junction(const Uuid &junction) noexcept
Definition trace.cpp:127
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition trace.cpp:70
TraceAnchor & operator=(const TraceAnchor &rhs) noexcept
Definition trace.cpp:119
const std::optional< Uuid > & tryGetPad() const noexcept
Definition trace.h:70
const std::optional< Uuid > & tryGetJunction() const noexcept
Definition trace.h:66
bool operator<(const TraceAnchor &rhs) const noexcept
Definition trace.cpp:90
std::optional< Uuid > mVia
Definition trace.h:105
const std::optional< PadAnchor > & tryGetFootprintPad() const noexcept
Definition trace.h:71
The Trace class represents a trace within a board.
Definition trace.h:123
Signal< Trace, Event > onEdited
Definition trace.h:134
const PositiveLength & getWidth() const noexcept
Definition trace.h:149
static void normalizeAnchors(TraceAnchor &start, TraceAnchor &end) noexcept
Definition trace.cpp:272
const TraceAnchor & getP2() const noexcept
Definition trace.h:151
const TraceAnchor & getP1() const noexcept
Definition trace.h:150
Uuid mUuid
Definition trace.h:177
Event
Definition trace.h:128
~Trace() noexcept
Definition trace.cpp:183
bool operator!=(const Trace &rhs) const noexcept
Definition trace.h:170
const Layer & getLayer() const noexcept
Definition trace.h:148
bool operator==(const Trace &rhs) const noexcept
Definition trace.cpp:251
bool setAnchors(TraceAnchor a, TraceAnchor b) noexcept
Definition trace.cpp:220
bool setLayer(const Layer &layer) noexcept
Definition trace.cpp:200
Trace & operator=(const Trace &rhs) noexcept
Definition trace.cpp:260
TraceAnchor mP1
Definition trace.h:180
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition trace.cpp:236
Slot< Trace, Event > OnEditedSlot
Definition trace.h:135
const Uuid & getUuid() const noexcept
Definition trace.h:147
bool setWidth(const PositiveLength &width) noexcept
Definition trace.cpp:210
const Layer * mLayer
Definition trace.h:178
TraceAnchor mP2
Definition trace.h:181
bool setUuid(const Uuid &uuid) noexcept
Definition trace.cpp:190
PositiveLength mWidth
Definition trace.h:179
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, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
Definition uuid.h:186
Uuid device
Definition trace.h:51
bool operator==(const PadAnchor &rhs) const noexcept
Definition trace.h:54
Uuid pad
Definition trace.h:52
Definition trace.h:188
static constexpr const char * tagname
Definition trace.h:189