diff --git a/src/components/DialogBox/HexBinDec.vue b/src/components/DialogBox/HexBinDec.vue index 5fc55df9..86c89f4e 100644 --- a/src/components/DialogBox/HexBinDec.vue +++ b/src/components/DialogBox/HexBinDec.vue @@ -5,7 +5,7 @@ > - Hex-Bin-Dec Convertor + Hex-Bin-Dec Converter mdi-close - {{ inputEle.label }} + {{ value[1].label }} converter(inputEle.inputId)" + @keyup="(payload) => converter(payload)" /> @@ -42,95 +42,178 @@ + + + + Hex-Bin-Dec Converter + + mdi-close + + + {{ value[1].label }} + + converter(payload)" + /> + + + + + + Reset + + + + - - diff --git a/src/simulator/src/utils.js b/src/simulator/src/utils.js index 6549edfd..9d6a32b9 100644 --- a/src/simulator/src/utils.js +++ b/src/simulator/src/utils.js @@ -216,20 +216,8 @@ export function truncateString(str, num) { } export function bitConverterDialog() { - console.log('Open dialog box') - const simulatorStore = SimulatorStore() - simulatorStore.dialogBox.hex_bin_dec_converter_dialog = true - console.log(simulatorStore.dialogBox.hex_bin_dec_converter_dialog) - // $('#bitconverterprompt').dialog({ - // buttons: [ - // { - // text: 'Reset', - // click: function () { - // setBaseValues(0) - // }, - // }, - // ], - // }) + const simulatorStore = SimulatorStore(); + simulatorStore.dialogBox.hex_bin_dec_converter_dialog = true; } export function getImageDimensions(file) { @@ -250,15 +238,6 @@ export var convertors = { dec2bcd: (x) => parseInt(x.toString(10), 16).toString(2), } -export function setBaseValues(x) { - if (isNaN(x)) return - $('#binaryInput').val(convertors.dec2bin(x)) - $('#bcdInput').val(convertors.dec2bcd(x)) - $('#octalInput').val(convertors.dec2octal(x)) - $('#hexInput').val(convertors.dec2hex(x)) - $('#decimalInput').val(x) -} - export function parseNumber(num) { if (num instanceof Number) return num if (num.slice(0, 2).toLocaleLowerCase() == '0b') @@ -269,50 +248,6 @@ export function parseNumber(num) { return parseInt(num) } -export function setupBitConvertor() { - console.log('check bit convertor') - $('#decimalInput').on('keyup', function () { - var x = parseInt($('#decimalInput').val(), 10) - setBaseValues(x) - }) - - $('#binaryInput').on('keyup', function () { - var inp = $('#binaryInput').val() - var x - if (inp.slice(0, 2) == '0b') x = parseInt(inp.slice(2), 2) - else x = parseInt(inp, 2) - setBaseValues(x) - }) - $('#bcdInput').on('keyup', function () { - var input = $('#bcdInput').val() - var num = 0 - while (input.length % 4 !== 0) { - input = '0' + input - } - if (input !== 0) { - var i = 0 - while (i < input.length / 4) { - if (parseInt(input.slice(4 * i, 4 * (i + 1)), 2) < 10) - num = - num * 10 + parseInt(input.slice(4 * i, 4 * (i + 1)), 2) - else return setBaseValues(NaN) - i++ - } - } - return setBaseValues(x) - }) - - $('#hexInput').on('keyup', function () { - var x = parseInt($('#hexInput').val(), 16) - setBaseValues(x) - }) - - $('#octalInput').on('keyup', function () { - var x = parseInt($('#octalInput').val(), 8) - setBaseValues(x) - }) -} - export function promptFile(contentType, multiple) { var input = document.createElement('input') input.type = 'file' diff --git a/src/simulator/src/ux.js b/src/simulator/src/ux.js index f01bdcee..9d61a4dc 100644 --- a/src/simulator/src/ux.js +++ b/src/simulator/src/ux.js @@ -22,7 +22,6 @@ import { setProjectName, getProjectName } from './data/save' import { changeScale } from './canvasApi' import { generateImage, generateSaveData } from './data/save' import { setupVerilogExportCodeWindow } from './verilog' -import { setupBitConvertor } from './utils' import { updateTestbenchUI, setupTestbenchUI } from './testbench' import { applyVerilogTheme } from './Verilog2CV' import { dragging } from './drag' @@ -184,7 +183,6 @@ export function setupUI() { // $('#moduleProperty').draggable(); setupPanels() // setupVerilogExportCodeWindow() - setupBitConvertor() } /** @@ -631,63 +629,6 @@ export function deleteSelected() { updateRestrictedElementsInScope() } -/** - * listener for opening the prompt for bin conversion - * @category ux - */ -$('#bitconverter').on('click', () => { - console.log('something clicked') - $('#bitconverterprompt').dialog({ - resizable: false, - buttons: [ - { - text: 'Reset', - click() { - $('#decimalInput').val('0') - $('#binaryInput').val('0') - $('#octalInput').val('0') - $('#hexInput').val('0') - }, - }, - ], - }) -}) - -// convertors -const convertors = { - dec2bin: (x) => `0b${x.toString(2)}`, - dec2hex: (x) => `0x${x.toString(16)}`, - dec2octal: (x) => `0${x.toString(8)}`, -} - -function setBaseValues(x) { - if (isNaN(x)) return - $('#binaryInput').val(convertors.dec2bin(x)) - $('#octalInput').val(convertors.dec2octal(x)) - $('#hexInput').val(convertors.dec2hex(x)) - $('#decimalInput').val(x) -} - -$('#decimalInput').on('keyup', () => { - var x = parseInt($('#decimalInput').val(), 10) - setBaseValues(x) -}) - -$('#binaryInput').on('keyup', () => { - var x = parseInt($('#binaryInput').val(), 2) - setBaseValues(x) -}) - -$('#hexInput').on('keyup', () => { - var x = parseInt($('#hexInput').val(), 16) - setBaseValues(x) -}) - -$('#octalInput').on('keyup', () => { - var x = parseInt($('#octalInput').val(), 8) - setBaseValues(x) -}) - export function setupPanels() { // $('#dragQPanel') // .on('mousedown', () =>
Hex-Bin-Dec Convertor
Hex-Bin-Dec Converter