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

Graphics scene for the circuit diagram editor. More...

#include <diagramScene.hpp>

Inheritance diagram for DiagramScene:
Collaboration diagram for DiagramScene:

Classes

struct  ComponentResizeTransaction
struct  RouteEditState
struct  ComponentDragState
struct  MixedDragItem
struct  WireDragState

Public Types

enum class  InteractionMode {
  NORMAL_MODE , PAN_MODE , WIRE_CREATION_MODE , COMPONENT_PLACING_MODE ,
  SIMULATION_MODE
}
 Operating modes for the diagram scene. More...

Public Slots

void hideCSB ()
 Hides the component search box.
void handleInputToggled (Bus targetBus, BusValue value, Component_weakPtr source)
 Handles input toggle events from GraphicalInput components.
bool calculateWiresForComponents ()
const ConnectionReport & currentConnectionReport ()
 Returns the cached connection report, refreshing it first when dirty.
void requestConnectionsRefresh ()
 Marks connections dirty and schedules one refresh on the event loop.
void refreshConnections ()
 Rebuilds the connection report, logical bindings, and visual error markers.

Signals

void componentResized ()
void logsClearRequested ()
void modeChanged (InteractionMode mode)
 Emitted when the interaction mode changes.
void waveformTraceReset (QStringList signalNames, int inputCount, QList< int > signalWidths)
 Emitted when interactive waveform signals should be rebuilt.
void waveformTraceSnapshots (QList< QPair< qulonglong, std::vector< BusValue > > > snapshots)
 Emitted when a completed simulation job produced multiple waveform states.

Public Member Functions

 DiagramScene (QObject *parent=nullptr)
 Constructs a diagram scene.
void expandSceneBounds (const QRectF &bounds)
 Grows the workspace in quantized steps to include scene coordinates.
void setDocumentStore (const SILICON::project::DocumentStore *documents) noexcept
const SILICON::project::DocumentStore * documentStore () const noexcept
void setCircuitResolver (const CircuitResolver *resolver) noexcept
const CircuitResolver * circuitResolver () const noexcept
void setUndoStack (QUndoStack *stack) noexcept
void setDocumentNavigator (DocumentNavigator *navigator) noexcept
DocumentNavigator * getDocumentNavigator () const noexcept
void setInteractionMode (InteractionMode mode)
 Sets the interaction mode.
bool cancelCurrentInteraction ()
 Cancels the active transient interaction, returning to normal editing.
bool beginComponentResize (GraphicalComponent *component, ResizeHandle handle, QPointF scenePos)
void updateComponentResize (QPointF scenePos)
void finishComponentResize ()
void cancelComponentResize ()
bool isResizingComponent () const
InteractionMode getInteractionMode () const
 Gets the current interaction mode.
GraphicalComponent * getComponentToBeDrawn () const
 Gets the component currently being placed.
bool isWireCreationInProgress () const
 Returns whether a wire currently has a starting endpoint and is being routed.
void showCSB (QPointF pos)
 Shows the component search box at a position.
void clearWireShadow ()
 Clears the wire being drawn.
void setComponentShadow ()
 Shows the component shadow at cursor position.
void clearComponentShadow ()
 Clears the component shadow.
void addComponent (GraphicalComponent *component, QPointF pos)
 Adds a component to the scene.
void placeComponent (std::string_view typeName, bool showSearchBox=true, const PropertyMap &initialProperties={})
 Begins placing a component and applies its initial properties first.
void rememberIoPlacementOrientation (const Component &component)
 Remembers a user IO orientation edit for subsequent placements.
QUndoStack * getUndoStack () const
WireManager & getWireManager ()
const WireManager & getWireManager () const
bool beginWireDrag (GraphicalWireSegment *segment, QPointF scenePos, QPointF localPos)
 Starts dragging the wire handle hit at a local position.
void updateWireDrag (GraphicalWireSegment *segment, QPointF scenePos)
 Previews the active segment drag at the given scene position.
void finishWireDrag (GraphicalWireSegment *segment)
 Commits the active segment drag and records its undo command.
void cancelWireDrag ()
 Restores original wire routes and clears the active wire drag.
bool isDraggingWire (const GraphicalWireSegment *segment) const
 Returns whether the segment owns the active wire drag.
std::vector< WireRouteChange > finishComponentDrag ()
 Commits the component gesture and returns its before and after wire routes.
void applyWireRouteChanges (std::span< const WireRouteChange > changes, bool useAfter, const WireEndpointEdit &endpointEdit={})
 Applies recorded wire routes and rebuilds connectivity.
void applyItemMoves (std::span< const ItemPositionChange > moves, std::span< const WireRouteChange > wires, bool useAfter, const WireEndpointEdit &topology={})
 Applies recorded item positions and wire routes and rebuilds connectivity.
std::shared_ptr< Circuit > getCircuit () const
void setCircuit (std::shared_ptr< Circuit > newCircuit)
 Replaces the derived topology cache.
void setDocumentCircuit (std::shared_ptr< Circuit > newCircuit)
 Installs an authoritative circuit.
void setIoInteractionsEnabled (bool enabled)
 Enables or disables user-triggered IO interactions in simulation mode.
void setSubcircuitDocumentMode (bool enabled)
 Enables reusable-circuit boundary I/O editing for the scene.
bool isSubcircuitDocumentMode () const
 Returns true when subcircuit-only graphical tools may be placed.
std::string serialize () const
 Serializes the full editor scene to JSON.
nlohmann::ordered_json serializeSelection () const
 Serializes the selected components and wire segments for clipboard use.
nlohmann::ordered_json serializeItems (const std::vector< QGraphicsItem * > &sceneItems) const
 Serializes arbitrary scene items using the internal selection payload format.
GraphicalItem * findGraphicalItemByUiId (uint64_t uiId) const
void registerGraphicalItem (GraphicalItem *item)
void unregisterGraphicalItem (GraphicalItem *item)
bool itemCollisionChecksEnabled () const
void setItemCollisionChecksEnabled (bool enabled)
bool isDraggingComponent (const GraphicalComponent *component) const
 Returns whether the component participates in an active component or mixed drag.
bool isWireAttachedToDraggedComponent (const GraphicalComponent *component, const GraphicalWire *wire) const
 Returns whether a wire was attached to the component when its drag began.
bool hasWireGroupSelection () const
 Returns whether the selection includes a wire and a component, or multiple wires.
WireEndpointEdit finishMixedDrag ()
 Commits a mixed selection drag and returns topology and net changes for undo.
void deserialize (const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
 Deserializes a full scene from JSON.
std::shared_ptr< SceneLoadPlan > prepareDeserialize (const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
 Deserializes a scene payload into a detached plan.
void applyDeserialize (std::shared_ptr< SceneLoadPlan > plan)
 Replaces the scene contents with a prepared plan.
void loadCircuit (std::shared_ptr< Circuit > circuit, GUIComponentFactory &guiFactory, bool resolveSubcircuitMetadata=true)
bool insertSelection (const nlohmann::json &payload, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry, QPointF targetOrigin, bool isPaste=false)
 Inserts a clipboard selection payload into the current scene.
void removeItems (const std::vector< QGraphicsItem * > &sceneItems)
 Removes the given scene items and refreshes the logical topology.
void autoPlaceCircuit ()
 Automatically places components and reroutes wires.
bool removeSelection (const nlohmann::json &payload)
 Removes items matching a serialized selection payload from the current scene.
void clear (bool clearUndoStack=true, bool clearLogs=true)
void updateSceneAfterEdit ()
void setFstTraceFile (std::optional< std::string > fileName)
 Enables or disables simulation FST tracing.
bool isFstTracingEnabled () const
void simulateEditedWaveform (qulonglong duration, std::vector< Sample > inputSnapshots)
 Simulates the circuit using an edited input waveform.
 ~DiagramScene () override

Static Public Member Functions

static QPoint snapToGrid (QPointF point)
 Snaps a point to the grid.
static int snapToGrid (qreal value)
 Snaps one scene coordinate to the grid.

Static Public Attributes

static constexpr int GRID_SIZE = SILICON::ui::GRID_SIZE
 Grid cell size in scene units.

Private Member Functions

void drawBackground (QPainter *painter, const QRectF &rect) override
 Draws the background grid.
void drawForeground (QPainter *painter, const QRectF &rect) override
 Draws helper items on the scene foreground.
void initializeSceneBounds (qreal expansionStep)
void setInteractionMode (InteractionMode newMode, bool force)
 Internal method to set mode with force option.
bool isWireCompletionPoint (QPointF scenePoint) const
 Lifecycle helper methods for interaction modes.
void updateWirePreview (QPointF scenePoint)
 Updates the route preview for the wire being drawn toward a scene position.
void finalizeWireCreation ()
void enterComponentPlacingMode ()
void exitComponentPlacingMode ()
bool enterSimulationMode ()
void exitSimulationMode ()
void mouseMoveEvent (QGraphicsSceneMouseEvent *mouseEvent) override
 Handles mouse movement for wire/component dragging.
void mousePressEvent (QGraphicsSceneMouseEvent *mouseEvent) override
 Handles mouse press for wire drawing and component placement.
void mouseReleaseEvent (QGraphicsSceneMouseEvent *mouseEvent) override
void keyPressEvent (QKeyEvent *event) override
 Handles key presses for mode changes.
NetConnection inspectConnection (const std::vector< GraphicalWire * > &wires) const
 Inspects the combined wire group for width and driver compatibility.
std::unique_ptr< InteractiveWireRouter > makeInteractiveRouter () const
 Creates a router snapshot from current components, routes, and electrical vertices.
QPointF resolveWireTarget (QPointF scenePoint) const
 Resolves a scene position to a nearby port, wire, or grid point.
void beginComponentDrag ()
 Captures selected component positions, attached wires, and routing geometry.
void updateComponentDrag ()
 Previews component moves and restores the last valid positions if routing fails.
void cancelComponentDrag ()
 Restores original component positions and wire geometry.
void beginMixedDrag ()
 Captures item positions, attached wires, and topology for a mixed selection drag.
void updateMixedDrag ()
 Validates mixed selection movement and retains the last valid positions.
void cancelMixedDrag ()
 Restores original item positions and clears the mixed drag state.
void applyRoutingPreview (const std::vector< RoutedSegment > &routes, RouteEditState &state)
 Applies preview routes while recording original geometry in the edit state.

Private Attributes

qreal sceneExpansionStep = 0
InteractionMode currentInteractionMode = InteractionMode::NORMAL_MODE
 Current interaction mode.
bool ioInteractionsEnabled = true
 Whether simulation-mode IO clicks may mutate input state.
bool subcircuitDocumentMode = false
 Whether reusable-circuit boundary I/O editing is enabled.
const SILICON::project::DocumentStore * documents = nullptr
const CircuitResolver * resolver = nullptr
QUndoStack * undoStack = nullptr
DocumentNavigator * documentNavigator = nullptr
struct SILICON::ui::DiagramScene::ComponentResizeTransaction componentResize
GraphicalComponent * componentToBeDrawn = nullptr
 Component being placed (shadow).
std::string lastInputOrientation = "RIGHT"
 Last user-edited orientations, kept only for this editor session.
std::string lastOutputOrientation = "LEFT"
bool suppressNextComponentSearch = false
 Suppresses the quick search popup for catalog-driven placement.
GraphicalWireSegment * wireSegmentToBeDrawn = nullptr
 Wire segment being drawn.
bool wirePreviewRouteValid = true
ComponentSearchBox * csb = nullptr
 Component search box.
WireManager wireManager
 Wire manager for wire topology.
ConnectionReport connectionReport
bool connectionReportDirty = true
bool refreshingConnections = false
bool connectionRefreshScheduled = false
struct SILICON::ui::DiagramScene::ComponentDragState componentDrag
std::vector< MixedDragItem > mixedDrag
std::unordered_map< const GraphicalComponent *, std::unordered_set< const GraphicalWire * > > mixedDragAttachedWires
std::map< uint64_t, WireManager::SegmentTopology > mixedDragTopologyBefore
std::map< uint64_t, WireEndpointEdit::NetState > mixedDragNetBefore
struct SILICON::ui::DiagramScene::WireDragState wireDrag
std::string lastPlacedComponentType
 Last placed component type for repeat placement.
PropertyMap lastPlacedComponentProperties
 Initial properties used when repeating placement of the last type.
std::shared_ptr< Circuit > circuit
 Underlying logic circuit model.
std::unordered_map< uint64_t, GraphicalItem * > itemsByUiId
 O(1) lookup table for runtime graphical items by stable UI id.
std::unique_ptr< DiagramSceneSimulationController > simulationController
 Simulation lifecycle and trace management.
std::unique_ptr< DiagramSceneSerializer > serializer
 Persistence and clipboard payload handling.
bool isItemCollisionEnabled = true
 Disabled while applying batch layouts that must not be rejected mid-move.

Detailed Description

Graphics scene for the circuit diagram editor.

DiagramScene extends QGraphicsScene to provide an interactive circuit diagram editor. It manages component placement, wire drawing, and various interaction modes for editing and simulation.

The scene integrates with WireManager for wire topology and uses ComponentSearchBox (CSB) for component selection. It maintains an underlying Circuit model and uses a Simulator for logic simulation.

See also
GraphicalComponent
GraphicalWireSegment
WireManager
Circuit
Simulator

Definition at line 118 of file diagramScene.hpp.

Member Enumeration Documentation

◆ InteractionMode

enum class InteractionMode
strong

Operating modes for the diagram scene.

Enumerator
NORMAL_MODE 

Default editing mode

PAN_MODE 

Panning the view

WIRE_CREATION_MODE 

Drawing a new wire

COMPONENT_PLACING_MODE 

Placing a component after selection

SIMULATION_MODE 

Interactive simulation

Definition at line 125 of file diagramScene.hpp.

Constructor & Destructor Documentation

◆ DiagramScene()

DiagramScene ( QObject * parent = nullptr)
explicit

Constructs a diagram scene.

Parameters
parentOptional parent object

Definition at line 104 of file diagramScene.cpp.

◆ ~DiagramScene()

~DiagramScene ( )
override

Definition at line 2086 of file diagramScene.cpp.

Member Function Documentation

◆ addComponent()

void addComponent ( GraphicalComponent * component,
QPointF pos )

Adds a component to the scene.

Parameters
componentThe component to add
posPosition to place the component

Definition at line 1810 of file diagramScene.cpp.

◆ applyDeserialize()

void applyDeserialize ( std::shared_ptr< SceneLoadPlan > plan)

Replaces the scene contents with a prepared plan.

Parameters
planPlan produced by prepareDeserialize, consumed by this call

Definition at line 1980 of file diagramScene.cpp.

◆ applyItemMoves()

void applyItemMoves ( std::span< const ItemPositionChange > moves,
std::span< const WireRouteChange > wires,
bool useAfter,
const WireEndpointEdit & topology = {} )

Applies recorded item positions and wire routes and rebuilds connectivity.

Parameters
movesBefore and after snapshots to apply.
wiresWire route snapshots accompanying the item moves.
useAfterTrue applies the after state; false applies the before state.
topologyReserved topology snapshot; currently unused.

Definition at line 940 of file diagramScene.cpp.

◆ applyRoutingPreview()

void applyRoutingPreview ( const std::vector< RoutedSegment > & routes,
RouteEditState & state )
private

Applies preview routes while recording original geometry in the edit state.

Definition at line 408 of file diagramScene.cpp.

◆ applyWireRouteChanges()

void applyWireRouteChanges ( std::span< const WireRouteChange > changes,
bool useAfter,
const WireEndpointEdit & endpointEdit = {} )

Applies recorded wire routes and rebuilds connectivity.

Parameters
changesBefore and after snapshots to apply.
useAfterTrue applies the after state; false applies the before state.
endpointEditReserved topology snapshot; currently unused.

Definition at line 922 of file diagramScene.cpp.

◆ autoPlaceCircuit()

void autoPlaceCircuit ( )

Automatically places components and reroutes wires.

The scene preserves its authoritative logical circuit when available, computes component positions with OGDF, and replaces WireManager's graphical wire segments with libavoid-routed paths carrying the original buses. The complete candidate set is compared while a cancellable progress dialog is shown.

Definition at line 1816 of file diagramScene.cpp.

◆ beginComponentDrag()

void beginComponentDrag ( )
private

Captures selected component positions, attached wires, and routing geometry.

Definition at line 537 of file diagramScene.cpp.

◆ beginComponentResize()

bool beginComponentResize ( GraphicalComponent * component,
ResizeHandle handle,
QPointF scenePos )

Shared resize transaction; component hooks supply the property changes.

Definition at line 1043 of file diagramScene.cpp.

◆ beginMixedDrag()

void beginMixedDrag ( )
private

Captures item positions, attached wires, and topology for a mixed selection drag.

Definition at line 664 of file diagramScene.cpp.

◆ beginWireDrag()

bool beginWireDrag ( GraphicalWireSegment * segment,
QPointF scenePos,
QPointF localPos )

Starts dragging the wire handle hit at a local position.

Parameters
segmentSegment whose handle is being dragged.
scenePosInitial mouse position in scene coordinates.
localPosHit-test position in segment coordinates.
Returns
True if a handle can be dragged in the current interaction mode.

Definition at line 785 of file diagramScene.cpp.

◆ calculateWiresForComponents

bool calculateWiresForComponents ( )
nodiscardslot

Returns the validity of the live scene connection report.

Definition at line 1805 of file diagramScene.cpp.

◆ cancelComponentDrag()

void cancelComponentDrag ( )
private

Restores original component positions and wire geometry.

Definition at line 638 of file diagramScene.cpp.

◆ cancelComponentResize()

void cancelComponentResize ( )

Definition at line 1115 of file diagramScene.cpp.

◆ cancelCurrentInteraction()

bool cancelCurrentInteraction ( )

Cancels the active transient interaction, returning to normal editing.

Returns
True when there was an interaction to cancel

Definition at line 1123 of file diagramScene.cpp.

◆ cancelMixedDrag()

void cancelMixedDrag ( )
private

Restores original item positions and clears the mixed drag state.

Definition at line 770 of file diagramScene.cpp.

◆ cancelWireDrag()

void cancelWireDrag ( )

Restores original wire routes and clears the active wire drag.

Definition at line 916 of file diagramScene.cpp.

◆ circuitResolver()

const CircuitResolver * circuitResolver ( ) const
nodiscardnoexcept

Definition at line 181 of file diagramScene.cpp.

◆ clear()

void clear ( bool clearUndoStack = true,
bool clearLogs = true )

Definition at line 2048 of file diagramScene.cpp.

◆ clearComponentShadow()

void clearComponentShadow ( )

Clears the component shadow.

Definition at line 1587 of file diagramScene.cpp.

◆ clearWireShadow()

void clearWireShadow ( )

Clears the wire being drawn.

Definition at line 1561 of file diagramScene.cpp.

◆ componentResized

void componentResized ( )
signal

◆ currentConnectionReport

const ConnectionReport & currentConnectionReport ( )
slot

Returns the cached connection report, refreshing it first when dirty.

Definition at line 1701 of file diagramScene.cpp.

◆ deserialize()

void deserialize ( const std::string & jsonStr,
GUIComponentFactory & guiFactory,
const ComponentRegistry & coreRegistry )

Deserializes a full scene from JSON.

Expects the payload documented in diagramscene_serialization_format.

Parameters
jsonStrJSON string
guiFactoryFactory for creating graphical components
coreRegistryRegistry for creating core components

Definition at line 1965 of file diagramScene.cpp.

◆ documentStore()

const SILICON::project::DocumentStore * documentStore ( ) const
nodiscardnoexcept

Definition at line 171 of file diagramScene.cpp.

◆ drawBackground()

void drawBackground ( QPainter * painter,
const QRectF & rect )
overrideprivate

Draws the background grid.

Definition at line 973 of file diagramScene.cpp.

◆ drawForeground()

void drawForeground ( QPainter * painter,
const QRectF & rect )
overrideprivate

Draws helper items on the scene foreground.

Definition at line 992 of file diagramScene.cpp.

◆ enterComponentPlacingMode()

void enterComponentPlacingMode ( )
private

Definition at line 1310 of file diagramScene.cpp.

◆ enterSimulationMode()

bool enterSimulationMode ( )
private

Definition at line 1338 of file diagramScene.cpp.

◆ exitComponentPlacingMode()

void exitComponentPlacingMode ( )
private

Definition at line 1300 of file diagramScene.cpp.

◆ exitSimulationMode()

void exitSimulationMode ( )
private

Definition at line 1343 of file diagramScene.cpp.

◆ expandSceneBounds()

void expandSceneBounds ( const QRectF & bounds)

Grows the workspace in quantized steps to include scene coordinates.

Definition at line 1022 of file diagramScene.cpp.

◆ finalizeWireCreation()

void finalizeWireCreation ( )
private

Definition at line 1199 of file diagramScene.cpp.

◆ findGraphicalItemByUiId()

GraphicalItem * findGraphicalItemByUiId ( uint64_t uiId) const
nodiscard

Definition at line 2001 of file diagramScene.cpp.

◆ finishComponentDrag()

std::vector< WireRouteChange > finishComponentDrag ( )
nodiscard

Commits the component gesture and returns its before and after wire routes.

Definition at line 620 of file diagramScene.cpp.

◆ finishComponentResize()

void finishComponentResize ( )

Definition at line 1101 of file diagramScene.cpp.

◆ finishMixedDrag()

WireEndpointEdit finishMixedDrag ( )
nodiscard

Commits a mixed selection drag and returns topology and net changes for undo.

Definition at line 719 of file diagramScene.cpp.

◆ finishWireDrag()

void finishWireDrag ( GraphicalWireSegment * segment)

Commits the active segment drag and records its undo command.

Definition at line 846 of file diagramScene.cpp.

◆ getCircuit()

std::shared_ptr< Circuit > getCircuit ( ) const
inlinenodiscard

Definition at line 292 of file diagramScene.hpp.

◆ getComponentToBeDrawn()

GraphicalComponent * getComponentToBeDrawn ( ) const
nodiscard

Gets the component currently being placed.

Returns
Pointer to component or nullptr

Definition at line 1556 of file diagramScene.cpp.

◆ getDocumentNavigator()

DocumentNavigator * getDocumentNavigator ( ) const
inlinenodiscardnoexcept

Definition at line 151 of file diagramScene.hpp.

◆ getInteractionMode()

InteractionMode getInteractionMode ( ) const
inlinenodiscard

Gets the current interaction mode.

Returns
Current mode

Definition at line 180 of file diagramScene.hpp.

◆ getUndoStack()

QUndoStack * getUndoStack ( ) const
inlinenodiscard

Definition at line 253 of file diagramScene.hpp.

◆ getWireManager() [1/2]

WireManager & getWireManager ( )
inlinenodiscard

Definition at line 254 of file diagramScene.hpp.

◆ getWireManager() [2/2]

const WireManager & getWireManager ( ) const
inlinenodiscard

Definition at line 255 of file diagramScene.hpp.

◆ handleInputToggled

void handleInputToggled ( Bus targetBus,
BusValue value,
Component_weakPtr source )
slot

Handles input toggle events from GraphicalInput components.

Parameters
targetBusThe bus to update
valueThe value to set
sourceThe component that triggered the change

Definition at line 1613 of file diagramScene.cpp.

◆ hasWireGroupSelection()

bool hasWireGroupSelection ( ) const
nodiscard

Returns whether the selection includes a wire and a component, or multiple wires.

Definition at line 653 of file diagramScene.cpp.

◆ hideCSB

void hideCSB ( )
slot

Hides the component search box.

Definition at line 1607 of file diagramScene.cpp.

◆ initializeSceneBounds()

void initializeSceneBounds ( qreal expansionStep)
private

Definition at line 1016 of file diagramScene.cpp.

◆ insertSelection()

bool insertSelection ( const nlohmann::json & payload,
GUIComponentFactory & guiFactory,
const ComponentRegistry & coreRegistry,
QPointF targetOrigin,
bool isPaste = false )

Inserts a clipboard selection payload into the current scene.

The payload's top-left origin is mapped to targetOrigin. Inserted items are selected and reconnected through the scene's wire topology.

The payload format is the scene-fragment clipboard form documented in serializeSelection(), derived from diagramscene_serialization_format.

Parameters
payloadDecoded clipboard payload
guiFactoryFactory for creating graphical components
coreRegistryRegistry for creating core components
targetOriginScene position where the payload origin should be placed
isPasteTrue iff is called by a paste action, remaps items ids
Returns
True when any item was inserted

Definition at line 1992 of file diagramScene.cpp.

◆ inspectConnection()

NetConnection inspectConnection ( const std::vector< GraphicalWire * > & wires) const
nodiscardprivate

Inspects the combined wire group for width and driver compatibility.

Definition at line 1696 of file diagramScene.cpp.

◆ isDraggingComponent()

bool isDraggingComponent ( const GraphicalComponent * component) const
nodiscard

Returns whether the component participates in an active component or mixed drag.

Definition at line 573 of file diagramScene.cpp.

◆ isDraggingWire()

bool isDraggingWire ( const GraphicalWireSegment * segment) const
nodiscard

Returns whether the segment owns the active wire drag.

Definition at line 811 of file diagramScene.cpp.

◆ isFstTracingEnabled()

bool isFstTracingEnabled ( ) const
nodiscard

Definition at line 1624 of file diagramScene.cpp.

◆ isResizingComponent()

bool isResizingComponent ( ) const
inlinenodiscard

Definition at line 174 of file diagramScene.hpp.

◆ isSubcircuitDocumentMode()

bool isSubcircuitDocumentMode ( ) const
inlinenodiscard

Returns true when subcircuit-only graphical tools may be placed.

Definition at line 316 of file diagramScene.hpp.

◆ isWireAttachedToDraggedComponent()

bool isWireAttachedToDraggedComponent ( const GraphicalComponent * component,
const GraphicalWire * wire ) const
nodiscard

Returns whether a wire was attached to the component when its drag began.

Definition at line 579 of file diagramScene.cpp.

◆ isWireCompletionPoint()

bool isWireCompletionPoint ( QPointF scenePoint) const
nodiscardprivate

Lifecycle helper methods for interaction modes.

Definition at line 1231 of file diagramScene.cpp.

◆ isWireCreationInProgress()

bool isWireCreationInProgress ( ) const
inlinenodiscard

Returns whether a wire currently has a starting endpoint and is being routed.

Definition at line 195 of file diagramScene.hpp.

◆ itemCollisionChecksEnabled()

bool itemCollisionChecksEnabled ( ) const
inlinenodiscard

Definition at line 380 of file diagramScene.hpp.

◆ keyPressEvent()

void keyPressEvent ( QKeyEvent * event)
overrideprivate

Handles key presses for mode changes.

Definition at line 1528 of file diagramScene.cpp.

◆ loadCircuit()

void loadCircuit ( std::shared_ptr< Circuit > circuit,
GUIComponentFactory & guiFactory,
bool resolveSubcircuitMetadata = true )

Replaces the scene with an autoplaced view of an existing core circuit.

Definition at line 1985 of file diagramScene.cpp.

◆ logsClearRequested

void logsClearRequested ( )
signal

◆ makeInteractiveRouter()

std::unique_ptr< InteractiveWireRouter > makeInteractiveRouter ( ) const
nodiscardprivate

Creates a router snapshot from current components, routes, and electrical vertices.

Definition at line 365 of file diagramScene.cpp.

◆ modeChanged

void modeChanged ( InteractionMode mode)
signal

Emitted when the interaction mode changes.

Parameters
modeThe new mode

◆ mouseMoveEvent()

void mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent)
overrideprivate

Handles mouse movement for wire/component dragging.

Definition at line 1348 of file diagramScene.cpp.

◆ mousePressEvent()

void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent)
overrideprivate

Handles mouse press for wire drawing and component placement.

Definition at line 1388 of file diagramScene.cpp.

◆ mouseReleaseEvent()

void mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent)
overrideprivate

Select only the clicked component or wire after its drag handling finishes.

Definition at line 1492 of file diagramScene.cpp.

◆ placeComponent()

void placeComponent ( std::string_view typeName,
bool showSearchBox = true,
const PropertyMap & initialProperties = {} )

Begins placing a component and applies its initial properties first.

Parameters
typeNameThe component type name
showSearchBoxWhether entering placement mode should show quick search
initialPropertiesProperties to apply to the graphical component

Definition at line 1863 of file diagramScene.cpp.

◆ prepareDeserialize()

std::shared_ptr< SceneLoadPlan > prepareDeserialize ( const std::string & jsonStr,
GUIComponentFactory & guiFactory,
const ComponentRegistry & coreRegistry )
nodiscard

Deserializes a scene payload into a detached plan.

Keeps the current drawing intact when the payload is malformed: nothing is cleared and no item is added to the scene until applyDeserialize runs.

Parameters
jsonStrJSON string to load
guiFactoryFactory for graphical component construction
coreRegistryRegistry for core component construction
Returns
A detached plan consumed by applyDeserialize

Definition at line 1973 of file diagramScene.cpp.

◆ refreshConnections

void refreshConnections ( )
slot

Rebuilds the connection report, logical bindings, and visual error markers.

Definition at line 1723 of file diagramScene.cpp.

◆ registerGraphicalItem()

void registerGraphicalItem ( GraphicalItem * item)

Definition at line 1923 of file diagramScene.cpp.

◆ rememberIoPlacementOrientation()

void rememberIoPlacementOrientation ( const Component & component)

Remembers a user IO orientation edit for subsequent placements.

Definition at line 1910 of file diagramScene.cpp.

◆ removeItems()

void removeItems ( const std::vector< QGraphicsItem * > & sceneItems)

Removes the given scene items and refreshes the logical topology.

Callers should pass only top-level user-editable items.

Definition at line 2008 of file diagramScene.cpp.

◆ removeSelection()

bool removeSelection ( const nlohmann::json & payload)

Removes items matching a serialized selection payload from the current scene.

Matching is performed against the same visual serialization used for clipboard and undo operations.

Parameters
payloadSerialized selection payload
Returns
True when any matching item was removed

Definition at line 2037 of file diagramScene.cpp.

◆ requestConnectionsRefresh

void requestConnectionsRefresh ( )
slot

Marks connections dirty and schedules one refresh on the event loop.

Definition at line 1708 of file diagramScene.cpp.

◆ resolveWireTarget()

QPointF resolveWireTarget ( QPointF scenePoint) const
nodiscardprivate

Resolves a scene position to a nearby port, wire, or grid point.

Definition at line 302 of file diagramScene.cpp.

◆ serialize()

std::string serialize ( ) const
nodiscard

Serializes the full editor scene to JSON.

This format wraps the core logical circuit serialization from core_serialization_format and adds the visual data needed to rebuild the editor scene exactly as drawn.

The payload contains:

  • circuit: the logical circuit model serialized by Circuit::serialize()
  • visual.components[]: graphical component state such as type, position, rotation, and vertexId
  • visual.wires[]: graphical wire routing data such as points and wireId

vertexId links each graphical logic item back to the corresponding core component vertex inside circuit. wireId keeps multiple wire segments attached to the same logical wire/bus after deserialization.

Unlike clipboard payloads, the persisted scene format does not retain runtime uiId values because they are editor-local identifiers rather than stable file data.

Returns
JSON string representation of the scene

Definition at line 1949 of file diagramScene.cpp.

◆ serializeItems()

nlohmann::ordered_json serializeItems ( const std::vector< QGraphicsItem * > & sceneItems) const
nodiscard

Serializes arbitrary scene items using the internal selection payload format.

The returned object follows the clipboard payload described in serializeSelection(), which in turn is a scene-fragment variant of diagramscene_serialization_format.

Parameters
sceneItemsItems to serialize
Returns
JSON payload containing the provided items and related core component state

Definition at line 1960 of file diagramScene.cpp.

◆ serializeSelection()

nlohmann::ordered_json serializeSelection ( ) const
nodiscard

Serializes the selected components and wire segments for clipboard use.

The returned JSON is an intermediate representation: callers choose the transport encoding, such as BSON for clipboard operations.

This payload is derived from diagramscene_serialization_format rather than being a separate file format. It keeps the same circuit plus visual split, but limits the payload to the selected fragment, adds an origin used for paste placement, and retains uiId values because clipboard, undo, and delete flows match runtime scene items by those identifiers.

Note
Uses serializeItems internally
Returns
JSON payload containing selected visual items and related core component state

Definition at line 1954 of file diagramScene.cpp.

◆ setCircuit()

void setCircuit ( std::shared_ptr< Circuit > newCircuit)
inline

Replaces the derived topology cache.

Definition at line 295 of file diagramScene.hpp.

◆ setCircuitResolver()

void setCircuitResolver ( const CircuitResolver * resolver)
noexcept

Definition at line 176 of file diagramScene.cpp.

◆ setComponentShadow()

void setComponentShadow ( )

Shows the component shadow at cursor position.

Definition at line 1572 of file diagramScene.cpp.

◆ setDocumentCircuit()

void setDocumentCircuit ( std::shared_ptr< Circuit > newCircuit)
inline

Installs an authoritative circuit.

Definition at line 301 of file diagramScene.hpp.

◆ setDocumentNavigator()

void setDocumentNavigator ( DocumentNavigator * navigator)
inlinenoexcept

Definition at line 147 of file diagramScene.hpp.

◆ setDocumentStore()

void setDocumentStore ( const SILICON::project::DocumentStore * documents)
noexcept

Definition at line 165 of file diagramScene.cpp.

◆ setFstTraceFile()

void setFstTraceFile ( std::optional< std::string > fileName)

Enables or disables simulation FST tracing.

When enabled during simulation mode, the active simulator immediately starts writing snapshots to the configured file. When enabled before entering simulation mode, the writer is attached during simulation initialization.

Definition at line 1619 of file diagramScene.cpp.

◆ setInteractionMode() [1/2]

void setInteractionMode ( InteractionMode mode)

Sets the interaction mode.

Parameters
modeThe new mode

Definition at line 1038 of file diagramScene.cpp.

◆ setInteractionMode() [2/2]

void setInteractionMode ( InteractionMode newMode,
bool force )
private

Internal method to set mode with force option.

Definition at line 1155 of file diagramScene.cpp.

◆ setIoInteractionsEnabled()

void setIoInteractionsEnabled ( bool enabled)
inline

Enables or disables user-triggered IO interactions in simulation mode.

Parameters
enabledTrue to allow clicks on interactive IO components

Definition at line 310 of file diagramScene.hpp.

◆ setItemCollisionChecksEnabled()

void setItemCollisionChecksEnabled ( bool enabled)
inline

Definition at line 381 of file diagramScene.hpp.

◆ setSubcircuitDocumentMode()

void setSubcircuitDocumentMode ( bool enabled)
inline

Enables reusable-circuit boundary I/O editing for the scene.

Definition at line 313 of file diagramScene.hpp.

◆ setUndoStack()

void setUndoStack ( QUndoStack * stack)
inlinenoexcept

Definition at line 146 of file diagramScene.hpp.

◆ showCSB()

void showCSB ( QPointF pos)

Shows the component search box at a position.

Parameters
posPosition to show the search box

Definition at line 1597 of file diagramScene.cpp.

◆ simulateEditedWaveform()

void simulateEditedWaveform ( qulonglong duration,
std::vector< Sample > inputSnapshots )

Simulates the circuit using an edited input waveform.

Parameters
durationTotal waveform duration to simulate
inputSnapshotsInput-only timestamped values ordered like waveform inputs

Definition at line 1629 of file diagramScene.cpp.

◆ snapToGrid() [1/2]

QPoint snapToGrid ( QPointF point)
static

Snaps a point to the grid.

Parameters
pointThe point to snap
Returns
Snapped point

Definition at line 297 of file diagramScene.cpp.

◆ snapToGrid() [2/2]

int snapToGrid ( qreal value)
static

Snaps one scene coordinate to the grid.

Definition at line 292 of file diagramScene.cpp.

◆ unregisterGraphicalItem()

void unregisterGraphicalItem ( GraphicalItem * item)

Definition at line 1932 of file diagramScene.cpp.

◆ updateComponentDrag()

void updateComponentDrag ( )
private

Previews component moves and restores the last valid positions if routing fails.

Definition at line 591 of file diagramScene.cpp.

◆ updateComponentResize()

void updateComponentResize ( QPointF scenePos)

Definition at line 1068 of file diagramScene.cpp.

◆ updateMixedDrag()

void updateMixedDrag ( )
private

Validates mixed selection movement and retains the last valid positions.

Definition at line 698 of file diagramScene.cpp.

◆ updateSceneAfterEdit()

void updateSceneAfterEdit ( )

Definition at line 2042 of file diagramScene.cpp.

◆ updateWireDrag()

void updateWireDrag ( GraphicalWireSegment * segment,
QPointF scenePos )

Previews the active segment drag at the given scene position.

Definition at line 816 of file diagramScene.cpp.

◆ updateWirePreview()

void updateWirePreview ( QPointF scenePoint)
private

Updates the route preview for the wire being drawn toward a scene position.

Definition at line 1255 of file diagramScene.cpp.

◆ waveformTraceReset

void waveformTraceReset ( QStringList signalNames,
int inputCount,
QList< int > signalWidths )
signal

Emitted when interactive waveform signals should be rebuilt.

Parameters
signalNamesOrdered signal labels
inputCountNumber of leading signals belonging to the input group
signalWidthsWidth of each signal in bits

◆ waveformTraceSnapshots

void waveformTraceSnapshots ( QList< QPair< qulonglong, std::vector< BusValue > > > snapshots)
signal

Emitted when a completed simulation job produced multiple waveform states.

Parameters
snapshotsOrdered timestamp and signal-value snapshots

Member Data Documentation

◆ circuit

std::shared_ptr<Circuit> circuit
private

Underlying logic circuit model.

Definition at line 732 of file diagramScene.hpp.

◆ componentDrag

struct SILICON::ui::DiagramScene::ComponentDragState componentDrag
private

◆ componentResize

◆ componentToBeDrawn

GraphicalComponent* componentToBeDrawn = nullptr
private

Component being placed (shadow).

Definition at line 623 of file diagramScene.hpp.

◆ connectionRefreshScheduled

bool connectionRefreshScheduled = false
private

Definition at line 644 of file diagramScene.hpp.

◆ connectionReport

ConnectionReport connectionReport
private

Definition at line 641 of file diagramScene.hpp.

◆ connectionReportDirty

bool connectionReportDirty = true
private

Definition at line 642 of file diagramScene.hpp.

◆ csb

ComponentSearchBox* csb = nullptr
private

Component search box.

Definition at line 637 of file diagramScene.hpp.

◆ currentInteractionMode

InteractionMode currentInteractionMode = InteractionMode::NORMAL_MODE
private

Current interaction mode.

Definition at line 599 of file diagramScene.hpp.

◆ documentNavigator

DocumentNavigator* documentNavigator = nullptr
private

Definition at line 610 of file diagramScene.hpp.

◆ documents

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

Definition at line 607 of file diagramScene.hpp.

◆ GRID_SIZE

int GRID_SIZE = SILICON::ui::GRID_SIZE
staticconstexpr

Grid cell size in scene units.

Definition at line 251 of file diagramScene.hpp.

◆ ioInteractionsEnabled

bool ioInteractionsEnabled = true
private

Whether simulation-mode IO clicks may mutate input state.

Definition at line 602 of file diagramScene.hpp.

◆ isItemCollisionEnabled

bool isItemCollisionEnabled = true
private

Disabled while applying batch layouts that must not be rejected mid-move.

Definition at line 745 of file diagramScene.hpp.

◆ itemsByUiId

std::unordered_map<uint64_t, GraphicalItem*> itemsByUiId
private

O(1) lookup table for runtime graphical items by stable UI id.

Definition at line 735 of file diagramScene.hpp.

◆ lastInputOrientation

std::string lastInputOrientation = "RIGHT"
private

Last user-edited orientations, kept only for this editor session.

Definition at line 626 of file diagramScene.hpp.

◆ lastOutputOrientation

std::string lastOutputOrientation = "LEFT"
private

Definition at line 627 of file diagramScene.hpp.

◆ lastPlacedComponentProperties

PropertyMap lastPlacedComponentProperties
private

Initial properties used when repeating placement of the last type.

Definition at line 729 of file diagramScene.hpp.

◆ lastPlacedComponentType

std::string lastPlacedComponentType
private

Last placed component type for repeat placement.

Definition at line 726 of file diagramScene.hpp.

◆ mixedDrag

std::vector<MixedDragItem> mixedDrag
private

Definition at line 709 of file diagramScene.hpp.

◆ mixedDragAttachedWires

std::unordered_map<const GraphicalComponent*, std::unordered_set<const GraphicalWire*> > mixedDragAttachedWires
private

Definition at line 711 of file diagramScene.hpp.

◆ mixedDragNetBefore

std::map<uint64_t, WireEndpointEdit::NetState> mixedDragNetBefore
private

Definition at line 713 of file diagramScene.hpp.

◆ mixedDragTopologyBefore

std::map<uint64_t, WireManager::SegmentTopology> mixedDragTopologyBefore
private

Definition at line 712 of file diagramScene.hpp.

◆ refreshingConnections

bool refreshingConnections = false
private

Definition at line 643 of file diagramScene.hpp.

◆ resolver

const CircuitResolver* resolver = nullptr
private

Definition at line 608 of file diagramScene.hpp.

◆ sceneExpansionStep

qreal sceneExpansionStep = 0
private

Definition at line 561 of file diagramScene.hpp.

◆ serializer

std::unique_ptr<DiagramSceneSerializer> serializer
private

Persistence and clipboard payload handling.

Definition at line 741 of file diagramScene.hpp.

◆ simulationController

std::unique_ptr<DiagramSceneSimulationController> simulationController
private

Simulation lifecycle and trace management.

Definition at line 738 of file diagramScene.hpp.

◆ subcircuitDocumentMode

bool subcircuitDocumentMode = false
private

Whether reusable-circuit boundary I/O editing is enabled.

Definition at line 605 of file diagramScene.hpp.

◆ suppressNextComponentSearch

bool suppressNextComponentSearch = false
private

Suppresses the quick search popup for catalog-driven placement.

Definition at line 630 of file diagramScene.hpp.

◆ undoStack

QUndoStack* undoStack = nullptr
private

Definition at line 609 of file diagramScene.hpp.

◆ wireDrag

◆ wireManager

WireManager wireManager
private

Wire manager for wire topology.

Definition at line 640 of file diagramScene.hpp.

◆ wirePreviewRouteValid

bool wirePreviewRouteValid = true
private

Definition at line 634 of file diagramScene.hpp.

◆ wireSegmentToBeDrawn

GraphicalWireSegment* wireSegmentToBeDrawn = nullptr
private

Wire segment being drawn.

Definition at line 633 of file diagramScene.hpp.


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