SILICON
Loading...
Searching...
No Matches
diagramSceneSerializer.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <memory>
21#include <string>
22#include <vector>
23
24#include <QGraphicsItem>
25
26#include <nlohmann/json.hpp>
27
29
30namespace SILICON::core {
31class Circuit;
32}
33
34namespace SILICON::ui {
35using namespace SILICON::core;
36
37class DiagramScene;
38class GraphicalItem;
40class SceneLoadPlan;
41
52public:
58
63 [[nodiscard]] std::string serialize() const;
64
69 [[nodiscard]] nlohmann::ordered_json serializeSelection() const;
70
76 [[nodiscard]] nlohmann::ordered_json
77 serializeItems(const std::vector<QGraphicsItem*>& sceneItems) const;
78
85 void deserialize(const std::string& jsonStr, GUIComponentFactory& guiFactory,
86 const ComponentRegistry& coreRegistry);
87
102 [[nodiscard]] std::shared_ptr<SceneLoadPlan>
103 prepareDeserialize(const std::string& jsonStr, GUIComponentFactory& guiFactory,
104 const ComponentRegistry& coreRegistry);
105
114 void applyDeserialize(std::shared_ptr<SceneLoadPlan> plan);
115
117 void loadCircuit(std::shared_ptr<Circuit> circuit, GUIComponentFactory& guiFactory,
118 bool resolveSubcircuitMetadata = true);
119
129 bool insertSelection(const nlohmann::json& payload, GUIComponentFactory& guiFactory,
130 const ComponentRegistry& coreRegistry, QPointF targetOrigin,
131 bool isPaste);
132
138 bool removeSelection(const nlohmann::json& payload);
139
140private:
143};
144
145} // namespace SILICON::ui
Represents a digital circuit as a directed graph of components.
Definition circuit.hpp:125
void loadCircuit(std::shared_ptr< Circuit > circuit, GUIComponentFactory &guiFactory, bool resolveSubcircuitMetadata=true)
nlohmann::ordered_json serializeItems(const std::vector< QGraphicsItem * > &sceneItems) const
Serializes arbitrary scene items using the selection payload format.
void applyDeserialize(std::shared_ptr< SceneLoadPlan > plan)
Replaces the host scene with a plan built by prepareDeserialize.
DiagramScene & scene
Host scene whose items and lookup tables back serialization operations.
std::shared_ptr< SceneLoadPlan > prepareDeserialize(const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
Parses a scene payload without touching the host scene.
bool removeSelection(const nlohmann::json &payload)
Removes items matching a serialized selection payload from the scene.
std::string serialize() const
Serializes the full editor scene to the persisted JSON format.
void deserialize(const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
Deserializes a full scene from persisted JSON.
DiagramSceneSerializer(DiagramScene &scene)
Constructs a serializer bound to a scene.
bool insertSelection(const nlohmann::json &payload, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry, QPointF targetOrigin, bool isPaste)
Inserts a serialized selection payload into the current scene.
nlohmann::ordered_json serializeSelection() const
Serializes the current selection to the clipboard payload format.
Graphics scene for the circuit diagram editor.
Factory for creating graphical circuit components.
Base class for all graphical items in the diagram.
Scene payload deserialized ahead of time, detached from the host scene.