SILICON
Loading...
Searching...
No Matches
GraphicalSubcircuitComponent Class Reference

Graphical component wrapper for a registered subcircuit. More...

#include <graphicalSubcircuit.hpp>

Inheritance diagram for GraphicalSubcircuitComponent:
Collaboration diagram for GraphicalSubcircuitComponent:

Public Member Functions

 GraphicalSubcircuitComponent (QGraphicsItem *parent=nullptr, const SILICON::project::DocumentStore *documents=nullptr, const CircuitResolver *resolver=nullptr)
 Creates a graphical subcircuit with an empty slug.
 GraphicalSubcircuitComponent (std::string slug, QGraphicsItem *parent=nullptr, const SILICON::project::DocumentStore *documents=nullptr, const CircuitResolver *resolver=nullptr)
 Creates a graphical subcircuit and immediately selects a slug.
 ~GraphicalSubcircuitComponent () override
 Unregisters the subcircuit registry listener.
void setComponent (const Component_ptr &component) override
 Replaces the associated core subcircuit component.
void applyProperty (std::string_view key, const PropertyValue &value) override
 Applies a component property and refreshes metadata when the slug changes.
void refreshFromMetadata ()
 Reloads shape and ports from the active registry document.
void setProjectContext (const SILICON::project::DocumentStore *documents, const CircuitResolver *resolver)
 Attaches project metadata and resolver in one refresh.
void useAttachedInterfaceMetadata ()
 Uses default metadata derived only from the attached imported buses.
int type () const override
Public Member Functions inherited from GraphicalLogicComponent
 GraphicalLogicComponent (const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
 Constructs a logic component.
 ~GraphicalLogicComponent () override
void setPorts (const std::vector< PortPair > &busToPortInputs, const std::vector< PortPair > &busToPortOutputs) override
 Sets ports and validates against component I/O.
virtual void assignInputPortBus (unsigned int portIndex, const Bus &bus) const
 Assigns a bus connected to a visible input port.
Component_ptr getComponent () const
 Gets the associated logical component.
const PropertyMap & getProperties () const override
 Properties exposed by graphical and simulation components alike.
std::optional< std::reference_wrapper< const StringPropertyOptions > > getStringPropertyOptions (std::string_view key) const override
std::string getTypeName () const override
 Gets the component type name for serialization.
Public Member Functions inherited from GraphicalComponent
std::optional< PropertyValue > getProperty (std::string_view key) const
virtual bool isMultilineProperty (std::string_view key) const
bool isPropertyHidden (std::string_view key) const
 Whether a property is omitted from the properties panel.
virtual bool participatesInCollisions () const
 Annotations remain selectable but do not obstruct placement or routing.
virtual std::span< const ResizeHandle > resizeHandles () const
virtual QRectF resizeBounds () const
virtual PropertyMap resizedProperties (QSizeF size, ResizeHandle handle, const PropertyMap &initial)
std::optional< ResizeHandle > resizeHandleAt (QPointF localPos) const
bool resizeHandlesVisible () const
ComponentResizeState resizeState () const
void applyResizeState (const ComponentResizeState &state)
void modeChanged (InteractionMode mode) override
 Called when the interaction mode changes.
void prepareSceneBoundsChange ()
 Prepares a geometry edit and checks its final bounds on the event loop.
QRectF collisionRectForWires () const
 Gets the collision rectangle extended for wire connections.
 GraphicalComponent (QGraphicsItem *shape, QGraphicsItem *parent=nullptr, bool scanShape=false)
void rotate ()
 Rotates the component by 90 degrees.
const std::vector< Port * > & getInputPorts () const
 Borrows input ports; copy before replacing the component ports.
const std::vector< Port * > & getOutputPorts () const
 Borrows output ports; copy before replacing the component ports.
auto getPorts () const
 Borrows every port, inputs first, without copying or deduplicating.
virtual nlohmann::ordered_json serialize () const
 Serializes the component to JSON.
virtual void loadSerializedState (const nlohmann::json &j)
 Loads subclass-specific serialized state.
Public Member Functions inherited from GraphicalItem
 GraphicalItem (ItemCategory category=ItemCategory::GraphicalItem, QGraphicsItem *parent=nullptr)
 ~GraphicalItem () override
void setCollidingStatus (CollidingStatus newStatus)
 Sets the collision status.
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Handles item change events.
int type () const override
 Returns the item type identifier.
bool isColliding () const
 Checks if the item is colliding.
QPointF getInitialPosition () const
 Gets the original position of the item before it started moving.
qreal getInitialRotation () const
uint64_t getUiId () const
void setInitialPosition ()
 Sets the initialPosition of the item to its current position (should be used when placed).
void setInitialRotation ()
void setUiId (uint64_t newUiId)
void setOwningScene (DiagramScene *scene)
void setGeometryPosition (QPointF position)
virtual void updateTopology ()

Protected Member Functions

void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override
Protected Member Functions inherited from GraphicalLogicComponent
void refreshComponentIOListener ()
 Installs the listener that keeps graphical ports synced to bus sizes.
virtual bool acceptsInputPortCount (size_t portCount, const std::vector< Bus > &componentInputs) const
 Checks whether a visible input port count is valid for this component.
virtual unsigned int inputPortSize (size_t portIndex, const std::vector< Bus > &componentInputs) const
 Returns the visible size for an input port.
 GraphicalLogicComponent (ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
Protected Member Functions inherited from GraphicalComponent
void setItemShape (QGraphicsItem *shape)
 Sets the component shape graphics item.
QGraphicsItem * getItemShape () const
 Gets the component shape.
QRectF boundingRect () const override
 Gets bounding rectangle with selection margin.
QRectF boundingRectWithoutMargins () const
 Gets bounding rectangle without margins.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 Paints the component (selection outline).
QRectF getCollisionRect () const override
 Gets physical body and port line bounds for drag/drop.
bool canRotate () const override
 Components can rotate by default.
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override
 Handles double-clicks not consumed by a component-specific action.
void hoverMoveEvent (QGraphicsSceneHoverEvent *event) override
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override
bool openDocumentOnDoubleClick (QGraphicsSceneMouseEvent *event, const std::string &path)
 Queues document navigation for a left double-click in normal mode.
void setPortLine (Port *port)
 Creates the connecting line from port to shape.
void clearPorts ()
 Removes existing input/output ports and their line items.
 GraphicalComponent (ItemCategory category, QGraphicsItem *shape, QGraphicsItem *parent=nullptr, bool scanShape=false)
Protected Member Functions inherited from GraphicalItem
virtual void onPositionChanged (QPointF offset)
 Called when the item position changes.
CollidingStatus getCollidingStatus () const
 Gets the current collision status.
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
void mousePressEvent (QGraphicsSceneMouseEvent *event) override

Private Member Functions

void subscribeToDocuments ()
void unsubscribeFromDocuments ()
std::string currentSlug () const
 Returns the slug stored by the associated core component.
void applyMetadata (const GraphicalSubcircuitMetadata &metadata)
 Applies parsed metadata to the rendered shape and ports.
void updatePortSizes () override
 Rebuilds visible ports when subcircuit I/O shape changes.

Private Attributes

std::uint64_t registryListenerId = 0
const SILICON::project::DocumentStore * documents = nullptr
bool refreshSuppressed = false

Additional Inherited Members

Static Public Member Functions inherited from GraphicalComponent
static std::unique_ptr< GraphicalComponent > deserialize (const nlohmann::json &j, GUIComponentFactory &factory)
 Deserializes a component from JSON using the factory.
Static Public Member Functions inherited from GraphicalItem
static uint64_t generateUiId ()
Protected Attributes inherited from GraphicalLogicComponent
Component_ptr associatedComponent
 The logical component this graphical component represents.
uint64_t componentIOListenerId = 0
 Listener id for associated component I/O changes.
bool isEditable = false
 Whether the component allows property editing.
Protected Attributes inherited from GraphicalComponent
std::unordered_set< std::string, TransparentStringHash, std::equal_to<> > hiddenProperties
 Property names hidden from the panel, still accessible and serialized. Add names in subclasses with hiddenProperties.insert("propertyName").
std::vector< Port * > inputPorts
 Input connection ports.
std::vector< Port * > outputPorts
 Output connection ports.
bool boundsUpdatePending = false
bool scanShape = false
 Whether to scan shape alpha for port placement.
bool printPortNames = false
 Whether to print port names.

Detailed Description

Graphical component wrapper for a registered subcircuit.

The component listens for subcircuit registry changes and redraws its rectangle and ports from the selected subcircuit's graphical metadata.

Definition at line 41 of file graphicalSubcircuit.hpp.

Constructor & Destructor Documentation

◆ GraphicalSubcircuitComponent() [1/2]

GraphicalSubcircuitComponent ( QGraphicsItem * parent = nullptr,
const SILICON::project::DocumentStore * documents = nullptr,
const CircuitResolver * resolver = nullptr )
explicit

Creates a graphical subcircuit with an empty slug.

Definition at line 47 of file graphicalSubcircuit.cpp.

◆ GraphicalSubcircuitComponent() [2/2]

GraphicalSubcircuitComponent ( std::string slug,
QGraphicsItem * parent = nullptr,
const SILICON::project::DocumentStore * documents = nullptr,
const CircuitResolver * resolver = nullptr )
explicit

Creates a graphical subcircuit and immediately selects a slug.

Parameters
slugSubcircuit registry slug.
parentOptional parent graphics item.
documentsOptional document store for resolving subcircuit metadata.
resolverOptional resolver for dependent circuits.

Definition at line 94 of file graphicalSubcircuit.cpp.

◆ ~GraphicalSubcircuitComponent()

Unregisters the subcircuit registry listener.

Definition at line 103 of file graphicalSubcircuit.cpp.

Member Function Documentation

◆ applyMetadata()

void applyMetadata ( const GraphicalSubcircuitMetadata & metadata)
private

Applies parsed metadata to the rendered shape and ports.

Definition at line 168 of file graphicalSubcircuit.cpp.

◆ applyProperty()

void applyProperty ( std::string_view key,
const PropertyValue & value )
overridevirtual

Applies a component property and refreshes metadata when the slug changes.

Reimplemented from GraphicalLogicComponent.

Definition at line 135 of file graphicalSubcircuit.cpp.

◆ currentSlug()

std::string currentSlug ( ) const
nodiscardprivate

Returns the slug stored by the associated core component.

Definition at line 146 of file graphicalSubcircuit.cpp.

◆ mouseDoubleClickEvent()

void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Definition at line 155 of file graphicalSubcircuit.cpp.

◆ refreshFromMetadata()

void refreshFromMetadata ( )

Reloads shape and ports from the active registry document.

Definition at line 198 of file graphicalSubcircuit.cpp.

◆ setComponent()

void setComponent ( const Component_ptr & component)
overridevirtual

Replaces the associated core subcircuit component.

Reimplemented from GraphicalLogicComponent.

Definition at line 108 of file graphicalSubcircuit.cpp.

◆ setProjectContext()

void setProjectContext ( const SILICON::project::DocumentStore * documents,
const CircuitResolver * resolver )

Attaches project metadata and resolver in one refresh.

Definition at line 117 of file graphicalSubcircuit.cpp.

◆ subscribeToDocuments()

void subscribeToDocuments ( )
private

Definition at line 62 of file graphicalSubcircuit.cpp.

◆ type()

int type ( ) const
inlineoverride

Definition at line 81 of file graphicalSubcircuit.hpp.

◆ unsubscribeFromDocuments()

void unsubscribeFromDocuments ( )
private

Definition at line 87 of file graphicalSubcircuit.cpp.

◆ updatePortSizes()

void updatePortSizes ( )
overrideprivatevirtual

Rebuilds visible ports when subcircuit I/O shape changes.

Reimplemented from GraphicalLogicComponent.

Definition at line 181 of file graphicalSubcircuit.cpp.

◆ useAttachedInterfaceMetadata()

void useAttachedInterfaceMetadata ( )

Uses default metadata derived only from the attached imported buses.

Definition at line 239 of file graphicalSubcircuit.cpp.

Member Data Documentation

◆ documents

const SILICON::project::DocumentStore* documents = nullptr
private

Definition at line 88 of file graphicalSubcircuit.hpp.

◆ refreshSuppressed

bool refreshSuppressed = false
private

Definition at line 89 of file graphicalSubcircuit.hpp.

◆ registryListenerId

std::uint64_t registryListenerId = 0
private

Definition at line 87 of file graphicalSubcircuit.hpp.


The documentation for this class was generated from the following files: