Skip to content

Commit 1ec22d6

Browse files
fix(gsoc'24): SubCircuit i/o nodes not consistent with localscope i/o nodes (CircuitVerse#355)
* fix(gsoc'24): SubCircuit i/o nodes not consistent with localscope i/o nodes * Update subcircuit.js --------- Co-authored-by: Arnabdaz <[email protected]>
1 parent c694ba9 commit 1ec22d6

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

src/simulator/src/data/save.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { scopeList } from '../circuit'
22
import { resetup } from '../setup'
3-
import { update } from '../engine'
3+
import { update, updateSubcircuitSet } from '../engine'
44
import { stripTags, showMessage } from '../utils'
55
import { backUp } from './backupCircuit'
66
import { simulationArea } from '../simulationArea'
@@ -122,6 +122,13 @@ export async function generateSaveData(name, setName = true) {
122122
}
123123

124124
completed[id] = true
125+
126+
// This update is very important.
127+
// if a scope's input/output changes and the user saves without going
128+
// to circuits where this circuit is used as a subcircuit. It will
129+
// break the code since the Subcircuit will have different number of
130+
// in/out nodes compared to the localscope input/output objects.
131+
updateSubcircuitSet(true);
125132
update(scopeList[id], true) // For any pending integrity checks on subcircuits
126133
data.scopes.push(backUp(scopeList[id]))
127134
}

src/simulator/src/node.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function replace(node, index) {
4747
node.parent = parent
4848
parent.nodeList.push(node)
4949
node.updateRotation()
50+
node.scope.timeStamp = new Date().getTime()
5051
return node
5152
}
5253
function rotate(x1, y1, dir) {
@@ -186,6 +187,7 @@ export default class Node {
186187
this.hover = false
187188
this.wasClicked = false
188189
this.scope = this.parent.scope
190+
this.scope.timeStamp = new Date().getTime()
189191
/**
190192
* @type {string}
191193
* value of this.prev is
@@ -289,6 +291,7 @@ export default class Node {
289291
for (var i = 0; i < this.connections.length; i++) {
290292
this.connections[i].connections = this.connections[i].connections.filter(x => x !== this)
291293
}
294+
this.scope.timeStamp = new Date().getTime()
292295
this.connections = []
293296
}
294297

@@ -341,6 +344,8 @@ export default class Node {
341344
this.connections.push(n)
342345
n.connections.push(this)
343346

347+
this.scope.timeStamp = new Date().getTime()
348+
344349
updateCanvasSet(true)
345350
updateSimulationSet(true)
346351
scheduleUpdate()
@@ -355,7 +360,9 @@ export default class Node {
355360
this.connections.push(n)
356361
n.connections.push(this)
357362

358-
updateCanvasSet(true)
363+
this.scope.timeStamp = new Date().getTime()
364+
365+
// updateCanvasSet(true)
359366
updateSimulationSet(true)
360367
scheduleUpdate()
361368
}
@@ -366,6 +373,8 @@ export default class Node {
366373
disconnectWireLess(n) {
367374
this.connections = this.connections.filter(x => x !== n)
368375
n.connections = n.connections.filter(x => x !== this)
376+
377+
this.scope.timeStamp = new Date().getTime()
369378
}
370379

371380
/**
@@ -908,6 +917,9 @@ export default class Node {
908917
this.connections[i].connections = this.connections[i].connections.filter(x => x !== this)
909918
this.connections[i].checkDeleted()
910919
}
920+
921+
this.scope.timeStamp = new Date().getTime()
922+
911923
wireToBeCheckedSet(1)
912924
forceResetNodesSet(true)
913925
scheduleUpdate()

src/simulator/src/subcircuit.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ export default class SubCircuit extends CircuitElement {
258258
}
259259

260260
/**
261-
* rebuilds the subcircuit if any change to localscope is made
261+
* If the circuit referenced by localscope is changed, then the localscope
262+
* needs to be updated. This function does that.
262263
*/
263264
reBuildCircuit() {
264265
this.data = JSON.parse(scheduleBackup(scopeList[this.id]))
@@ -433,12 +434,9 @@ export default class SubCircuit extends CircuitElement {
433434
this.reBuildCircuit()
434435
}
435436

436-
// Should this be done here or only when this.reBuildCircuit() is called?
437-
{
438-
this.localScope.reset()
439-
updateSimulationSet(true)
440-
forceResetNodesSet(true)
441-
}
437+
this.localScope.reset()
438+
updateSimulationSet(true)
439+
forceResetNodesSet(true)
442440

443441
this.makeConnections()
444442
}

src/simulator/src/wire.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,7 @@ export default class Wire {
230230
this.scope.wires = this.scope.wires.filter(x => x !== this)
231231
this.node1.checkDeleted()
232232
this.node2.checkDeleted()
233+
234+
this.scope.timeStamp = new Date().getTime();
233235
}
234236
}

0 commit comments

Comments
 (0)