LibrePCB Developers Documentation
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_PROJECT_EDITOR_BOARDCLIPBOARDDATA_H
21 #define LIBREPCB_PROJECT_EDITOR_BOARDCLIPBOARDDATA_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 
37 #include <librepcb/common/uuid.h>
40 
41 #include <QtCore>
42 #include <QtWidgets>
43 
44 #include <memory>
45 
46 /*******************************************************************************
47  * Namespace / Forward Declarations
48  ******************************************************************************/
49 namespace librepcb {
50 
51 class TransactionalFileSystem;
52 class TransactionalDirectory;
53 
54 namespace project {
55 namespace editor {
56 
57 /*******************************************************************************
58  * Class BoardClipboardData
59  ******************************************************************************/
60 
64 class BoardClipboardData final : public SerializableObject {
65 public:
66  // Types
67  struct Device : public SerializableObject {
68  static constexpr const char* tagname = "device";
69 
75  bool mirrored;
78 
79  Device(const Uuid& componentUuid, const Uuid& libDeviceUuid,
80  const Uuid& libFootprintUuid, const Point& position,
81  const Angle& rotation, bool mirrored,
82  const StrokeTextList& strokeTexts)
83  : componentUuid(componentUuid),
84  libDeviceUuid(libDeviceUuid),
85  libFootprintUuid(libFootprintUuid),
86  position(position),
87  rotation(rotation),
88  mirrored(mirrored),
89  strokeTexts(strokeTexts),
90  onEdited(*this) {}
91 
92  Device(const SExpression& node, const Version& fileFormat)
93  : componentUuid(deserialize<Uuid>(node.getChild("@0"), fileFormat)),
94  libDeviceUuid(
95  deserialize<Uuid>(node.getChild("lib_device/@0"), fileFormat)),
96  libFootprintUuid(
97  deserialize<Uuid>(node.getChild("lib_footprint/@0"), fileFormat)),
98  position(node.getChild("position"), fileFormat),
99  rotation(deserialize<Angle>(node.getChild("rotation/@0"), fileFormat)),
100  mirrored(deserialize<bool>(node.getChild("mirror/@0"), fileFormat)),
101  strokeTexts(node, fileFormat),
102  onEdited(*this) {}
103 
105  void serialize(SExpression& root) const override {
106  root.appendChild(componentUuid);
107  root.appendChild("lib_device", libDeviceUuid, true);
108  root.appendChild("lib_footprint", libFootprintUuid, true);
109  root.appendChild(position.serializeToDomElement("position"), true);
110  root.appendChild("rotation", rotation, false);
111  root.appendChild("mirror", mirrored, false);
112  strokeTexts.serialize(root);
113  }
114 
115  bool operator!=(const Device& rhs) noexcept {
116  return (componentUuid != rhs.componentUuid) ||
117  (libDeviceUuid != rhs.libDeviceUuid) ||
118  (libFootprintUuid != rhs.libFootprintUuid) ||
119  (position != rhs.position) || (rotation != rhs.rotation) ||
120  (mirrored != rhs.mirrored) || (strokeTexts != rhs.strokeTexts);
121  }
122  };
123 
124  struct NetSegment : public SerializableObject {
125  static constexpr const char* tagname = "netsegment";
126 
132 
133  explicit NetSegment(const CircuitIdentifier& netName)
134  : netName(netName), vias(), junctions(), traces(), onEdited(*this) {}
135 
136  NetSegment(const SExpression& node, const Version& fileFormat)
137  : netName(deserialize<CircuitIdentifier>(node.getChild("net/@0"),
138  fileFormat)),
139  vias(node, fileFormat),
140  junctions(node, fileFormat),
141  traces(node, fileFormat),
142  onEdited(*this) {}
143 
145  void serialize(SExpression& root) const override {
146  root.appendChild("net", netName, true);
147  vias.serialize(root);
148  junctions.serialize(root);
149  traces.serialize(root);
150  }
151 
152  bool operator!=(const NetSegment& rhs) noexcept {
153  return (netName != rhs.netName) || (vias != rhs.vias) ||
154  (junctions != rhs.junctions) || (traces != rhs.traces);
155  }
156  };
157 
158  struct Plane : public SerializableObject {
159  static constexpr const char* tagname = "plane";
160 
168  int priority;
171 
172  Plane(const Uuid& uuid, const GraphicsLayerName& layer,
173  const CircuitIdentifier& netSignalName, const Path& outline,
174  const UnsignedLength& minWidth, const UnsignedLength& minClearance,
175  bool keepOrphans, int priority, BI_Plane::ConnectStyle connectStyle)
176  : uuid(uuid),
177  layer(layer),
178  netSignalName(netSignalName),
179  outline(outline),
180  minWidth(minWidth),
181  minClearance(minClearance),
182  keepOrphans(keepOrphans),
183  priority(priority),
184  connectStyle(connectStyle),
185  onEdited(*this) {}
186 
187  Plane(const SExpression& node, const Version& fileFormat)
188  : uuid(deserialize<Uuid>(node.getChild("@0"), fileFormat)),
189  layer(deserialize<GraphicsLayerName>(node.getChild("layer/@0"),
190  fileFormat)),
191  netSignalName(deserialize<CircuitIdentifier>(node.getChild("net/@0"),
192  fileFormat)),
193  outline(node, fileFormat),
194  minWidth(deserialize<UnsignedLength>(node.getChild("min_width/@0"),
195  fileFormat)),
196  minClearance(deserialize<UnsignedLength>(
197  node.getChild("min_clearance/@0"), fileFormat)),
198  keepOrphans(
199  deserialize<bool>(node.getChild("keep_orphans/@0"), fileFormat)),
200  priority(deserialize<int>(node.getChild("priority/@0"), fileFormat)),
201  connectStyle(deserialize<BI_Plane::ConnectStyle>(
202  node.getChild("connect_style/@0"), fileFormat)),
203  onEdited(*this) {}
204 
206  void serialize(SExpression& root) const override {
207  root.appendChild(uuid);
208  root.appendChild("layer", layer, false);
209  root.appendChild("net", netSignalName, true);
210  root.appendChild("priority", priority, false);
211  root.appendChild("min_width", minWidth, true);
212  root.appendChild("min_clearance", minClearance, false);
213  root.appendChild("keep_orphans", keepOrphans, false);
214  root.appendChild("connect_style", connectStyle, true);
215  outline.serialize(root);
216  }
217 
218  bool operator!=(const Plane& rhs) noexcept {
219  return (uuid != rhs.uuid) || (layer != rhs.layer) ||
220  (netSignalName != rhs.netSignalName) || (outline != rhs.outline) ||
221  (minWidth != rhs.minWidth) || (minClearance != rhs.minClearance) ||
222  (keepOrphans != rhs.keepOrphans) || (priority != rhs.priority) ||
223  (connectStyle != rhs.connectStyle);
224  }
225  };
226 
227  // Constructors / Destructor
228  BoardClipboardData() = delete;
229  BoardClipboardData(const BoardClipboardData& other) = delete;
230  BoardClipboardData(const Uuid& boardUuid, const Point& cursorPos) noexcept;
231  explicit BoardClipboardData(const QByteArray& mimeData);
232  ~BoardClipboardData() noexcept;
233 
234  // Getters
235  std::unique_ptr<TransactionalDirectory> getDirectory(
236  const QString& path = "") noexcept;
237  const Uuid& getBoardUuid() const noexcept { return mBoardUuid; }
238  const Point& getCursorPos() const noexcept { return mCursorPos; }
240  return mDevices;
241  }
243  return mNetSegments;
244  }
246  PolygonList& getPolygons() noexcept { return mPolygons; }
248  HoleList& getHoles() noexcept { return mHoles; }
249  QMap<std::pair<Uuid, Uuid>, Point>& getPadPositions() noexcept {
250  return mPadPositions;
251  }
252 
253  // General Methods
254  std::unique_ptr<QMimeData> toMimeData() const;
255  static std::unique_ptr<BoardClipboardData> fromMimeData(
256  const QMimeData* mime);
257 
258  // Operator Overloadings
259  BoardClipboardData& operator=(const BoardClipboardData& rhs) = delete;
260 
261 private: // Methods
263  void serialize(SExpression& root) const override;
264 
265  static QString getMimeType() noexcept;
266 
267 private: // Data
268  std::shared_ptr<TransactionalFileSystem> mFileSystem;
277  QMap<std::pair<Uuid, Uuid>, Point> mPadPositions;
278 };
279 
280 /*******************************************************************************
281  * End of File
282  ******************************************************************************/
283 
284 } // namespace editor
285 } // namespace project
286 } // namespace librepcb
287 
288 #endif
CircuitIdentifier netSignalName
Definition: boardclipboarddata.h:163
PolygonList & getPolygons() noexcept
Definition: boardclipboarddata.h:246
JunctionList junctions
Definition: boardclipboarddata.h:129
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
std::unique_ptr< QMimeData > toMimeData() const
Definition: boardclipboarddata.cpp:105
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: boardclipboarddata.h:145
bool operator!=(const Plane &rhs) noexcept
Definition: boardclipboarddata.h:218
SExpression & appendChild(const SExpression &child, bool linebreak)
Definition: sexpression.cpp:148
Angle rotation
Definition: boardclipboarddata.h:74
Uuid libFootprintUuid
Definition: boardclipboarddata.h:72
SerializableObjectList< Device, Device > mDevices
Definition: boardclipboarddata.h:271
Definition: airwiresbuilder.cpp:32
QMap< std::pair< Uuid, Uuid >, Point > & getPadPositions() noexcept
Definition: boardclipboarddata.h:249
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
Device(const Uuid &componentUuid, const Uuid &libDeviceUuid, const Uuid &libFootprintUuid, const Point &position, const Angle &rotation, bool mirrored, const StrokeTextList &strokeTexts)
Definition: boardclipboarddata.h:79
QMap< std::pair< Uuid, Uuid >, Point > mPadPositions
Definition: boardclipboarddata.h:277
BI_Plane::ConnectStyle connectStyle
Definition: boardclipboarddata.h:169
SerializableObjectList< NetSegment, NetSegment > mNetSegments
Definition: boardclipboarddata.h:272
HAlign deserialize(const SExpression &sexpr, const Version &fileFormat)
Definition: alignment.h:90
StrokeTextList mStrokeTexts
Definition: boardclipboarddata.h:275
HoleList mHoles
Definition: boardclipboarddata.h:276
const Point & getCursorPos() const noexcept
Definition: boardclipboarddata.h:238
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
int priority
Definition: boardclipboarddata.h:168
TraceList traces
Definition: boardclipboarddata.h:130
NetSegment(const CircuitIdentifier &netName)
Definition: boardclipboarddata.h:133
Point mCursorPos
Definition: boardclipboarddata.h:270
static std::unique_ptr< BoardClipboardData > fromMimeData(const QMimeData *mime)
Definition: boardclipboarddata.cpp:119
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
NetSegment(const SExpression &node, const Version &fileFormat)
Definition: boardclipboarddata.h:136
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: serializableobjectlist.h:359
The BI_Plane class.
Definition: bi_plane.h:53
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: boardclipboarddata.h:206
bool operator!=(const NetSegment &rhs) noexcept
Definition: boardclipboarddata.h:152
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
PolygonList mPolygons
Definition: boardclipboarddata.h:274
Plane(const Uuid &uuid, const GraphicsLayerName &layer, const CircuitIdentifier &netSignalName, const Path &outline, const UnsignedLength &minWidth, const UnsignedLength &minClearance, bool keepOrphans, int priority, BI_Plane::ConnectStyle connectStyle)
Definition: boardclipboarddata.h:172
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: path.cpp:188
Signal< Device > onEdited
Dummy event, not used.
Definition: boardclipboarddata.h:77
The BoardClipboardData class.
Definition: boardclipboarddata.h:64
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:90
BoardClipboardData & operator=(const BoardClipboardData &rhs)=delete
SerializableObjectList< Plane, Plane > mPlanes
Definition: boardclipboarddata.h:273
StrokeTextList & getStrokeTexts() noexcept
Definition: boardclipboarddata.h:247
Device(const SExpression &node, const Version &fileFormat)
Definition: boardclipboarddata.h:92
Uuid uuid
Definition: boardclipboarddata.h:161
SerializableObjectList< NetSegment, NetSegment > & getNetSegments() noexcept
Definition: boardclipboarddata.h:242
UnsignedLength minClearance
Definition: boardclipboarddata.h:166
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition: boardclipboarddata.h:268
Path outline
Definition: boardclipboarddata.h:164
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
Point position
Definition: boardclipboarddata.h:73
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
static QString getMimeType() noexcept
Definition: boardclipboarddata.cpp:154
std::unique_ptr< TransactionalDirectory > getDirectory(const QString &path="") noexcept
Definition: boardclipboarddata.cpp:95
Signal< Plane > onEdited
Dummy event, not used.
Definition: boardclipboarddata.h:170
const Uuid & getBoardUuid() const noexcept
Definition: boardclipboarddata.h:237
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
SerializableObjectList< Device, Device > & getDevices() noexcept
Definition: boardclipboarddata.h:239
Uuid componentUuid
Definition: boardclipboarddata.h:70
bool keepOrphans
Definition: boardclipboarddata.h:167
ViaList vias
Definition: boardclipboarddata.h:128
Plane(const SExpression &node, const Version &fileFormat)
Definition: boardclipboarddata.h:187
SerializableObjectList< Plane, Plane > & getPlanes() noexcept
Definition: boardclipboarddata.h:245
Uuid mBoardUuid
Definition: boardclipboarddata.h:269
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: boardclipboarddata.h:105
bool mirrored
Definition: boardclipboarddata.h:75
SExpression serializeToDomElement(const QString &name) const
Serialize the object to a new S-Expression node.
Definition: serializableobject.h:63
Signal< NetSegment > onEdited
Dummy event, not used.
Definition: boardclipboarddata.h:131
CircuitIdentifier netName
Definition: boardclipboarddata.h:127
Definition: boardclipboarddata.h:158
UnsignedLength minWidth
Definition: boardclipboarddata.h:165
The SExpression class.
Definition: sexpression.h:72
Uuid libDeviceUuid
Definition: boardclipboarddata.h:71
bool operator!=(const Device &rhs) noexcept
Definition: boardclipboarddata.h:115
ConnectStyle
Definition: bi_plane.h:58
StrokeTextList strokeTexts
Definition: boardclipboarddata.h:76
HoleList & getHoles() noexcept
Definition: boardclipboarddata.h:248
~BoardClipboardData() noexcept
Definition: boardclipboarddata.cpp:83
GraphicsLayerName layer
Definition: boardclipboarddata.h:162
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:672
static constexpr const char * tagname
Definition: boardclipboarddata.h:68