LibrePCB Developers Documentation
Loading...
Searching...
No Matches
boardclipboarddata.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_EDITOR_BOARDCLIPBOARDDATA_H
21#define LIBREPCB_EDITOR_BOARDCLIPBOARDDATA_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
40
41#include <QtCore>
42#include <QtWidgets>
43
44#include <memory>
45
46/*******************************************************************************
47 * Namespace / Forward Declarations
48 ******************************************************************************/
49namespace librepcb {
50
51class Layer;
52class TransactionalDirectory;
53class TransactionalFileSystem;
54
55namespace editor {
56
57/*******************************************************************************
58 * Class BoardClipboardData
59 ******************************************************************************/
60
64class BoardClipboardData final {
65public:
66 // Types
67 struct Device {
68 static constexpr const char* tagname = "device";
69
76 bool locked;
78 QList<BoardStrokeTextData> strokeTexts;
80
96
97 explicit Device(const SExpression& node)
98 : componentUuid(deserialize<Uuid>(node.getChild("@0"))),
99 libDeviceUuid(deserialize<Uuid>(node.getChild("lib_device/@0"))),
100 libFootprintUuid(deserialize<Uuid>(node.getChild("lib_footprint/@0"))),
101 position(node.getChild("position")),
102 rotation(deserialize<Angle>(node.getChild("rotation/@0"))),
103 mirrored(deserialize<bool>(node.getChild("flip/@0"))),
104 locked(deserialize<bool>(node.getChild("lock/@0"))),
105 attributes(node),
106 strokeTexts(),
107 onEdited(*this) {
108 foreach (const SExpression* child, node.getChildren("stroke_text")) {
110 }
111 }
112
113 void serialize(SExpression& root) const {
115 root.ensureLineBreak();
116 root.appendChild("lib_device", libDeviceUuid);
117 root.ensureLineBreak();
118 root.appendChild("lib_footprint", libFootprintUuid);
119 root.ensureLineBreak();
120 position.serialize(root.appendList("position"));
121 root.appendChild("rotation", rotation);
122 root.appendChild("flip", mirrored);
123 root.appendChild("lock", locked);
124 root.ensureLineBreak();
125 attributes.serialize(root);
126 foreach (const BoardStrokeTextData& strokeText, strokeTexts) {
127 root.ensureLineBreak();
128 strokeText.serialize(root.appendList("stroke_text"));
129 }
130 root.ensureLineBreak();
131 }
132
133 bool operator!=(const Device& rhs) noexcept {
134 return (componentUuid != rhs.componentUuid) ||
135 (libDeviceUuid != rhs.libDeviceUuid) ||
136 (libFootprintUuid != rhs.libFootprintUuid) ||
137 (position != rhs.position) || (rotation != rhs.rotation) ||
138 (mirrored != rhs.mirrored) || (locked != rhs.locked) ||
139 (attributes != rhs.attributes) || (strokeTexts != rhs.strokeTexts);
140 }
141 };
142
143 struct NetSegment {
144 static constexpr const char* tagname = "netsegment";
145
146 std::optional<CircuitIdentifier> netName;
151
152 explicit NetSegment(const std::optional<CircuitIdentifier>& netName)
153 : netName(netName), vias(), junctions(), traces(), onEdited(*this) {}
154
155 explicit NetSegment(const SExpression& node)
157 node.getChild("net/@0"))),
158 vias(node),
159 junctions(node),
160 traces(node),
161 onEdited(*this) {}
162
163 void serialize(SExpression& root) const {
164 root.ensureLineBreak();
165 root.appendChild("net", netName);
166 root.ensureLineBreak();
167 vias.serialize(root);
168 root.ensureLineBreak();
169 junctions.serialize(root);
170 root.ensureLineBreak();
171 traces.serialize(root);
172 root.ensureLineBreak();
173 }
174
175 bool operator!=(const NetSegment& rhs) noexcept {
176 return (netName != rhs.netName) || (vias != rhs.vias) ||
177 (junctions != rhs.junctions) || (traces != rhs.traces);
178 }
179 };
180
181 struct Plane {
182 static constexpr const char* tagname = "plane";
183
185 const Layer* layer;
186 std::optional<CircuitIdentifier> netSignalName;
195 bool locked;
197
217
218 explicit Plane(const SExpression& node)
219 : uuid(deserialize<Uuid>(node.getChild("@0"))),
220 layer(deserialize<const Layer*>(node.getChild("layer/@0"))),
222 node.getChild("net/@0"))),
223 outline(node),
224 minWidth(deserialize<UnsignedLength>(node.getChild("min_width/@0"))),
226 deserialize<UnsignedLength>(node.getChild("min_clearance/@0"))),
227 keepIslands(deserialize<bool>(node.getChild("keep_islands/@0"))),
228 priority(deserialize<int>(node.getChild("priority/@0"))),
229 connectStyle(deserialize<BI_Plane::ConnectStyle>(
230 node.getChild("connect_style/@0"))),
232 deserialize<PositiveLength>(node.getChild("thermal_gap/@0"))),
234 deserialize<PositiveLength>(node.getChild("thermal_spoke/@0"))),
235 locked(deserialize<bool>(node.getChild("lock/@0"))),
236 onEdited(*this) {}
237
238 void serialize(SExpression& root) const {
239 root.appendChild(uuid);
240 root.appendChild("layer", *layer);
241 root.ensureLineBreak();
242 root.appendChild("net", netSignalName);
243 root.appendChild("priority", priority);
244 root.ensureLineBreak();
245 root.appendChild("min_width", minWidth);
246 root.appendChild("min_clearance", minClearance);
247 root.appendChild("thermal_gap", thermalGap);
248 root.appendChild("thermal_spoke", thermalSpokeWidth);
249 root.ensureLineBreak();
250 root.appendChild("connect_style", connectStyle);
251 root.appendChild("keep_islands", keepIslands);
252 root.appendChild("lock", locked);
253 root.ensureLineBreak();
254 outline.serialize(root);
255 root.ensureLineBreak();
256 }
257
258 bool operator!=(const Plane& rhs) noexcept {
259 return (uuid != rhs.uuid) || (layer != rhs.layer) ||
260 (netSignalName != rhs.netSignalName) || (outline != rhs.outline) ||
261 (minWidth != rhs.minWidth) || (minClearance != rhs.minClearance) ||
262 (keepIslands != rhs.keepIslands) || (priority != rhs.priority) ||
263 (connectStyle != rhs.connectStyle) ||
264 (thermalGap != rhs.thermalGap) ||
265 (thermalSpokeWidth != rhs.thermalSpokeWidth) ||
266 (locked != rhs.locked);
267 }
268 };
269
270 // Constructors / Destructor
273 BoardClipboardData(const Uuid& boardUuid, const Point& cursorPos) noexcept;
274 explicit BoardClipboardData(const QByteArray& mimeData);
275 ~BoardClipboardData() noexcept;
276
277 // Getters
278 bool isEmpty() const noexcept;
280 const QString& path = "") noexcept;
281 const Uuid& getBoardUuid() const noexcept { return mBoardUuid; }
282 const Point& getCursorPos() const noexcept { return mCursorPos; }
290 QList<BoardZoneData>& getZones() noexcept { return mZones; }
291 QList<BoardPolygonData>& getPolygons() noexcept { return mPolygons; }
292 QList<BoardStrokeTextData>& getStrokeTexts() noexcept { return mStrokeTexts; }
293 QList<BoardHoleData>& getHoles() noexcept { return mHoles; }
294 QMap<std::pair<Uuid, Uuid>, Point>& getPadPositions() noexcept {
295 return mPadPositions;
296 }
297
298 // General Methods
299 std::unique_ptr<QMimeData> toMimeData() const;
300 static std::unique_ptr<BoardClipboardData> fromMimeData(
301 const QMimeData* mime);
302
303 // Operator Overloadings
305
306private: // Methods
307 static QString getMimeType() noexcept;
308
309private: // Data
321};
322
323/*******************************************************************************
324 * End of File
325 ******************************************************************************/
326
327} // namespace editor
328} // namespace librepcb
329
330#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
The BI_Plane class.
Definition bi_plane.h:52
ConnectStyle
Definition bi_plane.h:68
The BoardHoleData class.
Definition boardholedata.h:45
The BoardPolygonData class.
Definition boardpolygondata.h:45
The BoardStrokeTextData class.
Definition boardstroketextdata.h:49
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition boardstroketextdata.cpp:242
The BoardZoneData class.
Definition boardzonedata.h:44
The Layer class provides all supported geometry layers.
Definition layer.h:42
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition path.h:57
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition path.cpp:348
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition point.cpp:136
The SExpression class.
Definition sexpression.h:69
SExpression & appendList(const QString &name)
Definition sexpression.cpp:212
QList< SExpression * > getChildren(Type type) noexcept
Definition sexpression.cpp:94
void ensureLineBreak()
Definition sexpression.cpp:206
void appendChild(std::unique_ptr< SExpression > child)
Definition sexpression.cpp:217
int append(const std::shared_ptr< T > &obj) noexcept
Definition serializableobjectlist.h:342
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition serializableobjectlist.h:379
The Signal class is used to emit signals on non-QObject derived classes.
Definition signalslot.h:65
Helper class to access a subdirectory of TransactionalFileSystem.
Definition transactionaldirectory.h:51
Transactional librepcb::FileSystem implementation.
Definition transactionalfilesystem.h:71
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
The BoardClipboardData class.
Definition boardclipboarddata.h:64
QMap< std::pair< Uuid, Uuid >, Point > mPadPositions
Definition boardclipboarddata.h:320
Uuid mBoardUuid
Definition boardclipboarddata.h:311
static QString getMimeType() noexcept
Definition boardclipboarddata.cpp:193
std::unique_ptr< QMimeData > toMimeData() const
Definition boardclipboarddata.cpp:122
QMap< std::pair< Uuid, Uuid >, Point > & getPadPositions() noexcept
Definition boardclipboarddata.h:294
SerializableObjectList< Device, Device > & getDevices() noexcept
Definition boardclipboarddata.h:283
SerializableObjectList< NetSegment, NetSegment > & getNetSegments() noexcept
Definition boardclipboarddata.h:286
std::unique_ptr< TransactionalDirectory > getDirectory(const QString &path="") noexcept
Definition boardclipboarddata.cpp:112
BoardClipboardData & operator=(const BoardClipboardData &rhs)=delete
SerializableObjectList< Device, Device > mDevices
Definition boardclipboarddata.h:313
QList< BoardZoneData > & getZones() noexcept
Definition boardclipboarddata.h:290
SerializableObjectList< NetSegment, NetSegment > mNetSegments
Definition boardclipboarddata.h:314
QList< BoardHoleData > & getHoles() noexcept
Definition boardclipboarddata.h:293
const Uuid & getBoardUuid() const noexcept
Definition boardclipboarddata.h:281
SerializableObjectList< Plane, Plane > mPlanes
Definition boardclipboarddata.h:315
const Point & getCursorPos() const noexcept
Definition boardclipboarddata.h:282
QList< BoardZoneData > mZones
Definition boardclipboarddata.h:316
QList< BoardStrokeTextData > & getStrokeTexts() noexcept
Definition boardclipboarddata.h:292
QList< BoardPolygonData > & getPolygons() noexcept
Definition boardclipboarddata.h:291
QList< BoardStrokeTextData > mStrokeTexts
Definition boardclipboarddata.h:318
static std::unique_ptr< BoardClipboardData > fromMimeData(const QMimeData *mime)
Definition boardclipboarddata.cpp:178
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition boardclipboarddata.h:310
~BoardClipboardData() noexcept
Definition boardclipboarddata.cpp:94
bool isEmpty() const noexcept
Definition boardclipboarddata.cpp:106
BoardClipboardData(const BoardClipboardData &other)=delete
QList< BoardPolygonData > mPolygons
Definition boardclipboarddata.h:317
QList< BoardHoleData > mHoles
Definition boardclipboarddata.h:319
SerializableObjectList< Plane, Plane > & getPlanes() noexcept
Definition boardclipboarddata.h:289
Point mCursorPos
Definition boardclipboarddata.h:312
Definition occmodel.cpp:76
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition circuitidentifier.h:95
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:104
Definition uuid.h:186
Definition boardclipboarddata.h:67
bool locked
Definition boardclipboarddata.h:76
QList< BoardStrokeTextData > strokeTexts
Definition boardclipboarddata.h:78
Device(const Uuid &componentUuid, const Uuid &libDeviceUuid, const Uuid &libFootprintUuid, const Point &position, const Angle &rotation, bool mirrored, bool locked, const AttributeList &attributes, const QList< BoardStrokeTextData > &strokeTexts)
Definition boardclipboarddata.h:81
Angle rotation
Definition boardclipboarddata.h:74
Device(const SExpression &node)
Definition boardclipboarddata.h:97
Uuid componentUuid
Definition boardclipboarddata.h:70
bool mirrored
Definition boardclipboarddata.h:75
bool operator!=(const Device &rhs) noexcept
Definition boardclipboarddata.h:133
AttributeList attributes
Definition boardclipboarddata.h:77
void serialize(SExpression &root) const
Definition boardclipboarddata.h:113
static constexpr const char * tagname
Definition boardclipboarddata.h:68
Uuid libFootprintUuid
Definition boardclipboarddata.h:72
Signal< Device > onEdited
Dummy event, not used.
Definition boardclipboarddata.h:79
Point position
Definition boardclipboarddata.h:73
Uuid libDeviceUuid
Definition boardclipboarddata.h:71
Definition boardclipboarddata.h:143
JunctionList junctions
Definition boardclipboarddata.h:148
std::optional< CircuitIdentifier > netName
Definition boardclipboarddata.h:146
TraceList traces
Definition boardclipboarddata.h:149
NetSegment(const std::optional< CircuitIdentifier > &netName)
Definition boardclipboarddata.h:152
ViaList vias
Definition boardclipboarddata.h:147
NetSegment(const SExpression &node)
Definition boardclipboarddata.h:155
void serialize(SExpression &root) const
Definition boardclipboarddata.h:163
static constexpr const char * tagname
Definition boardclipboarddata.h:144
bool operator!=(const NetSegment &rhs) noexcept
Definition boardclipboarddata.h:175
Signal< NetSegment > onEdited
Dummy event, not used.
Definition boardclipboarddata.h:150
Definition boardclipboarddata.h:181
bool locked
Definition boardclipboarddata.h:195
Plane(const Uuid &uuid, const Layer &layer, const std::optional< CircuitIdentifier > &netSignalName, const Path &outline, const UnsignedLength &minWidth, const UnsignedLength &minClearance, bool keepIslands, int priority, BI_Plane::ConnectStyle connectStyle, const PositiveLength &thermalGap, const PositiveLength &thermalSpokeWidth, bool locked)
Definition boardclipboarddata.h:198
Uuid uuid
Definition boardclipboarddata.h:184
bool keepIslands
Definition boardclipboarddata.h:190
Plane(const SExpression &node)
Definition boardclipboarddata.h:218
Path outline
Definition boardclipboarddata.h:187
bool operator!=(const Plane &rhs) noexcept
Definition boardclipboarddata.h:258
UnsignedLength minClearance
Definition boardclipboarddata.h:189
UnsignedLength minWidth
Definition boardclipboarddata.h:188
PositiveLength thermalSpokeWidth
Definition boardclipboarddata.h:194
void serialize(SExpression &root) const
Definition boardclipboarddata.h:238
static constexpr const char * tagname
Definition boardclipboarddata.h:182
BI_Plane::ConnectStyle connectStyle
Definition boardclipboarddata.h:192
int priority
Definition boardclipboarddata.h:191
const Layer * layer
Definition boardclipboarddata.h:185
PositiveLength thermalGap
Definition boardclipboarddata.h:193
std::optional< CircuitIdentifier > netSignalName
Definition boardclipboarddata.h:186
Signal< Plane > onEdited
Dummy event, not used.
Definition boardclipboarddata.h:196