SILICON
Loading...
Searching...
No Matches
metadata.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 <cstddef>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include <nlohmann/json.hpp>
27
28#include <QPoint>
29#include <QSize>
30
31#include <core/wire.hpp>
33
34namespace SILICON::core {
35class CircuitResolver;
36}
37
38namespace SILICON::ui {
39using namespace SILICON::core;
40
42
44inline constexpr int GRAPHICAL_SUBCIRCUIT_DEFAULT_SIZE = 2;
45
47[[nodiscard]] QSize defaultGraphicalSubcircuitSize(std::size_t inputCount,
48 std::size_t outputCount);
49
58 std::string name;
60 QPoint position;
62 unsigned int busSize = 1;
64 uint64_t id = 0;
65};
66
78
79 bool autoSize = true;
83 std::vector<GraphicalSubcircuitPortMetadata> inputs;
85 std::vector<GraphicalSubcircuitPortMetadata> outputs;
86};
87
93[[nodiscard]] std::optional<GraphicalSubcircuitMetadata>
94parseGraphicalSubcircuitMetadata(const nlohmann::json& document);
95
101[[nodiscard]] bool subcircuitHasGraphicalMetadata(std::string_view sceneJson);
102
119 const nlohmann::json& document, const GraphicalSubcircuitMetadata& fallbackMetadata,
120 const CircuitResolver* resolver = nullptr);
121
126[[nodiscard]] std::vector<GraphicalSubcircuitPortMetadata> synchronizePortsWithBuses(
127 const std::vector<GraphicalSubcircuitPortMetadata>& fallbackPorts,
128 const std::vector<Bus>& buses, const GraphicalSubcircuitMetadata& metadata,
129 bool inputPort);
130
136[[nodiscard]] nlohmann::ordered_json
138
139} // namespace SILICON::ui
QSize defaultGraphicalSubcircuitSize(std::size_t inputCount, std::size_t outputCount)
Default square dimensions for the boundary port counts, in pixels.
Definition metadata.cpp:215
constexpr int GRID_SIZE
Definition grid.hpp:27
std::optional< GraphicalSubcircuitMetadata > parseGraphicalSubcircuitMetadata(const nlohmann::json &document)
Parses graphical subcircuit metadata from a scene document.
Definition metadata.cpp:224
bool subcircuitHasGraphicalMetadata(std::string_view sceneJson)
Checks whether a scene document contains valid graphical metadata.
Definition metadata.cpp:269
nlohmann::ordered_json graphicalSubcircuitMetadataToJson(const GraphicalSubcircuitMetadata &metadata)
Serializes graphical metadata to the JSON shape/port object.
Definition metadata.cpp:324
GraphicalSubcircuitMetadata synchronizeGraphicalSubcircuitMetadata(const nlohmann::json &document, const GraphicalSubcircuitMetadata &fallbackMetadata, const CircuitResolver *resolver)
Reconciles saved graphical metadata with the current circuit document.
Definition metadata.cpp:276
std::vector< GraphicalSubcircuitPortMetadata > synchronizePortsWithBuses(const std::vector< GraphicalSubcircuitPortMetadata > &fallbackPorts, const std::vector< Bus > &buses, const GraphicalSubcircuitMetadata &metadata, const bool inputPort)
Reconciles metadata when a loaded subcircuit component has a different bus count than its saved graph...
Definition metadata.cpp:298
constexpr int GRAPHICAL_SUBCIRCUIT_DEFAULT_SIZE
Default subcircuit rectangle size in persisted grid units.
Definition metadata.hpp:44
Visual metadata used to render a subcircuit as a reusable component.
Definition metadata.hpp:74
std::vector< GraphicalSubcircuitPortMetadata > inputs
Input boundary ports in core interface order.
Definition metadata.hpp:83
PortPositioning positioning
One positioning mode for all input and output ports of the shape.
Definition metadata.hpp:81
std::vector< GraphicalSubcircuitPortMetadata > outputs
Output boundary ports in core interface order.
Definition metadata.hpp:85
QSize widthHeight
Rectangle dimensions in pixels.
Definition metadata.hpp:76
bool autoSize
Derive dimensions from port counts until the user edits the size.
Definition metadata.hpp:79
Visual metadata for one subcircuit boundary port.
Definition metadata.hpp:56
QPoint position
Port connection point in pixels, relative to the rectangle top-left.
Definition metadata.hpp:60
std::string name
Display label derived from the core boundary name.
Definition metadata.hpp:58
unsigned int busSize
Number of wires represented by the port.
Definition metadata.hpp:62