Skip to content

Commit

Permalink
calculate values from expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
staniska committed Nov 10, 2024
1 parent cbc6b05 commit 53f633c
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions lib/interpretator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]) {
Expand All @@ -482,40 +485,39 @@ 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) {
View.sinumerikView.parseData.activeToolR = parseFloat(operator.toolr);
}
}

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 = {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 = /(?<!\w)REPEAT(?!\w)/;
if (rowText.match(regEx_REPEAT)) {
Expand Down

0 comments on commit 53f633c

Please sign in to comment.