var smartDropXX = 50; var smartDropYY = 80; // Object stores the position of context menu var ctxPos = { x: 0, y: 0, visible: false, }; // Function hides the context menu function hideContextMenu() { var el = document.getElementById('contextMenu'); el.style = 'opacity:0;'; setTimeout(() => { el.style = 'visibility:hidden;'; ctxPos.visible = false; }, 200); // Hide after 2 sec } // Function displays context menu function showContextMenu() { if (layoutMode) return false; // Hide context menu when it is in Layout Mode $('#contextMenu').css({ visibility: 'visible', opacity: 1, top: `${ctxPos.y}px`, left: `${ctxPos.x}px`, }); ctxPos.visible = true; return false; } // Function is called when context item is clicked // eslint-disable-next-line no-unused-vars function menuItemClicked(id) { hideContextMenu(); if (id === 0) { document.execCommand('copy'); } else if (id === 1) { document.execCommand('cut'); } else if (id === 2) { // document.execCommand('paste'); it is restricted to sove this problem we use dataPasted variable paste(localStorage.getItem('clipboardData')); } else if (id === 3) { delete_selected(); } else if (id === 4) { undo(); undo(); } else if (id === 5) { newCircuit(); } else if (id === 6) { createSubCircuitPrompt(); } else if (id === 7) { globalScope.centerFocus(false); } } function setupUI() { var ctxEl = document.getElementById('contextMenu'); document.addEventListener('mousedown', (e) => { // Check if mouse is not inside the context menu and menu is visible if (!((e.clientX >= ctxPos.x && e.clientX <= ctxPos.x + ctxEl.offsetWidth) && (e.clientY >= ctxPos.y && e.clientY <= ctxPos.y + ctxEl.offsetHeight)) && (ctxPos.visible && e.which !== 3)) { hideContextMenu(); } // Change the position of context whenever mouse is clicked ctxPos.x = e.clientX; ctxPos.y = e.clientY; }); document.getElementById('canvasArea').oncontextmenu = showContextMenu; $("#sideBar").resizable({ handles: 'e', // minWidth:270, }); $("#menu").accordion({ collapsible: true, active: false, heightStyle: "content" }); // $( "#plot" ).resizable({ // handles: 'n', // // minHeight:200, // }); $('.logixModules').mousedown(function () { //////console.log(smartDropXX,smartDropYY); if (simulationArea.lastSelected && simulationArea.lastSelected.newElement) simulationArea.lastSelected.delete(); var obj = new window[this.id](); //(simulationArea.mouseX,simulationArea.mouseY); simulationArea.lastSelected = obj; // simulationArea.lastSelected=obj; // simulationArea.mouseDown=true; smartDropXX += 70; if (smartDropXX / globalScope.scale > width) { smartDropXX = 50; smartDropYY += 80; } }); $('.logixButton').click(function () { window[this.id](); }); // var dummyCounter=0; $('.logixModules').hover(function () { // Tooltip can be statically defined in the prototype. var tooltipText = window[this.id].prototype.tooltipText; if (!tooltipText) return; $("#Help").addClass("show"); $("#Help").empty(); ////console.log("SHOWING") $("#Help").append(tooltipText); }); // code goes in document ready fn only $('.logixModules').mouseleave(function () { $("#Help").removeClass("show"); }); // code goes in document ready fn only // $('#saveAsImg').click(function(){ // saveAsImg(); // }); // $('#Save').click(function(){ // Save(); // }); // $('#moduleProperty').draggable(); } var prevPropertyObj = undefined; function showProperties(obj) { if (obj == prevPropertyObj) return; hideProperties(); prevPropertyObj = obj; if (simulationArea.lastSelected === undefined || ["Wire", "CircuitElement", "Node"].indexOf(simulationArea.lastSelected.objectType) !== -1) { $('#moduleProperty').show(); $('#moduleProperty-inner').append("
Project :
"); $('#moduleProperty-inner').append("Circuit :
"); $('#moduleProperty-inner').append("Clock Time : ms
"); $('#moduleProperty-inner').append("Clock Enabled :
"); $('#moduleProperty-inner').append("Lite Mode :
"); // $('#moduleProperty-inner').append(""); $('#moduleProperty-inner').append("
"); } else { $('#moduleProperty').show(); $('#moduleProperty-inner').append("
BitWidth:
"); if (obj.changeInputSize) $('#moduleProperty-inner').append("Input Size:
"); if (!obj.propagationDelayFixed) $('#moduleProperty-inner').append("Delay:
"); $('#moduleProperty-inner').append("Label:
"); if (!obj.labelDirectionFixed) { var s = $(""); s.val(obj.labelDirection); $('#moduleProperty-inner').append("Label Direction: " + $(s).prop('outerHTML') + "
"); } if (!obj.directionFixed) { var s = $(""); $('#moduleProperty-inner').append("Direction: " + $(s).prop('outerHTML') + "
"); } else if (!obj.orientationFixed) { var s = $(""); $('#moduleProperty-inner').append("Orientation: " + $(s).prop('outerHTML') + "
"); } if (obj.mutableProperties) { for (attr in obj.mutableProperties) { var prop = obj.mutableProperties[attr]; if (obj.mutableProperties[attr].type == "number") { var s = "" + prop.name + "
"; $('#moduleProperty-inner').append(s); } else if (obj.mutableProperties[attr].type == "text") { var s = "" + prop.name + "
"; $('#moduleProperty-inner').append(s); } else if (obj.mutableProperties[attr].type == "button") { var s = ""; $('#moduleProperty-inner').append(s); } } } } var helplink = obj && (obj.helplink); if (helplink) { $('#moduleProperty-inner').append(''); $('#HelpButton').click(function () { window.open(helplink); }); } function checkValidBitWidth() { const selector = $("[name='newBitWidth']"); if (selector == undefined || selector.val() > 32 || selector.val() < 1 || !$.isNumeric(selector.val())) { // fallback to previously saves state selector.val(selector.attr("old-val")); } else { selector.attr("old-val", selector.val()); } } $(".objectPropertyAttribute").on("change keyup paste click", function () { // return; //////console.log(this.name+":"+this.value); checkValidBitWidth() scheduleUpdate(); updateCanvas = true; wireToBeChecked = 1; if (simulationArea.lastSelected && simulationArea.lastSelected[this.name]) prevPropertyObj = simulationArea.lastSelected[this.name](this.value) || prevPropertyObj; else window[this.name](this.value); }) $(".objectPropertyAttributeChecked").on("change keyup paste click", function () { // return; //////console.log(this.name+":"+this.value); scheduleUpdate(); updateCanvas = true; wireToBeChecked = 1; if (simulationArea.lastSelected && simulationArea.lastSelected[this.name]) prevPropertyObj = simulationArea.lastSelected[this.name](this.value) || prevPropertyObj; else window[this.name](this.checked); }) } function hideProperties() { $('#moduleProperty-inner').empty(); $('#moduleProperty').hide(); prevPropertyObj = undefined; $(".objectPropertyAttribute").unbind("change keyup paste click"); } function escapeHtml(unsafe) { return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } $('#bitconverterprompt').append(`