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_TRACE_H
21 #define LIBREPCB_TRACE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/cmd/cmdlistelementinsert.h"
27 #include "../fileio/cmd/cmdlistelementremove.h"
28 #include "../fileio/cmd/cmdlistelementsswap.h"
29 #include "../fileio/serializableobjectlist.h"
30 #include "../graphics/graphicslayername.h"
31 #include "../units/all_length_units.h"
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 /*******************************************************************************
41  * Class TraceAnchor
42  ******************************************************************************/
43 
47 class TraceAnchor final : public SerializableObject {
48  Q_DECLARE_TR_FUNCTIONS(TraceAnchor)
49 
50 public:
51  // Types
52  struct PadAnchor {
55 
56  bool operator==(const PadAnchor& rhs) const noexcept {
57  return (device == rhs.device) && (pad == rhs.pad);
58  }
59  };
60 
61  // Constructors / Destructor
62  TraceAnchor() = delete;
63  TraceAnchor(const TraceAnchor& other) noexcept;
64  TraceAnchor(const SExpression& node, const Version& fileFormat);
65  ~TraceAnchor() noexcept;
66 
67  // Getters
68  const tl::optional<Uuid>& tryGetJunction() const noexcept {
69  return mJunction;
70  }
71  const tl::optional<Uuid>& tryGetVia() const noexcept { return mVia; }
72  const tl::optional<PadAnchor>& tryGetPad() const noexcept { return mPad; }
73 
75  void serialize(SExpression& root) const override;
76 
77  // Operator Overloadings
78  bool operator==(const TraceAnchor& rhs) const noexcept;
79  bool operator!=(const TraceAnchor& rhs) const noexcept {
80  return !(*this == rhs);
81  }
82  TraceAnchor& operator=(const TraceAnchor& rhs) noexcept;
83 
84  // Static Methods
85  static TraceAnchor junction(const Uuid& junction) noexcept;
86  static TraceAnchor via(const Uuid& via) noexcept;
87  static TraceAnchor pad(const Uuid& device, const Uuid& pad) noexcept;
88 
89 private: // Methods
90  TraceAnchor(const tl::optional<Uuid>& junction, const tl::optional<Uuid>& via,
91  const tl::optional<PadAnchor>& pad) noexcept;
92 
93 private: // Data
94  tl::optional<Uuid> mJunction;
95  tl::optional<Uuid> mVia;
96  tl::optional<PadAnchor> mPad;
97 };
98 
99 /*******************************************************************************
100  * Class Trace
101  ******************************************************************************/
102 
108 class Trace final : public SerializableObject {
109  Q_DECLARE_TR_FUNCTIONS(Trace)
110 
111 public:
112  // Signals
113  enum class Event {
114  UuidChanged,
115  LayerChanged,
116  WidthChanged,
117  StartPointChanged,
118  EndPointChanged,
119  };
122 
123  // Constructors / Destructor
124  Trace() = delete;
125  Trace(const Trace& other) noexcept;
126  Trace(const Uuid& uuid, const Trace& other) noexcept;
127  Trace(const Uuid& uuid, const GraphicsLayerName& layer,
128  const PositiveLength& width, const TraceAnchor& start,
129  const TraceAnchor& end) noexcept;
130  Trace(const SExpression& node, const Version& fileFormat);
131  ~Trace() noexcept;
132 
133  // Getters
134  const Uuid& getUuid() const noexcept { return mUuid; }
135  const GraphicsLayerName& getLayer() const noexcept { return mLayer; }
136  const PositiveLength& getWidth() const noexcept { return mWidth; }
137  const TraceAnchor& getStartPoint() const noexcept { return mStart; }
138  const TraceAnchor& getEndPoint() const noexcept { return mEnd; }
139 
140  // Setters
141  bool setUuid(const Uuid& uuid) noexcept;
142  bool setLayer(const GraphicsLayerName& layer) noexcept;
143  bool setWidth(const PositiveLength& width) noexcept;
144  bool setStartPoint(const TraceAnchor& start) noexcept;
145  bool setEndPoint(const TraceAnchor& end) noexcept;
146 
148  void serialize(SExpression& root) const override;
149 
150  // Operator Overloadings
151  bool operator==(const Trace& rhs) const noexcept;
152  bool operator!=(const Trace& rhs) const noexcept { return !(*this == rhs); }
153  Trace& operator=(const Trace& rhs) noexcept;
154 
155 private: // Data
161 };
162 
163 /*******************************************************************************
164  * Class TraceList
165  ******************************************************************************/
166 
168  static constexpr const char* tagname = "trace";
169 };
170 using TraceList =
172 using CmdTraceInsert =
174 using CmdTraceRemove =
176 using CmdTracesSwap =
178 
179 /*******************************************************************************
180  * Non-Member Functions
181  ******************************************************************************/
182 
183 inline uint qHash(const TraceAnchor& key, uint seed) noexcept {
184  QString s;
185  if (tl::optional<Uuid> anchor = key.tryGetJunction()) {
186  s += anchor->toStr();
187  }
188  if (tl::optional<Uuid> anchor = key.tryGetVia()) {
189  s += anchor->toStr();
190  }
191  if (tl::optional<TraceAnchor::PadAnchor> anchor = key.tryGetPad()) {
192  s += anchor->device.toStr();
193  s += anchor->pad.toStr();
194  }
195  Q_ASSERT(!s.isEmpty());
196 
197  return ::qHash(s, seed);
198 }
199 
200 /*******************************************************************************
201  * End of File
202  ******************************************************************************/
203 
204 } // namespace librepcb
205 
206 #endif
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
tl::optional< Uuid > mVia
Definition: trace.h:95
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
bool operator==(const PadAnchor &rhs) const noexcept
Definition: trace.h:56
const GraphicsLayerName & getLayer() const noexcept
Definition: trace.h:135
const TraceAnchor & getStartPoint() const noexcept
Definition: trace.h:137
bool operator!=(const TraceAnchor &rhs) const noexcept
Definition: trace.h:79
const tl::optional< PadAnchor > & tryGetPad() const noexcept
Definition: trace.h:72
const tl::optional< Uuid > & tryGetJunction() const noexcept
Definition: trace.h:68
Definition: airwiresbuilder.cpp:32
The TraceAnchor class.
Definition: trace.h:47
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
const PositiveLength & getWidth() const noexcept
Definition: trace.h:136
uint qHash(const TraceAnchor &key, uint seed) noexcept
Definition: trace.h:183
TraceAnchor mStart
Definition: trace.h:159
Definition: trace.h:52
bool operator!=(const Trace &rhs) const noexcept
Definition: trace.h:152
Uuid device
Definition: trace.h:53
PositiveLength mWidth
Definition: trace.h:158
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
GraphicsLayerName mLayer
Definition: trace.h:157
Event
Definition: trace.h:113
const TraceAnchor & getEndPoint() const noexcept
Definition: trace.h:138
Uuid pad
Definition: trace.h:54
Slot< Trace, Event > OnEditedSlot
Definition: trace.h:121
The Trace class represents a trace within a board.
Definition: trace.h:108
Signal< Trace, Event > onEdited
Definition: trace.h:120
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:160
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:94
~TraceAnchor() noexcept
Definition: trace.cpp:60
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:792
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
const tl::optional< Uuid > & tryGetVia() const noexcept
Definition: trace.h:71
Definition: trace.h:167
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: trace.cpp:63
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
The SExpression class.
Definition: sexpression.h:72
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:120
Uuid mUuid
Definition: trace.h:156
tl::optional< PadAnchor > mPad
Definition: trace.h:96