Skip to content

Js to Ts : simulator/src/backupCircuits.ts #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
@@ -1,9 +1,11 @@
import { projectSavedSet } from './project'
import { moduleList, updateOrder } from '../metadata'

/* eslint-disable no-param-reassign */
function extract(obj) {
return obj.saveObject()
import { projectSavedSet } from './project';
import { moduleList, updateOrder } from '../metadata';
import { Scope, SaveableObject } from './data.types';
declare const globalScope: Scope;

// Helper function to extract data from an object
function extract(obj: SaveableObject): any {
return obj.saveObject();
}

// Check if there is anything to backup - to be deprecated
Expand All @@ -13,73 +15,73 @@
* @return {boolean}
* @category data
*/
export function checkIfBackup(scope) {
export function checkIfBackup(scope: Scope): boolean {
for (let i = 0; i < updateOrder.length; i++) {
if (scope[updateOrder[i]].length) return true
if (scope[updateOrder[i]].length) return true;
}
return false
return false;
}

export function backUp(scope = globalScope) {
export function backUp(scope: Scope = globalScope): any {
// Disconnection of subcircuits are needed because these are the connections between nodes
// in current scope and those in the subcircuit's scope
for (let i = 0; i < scope.SubCircuit.length; i++) {
scope.SubCircuit[i].removeConnections()
scope.SubCircuit[i].removeConnections();
}

var data = {}
const data: any = {};

// Storing layout
data.layout = scope.layout
data.layout = scope.layout;

// Storing Verilog Properties
data.verilogMetadata = scope.verilogMetadata
data.verilogMetadata = scope.verilogMetadata;

// Storing all nodes
data.allNodes = scope.allNodes.map(extract)
data.allNodes = scope.allNodes.map(extract);

// Storing test attached to scope
data.testbenchData = scope.testbenchData
data.testbenchData = scope.testbenchData;

// Storing other details
data.id = scope.id
data.name = scope.name
data.id = scope.id;
data.name = scope.name;

// Storing details of all module objects
for (let i = 0; i < moduleList.length; i++) {
if (scope[moduleList[i]].length) {
data[moduleList[i]] = scope[moduleList[i]].map(extract)
data[moduleList[i]] = scope[moduleList[i]].map(extract);
}
}

// Adding restricted circuit elements used in the save data
data.restrictedCircuitElementsUsed = scope.restrictedCircuitElementsUsed
data.restrictedCircuitElementsUsed = scope.restrictedCircuitElementsUsed;

// Storing intermediate nodes (nodes in wires)
data.nodes = []
data.nodes = [];
for (let i = 0; i < scope.nodes.length; i++) {
data.nodes.push(scope.allNodes.indexOf(scope.nodes[i]))
data.nodes.push(scope.allNodes.indexOf(scope.nodes[i]));
}

// Restoring the connections
for (let i = 0; i < scope.SubCircuit.length; i++) {
scope.SubCircuit[i].makeConnections()
scope.SubCircuit[i].makeConnections();
}

return data
return data;
}

export function scheduleBackup(scope = globalScope) {
var backup = JSON.stringify(backUp(scope))
export function scheduleBackup(scope: Scope = globalScope): string {
const backup = JSON.stringify(backUp(scope));
if (
scope.backups.length === 0 ||
scope.backups[scope.backups.length - 1] !== backup
) {
scope.backups.push(backup)
scope.history = []
scope.timeStamp = new Date().getTime()
projectSavedSet(false)
scope.backups.push(backup);
scope.history = [];
scope.timeStamp = new Date().getTime();
projectSavedSet(false);
}

return backup
}
return backup;
}
21 changes: 21 additions & 0 deletions src/simulator/src/data/data.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//Contains the interfaces to be exported in the src/simulator/src/data folder

export interface Scope {
layout: any;
verilogMetadata: any;
allNodes: any[];
testbenchData: any;
id: string;
name: string;
SubCircuit: any[];
nodes: any[];
backups: string[];
history: any[];
timeStamp: number;
restrictedCircuitElementsUsed: any;
[key: string]: any;
}

export interface SaveableObject {
saveObject(): any;
}
Loading