Skip to content

How Data is loaded in Simulator?

Shubhankar Sharma edited this page May 18, 2020 · 1 revision

Contributing author: @shubhankarsharma00

When someone tries to open a previouslt saved project or recover some project that was not saved it is done using load() function. serialized JSON is passed onto the function as a parameter. The function first sets identifying features such as projectId and projectName and then tries to load all the circuits. Since all circuits are stored in a particular order to avoid conflict first all the dependencies of a circuit are loaded by a simple for loop over data.scopes array. These circuits are loaded by calling a function newCircuit(name of the circuit) and then loading all the serialized data into the new cirucit by using loadScope function. Inside loadScope we call loadNode function to make all nodes and then connect them to their connections using constructNodeConnections. Then we iterate over all modules listed in the JSON data and then we load all the modules (all circuit element except subcircuit) using loadModule function and load the subcircuits using loadSubciruit. Next we try to load the layout of a scope's subCircuit and if no data for layout exists we give them default values (This is done because layout wasn't a part of the saved JSON in some old projects). After this a couple of functions from engine.js namely update and updateRestrictedElementsInScope are called to update the UI, draw everything and check if any restricted elements are used in the loaded project. After all this the focus is shifted back to the data.focussedCircuit and updateSimulation, updateCanvas, gridUpdate are set to true and UI update is scheduled using scheduleUpdate function in engine.js.

How loadModules work? In loadModules first the constructor of Module is called. data.customData.constructorParamaters is used to pass some of these parameters. Then the properties of the module are updated using data.customData. After all this we iterate over all the nodes of the module and replace new nodes with the correct old nodes (with connections).

loadNode simply calls Node constructor on Node parameters. For more information on how loadSubCircuit, update and scheduleUpdate works refer to engine.js and respective wiki pages.

Clone this wiki locally