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