LibrePCB Developers Documentation
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  ******************************************************************************/
34 namespace librepcb {
35 
36 /*******************************************************************************
37  * Class NetLineAnchor
38  ******************************************************************************/
39 
43 class NetLineAnchor final {
44  Q_DECLARE_TR_FUNCTIONS(NetLineAnchor)
45 
46 public:
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 tl::optional<Uuid>& tryGetJunction() const noexcept {
65  return mJunction;
66  }
67  const tl::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 
89 private: // Methods
90  NetLineAnchor(const tl::optional<Uuid>& junction,
91  const tl::optional<PinAnchor>& pin) noexcept;
92 
93 private: // Data
94  tl::optional<Uuid> mJunction;
95  tl::optional<PinAnchor> mPin;
96 };
97 
98 /*******************************************************************************
99  * Class NetLine
100  ******************************************************************************/
101 
108 class NetLine final {
109  Q_DECLARE_TR_FUNCTIONS(NetLine)
110 
111 public:
112  // Signals
113  enum class Event {
114  UuidChanged,
115  WidthChanged,
116  StartPointChanged,
117  EndPointChanged,
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 
157 private: // Data
162 };
163 
164 /*******************************************************************************
165  * Class NetLineList
166  ******************************************************************************/
167 
169  static constexpr const char* tagname = "line";
170 };
171 using NetLineList =
173 
174 /*******************************************************************************
175  * Non-Member Functions
176  ******************************************************************************/
177 
178 inline uint qHash(const NetLineAnchor& key, uint seed) noexcept {
179  QString s;
180  if (tl::optional<Uuid> anchor = key.tryGetJunction()) {
181  s += anchor->toStr();
182  }
183  if (tl::optional<NetLineAnchor::PinAnchor> anchor = key.tryGetPin()) {
184  s += anchor->symbol.toStr();
185  s += anchor->pin.toStr();
186  }
187  Q_ASSERT(!s.isEmpty());
188 
189  return ::qHash(s, seed);
190 }
191 
192 /*******************************************************************************
193  * End of File
194  ******************************************************************************/
195 
196 } // namespace librepcb
197 
198 #endif
Event
Definition: netline.h:113
NetLineAnchor mEnd
Definition: netline.h:161
~NetLineAnchor() noexcept
Definition: netline.cpp:55
NetLineAnchor mStart
Definition: netline.h:160
The NetLine class represents a net line within a schematic.
Definition: netline.h:108
bool operator!=(const NetLine &rhs) const noexcept
Definition: netline.h:154
tl::optional< Uuid > mJunction
Definition: netline.h:94
uint qHash(const NetLineAnchor &key, uint seed) noexcept
Definition: netline.h:178
Definition: occmodel.cpp:76
Definition: netline.h:168
Definition: netline.h:48
Slot< NetLine, Event > OnEditedSlot
Definition: netline.h:120
const tl::optional< PinAnchor > & tryGetPin() const noexcept
Definition: netline.h:67
const NetLineAnchor & getStartPoint() const noexcept
Definition: netline.h:134
tl::optional< PinAnchor > mPin
Definition: netline.h:95
static NetLineAnchor junction(const Uuid &junction) noexcept
Definition: netline.cpp:79
const NetLineAnchor & getEndPoint() const noexcept
Definition: netline.h:135
NetLineAnchor & operator=(const NetLineAnchor &rhs) noexcept
Definition: netline.cpp:73
bool operator!=(const NetLineAnchor &rhs) const noexcept
Definition: netline.h:80
Signal< NetLine, Event > onEdited
Definition: netline.h:119
UnsignedLength mWidth
Definition: netline.h:159
const UnsignedLength & getWidth() const noexcept
Definition: netline.h:133
Uuid symbol
Definition: netline.h:49
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
Uuid mUuid
Definition: netline.h:158
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: netline.cpp:58
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
The NetLineAnchor class.
Definition: netline.h:43
const tl::optional< Uuid > & tryGetJunction() const noexcept
Definition: netline.h:64
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
The SExpression class.
Definition: sexpression.h:66
Uuid pin
Definition: netline.h:50
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:118
bool operator==(const PinAnchor &rhs) const noexcept
Definition: netline.h:52
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:670