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 ******************************************************************************/
33
34#include <QtCore>
35#include <QtWidgets>
36
37#include <memory>
38
39/*******************************************************************************
40 * Namespace / Forward Declarations
41 ******************************************************************************/
42namespace librepcb {
43
44class TransactionalDirectory;
45class TransactionalFileSystem;
46
47namespace editor {
48
49/*******************************************************************************
50 * Class SchematicClipboardData
51 ******************************************************************************/
52
57public:
58 // Types
60 static constexpr const char* tagname = "component";
61
66 QString value;
70
72
87
88 explicit ComponentInstance(const SExpression& node)
89 : uuid(deserialize<Uuid>(node.getChild("@0"))),
90 libComponentUuid(deserialize<Uuid>(node.getChild("lib_component/@0"))),
91 libVariantUuid(deserialize<Uuid>(node.getChild("lib_variant/@0"))),
92 name(deserialize<CircuitIdentifier>(node.getChild("name/@0"))),
93 value(node.getChild("value/@0").getValue()),
94 attributes(node),
95 assemblyOptions(node),
96 lockAssembly(deserialize<bool>(node.getChild("lock_assembly/@0"))),
97 onEdited(*this) {}
98
100 const Uuid& getUuid() const noexcept { return uuid; }
101
102 void serialize(SExpression& root) const {
103 root.appendChild(uuid);
104 root.ensureLineBreak();
105 root.appendChild("lib_component", libComponentUuid);
106 root.ensureLineBreak();
107 root.appendChild("lib_variant", libVariantUuid);
108 root.ensureLineBreak();
109 root.appendChild("name", name);
110 root.appendChild("value", value);
111 root.ensureLineBreak();
112 attributes.serialize(root);
113 root.ensureLineBreak();
115 root.ensureLineBreak();
116 root.appendChild("lock_assembly", lockAssembly);
117 root.ensureLineBreak();
118 }
119
120 bool operator!=(const ComponentInstance& rhs) noexcept {
121 return (uuid != rhs.uuid) || (libComponentUuid != rhs.libComponentUuid) ||
122 (libVariantUuid != rhs.libVariantUuid) || (name != rhs.name) ||
123 (value != rhs.value) || (attributes != rhs.attributes) ||
124 (assemblyOptions != rhs.assemblyOptions) ||
125 (lockAssembly != rhs.lockAssembly);
126 }
127 };
128
130 static constexpr const char* tagname = "symbol";
131
139
141
153
154 explicit SymbolInstance(const SExpression& node)
155 : uuid(deserialize<Uuid>(node.getChild("@0"))),
156 componentInstanceUuid(deserialize<Uuid>(node.getChild("component/@0"))),
157 symbolVariantItemUuid(deserialize<Uuid>(node.getChild("lib_gate/@0"))),
158 position(node.getChild("position")),
159 rotation(deserialize<Angle>(node.getChild("rotation/@0"))),
160 mirrored(deserialize<bool>(node.getChild("mirror/@0"))),
161 texts(node),
162 onEdited(*this) {}
163
164 void serialize(SExpression& root) const {
165 root.appendChild(uuid);
166 root.ensureLineBreak();
167 root.appendChild("component", componentInstanceUuid);
168 root.ensureLineBreak();
169 root.appendChild("lib_gate", symbolVariantItemUuid);
170 root.ensureLineBreak();
171 position.serialize(root.appendList("position"));
172 root.appendChild("rotation", rotation);
173 root.appendChild("mirror", mirrored);
174 root.ensureLineBreak();
175 texts.serialize(root);
176 root.ensureLineBreak();
177 }
178
179 bool operator!=(const SymbolInstance& rhs) noexcept {
180 return (uuid != rhs.uuid) ||
181 (componentInstanceUuid != rhs.componentInstanceUuid) ||
182 (symbolVariantItemUuid != rhs.symbolVariantItemUuid) ||
183 (position != rhs.position) || (rotation != rhs.rotation) ||
184 (mirrored != rhs.mirrored) || (texts != rhs.texts);
185 }
186 };
187
188 struct NetSegment {
189 static constexpr const char* tagname = "netsegment";
190
196
198 : netName(netName), junctions(), lines(), labels(), onEdited(*this) {}
199
200 explicit NetSegment(const SExpression& node)
201 : netName(deserialize<CircuitIdentifier>(node.getChild("net/@0"))),
202 junctions(node),
203 lines(node),
204 labels(node),
205 onEdited(*this) {}
206
207 void serialize(SExpression& root) const {
208 root.ensureLineBreak();
209 root.appendChild("net", netName);
210 root.ensureLineBreak();
211 junctions.serialize(root);
212 root.ensureLineBreak();
213 lines.serialize(root);
214 root.ensureLineBreak();
215 labels.serialize(root);
216 root.ensureLineBreak();
217 }
218
219 bool operator!=(const NetSegment& rhs) noexcept {
220 return (netName != rhs.netName) || (junctions != rhs.junctions) ||
221 (lines != rhs.lines) || (labels != rhs.labels);
222 }
223 };
224
225 // Constructors / Destructor
228 SchematicClipboardData(const Uuid& schematicUuid, const Point& cursorPos,
229 const AssemblyVariantList& assemblyVariants) noexcept;
230 explicit SchematicClipboardData(const QByteArray& mimeData);
231 ~SchematicClipboardData() noexcept;
232
233 // Getters
235 const QString& path = "") noexcept;
236 const Uuid& getSchematicUuid() const noexcept { return mSchematicUuid; }
237 const Point& getCursorPos() const noexcept { return mCursorPos; }
239 return mAssemblyVariants;
240 }
243 return mComponentInstances;
244 }
247 return mSymbolInstances;
248 }
252 PolygonList& getPolygons() noexcept { return mPolygons; }
253 TextList& getTexts() noexcept { return mTexts; }
254
255 // General Methods
256 std::unique_ptr<QMimeData> toMimeData() const;
257 static std::unique_ptr<SchematicClipboardData> fromMimeData(
258 const QMimeData* mime);
259
260 // Operator Overloadings
262
263private: // Methods
264 static QString getMimeType() noexcept;
265
266private: // Data
277};
278
279/*******************************************************************************
280 * End of File
281 ******************************************************************************/
282
283} // namespace editor
284} // namespace librepcb
285
286#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: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 SchematicClipboardData class.
Definition schematicclipboarddata.h:56
SerializableObjectList< ComponentInstance, ComponentInstance > mComponentInstances
Definition schematicclipboarddata.h:272
static QString getMimeType() noexcept
Definition schematicclipboarddata.cpp:145
TextList mTexts
Definition schematicclipboarddata.h:276
std::unique_ptr< QMimeData > toMimeData() const
Definition schematicclipboarddata.cpp:95
PolygonList & getPolygons() noexcept
Definition schematicclipboarddata.h:252
SerializableObjectList< NetSegment, NetSegment > & getNetSegments() noexcept
Definition schematicclipboarddata.h:249
const AssemblyVariantList & getAssemblyVariants() noexcept
Definition schematicclipboarddata.h:238
std::unique_ptr< TransactionalDirectory > getDirectory(const QString &path="") noexcept
Definition schematicclipboarddata.cpp:85
SerializableObjectList< SymbolInstance, SymbolInstance > mSymbolInstances
Definition schematicclipboarddata.h:273
TextList & getTexts() noexcept
Definition schematicclipboarddata.h:253
SerializableObjectList< SymbolInstance, SymbolInstance > & getSymbolInstances() noexcept
Definition schematicclipboarddata.h:246
SerializableObjectList< NetSegment, NetSegment > mNetSegments
Definition schematicclipboarddata.h:274
const Point & getCursorPos() const noexcept
Definition schematicclipboarddata.h:237
SerializableObjectList< ComponentInstance, ComponentInstance > & getComponentInstances() noexcept
Definition schematicclipboarddata.h:242
Uuid mSchematicUuid
Definition schematicclipboarddata.h:268
SchematicClipboardData(const SchematicClipboardData &other)=delete
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition schematicclipboarddata.h:267
PolygonList mPolygons
Definition schematicclipboarddata.h:275
static std::unique_ptr< SchematicClipboardData > fromMimeData(const QMimeData *mime)
Definition schematicclipboarddata.cpp:130
AssemblyVariantList mAssemblyVariants
Definition schematicclipboarddata.h:270
SchematicClipboardData & operator=(const SchematicClipboardData &rhs)=delete
const Uuid & getSchematicUuid() const noexcept
Definition schematicclipboarddata.h:236
~SchematicClipboardData() noexcept
Definition schematicclipboarddata.cpp:73
Point mCursorPos
Definition schematicclipboarddata.h:269
Definition occmodel.cpp:76
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition circuitidentifier.h:95
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:104
Definition uuid.h:186
QString value
Definition schematicclipboarddata.h:66
ComponentInstance(const SExpression &node)
Definition schematicclipboarddata.h:88
Uuid libComponentUuid
Definition schematicclipboarddata.h:63
Uuid libVariantUuid
Definition schematicclipboarddata.h:64
Uuid uuid
Definition schematicclipboarddata.h:62
bool lockAssembly
Definition schematicclipboarddata.h:69
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:73
Signal< ComponentInstance > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:71
AttributeList attributes
Definition schematicclipboarddata.h:67
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:102
static constexpr const char * tagname
Definition schematicclipboarddata.h:60
const Uuid & getUuid() const noexcept
Required for librepcb::SerializableObjectList::contains()
Definition schematicclipboarddata.h:100
CircuitIdentifier name
Definition schematicclipboarddata.h:65
ComponentAssemblyOptionList assemblyOptions
Definition schematicclipboarddata.h:68
bool operator!=(const ComponentInstance &rhs) noexcept
Definition schematicclipboarddata.h:120
Definition schematicclipboarddata.h:188
JunctionList junctions
Definition schematicclipboarddata.h:192
NetLabelList labels
Definition schematicclipboarddata.h:194
NetLineList lines
Definition schematicclipboarddata.h:193
NetSegment(const SExpression &node)
Definition schematicclipboarddata.h:200
NetSegment(const CircuitIdentifier &netName)
Definition schematicclipboarddata.h:197
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:207
static constexpr const char * tagname
Definition schematicclipboarddata.h:189
bool operator!=(const NetSegment &rhs) noexcept
Definition schematicclipboarddata.h:219
Signal< NetSegment > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:195
CircuitIdentifier netName
Definition schematicclipboarddata.h:191
Definition schematicclipboarddata.h:129
Uuid uuid
Definition schematicclipboarddata.h:132
Angle rotation
Definition schematicclipboarddata.h:136
SymbolInstance(const SExpression &node)
Definition schematicclipboarddata.h:154
SymbolInstance(const Uuid &uuid, const Uuid &componentInstanceUuid, const Uuid &symbolVariantItemUuid, const Point &position, const Angle &rotation, bool mirrored, const TextList &texts)
Definition schematicclipboarddata.h:142
bool mirrored
Definition schematicclipboarddata.h:137
void serialize(SExpression &root) const
Definition schematicclipboarddata.h:164
static constexpr const char * tagname
Definition schematicclipboarddata.h:130
bool operator!=(const SymbolInstance &rhs) noexcept
Definition schematicclipboarddata.h:179
Uuid componentInstanceUuid
Definition schematicclipboarddata.h:133
TextList texts
Definition schematicclipboarddata.h:138
Uuid symbolVariantItemUuid
Definition schematicclipboarddata.h:134
Point position
Definition schematicclipboarddata.h:135
Signal< SymbolInstance > onEdited
Dummy event, not used.
Definition schematicclipboarddata.h:140