UNPKG

@scalenc/nc-format

Version:

Library for handling TRUMPF NC file format.

47 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssignmentProcessor = void 0; const models_1 = require("../models"); const Constants_1 = require("./Constants"); const ExpressionEvaluator_1 = require("./ExpressionEvaluator"); const MotionMode_1 = require("./MotionMode"); class AssignmentProcessor { state; variable = ''; value = 0; constructor(state) { this.state = state; } setMissingCenterVariables(variables) { if (this.state.motionMode === MotionMode_1.MotionMode.CLOCKWISE || this.state.motionMode === MotionMode_1.MotionMode.COUNTER_CLOCKWISE) { this.state.machine.getCenterAndReferenceVariables().forEach(({ name, centerName }) => { if (!variables.hasNumber(centerName)) { const value = variables.tryGetNumber(name); if (value !== undefined) { variables.setNumber(centerName, value); } } }); } } process(assignment) { this.variable = assignment.variable; let absolute = this.state.absolute ? this.state.machine.isAbsoluteAssignable(this.variable) : !this.state.machine.isRelativeAssignable(this.variable); let expression = assignment.expression; if (expression instanceof models_1.Function && expression.args.length === 1 && expression.args[0]) { const absoluteOverwrite = Constants_1.tryOverwriteAbsoluteModeByFunction(expression.name); if (absoluteOverwrite !== undefined) { absolute = absoluteOverwrite; expression = expression.args[0]; } } const value = ExpressionEvaluator_1.asNumber(ExpressionEvaluator_1.evaluate(expression, this.state.variables)); this.value = absolute ? 0.0 : this.state.variables.getNumberOrDefault(this.state.machine.getReferenceVariable(this.variable)); this.value += this.state.metric ? value : this.state.machine.inchToMillimeter(this.variable, value); } apply() { this.state.variables.setNumber(this.variable, this.value); } } exports.AssignmentProcessor = AssignmentProcessor; //# sourceMappingURL=AssignmentProcessor.js.map