LibrePCB Developers Documentation
Loading...
Searching...
No Matches
schematicclipboarddata.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_SCHEMATICCLIPBOARDDATA_H
21#define LIBREPCB_EDITOR_SCHEMATICCLIPBOARDDATA_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
35
36#include <QtCore>
37#include <QtWidgets>
38
39#include <memory>
40
41/*******************************************************************************
42 * Namespace / Forward Declarations
43 ******************************************************************************/
44namespace librepcb {
45
46class TransactionalDirectory;
47class TransactionalFileSystem;
48
49namespace editor {
50
51/*******************************************************************************
52 * Class SchematicClipboardData
53 ******************************************************************************/
54
59public:
60 // Types
62 static constexpr const char* tagname = "component";
63
68 QString value;
72
74
89
90 explicit ComponentInstance(const SExpression& node)
91 : uuid(deserialize<Uuid>(node.getChild("@0"))),
92 libComponentUuid(deserialize<Uuid>(node.getChild("lib_component/@0"))),
93 libVariantUuid(deserialize<Uuid>(node.getChild("lib_variant/@0"))),
94 name(deserialize<CircuitIdentifier>(node.getChild("name/@0"))),
95 value(node.getChild("value/@0").getValue()),
96 attributes(node),
97 assemblyOptions(node),
98 lockAssembly(deserialize<bool>(node.getChild("lock_assembly/@0"))),
99 onEdited(*this) {}
100
102 const Uuid& getUuid() const noexcept { return uuid; }
103
104 void serialize(SExpression& root) const {
105 root.appendChild(uuid);
106 root.ensureLineBreak();
107 root.appendChild("lib_component", libComponentUuid);
108 root.ensureLineBreak();
109 root.appendChild("lib_variant", libVariantUuid);
110 root.ensureLineBreak();
111 root.appendChild("name", name);
112 root.appendChild("value", value);
113 root.ensureLineBreak();
114 attributes.serialize(root);
115 root.ensureLineBreak();
117 root.ensureLineBreak();
118 root.appendChild("lock_assembly", lockAssembly);
119 root.ensureLineBreak();
120 }
121
122 bool operator!=(const ComponentInstance& rhs) noexcept {
123 return (uuid != rhs.uuid) || (libComponentUuid != rhs.libComponentUuid) ||
124 (libVariantUuid != rhs.libVariantUuid) || (name != rhs.name) ||
125 (value != rhs.value) || (attributes != rhs.attributes) ||
126 (assemblyOptions != rhs.assemblyOptions) ||
127 (lockAssembly != rhs.lockAssembly);
128 }
129 };
130
132 static constexpr const char* tagname = "symbol";
133
141
143
155
156 explicit SymbolInstance(const SExpression& node)
157 : uuid(deserialize<Uuid>(node.getChild("@0"))),
158 componentInstanceUuid(deserialize<Uuid>(node.getChild("component/@0"))),
159 symbolVariantItemUuid(deserialize<Uuid>(node.getChild("lib_gate/@0"))),
160 position(node.getChild("position")),
161 rotation(deserialize<Angle>(node.getChild("rotation/@0"))),
162 mirrored(deserialize<bool>(node.getChild("mirror/@0"))),
163 texts(node),
164 onEdited(*this) {}
165
166 void serialize(SExpression& root) const {
167 root.appendChild(uuid);
168 root.ensureLineBreak();
169 root.appendChild("component", componentInstanceUuid);
170 root.ensureLineBreak();
171 root.appendChild("lib_gate", symbolVariantItemUuid);
172 root.ensureLineBreak();
173 position.serialize(root.appendList("position"));
174 root.appendChild("rotation", rotation);
175 root.appendChild("mirror", mirrored);
176 root.ensureLineBreak();
177 texts.serialize(root);
178 root.ensureLineBreak();
179 }
180
181 bool operator!=(const SymbolInstance& rhs) noexcept {
182 return (uuid != rhs.uuid) ||
183 (componentInstanceUuid != rhs.componentInstanceUuid) ||
184 (symbolVariantItemUuid != rhs.symbolVariantItemUuid) ||
185 (position != rhs.position) || (rotation != rhs.rotation) ||
186 (mirrored != rhs.mirrored) || (texts != rhs.texts);
187 }
188 };
189
190 struct Bus {
191 static constexpr const char* tagname = "bus";
192
196 std::optional<UnsignedLength> maxTraceLengthDifference;
198
199 explicit Bus(const Uuid& uuid, const BusName& name, bool prefixNetNames,
200 const std::optional<UnsignedLength>& maxTraceLengthDifference)
201 : uuid(uuid),
202 name(name),
205 onEdited(*this) {}
206
207 explicit Bus(const SExpression& node)
208 : uuid(deserialize<Uuid>(node.getChild("@0"))),
209 name(deserialize<BusName>(node.getChild("name/@0"))),
210 prefixNetNames(deserialize<bool>(node.getChild("prefix_nets/@0"))),
212 node.getChild("max_trace_length_difference/@0"))),
213 onEdited(*this) {}
214
215 // For SerializableObjectList
216 const Uuid& getUuid() const noexcept { return uuid; }
217
218 void serialize(SExpression& root) const {
219 root.appendChild(uuid);
220 root.ensureLineBreak();
221 root.appendChild("name", name);
222 root.appendChild("prefix_nets", prefixNetNames);
223 root.appendChild("max_trace_length_difference", maxTraceLengthDifference);
224 root.ensureLineBreak();
225 }
226
227 bool operator!=(const Bus& rhs) noexcept {
228 return (uuid != rhs.uuid) || (name != rhs.name) ||
229 (prefixNetNames != rhs.prefixNetNames) ||
230 (maxTraceLengthDifference != rhs.maxTraceLengthDifference);
231 }
232 };
233
234 struct BusSegment {
235 static constexpr const char* tagname = "bussegment";
236
243
244 explicit BusSegment(const Uuid& uuid, const Uuid& busUuid)
245 : uuid(uuid),
247 junctions(),
248 lines(),
249 labels(),
250 onEdited(*this) {}
251
252 explicit BusSegment(const SExpression& node)
253 : uuid(deserialize<Uuid>(node.getChild("@0"))),
254 busUuid(deserialize<Uuid>(node.getChild("bus/@0"))),
255 junctions(node),
256 lines(node),
257 labels(node),
258 onEdited(*this) {}
259
260 void serialize(SExpression& root) const {
261 root.appendChild(uuid);
262 root.ensureLineBreak();
263 root.appendChild("bus", busUuid);
264 root.ensureLineBreak();
265 junctions.serialize(root);
266 root.ensureLineBreak();
267 lines.serialize(root);
268 root.ensureLineBreak();
269 labels.serialize(root);
270 root.ensureLineBreak();
271 }
272
273 bool operator!=(const BusSegment& rhs) noexcept {
274 return (uuid != rhs.uuid) || (busUuid != rhs.busUuid) ||
275 (junctions != rhs.junctions) || (lines != rhs.lines) ||
276 (labels != rhs.labels);
277 }
278 };
279
280 struct NetSegment {
281 static constexpr const char* tagname = "netsegment";
282
288
290 : netName(netName), junctions(), lines(), labels(), onEdited(*this) {}
291
292 explicit NetSegment(const SExpression& node)
293 : netName(deserialize<CircuitIdentifier>(node.getChild("net/@0"))),
294 junctions(node),
295 lines(node),
296 labels(node),
297 onEdited(*this) {}
298
299 void serialize(SExpression& root) const {
300 root.ensureLineBreak();
301 root.appendChild("net", netName);
302 root.ensureLineBreak();
303 junctions.serialize(root);
304 root.ensureLineBreak();
305 lines.serialize(root);
306 root.ensureLineBreak();
307 labels.serialize(root);
308 root.ensureLineBreak();
309 }
310
311 bool operator!=(const NetSegment& rhs) noexcept {
312 return (netName != rhs.netName) || (junctions != rhs.junctions) ||
313 (lines != rhs.lines) || (labels != rhs.labels);
314 }
315 };
316
317 // Constructors / Destructor
320 SchematicClipboardData(const Uuid& schematicUuid, const Point& cursorPos,
321 const AssemblyVariantList& assemblyVariants) noexcept;
322 explicit SchematicClipboardData(const QByteArray& mimeData);
323 ~SchematicClipboardData() noexcept;
324
325 // Getters
327 const QString& path = "") noexcept;
328 const Uuid& getSchematicUuid() const noexcept { return mSchematicUuid; }
329 const Point& getCursorPos() const noexcept { return mCursorPos; }
331 return mAssemblyVariants;
332 }
336 return mComponentInstances;
337 }
340 return mSymbolInstances;
341 }
348 PolygonList& getPolygons() noexcept { return mPolygons; }
349 TextList& getTexts() noexcept { return mTexts; }
350 ImageList& getImages() noexcept { return mImages; }
351
352 // General Methods
353 std::unique_ptr<QMimeData> toMimeData() const;
354 static std::unique_ptr<SchematicClipboardData> fromMimeData(
355 const QMimeData* mime);
356 static bool isValid(const QMimeData* mime) noexcept;
357
358 // Operator Overloadings
360
361private: // Methods
362 static QString getMimeType() noexcept;
363
364private: // Data
378};
379
380/*******************************************************************************
381 * End of File
382 ******************************************************************************/
383
384} // namespace editor
385} // namespace librepcb
386
387#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
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
void ensureLineBreak()
Definition sexpression.cpp:206
void appendChild(std::unique_ptr< SExpression > child)
Definition sexpression.cpp:217
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition serializableobjectlist.h:380
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:70
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
The SchematicClipboardData class.
Definition schematicclipboarddata.h:58
ImageList & getImages() noexcept
Definition schematicclipboarddata.h:350
SerializableObjectList< ComponentInstance, ComponentInstance > mComponentInstances
Definition schematicclipboarddata.h:371
static QString getMimeType() noexcept
Definition schematicclipboarddata.cpp:161
TextList mTexts
Definition schematicclipboarddata.h:376
ImageList mImages
Definition schematicclipboarddata.h:377
std::unique_ptr< QMimeData > toMimeData() const
Definition schematicclipboarddata.cpp:101
PolygonList & getPolygons() noexcept
Definition schematicclipboarddata.h:348
SerializableObjectList< NetSegment, NetSegment > & getNetSegments() noexcept
Definition schematicclipboarddata.h:345
SerializableObjectList< Bus, Bus > mBuses
Definition schematicclipboarddata.h:369
const AssemblyVariantList & getAssemblyVariants() noexcept
Definition schematicclipboarddata.h:330
std::unique_ptr< TransactionalDirectory > getDirectory(const QString &path="") noexcept
Definition schematicclipboarddata.cpp:91
SerializableObjectList< SymbolInstance, SymbolInstance > mSymbolInstances
Definition schematicclipboarddata.h:372
TextList & getTexts() noexcept
Definition schematicclipboarddata.h:349
SerializableObjectList< SymbolInstance, SymbolInstance > & getSymbolInstances() noexcept
Definition schematicclipboarddata.h:339
SerializableObjectList< NetSegment, NetSegment > mNetSegments
Definition schematicclipboarddata.h:374
const Point & getCursorPos() const noexcept
Definition schematicclipboarddata.h:329
SerializableObjectList< BusSegment, BusSegment > mBusSegments
Definition schematicclipboarddata.h:373
SerializableObjectList< BusSegment, BusSegment > & getBusSegments() noexcept
Definition schematicclipboarddata.h:342
SerializableObjectList< ComponentInstance, ComponentInstance > & getComponentInstances() noexcept
Definition schematicclipboarddata.h:335
Uuid mSchematicUuid
Definition schematicclipboarddata.h:366
SerializableObjectList< Bus, Bus > & getBuses() noexcept
Definition schematicclipboarddata.h:333
SchematicClipboardData(const SchematicClipboardData &other)=delete
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition schematicclipboarddata.h:365
PolygonList mPolygons
Definition schematicclipboarddata.h:375
static std::unique_ptr< SchematicClipboardData > fromMimeData(const QMimeData *mime)
Definition schematicclipboarddata.cpp:142
AssemblyVariantList mAssemblyVariants
Definition schematicclipboarddata.h:368
static bool isValid(const QMimeData *mime) noexcept
Definition schematicclipboarddata.cpp:153
SchematicClipboardData & operator=(const SchematicClipboardData &rhs)=delete
const Uuid & getSchematicUuid() const noexcept
Definition schematicclipboarddata.h:328
~SchematicClipboardData() noexcept
Definition schematicclipboarddata.cpp:79
Point mCursorPos
Definition schematicclipboarddata.h:367
Definition occmodel.cpp:77
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition circuitidentifier.h:88
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
type_safe::constrained_type< QString, BusNameConstraint, BusNameVerifier > BusName
Definition busname.h:82
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:99
Definition uuid.h:186
Definition schematicclipboarddata.h:190
Bus(const Uuid &uuid, const BusName &name, bool prefixNetNames, const std::optional< UnsignedLength > &maxTraceLengthDifference)
Definition schematicclipboarddata.h:199
bool prefixNetNames
Definition schematicclipboarddata.h:195
std::optional< UnsignedLength > maxTraceLengthDifference
Definition schematicclipboarddata.h:196
Uuid uuid
Definition schematicclipboarddata.h:193
Signal< Bus > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:197
BusName name
Definition schematicclipboarddata.h:194
bool operator!=(const Bus &rhs) noexcept
Definition schematicclipboarddata.h:227
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:218
static constexpr const char * tagname
Definition schematicclipboarddata.h:191
const Uuid & getUuid() const noexcept
Definition schematicclipboarddata.h:216
Bus(const SExpression &node)
Definition schematicclipboarddata.h:207
Definition schematicclipboarddata.h:234
JunctionList junctions
Definition schematicclipboarddata.h:239
NetLabelList labels
Definition schematicclipboarddata.h:241
Uuid uuid
Required for references from net lines.
Definition schematicclipboarddata.h:237
NetLineList lines
Definition schematicclipboarddata.h:240
BusSegment(const Uuid &uuid, const Uuid &busUuid)
Definition schematicclipboarddata.h:244
Signal< BusSegment > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:242
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:260
static constexpr const char * tagname
Definition schematicclipboarddata.h:235
Uuid busUuid
Definition schematicclipboarddata.h:238
bool operator!=(const BusSegment &rhs) noexcept
Definition schematicclipboarddata.h:273
BusSegment(const SExpression &node)
Definition schematicclipboarddata.h:252
QString value
Definition schematicclipboarddata.h:68
ComponentInstance(const SExpression &node)
Definition schematicclipboarddata.h:90
Uuid libComponentUuid
Definition schematicclipboarddata.h:65
Uuid libVariantUuid
Definition schematicclipboarddata.h:66
Uuid uuid
Definition schematicclipboarddata.h:64
bool lockAssembly
Definition schematicclipboarddata.h:71
ComponentInstance(const Uuid &uuid, const Uuid &libComponentUuid, const Uuid &libVariantUuid, const CircuitIdentifier &name, const QString &value, const AttributeList &attributes, const ComponentAssemblyOptionList &assemblyOptions, bool lockParts)
Definition schematicclipboarddata.h:75
Signal< ComponentInstance > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:73
AttributeList attributes
Definition schematicclipboarddata.h:69
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:104
static constexpr const char * tagname
Definition schematicclipboarddata.h:62
const Uuid & getUuid() const noexcept
Required for librepcb::SerializableObjectList::contains()
Definition schematicclipboarddata.h:102
CircuitIdentifier name
Definition schematicclipboarddata.h:67
ComponentAssemblyOptionList assemblyOptions
Definition schematicclipboarddata.h:70
bool operator!=(const ComponentInstance &rhs) noexcept
Definition schematicclipboarddata.h:122
Definition schematicclipboarddata.h:280
JunctionList junctions
Definition schematicclipboarddata.h:284
NetLabelList labels
Definition schematicclipboarddata.h:286
NetLineList lines
Definition schematicclipboarddata.h:285
NetSegment(const SExpression &node)
Definition schematicclipboarddata.h:292
NetSegment(const CircuitIdentifier &netName)
Definition schematicclipboarddata.h:289
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:299
static constexpr const char * tagname
Definition schematicclipboarddata.h:281
bool operator!=(const NetSegment &rhs) noexcept
Definition schematicclipboarddata.h:311
Signal< NetSegment > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:287
CircuitIdentifier netName
Definition schematicclipboarddata.h:283
Definition schematicclipboarddata.h:131
Uuid uuid
Definition schematicclipboarddata.h:134
Angle rotation
Definition schematicclipboarddata.h:138
SymbolInstance(const SExpression &node)
Definition schematicclipboarddata.h:156
SymbolInstance(const Uuid &uuid, const Uuid &componentInstanceUuid, const Uuid &symbolVariantItemUuid, const Point &position, const Angle &rotation, bool mirrored, const TextList &texts)
Definition schematicclipboarddata.h:144
bool mirrored
Definition schematicclipboarddata.h:139
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:166
static constexpr const char * tagname
Definition schematicclipboarddata.h:132
bool operator!=(const SymbolInstance &rhs) noexcept
Definition schematicclipboarddata.h:181
Uuid componentInstanceUuid
Definition schematicclipboarddata.h:135
TextList texts
Definition schematicclipboarddata.h:140
Uuid symbolVariantItemUuid
Definition schematicclipboarddata.h:136
Point position
Definition schematicclipboarddata.h:137
Signal< SymbolInstance > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:142