SILICON
Loading...
Searching...
No Matches
GraphicalIO Class Referenceabstract

Abstract base class for all graphical Input and Output components. More...

#include <graphicalIO.hpp>

Inheritance diagram for GraphicalIO:
Collaboration diagram for GraphicalIO:

Signals

void inputToggled (Bus targetBus, BusValue value, Component_weakPtr source)
 Emitted when an input component changes its state.

Public Member Functions

QPoint portPositionFor (PortSide side) const
 Returns the local port position for a proposed cardinal side.
QRectF collisionRectForPortSide (PortSide side) const
 Returns local wire-obstacle bounds for a proposed port side.
void setPortOrientation (PortSide side)
 Persists and applies a cardinal port orientation.
virtual void handleSimulationClick ()
 Called when the user clicks on the component during a live simulation.
virtual void applyStartValue ()=0
 Applies the default starting value configured in the component's properties.
virtual void resetSimulationState ()=0
 Resets the visual state to its initial simulation state.
void setComponent (const Component_ptr &component) override
 Sets the associated logical component.
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.
void applyProperty (std::string_view key, const PropertyValue &value) override
 Applies a component property while notifying Qt about possible geometry changes.
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 ()

Static Public Attributes

static const QFont UI_FONT {"NovaMono", 12}
 Shared, highly-optimized UI font for all IO components. Using an inline static font prevents allocating a QFont object for every component.

Protected Member Functions

 GraphicalIO (ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent=nullptr, bool scanShape=false)
 Constructs a GraphicalIO item.
QString getComponentName () const
 Safely retrieves the user-defined name of this component.
void installPortOrientationCallback ()
 Installs the callback that moves the IO port when orientation changes.
void updatePortOrientation ()
 Rebuilds the single IO port based on the current orientation property.
void updatePortOrientation (std::string_view orientation)
 Rebuilds the single IO port using an explicit orientation value.
bool isPortOrientationUp () const
 Returns true when the IO port is currently placed above the shape.
QRectF componentNameRect (const QString &name) const
 Returns the label rectangle for the current orientation.
Protected Member Functions inherited from GraphicalLogicComponent
void refreshComponentIOListener ()
 Installs the listener that keeps graphical ports synced to bus sizes.
virtual void updatePortSizes ()
 Copies associated component bus sizes into graphical ports.
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

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

Abstract base class for all graphical Input and Output components.

Definition at line 62 of file graphicalIO.hpp.

Constructor & Destructor Documentation

◆ GraphicalIO()

GraphicalIO ( ItemCategory category,
const Component_ptr & component,
QGraphicsItem * shape,
QGraphicsItem * parent = nullptr,
bool scanShape = false )
protected

Constructs a GraphicalIO item.

Parameters
categoryThe category of the item (Input or Output).
componentThe underlying core logic component.
shapeThe visual QGraphicsItem representing the component.
parentOptional parent QGraphicsItem.
scanShapeWhether to automatically scan the shape for port locations.

Definition at line 438 of file graphicalIO.cpp.

Member Function Documentation

◆ applyStartValue()

virtual void applyStartValue ( )
pure virtual

Applies the default starting value configured in the component's properties.

Implemented in GraphicalBusInput, GraphicalBusOutput, GraphicalInput, and GraphicalOutputSingle.

◆ collisionRectForPortSide()

QRectF collisionRectForPortSide ( PortSide side) const
nodiscard

Returns local wire-obstacle bounds for a proposed port side.

Definition at line 534 of file graphicalIO.cpp.

◆ componentNameRect()

QRectF componentNameRect ( const QString & name) const
nodiscardprotected

Returns the label rectangle for the current orientation.

Definition at line 512 of file graphicalIO.cpp.

◆ getComponentName()

QString getComponentName ( ) const
nodiscardprotected

Safely retrieves the user-defined name of this component.

Returns
A QString containing the name, or an empty string if none is set.

Definition at line 445 of file graphicalIO.cpp.

◆ handleSimulationClick()

virtual void handleSimulationClick ( )
inlinevirtual

Called when the user clicks on the component during a live simulation.

Reimplemented in GraphicalBusInput, and GraphicalInput.

Definition at line 116 of file graphicalIO.hpp.

◆ inputToggled

void inputToggled ( Bus targetBus,
BusValue value,
Component_weakPtr source )
signal

Emitted when an input component changes its state.

Parameters
targetBusThe bus that is being driven by this input.
valueThe new numerical value of the input.
sourceA weak pointer to the logic component that triggered the change.

◆ installPortOrientationCallback()

void installPortOrientationCallback ( )
protected

Installs the callback that moves the IO port when orientation changes.

Definition at line 456 of file graphicalIO.cpp.

◆ isPortOrientationUp()

bool isPortOrientationUp ( ) const
nodiscardprotected

Returns true when the IO port is currently placed above the shape.

Definition at line 504 of file graphicalIO.cpp.

◆ portPositionFor()

QPoint portPositionFor ( PortSide side) const
nodiscard

Returns the local port position for a proposed cardinal side.

Definition at line 526 of file graphicalIO.cpp.

◆ resetSimulationState()

virtual void resetSimulationState ( )
pure virtual

Resets the visual state to its initial simulation state.

Implemented in GraphicalBusInput, GraphicalBusOutput, GraphicalInput, and GraphicalOutputSingle.

◆ setComponent()

void setComponent ( const Component_ptr & component)
overridevirtual

Sets the associated logical component.

Parameters
componentThe component to associate

Reimplemented from GraphicalLogicComponent.

Definition at line 551 of file graphicalIO.cpp.

◆ setPortOrientation()

void setPortOrientation ( PortSide side)

Persists and applies a cardinal port orientation.

Definition at line 543 of file graphicalIO.cpp.

◆ updatePortOrientation() [1/2]

void updatePortOrientation ( )
protected

Rebuilds the single IO port based on the current orientation property.

Definition at line 476 of file graphicalIO.cpp.

◆ updatePortOrientation() [2/2]

void updatePortOrientation ( std::string_view orientation)
protected

Rebuilds the single IO port using an explicit orientation value.

Definition at line 484 of file graphicalIO.cpp.

Member Data Documentation

◆ UI_FONT

const QFont UI_FONT {"NovaMono", 12}
inlinestatic

Shared, highly-optimized UI font for all IO components. Using an inline static font prevents allocating a QFont object for every component.

Definition at line 102 of file graphicalIO.hpp.


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