Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
property-input-id="clockTime"
/>

<p>
<span>Play/Pause:</span>
<label class="switch">
<input
type="checkbox"
class="objectPropertyAttributeChecked"
name="changeSimulationPlaying"
:checked="simulationArea.simulationPlaying"
@change="toggleSimulationPlaying"
/>
Comment on lines +46 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add v-model here

<span class="slider"></span>
</label>
</p>

<p>
<span>Clock Enabled:</span>
<label class="switch">
Expand Down Expand Up @@ -104,6 +118,7 @@ import { toggleLayoutMode } from '#/simulator/src/layoutMode'
// } from '#/simulator/src/circuit'
// import { showMessage } from '#/simulator/src/utils'
import { simulationArea } from '#/simulator/src/simulationArea'
import { toggleSimulationPlaying } from '#/simulator/src/utils'
import InputGroups from '#/components/Panels/Shared/InputGroups.vue'
// import MessageBox from '#/components/MessageBox/messageBox.vue'
// import { ref, Ref, onMounted, watch } from 'vue'
Expand Down
1 change: 1 addition & 0 deletions src/simulator/src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export function updateSelectionsAndPane(scope = globalScope) {
export function play(scope = globalScope, resetNodes = false) {
if (errorDetected) return // Don't simulate until error is fixed
if (loading === true) return // Don't simulate until loaded
if (!simulationArea.simulationPlaying) return // Don't simulate when paused

simulationArea.simulationQueue.reset()
plotArea.setExecutionTime() // Waveform thing
Expand Down
1 change: 1 addition & 0 deletions src/simulator/src/interface/simulationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface SimulationArea {
hover: boolean;
clockState: number;
clockEnabled: boolean;
simulationPlaying: boolean;
// TODO: make this CircuitElement|null once converted to typescript
lastSelected: any|null;
stack: any[];
Expand Down
9 changes: 9 additions & 0 deletions src/simulator/src/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { changeScale, findDimensions } from './canvasApi'
import { scheduleBackup } from './data/backupCircuit'
import { hideProperties, deleteSelected, uxvar, exitFullView } from './ux';
import { toggleSimulationPlaying } from './utils'
import { updateRestrictedElementsList, updateRestrictedElementsInScope, hideRestricted, showRestricted } from './restrictedElementDiv';
import { removeMiniMap, updatelastMinimapShown } from './minimap'
import undo from './data/undo'
Expand Down Expand Up @@ -557,6 +558,14 @@ export default function startListeners() {
// e.preventDefault(); //browsers normally open a new tab
simulationArea.changeClockTime(prompt('Enter Time:'))
}

// Simulation play/pause with space key
if (e.code === 'Space' || e.key === ' ' || e.keyCode === 32) {
if (e.repeat) return
toggleSimulationPlaying()
e.preventDefault()
return
}
}

if (e.keyCode == 8 || e.key == 'Delete') {
Expand Down
1 change: 1 addition & 0 deletions src/simulator/src/simulationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const simulationArea: SimulationArea = {
hover: false,
clockState: 0,
clockEnabled: true,
simulationPlaying: true,
lastSelected: null,
stack: [],
prevScale: 0,
Expand Down
10 changes: 10 additions & 0 deletions src/simulator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function stripTags(string = '') {

export function clockTick() {
if (!simulationArea.clockEnabled) return
if (!simulationArea.simulationPlaying) return
if (errorDetectedGet()) return
if (layoutModeGet()) return
updateCanvasSet(true)
Expand All @@ -50,6 +51,15 @@ export function clockTick() {
scheduleUpdate(0, 20)
}

export function toggleSimulationPlaying() {
simulationArea.simulationPlaying = !simulationArea.simulationPlaying
// UI Update
if (simulationArea.simulationPlaying) {
updateCanvasSet(true)
scheduleUpdate(1)
}
}

/**
* Helper function to show error
*/
Expand Down
Loading