constructor(
        x,
        y,
        scope = globalScope,
        id = undefined,
        savedData = undefined
    ) {
        super(x, y, scope, "RIGHT", 1); // super call
        this.objectType = "SubCircuit";
        this.scope.SubCircuit.push(this);
        this.id = id || prompt("Enter Id: ");
        this.directionFixed = true;
        this.fixedBitWidth = true;
        this.savedData = savedData;
        this.inputNodes = [];
        this.outputNodes = [];
        this.localScope = new Scope();
        this.preventCircuitSwitch = false; // prevents from switching circuit if double clicking element
        this.rectangleObject = false;

        var subcircuitScope = scopeList[this.id]; // Scope of the subcircuit
        // Error handing
        if (subcircuitScope == undefined) {
            // if no such scope for subcircuit exists
            showError(
                `SubCircuit : ${
                    (savedData && savedData.title) || this.id
                } Not found`
            );
        } else if (!checkIfBackup(subcircuitScope)) {
            // if there is no input/output nodes there will be no backup
            showError(
                `SubCircuit : ${
                    (savedData && savedData.title) || subcircuitScope.name
                } is an empty circuit`
            );
        } else if (subcircuitScope.checkDependency(scope.id)) {
            // check for cyclic dependency
            showError("Cyclic Circuit Error");
        }
        // Error handling, cleanup
        if (
            subcircuitScope == undefined ||
            subcircuitScope.checkDependency(scope.id)
        ) {
            if (savedData) {
                for (var i = 0; i < savedData.inputNodes.length; i++) {
                    scope.allNodes[savedData.inputNodes[i]].deleted = true;
                }
                for (var i = 0; i < savedData.outputNodes.length; i++) {
                    scope.allNodes[savedData.outputNodes[i]].deleted = true;
                }
            }
            return;
        }

        if (this.savedData != undefined) {
            updateSubcircuitSet(true);
            scheduleUpdate();
            this.version = this.savedData.version || "1.0";

            this.id = this.savedData.id;
            this.label = this.savedData.label || "";
            this.labelDirection = this.savedData.labelDirection || "RIGHT";
            for (var i = 0; i < this.savedData.inputNodes.length; i++) {
                this.inputNodes.push(
                    this.scope.allNodes[this.savedData.inputNodes[i]]
                );
                this.inputNodes[i].parent = this;
                this.inputNodes[i].layout_id =
                    subcircuitScope.Input[i]?.layoutProperties.id;
            }
            for (var i = 0; i < this.savedData.outputNodes.length; i++) {
                this.outputNodes.push(
                    this.scope.allNodes[this.savedData.outputNodes[i]]
                );
                this.outputNodes[i].parent = this;
                this.outputNodes[i].layout_id =
                    subcircuitScope.Output[i]?.layoutProperties.id;
            }
            if (this.version == "1.0") {
                // For backward compatibility
                this.version = "2.0";
                this.x -= subcircuitScope.layout.width / 2;
                this.y -= subcircuitScope.layout.height / 2;
                for (var i = 0; i < this.inputNodes.length; i++) {
                    this.inputNodes[i].x =
                        subcircuitScope.Input[i].layoutProperties.x;
                    this.inputNodes[i].y =
                        subcircuitScope.Input[i].layoutProperties.y;
                    this.inputNodes[i].leftx = this.inputNodes[i].x;
                    this.inputNodes[i].lefty = this.inputNodes[i].y;
                }
                for (var i = 0; i < this.outputNodes.length; i++) {
                    this.outputNodes[i].x =
                        subcircuitScope.Output[i].layoutProperties.x;
                    this.outputNodes[i].y =
                        subcircuitScope.Output[i].layoutProperties.y;
                    this.outputNodes[i].leftx = this.outputNodes[i].x;
                    this.outputNodes[i].lefty = this.outputNodes[i].y;
                }
            }

            if (this.version == "2.0") {
                this.leftDimensionX = 0;
                this.upDimensionY = 0;
                this.rightDimensionX = subcircuitScope.layout.width;
                this.downDimensionY = subcircuitScope.layout.height;
            }

            this.nodeList.extend(this.inputNodes);
            this.nodeList.extend(this.outputNodes);
        } else {
            this.version = "2.0";
        }

        this.data = JSON.parse(scheduleBackup(subcircuitScope));
        this.buildCircuit(); // load the localScope for the subcircuit
        this.makeConnections(); // which will be wireless
    }
@class
@extends CircuitElement
@param {number} x - x coord of subcircuit
@param {number} y - y coord of subcircuit
@param {Scope=} scope - the circuit in which subcircuit has been added
@param {string} id - the id of the subcircuit scope
@param {JSON} savedData - the saved data
@category subcircuit