26#include <QScopedValueRollback>
31 using namespace SILICON::core;
35 [[nodiscard]] std::vector<PortPair>
36 portPairs(
const std::vector<GraphicalSubcircuitPortMetadata>& ports)
38 std::vector<PortPair> result;
39 result.reserve(ports.size());
40 for (
const auto& port : ports)
41 result.emplace_back(QString::fromStdString(
port.name),
port.position);
69 const bool affectsConfiguredDocument =
75 || affectsConfiguredDocument) {
78 if (
const auto subcircuit =
80 subcircuit->reloadFromResolver();
95 std::string slug, QGraphicsItem* parent,
128 if (
const auto subcircuit =
130 subcircuit->setCircuitResolver(newResolver);
171 prepareGeometryChange();
189 if (
inputPorts.size() != componentInputs.size()
190 ||
outputPorts.size() != componentOutputs.size()) {
216 const auto json = nlohmann::json::parse(document->getContents(),
nullptr,
false);
217 const auto subcircuit =
222 subcircuit ? subcircuit->circuitResolver() :
nullptr);
228 if (metadata.inputs.size() != componentInputs.size())
231 if (metadata.outputs.size() != componentOutputs.size())
251 if (
const auto imported =
253 const auto& inputNames = imported->importedInputNames();
254 for (std::size_t i = 0; i < std::min(metadata.
inputs.size(), inputNames.size());
256 metadata.
inputs[i].name = inputNames[i];
257 const auto& outputNames = imported->importedOutputNames();
258 for (std::size_t i = 0; i < std::min(metadata.
outputs.size(), outputNames.size());
260 metadata.
outputs[i].name = outputNames[i];
void clearPorts()
Removes existing input/output ports and their line items.
std::vector< Port * > outputPorts
Output connection ports.
bool printPortNames
Whether to print port names.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Handles double-clicks not consumed by a component-specific action.
bool openDocumentOnDoubleClick(QGraphicsSceneMouseEvent *event, const std::string &path)
Queues document navigation for a left double-click in normal mode.
std::vector< Port * > inputPorts
Input connection ports.
void setItemShape(QGraphicsItem *shape)
Sets the component shape graphics item.
virtual void updatePortSizes()
Copies associated component bus sizes into graphical ports.
void setPorts(const std::vector< PortPair > &busToPortInputs, const std::vector< PortPair > &busToPortOutputs) override
Sets ports and validates against component I/O.
void applyProperty(std::string_view key, const PropertyValue &value) override
Applies a component property while notifying Qt about possible geometry changes.
GraphicalLogicComponent(ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
virtual void setComponent(const Component_ptr &component)
Sets the associated logical component.
Component_ptr associatedComponent
The logical component this graphical component represents.
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 unsubscribeFromDocuments()
std::uint64_t registryListenerId
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 subscribeToDocuments()
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.
RTLIL::SigSpec port(RTLIL::Module *module, RTLIL::Cell *cell, RTLIL::IdString key, int expected)
std::shared_ptr< Component > Component_ptr
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
std::string documentPathForSlug(const DocumentType type, const std::string_view slug)
bool isValidDocumentSlug(const std::string_view slug)
QSize defaultGraphicalSubcircuitSize(std::size_t inputCount, std::size_t outputCount)
Default square dimensions for the boundary port counts, in pixels.
std::optional< GraphicalSubcircuitMetadata > parseGraphicalSubcircuitMetadata(const nlohmann::json &document)
Parses graphical subcircuit metadata from a scene document.
GraphicalSubcircuitMetadata synchronizeGraphicalSubcircuitMetadata(const nlohmann::json &document, const GraphicalSubcircuitMetadata &fallbackMetadata, const CircuitResolver *resolver)
Reconciles saved graphical metadata with the current circuit document.
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...
std::optional< std::string > path