SILICON
Loading...
Searching...
No Matches
graphicalSubcircuit.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 <string>
21
22#include <QGraphicsItem>
23
24#include <core/subcircuit.hpp>
27
28namespace SILICON::project {
29class DocumentStore;
30}
31
32namespace SILICON::ui {
33 using namespace SILICON::core;
34
42 Q_OBJECT
43 public:
46 QGraphicsItem* parent = nullptr,
48 const CircuitResolver* resolver = nullptr);
49
58 std::string slug, QGraphicsItem* parent = nullptr,
60 const CircuitResolver* resolver = nullptr);
61
64
66 void setComponent(const Component_ptr& component) override;
67
70 void applyProperty(std::string_view key, const PropertyValue& value) override;
71
76 const CircuitResolver* resolver);
77
80
81 int type() const override { return SiliconTypes::SUBCIRCUIT; }
82
83 protected:
84 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
85
86 private:
87 std::uint64_t registryListenerId = 0;
89 bool refreshSuppressed = false;
90
93
95 [[nodiscard]] std::string currentSlug() const;
96
98 void applyMetadata(const GraphicalSubcircuitMetadata& metadata);
99
101 void updatePortSizes() override;
102 };
103
104} // namespace SILICON::ui
GraphicalLogicComponent(ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
void setProjectContext(const SILICON::project::DocumentStore *documents, const CircuitResolver *resolver)
Attaches project metadata and resolver in one refresh.
~GraphicalSubcircuitComponent() override
Unregisters the subcircuit registry listener.
const SILICON::project::DocumentStore * documents
void applyProperty(std::string_view key, const PropertyValue &value) override
Applies a component property and refreshes metadata when the slug changes.
void useAttachedInterfaceMetadata()
Uses default metadata derived only from the attached imported buses.
void applyMetadata(const GraphicalSubcircuitMetadata &metadata)
Applies parsed metadata to the rendered shape and ports.
void setComponent(const Component_ptr &component) override
Replaces the associated core subcircuit component.
void refreshFromMetadata()
Reloads shape and ports from the active registry document.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
void updatePortSizes() override
Rebuilds visible ports when subcircuit I/O shape changes.
GraphicalSubcircuitComponent(QGraphicsItem *parent=nullptr, const SILICON::project::DocumentStore *documents=nullptr, const CircuitResolver *resolver=nullptr)
Creates a graphical subcircuit with an empty slug.
std::string currentSlug() const
Returns the slug stored by the associated core component.
std::shared_ptr< Component > Component_ptr
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
Visual metadata used to render a subcircuit as a reusable component.
Definition metadata.hpp:74