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

Manages simulation lifecycle and waveform tracing for DiagramScene. More...

#include <diagramSceneSimulationController.hpp>

Collaboration diagram for DiagramSceneSimulationController:

Classes

struct  TraceConfiguration
 Ordered buses and group metadata used by waveform tracing. More...

Public Member Functions

 DiagramSceneSimulationController (DiagramScene &scene)
 Constructs a simulation controller bound to a scene.
 ~DiagramSceneSimulationController ()
 Destroys the controller and releases any simulator resources.
bool enterSimulationMode ()
 Enters interactive simulation mode for the scene.
void exitSimulationMode ()
 Leaves interactive simulation mode and clears runtime state.
void handleInputToggled (Bus targetBus, const BusValue &value, Component_weakPtr source)
 Applies a user input toggle to the running simulator.
void setFstTraceFile (std::optional< std::string > fileName)
 Enables or disables FST tracing for the active simulation session.
void refreshGraphicalOutputs ()
 Refreshes the visual state of all graphical outputs from bus values.
void clearWaveformTrace ()
 Clears waveform state after the scene has been fully emptied.
void simulateEditedWaveform (qulonglong duration, std::vector< Sample > inputSnapshots)
 Runs the circuit from an edited input waveform and publishes output trace.
bool isFstTracingEnabled () const
 Returns whether FST tracing is currently enabled.

Private Member Functions

void refreshTraceConfiguration ()
 Refreshes waveform, simulator, and FST tracing from one scene snapshot.
TraceConfiguration collectTraceConfiguration () const
 Collects ordered trace buses and their input count.
void startJob (std::function< Simulator::RunResult()> job)
 Starts one cancellable simulation operation and its progress UI.
void setupJobUI ()
 Configures progress dialog, timers, and locks the views before a job.
void finishJob ()
 Finalizes a completed job on the GUI thread.
void cancelAndWait ()
 Requests cancellation and waits for the active job before teardown.
bool isJobFinished () const
 Returns whether the active job has completed.
void setJobFinished (bool finished)
 Publishes whether the active job has completed.
bool isJobCancellationRequested () const
 Returns whether cancellation has been requested for the active job.
void requestJobCancellation ()
 Publishes a cancellation request for the active job.
void resetJobCancellation ()
 Clears cancellation state before starting a job.
void resetTrace (const TraceConfiguration &trace)
 Rebuilds the waveform viewer's signal-name configuration.
void configureSimulatorTrace (const TraceConfiguration &trace, const std::optional< std::string > &traceFile)
 Applies trace buses, snapshot collection, and optional FST output.

Private Attributes

DiagramScene & scene
 Host scene that owns the graphical items and Qt signals.
std::unique_ptr< SILICON::simulation::Session > simulator
 Runtime simulation session active only during simulation mode.
std::optional< std::string > fstTraceFile
 Optional output file used for live FST tracing.
std::jthread worker
 Native worker synchronization.
std::atomic_bool jobCancellationRequested = false
 Platform-agnostic thread-safe job state.
std::atomic_bool jobFinished = true
Simulator::RunResult jobResult = Simulator::RunResult::Completed
 Result produced by the latest simulation operation.
std::exception_ptr jobException
 Exception captured during a job and reported on the GUI thread.
QProgressDialog * progressDialog = nullptr
 Delayed cancellation dialog for long-running jobs.
QTimer * completionTimer = nullptr
 GUI timer that detects job completion without blocking the event loop.
QTimer * dialogTimer = nullptr
 GUI timer that prevents the progress dialog flashing for short jobs.
QList< QPair< qulonglong, std::vector< BusValue > > > pendingWaveformSnapshots
 Worker-produced snapshots delivered to the viewer as one GUI batch.

Detailed Description

Manages simulation lifecycle and waveform tracing for DiagramScene.

This helper owns the temporary runtime-only simulation state used by the editor, including the Simulator instance and optional FST trace output. It keeps DiagramScene focused on interaction and scene management while centralizing simulation entry/exit, live input toggles, output refreshes, and waveform updates.

Definition at line 62 of file diagramSceneSimulationController.hpp.

Constructor & Destructor Documentation

◆ DiagramSceneSimulationController()

DiagramSceneSimulationController ( DiagramScene & scene)
explicit

Constructs a simulation controller bound to a scene.

Parameters
sceneHost scene that provides items, signals, and repaint hooks

Definition at line 91 of file diagramSceneSimulationController.cpp.

◆ ~DiagramSceneSimulationController()

Destroys the controller and releases any simulator resources.

Definition at line 96 of file diagramSceneSimulationController.cpp.

Member Function Documentation

◆ cancelAndWait()

void cancelAndWait ( )
private

Requests cancellation and waits for the active job before teardown.

Definition at line 510 of file diagramSceneSimulationController.cpp.

◆ clearWaveformTrace()

void clearWaveformTrace ( )

Clears waveform state after the scene has been fully emptied.

Definition at line 259 of file diagramSceneSimulationController.cpp.

◆ collectTraceConfiguration()

DiagramSceneSimulationController::TraceConfiguration collectTraceConfiguration ( ) const
nodiscardprivate

Collects ordered trace buses and their input count.

Definition at line 552 of file diagramSceneSimulationController.cpp.

◆ configureSimulatorTrace()

void configureSimulatorTrace ( const TraceConfiguration & trace,
const std::optional< std::string > & traceFile )
private

Applies trace buses, snapshot collection, and optional FST output.

Parameters
traceTrace buses collected from the scene
traceFileOptional destination for FST output

Definition at line 365 of file diagramSceneSimulationController.cpp.

◆ enterSimulationMode()

bool enterSimulationMode ( )

Enters interactive simulation mode for the scene.

Recalculates wire-to-component assignments before creating runtime simulation state. If that recalculation fails while assigning an input, startup is aborted and the caller should leave the scene in normal mode.

Returns
True when simulation startup succeeds.

Definition at line 101 of file diagramSceneSimulationController.cpp.

◆ exitSimulationMode()

void exitSimulationMode ( )

Leaves interactive simulation mode and clears runtime state.

Definition at line 167 of file diagramSceneSimulationController.cpp.

◆ finishJob()

void finishJob ( )
private

Finalizes a completed job on the GUI thread.

Definition at line 455 of file diagramSceneSimulationController.cpp.

◆ handleInputToggled()

void handleInputToggled ( Bus targetBus,
const BusValue & value,
Component_weakPtr source )

Applies a user input toggle to the running simulator.

Parameters
targetBusLogic bus driven by the input widget
valueNew value to inject
sourceComponent that originated the change

Definition at line 189 of file diagramSceneSimulationController.cpp.

◆ isFstTracingEnabled()

bool isFstTracingEnabled ( ) const
inlinenodiscard

Returns whether FST tracing is currently enabled.

Definition at line 126 of file diagramSceneSimulationController.hpp.

◆ isJobCancellationRequested()

bool isJobCancellationRequested ( ) const
nodiscardprivate

Returns whether cancellation has been requested for the active job.

Definition at line 536 of file diagramSceneSimulationController.cpp.

◆ isJobFinished()

bool isJobFinished ( ) const
nodiscardprivate

Returns whether the active job has completed.

Definition at line 526 of file diagramSceneSimulationController.cpp.

◆ refreshGraphicalOutputs()

void refreshGraphicalOutputs ( )

Refreshes the visual state of all graphical outputs from bus values.

Definition at line 227 of file diagramSceneSimulationController.cpp.

◆ refreshTraceConfiguration()

void refreshTraceConfiguration ( )
private

Refreshes waveform, simulator, and FST tracing from one scene snapshot.

Definition at line 339 of file diagramSceneSimulationController.cpp.

◆ requestJobCancellation()

void requestJobCancellation ( )
private

Publishes a cancellation request for the active job.

Definition at line 541 of file diagramSceneSimulationController.cpp.

◆ resetJobCancellation()

void resetJobCancellation ( )
private

Clears cancellation state before starting a job.

Definition at line 546 of file diagramSceneSimulationController.cpp.

◆ resetTrace()

void resetTrace ( const TraceConfiguration & trace)
private

Rebuilds the waveform viewer's signal-name configuration.

Definition at line 354 of file diagramSceneSimulationController.cpp.

◆ setFstTraceFile()

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

Enables or disables FST tracing for the active simulation session.

Parameters
fileNameDestination file or std::nullopt to disable tracing

Definition at line 213 of file diagramSceneSimulationController.cpp.

◆ setJobFinished()

void setJobFinished ( bool finished)
private

Publishes whether the active job has completed.

Definition at line 531 of file diagramSceneSimulationController.cpp.

◆ setupJobUI()

void setupJobUI ( )
private

Configures progress dialog, timers, and locks the views before a job.

Definition at line 420 of file diagramSceneSimulationController.cpp.

◆ simulateEditedWaveform()

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

Runs the circuit from an edited input waveform and publishes output trace.

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

Definition at line 264 of file diagramSceneSimulationController.cpp.

◆ startJob()

void startJob ( std::function< Simulator::RunResult()> job)
private

Starts one cancellable simulation operation and its progress UI.

Parameters
jobOperation that checks jobCancellationRequested cooperatively

Definition at line 384 of file diagramSceneSimulationController.cpp.

Member Data Documentation

◆ completionTimer

QTimer* completionTimer = nullptr
private

GUI timer that detects job completion without blocking the event loop.

Definition at line 217 of file diagramSceneSimulationController.hpp.

◆ dialogTimer

QTimer* dialogTimer = nullptr
private

GUI timer that prevents the progress dialog flashing for short jobs.

Definition at line 220 of file diagramSceneSimulationController.hpp.

◆ fstTraceFile

std::optional<std::string> fstTraceFile
private

Optional output file used for live FST tracing.

Definition at line 196 of file diagramSceneSimulationController.hpp.

◆ jobCancellationRequested

std::atomic_bool jobCancellationRequested = false
private

Platform-agnostic thread-safe job state.

Definition at line 204 of file diagramSceneSimulationController.hpp.

◆ jobException

std::exception_ptr jobException
private

Exception captured during a job and reported on the GUI thread.

Definition at line 211 of file diagramSceneSimulationController.hpp.

◆ jobFinished

std::atomic_bool jobFinished = true
private

Definition at line 205 of file diagramSceneSimulationController.hpp.

◆ jobResult

Simulator::RunResult jobResult = Simulator::RunResult::Completed
private

Result produced by the latest simulation operation.

Definition at line 208 of file diagramSceneSimulationController.hpp.

◆ pendingWaveformSnapshots

QList<QPair<qulonglong, std::vector<BusValue> > > pendingWaveformSnapshots
private

Worker-produced snapshots delivered to the viewer as one GUI batch.

Definition at line 223 of file diagramSceneSimulationController.hpp.

◆ progressDialog

QProgressDialog* progressDialog = nullptr
private

Delayed cancellation dialog for long-running jobs.

Definition at line 214 of file diagramSceneSimulationController.hpp.

◆ scene

DiagramScene& scene
private

Host scene that owns the graphical items and Qt signals.

Definition at line 190 of file diagramSceneSimulationController.hpp.

◆ simulator

std::unique_ptr<SILICON::simulation::Session> simulator
private

Runtime simulation session active only during simulation mode.

Definition at line 193 of file diagramSceneSimulationController.hpp.

◆ worker

std::jthread worker
private

Native worker synchronization.

Definition at line 200 of file diagramSceneSimulationController.hpp.


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