From 53f633c181286b0e73e6eae442e595ca4a5a2f96 Mon Sep 17 00:00:00 2001 From: Staniska Date: Sun, 10 Nov 2024 21:06:35 +0300 Subject: [PATCH] calculate values from expressions --- lib/interpretator.js | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/interpretator.js b/lib/interpretator.js index 043a741..91e5e44 100644 --- a/lib/interpretator.js +++ b/lib/interpretator.js @@ -22,7 +22,10 @@ class CanvasElementsArray extends Array { push(element) { element.offn = View.sinumerikView.parseData.offn; element.toolRadiusCompensation = View.sinumerikView.parseData.toolRadiusCompensation - element.activeTool = {type: View.sinumerikView.parseData.activeTool, r: View.sinumerikView.parseData.activeToolR} + element.activeTool = { + type: View.sinumerikView.parseData.activeTool, + r: View.sinumerikView.parseData.activeToolR + } element.workPlane = View.sinumerikView.parseData.plane element.spindleSpeed = {...View.sinumerikView.parseData.spindleSpeed} element.feed = {...View.sinumerikView.parseData.feed} @@ -260,7 +263,7 @@ function clearAxesPos(programName) { ); View.sinumerikView.parseData.plane = 'G17'; - if (View.sinumerikView.singleLineDebugData.machine.machineType == 'Lathe') { + if (View.sinumerikView.singleLineDebugData.machine.machineType === 'Lathe') { View.sinumerikView.parseData.diamon = 1; View.sinumerikView.parseData.diam90 = 0; View.sinumerikView.parseData.axesPos.Y = 0; @@ -297,7 +300,7 @@ function parseRows(programText, programName, variables, firstCall) { } //search PROC DEF for (let i = 0; i < programText.length; i++) { - if (programText[i].trim().substring(0, 1) != ';' && + if (programText[i].trim().substring(0, 1) !== ';' && programText[i].trim().length > 1) { if (programText[i].split(' ')[0].match(/PROC|DEF/)) { checkDef(programText[i], programName, variables, i); @@ -467,7 +470,7 @@ function parseRows(programText, programName, variables, firstCall) { operator.value *= View.sinumerikView.parseData.frame.mirror[operator.name] } - if (operator.type == 'assignment') { + if (operator.type === 'assignment') { if (operator.name.match(/R\d*/) && operator.name.match(/R\d*/) == operator.name) { //console.log('R assign'); if (!View.sinumerikView.parseData.variables.firstChannelVariables[operator.name]) { @@ -482,20 +485,20 @@ function parseRows(programText, programName, variables, firstCall) { } } - if (operator.type == 'diamon') { + if (operator.type === 'diamon') { View.sinumerikView.parseData.diamon = 1; View.sinumerikView.parseData.diam90 = 0 } - if (operator.type == 'diam90') { + if (operator.type === 'diam90') { View.sinumerikView.parseData.diamon = 1; View.sinumerikView.parseData.diam90 = 1; } - if (operator.type == 'diamof') { + if (operator.type === 'diamof') { View.sinumerikView.parseData.diamon = 0; View.sinumerikView.parseData.diam90 = 0; } - if (operator.type == 'T_name') { + if (operator.type === 'T_name') { // console.log(operator) View.sinumerikView.parseData.activeTool = operator.value; if (operator.toolr) { @@ -503,19 +506,18 @@ function parseRows(programText, programName, variables, firstCall) { } } - if (operator.type == 'toolRadiusCompensation') { - View.sinumerikView.parseData.toolRadiusCompensation = operator.value; - // console.log(View.sinumerikView.parseData.toolRadiusCompensation); + if (operator.type === 'toolRadiusCompensation') { + View.sinumerikView.parseData.toolRadiusCompensation = calcValue(operator.value, programName, row) } - if (operator.type == 'MSG') { + if (operator.type === 'MSG') { var msg = { type: 'msg', value: operator.value } View.sinumerikView.parseData.canvas.push(msg); } - if (operator.type == 'M_func') { + if (operator.type === 'M_func') { if (operator.value === '30' || operator.value === '17') { // console.log(View.sinumerikView.parseData) msg = { @@ -536,10 +538,10 @@ function parseRows(programText, programName, variables, firstCall) { } } - if (operator.type === 'S_speed' ) { - View.sinumerikView.parseData.spindleSpeed.value = operator.value + if (operator.type === 'S_speed') { + View.sinumerikView.parseData.spindleSpeed.value = calcValue(operator.value, programName, row) } - if (operator.type === 'F_feed') View.sinumerikView.parseData.feed.value = operator.value + if (operator.type === 'F_feed') View.sinumerikView.parseData.feed.value = calcValue(operator.value, programName, row) if (operator.type === 'generalGroup15') { if (operator.value === 'G96' || operator.value === 'G97') { View.sinumerikView.parseData.spindleSpeed.type = operator.value @@ -584,9 +586,9 @@ function parseRows(programText, programName, variables, firstCall) { } } - if (row == (programText.length - 1)) { + if (row === (programText.length - 1)) { if (View.sinumerikView.parseData.prevMove.length) { - if (View.sinumerikView.parseData.prevMove[0].type == 'G1') { + if (View.sinumerikView.parseData.prevMove[0].type === 'G1') { View.sinumerikView.parseData.canvas.push(View.sinumerikView.parseData.prevMove[0]); View.sinumerikView.parseData.prevMove.shift(); return; @@ -600,6 +602,10 @@ function parseRows(programText, programName, variables, firstCall) { } } +const calcValue = (value, programName, row) => { + return value[0] === '=' ? mathParse(value.substring(1), programName, row) : value +} + function checkRepeat(rowText, programName, programText, row) { var regEx_REPEAT = /(?