UNPKG

@scalenc/nc-format

Version:

Library for handling TRUMPF NC file format.

84 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlockBuilder = void 0; const models_1 = require("../models"); class BlockBuilder { block = new models_1.Block(); N(blockNumber) { this.block.blockNumber = blockNumber; return this; } label(name) { this.block.labels.push(name); return this; } comment(comment) { this.block.comment = comment; return this; } G(code) { this.block.statements.push(new models_1.GCode(code)); return this; } get metric() { return this.G(71); } get absolute() { return this.G(90); } get relative() { return this.G(91); } get quick() { return this.G(0); } get linear() { return this.G(1); } get clockwise() { return this.G(2); } get counterClockwise() { return this.G(3); } M(code) { this.block.statements.push(new models_1.MCode(code)); return this; } get endMainProgram() { return this.M(30); } get endSubProgram() { return this.M(17); } set(name, value) { const expression = this.toExpression(value); this.block.statements.push(new models_1.Assignment(name, undefined, expression)); return this; } X(value) { return this.set('X', value); } Y(value) { return this.set('Y', value); } I(value) { return this.set('I', value); } J(value) { return this.set('J', value); } F(value) { return this.set('F', value); } call(name, args) { const expressions = args?.map(this.toExpression.bind(this)); this.block.statements.push(new models_1.Instruction(name, expressions)); return this; } toExpression(value) { return typeof value === 'number' ? new models_1.Number(value, false) : typeof value === 'string' ? new models_1.String(value) : value; } } exports.BlockBuilder = BlockBuilder; //# sourceMappingURL=BlockBuilder.js.map