SILICON
Toggle main menu visibility
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
28
#include <
core/serialization/component_registry.hpp
>
29
30
namespace
SILICON::core
{
31
class
Circuit
;
32
}
33
34
namespace
SILICON::ui
{
35
using namespace
SILICON::core;
36
37
class
DiagramScene
;
38
class
GraphicalItem
;
39
class
GUIComponentFactory
;
40
class
SceneLoadPlan
;
41
51
class
DiagramSceneSerializer
{
52
public
:
57
explicit
DiagramSceneSerializer
(
DiagramScene
&
scene
);
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
140
private
:
142
DiagramScene
&
scene
;
143
};
144
145
}
// namespace SILICON::ui
SILICON::core::Circuit
Represents a digital circuit as a directed graph of components.
Definition
circuit.hpp:125
SILICON::core::ComponentRegistry
Definition
component_registry.hpp:35
SILICON::ui::DiagramSceneSerializer::loadCircuit
void loadCircuit(std::shared_ptr< Circuit > circuit, GUIComponentFactory &guiFactory, bool resolveSubcircuitMetadata=true)
Definition
diagramSceneSerializer.cpp:566
SILICON::ui::DiagramSceneSerializer::serializeItems
nlohmann::ordered_json serializeItems(const std::vector< QGraphicsItem * > &sceneItems) const
Serializes arbitrary scene items using the selection payload format.
Definition
diagramSceneSerializer.cpp:415
SILICON::ui::DiagramSceneSerializer::applyDeserialize
void applyDeserialize(std::shared_ptr< SceneLoadPlan > plan)
Replaces the host scene with a plan built by prepareDeserialize.
Definition
diagramSceneSerializer.cpp:535
SILICON::ui::DiagramSceneSerializer::scene
DiagramScene & scene
Host scene whose items and lookup tables back serialization operations.
Definition
diagramSceneSerializer.hpp:142
SILICON::ui::DiagramSceneSerializer::prepareDeserialize
std::shared_ptr< SceneLoadPlan > prepareDeserialize(const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
Parses a scene payload without touching the host scene.
Definition
diagramSceneSerializer.cpp:507
SILICON::ui::DiagramSceneSerializer::removeSelection
bool removeSelection(const nlohmann::json &payload)
Removes items matching a serialized selection payload from the scene.
Definition
diagramSceneSerializer.cpp:638
SILICON::ui::DiagramSceneSerializer::serialize
std::string serialize() const
Serializes the full editor scene to the persisted JSON format.
Definition
diagramSceneSerializer.cpp:354
SILICON::ui::DiagramSceneSerializer::deserialize
void deserialize(const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
Deserializes a full scene from persisted JSON.
Definition
diagramSceneSerializer.cpp:499
SILICON::ui::DiagramSceneSerializer::DiagramSceneSerializer
DiagramSceneSerializer(DiagramScene &scene)
Constructs a serializer bound to a scene.
Definition
diagramSceneSerializer.cpp:352
SILICON::ui::DiagramSceneSerializer::insertSelection
bool insertSelection(const nlohmann::json &payload, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry, QPointF targetOrigin, bool isPaste)
Inserts a serialized selection payload into the current scene.
Definition
diagramSceneSerializer.cpp:591
SILICON::ui::DiagramSceneSerializer::serializeSelection
nlohmann::ordered_json serializeSelection() const
Serializes the current selection to the clipboard payload format.
Definition
diagramSceneSerializer.cpp:410
SILICON::ui::DiagramScene
Graphics scene for the circuit diagram editor.
Definition
diagramScene.hpp:118
SILICON::ui::GUIComponentFactory
Factory for creating graphical circuit components.
Definition
gui_component_factory.hpp:55
SILICON::ui::GraphicalItem
Base class for all graphical items in the diagram.
Definition
graphicalItem.hpp:62
SILICON::ui::SceneLoadPlan
Scene payload deserialized ahead of time, detached from the host scene.
Definition
diagramSceneSerializer.cpp:336
component_registry.hpp
SILICON::core
Definition
activeKeyGuard.hpp:28
SILICON::ui
Definition
actionGroups.hpp:14
src
ui
circuit
diagram
scene
diagramSceneSerializer.hpp
Generated by
1.17.0