LibrePCB Developers Documentation
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 "../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
37class Layer;
38
39/*******************************************************************************
40 * Class TraceAnchor
41 ******************************************************************************/
42
46class TraceAnchor final {
47 Q_DECLARE_TR_FUNCTIONS(TraceAnchor)
48
49public:
50 // Types
51 struct PadAnchor {
54
55 bool operator==(const PadAnchor& rhs) const noexcept {
56 return (device == rhs.device) && (pad == rhs.pad);
57 }
58 };
59
60 // Constructors / Destructor
61 TraceAnchor() = delete;
62 TraceAnchor(const TraceAnchor& other) noexcept;
63 explicit TraceAnchor(const SExpression& node);
64 ~TraceAnchor() noexcept;
65
66 // Getters
67 const tl::optional<Uuid>& tryGetJunction() const noexcept {
68 return mJunction;
69 }
70 const tl::optional<Uuid>& tryGetVia() const noexcept { return mVia; }
71 const tl::optional<PadAnchor>& tryGetPad() const noexcept { return mPad; }
72
73 // General Methods
74
80 void serialize(SExpression& root) const;
81
82 // Operator Overloadings
83 bool operator==(const TraceAnchor& rhs) const noexcept;
84 bool operator!=(const TraceAnchor& rhs) const noexcept {
85 return !(*this == rhs);
86 }
87 TraceAnchor& operator=(const TraceAnchor& rhs) noexcept;
88
89 // Static Methods
90 static TraceAnchor junction(const Uuid& junction) noexcept;
91 static TraceAnchor via(const Uuid& via) noexcept;
92 static TraceAnchor pad(const Uuid& device, const Uuid& pad) noexcept;
93
94private: // Methods
95 TraceAnchor(const tl::optional<Uuid>& junction, const tl::optional<Uuid>& via,
96 const tl::optional<PadAnchor>& pad) noexcept;
97
98private: // Data
99 tl::optional<Uuid> mJunction;
100 tl::optional<Uuid> mVia;
101 tl::optional<PadAnchor> mPad;
102};
103
104/*******************************************************************************
105 * Class Trace
106 ******************************************************************************/
107
113class Trace final {
114 Q_DECLARE_TR_FUNCTIONS(Trace)
115
116public:
117 // Signals
118 enum class Event {
119 UuidChanged,
120 LayerChanged,
121 WidthChanged,
122 StartPointChanged,
123 EndPointChanged,
124 };
127
128 // Constructors / Destructor
129 Trace() = delete;
130 Trace(const Trace& other) noexcept;
131 Trace(const Uuid& uuid, const Trace& other) noexcept;
132 Trace(const Uuid& uuid, const Layer& layer, const PositiveLength& width,
133 const TraceAnchor& start, const TraceAnchor& end) noexcept;
134 explicit Trace(const SExpression& node);
135 ~Trace() noexcept;
136
137 // Getters
138 const Uuid& getUuid() const noexcept { return mUuid; }
139 const Layer& getLayer() const noexcept { return *mLayer; }
140 const PositiveLength& getWidth() const noexcept { return mWidth; }
141 const TraceAnchor& getStartPoint() const noexcept { return mStart; }
142 const TraceAnchor& getEndPoint() const noexcept { return mEnd; }
143
144 // Setters
145 bool setUuid(const Uuid& uuid) noexcept;
146 bool setLayer(const Layer& layer) noexcept;
147 bool setWidth(const PositiveLength& width) noexcept;
148 bool setStartPoint(const TraceAnchor& start) noexcept;
149 bool setEndPoint(const TraceAnchor& end) noexcept;
150
151 // General Methods
152
158 void serialize(SExpression& root) const;
159
160 // Operator Overloadings
161 bool operator==(const Trace& rhs) const noexcept;
162 bool operator!=(const Trace& rhs) const noexcept { return !(*this == rhs); }
163 Trace& operator=(const Trace& rhs) noexcept;
164
165private: // Data
167 const Layer* mLayer;
171};
172
173/*******************************************************************************
174 * Class TraceList
175 ******************************************************************************/
176
178 static constexpr const char* tagname = "trace";
179};
182
183/*******************************************************************************
184 * Non-Member Functions
185 ******************************************************************************/
186
188 QtCompat::Hash seed = 0) noexcept {
189 QString s;
190 if (tl::optional<Uuid> anchor = key.tryGetJunction()) {
191 s += anchor->toStr();
192 }
193 if (tl::optional<Uuid> anchor = key.tryGetVia()) {
194 s += anchor->toStr();
195 }
196 if (tl::optional<TraceAnchor::PadAnchor> anchor = key.tryGetPad()) {
197 s += anchor->device.toStr();
198 s += anchor->pad.toStr();
199 }
200 Q_ASSERT(!s.isEmpty());
201
202 return ::qHash(s, seed);
203}
204
205/*******************************************************************************
206 * End of File
207 ******************************************************************************/
208
209} // namespace librepcb
210
211#endif
The Layer class provides all supported geometry layers.
Definition: layer.h:40
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 TraceAnchor class.
Definition: trace.h:46
const tl::optional< Uuid > & tryGetJunction() const noexcept
Definition: trace.h:67
tl::optional< PadAnchor > mPad
Definition: trace.h:101
~TraceAnchor() noexcept
Definition: trace.cpp:60
bool operator!=(const TraceAnchor &rhs) const noexcept
Definition: trace.h:84
bool operator==(const TraceAnchor &rhs) const noexcept
Definition: trace.cpp:76
const tl::optional< PadAnchor > & tryGetPad() const noexcept
Definition: trace.h:71
static TraceAnchor pad(const Uuid &device, const Uuid &pad) noexcept
Definition: trace.cpp:96
tl::optional< Uuid > mVia
Definition: trace.h:100
static TraceAnchor via(const Uuid &via) noexcept
Definition: trace.cpp:92
static TraceAnchor junction(const Uuid &junction) noexcept
Definition: trace.cpp:88
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: trace.cpp:63
TraceAnchor & operator=(const TraceAnchor &rhs) noexcept
Definition: trace.cpp:81
const tl::optional< Uuid > & tryGetVia() const noexcept
Definition: trace.h:70
tl::optional< Uuid > mJunction
Definition: trace.h:99
The Trace class represents a trace within a board.
Definition: trace.h:113
Signal< Trace, Event > onEdited
Definition: trace.h:125
const TraceAnchor & getStartPoint() const noexcept
Definition: trace.h:141
const PositiveLength & getWidth() const noexcept
Definition: trace.h:140
bool setEndPoint(const TraceAnchor &end) noexcept
Definition: trace.cpp:183
Uuid mUuid
Definition: trace.h:166
Event
Definition: trace.h:118
~Trace() noexcept
Definition: trace.cpp:136
bool operator!=(const Trace &rhs) const noexcept
Definition: trace.h:162
const Layer & getLayer() const noexcept
Definition: trace.h:139
bool operator==(const Trace &rhs) const noexcept
Definition: trace.cpp:212
const TraceAnchor & getEndPoint() const noexcept
Definition: trace.h:142
bool setLayer(const Layer &layer) noexcept
Definition: trace.cpp:153
Trace & operator=(const Trace &rhs) noexcept
Definition: trace.cpp:221
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: trace.cpp:197
Slot< Trace, Event > OnEditedSlot
Definition: trace.h:126
const Uuid & getUuid() const noexcept
Definition: trace.h:138
bool setWidth(const PositiveLength &width) noexcept
Definition: trace.cpp:163
const Layer * mLayer
Definition: trace.h:167
TraceAnchor mStart
Definition: trace.h:169
bool setUuid(const Uuid &uuid) noexcept
Definition: trace.cpp:143
PositiveLength mWidth
Definition: trace.h:168
bool setStartPoint(const TraceAnchor &start) noexcept
Definition: trace.cpp:173
TraceAnchor mEnd
Definition: trace.h:170
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
QtCompat::Hash qHash(const TraceAnchor &key, QtCompat::Hash seed=0) noexcept
Definition: trace.h:187
Definition: uuid.h:183
Definition: trace.h:51
Uuid device
Definition: trace.h:52
bool operator==(const PadAnchor &rhs) const noexcept
Definition: trace.h:55
Uuid pad
Definition: trace.h:53
Definition: trace.h:177
static constexpr const char * tagname
Definition: trace.h:178