From b7d03423c1e570e26155c8da335289dd1e5d8a17 Mon Sep 17 00:00:00 2001 From: Achim Nacke Date: Thu, 12 Jan 2023 12:07:32 +0100 Subject: [PATCH 1/2] Moved all files from root to deprecated folder. --- Circle546.csv => deprecated/Circle546.csv | 0 ...NTERNAL TESTING ONLY datron mcr german.cps | 4624 +++++++------- .../SimP_Sequence2.cps | 776 +-- datron c5.cps => deprecated/datron c5.cps | 3614 +++++------ datron iso.cps => deprecated/datron iso.cps | 1498 ++--- .../datron mcr english.cps | 4826 +++++++-------- .../datron mcr german millTurn.cps | 4852 +++++++-------- .../datron mcr german uvw.cps | 4844 +++++++-------- .../datron mcr german.cps | 5310 ++++++++--------- .../datron next dispense.cps | 4828 +++++++-------- datron next.cps => deprecated/datron next.cps | 4872 +++++++-------- .../datron next.cps.orig | 4110 ++++++------- .../datron trunnion mcr english.cps | 4566 +++++++------- .../datron_RTCP_rotate.cps | 3340 +++++------ 14 files changed, 26030 insertions(+), 26030 deletions(-) rename Circle546.csv => deprecated/Circle546.csv (100%) rename INTERNAL TESTING ONLY datron mcr german.cps => deprecated/INTERNAL TESTING ONLY datron mcr german.cps (97%) rename SimP_Sequence2.cps => deprecated/SimP_Sequence2.cps (96%) rename datron c5.cps => deprecated/datron c5.cps (97%) rename datron iso.cps => deprecated/datron iso.cps (96%) rename datron mcr english.cps => deprecated/datron mcr english.cps (97%) rename datron mcr german millTurn.cps => deprecated/datron mcr german millTurn.cps (97%) rename datron mcr german uvw.cps => deprecated/datron mcr german uvw.cps (97%) rename datron mcr german.cps => deprecated/datron mcr german.cps (97%) rename datron next dispense.cps => deprecated/datron next dispense.cps (97%) rename datron next.cps => deprecated/datron next.cps (97%) mode change 100755 => 100644 rename datron next.cps.orig => deprecated/datron next.cps.orig (97%) rename datron trunnion mcr english.cps => deprecated/datron trunnion mcr english.cps (97%) rename datron_RTCP_rotate.cps => deprecated/datron_RTCP_rotate.cps (97%) diff --git a/Circle546.csv b/deprecated/Circle546.csv similarity index 100% rename from Circle546.csv rename to deprecated/Circle546.csv diff --git a/INTERNAL TESTING ONLY datron mcr german.cps b/deprecated/INTERNAL TESTING ONLY datron mcr german.cps similarity index 97% rename from INTERNAL TESTING ONLY datron mcr german.cps rename to deprecated/INTERNAL TESTING ONLY datron mcr german.cps index 4481db9..5966feb 100644 --- a/INTERNAL TESTING ONLY datron mcr german.cps +++ b/deprecated/INTERNAL TESTING ONLY datron mcr german.cps @@ -1,2312 +1,2312 @@ -/** - Copyright (C) 2012-2017 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {1FDF0D08-45B6-4EAD-A71D-7BA04089886D} -*/ - -// Mservice 1, 35, 0, 0, 0, 0, 0, 0, 0;!(ISO-PreProcessor wiederherstellen)! -// Mservice 1, 35, 2, 0, 0, 0, 0, 0, 0;!(ISO-PreProcessor deaktivieren)! - -description = "Generic DATRON MCR (German)"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON C5, DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: true, // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - useTimeStamp: false, // specifies to output time stamp - writeCoolantCommands: false, // en/disable coolant code output for the entire program - _got4thAxis: false, // specifies if the machine has a 4th axis - _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y - _got5thAxis: false // specifies if the machine has a 5th axis -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); - -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var language = "de"; // supported languages are: "en", "de" -var useRTCPSimu = true; // use TCP "light" or not -var useInverseTime = false; // enable inverseTime output here if needed - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; -var previousABC = new Vector(0, 0, 0); - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -// Start of Multi-axis Feed Rate logic -/***** Be sure to add 'useInverseTime' to post properties if necessary *****/ -/***** 'previousABC' must be added throughout to maintain previous rotary positions *****/ -/***** 'headOffset' should be defined when a head rotary axis is defined *****/ -/***** The feed rate mode must be included in motion block output (linear, circular, etc. *****/ -var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations -var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds -var maxInverseTime = 9999.999 * 2.9; // maximum value to output for Inverse Time feeds - -/** Calculate the multi-axis feed rate number */ -function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { - var f = {frn:0, fmode:0}; - if (feed <= 0) { - error(localize("Feedrate is less than or equal to 0.")); - return f; - } - - var length = getMoveLength(_x, _y, _z, _a, _b, _c); - - if (useInverseTime) { // inverse time - var time = getInverseTime(length[0], feed); - f.frn = inverseTimeFormat.format(time); - f.fmode = 93; - feedOutput.reset(); - } else { // degrees per minute - f.frn = feedOutput.format(getFeedDPM(length, feed)); - f.fmode = 94; - } - return f; -} - -/** Calculate the DPM feed rate number */ -function getFeedDPM(_moveLength, _feed) { - // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC - - if (properties.useTCPMode) { // TCP mode is supported, output feed as FPM - return feed; - } else { // DPM feed rate calculation - var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; - var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); - return length / moveTime; - } -} - -/** Calculate the Inverse time feed rate number */ -function getInverseTime(_length, _feed) { - var inverseTime; - if (_length < 1.e-6) { // tool doesn't move - if (typeof (maxInverseTime) == "number") { - inverseTime = maxInverseTime; - } else { - inverseTime = 999999; - } - } else { - inverseTime = _feed / _length / inverseTimeUnits; - if (typeof (maxInverseTime) == "number") { - if (inverseTime > maxInverseTime) { - inverseTime = maxInverseTime; - } - } - } - return inverseTime; -} - -/** Calculate the distance of the tool position to the center of a rotary axis */ -function getRotaryRadius(center, direction, toolPosition) { - var normal = direction.getNormalized(); - var d1 = toolPosition.x - center.x; - var d2 = toolPosition.y - center.y; - var d3 = toolPosition.z - center.z; - var radius = Math.sqrt( - Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + - Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + - Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) - ); - return radius; -} - -/** Calculate the linear distance based on the rotation of a rotary axis */ -function getRadialDistance(axis, startTool, endTool, startABC, endABC) { - // rotary axis does not exist - if (!axis.isEnabled()) { - return 0.0; - } - - // calculate the rotary center based on head/table - var center; - if (axis.isHead()) { - var pivot; - if (typeof (headOffset) == "number") { - pivot = headOffset; - } else { - pivot = tool.getBodyLength(); - } - center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); - center = Vector.sum(center, axis.getOffset()); - } else { - center = axis.getOffset(); - } - - // calculate the radius of the tool end point compared to the rotary center - var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); - var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); - - // calculate length of radial move - var radius = Math.max(startRadius, endRadius); - var delta = Math.abs(endABC[axis.getCoordinate()] - startABC[axis.getCoordinate()]); - if (delta > Math.PI) { - delta = 2*Math.PI - delta; - } - var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); - return radialLength; -} - -/** Calculate tooltip, XYZ, and rotary move lengths. */ -function getMoveLength(_x, _y, _z, _a, _b, _c) { - // get starting and ending positions - var moveLength = new Array(); - var startTool; - var endTool; - var startXYZ; - var endXYZ; - var startABC = new Array(previousABC.x, previousABC.y, previousABC.z); - var endABC = new Array(_a, _b, _c); - - if (currentSection.getOptimizedTCPMode() == 0) { - startTool = getCurrentPosition(); - endTool = new Vector(_x, _y, _z); - startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); - endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); - } else { - startXYZ = getCurrentPosition(); - endXYZ = new Vector(_x, _y, _z); - startTool = machineConfiguration.getOrientation(previousABC).multiply(startXYZ); - endTool = machineConfiguration.getOrientation(new Vector(_a, _b, _c)).multiply(endXYZ); - } - - // calculate the radial portion of the move - var radialLength = Math.sqrt( - Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) - ); - - // calculate the lengths of move - // tool tip distance is the move distance based on a combination of linear and rotary axes movement - var linearLength = Vector.diff(endXYZ, startXYZ).length; - moveLength[0] = linearLength + radialLength; - moveLength[1] = Vector.diff(endXYZ, startXYZ).length; - moveLength[2] = Vector.diff( - new Vector(endABC[0], endABC[1], endABC[2]), - new Vector(startABC[0], startABC[1], startABC[2]) - ).length; - return moveLength; -} -// End of Multi-axis Feed Rate logic - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here - var aAxis = createAxis({coordinate:properties._got5thAxis ? 0 : 1, table:true, axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], preference:-1}); - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); - - if (properties._got4thAxis && !properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis); - } - if (properties._got4thAxis && properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } - - if (properties._got4thAxis) { - if (properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else { - machineConfiguration = new MachineConfiguration(aAxis); - } - } - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - } else { - writeBlock("!Makro file ; V9.09F!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); - switch (language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog) { - variablesDeclaration.push("optional_stop"); - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog) { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog) { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog) { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog) { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - variablesDeclaration.push("A_delta"); - variablesDeclaration.push("B_delta"); - variablesDeclaration.push("C_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - variablesDeclaration.push("A_temp"); - variablesDeclaration.push("B_temp"); - variablesDeclaration.push("C_temp"); - variablesDeclaration.push("Isinitialposition"); - variablesDeclaration.push("timefeed"); - - - submacrosDeclaration.push("Initposition"); - submacrosDeclaration.push("Endmacro"); - } - - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - submacrosDeclaration.push("Transformpath"); - } - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - submacrosDeclaration.push("Transformoffset"); - } - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("_exit Endmacro;"); - writeln(""); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - } - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); - writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); - writeln(""); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - createPositionInitSubmacro(); - createEndmacro(); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - createRtcpTransformationSubmacro(); - } - - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - //writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - writeBlock(translate("Label") + " " + sectionID + ";"); - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - - // wcs - var workOffset; - if (!is3D()) { - workOffset = 19; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } else { - workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - } - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - // insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function onRewindMachine() { - writeComment("REWIND"); -} - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - if (true) { - writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); - writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); - writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); - } - - if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { - writeBlock(translate("Submacro") + " Transformoffset 0, ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.y) +", ", - abcFormat.format(abc.z) +";"); - } - - currentWorkPlaneABC = abc; - previousABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - // error(localize("RTCP is not supported.")); - // return; - - writeBlock("("); - if (useInverseTime) { - writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); - } - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); - - writeBlock("A_temp = A - A_delta;"); - writeBlock("B_temp = B - B_delta;"); - writeBlock("C_temp = C - C_delta;"); - - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, B_temp, C_temp;"); - writeBlock(") Transformpath;"); - -} - -function createRtcpTransformationSubmacro() { - writeBlock("("); - writeBlock("Position 19, 2;"); - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X6p + X_trans;"); - writeBlock("Y_new = Y6p + Y_trans;"); - writeBlock("Z_new = Z6p + Z_trans;"); - writeBlock(";!set new position!;"); - writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); - writeBlock(") Transformoffset;"); -} - -function createPositionInitSubmacro() { - // get initial offset - writeBlock("("); - writeBlock("X_initial_pos = X6p;"); - writeBlock("Y_initial_pos = Y6p;"); - writeBlock("Z_initial_pos = Z6p;"); - writeBlock("A_initial_pos = A6p;"); - writeBlock("B_initial_pos = B6p;"); - writeBlock("C_initial_pos = C6p;"); - writeBlock("Position 19, 2;"); - writeBlock("X_delta = X_initial_pos - X6p;"); - writeBlock("Y_delta = Y_initial_pos - Y6p;"); - writeBlock("Z_delta = Z_initial_pos - Z6p;"); - writeBlock("A_delta = A_initial_pos - A6p;"); - writeBlock("B_delta = B_initial_pos - B6p;"); - writeBlock("C_delta = C_initial_pos - C6p;"); - writeBlock(") Initposition;"); -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - 10;"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - - -function createEndmacro() { - writeBlock("("); - if (useInverseTime) { - mcrSetTimeFeed(); - } - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); - - writeBlock("("); - if (isProbeOperation(currentSection)) { - writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // enable probe - writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); - } else { - writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // disable probe - } - - if (insertToolCall || newWorkOffset || newWorkPlane) { - - // retract to safe plane - retracted = true; - writeBlock(translate("Submacro") + " Retractzmax;"); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - retracted = true; - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("Position 19, 2;"); - writeBlock(translate("Submacro") + " Retractzmax;"); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - } else { - if (!retracted) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - (getPreviousSection().getPatternId() == currentSection.getPatternId())) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -//Implement G93 command -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -//Implement G94 command -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -//write a command to the cnc cernel without interpration from the control DANGEROUS -function directWriteToCNC(command){ - writeBlock("Mservice 1, 35, 0, 0, 0, 0, 0, 0, 0;"); - writeBlock("_N " + command); - writeBlock("Mservice 1, 35, 2, 0, 0, 0, 0, 0, 0;"); -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - if (currentSection.isOptimizedForMachine() && (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration())) { - // non TCP - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); - } else { - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); - previousABC = new Vector(_a, _b, _c); -} - -var currentFMode; -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); - - // get feed rate number - if (useInverseTime) { - var f = {frn:0, fmode:0}; - if (a || b || c) { - f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); - } else { - f.frn = feedOutput.format(feed); - f.fmode = 94; - } - } - - if (x || y || z || a || b || c) { - if (useRTCPSimu) { - if (useInverseTime) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - } else { - writeBlock(getFeed(feed)); - } - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTime ? f.frn : 0) + ";"); - } else { - if (useInverseTime) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); - } else { - writeBlock(getFeed(feed)); - } - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } - previousABC = new Vector(_a, _b, _c); -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 4/5 Achs Operationen gefunden. |" + - "\r\n| Sie muessen die Property |" + - "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + - "\r\n| andernfalls koennen Sie lediglich |" + - "\r\n| 3 Achsen Programme erzeugen. |" + - "\r\n| Besteht das Problem weiterhin, |" + - "\r\n| wenden Sie sich bitte an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return; // do not output coolants - } - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - if (useInverseTime && currentSection.isMultiAxis()) { - directWriteToCNC("G" + 94); - currentFMode = 94; - } - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - if (!isLastSection() && properties.showOperationDialog) { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - if (!is3D()) { - writeBlock(translate("Submacro") + " Initposition;"); - } - //write jump to start operation - if (properties.showOperationDialog) { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - // onCommand(COMMAND_COOLANT_OFF); - - if (!is3D()) { - writeBlock(translate("Submacro") + " Endmacro;"); - } - - writeBlock(translate("Submacro") + " Retractzmax;"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - if (properties.useParkPosition) { - writeBlock("Park;"); - } else { - writeBlock(translate("Submacro") + " Retractzmax;"); - zOutput.reset(); - } -} +/** + Copyright (C) 2012-2017 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {1FDF0D08-45B6-4EAD-A71D-7BA04089886D} +*/ + +// Mservice 1, 35, 0, 0, 0, 0, 0, 0, 0;!(ISO-PreProcessor wiederherstellen)! +// Mservice 1, 35, 2, 0, 0, 0, 0, 0, 0;!(ISO-PreProcessor deaktivieren)! + +description = "Generic DATRON MCR (German)"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON C5, DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: true, // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + useTimeStamp: false, // specifies to output time stamp + writeCoolantCommands: false, // en/disable coolant code output for the entire program + _got4thAxis: false, // specifies if the machine has a 4th axis + _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y + _got5thAxis: false // specifies if the machine has a 5th axis +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var language = "de"; // supported languages are: "en", "de" +var useRTCPSimu = true; // use TCP "light" or not +var useInverseTime = false; // enable inverseTime output here if needed + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; +var previousABC = new Vector(0, 0, 0); + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of Multi-axis Feed Rate logic +/***** Be sure to add 'useInverseTime' to post properties if necessary *****/ +/***** 'previousABC' must be added throughout to maintain previous rotary positions *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined *****/ +/***** The feed rate mode must be included in motion block output (linear, circular, etc. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 9999.999 * 2.9; // maximum value to output for Inverse Time feeds + +/** Calculate the multi-axis feed rate number */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTime) { // inverse time + var time = getInverseTime(length[0], feed); + f.frn = inverseTimeFormat.format(time); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = feedOutput.format(getFeedDPM(length, feed)); + f.fmode = 94; + } + return f; +} + +/** Calculate the DPM feed rate number */ +function getFeedDPM(_moveLength, _feed) { + // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC + + if (properties.useTCPMode) { // TCP mode is supported, output feed as FPM + return feed; + } else { // DPM feed rate calculation + var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; + var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); + return length / moveTime; + } +} + +/** Calculate the Inverse time feed rate number */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof (maxInverseTime) == "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof (maxInverseTime) == "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate the distance of the tool position to the center of a rotary axis */ +function getRotaryRadius(center, direction, toolPosition) { + var normal = direction.getNormalized(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis */ +function getRadialDistance(axis, startTool, endTool, startABC, endABC) { + // rotary axis does not exist + if (!axis.isEnabled()) { + return 0.0; + } + + // calculate the rotary center based on head/table + var center; + if (axis.isHead()) { + var pivot; + if (typeof (headOffset) == "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); + center = Vector.sum(center, axis.getOffset()); + } else { + center = axis.getOffset(); + } + + // calculate the radius of the tool end point compared to the rotary center + var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); + var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); + + // calculate length of radial move + var radius = Math.max(startRadius, endRadius); + var delta = Math.abs(endABC[axis.getCoordinate()] - startABC[axis.getCoordinate()]); + if (delta > Math.PI) { + delta = 2*Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = new Array(); + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC = new Array(previousABC.x, previousABC.y, previousABC.z); + var endABC = new Array(_a, _b, _c); + + if (currentSection.getOptimizedTCPMode() == 0) { + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); + endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); + } else { + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(previousABC).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(new Vector(_a, _b, _c)).multiply(endXYZ); + } + + // calculate the radial portion of the move + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) + ); + + // calculate the lengths of move + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + var linearLength = Vector.diff(endXYZ, startXYZ).length; + moveLength[0] = linearLength + radialLength; + moveLength[1] = Vector.diff(endXYZ, startXYZ).length; + moveLength[2] = Vector.diff( + new Vector(endABC[0], endABC[1], endABC[2]), + new Vector(startABC[0], startABC[1], startABC[2]) + ).length; + return moveLength; +} +// End of Multi-axis Feed Rate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here + var aAxis = createAxis({coordinate:properties._got5thAxis ? 0 : 1, table:true, axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], preference:-1}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + + if (properties._got4thAxis && !properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis); + } + if (properties._got4thAxis && properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } + + if (properties._got4thAxis) { + if (properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } else { + machineConfiguration = new MachineConfiguration(aAxis); + } + } + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); + switch (language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog) { + variablesDeclaration.push("optional_stop"); + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog) { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog) { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog) { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog) { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + submacrosDeclaration.push("Transformpath"); + } + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + submacrosDeclaration.push("Transformoffset"); + } + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + } + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + createRtcpTransformationSubmacro(); + } + + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + //writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + writeBlock(translate("Label") + " " + sectionID + ";"); + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset; + if (!is3D()) { + workOffset = 19; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } else { + workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + this.feed = feed; +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function onRewindMachine() { + writeComment("REWIND"); +} + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + if (true) { + writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); + writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); + writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); + } + + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.y) +", ", + abcFormat.format(abc.z) +";"); + } + + currentWorkPlaneABC = abc; + previousABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + // error(localize("RTCP is not supported.")); + // return; + + writeBlock("("); + if (useInverseTime) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, B_temp, C_temp;"); + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + writeBlock("A_initial_pos = A6p;"); + writeBlock("B_initial_pos = B6p;"); + writeBlock("C_initial_pos = C6p;"); + writeBlock("Position 19, 2;"); + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + writeBlock("A_delta = A_initial_pos - A6p;"); + writeBlock("B_delta = B_initial_pos - B6p;"); + writeBlock("C_delta = C_initial_pos - C6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - 10;"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + + +function createEndmacro() { + writeBlock("("); + if (useInverseTime) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); + + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // disable probe + } + + if (insertToolCall || newWorkOffset || newWorkPlane) { + + // retract to safe plane + retracted = true; + writeBlock(translate("Submacro") + " Retractzmax;"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + retracted = true; + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("Position 19, 2;"); + writeBlock(translate("Submacro") + " Retractzmax;"); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + } else { + if (!retracted) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + (getPreviousSection().getPatternId() == currentSection.getPatternId())) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +//Implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +//Implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +//write a command to the cnc cernel without interpration from the control DANGEROUS +function directWriteToCNC(command){ + writeBlock("Mservice 1, 35, 0, 0, 0, 0, 0, 0, 0;"); + writeBlock("_N " + command); + writeBlock("Mservice 1, 35, 2, 0, 0, 0, 0, 0, 0;"); +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration())) { + // non TCP + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); + previousABC = new Vector(_a, _b, _c); +} + +var currentFMode; +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); + + // get feed rate number + if (useInverseTime) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCPSimu) { + if (useInverseTime) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTime ? f.frn : 0) + ";"); + } else { + if (useInverseTime) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } + previousABC = new Vector(_a, _b, _c); +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return; // do not output coolants + } + if (coolant == currentCoolantMode) { + return; // coolant is already active + } + + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTime && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && properties.showOperationDialog) { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (!is3D()) { + writeBlock(translate("Submacro") + " Initposition;"); + } + //write jump to start operation + if (properties.showOperationDialog) { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // onCommand(COMMAND_COOLANT_OFF); + + if (!is3D()) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeBlock(translate("Submacro") + " Retractzmax;"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (properties.useParkPosition) { + writeBlock("Park;"); + } else { + writeBlock(translate("Submacro") + " Retractzmax;"); + zOutput.reset(); + } +} diff --git a/SimP_Sequence2.cps b/deprecated/SimP_Sequence2.cps similarity index 96% rename from SimP_Sequence2.cps rename to deprecated/SimP_Sequence2.cps index 8554a82..1849459 100644 --- a/SimP_Sequence2.cps +++ b/deprecated/SimP_Sequence2.cps @@ -1,388 +1,388 @@ -/** - Copyright (C) 2012-2014 by Autodesk, Inc. - All rights reserved. - - Minimal post processor configuration. - - $Revision: 40941 d23033c3af7c1d3a5723876fd4bd23be0cdb24b5 $ - $Date: 2016-01-16 19:30:18 $ - - FORKID {96F3CC76-19C0-4828-BF27-6A50AED3B187} -*/ - -description = "Minimal Heidenhain"; -vendor = "Autodesk"; -vendorUrl = "http://www.autodesk.com"; -legal = "Copyright (C) 2012-2014 by Autodesk, Inc."; -certificationLevel = 2; - -extension = "simpl"; -setCodePage("utf-8"); - -var spindleAxisTable = new Table(["X", "Y", "Z"], {force:true}); - -var radiusCompensationTable = new Table( - [" R0", " RL", " RR"], - {initial:RADIUS_COMPENSATION_OFF}, - "Invalid radius compensation" -); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(120); -allowHelicalMoves = true; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - - -var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true}); -var feedFormat = createFormat({decimals:(unit == MM ? 0 : 2), scale:(unit == MM ? 1 : 10)}); -var rpmFormat = createFormat({decimals:0}); -var mFormat = createFormat({prefix:"M", decimals:0}); -var toolFormat = createFormat({decimals:0}); -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); - -var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); -var xOutput = createVariable({prefix:" X="}, xyzFormat); -var yOutput = createVariable({prefix:" Y="}, xyzFormat); -var zOutput = createVariable({prefix:" Z="}, xyzFormat); -var iOutput = createVariable({prefix:" dX=", force : true}, feedFormat); -var jOutput = createVariable({prefix:" dY=", force : true}, feedFormat); -var kOutput = createVariable({prefix:" dZ="}, feedFormat); - -var feedOutput = createVariable({prefix:"Feed="}, feedFormat); - -var blockNumber = 0; - -/** - Writes the specified block. -*/ -function writeBlock(block) { - writeln(block); -} - -function onOpen() { - writeBlock("module SimPlSequence" + (programName ? (programName) : "")); - writeBlock(""); - createToolDescriptionTable(); - writeBlock(""); - writeWorkpiece(); - writeBlock(""); - writeBlock((unit == MM) ? "@ MeasuringSystem = \"Metric\" @" : " @ MeasuringSystem = \"Inch\" @"); - writeBlock(""); - writeBlock("sequence SimPLSequence"); - writeBlock(""); - writeBlock("using Base"); - writeBlock(""); - writeBlock("export program Main"); - writeBlock(" Spindle On"); // spindle on - clockwise - writeBlock(" SimPLSequence"); - writeBlock("endprogram"); - writeBlock(""); - writeBlock("end"); - writeBlock(""); - writeBlock("$$$SimPLSequence"); -} - -/** - Invalidates the current position and feedrate. Invoke this function to - force X, Y, Z, and F in the following block. -*/ -function invalidate() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); - feedOutput.reset(); -} - -function onSection() { - //TODO - writeBlock("MoveToSafetyPosition"); - var retracted = true; - - writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + - " newRpm=" + rpmFormat.format(tool.spindleRPM) + - " skipRestoring" -); - - setTranslation(currentSection.workOrigin); - setRotation(currentSection.workPlane); - - invalidate(); - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock("Rapid" + zOutput.format(initialPosition.z)); - } - } - writeBlock("Line" + xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z)); -} - -function onRapid(x, y, z) { - var xyz = xOutput.format(x) + yOutput.format(y) + zOutput.format(z); - if (xyz) { - writeBlock("Rapid" + xyz); - feedOutput.reset(); - } -} - -function onLinear(x, y, z, feed) { - var xyz = xOutput.format(x) + yOutput.format(y) + zOutput.format(z); - var f = feedOutput.format(feed); - if(f){ - writeBlock(f); - } - if (xyz) { - writeBlock("Line" + xyz); - } -} - -function onSectionEnd() { - // full retract in machine coordinate system - writeBlock("MoveToSafetyPosition"); - invalidate(); -} - -function onClose() { - writeBlock("Spindle Off"); // stop program, spindle stop, coolant off -} - -function createToolDescriptionTable() { - var toolDescriptionArray = new Array(); - var toolNameList = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var tool = section.getTool(); - if (tool.type != TOOL_PROBE) { - var toolName = createToolName(tool); - var toolProgrammed = createToolDescription(tool); - if (toolNameList.indexOf(toolName) == -1) { - toolNameList.push(toolName); - toolDescriptionArray.push(toolProgrammed); - } else { - /* - if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { - error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + - toolNameList.join("\r\n") + "#####################################\r\n"); - } - */ - } - } - } - - writeBlock(toolDescriptionArray.join("\r\n")); - } - - function createToolDescription(tool) { - var toolProgrammed = "@ ToolDescription : " + - "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + - "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + - "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + - "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + - "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + - "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + - "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + - "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + - "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + - "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + - "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + - "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + - "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + - "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + - "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + - " @"; - return toolProgrammed; - } - - /** - Generate the logical tool name for the assignment table of used tools. -*/ -function createToolName(tool) { - var toolName = toolFormat.format(tool.number); - toolName += "_" + translateToolType(tool.type); - if (tool.comment) { - toolName += "_" + tool.comment; - } - if (tool.diameter) { - toolName += "_D" + tool.diameter; - } - var description = tool.getDescription(); - if (description) { - toolName += "_" + description; - } - toolName = formatVariable(toolName); - return toolName; - } - - -/** - Translate HSM tools to Datron tool categories. -*/ -function translateToolType(toolType) { - - var datronCategoryName = ""; - - toolCategory = toolType; - switch (toolType) { - case TOOL_UNSPECIFIED: - datronCategoryName = "Unspecified"; - break; - case TOOL_DRILL: - datronCategoryName = "Drill"; - break; - case TOOL_DRILL_CENTER: - datronCategoryName = "DrillCenter"; - break; - case TOOL_DRILL_SPOT: - datronCategoryName = "DrillSpot"; - break; - case TOOL_DRILL_BLOCK: - datronCategoryName = "DrillBlock"; - break; - case TOOL_MILLING_END_FLAT: - datronCategoryName = "MillingEndFlat"; - break; - case TOOL_MILLING_END_BALL: - datronCategoryName = "MillingEndBall"; - break; - case TOOL_MILLING_END_BULLNOSE: - datronCategoryName = "MillingEndBullnose"; - break; - case TOOL_MILLING_CHAMFER: - datronCategoryName = "Graver"; - break; - case TOOL_MILLING_FACE: - datronCategoryName = "MillingFace"; - break; - case TOOL_MILLING_SLOT: - datronCategoryName = "MillingSlot"; - break; - case TOOL_MILLING_RADIUS: - datronCategoryName = "MillingRadius"; - break; - case TOOL_MILLING_DOVETAIL: - datronCategoryName = "MillingDovetail"; - break; - case TOOL_MILLING_TAPERED: - datronCategoryName = "MillingTapered"; - break; - case TOOL_MILLING_LOLLIPOP: - datronCategoryName = "MillingLollipop"; - break; - case TOOL_TAP_RIGHT_HAND: - datronCategoryName = "TapRightHand"; - break; - case TOOL_TAP_LEFT_HAND: - datronCategoryName = "TapLeftHand"; - break; - case TOOL_REAMER: - datronCategoryName = "Reamer"; - break; - case TOOL_BORING_BAR: - datronCategoryName = "BoringBar"; - break; - case TOOL_COUNTER_BORE: - datronCategoryName = "CounterBore"; - break; - case TOOL_COUNTER_SINK: - datronCategoryName = "CounterSink"; - break; - case TOOL_HOLDER_ONLY: - datronCategoryName = "HolderOnly"; - break; - case TOOL_PROBE: - datronCategoryName = "XYZSensor"; - break; - default: - datronCategoryName = "Unspecified"; - } - return datronCategoryName; - } - - -function formatVariable(text) { - return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); - } - - function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("# Workpiece dimensions"); - writeBlock( - "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z)); - writeBlock( - "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z)); - writeBlock( - "# Part size X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z)); - - writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + - "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + - " @"); - writeBlock(" "); - } - - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = feedOutput.format(feed); - if(f){ - writeBlock(f); - } - - // if (pendingRadiusCompensation >= 0) { - // error(localize("radius compensation cannot be activated/deactivated for a circular move.")); - // return; - // } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (isHelical()) { - linearize(tolerance); - return; - } - // TAG: are 360deg arcs supported - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } else { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - yOutput.format(y) + - zOutput.format(z) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } -} +/** + Copyright (C) 2012-2014 by Autodesk, Inc. + All rights reserved. + + Minimal post processor configuration. + + $Revision: 40941 d23033c3af7c1d3a5723876fd4bd23be0cdb24b5 $ + $Date: 2016-01-16 19:30:18 $ + + FORKID {96F3CC76-19C0-4828-BF27-6A50AED3B187} +*/ + +description = "Minimal Heidenhain"; +vendor = "Autodesk"; +vendorUrl = "http://www.autodesk.com"; +legal = "Copyright (C) 2012-2014 by Autodesk, Inc."; +certificationLevel = 2; + +extension = "simpl"; +setCodePage("utf-8"); + +var spindleAxisTable = new Table(["X", "Y", "Z"], {force:true}); + +var radiusCompensationTable = new Table( + [" R0", " RL", " RR"], + {initial:RADIUS_COMPENSATION_OFF}, + "Invalid radius compensation" +); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = true; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + + +var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true}); +var feedFormat = createFormat({decimals:(unit == MM ? 0 : 2), scale:(unit == MM ? 1 : 10)}); +var rpmFormat = createFormat({decimals:0}); +var mFormat = createFormat({prefix:"M", decimals:0}); +var toolFormat = createFormat({decimals:0}); +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); + +var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); +var xOutput = createVariable({prefix:" X="}, xyzFormat); +var yOutput = createVariable({prefix:" Y="}, xyzFormat); +var zOutput = createVariable({prefix:" Z="}, xyzFormat); +var iOutput = createVariable({prefix:" dX=", force : true}, feedFormat); +var jOutput = createVariable({prefix:" dY=", force : true}, feedFormat); +var kOutput = createVariable({prefix:" dZ="}, feedFormat); + +var feedOutput = createVariable({prefix:"Feed="}, feedFormat); + +var blockNumber = 0; + +/** + Writes the specified block. +*/ +function writeBlock(block) { + writeln(block); +} + +function onOpen() { + writeBlock("module SimPlSequence" + (programName ? (programName) : "")); + writeBlock(""); + createToolDescriptionTable(); + writeBlock(""); + writeWorkpiece(); + writeBlock(""); + writeBlock((unit == MM) ? "@ MeasuringSystem = \"Metric\" @" : " @ MeasuringSystem = \"Inch\" @"); + writeBlock(""); + writeBlock("sequence SimPLSequence"); + writeBlock(""); + writeBlock("using Base"); + writeBlock(""); + writeBlock("export program Main"); + writeBlock(" Spindle On"); // spindle on - clockwise + writeBlock(" SimPLSequence"); + writeBlock("endprogram"); + writeBlock(""); + writeBlock("end"); + writeBlock(""); + writeBlock("$$$SimPLSequence"); +} + +/** + Invalidates the current position and feedrate. Invoke this function to + force X, Y, Z, and F in the following block. +*/ +function invalidate() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); + feedOutput.reset(); +} + +function onSection() { + //TODO + writeBlock("MoveToSafetyPosition"); + var retracted = true; + + writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + + " newRpm=" + rpmFormat.format(tool.spindleRPM) + + " skipRestoring" +); + + setTranslation(currentSection.workOrigin); + setRotation(currentSection.workPlane); + + invalidate(); + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock("Rapid" + zOutput.format(initialPosition.z)); + } + } + writeBlock("Line" + xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z)); +} + +function onRapid(x, y, z) { + var xyz = xOutput.format(x) + yOutput.format(y) + zOutput.format(z); + if (xyz) { + writeBlock("Rapid" + xyz); + feedOutput.reset(); + } +} + +function onLinear(x, y, z, feed) { + var xyz = xOutput.format(x) + yOutput.format(y) + zOutput.format(z); + var f = feedOutput.format(feed); + if(f){ + writeBlock(f); + } + if (xyz) { + writeBlock("Line" + xyz); + } +} + +function onSectionEnd() { + // full retract in machine coordinate system + writeBlock("MoveToSafetyPosition"); + invalidate(); +} + +function onClose() { + writeBlock("Spindle Off"); // stop program, spindle stop, coolant off +} + +function createToolDescriptionTable() { + var toolDescriptionArray = new Array(); + var toolNameList = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var tool = section.getTool(); + if (tool.type != TOOL_PROBE) { + var toolName = createToolName(tool); + var toolProgrammed = createToolDescription(tool); + if (toolNameList.indexOf(toolName) == -1) { + toolNameList.push(toolName); + toolDescriptionArray.push(toolProgrammed); + } else { + /* + if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { + error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + + toolNameList.join("\r\n") + "#####################################\r\n"); + } + */ + } + } + } + + writeBlock(toolDescriptionArray.join("\r\n")); + } + + function createToolDescription(tool) { + var toolProgrammed = "@ ToolDescription : " + + "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + + "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + + "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + + "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + + "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + + "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + + "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + + "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + + "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + + "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + + "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + + "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + + "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + + "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + + "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + + " @"; + return toolProgrammed; + } + + /** + Generate the logical tool name for the assignment table of used tools. +*/ +function createToolName(tool) { + var toolName = toolFormat.format(tool.number); + toolName += "_" + translateToolType(tool.type); + if (tool.comment) { + toolName += "_" + tool.comment; + } + if (tool.diameter) { + toolName += "_D" + tool.diameter; + } + var description = tool.getDescription(); + if (description) { + toolName += "_" + description; + } + toolName = formatVariable(toolName); + return toolName; + } + + +/** + Translate HSM tools to Datron tool categories. +*/ +function translateToolType(toolType) { + + var datronCategoryName = ""; + + toolCategory = toolType; + switch (toolType) { + case TOOL_UNSPECIFIED: + datronCategoryName = "Unspecified"; + break; + case TOOL_DRILL: + datronCategoryName = "Drill"; + break; + case TOOL_DRILL_CENTER: + datronCategoryName = "DrillCenter"; + break; + case TOOL_DRILL_SPOT: + datronCategoryName = "DrillSpot"; + break; + case TOOL_DRILL_BLOCK: + datronCategoryName = "DrillBlock"; + break; + case TOOL_MILLING_END_FLAT: + datronCategoryName = "MillingEndFlat"; + break; + case TOOL_MILLING_END_BALL: + datronCategoryName = "MillingEndBall"; + break; + case TOOL_MILLING_END_BULLNOSE: + datronCategoryName = "MillingEndBullnose"; + break; + case TOOL_MILLING_CHAMFER: + datronCategoryName = "Graver"; + break; + case TOOL_MILLING_FACE: + datronCategoryName = "MillingFace"; + break; + case TOOL_MILLING_SLOT: + datronCategoryName = "MillingSlot"; + break; + case TOOL_MILLING_RADIUS: + datronCategoryName = "MillingRadius"; + break; + case TOOL_MILLING_DOVETAIL: + datronCategoryName = "MillingDovetail"; + break; + case TOOL_MILLING_TAPERED: + datronCategoryName = "MillingTapered"; + break; + case TOOL_MILLING_LOLLIPOP: + datronCategoryName = "MillingLollipop"; + break; + case TOOL_TAP_RIGHT_HAND: + datronCategoryName = "TapRightHand"; + break; + case TOOL_TAP_LEFT_HAND: + datronCategoryName = "TapLeftHand"; + break; + case TOOL_REAMER: + datronCategoryName = "Reamer"; + break; + case TOOL_BORING_BAR: + datronCategoryName = "BoringBar"; + break; + case TOOL_COUNTER_BORE: + datronCategoryName = "CounterBore"; + break; + case TOOL_COUNTER_SINK: + datronCategoryName = "CounterSink"; + break; + case TOOL_HOLDER_ONLY: + datronCategoryName = "HolderOnly"; + break; + case TOOL_PROBE: + datronCategoryName = "XYZSensor"; + break; + default: + datronCategoryName = "Unspecified"; + } + return datronCategoryName; + } + + +function formatVariable(text) { + return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); + } + + function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("# Workpiece dimensions"); + writeBlock( + "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z)); + writeBlock( + "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z)); + writeBlock( + "# Part size X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z)); + + writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + + "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + + " @"); + writeBlock(" "); + } + + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = feedOutput.format(feed); + if(f){ + writeBlock(f); + } + + // if (pendingRadiusCompensation >= 0) { + // error(localize("radius compensation cannot be activated/deactivated for a circular move.")); + // return; + // } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + yOutput.format(y) + + zOutput.format(z) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } +} diff --git a/datron c5.cps b/deprecated/datron c5.cps similarity index 97% rename from datron c5.cps rename to deprecated/datron c5.cps index 4adaa16..d332620 100644 --- a/datron c5.cps +++ b/deprecated/datron c5.cps @@ -1,1807 +1,1807 @@ -/** - Copyright (C) 2012-2017 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {DC597035-3395-48C2-BA86-28EFF6A7E339} -*/ - -description = "DATRON C5"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -longDescription = "Post for DATRON C5."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only -mapWorkOrigin = false; - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: true, // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useTimeStamp: false, // specifies to output time stamp - writeCoolantCommands: false // en/disable coolant code output for the entire program -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var language = "de"; // supported languages are: "en", "de" - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - - if (true) { // note: setup your machine here - var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 100.001], preference:0}); - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[0, 360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(0); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.85D!"); - } else { - writeBlock("!Makro file ; V9.85D!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); - switch (language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog) { - variablesDeclaration.push("optional_stop"); - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog) { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - - // Write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog) { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog) { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog) { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // submacrosDeclaration.push("Initposition"); - // submacrosDeclaration.push("Endmacro"); - } - - // variablesDeclaration.push("Curr_zpno"); - // variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock("_exit Endmacro;"); - // writeln(""); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // createEndmacro(); - } -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - // writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - writeBlock(translate("Label") + " " + sectionID + ";"); - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - -/* - // wcs - var workOffset; - if (!is3D()) { - workOffset = 19; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } else { - workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - } -*/ - writeBlock(translate("Submacro") + " " + sectionName + ";"); - } -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function onRewindMachine() { - writeComment("REWIND OF MACHINE AXIS"); -} - -function setWorkPlane(abc, turn) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - - var st = turn ? 1 : 0; - // move origin - var initialPosition = getFramePosition((currentSection.getInitialPosition())); - var xv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.x : currentSection.workOrigin.x) : xyzFormat.format(0); - var yv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.y : currentSection.workOrigin.y) : xyzFormat.format(0); - var zv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.z : currentSection.workOrigin.z) : xyzFormat.format(0); - - // rotate workplane and axis - var xs = abcFormat.format(abc.x); - var ys = abcFormat.format(abc.y); - var zs = abcFormat.format(abc.z); - var wz = turn ? 0 : 2; // 0 = indexing with retract 1= indexing with moving tool 2 = coordinate system rotation only - var vr = feedFormat.format(10000); // feed for indexing - - if (turn) { - writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";"); - writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";"); - } else { - writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";"); - writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";"); - } - - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); - - writeBlock("("); - - if (insertToolCall || newWorkOffset || newWorkPlane) { - // retract to safe plane - retracted = true; - writeBlock(translate("ToolRetraction") + ";"); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - retracted = true; - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - if (!retracted) { - writeBlock(translate("ToolRetraction") + ";"); - } - } else { - var eulerXYZ = currentSection.workPlane.getTransposed().eulerZYX_R; - var abc = new Vector(-eulerXYZ.x, -eulerXYZ.y, -eulerXYZ.z); - setWorkPlane(abc, true); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !isProbeOperation(currentSection)) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("ToolRetraction") + ";"); - } - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - writeComment("Prepositioning start"); - setWorkPlane(abc, true); - writeBlock(gMotionModal.format(1), xyzFormat.format(0) + ", " + xyzFormat.format(0) + ", " + "z6p" + ";"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + xyzFormat.format(0) + ";"); - setWorkPlane(new Vector(0, 0, 0), false); - writeComment("Prepositioning end"); - cancelTransformation(); - forceWorkPlane(); - if (currentSection.getOptimizedTCPMode() == 0) { - writeBlock("Rtcp 1;"); - } - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - (getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0)) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -/** Implement G93 command. */ -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -/** Implement G94 command. */ -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -/** Write a command to the cnc kernel without interpretation from the control DANGEROUS. */ -function directWriteToCNC(command) { - error(localize("Inverse Time feed is currently not supported.")); - return; -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - - forceFeed(); -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); - - if (x || y || z || a || b || c) { - writeBlock(getFeed(feed)); - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "ToolRetraction": - return "Wzrueckzug"; - case "Shift": - return "Verschieben"; - case "Tilt": - return "Schwenken"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 4/5 Achs Operationen gefunden. |" + - "\r\n| Sie muessen die Property |" + - "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + - "\r\n| andernfalls koennen Sie lediglich |" + - "\r\n| 3 Achsen Programme erzeugen. |" + - "\r\n| Besteht das Problem weiterhin, |" + - "\r\n| wenden Sie sich bitte an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return; // do not output coolants - } - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("Rtcp 0;"); - } - - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - - writeBlock(translate("ToolRetraction") + ";"); // optional - setWorkPlane(new Vector(0, 0, 0), false); // optional - forceWorkPlane(); // optional - - if (!isLastSection() && properties.showOperationDialog) { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - - // write jump to start operation - if (properties.showOperationDialog) { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - - writeBlock(translate("ToolRetraction") + ";"); - - // setWorkPlane(new Vector(0, 0, 0), false); // reset working plane - writeBlock("Clamping_position"); - zOutput.reset(); -} +/** + Copyright (C) 2012-2017 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {DC597035-3395-48C2-BA86-28EFF6A7E339} +*/ + +description = "DATRON C5"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +longDescription = "Post for DATRON C5."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only +mapWorkOrigin = false; + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: true, // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useTimeStamp: false, // specifies to output time stamp + writeCoolantCommands: false // en/disable coolant code output for the entire program +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var language = "de"; // supported languages are: "en", "de" + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + + if (true) { // note: setup your machine here + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 100.001], preference:0}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[0, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(0); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.85D!"); + } else { + writeBlock("!Makro file ; V9.85D!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); + switch (language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog) { + variablesDeclaration.push("optional_stop"); + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog) { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + + // Write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog) { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog) { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog) { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // submacrosDeclaration.push("Initposition"); + // submacrosDeclaration.push("Endmacro"); + } + + // variablesDeclaration.push("Curr_zpno"); + // variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock("_exit Endmacro;"); + // writeln(""); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // createEndmacro(); + } +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + // writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + writeBlock(translate("Label") + " " + sectionID + ";"); + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + +/* + // wcs + var workOffset; + if (!is3D()) { + workOffset = 19; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } else { + workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + } +*/ + writeBlock(translate("Submacro") + " " + sectionName + ";"); + } +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + this.feed = feed; +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function onRewindMachine() { + writeComment("REWIND OF MACHINE AXIS"); +} + +function setWorkPlane(abc, turn) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + + var st = turn ? 1 : 0; + // move origin + var initialPosition = getFramePosition((currentSection.getInitialPosition())); + var xv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.x : currentSection.workOrigin.x) : xyzFormat.format(0); + var yv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.y : currentSection.workOrigin.y) : xyzFormat.format(0); + var zv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.z : currentSection.workOrigin.z) : xyzFormat.format(0); + + // rotate workplane and axis + var xs = abcFormat.format(abc.x); + var ys = abcFormat.format(abc.y); + var zs = abcFormat.format(abc.z); + var wz = turn ? 0 : 2; // 0 = indexing with retract 1= indexing with moving tool 2 = coordinate system rotation only + var vr = feedFormat.format(10000); // feed for indexing + + if (turn) { + writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";"); + writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";"); + } else { + writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";"); + writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";"); + } + + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); + + writeBlock("("); + + if (insertToolCall || newWorkOffset || newWorkPlane) { + // retract to safe plane + retracted = true; + writeBlock(translate("ToolRetraction") + ";"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + retracted = true; + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + if (!retracted) { + writeBlock(translate("ToolRetraction") + ";"); + } + } else { + var eulerXYZ = currentSection.workPlane.getTransposed().eulerZYX_R; + var abc = new Vector(-eulerXYZ.x, -eulerXYZ.y, -eulerXYZ.z); + setWorkPlane(abc, true); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("ToolRetraction") + ";"); + } + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + writeComment("Prepositioning start"); + setWorkPlane(abc, true); + writeBlock(gMotionModal.format(1), xyzFormat.format(0) + ", " + xyzFormat.format(0) + ", " + "z6p" + ";"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + xyzFormat.format(0) + ";"); + setWorkPlane(new Vector(0, 0, 0), false); + writeComment("Prepositioning end"); + cancelTransformation(); + forceWorkPlane(); + if (currentSection.getOptimizedTCPMode() == 0) { + writeBlock("Rtcp 1;"); + } + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + (getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0)) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +/** Implement G93 command. */ +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +/** Implement G94 command. */ +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +/** Write a command to the cnc kernel without interpretation from the control DANGEROUS. */ +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); + + if (x || y || z || a || b || c) { + writeBlock(getFeed(feed)); + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "ToolRetraction": + return "Wzrueckzug"; + case "Shift": + return "Verschieben"; + case "Tilt": + return "Schwenken"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return; // do not output coolants + } + if (coolant == currentCoolantMode) { + return; // coolant is already active + } + + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("Rtcp 0;"); + } + + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + + writeBlock(translate("ToolRetraction") + ";"); // optional + setWorkPlane(new Vector(0, 0, 0), false); // optional + forceWorkPlane(); // optional + + if (!isLastSection() && properties.showOperationDialog) { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + + // write jump to start operation + if (properties.showOperationDialog) { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + + writeBlock(translate("ToolRetraction") + ";"); + + // setWorkPlane(new Vector(0, 0, 0), false); // reset working plane + writeBlock("Clamping_position"); + zOutput.reset(); +} diff --git a/datron iso.cps b/deprecated/datron iso.cps similarity index 96% rename from datron iso.cps rename to deprecated/datron iso.cps index 118327a..3708423 100644 --- a/datron iso.cps +++ b/deprecated/datron iso.cps @@ -1,749 +1,749 @@ -/** - Copyright (C) 2012-2013 by Autodesk, Inc. - All rights reserved. - - Datron ISO post processor configuration. - - $Revision$ - $Date$ - - FORKID {2EECF092-D7C3-4aca-BFE6-377B72950FE9} -*/ - -description = "Datron ISO"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2013 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -extension = "nc"; -setCodePage("ascii"); - -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(180); -allowHelicalMoves = true; -allowedCircularPlanes = undefined; // allow any circular motion - - - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeTools: true, // writes the tools - preloadTool: true, // preloads next tool on tool change if any - showSequenceNumbers: true, // show sequence numbers - sequenceNumberStart: 10, // first sequence number - sequenceNumberIncrement: 5, // increment for sequence numbers - optionalStop: true, // optional stop - separateWordsWithSpace: true // specifies that the words should be separated with a white space -}; - -var numberOfToolSlots = 9999; - - - -var mapCoolantTable = new Table( - [9, 8, 7], - {initial:COOLANT_OFF, force:true}, - "Invalid coolant mode" -); - -var gFormat = createFormat({prefix:"G", decimals:0}); -var mFormat = createFormat({prefix:"M", decimals:0}); -var hFormat = createFormat({prefix:"H", decimals:0}); -var dFormat = createFormat({prefix:"D", decimals:0}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4)}); -var feedFormat = createFormat({decimals:(unit == MM ? 1 : 2)}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 -var taperFormat = createFormat({decimals:1, scale:DEG}); - -var xOutput = createVariable({prefix:"X"}, xyzFormat); -var yOutput = createVariable({prefix:"Y"}, xyzFormat); -var zOutput = createVariable({prefix:"Z"}, xyzFormat); -var feedOutput = createVariable({prefix:"F"}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); -var dOutput = createVariable({}, dFormat); - -// circular output -var iOutput = createReferenceVariable({prefix:"I"}, xyzFormat); -var jOutput = createReferenceVariable({prefix:"J"}, xyzFormat); - -var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 -var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 -var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... -var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 - -var WARNING_WORK_OFFSET = 0; - -// collected state -var sequenceNumber; -var currentWorkOffset; - -/** - Writes the specified block. -*/ -function writeBlock() { - if (properties.showSequenceNumbers) { - writeWords2("N" + sequenceNumber, arguments); - sequenceNumber += properties.sequenceNumberIncrement; - } else { - writeWords(arguments); - } -} - -function formatComment(text) { - return "(" + String(text).replace(/[\(\)]/g, "") + ")"; -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln(formatComment(text)); -} - -function onOpen() { - if (!properties.separateWordsWithSpace) { - setWordSeparator(""); - } - - sequenceNumber = properties.sequenceNumberStart; - writeln("%"); - - if (programName) { - writeComment(programName); - } - if (programComment) { - writeComment(programComment); - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - - // dump tool information - if (properties.writeTools) { - var zRanges = {}; - if (is3D()) { - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var zRange = section.getGlobalZRange(); - var tool = section.getTool(); - if (zRanges[tool.number]) { - zRanges[tool.number].expandToRange(zRange); - } else { - zRanges[tool.number] = zRange; - } - } - } - - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + toolFormat.format(tool.number) + " " + - "D=" + xyzFormat.format(tool.diameter) + " " + - localize("CR") + "=" + xyzFormat.format(tool.cornerRadius); - if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) { - comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg"); - } - if (zRanges[tool.number]) { - comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum()); - } - comment += " - " + getToolTypeName(tool.type); - writeComment(comment); - } - } - } - - // absolute coordinates and feed per min - writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94)); - writeBlock(gPlaneModal.format(17)); - - switch (unit) { - case IN: - writeBlock(gUnitModal.format(20)); - break; - case MM: - writeBlock(gUnitModal.format(21)); - break; - } -} - -function onComment(message) { - writeComment(message); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of X, Y, Z, and F on next output. */ -function forceAny() { - forceXYZ(); - feedOutput.reset(); -} - -function onSection() { - var insertToolCall = isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); - if (insertToolCall || newWorkOffset || newWorkPlane) { - - // stop spindle before retract during tool change - if (insertToolCall && !isFirstSection()) { - onCommand(COMMAND_STOP_SPINDLE); - } - - // retract to safe plane - retracted = true; - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract - writeBlock(gAbsIncModal.format(90)); - zOutput.reset(); - } - - if (hasParameter("operation-comment")) { - var comment = getParameter("operation-comment"); - if (comment) { - writeComment(comment); - } - } - - if (insertToolCall) { - retracted = true; - onCommand(COMMAND_COOLANT_OFF); - - if (!isFirstSection() && properties.optionalStop) { - onCommand(COMMAND_OPTIONAL_STOP); - } - - if (tool.number > numberOfToolSlots) { - warning(localize("Tool number exceeds maximum value.")); - } - - writeBlock("T" + toolFormat.format(tool.number)); - if (tool.comment) { - writeComment(tool.comment); - } - var showToolZMin = false; - if (showToolZMin) { - if (is3D()) { - var numberOfSections = getNumberOfSections(); - var zRange = currentSection.getGlobalZRange(); - var number = tool.number; - for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) { - var section = getSection(i); - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - } - writeComment(localize("ZMIN") + "=" + zRange.getMinimum()); - } - } - - if (properties.preloadTool) { - var nextTool = getNextTool(tool.number); - if (nextTool) { - writeBlock("T" + toolFormat.format(nextTool.number)); - } else { - // preload first tool - var section = getSection(0); - var firstToolNumber = section.getTool().number; - if (tool.number != firstToolNumber) { - writeBlock("T" + toolFormat.format(firstToolNumber)); - } - } - } - } - - if (insertToolCall || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - if (tool.spindleRPM < 1) { - error(localize("Spindle speed out of range.")); - } - if (tool.spindleRPM > 99999) { - warning(localize("Spindle speed exceeds maximum value.")); - } - writeBlock( - sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4) - ); - } - - // wcs - if (insertToolCall) { // force work offset when changing tool - currentWorkOffset = undefined; - } - var workOffset = currentSection.workOffset; - if (workOffset == 0) { - warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET); - workOffset = 1; - } - if (workOffset > 0) { - if (workOffset > 6) { - var code = workOffset - 6; - if (code > 3) { - error(localize("Work offset out of range.")); - } - if (workOffset != currentWorkOffset) { - writeBlock(gFormat.format(59) + "." + code); - currentWorkOffset = workOffset; - } - } else { - if (workOffset != currentWorkOffset) { - writeBlock(gFormat.format(53 + workOffset)); // G54->G59 - currentWorkOffset = workOffset; - } - } - } - - forceXYZ(); - - { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - error(localize("Tool orientation is not supported.")); - return; - } - setRotation(remaining); - } - - // set coolant after we have positioned at Z - { - var c = mapCoolantTable.lookup(tool.coolant); - if (c) { - writeBlock(mFormat.format(c)); - } else { - warning(localize("Coolant not supported.")); - } - } - - forceAny(); - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); - } - } - - if (insertToolCall || retracted) { - var lengthOffset = tool.lengthOffset; - if (lengthOffset > numberOfToolSlots) { - error(localize("Length offset out of range.")); - } - - if (!machineConfiguration.isHeadConfiguration()) { - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y) - ); - writeBlock(gMotionModal.format(0), gFormat.format(43), zOutput.format(initialPosition.z), hFormat.format(lengthOffset)); - } else { - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(0), - gFormat.format(43), xOutput.format(initialPosition.x), - yOutput.format(initialPosition.y), - zOutput.format(initialPosition.z), hFormat.format(lengthOffset) - ); - } - } else { - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(0), - xOutput.format(initialPosition.x), - yOutput.format(initialPosition.y) - ); - } - - if (insertToolCall) { - gPlaneModal.reset(); - } -} - -function onDwell(seconds) { - if (seconds > 99999.999) { - warning(localize("Dwelling time is out of range.")); - } - seconds = clamp(0.001, seconds, 99999.999); - writeBlock(gFormat.format(4), "P" + secFormat.format(seconds)); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(sOutput.format(spindleSpeed)); -} - -function onCycle() { - // writeBlock(gPlaneModal.format(17)); -} - -function getCommonCycle(x, y, z, r) { - forceXYZ(); - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + xyzFormat.format(r)]; -} - -function onCyclePoint(x, y, z) { - expandCyclePoint(x, y, z); - return; -/* - if (isFirstCyclePoint()) { - repositionToCycleClearance(cycle, x, y, z); - - // return to initial Z which is clearance plane and set absolute mode - - var F = cycle.feedrate; - var P = (cycle.dwell == 0) ? 0 : clamp(0.001, cycle.dwell, 99999.999); // in seconds - - switch (cycleType) { - case "drilling": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract), - "P" + secFormat.format(P), // not optional - feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "chip-breaking": - expandCyclePoint(x, y, z); - break; - case "deep-drilling": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract), - "Q" + xyzFormat.format(cycle.incrementalDepth), - feedOutput.format(F) - ); - } - break; - case "tapping": - if (!F) { - F = tool.getTappingFeedrate(); - } - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "left-tapping": - if (!F) { - F = tool.getTappingFeedrate(); - } - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(74), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "right-tapping": - if (!F) { - F = tool.getTappingFeedrate(); - } - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "fine-boring": // not supported - expandCyclePoint(x, y, z); - break; - case "back-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - var I = cycle.shift * 1; - var J = cycle.shift * 0; - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87), - getCommonCycle(x, y, z, cycle.retract), - "I" + xyzFormat.format(I), - "J" + xyzFormat.format(J), - "K" + xyzFormat.format(cycle.bottom - cycle.backBoreDistance), - feedOutput.format(F) - ); - } - break; - case "reaming": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "stop-boring": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F), - // conditional(P > 0, "P" + secFormat.format(P)), - "P" + secFormat.format(P) // not optional - ); - break; - case "manual-boring": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88), - getCommonCycle(x, y, z, cycle.retract), - "P" + secFormat.format(P), // not optional - feedOutput.format(F) - ); - break; - case "boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract), - "P" + secFormat.format(P), // not optional - feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - default: - expandCyclePoint(x, y, z); - } - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - var _x = xOutput.format(x); - var _y = yOutput.format(y); - if (!_x && !_y) { - xOutput.reset(); // at least one axis is required - _x = xOutput.format(x); - } - writeBlock(_x, _y); - } - } -*/ -} - -function onCycleEnd() { - if (!cycleExpanded) { - writeBlock(gCycleModal.format(80)); - zOutput.reset(); - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - if (x || y || z) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(0), x, y, z); - feedOutput.reset(); - } -} - -function onLinear(_x, _y, _z, feed) { - // at least one axis is required - if (pendingRadiusCompensation >= 0) { - // ensure that we end at desired position when compensation is turned off - xOutput.reset(); - yOutput.reset(); - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var f = feedOutput.format(feed); - if (x || y || z) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - var d = tool.diameterOffset; - if (d > numberOfToolSlots) { - warning(localize("The diameter offset exceeds the maximum value.")); - } - writeBlock(gPlaneModal.format(17)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); - break; - case RADIUS_COMPENSATION_RIGHT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); - break; - default: - writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); - } - } else { - writeBlock(gMotionModal.format(1), x, y, z, f); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - feedOutput.reset(); // force feed on next line - } else { - writeBlock(gMotionModal.format(1), f); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - // one of X/Y and I/J are required and likewise - - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (isHelical()) { - linearize(tolerance); - return; - } - // TAG: are 360deg arcs supported - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); - break; - default: - linearize(tolerance); - } - } else { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); - break; - default: - linearize(tolerance); - } - } -} - -var mapCommand = { - COMMAND_STOP:0, - COMMAND_OPTIONAL_STOP:1, - COMMAND_END:2, - COMMAND_SPINDLE_CLOCKWISE:3, - COMMAND_SPINDLE_COUNTERCLOCKWISE:4, - COMMAND_STOP_SPINDLE:5, - COMMAND_COOLANT_ON:8, - COMMAND_COOLANT_OFF:9 -}; - -function onCommand(command) { - switch (command) { - case COMMAND_START_SPINDLE: - onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - writeBlock(gPlaneModal.format(17)); - forceAny(); -} - -function onClose() { - onCommand(COMMAND_COOLANT_OFF); - - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract - zOutput.reset(); - - if (!machineConfiguration.hasHomePositionX() && !machineConfiguration.hasHomePositionY()) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "X" + xyzFormat.format(0), "Y" + xyzFormat.format(0)); // return to home - } else { - var homeX; - if (machineConfiguration.hasHomePositionX()) { - homeX = "X" + xyzFormat.format(machineConfiguration.getHomePositionX()); - } - var homeY; - if (machineConfiguration.hasHomePositionY()) { - homeY = "Y" + xyzFormat.format(machineConfiguration.getHomePositionY()); - } - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), homeX, homeY); - } - - onImpliedCommand(COMMAND_END); - onImpliedCommand(COMMAND_STOP_SPINDLE); - writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off - writeln("%"); -} +/** + Copyright (C) 2012-2013 by Autodesk, Inc. + All rights reserved. + + Datron ISO post processor configuration. + + $Revision$ + $Date$ + + FORKID {2EECF092-D7C3-4aca-BFE6-377B72950FE9} +*/ + +description = "Datron ISO"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2013 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +extension = "nc"; +setCodePage("ascii"); + +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(180); +allowHelicalMoves = true; +allowedCircularPlanes = undefined; // allow any circular motion + + + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeTools: true, // writes the tools + preloadTool: true, // preloads next tool on tool change if any + showSequenceNumbers: true, // show sequence numbers + sequenceNumberStart: 10, // first sequence number + sequenceNumberIncrement: 5, // increment for sequence numbers + optionalStop: true, // optional stop + separateWordsWithSpace: true // specifies that the words should be separated with a white space +}; + +var numberOfToolSlots = 9999; + + + +var mapCoolantTable = new Table( + [9, 8, 7], + {initial:COOLANT_OFF, force:true}, + "Invalid coolant mode" +); + +var gFormat = createFormat({prefix:"G", decimals:0}); +var mFormat = createFormat({prefix:"M", decimals:0}); +var hFormat = createFormat({prefix:"H", decimals:0}); +var dFormat = createFormat({prefix:"D", decimals:0}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4)}); +var feedFormat = createFormat({decimals:(unit == MM ? 1 : 2)}); +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 +var taperFormat = createFormat({decimals:1, scale:DEG}); + +var xOutput = createVariable({prefix:"X"}, xyzFormat); +var yOutput = createVariable({prefix:"Y"}, xyzFormat); +var zOutput = createVariable({prefix:"Z"}, xyzFormat); +var feedOutput = createVariable({prefix:"F"}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); +var dOutput = createVariable({}, dFormat); + +// circular output +var iOutput = createReferenceVariable({prefix:"I"}, xyzFormat); +var jOutput = createReferenceVariable({prefix:"J"}, xyzFormat); + +var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... +var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 +var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 +var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 +var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 +var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... +var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 + +var WARNING_WORK_OFFSET = 0; + +// collected state +var sequenceNumber; +var currentWorkOffset; + +/** + Writes the specified block. +*/ +function writeBlock() { + if (properties.showSequenceNumbers) { + writeWords2("N" + sequenceNumber, arguments); + sequenceNumber += properties.sequenceNumberIncrement; + } else { + writeWords(arguments); + } +} + +function formatComment(text) { + return "(" + String(text).replace(/[\(\)]/g, "") + ")"; +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln(formatComment(text)); +} + +function onOpen() { + if (!properties.separateWordsWithSpace) { + setWordSeparator(""); + } + + sequenceNumber = properties.sequenceNumberStart; + writeln("%"); + + if (programName) { + writeComment(programName); + } + if (programComment) { + writeComment(programComment); + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + // dump tool information + if (properties.writeTools) { + var zRanges = {}; + if (is3D()) { + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var zRange = section.getGlobalZRange(); + var tool = section.getTool(); + if (zRanges[tool.number]) { + zRanges[tool.number].expandToRange(zRange); + } else { + zRanges[tool.number] = zRange; + } + } + } + + var tools = getToolTable(); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + toolFormat.format(tool.number) + " " + + "D=" + xyzFormat.format(tool.diameter) + " " + + localize("CR") + "=" + xyzFormat.format(tool.cornerRadius); + if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) { + comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg"); + } + if (zRanges[tool.number]) { + comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum()); + } + comment += " - " + getToolTypeName(tool.type); + writeComment(comment); + } + } + } + + // absolute coordinates and feed per min + writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94)); + writeBlock(gPlaneModal.format(17)); + + switch (unit) { + case IN: + writeBlock(gUnitModal.format(20)); + break; + case MM: + writeBlock(gUnitModal.format(21)); + break; + } +} + +function onComment(message) { + writeComment(message); +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of X, Y, Z, and F on next output. */ +function forceAny() { + forceXYZ(); + feedOutput.reset(); +} + +function onSection() { + var insertToolCall = isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); + if (insertToolCall || newWorkOffset || newWorkPlane) { + + // stop spindle before retract during tool change + if (insertToolCall && !isFirstSection()) { + onCommand(COMMAND_STOP_SPINDLE); + } + + // retract to safe plane + retracted = true; + writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract + writeBlock(gAbsIncModal.format(90)); + zOutput.reset(); + } + + if (hasParameter("operation-comment")) { + var comment = getParameter("operation-comment"); + if (comment) { + writeComment(comment); + } + } + + if (insertToolCall) { + retracted = true; + onCommand(COMMAND_COOLANT_OFF); + + if (!isFirstSection() && properties.optionalStop) { + onCommand(COMMAND_OPTIONAL_STOP); + } + + if (tool.number > numberOfToolSlots) { + warning(localize("Tool number exceeds maximum value.")); + } + + writeBlock("T" + toolFormat.format(tool.number)); + if (tool.comment) { + writeComment(tool.comment); + } + var showToolZMin = false; + if (showToolZMin) { + if (is3D()) { + var numberOfSections = getNumberOfSections(); + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) { + var section = getSection(i); + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + } + writeComment(localize("ZMIN") + "=" + zRange.getMinimum()); + } + } + + if (properties.preloadTool) { + var nextTool = getNextTool(tool.number); + if (nextTool) { + writeBlock("T" + toolFormat.format(nextTool.number)); + } else { + // preload first tool + var section = getSection(0); + var firstToolNumber = section.getTool().number; + if (tool.number != firstToolNumber) { + writeBlock("T" + toolFormat.format(firstToolNumber)); + } + } + } + } + + if (insertToolCall || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + if (tool.spindleRPM < 1) { + error(localize("Spindle speed out of range.")); + } + if (tool.spindleRPM > 99999) { + warning(localize("Spindle speed exceeds maximum value.")); + } + writeBlock( + sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4) + ); + } + + // wcs + if (insertToolCall) { // force work offset when changing tool + currentWorkOffset = undefined; + } + var workOffset = currentSection.workOffset; + if (workOffset == 0) { + warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET); + workOffset = 1; + } + if (workOffset > 0) { + if (workOffset > 6) { + var code = workOffset - 6; + if (code > 3) { + error(localize("Work offset out of range.")); + } + if (workOffset != currentWorkOffset) { + writeBlock(gFormat.format(59) + "." + code); + currentWorkOffset = workOffset; + } + } else { + if (workOffset != currentWorkOffset) { + writeBlock(gFormat.format(53 + workOffset)); // G54->G59 + currentWorkOffset = workOffset; + } + } + } + + forceXYZ(); + + { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { + error(localize("Tool orientation is not supported.")); + return; + } + setRotation(remaining); + } + + // set coolant after we have positioned at Z + { + var c = mapCoolantTable.lookup(tool.coolant); + if (c) { + writeBlock(mFormat.format(c)); + } else { + warning(localize("Coolant not supported.")); + } + } + + forceAny(); + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); + } + } + + if (insertToolCall || retracted) { + var lengthOffset = tool.lengthOffset; + if (lengthOffset > numberOfToolSlots) { + error(localize("Length offset out of range.")); + } + + if (!machineConfiguration.isHeadConfiguration()) { + writeBlock( + gAbsIncModal.format(90), + gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y) + ); + writeBlock(gMotionModal.format(0), gFormat.format(43), zOutput.format(initialPosition.z), hFormat.format(lengthOffset)); + } else { + writeBlock( + gAbsIncModal.format(90), + gMotionModal.format(0), + gFormat.format(43), xOutput.format(initialPosition.x), + yOutput.format(initialPosition.y), + zOutput.format(initialPosition.z), hFormat.format(lengthOffset) + ); + } + } else { + writeBlock( + gAbsIncModal.format(90), + gMotionModal.format(0), + xOutput.format(initialPosition.x), + yOutput.format(initialPosition.y) + ); + } + + if (insertToolCall) { + gPlaneModal.reset(); + } +} + +function onDwell(seconds) { + if (seconds > 99999.999) { + warning(localize("Dwelling time is out of range.")); + } + seconds = clamp(0.001, seconds, 99999.999); + writeBlock(gFormat.format(4), "P" + secFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(sOutput.format(spindleSpeed)); +} + +function onCycle() { + // writeBlock(gPlaneModal.format(17)); +} + +function getCommonCycle(x, y, z, r) { + forceXYZ(); + return [xOutput.format(x), yOutput.format(y), + zOutput.format(z), + "R" + xyzFormat.format(r)]; +} + +function onCyclePoint(x, y, z) { + expandCyclePoint(x, y, z); + return; +/* + if (isFirstCyclePoint()) { + repositionToCycleClearance(cycle, x, y, z); + + // return to initial Z which is clearance plane and set absolute mode + + var F = cycle.feedrate; + var P = (cycle.dwell == 0) ? 0 : clamp(0.001, cycle.dwell, 99999.999); // in seconds + + switch (cycleType) { + case "drilling": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "counter-boring": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82), + getCommonCycle(x, y, z, cycle.retract), + "P" + secFormat.format(P), // not optional + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + case "chip-breaking": + expandCyclePoint(x, y, z); + break; + case "deep-drilling": + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), + getCommonCycle(x, y, z, cycle.retract), + "Q" + xyzFormat.format(cycle.incrementalDepth), + feedOutput.format(F) + ); + } + break; + case "tapping": + if (!F) { + F = tool.getTappingFeedrate(); + } + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "left-tapping": + if (!F) { + F = tool.getTappingFeedrate(); + } + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(74), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "right-tapping": + if (!F) { + F = tool.getTappingFeedrate(); + } + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "fine-boring": // not supported + expandCyclePoint(x, y, z); + break; + case "back-boring": + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + var I = cycle.shift * 1; + var J = cycle.shift * 0; + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87), + getCommonCycle(x, y, z, cycle.retract), + "I" + xyzFormat.format(I), + "J" + xyzFormat.format(J), + "K" + xyzFormat.format(cycle.bottom - cycle.backBoreDistance), + feedOutput.format(F) + ); + } + break; + case "reaming": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "stop-boring": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F), + // conditional(P > 0, "P" + secFormat.format(P)), + "P" + secFormat.format(P) // not optional + ); + break; + case "manual-boring": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88), + getCommonCycle(x, y, z, cycle.retract), + "P" + secFormat.format(P), // not optional + feedOutput.format(F) + ); + break; + case "boring": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), + getCommonCycle(x, y, z, cycle.retract), + "P" + secFormat.format(P), // not optional + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + default: + expandCyclePoint(x, y, z); + } + } else { + if (cycleExpanded) { + expandCyclePoint(x, y, z); + } else { + var _x = xOutput.format(x); + var _y = yOutput.format(y); + if (!_x && !_y) { + xOutput.reset(); // at least one axis is required + _x = xOutput.format(x); + } + writeBlock(_x, _y); + } + } +*/ +} + +function onCycleEnd() { + if (!cycleExpanded) { + writeBlock(gCycleModal.format(80)); + zOutput.reset(); + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + if (x || y || z) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(0), x, y, z); + feedOutput.reset(); + } +} + +function onLinear(_x, _y, _z, feed) { + // at least one axis is required + if (pendingRadiusCompensation >= 0) { + // ensure that we end at desired position when compensation is turned off + xOutput.reset(); + yOutput.reset(); + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var f = feedOutput.format(feed); + if (x || y || z) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > numberOfToolSlots) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + writeBlock(gPlaneModal.format(17)); + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + dOutput.reset(); + writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); + break; + case RADIUS_COMPENSATION_RIGHT: + dOutput.reset(); + writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); + break; + default: + writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); + } + } else { + writeBlock(gMotionModal.format(1), x, y, z, f); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + feedOutput.reset(); // force feed on next line + } else { + writeBlock(gMotionModal.format(1), f); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); + break; + default: + linearize(tolerance); + } + } +} + +var mapCommand = { + COMMAND_STOP:0, + COMMAND_OPTIONAL_STOP:1, + COMMAND_END:2, + COMMAND_SPINDLE_CLOCKWISE:3, + COMMAND_SPINDLE_COUNTERCLOCKWISE:4, + COMMAND_STOP_SPINDLE:5, + COMMAND_COOLANT_ON:8, + COMMAND_COOLANT_OFF:9 +}; + +function onCommand(command) { + switch (command) { + case COMMAND_START_SPINDLE: + onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + writeBlock(gPlaneModal.format(17)); + forceAny(); +} + +function onClose() { + onCommand(COMMAND_COOLANT_OFF); + + writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract + zOutput.reset(); + + if (!machineConfiguration.hasHomePositionX() && !machineConfiguration.hasHomePositionY()) { + writeBlock(gFormat.format(28), gAbsIncModal.format(91), "X" + xyzFormat.format(0), "Y" + xyzFormat.format(0)); // return to home + } else { + var homeX; + if (machineConfiguration.hasHomePositionX()) { + homeX = "X" + xyzFormat.format(machineConfiguration.getHomePositionX()); + } + var homeY; + if (machineConfiguration.hasHomePositionY()) { + homeY = "Y" + xyzFormat.format(machineConfiguration.getHomePositionY()); + } + writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), homeX, homeY); + } + + onImpliedCommand(COMMAND_END); + onImpliedCommand(COMMAND_STOP_SPINDLE); + writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off + writeln("%"); +} diff --git a/datron mcr english.cps b/deprecated/datron mcr english.cps similarity index 97% rename from datron mcr english.cps rename to deprecated/datron mcr english.cps index ae72497..327f385 100644 --- a/datron mcr english.cps +++ b/deprecated/datron mcr english.cps @@ -1,2413 +1,2413 @@ -/** - Copyright (C) 2012-2017 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} -*/ - -description = "Generic DATRON MCR (English)"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - useTimeStamp: false, // specifies to output time stamp - language: "en", // specifies the language "en" or "de" - writeCoolantCommands: false, // en/disable coolant code output for the entire program - _got4thAxis: false, // specifies if the machine has a 4th axis - _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y - _got5thAxis: false // specifies if the machine has a 5th axis -}; - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, - showOperationDialog: { - title: "Show operation dialog", - description:"Shows a start dialog on the control which allows you to select the operation to start with.", - type:"enum", - values:[ - {id: "disabled", title: "Disabled"}, - {id: "dropdown", title:"Dropdown style"}, - {id: "checkbox", title:"Checkbox style"} - ] - }, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, - useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, - language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, - _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, - _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"} -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); - -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics -var useInverseTimeFeed = false; // beta, keep false -var maxMaskLength = 40; - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -// Start of multi-axis feedrate logic -/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ -/***** 'inverseTimeOutput' must be defined. *****/ -/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ -/***** The feed rate mode must be included in motion block output (linear, circular, etc. *****/ -var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations -var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds -var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds - -/** Calculate the multi-axis feedrate number. */ -function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { - var f = {frn:0, fmode:0}; - if (feed <= 0) { - error(localize("Feedrate is less than or equal to 0.")); - return f; - } - - var length = getMoveLength(_x, _y, _z, _a, _b, _c); - - if (useInverseTimeFeed) { // inverse time - f.frn = inverseTimeFormat.format(getInverseTime(length[0], feed)); - f.fmode = 93; - feedOutput.reset(); - } else { // degrees per minute - f.frn = feedOutput.format(getFeedDPM(length, feed)); - f.fmode = 94; - } - return f; -} - -/** Calculate the DPM feedrate number. */ -function getFeedDPM(_moveLength, _feed) { - // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC - - if (currentSection.getOptimizedTCPMode() == 0) { // TCP mode is supported, output feed as FPM - return _feed; - } else { // DPM feed rate calculation - var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; - var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); - return length / moveTime; - } -} - -/** Calculate the Inverse time feedrate number. */ -function getInverseTime(_length, _feed) { - var inverseTime; - if (_length < 1.e-6) { // tool doesn't move - if (typeof maxInverseTime === "number") { - inverseTime = maxInverseTime; - } else { - inverseTime = 999999; - } - } else { - inverseTime = _feed / _length / inverseTimeUnits; - if (typeof maxInverseTime === "number") { - if (inverseTime > maxInverseTime) { - inverseTime = maxInverseTime; - } - } - } - return inverseTime; -} - -/** Calculate the distance of the tool position to the center of a rotary axis. */ -function getRotaryRadius(center, direction, toolPosition) { - var normal = direction.getNormalized(); - var d1 = toolPosition.x - center.x; - var d2 = toolPosition.y - center.y; - var d3 = toolPosition.z - center.z; - var radius = Math.sqrt( - Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + - Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + - Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) - ); - return radius; -} - -/** Calculate the linear distance based on the rotation of a rotary axis. */ -function getRadialDistance(axis, startTool, endTool, startABC, endABC) { - // rotary axis does not exist - if (!axis.isEnabled()) { - return 0.0; - } - - // calculate the rotary center based on head/table - var center; - if (axis.isHead()) { - var pivot; - if (typeof headOffset === "number") { - pivot = headOffset; - } else { - pivot = tool.getBodyLength(); - } - center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); - center = Vector.sum(center, axis.getOffset()); - } else { - center = axis.getOffset(); - } - - // calculate the radius of the tool end point compared to the rotary center - var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); - var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); - - // calculate length of radial move - var radius = Math.max(startRadius, endRadius); - var delta = Math.abs(endABC.getCoordinate(axis.getCoordinate()) - startABC.getCoordinate(axis.getCoordinate())); - if (delta > Math.PI) { - delta = 2*Math.PI - delta; - } - var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); - return radialLength; -} - -/** Calculate tooltip, XYZ, and rotary move lengths. */ -function getMoveLength(_x, _y, _z, _a, _b, _c) { - // get starting and ending positions - var moveLength = new Array(); - var startTool; - var endTool; - var startXYZ; - var endXYZ; - var startABC = getCurrentDirection(); - var endABC = new Vector(_a, _b, _c); - - if (currentSection.getOptimizedTCPMode() == 0) { - startTool = getCurrentPosition(); - endTool = new Vector(_x, _y, _z); - startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); - endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); - } else { - startXYZ = getCurrentPosition(); - endXYZ = new Vector(_x, _y, _z); - startTool = machineConfiguration.getOrientation(startABC).multiply(startXYZ); - endTool = machineConfiguration.getOrientation(endABC).multiply(endXYZ); - } - - // calculate the radial portion of the move - var radialLength = Math.sqrt( - Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) - ); - - // calculate the lengths of move - // tool tip distance is the move distance based on a combination of linear and rotary axes movement - var linearLength = Vector.diff(endXYZ, startXYZ).length; - moveLength[0] = linearLength + radialLength; - moveLength[1] = Vector.diff(endXYZ, startXYZ).length; - moveLength[2] = 0; - - var start = new Array(startABC.x, startABC.y, startABC.z); - var end = new Array(endABC.x, endABC.y, endABC.z); - for (var i = 0; i < 3; ++i) { - var delta = Math.abs(end[i] - start[i]); - if (delta > Math.PI) { - delta = 2 * Math.PI - delta; - } - moveLength[2] += Math.pow(delta, 2.0); - } - moveLength[2] = Math.sqrt(moveLength[2]); - return moveLength; -} -// End of multi-axis feedrate logic - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here - var aAxis; - if (properties._got4thAxis && properties._got5thAxis) { - aAxis = createAxis( - { - coordinate:properties._got5thAxis ? 0 : 1, - table:true, - axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], - range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], - preference:-1 - } - ); - } else { - aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); - } - - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); - - if (properties._got4thAxis) { - if (properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else { - machineConfiguration = new MachineConfiguration(aAxis); - } - } - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - } else { - writeBlock("!Makro file ; V9.09F!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); - switch (properties.language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog != "disabled") { - variablesDeclaration.push("optional_stop"); - if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() >= maxMaskLength) { - submacrosDeclaration.push("Initvariables"); - } - } - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog != "disabled") { - if (properties.showOperationDialog == "dropdown") { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } else { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "dropdown") { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog == "dropdown") { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } else if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() < maxMaskLength) { - dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" - ); - } - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog == "dropdown") { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - variablesDeclaration.push("A_delta"); - variablesDeclaration.push("B_delta"); - variablesDeclaration.push("C_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - variablesDeclaration.push("A_temp"); - variablesDeclaration.push("B_temp"); - variablesDeclaration.push("C_temp"); - variablesDeclaration.push("Isinitialposition"); - variablesDeclaration.push("timefeed"); - - submacrosDeclaration.push("Initposition"); - submacrosDeclaration.push("Endmacro"); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformpath"); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformoffset"); - } - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_exit Endmacro;"); - writeln(""); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); - writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); - writeln(""); - } - - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock("("); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); - } - writeln(") Initvariables;"); - } - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createPositionInitSubmacro(); - createEndmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpTransformationSubmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock(translate("Submacro") + " Initvariables;"); - } - } - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - } else if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - - // wcs - var workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - // insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; -} -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -/* -function onRewindMachine() { - writeComment("REWIND"); -} -*/ - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); - writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); - writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); - //writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); - if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { - writeBlock(translate("Submacro") + " Transformoffset 0, ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.y) +", ", - abcFormat.format(abc.z) +";"); - } - } else { - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); - } - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - - writeBlock("("); - if (useInverseTimeFeed) { - writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); - } - - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - if (properties._got5thAxis) { - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - } - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); - - writeBlock("A_temp = A - A_delta;"); - writeBlock("B_temp = B - B_delta;"); - writeBlock("C_temp = C - C_delta;"); - - if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); - } else { - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); - } - - writeBlock(") Transformpath;"); - -} - -function createRtcpTransformationSubmacro() { - writeBlock("("); - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X6p + X_trans;"); - writeBlock("Y_new = Y6p + Y_trans;"); - writeBlock("Z_new = Z6p + Z_trans;"); - writeBlock(";!set new position!;"); - writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); - writeBlock(") Transformoffset;"); -} - -function createPositionInitSubmacro() { - // get initial offset - writeBlock("("); - writeBlock("X_initial_pos = X6p;"); - writeBlock("Y_initial_pos = Y6p;"); - writeBlock("Z_initial_pos = Z6p;"); - writeBlock("A_initial_pos = A6p;"); - writeBlock("B_initial_pos = B6p;"); - writeBlock("C_initial_pos = C6p;"); - - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_delta = X_initial_pos - X6p;"); - writeBlock("Y_delta = Y_initial_pos - Y6p;"); - writeBlock("Z_delta = Z_initial_pos - Z6p;"); - writeBlock("A_delta = A_initial_pos - A6p;"); - writeBlock("B_delta = B_initial_pos - B6p;"); - writeBlock("C_delta = C_initial_pos - C6p;"); - writeBlock(") Initposition;"); -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - - -function createEndmacro() { - writeBlock("("); - if (useInverseTimeFeed) { - mcrSetTimeFeed(); - } - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()); - - writeBlock("("); - if (isProbeOperation(currentSection)) { - writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe - writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); - } else { - writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe - } - - if (newWorkOffset || newWorkPlane) { - // retract to safe plane - retracted = true; - writeBlock(translate("Submacro") + " Retractzmax;"); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("Position 19, 2;"); - /* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } - */ - writeBlock(translate("Submacro") + " Retractzmax;"); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - } else { - if (!retracted) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -// implement G93 command -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -// implement G94 command -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -//write a command to the cnc kernel without interpretation from the control -function directWriteToCNC(command) { - error(localize("Inverse Time feed is currently not supported.")); - return; -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { - // non TCP - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); - } else { - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); -} - -var currentFMode; - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - // get feed rate number - if (useInverseTimeFeed) { - var f = {frn:0, fmode:0}; - if (a || b || c) { - f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); - } else { - f.frn = feedOutput.format(feed); - f.fmode = 94; - } - } - - if (x || y || z || a || b || c) { - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - } else { - writeBlock(getFeed(feed)); - } - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); - } else { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); - } else { - writeBlock(getFeed(feed)); - } - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (properties.language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 4/5 Achs Operationen gefunden. |" + - "\r\n| Sie muessen die Property |" + - "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + - "\r\n| andernfalls koennen Sie lediglich |" + - "\r\n| 3 Achsen Programme erzeugen. |" + - "\r\n| Besteht das Problem weiterhin, |" + - "\r\n| wenden Sie sich bitte an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return; // do not output coolant - } - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - if (useInverseTimeFeed && currentSection.isMultiAxis()) { - directWriteToCNC("G" + 94); - currentFMode = 94; - } - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - if (!isLastSection() && properties.showOperationDialog != "disabled") { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Initposition;"); - } - - //write jump to start operation - if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - // onCommand(COMMAND_COOLANT_OFF); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Endmacro;"); - } - - writeBlock(translate("Submacro") + " Retractzmax;"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - if (properties.useParkPosition) { - writeBlock("Park;"); - } else { - writeBlock(translate("Submacro") + " Retractzmax;"); - zOutput.reset(); - } -} +/** + Copyright (C) 2012-2017 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} +*/ + +description = "Generic DATRON MCR (English)"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + useTimeStamp: false, // specifies to output time stamp + language: "en", // specifies the language "en" or "de" + writeCoolantCommands: false, // en/disable coolant code output for the entire program + _got4thAxis: false, // specifies if the machine has a 4th axis + _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y + _got5thAxis: false // specifies if the machine has a 5th axis +}; + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, + showOperationDialog: { + title: "Show operation dialog", + description:"Shows a start dialog on the control which allows you to select the operation to start with.", + type:"enum", + values:[ + {id: "disabled", title: "Disabled"}, + {id: "dropdown", title:"Dropdown style"}, + {id: "checkbox", title:"Checkbox style"} + ] + }, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, + useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, + language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, + _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, + _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"} +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics +var useInverseTimeFeed = false; // beta, keep false +var maxMaskLength = 40; + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of multi-axis feedrate logic +/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ +/***** 'inverseTimeOutput' must be defined. *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ +/***** The feed rate mode must be included in motion block output (linear, circular, etc. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds + +/** Calculate the multi-axis feedrate number. */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTimeFeed) { // inverse time + f.frn = inverseTimeFormat.format(getInverseTime(length[0], feed)); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = feedOutput.format(getFeedDPM(length, feed)); + f.fmode = 94; + } + return f; +} + +/** Calculate the DPM feedrate number. */ +function getFeedDPM(_moveLength, _feed) { + // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC + + if (currentSection.getOptimizedTCPMode() == 0) { // TCP mode is supported, output feed as FPM + return _feed; + } else { // DPM feed rate calculation + var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; + var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); + return length / moveTime; + } +} + +/** Calculate the Inverse time feedrate number. */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof maxInverseTime === "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof maxInverseTime === "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate the distance of the tool position to the center of a rotary axis. */ +function getRotaryRadius(center, direction, toolPosition) { + var normal = direction.getNormalized(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis. */ +function getRadialDistance(axis, startTool, endTool, startABC, endABC) { + // rotary axis does not exist + if (!axis.isEnabled()) { + return 0.0; + } + + // calculate the rotary center based on head/table + var center; + if (axis.isHead()) { + var pivot; + if (typeof headOffset === "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); + center = Vector.sum(center, axis.getOffset()); + } else { + center = axis.getOffset(); + } + + // calculate the radius of the tool end point compared to the rotary center + var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); + var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); + + // calculate length of radial move + var radius = Math.max(startRadius, endRadius); + var delta = Math.abs(endABC.getCoordinate(axis.getCoordinate()) - startABC.getCoordinate(axis.getCoordinate())); + if (delta > Math.PI) { + delta = 2*Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = new Array(); + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC = getCurrentDirection(); + var endABC = new Vector(_a, _b, _c); + + if (currentSection.getOptimizedTCPMode() == 0) { + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); + endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); + } else { + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(startABC).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(endABC).multiply(endXYZ); + } + + // calculate the radial portion of the move + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) + ); + + // calculate the lengths of move + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + var linearLength = Vector.diff(endXYZ, startXYZ).length; + moveLength[0] = linearLength + radialLength; + moveLength[1] = Vector.diff(endXYZ, startXYZ).length; + moveLength[2] = 0; + + var start = new Array(startABC.x, startABC.y, startABC.z); + var end = new Array(endABC.x, endABC.y, endABC.z); + for (var i = 0; i < 3; ++i) { + var delta = Math.abs(end[i] - start[i]); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + moveLength[2] += Math.pow(delta, 2.0); + } + moveLength[2] = Math.sqrt(moveLength[2]); + return moveLength; +} +// End of multi-axis feedrate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here + var aAxis; + if (properties._got4thAxis && properties._got5thAxis) { + aAxis = createAxis( + { + coordinate:properties._got5thAxis ? 0 : 1, + table:true, + axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], + range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], + preference:-1 + } + ); + } else { + aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); + } + + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + + if (properties._got4thAxis) { + if (properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } else { + machineConfiguration = new MachineConfiguration(aAxis); + } + } + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); + switch (properties.language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog != "disabled") { + variablesDeclaration.push("optional_stop"); + if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() >= maxMaskLength) { + submacrosDeclaration.push("Initvariables"); + } + } + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog != "disabled") { + if (properties.showOperationDialog == "dropdown") { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } else { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "dropdown") { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog == "dropdown") { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } else if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() < maxMaskLength) { + dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + ); + } + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog == "dropdown") { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformpath"); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformoffset"); + } + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock("("); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); + } + writeln(") Initvariables;"); + } + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpTransformationSubmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock(translate("Submacro") + " Initvariables;"); + } + } + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + } else if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; +} +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +/* +function onRewindMachine() { + writeComment("REWIND"); +} +*/ + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); + writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); + writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); + //writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.y) +", ", + abcFormat.format(abc.z) +";"); + } + } else { + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); + } + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + + writeBlock("("); + if (useInverseTimeFeed) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + if (properties._got5thAxis) { + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + } + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); + } else { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); + } + + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + writeBlock("A_initial_pos = A6p;"); + writeBlock("B_initial_pos = B6p;"); + writeBlock("C_initial_pos = C6p;"); + + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + writeBlock("A_delta = A_initial_pos - A6p;"); + writeBlock("B_delta = B_initial_pos - B6p;"); + writeBlock("C_delta = C_initial_pos - C6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + + +function createEndmacro() { + writeBlock("("); + if (useInverseTimeFeed) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()); + + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + + if (newWorkOffset || newWorkPlane) { + // retract to safe plane + retracted = true; + writeBlock(translate("Submacro") + " Retractzmax;"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("Position 19, 2;"); + /* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } + */ + writeBlock(translate("Submacro") + " Retractzmax;"); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + } else { + if (!retracted) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +// implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +// implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +//write a command to the cnc kernel without interpretation from the control +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { + // non TCP + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); +} + +var currentFMode; + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + // get feed rate number + if (useInverseTimeFeed) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); + } else { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (properties.language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return; // do not output coolant + } + if (coolant == currentCoolantMode) { + return; // coolant is already active + } + + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTimeFeed && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && properties.showOperationDialog != "disabled") { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Initposition;"); + } + + //write jump to start operation + if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // onCommand(COMMAND_COOLANT_OFF); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeBlock(translate("Submacro") + " Retractzmax;"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (properties.useParkPosition) { + writeBlock("Park;"); + } else { + writeBlock(translate("Submacro") + " Retractzmax;"); + zOutput.reset(); + } +} diff --git a/datron mcr german millTurn.cps b/deprecated/datron mcr german millTurn.cps similarity index 97% rename from datron mcr german millTurn.cps rename to deprecated/datron mcr german millTurn.cps index a7bfde4..a5a5ad8 100644 --- a/datron mcr german millTurn.cps +++ b/deprecated/datron mcr german millTurn.cps @@ -1,2426 +1,2426 @@ -/** - Copyright (C) 2012-2017 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} -*/ - -description = "Generic DATRON MCR Millturn (German)"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC -allowHelicalMoves = false; -allowedCircularPlanes =0;// (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - useTimeStamp: false, // specifies to output time stamp - language: "de", // specifies the language "en" or "de" - writeCoolantCommands: false, // en/disable coolant code output for the entire program - _got4thAxis: false, // specifies if the machine has a 4th axis - _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y - _got5thAxis: false, // specifies if the machine has a 5th axis - _MillTurn:true, - _FeedPerTurn : 1 -}; - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, - showOperationDialog: { - title: "Show operation dialog", - description:"Shows a start dialog on the control which allows you to select the operation to start with.", - type:"enum", - values:[ - {id: "disabled", title: "Disabled"}, - {id: "dropdown", title:"Dropdown style"}, - {id: "checkbox", title:"Checkbox style"} - ] - }, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, - useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, - language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, - _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, - _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"} -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); - -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics -var useInverseTimeFeed = false; // beta, keep false -var maxMaskLength = 40; - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -// Start of multi-axis feedrate logic -/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ -/***** 'inverseTimeOutput' must be defined. *****/ -/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ -/***** The feedrate mode must be included in motion block output (linear, circular, etc. *****/ -var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations -var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds -var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds - -/** Calculate the multi-axis feedrate number. */ -function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { - var f = {frn:0, fmode:0}; - if (feed <= 0) { - error(localize("Feedrate is less than or equal to 0.")); - return f; - } - - var length = getMoveLength(_x, _y, _z, _a, _b, _c); - - if (useInverseTimeFeed) { // inverse time - f.frn = inverseTimeFormat.format(getInverseTime(length[0], feed)); - f.fmode = 93; - feedOutput.reset(); - } else { // degrees per minute - f.frn = feedOutput.format(getFeedDPM(length, feed)); - f.fmode = 94; - } - return f; -} - -/** Calculate the DPM feedrate number. */ -function getFeedDPM(_moveLength, _feed) { - // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC - - if (currentSection.getOptimizedTCPMode() == 0) { // TCP mode is supported, output feed as FPM - return _feed; - } else { // DPM feedrate calculation - var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; - var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); - return length / moveTime; - } -} - -/** Calculate the Inverse time feedrate number. */ -function getInverseTime(_length, _feed) { - var inverseTime; - if (_length < 1.e-6) { // tool doesn't move - if (typeof maxInverseTime === "number") { - inverseTime = maxInverseTime; - } else { - inverseTime = 999999; - } - } else { - inverseTime = _feed / _length / inverseTimeUnits; - if (typeof maxInverseTime === "number") { - if (inverseTime > maxInverseTime) { - inverseTime = maxInverseTime; - } - } - } - return inverseTime; -} - -/** Calculate the distance of the tool position to the center of a rotary axis. */ -function getRotaryRadius(center, direction, toolPosition) { - var normal = direction.getNormalized(); - var d1 = toolPosition.x - center.x; - var d2 = toolPosition.y - center.y; - var d3 = toolPosition.z - center.z; - var radius = Math.sqrt( - Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + - Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + - Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) - ); - return radius; -} - -/** Calculate the linear distance based on the rotation of a rotary axis. */ -function getRadialDistance(axis, startTool, endTool, startABC, endABC) { - // rotary axis does not exist - if (!axis.isEnabled()) { - return 0.0; - } - - // calculate the rotary center based on head/table - var center; - if (axis.isHead()) { - var pivot; - if (typeof headOffset === "number") { - pivot = headOffset; - } else { - pivot = tool.getBodyLength(); - } - center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); - center = Vector.sum(center, axis.getOffset()); - } else { - center = axis.getOffset(); - } - - // calculate the radius of the tool end point compared to the rotary center - var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); - var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); - - // calculate length of radial move - var radius = Math.max(startRadius, endRadius); - var delta = Math.abs(endABC.getCoordinate(axis.getCoordinate()) - startABC.getCoordinate(axis.getCoordinate())); - if (delta > Math.PI) { - delta = 2 * Math.PI - delta; - } - var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); - return radialLength; -} - -/** Calculate tooltip, XYZ, and rotary move lengths. */ -function getMoveLength(_x, _y, _z, _a, _b, _c) { - // get starting and ending positions - var moveLength = new Array(); - var startTool; - var endTool; - var startXYZ; - var endXYZ; - var startABC = getCurrentDirection(); - var endABC = new Vector(_a, _b, _c); - - if (currentSection.getOptimizedTCPMode() == 0) { - startTool = getCurrentPosition(); - endTool = new Vector(_x, _y, _z); - startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); - endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); - } else { - startXYZ = getCurrentPosition(); - endXYZ = new Vector(_x, _y, _z); - startTool = machineConfiguration.getOrientation(startABC).multiply(startXYZ); - endTool = machineConfiguration.getOrientation(endABC).multiply(endXYZ); - } - - // calculate the radial portion of the move - var radialLength = Math.sqrt( - Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) - ); - - // calculate the lengths of move - // tool tip distance is the move distance based on a combination of linear and rotary axes movement - var linearLength = Vector.diff(endXYZ, startXYZ).length; - moveLength[0] = linearLength + radialLength; - moveLength[1] = Vector.diff(endXYZ, startXYZ).length; - moveLength[2] = 0; - - var start = new Array(startABC.x, startABC.y, startABC.z); - var end = new Array(endABC.x, endABC.y, endABC.z); - for (var i = 0; i < 3; ++i) { - var delta = Math.abs(end[i] - start[i]); - if (delta > Math.PI) { - delta = 2 * Math.PI - delta; - } - moveLength[2] += Math.pow(delta, 2.0); - } - moveLength[2] = Math.sqrt(moveLength[2]); - return moveLength; -} -// End of multi-axis feedrate logic - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here - var aAxis; - if (properties._got4thAxis && properties._got5thAxis) { - aAxis = createAxis( - { - coordinate:properties._got5thAxis ? 0 : 1, - table:true, - axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], - range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], - preference:-1 - } - ); - } else { - aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); - } - - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); - - if (properties._got4thAxis) { - if (properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else { - machineConfiguration = new MachineConfiguration(aAxis); - } - } - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - } else { - writeBlock("!Makro file ; V9.09F!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); - switch (properties.language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog != "disabled") { - variablesDeclaration.push("optional_stop"); - if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() >= maxMaskLength) { - submacrosDeclaration.push("Initvariables"); - } - } - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog != "disabled") { - if (properties.showOperationDialog == "dropdown") { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } else { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "dropdown") { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog == "dropdown") { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } else if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() < maxMaskLength) { - dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" - ); - } - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog == "dropdown") { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - variablesDeclaration.push("A_delta"); - variablesDeclaration.push("B_delta"); - variablesDeclaration.push("C_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - variablesDeclaration.push("A_temp"); - variablesDeclaration.push("B_temp"); - variablesDeclaration.push("C_temp"); - variablesDeclaration.push("Isinitialposition"); - variablesDeclaration.push("timefeed"); - - submacrosDeclaration.push("Initposition"); - submacrosDeclaration.push("Endmacro"); - } - if ( properties._MillTurn){ - variablesDeclaration.push("Cpos"); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformpath"); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformoffset"); - } - - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_exit Endmacro;"); - writeln(""); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); - writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); - writeln(""); - } - - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock("("); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); - } - writeln(") Initvariables;"); - } - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createPositionInitSubmacro(); - createEndmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpTransformationSubmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock(translate("Submacro") + " Initvariables;"); - } - } - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - } else if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - - // wcs - var workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - // insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; - } -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -/* -function onRewindMachine() { - writeComment("REWIND"); -} -*/ - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); - writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); - writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); - //writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); - if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { - writeBlock(translate("Submacro") + " Transformoffset 0, ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.y) +", ", - abcFormat.format(abc.z) +";"); - } - } else { - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); - } - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - - writeBlock("("); - if (useInverseTimeFeed) { - writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); - } - - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - if (properties._got5thAxis) { - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - } - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); - - writeBlock("A_temp = A - A_delta;"); - writeBlock("B_temp = B - B_delta;"); - writeBlock("C_temp = C - C_delta;"); - - if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); - } else { - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); - } - - writeBlock(") Transformpath;"); - -} - -function createRtcpTransformationSubmacro() { - writeBlock("("); - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X6p + X_trans;"); - writeBlock("Y_new = Y6p + Y_trans;"); - writeBlock("Z_new = Z6p + Z_trans;"); - writeBlock(";!set new position!;"); - writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); - writeBlock(") Transformoffset;"); -} - -function createPositionInitSubmacro() { - // get initial offset - writeBlock("("); - writeBlock("X_initial_pos = X6p;"); - writeBlock("Y_initial_pos = Y6p;"); - writeBlock("Z_initial_pos = Z6p;"); - writeBlock("A_initial_pos = A6p;"); - writeBlock("B_initial_pos = B6p;"); - writeBlock("C_initial_pos = C6p;"); - - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_delta = X_initial_pos - X6p;"); - writeBlock("Y_delta = Y_initial_pos - Y6p;"); - writeBlock("Z_delta = Z_initial_pos - Z6p;"); - writeBlock("A_delta = A_initial_pos - A6p;"); - writeBlock("B_delta = B_initial_pos - B6p;"); - writeBlock("C_delta = C_initial_pos - C6p;"); - writeBlock(") Initposition;"); -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - - -function createEndmacro() { - writeBlock("("); - if (useInverseTimeFeed) { - mcrSetTimeFeed(); - } - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()); - - writeBlock("("); - if (isProbeOperation(currentSection)) { - writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe - writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); - } else { - writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe - } - - if (newWorkOffset || newWorkPlane) { - // retract to safe plane - retracted = true; - writeBlock(translate("Submacro") + " Retractzmax;"); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("Position 19, 2;"); - /* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } - */ - writeBlock(translate("Submacro") + " Retractzmax;"); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - } else { - if (!retracted) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -// implement G93 command -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -// implement G94 command -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -//write a command to the cnc kernel without interpretation from the control -function directWriteToCNC(command) { - error(localize("Inverse Time feed is currently not supported.")); - return; -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - - //Anpassung an die funktion drehfräsen - if( properties._MillTurn ){ - - var targetVec = new Vector(_x,_y,_z); - var startVec = getCurrentPosition(); - var linearLength = Vector.diff(targetVec, startVec).length; - var incTurns = linearLength / properties._FeedPerTurn * 360; - - var steps = Math.ceil(incTurns / 90); - for (step = 1;step<=steps ;step++){ - var currX = startVec.x + (targetVec.x - startVec.x) / steps * step; - var currY = startVec.y + (targetVec.y - startVec.y) / steps * step; - var currZ = startVec.z + (targetVec.z - startVec.z) / steps * step; - forceXYZ(); - writeBlock("Cpos = C6P + " + xOutput.format(incTurns/steps)); - writeBlock("Axyzabc 0, " + xOutput.format(currX) + ", " + yOutput.format(currY) + ", " + zOutput.format(currZ) + ", " + "a6p" + ", " + "0" + ", Cpos" + ";"); - } - - }else{ - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { - // non TCP - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); - } else { - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); -} - -var currentFMode; - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - // get feed rate number - if (useInverseTimeFeed) { - var f = {frn:0, fmode:0}; - if (a || b || c) { - f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); - } else { - f.frn = feedOutput.format(feed); - f.fmode = 94; - } - } - - if (x || y || z || a || b || c) { - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - } else { - writeBlock(getFeed(feed)); - } - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); - } else { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); - } else { - writeBlock(getFeed(feed)); - } - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (properties.language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 4/5 Achs Operationen gefunden. |" + - "\r\n| Sie muessen die Property |" + - "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + - "\r\n| andernfalls koennen Sie lediglich |" + - "\r\n| 3 Achsen Programme erzeugen. |" + - "\r\n| Besteht das Problem weiterhin, |" + - "\r\n| wenden Sie sich bitte an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return; // do not output coolant - } - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - if (useInverseTimeFeed && currentSection.isMultiAxis()) { - directWriteToCNC("G" + 94); - currentFMode = 94; - } - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - if (!isLastSection() && properties.showOperationDialog != "disabled") { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Initposition;"); - } - - //write jump to start operation - if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - // onCommand(COMMAND_COOLANT_OFF); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Endmacro;"); - } - - writeBlock(translate("Submacro") + " Retractzmax;"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - if (properties.useParkPosition) { - writeBlock("Park;"); - } else { - writeBlock(translate("Submacro") + " Retractzmax;"); - zOutput.reset(); - } -} +/** + Copyright (C) 2012-2017 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} +*/ + +description = "Generic DATRON MCR Millturn (German)"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes =0;// (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + useTimeStamp: false, // specifies to output time stamp + language: "de", // specifies the language "en" or "de" + writeCoolantCommands: false, // en/disable coolant code output for the entire program + _got4thAxis: false, // specifies if the machine has a 4th axis + _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y + _got5thAxis: false, // specifies if the machine has a 5th axis + _MillTurn:true, + _FeedPerTurn : 1 +}; + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, + showOperationDialog: { + title: "Show operation dialog", + description:"Shows a start dialog on the control which allows you to select the operation to start with.", + type:"enum", + values:[ + {id: "disabled", title: "Disabled"}, + {id: "dropdown", title:"Dropdown style"}, + {id: "checkbox", title:"Checkbox style"} + ] + }, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, + useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, + language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, + _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, + _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"} +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics +var useInverseTimeFeed = false; // beta, keep false +var maxMaskLength = 40; + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of multi-axis feedrate logic +/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ +/***** 'inverseTimeOutput' must be defined. *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ +/***** The feedrate mode must be included in motion block output (linear, circular, etc. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds + +/** Calculate the multi-axis feedrate number. */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTimeFeed) { // inverse time + f.frn = inverseTimeFormat.format(getInverseTime(length[0], feed)); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = feedOutput.format(getFeedDPM(length, feed)); + f.fmode = 94; + } + return f; +} + +/** Calculate the DPM feedrate number. */ +function getFeedDPM(_moveLength, _feed) { + // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC + + if (currentSection.getOptimizedTCPMode() == 0) { // TCP mode is supported, output feed as FPM + return _feed; + } else { // DPM feedrate calculation + var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; + var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); + return length / moveTime; + } +} + +/** Calculate the Inverse time feedrate number. */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof maxInverseTime === "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof maxInverseTime === "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate the distance of the tool position to the center of a rotary axis. */ +function getRotaryRadius(center, direction, toolPosition) { + var normal = direction.getNormalized(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis. */ +function getRadialDistance(axis, startTool, endTool, startABC, endABC) { + // rotary axis does not exist + if (!axis.isEnabled()) { + return 0.0; + } + + // calculate the rotary center based on head/table + var center; + if (axis.isHead()) { + var pivot; + if (typeof headOffset === "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); + center = Vector.sum(center, axis.getOffset()); + } else { + center = axis.getOffset(); + } + + // calculate the radius of the tool end point compared to the rotary center + var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); + var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); + + // calculate length of radial move + var radius = Math.max(startRadius, endRadius); + var delta = Math.abs(endABC.getCoordinate(axis.getCoordinate()) - startABC.getCoordinate(axis.getCoordinate())); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = new Array(); + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC = getCurrentDirection(); + var endABC = new Vector(_a, _b, _c); + + if (currentSection.getOptimizedTCPMode() == 0) { + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); + endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); + } else { + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(startABC).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(endABC).multiply(endXYZ); + } + + // calculate the radial portion of the move + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) + ); + + // calculate the lengths of move + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + var linearLength = Vector.diff(endXYZ, startXYZ).length; + moveLength[0] = linearLength + radialLength; + moveLength[1] = Vector.diff(endXYZ, startXYZ).length; + moveLength[2] = 0; + + var start = new Array(startABC.x, startABC.y, startABC.z); + var end = new Array(endABC.x, endABC.y, endABC.z); + for (var i = 0; i < 3; ++i) { + var delta = Math.abs(end[i] - start[i]); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + moveLength[2] += Math.pow(delta, 2.0); + } + moveLength[2] = Math.sqrt(moveLength[2]); + return moveLength; +} +// End of multi-axis feedrate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here + var aAxis; + if (properties._got4thAxis && properties._got5thAxis) { + aAxis = createAxis( + { + coordinate:properties._got5thAxis ? 0 : 1, + table:true, + axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], + range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], + preference:-1 + } + ); + } else { + aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); + } + + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + + if (properties._got4thAxis) { + if (properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } else { + machineConfiguration = new MachineConfiguration(aAxis); + } + } + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); + switch (properties.language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog != "disabled") { + variablesDeclaration.push("optional_stop"); + if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() >= maxMaskLength) { + submacrosDeclaration.push("Initvariables"); + } + } + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog != "disabled") { + if (properties.showOperationDialog == "dropdown") { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } else { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "dropdown") { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog == "dropdown") { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } else if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() < maxMaskLength) { + dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + ); + } + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog == "dropdown") { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + if ( properties._MillTurn){ + variablesDeclaration.push("Cpos"); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformpath"); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformoffset"); + } + + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock("("); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); + } + writeln(") Initvariables;"); + } + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpTransformationSubmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock(translate("Submacro") + " Initvariables;"); + } + } + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + } else if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +/* +function onRewindMachine() { + writeComment("REWIND"); +} +*/ + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); + writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); + writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); + //writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.y) +", ", + abcFormat.format(abc.z) +";"); + } + } else { + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); + } + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + + writeBlock("("); + if (useInverseTimeFeed) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + if (properties._got5thAxis) { + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + } + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); + } else { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); + } + + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + writeBlock("A_initial_pos = A6p;"); + writeBlock("B_initial_pos = B6p;"); + writeBlock("C_initial_pos = C6p;"); + + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + writeBlock("A_delta = A_initial_pos - A6p;"); + writeBlock("B_delta = B_initial_pos - B6p;"); + writeBlock("C_delta = C_initial_pos - C6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + + +function createEndmacro() { + writeBlock("("); + if (useInverseTimeFeed) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()); + + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + + if (newWorkOffset || newWorkPlane) { + // retract to safe plane + retracted = true; + writeBlock(translate("Submacro") + " Retractzmax;"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("Position 19, 2;"); + /* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } + */ + writeBlock(translate("Submacro") + " Retractzmax;"); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + } else { + if (!retracted) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +// implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +// implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +//write a command to the cnc kernel without interpretation from the control +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + + //Anpassung an die funktion drehfräsen + if( properties._MillTurn ){ + + var targetVec = new Vector(_x,_y,_z); + var startVec = getCurrentPosition(); + var linearLength = Vector.diff(targetVec, startVec).length; + var incTurns = linearLength / properties._FeedPerTurn * 360; + + var steps = Math.ceil(incTurns / 90); + for (step = 1;step<=steps ;step++){ + var currX = startVec.x + (targetVec.x - startVec.x) / steps * step; + var currY = startVec.y + (targetVec.y - startVec.y) / steps * step; + var currZ = startVec.z + (targetVec.z - startVec.z) / steps * step; + forceXYZ(); + writeBlock("Cpos = C6P + " + xOutput.format(incTurns/steps)); + writeBlock("Axyzabc 0, " + xOutput.format(currX) + ", " + yOutput.format(currY) + ", " + zOutput.format(currZ) + ", " + "a6p" + ", " + "0" + ", Cpos" + ";"); + } + + }else{ + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { + // non TCP + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); +} + +var currentFMode; + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + // get feed rate number + if (useInverseTimeFeed) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); + } else { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (properties.language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return; // do not output coolant + } + if (coolant == currentCoolantMode) { + return; // coolant is already active + } + + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTimeFeed && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && properties.showOperationDialog != "disabled") { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Initposition;"); + } + + //write jump to start operation + if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // onCommand(COMMAND_COOLANT_OFF); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeBlock(translate("Submacro") + " Retractzmax;"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (properties.useParkPosition) { + writeBlock("Park;"); + } else { + writeBlock(translate("Submacro") + " Retractzmax;"); + zOutput.reset(); + } +} diff --git a/datron mcr german uvw.cps b/deprecated/datron mcr german uvw.cps similarity index 97% rename from datron mcr german uvw.cps rename to deprecated/datron mcr german uvw.cps index 0753603..36442be 100644 --- a/datron mcr german uvw.cps +++ b/deprecated/datron mcr german uvw.cps @@ -1,2422 +1,2422 @@ -/** - Copyright (C) 2012-2017 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} -*/ - -description = "Generic DATRON MCR (German)"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - useTimeStamp: false, // specifies to output time stamp - language: "de", // specifies the language "en" or "de" - writeCoolantCommands: false, // en/disable coolant code output for the entire program - _got4thAxis: true, // specifies if the machine has a 4th axis - _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y - _got5thAxis: true // specifies if the machine has a 5th axis -}; - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, - showOperationDialog: { - title: "Show operation dialog", - description:"Shows a start dialog on the control which allows you to select the operation to start with.", - type:"enum", - values:[ - {id: "disabled", title: "Disabled"}, - {id: "dropdown", title:"Dropdown style"}, - {id: "checkbox", title:"Checkbox style"} - ] - }, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, - useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, - language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, - _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, - _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"} -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); - -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics -var useInverseTimeFeed = false; // beta, keep false -var maxMaskLength = 40; - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -// Start of multi-axis feedrate logic -/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ -/***** 'inverseTimeOutput' must be defined. *****/ -/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ -/***** The feedrate mode must be included in motion block output (linear, circular, etc. *****/ -var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations -var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds -var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds - -/** Calculate the multi-axis feedrate number. */ -function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { - var f = {frn:0, fmode:0}; - if (feed <= 0) { - error(localize("Feedrate is less than or equal to 0.")); - return f; - } - - var length = getMoveLength(_x, _y, _z, _a, _b, _c); - - if (useInverseTimeFeed) { // inverse time - f.frn = inverseTimeFormat.format(getInverseTime(length[0], feed)); - f.fmode = 93; - feedOutput.reset(); - } else { // degrees per minute - f.frn = feedOutput.format(getFeedDPM(length, feed)); - f.fmode = 94; - } - return f; -} - -/** Calculate the DPM feedrate number. */ -function getFeedDPM(_moveLength, _feed) { - // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC - - if (currentSection.getOptimizedTCPMode() == 0) { // TCP mode is supported, output feed as FPM - return _feed; - } else { // DPM feedrate calculation - var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; - var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); - return length / moveTime; - } -} - -/** Calculate the Inverse time feedrate number. */ -function getInverseTime(_length, _feed) { - var inverseTime; - if (_length < 1.e-6) { // tool doesn't move - if (typeof maxInverseTime === "number") { - inverseTime = maxInverseTime; - } else { - inverseTime = 999999; - } - } else { - inverseTime = _feed / _length / inverseTimeUnits; - if (typeof maxInverseTime === "number") { - if (inverseTime > maxInverseTime) { - inverseTime = maxInverseTime; - } - } - } - return inverseTime; -} - -/** Calculate the distance of the tool position to the center of a rotary axis. */ -function getRotaryRadius(center, direction, toolPosition) { - var normal = direction.getNormalized(); - var d1 = toolPosition.x - center.x; - var d2 = toolPosition.y - center.y; - var d3 = toolPosition.z - center.z; - var radius = Math.sqrt( - Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + - Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + - Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) - ); - return radius; -} - -/** Calculate the linear distance based on the rotation of a rotary axis. */ -function getRadialDistance(axis, startTool, endTool, startABC, endABC) { - // rotary axis does not exist - if (!axis.isEnabled()) { - return 0.0; - } - - // calculate the rotary center based on head/table - var center; - if (axis.isHead()) { - var pivot; - if (typeof headOffset === "number") { - pivot = headOffset; - } else { - pivot = tool.getBodyLength(); - } - center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); - center = Vector.sum(center, axis.getOffset()); - } else { - center = axis.getOffset(); - } - - // calculate the radius of the tool end point compared to the rotary center - var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); - var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); - - // calculate length of radial move - var radius = Math.max(startRadius, endRadius); - var delta = Math.abs(endABC.getCoordinate(axis.getCoordinate()) - startABC.getCoordinate(axis.getCoordinate())); - if (delta > Math.PI) { - delta = 2 * Math.PI - delta; - } - var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); - return radialLength; -} - -/** Calculate tooltip, XYZ, and rotary move lengths. */ -function getMoveLength(_x, _y, _z, _a, _b, _c) { - // get starting and ending positions - var moveLength = new Array(); - var startTool; - var endTool; - var startXYZ; - var endXYZ; - var startABC = getCurrentDirection(); - var endABC = new Vector(_a, _b, _c); - - if (currentSection.getOptimizedTCPMode() == 0) { - startTool = getCurrentPosition(); - endTool = new Vector(_x, _y, _z); - startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); - endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); - } else { - startXYZ = getCurrentPosition(); - endXYZ = new Vector(_x, _y, _z); - startTool = machineConfiguration.getOrientation(startABC).multiply(startXYZ); - endTool = machineConfiguration.getOrientation(endABC).multiply(endXYZ); - } - - // calculate the radial portion of the move - var radialLength = Math.sqrt( - Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) - ); - - // calculate the lengths of move - // tool tip distance is the move distance based on a combination of linear and rotary axes movement - var linearLength = Vector.diff(endXYZ, startXYZ).length; - moveLength[0] = linearLength + radialLength; - moveLength[1] = Vector.diff(endXYZ, startXYZ).length; - moveLength[2] = 0; - - var start = new Array(startABC.x, startABC.y, startABC.z); - var end = new Array(endABC.x, endABC.y, endABC.z); - for (var i = 0; i < 3; ++i) { - var delta = Math.abs(end[i] - start[i]); - if (delta > Math.PI) { - delta = 2 * Math.PI - delta; - } - moveLength[2] += Math.pow(delta, 2.0); - } - moveLength[2] = Math.sqrt(moveLength[2]); - return moveLength; -} -// End of multi-axis feedrate logic - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here - var aAxis; - if (properties._got4thAxis && properties._got5thAxis) { - aAxis = createAxis( - { - coordinate:properties._got5thAxis ? 0 : 1, - table:true, - axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], - range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], - preference:-1 - } - ); - } else { - aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); - } - - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); - - if (properties._got4thAxis) { - if (properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else { - machineConfiguration = new MachineConfiguration(aAxis); - } - } - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - } else { - writeBlock("!Makro file ; V9.09F!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); - switch (properties.language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog != "disabled") { - variablesDeclaration.push("optional_stop"); - if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() >= maxMaskLength) { - submacrosDeclaration.push("Initvariables"); - } - } - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog != "disabled") { - if (properties.showOperationDialog == "dropdown") { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } else { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "dropdown") { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog == "dropdown") { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } else if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() < maxMaskLength) { - dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" - ); - } - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog == "dropdown") { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - //variablesDeclaration.push("U_delta"); - variablesDeclaration.push("V_delta"); - variablesDeclaration.push("W_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - //variablesDeclaration.push("U_temp"); - variablesDeclaration.push("V_temp"); - variablesDeclaration.push("W_temp"); - variablesDeclaration.push("Isinitialposition"); - variablesDeclaration.push("timefeed"); - - variablesDeclaration.push("Znr"); - variablesDeclaration.push("Zkor"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("Zdelta"); - - submacrosDeclaration.push("Initposition"); - submacrosDeclaration.push("Endmacro"); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformpath"); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformoffset"); - } - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_exit Endmacro;"); - writeln(""); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); - writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); - writeln(""); - } - - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock("("); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); - } - writeln(") Initvariables;"); - } - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createPositionInitSubmacro(); - createEndmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpTransformationSubmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock(translate("Submacro") + " Initvariables;"); - } - } - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - } else if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - - // wcs - var workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - // insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; - } -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -/* -function onRewindMachine() { - writeComment("REWIND"); -} -*/ - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - //writeBlock("U_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "u6p") + " - U_delta;"); - writeBlock("V_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "v6p") + " - V_delta;"); - writeBlock("W_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "w6p") + " - W_delta;"); - writeBlock("Axyzuvw 1, x6p, y6p, z6p, u6p, V_temp, W_temp;"); - //writeBlock("Axyzuvw 1, x6p, y6p, z6p, u6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "v6p") + ", w6p;"); - if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { - writeBlock(translate("Submacro") + " Transformoffset 0, ", - abcFormat.format(0) +", ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.z) +";"); - } - } else { - var a = 0; - var b = (machineConfiguration.isMachineCoordinate(0) ? bOutput.format(abc.x) : "v6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "w6p"); - writeBlock("Axyzuvw 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); - } - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - - writeBlock("("); - if (useInverseTimeFeed) { - writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); - } - - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - if (properties._got5thAxis) { - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - } - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( B ) - Z_temp * Sin ( B );"); - writeBlock("Z_trans = Y_temp * Sin ( B ) + Z_temp * Cos ( B );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - - writeBlock("Znr = Zeromemnr;"); - writeBlock("Relsp 0;"); - writeBlock("Zkor = 3;"); - writeBlock("Zdelta = Z6p + Wzl + Zkor;"); - writeBlock("Relsp Znr;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * (Z6p + Zdelta);"); - - //writeBlock("U_temp = A - U_delta;"); - writeBlock("V_temp = B - V_delta;"); - writeBlock("W_temp = C - W_delta;"); - - if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Axyzuvw Israpid, X_new, Y_new, Z_new, 0, V_temp, W_temp;"); - } else { - writeBlock("Axyzuvw Israpid, X_new, Y_new, Z_new, 0, V_temp, 0;"); - } - - writeBlock(") Transformpath;"); - -} - -function createRtcpTransformationSubmacro() { - writeBlock("("); - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( B ) - Z_temp * Sin ( B );"); - writeBlock("Z_trans = Y_temp * Sin ( B ) + Z_temp * Cos ( B );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X6p + X_trans;"); - writeBlock("Y_new = Y6p + Y_trans;"); - writeBlock("Z_new = Z6p + Z_trans;"); - writeBlock(";!set new position!;"); - writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); - writeBlock(") Transformoffset;"); -} - -function createPositionInitSubmacro() { - // get initial offset - writeBlock("("); - writeBlock("X_initial_pos = X6p;"); - writeBlock("Y_initial_pos = Y6p;"); - writeBlock("Z_initial_pos = Z6p;"); - //writeBlock("A_initial_pos = u6p;"); - writeBlock("B_initial_pos = v6p;"); - writeBlock("C_initial_pos = w6p;"); - - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_delta = X_initial_pos - X6p;"); - writeBlock("Y_delta = Y_initial_pos - Y6p;"); - writeBlock("Z_delta = Z_initial_pos - Z6p;"); - //writeBlock("U_delta = A_initial_pos - u6p;"); - writeBlock("V_delta = B_initial_pos - v6p;"); - writeBlock("W_delta = C_initial_pos - w6p;"); - writeBlock(") Initposition;"); -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - - -function createEndmacro() { - writeBlock("("); - if (useInverseTimeFeed) { - mcrSetTimeFeed(); - } - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()); - - writeBlock("("); - if (isProbeOperation(currentSection)) { - writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe - writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); - } else { - writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe - } - - if (newWorkOffset || newWorkPlane) { - // retract to safe plane - retracted = true; - writeBlock(translate("Submacro") + " Retractzmax;"); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - //writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - writeBlock("Glaettung " + " 1, " + xyzFormat.format(t * 1.2) + ", 10, 0;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = 0; - var b = (machineConfiguration.isMachineCoordinate(0) ? bOutput.format(abc.x) : "v6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "w6p"); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("Position 19, 2;"); - /* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } - */ - writeBlock(translate("Submacro") + " Retractzmax;"); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - - - } else { - if (!retracted) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - writeBlock("Axyzuvw 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzuvw 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -// implement G93 command -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -// implement G94 command -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -//write a command to the cnc kernel without interpretation from the control -function directWriteToCNC(command) { - error(localize("Inverse Time feed is currently not supported.")); - return; -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = 0; - var b = (machineConfiguration.isMachineCoordinate(0) ? cOutput.format(_a) : "v6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "w6p"); - - if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { - // non TCP - //writeComment("Hallo a,b,c " +a +" "+b +" "+c); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); - } else { - forceXYZ(); - writeBlock("Axyzuvw 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); -} - -var currentFMode; -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - // writeComment("Hallo am anfang vor format _a:" +_a +" _b:"+_b +" _c:"+_c); - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - - - var a = 0; - // var b = (machineConfiguration.isMachineCoordinate(0) ? _a : "v6p"); - // var c = (machineConfiguration.isMachineCoordinate(2) ? _c : "w6p"); - - var b = (machineConfiguration.isMachineCoordinate(0) ? cOutput.format(_a) : "v6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "w6p"); - //writeComment("Hallo b:" + b +" c:"+c); - //writeComment("Hallo am nach format b(_a):"+ b +" c:"+ c); - - - // get feed rate number - if (useInverseTimeFeed) { - var f = {frn:0, fmode:0}; - if (a || b || c) { - f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); - } else { - f.frn = feedOutput.format(feed); - f.fmode = 94; - } - } - - if (x || y || z || a || b || c) { - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - } else { - writeBlock(getFeed(feed)); - } -//TODO - // writeComment("Hallo a,b,c " +a +" "+b +" "+c); - - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); - } else { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); - } else { - writeBlock(getFeed(feed)); - } - writeBlock("Axyzuvw 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (properties.language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 4/5 Achs Operationen gefunden. |" + - "\r\n| Sie muessen die Property |" + - "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + - "\r\n| andernfalls koennen Sie lediglich |" + - "\r\n| 3 Achsen Programme erzeugen. |" + - "\r\n| Besteht das Problem weiterhin, |" + - "\r\n| wenden Sie sich bitte an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return; // do not output coolant - } - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - if (useInverseTimeFeed && currentSection.isMultiAxis()) { - directWriteToCNC("G" + 94); - currentFMode = 94; - } - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - if (!isLastSection() && properties.showOperationDialog != "disabled") { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Initposition;"); - } - - //write jump to start operation - if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - // onCommand(COMMAND_COOLANT_OFF); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Endmacro;"); - } - - writeBlock(translate("Submacro") + " Retractzmax;"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - if (properties.useParkPosition) { - writeBlock("Park;"); - } else { - writeBlock(translate("Submacro") + " Retractzmax;"); - zOutput.reset(); - } -} +/** + Copyright (C) 2012-2017 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} +*/ + +description = "Generic DATRON MCR (German)"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + useTimeStamp: false, // specifies to output time stamp + language: "de", // specifies the language "en" or "de" + writeCoolantCommands: false, // en/disable coolant code output for the entire program + _got4thAxis: true, // specifies if the machine has a 4th axis + _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y + _got5thAxis: true // specifies if the machine has a 5th axis +}; + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, + showOperationDialog: { + title: "Show operation dialog", + description:"Shows a start dialog on the control which allows you to select the operation to start with.", + type:"enum", + values:[ + {id: "disabled", title: "Disabled"}, + {id: "dropdown", title:"Dropdown style"}, + {id: "checkbox", title:"Checkbox style"} + ] + }, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, + useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, + language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, + _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, + _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"} +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics +var useInverseTimeFeed = false; // beta, keep false +var maxMaskLength = 40; + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of multi-axis feedrate logic +/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ +/***** 'inverseTimeOutput' must be defined. *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ +/***** The feedrate mode must be included in motion block output (linear, circular, etc. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds + +/** Calculate the multi-axis feedrate number. */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTimeFeed) { // inverse time + f.frn = inverseTimeFormat.format(getInverseTime(length[0], feed)); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = feedOutput.format(getFeedDPM(length, feed)); + f.fmode = 94; + } + return f; +} + +/** Calculate the DPM feedrate number. */ +function getFeedDPM(_moveLength, _feed) { + // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC + + if (currentSection.getOptimizedTCPMode() == 0) { // TCP mode is supported, output feed as FPM + return _feed; + } else { // DPM feedrate calculation + var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; + var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); + return length / moveTime; + } +} + +/** Calculate the Inverse time feedrate number. */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof maxInverseTime === "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof maxInverseTime === "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate the distance of the tool position to the center of a rotary axis. */ +function getRotaryRadius(center, direction, toolPosition) { + var normal = direction.getNormalized(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis. */ +function getRadialDistance(axis, startTool, endTool, startABC, endABC) { + // rotary axis does not exist + if (!axis.isEnabled()) { + return 0.0; + } + + // calculate the rotary center based on head/table + var center; + if (axis.isHead()) { + var pivot; + if (typeof headOffset === "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); + center = Vector.sum(center, axis.getOffset()); + } else { + center = axis.getOffset(); + } + + // calculate the radius of the tool end point compared to the rotary center + var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); + var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); + + // calculate length of radial move + var radius = Math.max(startRadius, endRadius); + var delta = Math.abs(endABC.getCoordinate(axis.getCoordinate()) - startABC.getCoordinate(axis.getCoordinate())); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = new Array(); + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC = getCurrentDirection(); + var endABC = new Vector(_a, _b, _c); + + if (currentSection.getOptimizedTCPMode() == 0) { + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); + endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); + } else { + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(startABC).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(endABC).multiply(endXYZ); + } + + // calculate the radial portion of the move + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) + ); + + // calculate the lengths of move + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + var linearLength = Vector.diff(endXYZ, startXYZ).length; + moveLength[0] = linearLength + radialLength; + moveLength[1] = Vector.diff(endXYZ, startXYZ).length; + moveLength[2] = 0; + + var start = new Array(startABC.x, startABC.y, startABC.z); + var end = new Array(endABC.x, endABC.y, endABC.z); + for (var i = 0; i < 3; ++i) { + var delta = Math.abs(end[i] - start[i]); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + moveLength[2] += Math.pow(delta, 2.0); + } + moveLength[2] = Math.sqrt(moveLength[2]); + return moveLength; +} +// End of multi-axis feedrate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here + var aAxis; + if (properties._got4thAxis && properties._got5thAxis) { + aAxis = createAxis( + { + coordinate:properties._got5thAxis ? 0 : 1, + table:true, + axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], + range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], + preference:-1 + } + ); + } else { + aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); + } + + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + + if (properties._got4thAxis) { + if (properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } else { + machineConfiguration = new MachineConfiguration(aAxis); + } + } + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); + switch (properties.language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog != "disabled") { + variablesDeclaration.push("optional_stop"); + if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() >= maxMaskLength) { + submacrosDeclaration.push("Initvariables"); + } + } + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog != "disabled") { + if (properties.showOperationDialog == "dropdown") { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } else { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "dropdown") { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog == "dropdown") { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } else if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() < maxMaskLength) { + dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + ); + } + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog == "dropdown") { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + //variablesDeclaration.push("U_delta"); + variablesDeclaration.push("V_delta"); + variablesDeclaration.push("W_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + //variablesDeclaration.push("U_temp"); + variablesDeclaration.push("V_temp"); + variablesDeclaration.push("W_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + variablesDeclaration.push("Znr"); + variablesDeclaration.push("Zkor"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("Zdelta"); + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformpath"); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformoffset"); + } + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock("("); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); + } + writeln(") Initvariables;"); + } + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpTransformationSubmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock(translate("Submacro") + " Initvariables;"); + } + } + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + } else if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +/* +function onRewindMachine() { + writeComment("REWIND"); +} +*/ + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + //writeBlock("U_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "u6p") + " - U_delta;"); + writeBlock("V_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "v6p") + " - V_delta;"); + writeBlock("W_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "w6p") + " - W_delta;"); + writeBlock("Axyzuvw 1, x6p, y6p, z6p, u6p, V_temp, W_temp;"); + //writeBlock("Axyzuvw 1, x6p, y6p, z6p, u6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "v6p") + ", w6p;"); + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(0) +", ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.z) +";"); + } + } else { + var a = 0; + var b = (machineConfiguration.isMachineCoordinate(0) ? bOutput.format(abc.x) : "v6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "w6p"); + writeBlock("Axyzuvw 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); + } + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + + writeBlock("("); + if (useInverseTimeFeed) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + if (properties._got5thAxis) { + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + } + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( B ) - Z_temp * Sin ( B );"); + writeBlock("Z_trans = Y_temp * Sin ( B ) + Z_temp * Cos ( B );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + + writeBlock("Znr = Zeromemnr;"); + writeBlock("Relsp 0;"); + writeBlock("Zkor = 3;"); + writeBlock("Zdelta = Z6p + Wzl + Zkor;"); + writeBlock("Relsp Znr;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * (Z6p + Zdelta);"); + + //writeBlock("U_temp = A - U_delta;"); + writeBlock("V_temp = B - V_delta;"); + writeBlock("W_temp = C - W_delta;"); + + if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Axyzuvw Israpid, X_new, Y_new, Z_new, 0, V_temp, W_temp;"); + } else { + writeBlock("Axyzuvw Israpid, X_new, Y_new, Z_new, 0, V_temp, 0;"); + } + + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( B ) - Z_temp * Sin ( B );"); + writeBlock("Z_trans = Y_temp * Sin ( B ) + Z_temp * Cos ( B );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + //writeBlock("A_initial_pos = u6p;"); + writeBlock("B_initial_pos = v6p;"); + writeBlock("C_initial_pos = w6p;"); + + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + //writeBlock("U_delta = A_initial_pos - u6p;"); + writeBlock("V_delta = B_initial_pos - v6p;"); + writeBlock("W_delta = C_initial_pos - w6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + + +function createEndmacro() { + writeBlock("("); + if (useInverseTimeFeed) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()); + + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + + if (newWorkOffset || newWorkPlane) { + // retract to safe plane + retracted = true; + writeBlock(translate("Submacro") + " Retractzmax;"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + //writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + writeBlock("Glaettung " + " 1, " + xyzFormat.format(t * 1.2) + ", 10, 0;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = 0; + var b = (machineConfiguration.isMachineCoordinate(0) ? bOutput.format(abc.x) : "v6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "w6p"); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("Position 19, 2;"); + /* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } + */ + writeBlock(translate("Submacro") + " Retractzmax;"); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + + + } else { + if (!retracted) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + writeBlock("Axyzuvw 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzuvw 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +// implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +// implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +//write a command to the cnc kernel without interpretation from the control +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = 0; + var b = (machineConfiguration.isMachineCoordinate(0) ? cOutput.format(_a) : "v6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "w6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { + // non TCP + //writeComment("Hallo a,b,c " +a +" "+b +" "+c); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzuvw 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); +} + +var currentFMode; +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + // writeComment("Hallo am anfang vor format _a:" +_a +" _b:"+_b +" _c:"+_c); + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + + + var a = 0; + // var b = (machineConfiguration.isMachineCoordinate(0) ? _a : "v6p"); + // var c = (machineConfiguration.isMachineCoordinate(2) ? _c : "w6p"); + + var b = (machineConfiguration.isMachineCoordinate(0) ? cOutput.format(_a) : "v6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "w6p"); + //writeComment("Hallo b:" + b +" c:"+c); + //writeComment("Hallo am nach format b(_a):"+ b +" c:"+ c); + + + // get feed rate number + if (useInverseTimeFeed) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } +//TODO + // writeComment("Hallo a,b,c " +a +" "+b +" "+c); + + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); + } else { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzuvw 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (properties.language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return; // do not output coolant + } + if (coolant == currentCoolantMode) { + return; // coolant is already active + } + + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTimeFeed && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && properties.showOperationDialog != "disabled") { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Initposition;"); + } + + //write jump to start operation + if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // onCommand(COMMAND_COOLANT_OFF); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeBlock(translate("Submacro") + " Retractzmax;"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (properties.useParkPosition) { + writeBlock("Park;"); + } else { + writeBlock(translate("Submacro") + " Retractzmax;"); + zOutput.reset(); + } +} diff --git a/datron mcr german.cps b/deprecated/datron mcr german.cps similarity index 97% rename from datron mcr german.cps rename to deprecated/datron mcr german.cps index 36ee076..dc30269 100644 --- a/datron mcr german.cps +++ b/deprecated/datron mcr german.cps @@ -1,2655 +1,2655 @@ -/** - Copyright (C) 2012-2018 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} -*/ - -description = "Generic DATRON MCR (German)"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 41215; - -longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - useTimeStamp: false, // specifies to output time stamp - language: "de", // specifies the language "en" or "de" - writeCoolantCommands: false, // en/disable coolant code output for the entire program - _got4thAxis: false, // specifies if the machine has a 4th axis - _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y - _got5thAxis: false, // specifies if the machine has a 5th axis - minimumSpindleRPM: 6000 // specifies the lowest available rpm for the spindle -}; - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, - showOperationDialog: { - title: "Show operation dialog", - description:"Shows a start dialog on the control which allows you to select the operation to start with.", - type:"enum", - values:[ - {id: "disabled", title:"Disabled"}, - {id: "dropdown", title:"Dropdown style"}, - {id: "checkbox", title:"Checkbox style"} - ] - }, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, - useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, - language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, - _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, - _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"}, - minimumSpindleRPM: {title:"Minimum spindle RPM", description:"Specifies the lowest available rpm for the spindle.", type:"integer", range:[0, 999999999]} -}; - -// samples: -// throughTool: {on: 88, off: 89} -// throughTool: {on: [8, 88], off: [9, 89]} -var coolants = { - flood: {on: 1}, - mist: {on: 1}, - throughTool: {}, - air: {on: 3}, - airThroughTool: {}, - suction: {}, - floodMist: {}, - floodThroughTool: {}, - off: 2 -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); - -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({onchange:function () {retracted = false;}, force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics -var maxMaskLength = 40; - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; -var retracted = false; // specifies that the tool has been retracted to the safe plane - -// format date + time -var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -// Start of multi-axis feedrate logic -/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ -/***** 'inverseTimeOutput' should be defined if Inverse Time feedrates are supported. *****/ -/***** 'previousABC' can be added throughout to maintain previous rotary positions. Required for Mill/Turn machines. *****/ -/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ -/***** The feedrate mode must be included in motion block output (linear, circular, etc.) for Inverse Time feedrate support. *****/ -var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations -var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds -var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds -var maxDPM = 9999.99; // maximum value to output for DPM feeds -var useInverseTimeFeed = false; // use 1/T feeds -var previousDPMFeed = 0; // previously output DPM feed -var dpmFeedToler = 0.5; // tolerance to determine when the DPM feed has changed -// var previousABC = new Vector(0, 0, 0); // previous ABC position if maintained in post, don't define if not used -var forceOptimized = undefined; // used to override optimized-for-angles points (XZC-mode) - -/** Calculate the multi-axis feedrate number. */ -function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { - var f = {frn:0, fmode:0}; - if (feed <= 0) { - error(localize("Feedrate is less than or equal to 0.")); - return f; - } - - var length = getMoveLength(_x, _y, _z, _a, _b, _c); - - if (useInverseTimeFeed) { // inverse time - f.frn = getInverseTime(length.tool, feed); - f.fmode = 93; - feedOutput.reset(); - } else { // degrees per minute - f.frn = getFeedDPM(length, feed); - f.fmode = 94; - } - return f; -} - -/** Returns point optimization mode. */ -function getOptimizedMode() { - if (forceOptimized != undefined) { - return forceOptimized; - } - // return (currentSection.getOptimizedTCPMode() != 0); // TAG:doesn't return correct value - return true; // always return false for non-TCP based heads -} - -/** Calculate the DPM feedrate number. */ -function getFeedDPM(_moveLength, _feed) { - if ((_feed == 0) || (_moveLength.tool < 0.0001) || (toDeg(_moveLength.abcLength) < 0.0005)) { - previousDPMFeed = 0; - return _feed; - } - var moveTime = _moveLength.tool / _feed; - if (moveTime == 0) { - previousDPMFeed = 0; - return _feed; - } - - var dpmFeed; - var tcp = false; // !getOptimizedMode() && (forceOptimized == undefined); // set to false for rotary heads - if (tcp) { // TCP mode is supported, output feed as FPM - dpmFeed = _feed; - } else if (false) { // standard DPM - dpmFeed = Math.min(toDeg(_moveLength.abcLength) / moveTime, maxDPM); - if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) { - dpmFeed = previousDPMFeed; - } - } else if (true) { // combination FPM/DPM - var length = Math.sqrt(Math.pow(_moveLength.xyzLength, 2.0) + Math.pow((toDeg(_moveLength.abcLength) * dpmBPW), 2.0)); - dpmFeed = Math.min((length / moveTime), maxDPM); - if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) { - dpmFeed = previousDPMFeed; - } - } else { // machine specific calculation - dpmFeed = _feed; - } - previousDPMFeed = dpmFeed; - return dpmFeed; -} - -/** Calculate the Inverse time feedrate number. */ -function getInverseTime(_length, _feed) { - var inverseTime; - if (_length < 1.e-6) { // tool doesn't move - if (typeof maxInverseTime === "number") { - inverseTime = maxInverseTime; - } else { - inverseTime = 999999; - } - } else { - inverseTime = _feed / _length / inverseTimeUnits; - if (typeof maxInverseTime === "number") { - if (inverseTime > maxInverseTime) { - inverseTime = maxInverseTime; - } - } - } - return inverseTime; -} - -/** Calculate radius for each rotary axis. */ -function getRotaryRadii(startTool, endTool, startABC, endABC) { - var radii = new Vector(0, 0, 0); - var startRadius; - var endRadius; - var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); - for (var i = 0; i < 3; ++i) { - if (axis[i].isEnabled()) { - var startRadius = getRotaryRadius(axis[i], startTool, startABC); - var endRadius = getRotaryRadius(axis[i], endTool, endABC); - radii.setCoordinate(axis[i].getCoordinate(), Math.max(startRadius, endRadius)); - } - } - return radii; -} - -/** Calculate the distance of the tool position to the center of a rotary axis. */ -function getRotaryRadius(axis, toolPosition, abc) { - if (!axis.isEnabled()) { - return 0; - } - - var direction = axis.getEffectiveAxis(); - var normal = direction.getNormalized(); - // calculate the rotary center based on head/table - var center; - var radius; - if (axis.isHead()) { - var pivot; - if (typeof headOffset === "number") { - pivot = headOffset; - } else { - pivot = tool.getBodyLength(); - } - if (axis.getCoordinate() == machineConfiguration.getAxisU().getCoordinate()) { // rider - center = Vector.sum(toolPosition, Vector.product(machineConfiguration.getDirection(abc), pivot)); - center = Vector.sum(center, axis.getOffset()); - radius = Vector.diff(toolPosition, center).length; - } else { // carrier - var angle = abc.getCoordinate(machineConfiguration.getAxisU().getCoordinate()); - radius = Math.abs(pivot * Math.sin(angle)); - radius += axis.getOffset().length; - } - } else { - center = axis.getOffset(); - var d1 = toolPosition.x - center.x; - var d2 = toolPosition.y - center.y; - var d3 = toolPosition.z - center.z; - var radius = Math.sqrt( - Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + - Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + - Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) - ); - } - return radius; -} - -/** Calculate the linear distance based on the rotation of a rotary axis. */ -function getRadialDistance(radius, startABC, endABC) { - // calculate length of radial move - var delta = Math.abs(endABC - startABC); - if (delta > Math.PI) { - delta = 2 * Math.PI - delta; - } - var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); - return radialLength; -} - -/** Calculate tooltip, XYZ, and rotary move lengths. */ -function getMoveLength(_x, _y, _z, _a, _b, _c) { - // get starting and ending positions - var moveLength = {}; - var startTool; - var endTool; - var startXYZ; - var endXYZ; - var startABC; - if (typeof previousABC !== "undefined") { - startABC = new Vector(previousABC.x, previousABC.y, previousABC.z); - } else { - startABC = getCurrentDirection(); - } - var endABC = new Vector(_a, _b, _c); - - if (!getOptimizedMode()) { // calculate XYZ from tool tip - startTool = getCurrentPosition(); - endTool = new Vector(_x, _y, _z); - startXYZ = startTool; - endXYZ = endTool; - - // adjust points for tables - if (!machineConfiguration.getTableABC(startABC).isZero() || !machineConfiguration.getTableABC(endABC).isZero()) { - startXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).getTransposed().multiply(startXYZ); - endXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).getTransposed().multiply(endXYZ); - } - - // adjust points for heads - if (machineConfiguration.getAxisU().isEnabled() && machineConfiguration.getAxisU().isHead()) { - if (typeof getOptimizedHeads === "function") { // use post processor function to adjust heads - startXYZ = getOptimizedHeads(startXYZ.x, startXYZ.y, startXYZ.z, startABC.x, startABC.y, startABC.z); - endXYZ = getOptimizedHeads(endXYZ.x, endXYZ.y, endXYZ.z, endABC.x, endABC.y, endABC.z); - } else { // guess at head adjustments - var startDisplacement = machineConfiguration.getDirection(startABC); - startDisplacement.multiply(headOffset); - var endDisplacement = machineConfiguration.getDirection(endABC); - endDisplacement.multiply(headOffset); - startXYZ = Vector.sum(startTool, startDisplacement); - endXYZ = Vector.sum(endTool, endDisplacement); - } - } - } else { // calculate tool tip from XYZ, heads are always programmed in TCP mode, so not handled here - startXYZ = getCurrentPosition(); - endXYZ = new Vector(_x, _y, _z); - startTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).multiply(startXYZ); - endTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).multiply(endXYZ); - } - - // calculate axes movements - moveLength.xyz = Vector.diff(endXYZ, startXYZ).abs; - moveLength.xyzLength = moveLength.xyz.length; - moveLength.abc = Vector.diff(endABC, startABC).abs; - for (var i = 0; i < 3; ++i) { - if (moveLength.abc.getCoordinate(i) > Math.PI) { - moveLength.abc.setCoordinate(i, 2 * Math.PI - moveLength.abc.getCoordinate(i)); - } - } - moveLength.abcLength = moveLength.abc.length; - - // calculate radii - moveLength.radius = getRotaryRadii(startTool, endTool, startABC, endABC); - - // calculate the radial portion of the tool tip movement - var radialLength = Math.sqrt( - Math.pow(getRadialDistance(moveLength.radius.x, startABC.x, endABC.x), 2.0) + - Math.pow(getRadialDistance(moveLength.radius.y, startABC.y, endABC.y), 2.0) + - Math.pow(getRadialDistance(moveLength.radius.z, startABC.z, endABC.z), 2.0) - ); - - // calculate the tool tip move length - // tool tip distance is the move distance based on a combination of linear and rotary axes movement - moveLength.tool = moveLength.xyzLength + radialLength; - - // debug - if (false) { - writeComment("DEBUG - tool = " + moveLength.tool); - writeComment("DEBUG - xyz = " + moveLength.xyz); - var temp = Vector.product(moveLength.abc, 180/Math.PI); - writeComment("DEBUG - abc = " + temp); - writeComment("DEBUG - radius = " + moveLength.radius); - } - return moveLength; -} -// End of multi-axis feedrate logic - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here - var aAxis; - if (properties._got4thAxis && properties._got5thAxis) { - aAxis = createAxis( - { - coordinate:properties._got5thAxis ? 0 : 1, - table:true, - axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], - range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], - preference:-1 - } - ); - } else { - aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); - } - - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); - - if (properties._got4thAxis) { - if (properties._got5thAxis) { - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else { - machineConfiguration = new MachineConfiguration(aAxis); - } - } - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - } else { - writeBlock("!Makro file ; V9.09F!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); - switch (properties.language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog != "disabled") { - variablesDeclaration.push("optional_stop"); - if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() >= maxMaskLength) { - submacrosDeclaration.push("Initvariables"); - } - } - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog != "disabled") { - if (properties.showOperationDialog == "dropdown") { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } else { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "dropdown") { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog == "dropdown") { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } else if (properties.showOperationDialog == "checkbox") { - if (getNumberOfSections() < maxMaskLength) { - dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" - ); - } - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog == "dropdown") { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - variablesDeclaration.push("A_delta"); - variablesDeclaration.push("B_delta"); - variablesDeclaration.push("C_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - variablesDeclaration.push("A_temp"); - variablesDeclaration.push("B_temp"); - variablesDeclaration.push("C_temp"); - variablesDeclaration.push("Isinitialposition"); - variablesDeclaration.push("timefeed"); - - submacrosDeclaration.push("Initposition"); - submacrosDeclaration.push("Endmacro"); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformpath"); - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - submacrosDeclaration.push("Transformoffset"); - } - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_exit Endmacro;"); - writeln(""); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); - writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); - writeln(""); - } - - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock("("); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); - } - writeln(") Initvariables;"); - } - } - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createPositionInitSubmacro(); - createEndmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpTransformationSubmacro(); - } - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog == "checkbox") { - if (numberOfSections >= maxMaskLength) { - writeBlock(translate("Submacro") + " Initvariables;"); - } - } - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - } else if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - var _spindleSpeed = section.getInitialSpindleSpeed(); - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(Math.max(_spindleSpeed, properties.minimumSpindleRPM)) + ", 0, 30;"); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - - // wcs - var workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - if (properties.showOperationDialog == "checkbox") { - writeBlock(translate("Label") + " " + sectionID + ";"); - } - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - // insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - previousDPMFeed = 0; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; - } -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -/* -function onRewindMachine() { - writeComment("REWIND"); -} -*/ - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - if (!retracted) { - writeRetract(Z); - } - - gMotionModal.reset(); - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); - writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); - writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); - // writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); - if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { - writeBlock(translate("Submacro") + " Transformoffset 0, ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.y) +", ", - abcFormat.format(abc.z) +";"); - } - } else { - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); - } - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - - writeBlock("("); - if (useInverseTimeFeed) { - writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); - } - - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - if (properties._got5thAxis) { - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - } - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); - - writeBlock("A_temp = A - A_delta;"); - writeBlock("B_temp = B - B_delta;"); - writeBlock("C_temp = C - C_delta;"); - - if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); - } else { - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); - } - - writeBlock(") Transformpath;"); - -} - -function createRtcpTransformationSubmacro() { - writeBlock("("); - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X6p + X_trans;"); - writeBlock("Y_new = Y6p + Y_trans;"); - writeBlock("Z_new = Z6p + Z_trans;"); - writeBlock(";!set new position!;"); - writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); - writeBlock(") Transformoffset;"); -} - -function createPositionInitSubmacro() { - // get initial offset - writeBlock("("); - writeBlock("X_initial_pos = X6p;"); - writeBlock("Y_initial_pos = Y6p;"); - writeBlock("Z_initial_pos = Z6p;"); - writeBlock("A_initial_pos = A6p;"); - writeBlock("B_initial_pos = B6p;"); - writeBlock("C_initial_pos = C6p;"); - - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeBlock("X_delta = X_initial_pos - X6p;"); - writeBlock("Y_delta = Y_initial_pos - Y6p;"); - writeBlock("Z_delta = Z_initial_pos - Z6p;"); - writeBlock("A_delta = A_initial_pos - A6p;"); - writeBlock("B_delta = B_initial_pos - B6p;"); - writeBlock("C_delta = C_initial_pos - C6p;"); - writeBlock(") Initposition;"); -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - - -function createEndmacro() { - writeBlock("("); - if (useInverseTimeFeed) { - mcrSetTimeFeed(); - } - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - retracted = false; - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || - (getPreviousSection().isMultiAxis() != currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations - writeBlock("("); - if (isProbeOperation(currentSection)) { - writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe - writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); - } else { - writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe - } - - if (newWorkOffset || newWorkPlane) { - // retract to safe plane - writeRetract(Z); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (spindleSpeed < properties.minimumSpindleRPM) { - warning(localize("Spindle speed is below the minimum value.")); - } - if (spindleSpeed > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeRetract(Z); - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock("Position 19, 2;"); -/* - if (properties._got5thAxis) { - writeBlock("Position 19, 2;"); - } else if (properties._got4thAxis && properties._got5thAxis) { - writeBlock("Position 21, 2;"); - } -*/ - writeRetract(Z); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - } else { - if (!retracted) { - writeRetract(Z); - } - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } - retracted = false; -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - var _spindleSpeed = spindleSpeed; - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(Math.max(_spindleSpeed, properties.minimumSpindleRPM)) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } - - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -// implement G93 command -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -// implement G94 command -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -// write a command to the cnc kernel without interpretation from the control -function directWriteToCNC(command) { - error(localize("Inverse Time feed is currently not supported.")); - return; -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { - // non TCP - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); - } else { - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); -} - -var currentFMode; - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - // get feed rate number - if (useInverseTimeFeed) { - var f = {frn:0, fmode:0}; - if (a || b || c) { - f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); - } else { - f.frn = feedOutput.format(feed); - f.fmode = 94; - } - } - - if (x || y || z || a || b || c) { - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - } else { - writeBlock(getFeed(feed)); - } - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); - } else { - if (useInverseTimeFeed) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); - } else { - writeBlock(getFeed(feed)); - } - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (properties.language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 4/5 axis operations detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis or got5Axis, |" + - "\r\n| otherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 4/5 Achs Operationen gefunden. |" + - "\r\n| Sie muessen die Property |" + - "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + - "\r\n| andernfalls koennen Sie lediglich |" + - "\r\n| 3 Achsen Programme erzeugen. |" + - "\r\n| Besteht das Problem weiterhin, |" + - "\r\n| wenden Sie sich bitte an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; -var coolantOff = undefined; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return undefined; // do not output coolant - } - var coolantCodes = getCoolantCodes(coolant); - if (Array.isArray(coolantCodes)) { - for (var c in coolantCodes) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + coolantCodes[c] + ", 0;"); // coolant off - } - return undefined; - } - return coolantCodes; -} - -function getCoolantCodes(coolant) { - if (!coolants) { - error(localize("Coolants have not been defined.")); - } - if (!coolantOff) { // use the default coolant off command when an 'off' value is not specified for the previous coolant mode - coolantOff = coolants.off; - } - - if (isProbeOperation()) { // avoid coolant output for probing - coolant = COOLANT_OFF; - } - - if (coolant == currentCoolantMode) { - return undefined; // coolant is already active - } - - var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line - if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF)) { - multipleCoolantBlocks.push(mFormat.format(coolantOff)); - } - - var m; - if (coolant == COOLANT_OFF) { - m = coolantOff; - coolantOff = coolants.off; - } - - switch (coolant) { - case COOLANT_FLOOD: - if (!coolants.flood) { - break; - } - m = coolants.flood.on; - coolantOff = coolants.flood.off; - break; - case COOLANT_THROUGH_TOOL: - if (!coolants.throughTool) { - break; - } - m = coolants.throughTool.on; - coolantOff = coolants.throughTool.off; - break; - case COOLANT_AIR: - if (!coolants.air) { - break; - } - m = coolants.air.on; - coolantOff = coolants.air.off; - break; - case COOLANT_AIR_THROUGH_TOOL: - if (!coolants.airThroughTool) { - break; - } - m = coolants.airThroughTool.on; - coolantOff = coolants.airThroughTool.off; - break; - case COOLANT_FLOOD_MIST: - if (!coolants.floodMist) { - break; - } - m = coolants.floodMist.on; - coolantOff = coolants.floodMist.off; - break; - case COOLANT_MIST: - if (!coolants.mist) { - break; - } - m = coolants.mist.on; - coolantOff = coolants.mist.off; - break; - case COOLANT_SUCTION: - if (!coolants.suction) { - break; - } - m = coolants.suction.on; - coolantOff = coolants.suction.off; - break; - case COOLANT_FLOOD_THROUGH_TOOL: - if (!coolants.floodThroughTool) { - break; - } - m = coolants.floodThroughTool.on; - coolantOff = coolants.floodThroughTool.off; - break; - } - - if (!m) { - onUnsupportedCoolant(coolant); - m = 9; - } - - if (m) { - if (Array.isArray(m)) { - for (var i in m) { - multipleCoolantBlocks.push(mFormat.format(m[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(m)); - } - currentCoolantMode = coolant; - return multipleCoolantBlocks; // return the single formatted coolant value - } - return undefined; -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_OPTIONAL_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - if (useInverseTimeFeed && currentSection.isMultiAxis()) { - directWriteToCNC("G" + 94); - currentFMode = 94; - } - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - if (!isLastSection() && properties.showOperationDialog != "disabled") { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -/** Output block to do safe retract and/or move to home position. */ -function writeRetract() { - if (arguments.length == 0) { - error(localize("No axis specified for writeRetract().")); - return; - } - var words = []; // store all retracted axes in an array - for (var i = 0; i < arguments.length; ++i) { - let instances = 0; // checks for duplicate retract calls - for (var j = 0; j < arguments.length; ++j) { - if (arguments[i] == arguments[j]) { - ++instances; - } - } - if (instances > 1) { // error if there are multiple retract calls for the same axis - error(localize("Cannot retract the same axis twice in one line")); - return; - } - switch (arguments[i]) { - case X: - words.push("X" + xyzFormat.format(machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : 0)); - break; - case Y: - words.push("Y" + xyzFormat.format(machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : 0)); - break; - case Z: - writeBlock(translate("Submacro") + " Retractzmax;"); - retracted = true; // specifies that the tool has been retracted to the safe plane - zOutput.reset(); - break; - default: - error(localize("Bad axis specified for writeRetract().")); - return; - } - } - if (words.length > 0) { - if (properties.useParkPosition) { - writeBlock("Park;"); - } - } -} - - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Initposition;"); - } - - // write jump to start operation - if (properties.showOperationDialog == "dropdown") { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - // setCoolant(COOLANT_OFF); - - if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { - writeBlock(translate("Submacro") + " Endmacro;"); - } - - writeRetract(Z); - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - writeRetract(X, Y); -} +/** + Copyright (C) 2012-2018 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {9FA90B9F-51A1-4B08-9105-510C69047622} +*/ + +description = "Generic DATRON MCR (German)"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 41215; + +longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: "dropdown", // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + useTimeStamp: false, // specifies to output time stamp + language: "de", // specifies the language "en" or "de" + writeCoolantCommands: false, // en/disable coolant code output for the entire program + _got4thAxis: false, // specifies if the machine has a 4th axis + _4thAxisRotatesAroundX: true, // specifies if the 4th axis rotates around X or Y + _got5thAxis: false, // specifies if the machine has a 5th axis + minimumSpindleRPM: 6000 // specifies the lowest available rpm for the spindle +}; + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"}, + showOperationDialog: { + title: "Show operation dialog", + description:"Shows a start dialog on the control which allows you to select the operation to start with.", + type:"enum", + values:[ + {id: "disabled", title:"Disabled"}, + {id: "dropdown", title:"Dropdown style"}, + {id: "checkbox", title:"Checkbox style"} + ] + }, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Enable to use smoothing in the NC program.", type:"boolean"}, + useDynamic: {title: "Use dynamic mode", description:"Enable to use dynamic mode.", type:"boolean"}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + useTimeStamp: {title:"Use timestamp", description:"Enable to include timestamp in program header.", type:"boolean"}, + language: {title: "Language", description:"Specifies the language to use in the NC program.", type:"enum", values:[{id: "en", title: "English"}, {id: "de", title:"German"}]}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + _got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, + _4thAxisRotatesAroundX: {title:"4th axis rotates around X", description:"Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", type:"boolean"}, + _got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with 5-axis capabilities.", type:"boolean"}, + minimumSpindleRPM: {title:"Minimum spindle RPM", description:"Specifies the lowest available rpm for the spindle.", type:"integer", range:[0, 999999999]} +}; + +// samples: +// throughTool: {on: 88, off: 89} +// throughTool: {on: [8, 88], off: [9, 89]} +var coolants = { + flood: {on: 1}, + mist: {on: 1}, + throughTool: {}, + air: {on: 3}, + airThroughTool: {}, + suction: {}, + floodMist: {}, + floodThroughTool: {}, + off: 2 +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({onchange:function () {retracted = false;}, force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics +var maxMaskLength = 40; + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; +var retracted = false; // specifies that the tool has been retracted to the safe plane + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of multi-axis feedrate logic +/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/ +/***** 'inverseTimeOutput' should be defined if Inverse Time feedrates are supported. *****/ +/***** 'previousABC' can be added throughout to maintain previous rotary positions. Required for Mill/Turn machines. *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ +/***** The feedrate mode must be included in motion block output (linear, circular, etc.) for Inverse Time feedrate support. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds +var maxDPM = 9999.99; // maximum value to output for DPM feeds +var useInverseTimeFeed = false; // use 1/T feeds +var previousDPMFeed = 0; // previously output DPM feed +var dpmFeedToler = 0.5; // tolerance to determine when the DPM feed has changed +// var previousABC = new Vector(0, 0, 0); // previous ABC position if maintained in post, don't define if not used +var forceOptimized = undefined; // used to override optimized-for-angles points (XZC-mode) + +/** Calculate the multi-axis feedrate number. */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTimeFeed) { // inverse time + f.frn = getInverseTime(length.tool, feed); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = getFeedDPM(length, feed); + f.fmode = 94; + } + return f; +} + +/** Returns point optimization mode. */ +function getOptimizedMode() { + if (forceOptimized != undefined) { + return forceOptimized; + } + // return (currentSection.getOptimizedTCPMode() != 0); // TAG:doesn't return correct value + return true; // always return false for non-TCP based heads +} + +/** Calculate the DPM feedrate number. */ +function getFeedDPM(_moveLength, _feed) { + if ((_feed == 0) || (_moveLength.tool < 0.0001) || (toDeg(_moveLength.abcLength) < 0.0005)) { + previousDPMFeed = 0; + return _feed; + } + var moveTime = _moveLength.tool / _feed; + if (moveTime == 0) { + previousDPMFeed = 0; + return _feed; + } + + var dpmFeed; + var tcp = false; // !getOptimizedMode() && (forceOptimized == undefined); // set to false for rotary heads + if (tcp) { // TCP mode is supported, output feed as FPM + dpmFeed = _feed; + } else if (false) { // standard DPM + dpmFeed = Math.min(toDeg(_moveLength.abcLength) / moveTime, maxDPM); + if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) { + dpmFeed = previousDPMFeed; + } + } else if (true) { // combination FPM/DPM + var length = Math.sqrt(Math.pow(_moveLength.xyzLength, 2.0) + Math.pow((toDeg(_moveLength.abcLength) * dpmBPW), 2.0)); + dpmFeed = Math.min((length / moveTime), maxDPM); + if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) { + dpmFeed = previousDPMFeed; + } + } else { // machine specific calculation + dpmFeed = _feed; + } + previousDPMFeed = dpmFeed; + return dpmFeed; +} + +/** Calculate the Inverse time feedrate number. */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof maxInverseTime === "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof maxInverseTime === "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate radius for each rotary axis. */ +function getRotaryRadii(startTool, endTool, startABC, endABC) { + var radii = new Vector(0, 0, 0); + var startRadius; + var endRadius; + var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); + for (var i = 0; i < 3; ++i) { + if (axis[i].isEnabled()) { + var startRadius = getRotaryRadius(axis[i], startTool, startABC); + var endRadius = getRotaryRadius(axis[i], endTool, endABC); + radii.setCoordinate(axis[i].getCoordinate(), Math.max(startRadius, endRadius)); + } + } + return radii; +} + +/** Calculate the distance of the tool position to the center of a rotary axis. */ +function getRotaryRadius(axis, toolPosition, abc) { + if (!axis.isEnabled()) { + return 0; + } + + var direction = axis.getEffectiveAxis(); + var normal = direction.getNormalized(); + // calculate the rotary center based on head/table + var center; + var radius; + if (axis.isHead()) { + var pivot; + if (typeof headOffset === "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + if (axis.getCoordinate() == machineConfiguration.getAxisU().getCoordinate()) { // rider + center = Vector.sum(toolPosition, Vector.product(machineConfiguration.getDirection(abc), pivot)); + center = Vector.sum(center, axis.getOffset()); + radius = Vector.diff(toolPosition, center).length; + } else { // carrier + var angle = abc.getCoordinate(machineConfiguration.getAxisU().getCoordinate()); + radius = Math.abs(pivot * Math.sin(angle)); + radius += axis.getOffset().length; + } + } else { + center = axis.getOffset(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + } + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis. */ +function getRadialDistance(radius, startABC, endABC) { + // calculate length of radial move + var delta = Math.abs(endABC - startABC); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = {}; + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC; + if (typeof previousABC !== "undefined") { + startABC = new Vector(previousABC.x, previousABC.y, previousABC.z); + } else { + startABC = getCurrentDirection(); + } + var endABC = new Vector(_a, _b, _c); + + if (!getOptimizedMode()) { // calculate XYZ from tool tip + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = startTool; + endXYZ = endTool; + + // adjust points for tables + if (!machineConfiguration.getTableABC(startABC).isZero() || !machineConfiguration.getTableABC(endABC).isZero()) { + startXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).getTransposed().multiply(startXYZ); + endXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).getTransposed().multiply(endXYZ); + } + + // adjust points for heads + if (machineConfiguration.getAxisU().isEnabled() && machineConfiguration.getAxisU().isHead()) { + if (typeof getOptimizedHeads === "function") { // use post processor function to adjust heads + startXYZ = getOptimizedHeads(startXYZ.x, startXYZ.y, startXYZ.z, startABC.x, startABC.y, startABC.z); + endXYZ = getOptimizedHeads(endXYZ.x, endXYZ.y, endXYZ.z, endABC.x, endABC.y, endABC.z); + } else { // guess at head adjustments + var startDisplacement = machineConfiguration.getDirection(startABC); + startDisplacement.multiply(headOffset); + var endDisplacement = machineConfiguration.getDirection(endABC); + endDisplacement.multiply(headOffset); + startXYZ = Vector.sum(startTool, startDisplacement); + endXYZ = Vector.sum(endTool, endDisplacement); + } + } + } else { // calculate tool tip from XYZ, heads are always programmed in TCP mode, so not handled here + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).multiply(endXYZ); + } + + // calculate axes movements + moveLength.xyz = Vector.diff(endXYZ, startXYZ).abs; + moveLength.xyzLength = moveLength.xyz.length; + moveLength.abc = Vector.diff(endABC, startABC).abs; + for (var i = 0; i < 3; ++i) { + if (moveLength.abc.getCoordinate(i) > Math.PI) { + moveLength.abc.setCoordinate(i, 2 * Math.PI - moveLength.abc.getCoordinate(i)); + } + } + moveLength.abcLength = moveLength.abc.length; + + // calculate radii + moveLength.radius = getRotaryRadii(startTool, endTool, startABC, endABC); + + // calculate the radial portion of the tool tip movement + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(moveLength.radius.x, startABC.x, endABC.x), 2.0) + + Math.pow(getRadialDistance(moveLength.radius.y, startABC.y, endABC.y), 2.0) + + Math.pow(getRadialDistance(moveLength.radius.z, startABC.z, endABC.z), 2.0) + ); + + // calculate the tool tip move length + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + moveLength.tool = moveLength.xyzLength + radialLength; + + // debug + if (false) { + writeComment("DEBUG - tool = " + moveLength.tool); + writeComment("DEBUG - xyz = " + moveLength.xyz); + var temp = Vector.product(moveLength.abc, 180/Math.PI); + writeComment("DEBUG - abc = " + temp); + writeComment("DEBUG - radius = " + moveLength.radius); + } + return moveLength; +} +// End of multi-axis feedrate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + if (properties._got4thAxis || properties._got5thAxis) { // note: setup your machine here + var aAxis; + if (properties._got4thAxis && properties._got5thAxis) { + aAxis = createAxis( + { + coordinate:properties._got5thAxis ? 0 : 1, + table:true, + axis:[properties._4thAxisRotatesAroundX ? -1 : 0, properties._4thAxisRotatesAroundX ? 0 : -1, 0], + range:[properties._got5thAxis ? -100 : -360, properties._got5thAxis ? 0 : 360], + preference:-1 + } + ); + } else { + aAxis = createAxis({coordinate:1, table:true, axis:[properties._4thAxisRotatesAroundX ? 1 : 0, properties._4thAxisRotatesAroundX ? 0 : 1, 0], range:[-360, 360], preference:1}); + } + + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + + if (properties._got4thAxis) { + if (properties._got5thAxis) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } else { + machineConfiguration = new MachineConfiguration(aAxis); + } + } + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + properties.language + "\"" + "!"); + switch (properties.language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog != "disabled") { + variablesDeclaration.push("optional_stop"); + if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() >= maxMaskLength) { + submacrosDeclaration.push("Initvariables"); + } + } + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog != "disabled") { + if (properties.showOperationDialog == "dropdown") { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } else { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "dropdown") { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog == "dropdown") { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } else if (properties.showOperationDialog == "checkbox") { + if (getNumberOfSections() < maxMaskLength) { + dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + ); + } + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog == "dropdown") { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformpath"); + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + submacrosDeclaration.push("Transformoffset"); + } + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock("("); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); + } + writeln(") Initvariables;"); + } + } + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpTransformationSubmacro(); + } + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock(translate("Submacro") + " Initvariables;"); + } + } + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + } else if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + var _spindleSpeed = section.getInitialSpindleSpeed(); + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(Math.max(_spindleSpeed, properties.minimumSpindleRPM)) + ", 0, 30;"); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + workOffset = (properties._got4thAxis && properties._got5thAxis) ? 19 : workOffset; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + if (properties.showOperationDialog == "checkbox") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + previousDPMFeed = 0; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +/* +function onRewindMachine() { + writeComment("REWIND"); +} +*/ + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + if (!retracted) { + writeRetract(Z); + } + + gMotionModal.reset(); + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); + writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); + writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); + // writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.y) +", ", + abcFormat.format(abc.z) +";"); + } + } else { + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); + } + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + + writeBlock("("); + if (useInverseTimeFeed) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + if (properties._got5thAxis) { + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + } + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); + } else { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); + } + + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + writeBlock("A_initial_pos = A6p;"); + writeBlock("B_initial_pos = B6p;"); + writeBlock("C_initial_pos = C6p;"); + + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + writeBlock("A_delta = A_initial_pos - A6p;"); + writeBlock("B_delta = B_initial_pos - B6p;"); + writeBlock("C_delta = C_initial_pos - C6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + + +function createEndmacro() { + writeBlock("("); + if (useInverseTimeFeed) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + retracted = false; + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || + (getPreviousSection().isMultiAxis() != currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + + if (newWorkOffset || newWorkPlane) { + // retract to safe plane + writeRetract(Z); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (spindleSpeed < properties.minimumSpindleRPM) { + warning(localize("Spindle speed is below the minimum value.")); + } + if (spindleSpeed > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeRetract(Z); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock("Position 19, 2;"); +/* + if (properties._got5thAxis) { + writeBlock("Position 19, 2;"); + } else if (properties._got4thAxis && properties._got5thAxis) { + writeBlock("Position 21, 2;"); + } +*/ + writeRetract(Z); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + } else { + if (!retracted) { + writeRetract(Z); + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } + retracted = false; +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + var _spindleSpeed = spindleSpeed; + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(Math.max(_spindleSpeed, properties.minimumSpindleRPM)) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +// implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +// implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +// write a command to the cnc kernel without interpretation from the control +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCP && (properties._got4thAxis && properties._got5thAxis))) { + // non TCP + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); +} + +var currentFMode; + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + // get feed rate number + if (useInverseTimeFeed) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); + } else { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (properties.language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; +var coolantOff = undefined; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return undefined; // do not output coolant + } + var coolantCodes = getCoolantCodes(coolant); + if (Array.isArray(coolantCodes)) { + for (var c in coolantCodes) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + coolantCodes[c] + ", 0;"); // coolant off + } + return undefined; + } + return coolantCodes; +} + +function getCoolantCodes(coolant) { + if (!coolants) { + error(localize("Coolants have not been defined.")); + } + if (!coolantOff) { // use the default coolant off command when an 'off' value is not specified for the previous coolant mode + coolantOff = coolants.off; + } + + if (isProbeOperation()) { // avoid coolant output for probing + coolant = COOLANT_OFF; + } + + if (coolant == currentCoolantMode) { + return undefined; // coolant is already active + } + + var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line + if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF)) { + multipleCoolantBlocks.push(mFormat.format(coolantOff)); + } + + var m; + if (coolant == COOLANT_OFF) { + m = coolantOff; + coolantOff = coolants.off; + } + + switch (coolant) { + case COOLANT_FLOOD: + if (!coolants.flood) { + break; + } + m = coolants.flood.on; + coolantOff = coolants.flood.off; + break; + case COOLANT_THROUGH_TOOL: + if (!coolants.throughTool) { + break; + } + m = coolants.throughTool.on; + coolantOff = coolants.throughTool.off; + break; + case COOLANT_AIR: + if (!coolants.air) { + break; + } + m = coolants.air.on; + coolantOff = coolants.air.off; + break; + case COOLANT_AIR_THROUGH_TOOL: + if (!coolants.airThroughTool) { + break; + } + m = coolants.airThroughTool.on; + coolantOff = coolants.airThroughTool.off; + break; + case COOLANT_FLOOD_MIST: + if (!coolants.floodMist) { + break; + } + m = coolants.floodMist.on; + coolantOff = coolants.floodMist.off; + break; + case COOLANT_MIST: + if (!coolants.mist) { + break; + } + m = coolants.mist.on; + coolantOff = coolants.mist.off; + break; + case COOLANT_SUCTION: + if (!coolants.suction) { + break; + } + m = coolants.suction.on; + coolantOff = coolants.suction.off; + break; + case COOLANT_FLOOD_THROUGH_TOOL: + if (!coolants.floodThroughTool) { + break; + } + m = coolants.floodThroughTool.on; + coolantOff = coolants.floodThroughTool.off; + break; + } + + if (!m) { + onUnsupportedCoolant(coolant); + m = 9; + } + + if (m) { + if (Array.isArray(m)) { + for (var i in m) { + multipleCoolantBlocks.push(mFormat.format(m[i])); + } + } else { + multipleCoolantBlocks.push(mFormat.format(m)); + } + currentCoolantMode = coolant; + return multipleCoolantBlocks; // return the single formatted coolant value + } + return undefined; +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_OPTIONAL_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTimeFeed && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && properties.showOperationDialog != "disabled") { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +/** Output block to do safe retract and/or move to home position. */ +function writeRetract() { + if (arguments.length == 0) { + error(localize("No axis specified for writeRetract().")); + return; + } + var words = []; // store all retracted axes in an array + for (var i = 0; i < arguments.length; ++i) { + let instances = 0; // checks for duplicate retract calls + for (var j = 0; j < arguments.length; ++j) { + if (arguments[i] == arguments[j]) { + ++instances; + } + } + if (instances > 1) { // error if there are multiple retract calls for the same axis + error(localize("Cannot retract the same axis twice in one line")); + return; + } + switch (arguments[i]) { + case X: + words.push("X" + xyzFormat.format(machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : 0)); + break; + case Y: + words.push("Y" + xyzFormat.format(machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : 0)); + break; + case Z: + writeBlock(translate("Submacro") + " Retractzmax;"); + retracted = true; // specifies that the tool has been retracted to the safe plane + zOutput.reset(); + break; + default: + error(localize("Bad axis specified for writeRetract().")); + return; + } + } + if (words.length > 0) { + if (properties.useParkPosition) { + writeBlock("Park;"); + } + } +} + + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + properties.language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Initposition;"); + } + + // write jump to start operation + if (properties.showOperationDialog == "dropdown") { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // setCoolant(COOLANT_OFF); + + if (useRTCP && (properties._got4thAxis && properties._got5thAxis)) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeRetract(Z); + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + writeRetract(X, Y); +} diff --git a/datron next dispense.cps b/deprecated/datron next dispense.cps similarity index 97% rename from datron next dispense.cps rename to deprecated/datron next dispense.cps index 8131481..9f88bad 100644 --- a/datron next dispense.cps +++ b/deprecated/datron next dispense.cps @@ -1,2414 +1,2414 @@ -/** - Copyright (C) 2012-2018 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} -*/ - -description = "DATRON next"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 40783; - -longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; - -extension = "simpl"; -setCodePage("utf-8"); - -capabilities = CAPABILITY_JET; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(120); -allowHelicalMoves = true; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -const MachineType = { - NEO: 'NEO', - CUBE: 'Cube', - MX: 'MX' -} - - -// user-defined properties -properties = { - writeMachine : true, // write machine - showNotes : false, // specifies that operation notes should be output - useSmoothing : true, // specifies if smoothing should be used or not - useDynamic : true, // specifies using dynamic mode or not - machineType : MachineType.MX, // specifiees the DATRON machine type - useParkPosition : true, // specifies to use park position at the end of the program - writeToolTable : true, // write the table with the geometric tool informations - useSequences : true, // this use a sequence in the output format to perform on large files - useExternalSequencesFiles : false, // this property create one external sequence files for each operation - writeCoolantCommands : true, // disable the coolant commands in the file - useParametricFeed : true, // specifies that feed should be output using parameters - waitAfterOperation : false, // optional stop - got4thAxis: false, // specifies if the machine has a rotational 4th axis - got5thAxis: false, // activate the RTCP options - useSuction: false, // activate suction support - createThreadChamfer: false, // create a chamfer with the thread milling tool - preloadTool: false, //prepare a Tool for the DATROn tool assist - writePathOffset:true, //write the definition for the PathOffset variable for every Operation - useRtcp:false, - rampLength: 40, - rampZBindingDepth: 1, - useClosedContour:true, -}; - - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Specifies if smoothing should be used or not.", type:"boolean"}, - useDynamic: {title:"Dynamic mode", description:"Specifies the using of dynamic mode or not.", type:"boolean"}, - machineType:{title:"Machine type", description:"Specifies the DATRON machine type.", type:"MachineType"}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - writeToolTable: {title:"Write tool table", description:"Write a tool table containing geometric tool information.", group:0, type:"boolean"}, - useSequences: {title:"Use sequences", description:"If enables, sequences are used in the output format on large files.", type:"boolean"}, - useExternalSequencesFiles: {title:"Use external sequence files", description:"If enabled, an external sequence file is created for each operation.", type:"boolean"}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - waitAfterOperation: {title:"Wait after operation", description:"If enabled, an optional stop is outputted to pause after each operation.", type:"boolean"}, - got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, - got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with a DST.", type:"boolean"}, - useSuction: {title:"Use Suction", description:"Enable the suction for every operation.", type:"boolean"}, - createThreadChamfer: {title:"Create a Thread Chamfer",description:"create a chamfer with the thread milling tool"}, - preloadTool:{title:"Preload the next Tool", description:"Preload the next Tool in the DATRON Tool assist."}, - writePathOffset:{title:"Write Path Offset", description:"Write the PathOffset declaration."} -} - -var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); -var toolFormat = createFormat({decimals:0}); -var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); -var rpmFormat = createFormat({decimals:0, scale:1}); -var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); - -var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); -var feedOutput = createVariable({prefix:""}, feedFormat); - -var xOutput = createVariable({prefix:" X="}, xyzFormat); -var yOutput = createVariable({prefix:" Y="}, xyzFormat); -var zOutput = createVariable({prefix:" Z="}, xyzFormat); -var aOutput = createVariable({prefix:" A="}, abcFormat); -var bOutput = createVariable({prefix:" B="}, abcFormat); -var cOutput = createVariable({prefix:" C="}, abcFormat); - -var iOutput = createVariable({prefix:" dX=", force : true}, xyzFormat); -var jOutput = createVariable({prefix:" dY=", force : true}, xyzFormat); -var kOutput = createVariable({prefix:" dZ="}, xyzFormat); - -// fixed settings -var useDatronFeedCommand = false; // unsupported for now, keep false -var language = "de"; // specifies the language, replace with getLangId() -var spacingDepth = 0; -var spacingString = " "; -var spacing = "##########################################################"; - -// buffer for building up a program not serial created -var sequenceBuffer = new StringBuffer(); - -function NewOperation(operationCall){ - this.operationCall = operationCall; - this.operationProgram = new StringBuffer(); - this.operationProgram.append(""); -} -var currentOperation; -function NewSimPLProgram(){ - this.moduleName = new StringBuffer(); - this.measuringSystem = "Metric"; - this.toolDescriptionList = new Array(); - this.workpieceGeometry = ""; - this.sequenceList = new Array(); - this.usingList = new Array(); - this.externalUsermodules = new Array(); - this.globalVariableList = new Array(); - this.mainProgram = new StringBuffer(); - this.operationList = new Array(); -} - -var SimPLProgram = new NewSimPLProgram(); - -// collected state -var currentFeedValue = -1; -var optionalSection = false; -var activeMovements; // do not use by default -var currentFeedId; - -// format date + time -var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -function getSequenceName(section) { - var sequenceName = ""; - if (properties.useExternalSequencesFiles) { - sequenceName += FileSystem.getFilename(getOutputPath().substr(0, getOutputPath().lastIndexOf("."))) + "_"; - } - sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); - return sequenceName; -} - -function getFilename(){ - var filePath = getOutputPath(); - var filename = filePath.slice(filePath.lastIndexOf("\\")+1, filePath.lastIndexOf(".")); - return filename; -} - -function getOperationName(section) { - return "Operation_" + getOperationDescription(section); -} - -function capitalizeFirstLetter(text) { - return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); -} - -function getSpacing() { - var space = ""; - for (var i = 0; i < spacingDepth; i++) { - space += spacingString; - } - return space; -} - -/** - Redirect the output to an infinite number of buffers ;-) - works like a stack you can use many redirection levels and go back again -*/ -var writeRedirectionStack = new Array(); - -function SetWriteRedirection(redirectionbuffer){ - writeRedirectionStack.push(redirectionbuffer); -} - -function ResetWriteRedirection(){ - return writeRedirectionStack.pop(); -} - -/** - Writes the specified block. -*/ -function writeBlock(arguments) { - var text = getSpacing() + formatWords(arguments); - if (writeRedirectionStack.length == 0){ - writeWords(text); - } else { - writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); - } -} - -/** - Output a comment. -*/ -function writeComment(text) { - if (text) { - text = getSpacing() + "# " + text; - if (writeRedirectionStack.length == 0){ - writeln(text); - } else { - writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); - } - } -} - -var charMap = { - "\u00c4" : "Ae", - "\u00e4" : "ae", - "\u00dc" : "Ue", - "\u00fc" : "ue", - "\u00d6" : "Oe", - "\u00f6" : "oe", - "\u00df" : "ss", - "\u002d" : "_", - "\u0020" : "_" -}; - -/** Map specific chars. */ -function mapComment(text) { - text = formatVariable(text); - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); -} - -function onOpen() { - // note: setup your machine here - - // if (properties.got4thAxis && !properties.got5thAxis) { - // var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0}); - // machineConfiguration = new MachineConfiguration(aAxis); - // machineConfiguration.setVendor("DATRON"); - // machineConfiguration.setModel("NEO with A Axis"); - // machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); - // setMachineConfiguration(machineConfiguration); - // optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis - // } - - // // note: setup your machine here - // if (properties.got4thAxis && properties.got5thAxis) { - // var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0}); - // var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0}); - // machineConfiguration = new MachineConfiguration(aAxis,cAxis); - // machineConfiguration.setVendor("DATRON"); - // machineConfiguration.setModel("NEXT with DST"); - // machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); - // setMachineConfiguration(machineConfiguration); - // optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis - // } - - // if (!machineConfiguration.isMachineCoordinate(0)) { - // aOutput.disable(); - // } - // if (!machineConfiguration.isMachineCoordinate(1)) { - // bOutput.disable(); - // } - // if (!machineConfiguration.isMachineCoordinate(2)) { - // cOutput.disable(); - // } - - - // machineConfiguration = new MachineConfiguration(); - // machineConfiguration.setJet(true); - // machineConfiguration.setWire(true); - // setMachineConfiguration(machineConfiguration); - - // header of the main program - writeProgramHeader(); - spacingDepth -= 1; - ResetWriteRedirection(); - - // the rest of program main will be set at closing when all the code is analysed -} - -function getOperationDescription(section) { - // creates the name of the operation - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -function createToolVariables() { - var tools = getToolTable(); - var toolVariables = new Array(); - if (tools.getNumberOfTools() > 0 && !properties.writeToolTable) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - toolVariables.push(toolOutput.format(tool.number) + ":number"); - } - } - return toolVariables; -} - -function getNextTool(number) { - var currentSectionId = getCurrentSectionId(); - if (currentSectionId < 0) { - return null; - } - for (var i = currentSectionId + 1; i < getNumberOfSections(); ++i) { - var section = getSection(i); - var sectionTool = section.getTool(); - if (number != sectionTool.number) { - return sectionTool; // found next tool - } - } - return null; // not found -} - -// function createToolDescriptionTable() { -// if (!properties.writeToolTable) { -// return; -// } - -// var toolDescriptionArray = new Array(); -// var toolNameList = new Array(); -// var numberOfSections = getNumberOfSections(); -// for (var i = 0; i < numberOfSections; ++i) { -// var section = getSection(i); -// var tool = section.getTool(); -// if (tool.type != TOOL_PROBE) { -// var toolName = createToolName(tool); -// var toolProgrammed = createToolDescription(tool); -// if (toolNameList.indexOf(toolName) == -1) { -// toolNameList.push(toolName); -// toolDescriptionArray.push(toolProgrammed); -// } else { -// /* -// if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { -// error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + -// toolNameList.join("\r\n") + "#####################################\r\n"); -// } -// */ -// } -// } -// } - -// return toolDescriptionArray; -// } - -function createToolDescription(tool) { - var toolProgrammed = "@ ToolDescription : " + - "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + - "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + - "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + - "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + - "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + - "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + - "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + - "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + - "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + - "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + - "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + - "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + - "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + - "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + - "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + - " @"; - return toolProgrammed; -} - -/** - Generate the logical tool name for the assignment table of used tools. -*/ -// function createToolName(tool) { -// var toolName = toolFormat.format(tool.number); -// toolName += "_" + translateToolType(tool.type); -// if (tool.comment) { -// toolName += "_" + tool.comment; -// } -// if (tool.diameter) { -// toolName += "_D" + tool.diameter; -// } -// var description = tool.getDescription(); -// if (description) { -// toolName += "_" + description; -// } -// toolName = formatVariable(toolName); -// return toolName; -// } - -/** - Translate HSM tools to Datron tool categories. -*/ -function translateToolType(toolType) { - - var datronCategoryName = ""; - - toolCategory = toolType; - switch (toolType) { - case TOOL_UNSPECIFIED: - datronCategoryName = "Unspecified"; - break; - case TOOL_DRILL: - datronCategoryName = "Drill"; - break; - case TOOL_DRILL_CENTER: - datronCategoryName = "DrillCenter"; - break; - case TOOL_DRILL_SPOT: - datronCategoryName = "DrillSpot"; - break; - case TOOL_DRILL_BLOCK: - datronCategoryName = "DrillBlock"; - break; - case TOOL_MILLING_END_FLAT: - datronCategoryName = "MillingEndFlat"; - break; - case TOOL_MILLING_END_BALL: - datronCategoryName = "MillingEndBall"; - break; - case TOOL_MILLING_END_BULLNOSE: - datronCategoryName = "MillingEndBullnose"; - break; - case TOOL_MILLING_CHAMFER: - datronCategoryName = "Graver"; - break; - case TOOL_MILLING_FACE: - datronCategoryName = "MillingFace"; - break; - case TOOL_MILLING_SLOT: - datronCategoryName = "MillingSlot"; - break; - case TOOL_MILLING_RADIUS: - datronCategoryName = "MillingRadius"; - break; - case TOOL_MILLING_DOVETAIL: - datronCategoryName = "MillingDovetail"; - break; - case TOOL_MILLING_TAPERED: - datronCategoryName = "MillingTapered"; - break; - case TOOL_MILLING_LOLLIPOP: - datronCategoryName = "MillingLollipop"; - break; - case TOOL_TAP_RIGHT_HAND: - datronCategoryName = "TapRightHand"; - break; - case TOOL_TAP_LEFT_HAND: - datronCategoryName = "TapLeftHand"; - break; - case TOOL_REAMER: - datronCategoryName = "Reamer"; - break; - case TOOL_BORING_BAR: - datronCategoryName = "BoringBar"; - break; - case TOOL_COUNTER_BORE: - datronCategoryName = "CounterBore"; - break; - case TOOL_COUNTER_SINK: - datronCategoryName = "CounterSink"; - break; - case TOOL_HOLDER_ONLY: - datronCategoryName = "HolderOnly"; - break; - case TOOL_PROBE: - datronCategoryName = "XYZSensor"; - break; - default: - datronCategoryName = "Unspecified"; - } - return datronCategoryName; -} - -function writeProgramHeader() { - // write creation Date - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - SetWriteRedirection(SimPLProgram.moduleName); - writeComment("!File ; generated at " + date + " - " + time); - if (programComment) { - writeComment(formatComment(programComment)); - } - writeComment("####################### "); - writeComment(" DATRON NEXT "); - writeComment(" Dispensing Program"); - writeComment(""); - writeComment(" | |"); - writeComment(" | |"); - writeComment(" ==> \\ /"); - writeComment(" ||"); - writeComment(" ||"); - writeComment(" ==========="); - writeComment("#######################"); - writeBlock(" "); - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - - writeBlock("module " + "CamGeneratedDispensingModule"); - writeBlock(" "); - - writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); - ResetWriteRedirection(); - - // set the table of used tools in the header of the program - //SimPLProgram.toolDescriptionList = createToolDescriptionTable(); - - // set the workpiece information - SimPLProgram.workpieceGeometry = writeWorkpiece(); - - // set the sequence header in the program file - if (properties.useSequences) { - var sequences = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (!isProbeOperation(section)) { - sequences.push("sequence " + getSequenceName(section)); - } - } - if (properties.useExternalSequencesFiles) { - writeBlock("@ EmbeddedSequences = false @"); - } - - SimPLProgram.sequenceList = sequences; - } - - // set usings - SimPLProgram.usingList.push("using Base"); - SimPLProgram.usingList.push("using DispensingCycles"); - - if ((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ - SimPLProgram.usingList.push("using Rtcp"); - } - if (properties.waitAfterOperation) { - SimPLProgram.usingList.push("import System"); - } - - // set paramtric feed variables - //var feedDeclaration = new Array(); - var currentMovements = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (properties.useParametricFeed && (!useDatronFeedCommand)) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(FeedContextTranslator(feedContext.description)); - if (SimPLProgram.globalVariableList.indexOf(feedDescription + ":number") == -1) { - SimPLProgram.globalVariableList.push(feedDescription + ":number"); - } - } - } - } - - // if (!useDatronFeedCommand) { - // if (feedDeclaration != 0) { - // SimPLProgram.globalVariableList.push(feedDeclaration); - // } - // } - SetWriteRedirection(SimPLProgram.mainProgram); - writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); - spacingDepth += 1; - writeBlock("Absolute"); - - writeBlock("DispensingTechnology P=1 D=0.025"); - writeBlock("DispensingVolume crossSection=2"); - writeBlock(""); - - - // set the parameter tool table - SimPLProgram.globalVariableList.push(createToolVariables()); - - if (!properties.writeToolTable) { - var tools = getToolTable(); - writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + dimensionFormat.format(tool.diameter) + " " + - "L2:" + dimensionFormat.format(tool.fluteLength) + " " + - "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + - "ProductID:" + formatComment(tool.productId); - writeBlock(toolAsigment); - } - writeBlock(" "); - } - } - ResetWriteRedirection(); -} - - -function writeWorkpiece() { - var workpieceString = new StringBuffer(); - SetWriteRedirection(workpieceString); - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - - writeBlock("# Workpiece dimensions"); - writeBlock( - "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z)); - writeBlock( - "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z)); - writeBlock( - "# Part size X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z)); - - writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + - "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + - " @"); - ResetWriteRedirection(); - return workpieceString; -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, datronFeedName, feed) { - this.id = id; - this.description = description; - this.datronFeedName = datronFeedName; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; - } -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - if (useDatronFeedCommand) { - return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); - } else { - return ("Feed=" + formatVariable(FeedContextTranslator( feedContext.description))); - } - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return "Feed=" + feedFormat.format(f); - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - var id = 0; - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - addFeedContext(feedContext, activeFeeds); - } - ++id; - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - - // this part allows us to use feedContext also for the cycles - if (hasParameter("operation:cycleType")) { - var cycleType = getParameter("operation:cycleType"); - if (hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - - switch (cycleType) { - case "thread-milling": - if (hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:ramp")) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:finish_cutting")) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - break; - case "bore-milling": - if (section.hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (section.hasParameter("movement:ramp")) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:finish_cutting")) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - break; - } - } - - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -/** Check that all elements are only one time in the result list. */ -function addFeedContext(feedContext, activeFeeds) { - if (activeFeeds.indexOf(feedContext) == -1) { - activeFeeds.push(feedContext); - } -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - forceWorkPlane(); // always need the new workPlane - forceABC(); - if((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ - writeBlock("MoveZToTopPosition"); - }else{ - writeBlock("MoveToSafetyPosition"); - } - writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); - - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function onSection() { - // this is the container that hold all operation informations... - currentOperation = new NewOperation(getOperationName(currentSection)) - SetWriteRedirection(currentOperation.operationProgram); - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - var tool = currentSection.getTool(); - - if (!isProbeOperation(currentSection)) { - writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); - } - - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = currentSection.getGlobalZRange(); - var number = tool.number; - zRange.expandToRange(currentSection.getGlobalZRange()); - writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); - } - } - // create sub program - writeBlock("program " + getOperationName(currentSection)); - spacingDepth += 1; - - if (passThrough) { - var joinString = "\r\n" + getSpacing(); - var passThroughString = passThrough.join(joinString); - if (passThroughString != "") { - writeBlock(passThroughString); - } - passThrough = []; - } - - // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. - writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); - var operationTolerance = tolerance; - if (hasParameter("operation:tolerance")) { - if (operationTolerance < getParameter("operation:tolerance")) { - operationTolerance = getParameter("operation:tolerance"); - } - } - - //load the matching workOffset - var workOffset = currentSection.getWorkOffset(); - if (workOffset != 0) { - writeBlock("LoadWcs name=\"" + workOffset +"\""); - } - - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); - } else - { - writeBlock("Smoothing Off"); - } - - if (properties.useDynamic) { - var dynamic = 5; - // set machine type specific dynamic sets - /* - switch(properties.machineType){ - case 'NEO': - dynamic =5; - break; - case 'MX': - case 'CUBE': - if (operationTolerance <= (unit == MM ? 0.04 : (0.04/25.4))) { - dynamic = 4; - } - if (operationTolerance <= (unit == MM ? 0.02 : (0.02/25.4))) { - dynamic = 3; - } - if (operationTolerance <= (unit == MM ? 0.005 : (0.005/25.4))) { - dynamic = 2; - } - if (operationTolerance <= (unit == MM ? 0.003 : (0.003/25.4))) { - dynamic = 1; - } - break; - } - */ - writeBlock("Dynamic = " + dynamic); - } - if (properties.waitAfterOperation) { - showWaitDialog(); - } - - if (machineConfiguration.isMultiAxisConfiguration()) { - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - if((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ - writeBlock("Rtcp On"); - } - writeBlock("MoveToSafetyPosition"); - writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); - } else { - forceWorkPlane(); - var abc = getWorkPlaneMachineABC(currentSection.workPlane); - - setWorkPlane(abc); - if((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ - writeBlock("Rtcp On"); - } - } - } else { - // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - error("\r\n_________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| Tool orientation detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis, otherwise you can only post|" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|________________________________________|\r\n"); - return; - } - setRotation(remaining); - } - - forceAny(); - - if (properties.showNotes && currentSection.hasParameter("notes")) { - var notes = currentSection.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - - var clearance = getFramePosition(currentSection.getInitialPosition()).z; - writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); - - // radius Compensation - var compensationType - if(hasParameter('operation:compensationType')){ - compensationType = getParameter('operation:compensationType'); - } else { - compensationType = 'computer'; - } - - var wearCompensation - if(hasParameter('operation:compensationDeltaRadius')){ - wearCompensation = getParameter('operation:compensationDeltaRadius'); - } else { - wearCompensation = 0; - } - - if(properties.writePathOffset){ - switch( compensationType){ - case 'computer': - break; - case 'control': - writeBlock("PathOffset = 0") - break; - case 'wear': - - writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); - break; - case 'inverseWear': - writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation * -1)); - break; - } - } - - if (!isProbeOperation(currentSection)) { - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - - // // tool changer command - // if (properties.writeToolTable) { - // writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + - // " newRpm=" + rpmFormat.format(spindleSpeed) + - // " skipRestoring" - // ); - // } else { - // writeBlock("Tool = " + toolOutput.format(tool.number) + - // " newRpm=" + rpmFormat.format(spindleSpeed) + - // " skipRestoring" - // ); - // } - - // //preload the next tool for the Datron tool assist - // if(properties.preloadTool){ - // var nextTool = getNextTool(tool.number); - // if(nextTool){ - // if (properties.writeToolTable) { - // writeBlock("ProvideTool name=" + "\"" + createToolName(nextTool) + "\""); - // } else { - // writeBlock("ProvideTool = " + toolOutput.format(nextTool.number)); - // } - // } - // } - - - // write dispense specific paramters - SimPLProgram.globalVariableList.push("rampLength:number"); - SimPLProgram.globalVariableList.push("zBindingDepth:number"); - - writeBlock("rampLength = " + properties.rampLength); - writeBlock("zBindingDepth = " + properties.rampZBindingDepth); - - - // set the current feed - // replace by the default feed command - if (properties.useParametricFeed && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - activeFeeds = initializeActiveFeeds(currentSection); - if (useDatronFeedCommand) { - var datronFeedParameter = new Array(); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var datronFeedCommand = { - name : feedContext.datronFeedName, - feed : feedFormat.format(feedContext.feed) - }; -/*eslint-disable*/ - var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); -/*eslint-enable*/ - if (indexOfFeedContext == -1) { - datronFeedParameter.push(datronFeedCommand); - } else { - var existingFeedContext = datronFeedParameter[indexOfFeedContext]; - if (existingFeedContext.feed < datronFeedCommand.feed) { - existingFeedContext.feed = datronFeedCommand.feed; - } - } - } - var datronFeedCommand = "SetFeedTechnology"; - for (var i = 0; i < datronFeedParameter.length; i++) { - datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; - } - writeBlock(datronFeedCommand); - - } else { - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(FeedContextTranslator(feedContext.description)) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); - } - } - } - } - - // parameter for the sequences - var sequenceParamter = new Array(); - - if (hasParameter("operation:cycleType")) { - - //Reset all movements to suppress older entries... - activeMovements = new Array(); - - var cycleType = getParameter("operation:cycleType"); - writeComment("Parameter " + cycleType + " cycle"); - - switch (cycleType) { - case "thread-milling": - writeBlock("SetFeedTechnology" + " ramp=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:finish_cutting"))); - var diameter = currentSection.getParameter("diameter"); - var pitch = currentSection.getParameter("pitch"); - var finishing = currentSection.getParameter("stepover"); - - writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); - sequenceParamter.push("nominalDiameter=nominalDiameter"); - writeBlock("pitch=" + xyzFormat.format(pitch)); - sequenceParamter.push("pitch=pitch"); - if (xyzFormat.isSignificant(finishing)) { - writeBlock("finishing=" + xyzFormat.format(finishing)); - sequenceParamter.push("finishing=finishing"); - } else { - sequenceParamter.push("finishing=0"); - } -/* - writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); - sequenceParamter.push('threadName=threadName'); - writeBlock("threading = " + currentSection.getParameter("threading")); - sequenceParamter.push("threading=threading"); - - TAG: den Standard auch mit Imperial unterstuezten - sequenceParamter.push("threadStandard=ThreadStandards.Metric"); - sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); - sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); - sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); - writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); - sequenceParamter.push("direction=direction"); - writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); - sequenceParamter.push("repeatPass=repeatPass"); -*/ - break; - case "bore-milling": - writeBlock("SetFeedTechnology roughing=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:cutting"))); - writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); - sequenceParamter.push("diameter=diameter"); - - writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); - sequenceParamter.push("infeedZ=infeedZ"); - writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); - sequenceParamter.push("repeatPass=repeatPass"); - break; - case "drilling": - writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge"))); - break; - case "chip-breaking": - writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge")) + " roughing=" + feedFormat.format(getParameter("movement:cutting"))); - writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); - sequenceParamter.push("infeedZ=infeedZ"); - break; - } - } - - if (properties.useSequences && !isProbeOperation(currentSection)) { - sequenceParamter.push("rampLength=rampLength"); - sequenceParamter.push("zBindingDepth=zBindingDepth"); - - // call sequence - if (properties.useParametricFeed && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - activeFeeds = initializeActiveFeeds(currentSection); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - sequenceParamter.push(formatVariable(FeedContextTranslator(feedContext.description)) + "=" + formatVariable(FeedContextTranslator(feedContext.description))); - } - } - var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); - writeBlock(currentSectionCall); - - // write sequence - var currentSequenceName = getSequenceName(currentSection); - if (properties.useExternalSequencesFiles) { - spacingDepth -= 1; - var filename = getOutputPath(); - //sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; - sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; - sequenceFilePath += currentSequenceName + ".seq"; - redirectToFile(sequenceFilePath); - } else { - SetWriteRedirection(sequenceBuffer); - writeBlock(" "); - // TAG: modify parameter - spacingDepth -= 1; - writeBlock("$$$ " + currentSequenceName); - } - } - - if (!isProbeOperation(currentSection)) { - writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); - } else { - writeBlock("Spindle Off"); - writeBlock("PrepareXyzSensor"); - } - - // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); - - writeBlock("PrePositioning" + xyz); - - // adds support for suction - if(properties.useSuction){ - writeBlock("Suction On"); - } - -} - -function FeedContextTranslator(feed){ - if(feed= "Cutting") - return "dispenseFeed"; - else - return feed; - -} - -function showWaitDialog(operationName) { - writeBlock("showWaitDialog"); -} - -function writeWaitProgram() { - writeBlock("#Show the wait dialog for the next operation"); - writeBlock("program showWaitDialog optional operationName:string"); - writeBlock(""); - writeBlock(" if not operationName hasvalue "); - writeBlock(" operationName =" + "\"" + "\""); - writeBlock(" endif"); - writeBlock(""); - writeBlock(" messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName "); - writeBlock(" dialogResult = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel"); - writeBlock(" if dialogResult == System::DialogResult.Cancel"); - writeBlock(" exit"); - writeBlock(" endif"); - writeBlock(""); - writeBlock("endprogram"); -} - -function onDwell(seconds) { - writeBlock("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); -} - -function onSpindleSpeed(spindleSpeed) { - // writeBlock("Rpm=" + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed)); - writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(x, y, z) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock("Rapid" + xyz); - forceFeed(); - } -} - -function onPrePositioning(x, y, z) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock("PrePositioning" + xyz); - forceFeed(); - } -} - -function onLinear(x, y, z, feed) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - var f = getFeed(feed); - - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - var d = tool.diameterOffset; - if (d > 99) { - warning(localize("The diameter offset exceeds the maximum value.")); - } - // TAG: um die Ebenen kuemmern - // writeBlock(gPlaneModal.format(17)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock("ToolCompensation Left"); - writeBlock("PathCorrection Left"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock("ToolCompensation Right"); - writeBlock("PathCorrection Right"); - break; - case RADIUS_COMPENSATION_OFF: - writeBlock("ToolCompensation Off"); - writeBlock("PathCorrection Off"); - break; - } - } - - if (xyz) { - if (f) { - writeBlock(f); - } - writeBlock("Line" + xyz); - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - // one of X/Y and I/J are required and likewise - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - - if (pendingRadiusCompensation >= 0) { - error(localize("radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (isHelical()) { - linearize(tolerance); - return; - } - // TAG: are 360deg arcs supported - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } else { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - yOutput.format(y) + - zOutput.format(z) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = aOutput.format(_a); - var b = bOutput.format(_b); - var c = cOutput.format(_c); - - forceABC(); - var xyzabc = x + y + z + a + b + c; - writeBlock("Rapid" + xyzabc); - forceFeed(); -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = aOutput.format(_a); - var b = bOutput.format(_b); - var c = cOutput.format(_c); - var f = getFeed(feed); - - writeBlock(f); - if (x || y || z || a || b || c) { - var xyzabc = x + y + z + a + b + c; - writeBlock("Line" + xyzabc); - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onRewindMachine(a, b, c) { - writeBlock("MoveToSafetyPosition"); - var abc = aOutput.format(a) + bOutput.format(b) + cOutput.format(c); - writeBlock("Line" + abc); -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - return; - // if (properties.writeCoolantCommands) { - // if (coolant == COOLANT_OFF) { - // writeBlock("SpraySystem Off"); - // currentCoolantMode = COOLANT_OFF; - // return; - // } - - // switch (coolant) { - // case COOLANT_FLOOD: - // case COOLANT_MIST: - // writeBlock("SprayTechnology External"); - // writeBlock("Coolant Alcohol"); - // break; - // case COOLANT_AIR: - // writeBlock("SprayTechnology External"); - // writeBlock("Coolant Air"); - // break; - // case COOLANT_THROUGH_TOOL: - // writeBlock("SprayTechnology Internal"); - // writeBlock("Coolant Alcohol"); - // break; - // case COOLANT_AIR_THROUGH_TOOL: - // writeBlock("SprayTechnology Internal"); - // writeBlock("Coolant Air"); - // break; - - // default: - // onUnsupportedCoolant(coolant); - // } - // writeBlock("SpraySystem On"); - // currentCoolantMode = coolant; - // } -} - -var isInsideProgramDeclaration = false; -var directNcOperation; -function ParseManualNc(text){ - - var modulePattern = new RegExp("\.*(using|import)"); - var isModuleImport = modulePattern.test(text); - if(isModuleImport){ - SimPLProgram.usingList.push(text); - return; - } - - var programPattern = /(?:\s*program\s+)(\w+)/; - var isProgramDeclaration = programPattern.test(text); - - if(isProgramDeclaration){ - var subProgramName = programPattern.exec(text); - if(subProgramName == undefined) return; - directNcOperation = {operationCall:subProgramName[1],operationProgram: new StringBuffer()}; - SimPLProgram.operationList.push(directNcOperation); - isInsideProgramDeclaration = true; - } - - var isEndProgram = /\s*endprogram/.test(text); - if(isEndProgram){ - isInsideProgramDeclaration = false; - directNcOperation.operationProgram.append(text + "\r\n"); - return; - } - - if (isInsideProgramDeclaration){ - directNcOperation.operationProgram.append(text + "\r\n"); - return; - } - - return text; -} - -function onManualNC(command, value) { - switch (command) { - case 42: // Manual NC enumeration code ??? - value = ParseManualNc(value); - break; - case 40: // Comment - value = "# " + value; - break; - case 41: //wait - value = "Sleep seconds=" + value; - break; - case COMMAND_COOLANT_OFF: - value = "SpraySystem Off"; - break; - case COMMAND_COOLANT_ON: - value = "SpraySystem On"; - break; - case COMMAND_STOP: - value = "break"; - break; - case COMMAND_START_SPINDLE: - value = "Spindle On"; - break; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - value = "ChipConveyor On"; - break; - case COMMAND_STOP_CHIP_TRANSPORT: - value = "ChipConveyor Off"; - break; - case COMMAND_OPEN_DOOR: //open door - value = "ReleaseDoor"; - break; - case COMMAND_CLOSE_DOOR: //close door not needed - return; - case COMMAND_CALIBRATE: //calibrate - value = "# calibration currently not supported!"; - break; - case COMMAND_VERIFY: // check part - value = 'Dialog message="Please check workpiece!" Ok Cancel caption="Cam generated dialog"' - break; - case COMMAND_CLEAN: // clean part - value = 'Dialog message="Please clean workpiece!" Ok Cancel caption="Cam generated dialog"' - break; - case 43: // action no idea for what has a paramter - return; - //value = "# Action currently not supported!" - //break; - case 44: // print message - // value = 'Dialog message="' + value + '" Ok Cancel caption="Cam generated dialog"' - SimPLProgram.usingList.push('using File'); - SimPLProgram.usingList.push('using DateTimeModule') - var message = (' value=(GetNow + "\t' + value + '")') - value = 'FileWriteLine filename="' + getFilename() + '.log"' + message; - break; - case 46: // show message - value = 'StatusMessage message="' + value + '"'; - break; - case COMMAND_ALARM: // alarm - value = 'Dialog message="Alarm!" Ok Cancel caption="Cam generated dialog"' - break; - case COMMAND_ALERT: // alarm - value = 'Dialog message="Warning!" Ok Cancel caption="Cam generated dialog"' - break; - case COMMAND_BREAK_CONTROL: - value = "MeasureToolLength" - break; - case COMMAND_TOOL_MEASURE: - value = "MeasureToolLength" - break; - case COMMAND_OPTIONAL_STOP: - value = "OptionalBreak"; - break; - case 45: //call subprogram - var subprogramName = "SubProgram_" + SimPLProgram.externalUsermodules.length; - SimPLProgram.externalUsermodules.push('usermodule ' + subprogramName + '="' + value + '"'); - value = subprogramName; - break; - } - - if(value != undefined){ - var operation = {operationCall: value, operationProgram:""} - SimPLProgram.operationList.push(operation); - } -} - -var mapCommand = {}; - -var passThrough = new Array(); -function onPassThrough(text) { - passThrough.push(text); -} - -function onCommand(command) { - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - if(properties.useClosedContour){ - if(command == COMMAND_POWER_ON ){ - writeBlock("BeginClosedContour rampLength=rampLength zBindingDepth=zBindingDepth"); - } - if(command == COMMAND_POWER_OFF ){ - writeBlock("EndClosedContour"); - } - }else{ - if(command == COMMAND_POWER_ON ){ - writeBlock("DispensingPump On"); - } - if(command == COMMAND_POWER_OFF ){ - writeBlock("DispensingPump Off"); - } - } - - // onUnsupportedCommand(command); - } -} - -function onCycle() { -} - -function onCycleEnd() { -} - -function isProbeOperation(section) { - return (section.hasParameter("operation-strategy") && section.getParameter("operation-strategy") == "probe"); -} - -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - var feedString = feedOutput.format(cycle.feedrate); - - if (isProbeOperation(currentSection)) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } - - var startPositionOffset = cycle.probeClearance + tool.cornerRadius; - } - - switch (cycleType) { - case "bore-milling": - for (var i = 0; i <= cycle.repeatPass; ++i) { - forceXYZ(); - onRapid(x, y, cycle.clearance); - boreMilling(cycle); - onRapid(x, y, cycle.clearance); - } - break; - case "thread-milling": - for (var i = 0; i <= cycle.repeatPass; ++i) { - forceXYZ(); - onRapid(x, y, cycle.clearance); - threadMilling(cycle); - onRapid(x, y, cycle.clearance); - } - break; - case "drilling": - forceXYZ(); - onRapid(x, y, cycle.clearance); - drilling(cycle); - onRapid(x, y, cycle.clearance); - break; -/* - case "chip-breaking": - forceXYZ(); - onRapid(x, y, null); - onRapid(x, y, cycle.retract); - chipBreaking(cycle); - onRapid(x, y, cycle.clearance); - break; -*/ - - case "tapping": - case "left-tapping": - case "right-tapping": - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceXYZ(); - onRapid(x, y, cycle.clearance); - tapping(cycle); - onRapid(x, y, cycle.clearance); - break; - case "probing-x": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - break; - case "probing-y": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - break; - case "probing-z": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); - - var measureString = "SurfaceMeasure "; - measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); - writeBlock(measureString); - break; - case "probing-x-wall": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " YAligned"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-y-wall": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " XAligned"; - measureString += " skipZMeasure"; - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-x-channel": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " YAligned"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-x-channel-with-island": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " YAligned"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-y-channel": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " XAligned"; - measureString += " skipZMeasure"; - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-y-channel-with-island": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " XAligned"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-boss": - var measureString = "CircleMeasure"; - measureString += " diameter=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-hole": - var measureString = "CircleMeasure"; - measureString += " diameter=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-hole-with-island": - var measureString = "CircleMeasure"; - measureString += " diameter=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-boss": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + cycle.width1; - measureString += " dimensionY=" + cycle.width2; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " Center"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-hole": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + cycle.width1; - measureString += " dimensionY=" + cycle.width2; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " Center"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-hole-with-island": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + cycle.width1; - measureString += " dimensionY=" + cycle.width2; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " Center"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-inner-corner": - var probingDepth = (z - cycle.depth + tool.cornerRadius); - var measureString = "EdgeMeasure "; - - zOutput.reset(); - onRapid(x, y, cycle.stock); - onLinear(x, y, probingDepth, cycle.feedrate); - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - - forceXYZ(); - //zOutput.reset(); - onRapid(x, y, cycle.stock); - onLinear(x, y, probingDepth, cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; - // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; - - // var orientation = "" - // if (!isXNeagtive && !isYNeagtive) orientation = "BackRight"; - // if (isXNeagtive && !isYNeagtive) orientation = "BackLeft"; - // if (!isXNeagtive && isYNeagtive) orientation = "FrontRight"; - // if (isXNeagtive && isYNeagtive) orientation = "FrontLeft"; - - // var measureString = "CornerMeasure"; - // measureString += " " + orientation; - // measureString += " Inside"; - // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " forceSafeHeight" - // measureString += " skipZMeasure"; - // measureString += " originXShift=" + xyzFormat.format(-x); - // measureString += " originYShift=" + xyzFormat.format(-y); - // writeBlock(measureString); - break; - case "probing-xy-outer-corner": - var probingDepth = (z - cycle.depth + tool.cornerRadius); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var measureString = "EdgeMeasure "; - - zOutput.reset(); - onRapid(x, y, probingDepth); - onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - forceXYZ(); - onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); - onLinear(x, y, probingDepth, cycle.feedrate); - //forceXYZ(); - //zOutput.reset(); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - forceXYZ(); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - onLinear(x, y, probingDepth, cycle.feedrate); - - // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; - // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; - - // var orientation = "" - // if (!isXNeagtive && !isYNeagtive) orientation = "FrontLeft"; - // if (isXNeagtive && !isYNeagtive) orientation = "FrontRight"; - // if (!isXNeagtive && isYNeagtive) orientation = "BackLeft"; - // if (isXNeagtive && isYNeagtive) orientation = "BackRight"; - - // var measureString = "CornerMeasure"; - // measureString += " " + orientation; - // measureString += " Outside"; - // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " forceSafeHeight" - // measureString += " skipZMeasure"; - // measureString += " originXShift=" + xyzFormat.format(-x); - // measureString += " originYShift=" + xyzFormat.format(-y); - // writeBlock(measureString); - break; - case "probing-x-plane-angle": - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - // var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - // var touchPositionX2 = touchPositionX1; - // writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - // writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - // writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - // writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - // writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - // var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - // var touchPositionY2 = touchPositionY1; - // writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - // writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - // writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - // writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - // writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - return; - } - - // save probing result in defined wcs - if(currentSection.workOffset != null){ - writeBlock('SaveWcs name="' + currentSection.workOffset + '"'); - } - - return; -} - -function drilling(cycle) { - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - boreCommandString.push("Drill"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - writeBlock(boreCommandString.join(" ")); -} - -function chipBreaking(cycle) { - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - boreCommandString.push("Drill"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - boreCommandString.push("infeedZ=infeedZ"); - writeBlock(boreCommandString.join(" ")); -} - -function boreMilling(cycle) { - if (cycle.numberOfSteps > 2) { - error("Only 2 steps are allowed for bore-milling."); - } - - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - boreCommandString.push("DrillMilling"); - boreCommandString.push("diameter=diameter"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("infeedZ=infeedZ"); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - - if (cycle.numberOfSteps == 2) { - var xycleaning = cycle.stepover; - var maxzdepthperstep = tool.fluteLength * 0.8; - boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); - boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); - } - var bottomcleaning = 0; - // finishingZ = 1; - writeBlock(boreCommandString.join(" ")); -} - -function threadMilling(cycle) { - var threadString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - threadString.push("SpecialThread"); - // threadString.push('threadName=threadName'); - threadString.push("nominalDiameter=nominalDiameter"); - threadString.push("pitch=pitch"); - threadString.push("depth=" + depth); - threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - // threadString.push("threadStandard=threadStandard"); - if(properties.createThreadChamfer){ - threadString.push("Deburring"); - } - // ; - // threadString.push("insideOutside=ThreadMillingSide.Inside"); - threadString.push("finishing=finishing"); - if (cycle.threading == "left") { - threadString.push("direction=ThreadMillingDirection.LeftHandThread"); - } else { - threadString.push("direction=ThreadMillingDirection.RightHandThread"); - } - writeBlock(threadString.join(" ")); -} - -function tapping(cycle) { - var tappingString = new Array(); - var depth = xyzFormat.format(cycle.depth); - tappingString.push("ThreadCutting"); - tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); - tappingString.push("depth=" + depth); - tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); - if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { - tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); - } - if (tool.type == TOOL_TAP_LEFT_HAND) { - tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); - } else { - tappingString.push("direction=ThreadMillingDirection.RightHandThread"); - } - writeBlock(tappingString.join(" ")); -} - -function formatCycleTime(cycleTime) { - // cycleTime = cycleTime + 0.5; // round up - var seconds = cycleTime % 60 | 0; - var minutes = ((cycleTime - seconds)/60 | 0) % 60; - var hours = (cycleTime - minutes * 60 - seconds)/(60 * 60) | 0; - if (hours > 0) { - return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); - } else if (minutes > 0) { - return subst(localize("%1m:%2s"), minutes, seconds); - } else { - return subst(localize("%1s"), seconds); - } -} - -function dump(name, _arguments) { - var result = getCurrentRecordId() + ": " + name + "("; - for (var i = 0; i < _arguments.length; ++i) { - if (i > 0) { - result += ", "; - } - if (typeof _arguments[i] == "string") { - result += "'" + _arguments[i] + "'"; - } else { - result += _arguments[i]; - } - } - result += ")"; - writeln(result); -} - -function onSectionEnd() { - writeBlock("ToolCompensation Off"); - writeBlock("PathCorrection Off"); - if (currentSection.isMultiAxis && (properties.got4thAxis || properties.got5thAxis) && properties.useRtcp){ - writeBlock("Rtcp Off"); - } - - // adds support for suction - if(properties.useSuction){ - writeBlock("Suction Off"); - } - - if (properties.useSequences && !isProbeOperation(currentSection)) { - if (!properties.useExternalSequencesFiles) { - ResetWriteRedirection(); - } - spacingDepth += 1; - } - - - writeBlock("EndBlock"); - - spacingDepth -= 1; - - writeBlock("endprogram " + "# " + getOperationName(currentSection)); - ResetWriteRedirection(); - SimPLProgram.operationList.push(currentOperation); - forceAny(); -} - -function onClose() { - - if (properties.waitAfterOperation) { - writeWaitProgram(); - } - - writeBlock(SimPLProgram.moduleName); - writeBlock(""); - writeBlock(SimPLProgram.toolDescriptionList.join("\r\n") ); - writeBlock(""); - writeBlock(SimPLProgram.workpieceGeometry); - writeBlock(""); - writeBlock(SimPLProgram.sequenceList.join("\r\n") ); - writeBlock(""); - writeBlock(SimPLProgram.usingList.join("\r\n") ); - writeBlock(""); - writeBlock(SimPLProgram.externalUsermodules.join("\r\n")); - writeBlock(""); - writeBlock(SimPLProgram.globalVariableList.join("\r\n") ); - writeBlock(""); - - finishMainProgram(); - writeBlock(SimPLProgram.mainProgram); - writeBlock(""); - - SimPLProgram.operationList.forEach(function (operation){ - if(operation != undefined){ - writeBlock(operation.operationProgram); - } - }) - - writeBlock("end"); - - if (properties.useSequences && !properties.useExternalSequencesFiles) { - writeComment(spacing); - writeBlock(sequenceBuffer.toString()); - } -} - -// after all the oiperation calls are set close the main program with all the calls -function finishMainProgram(){ - // write the main program footer - SetWriteRedirection(SimPLProgram.mainProgram); - spacingDepth += 1; - - // write all subprogram calls in the main Program - SimPLProgram.operationList.forEach(function(operation){ - if(operation!=undefined){ - writeBlock(operation.operationCall); - } - - }) - - //writeBlock("SpraySystem Off"); - //writeBlock("Spindle Off"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - if (properties.useParkPosition) { - writeBlock("MoveToParkPosition"); - } else { - writeBlock("MoveToSafetyPosition"); - zOutput.reset(); - } - - spacingDepth -= 1; - writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); - ResetWriteRedirection(); -} - - +/** + Copyright (C) 2012-2018 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} +*/ + +description = "DATRON next"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 40783; + +longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; + +extension = "simpl"; +setCodePage("utf-8"); + +capabilities = CAPABILITY_JET; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = true; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +const MachineType = { + NEO: 'NEO', + CUBE: 'Cube', + MX: 'MX' +} + + +// user-defined properties +properties = { + writeMachine : true, // write machine + showNotes : false, // specifies that operation notes should be output + useSmoothing : true, // specifies if smoothing should be used or not + useDynamic : true, // specifies using dynamic mode or not + machineType : MachineType.MX, // specifiees the DATRON machine type + useParkPosition : true, // specifies to use park position at the end of the program + writeToolTable : true, // write the table with the geometric tool informations + useSequences : true, // this use a sequence in the output format to perform on large files + useExternalSequencesFiles : false, // this property create one external sequence files for each operation + writeCoolantCommands : true, // disable the coolant commands in the file + useParametricFeed : true, // specifies that feed should be output using parameters + waitAfterOperation : false, // optional stop + got4thAxis: false, // specifies if the machine has a rotational 4th axis + got5thAxis: false, // activate the RTCP options + useSuction: false, // activate suction support + createThreadChamfer: false, // create a chamfer with the thread milling tool + preloadTool: false, //prepare a Tool for the DATROn tool assist + writePathOffset:true, //write the definition for the PathOffset variable for every Operation + useRtcp:false, + rampLength: 40, + rampZBindingDepth: 1, + useClosedContour:true, +}; + + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Specifies if smoothing should be used or not.", type:"boolean"}, + useDynamic: {title:"Dynamic mode", description:"Specifies the using of dynamic mode or not.", type:"boolean"}, + machineType:{title:"Machine type", description:"Specifies the DATRON machine type.", type:"MachineType"}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + writeToolTable: {title:"Write tool table", description:"Write a tool table containing geometric tool information.", group:0, type:"boolean"}, + useSequences: {title:"Use sequences", description:"If enables, sequences are used in the output format on large files.", type:"boolean"}, + useExternalSequencesFiles: {title:"Use external sequence files", description:"If enabled, an external sequence file is created for each operation.", type:"boolean"}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + waitAfterOperation: {title:"Wait after operation", description:"If enabled, an optional stop is outputted to pause after each operation.", type:"boolean"}, + got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, + got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with a DST.", type:"boolean"}, + useSuction: {title:"Use Suction", description:"Enable the suction for every operation.", type:"boolean"}, + createThreadChamfer: {title:"Create a Thread Chamfer",description:"create a chamfer with the thread milling tool"}, + preloadTool:{title:"Preload the next Tool", description:"Preload the next Tool in the DATRON Tool assist."}, + writePathOffset:{title:"Write Path Offset", description:"Write the PathOffset declaration."} +} + +var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); +var toolFormat = createFormat({decimals:0}); +var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); +var rpmFormat = createFormat({decimals:0, scale:1}); +var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); + +var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); +var feedOutput = createVariable({prefix:""}, feedFormat); + +var xOutput = createVariable({prefix:" X="}, xyzFormat); +var yOutput = createVariable({prefix:" Y="}, xyzFormat); +var zOutput = createVariable({prefix:" Z="}, xyzFormat); +var aOutput = createVariable({prefix:" A="}, abcFormat); +var bOutput = createVariable({prefix:" B="}, abcFormat); +var cOutput = createVariable({prefix:" C="}, abcFormat); + +var iOutput = createVariable({prefix:" dX=", force : true}, xyzFormat); +var jOutput = createVariable({prefix:" dY=", force : true}, xyzFormat); +var kOutput = createVariable({prefix:" dZ="}, xyzFormat); + +// fixed settings +var useDatronFeedCommand = false; // unsupported for now, keep false +var language = "de"; // specifies the language, replace with getLangId() +var spacingDepth = 0; +var spacingString = " "; +var spacing = "##########################################################"; + +// buffer for building up a program not serial created +var sequenceBuffer = new StringBuffer(); + +function NewOperation(operationCall){ + this.operationCall = operationCall; + this.operationProgram = new StringBuffer(); + this.operationProgram.append(""); +} +var currentOperation; +function NewSimPLProgram(){ + this.moduleName = new StringBuffer(); + this.measuringSystem = "Metric"; + this.toolDescriptionList = new Array(); + this.workpieceGeometry = ""; + this.sequenceList = new Array(); + this.usingList = new Array(); + this.externalUsermodules = new Array(); + this.globalVariableList = new Array(); + this.mainProgram = new StringBuffer(); + this.operationList = new Array(); +} + +var SimPLProgram = new NewSimPLProgram(); + +// collected state +var currentFeedValue = -1; +var optionalSection = false; +var activeMovements; // do not use by default +var currentFeedId; + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +function getSequenceName(section) { + var sequenceName = ""; + if (properties.useExternalSequencesFiles) { + sequenceName += FileSystem.getFilename(getOutputPath().substr(0, getOutputPath().lastIndexOf("."))) + "_"; + } + sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); + return sequenceName; +} + +function getFilename(){ + var filePath = getOutputPath(); + var filename = filePath.slice(filePath.lastIndexOf("\\")+1, filePath.lastIndexOf(".")); + return filename; +} + +function getOperationName(section) { + return "Operation_" + getOperationDescription(section); +} + +function capitalizeFirstLetter(text) { + return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); +} + +function getSpacing() { + var space = ""; + for (var i = 0; i < spacingDepth; i++) { + space += spacingString; + } + return space; +} + +/** + Redirect the output to an infinite number of buffers ;-) + works like a stack you can use many redirection levels and go back again +*/ +var writeRedirectionStack = new Array(); + +function SetWriteRedirection(redirectionbuffer){ + writeRedirectionStack.push(redirectionbuffer); +} + +function ResetWriteRedirection(){ + return writeRedirectionStack.pop(); +} + +/** + Writes the specified block. +*/ +function writeBlock(arguments) { + var text = getSpacing() + formatWords(arguments); + if (writeRedirectionStack.length == 0){ + writeWords(text); + } else { + writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); + } +} + +/** + Output a comment. +*/ +function writeComment(text) { + if (text) { + text = getSpacing() + "# " + text; + if (writeRedirectionStack.length == 0){ + writeln(text); + } else { + writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); + } + } +} + +var charMap = { + "\u00c4" : "Ae", + "\u00e4" : "ae", + "\u00dc" : "Ue", + "\u00fc" : "ue", + "\u00d6" : "Oe", + "\u00f6" : "oe", + "\u00df" : "ss", + "\u002d" : "_", + "\u0020" : "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + text = formatVariable(text); + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); +} + +function onOpen() { + // note: setup your machine here + + // if (properties.got4thAxis && !properties.got5thAxis) { + // var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0}); + // machineConfiguration = new MachineConfiguration(aAxis); + // machineConfiguration.setVendor("DATRON"); + // machineConfiguration.setModel("NEO with A Axis"); + // machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); + // setMachineConfiguration(machineConfiguration); + // optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis + // } + + // // note: setup your machine here + // if (properties.got4thAxis && properties.got5thAxis) { + // var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0}); + // var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0}); + // machineConfiguration = new MachineConfiguration(aAxis,cAxis); + // machineConfiguration.setVendor("DATRON"); + // machineConfiguration.setModel("NEXT with DST"); + // machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); + // setMachineConfiguration(machineConfiguration); + // optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis + // } + + // if (!machineConfiguration.isMachineCoordinate(0)) { + // aOutput.disable(); + // } + // if (!machineConfiguration.isMachineCoordinate(1)) { + // bOutput.disable(); + // } + // if (!machineConfiguration.isMachineCoordinate(2)) { + // cOutput.disable(); + // } + + + // machineConfiguration = new MachineConfiguration(); + // machineConfiguration.setJet(true); + // machineConfiguration.setWire(true); + // setMachineConfiguration(machineConfiguration); + + // header of the main program + writeProgramHeader(); + spacingDepth -= 1; + ResetWriteRedirection(); + + // the rest of program main will be set at closing when all the code is analysed +} + +function getOperationDescription(section) { + // creates the name of the operation + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +function createToolVariables() { + var tools = getToolTable(); + var toolVariables = new Array(); + if (tools.getNumberOfTools() > 0 && !properties.writeToolTable) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + toolVariables.push(toolOutput.format(tool.number) + ":number"); + } + } + return toolVariables; +} + +function getNextTool(number) { + var currentSectionId = getCurrentSectionId(); + if (currentSectionId < 0) { + return null; + } + for (var i = currentSectionId + 1; i < getNumberOfSections(); ++i) { + var section = getSection(i); + var sectionTool = section.getTool(); + if (number != sectionTool.number) { + return sectionTool; // found next tool + } + } + return null; // not found +} + +// function createToolDescriptionTable() { +// if (!properties.writeToolTable) { +// return; +// } + +// var toolDescriptionArray = new Array(); +// var toolNameList = new Array(); +// var numberOfSections = getNumberOfSections(); +// for (var i = 0; i < numberOfSections; ++i) { +// var section = getSection(i); +// var tool = section.getTool(); +// if (tool.type != TOOL_PROBE) { +// var toolName = createToolName(tool); +// var toolProgrammed = createToolDescription(tool); +// if (toolNameList.indexOf(toolName) == -1) { +// toolNameList.push(toolName); +// toolDescriptionArray.push(toolProgrammed); +// } else { +// /* +// if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { +// error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + +// toolNameList.join("\r\n") + "#####################################\r\n"); +// } +// */ +// } +// } +// } + +// return toolDescriptionArray; +// } + +function createToolDescription(tool) { + var toolProgrammed = "@ ToolDescription : " + + "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + + "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + + "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + + "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + + "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + + "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + + "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + + "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + + "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + + "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + + "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + + "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + + "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + + "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + + "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + + " @"; + return toolProgrammed; +} + +/** + Generate the logical tool name for the assignment table of used tools. +*/ +// function createToolName(tool) { +// var toolName = toolFormat.format(tool.number); +// toolName += "_" + translateToolType(tool.type); +// if (tool.comment) { +// toolName += "_" + tool.comment; +// } +// if (tool.diameter) { +// toolName += "_D" + tool.diameter; +// } +// var description = tool.getDescription(); +// if (description) { +// toolName += "_" + description; +// } +// toolName = formatVariable(toolName); +// return toolName; +// } + +/** + Translate HSM tools to Datron tool categories. +*/ +function translateToolType(toolType) { + + var datronCategoryName = ""; + + toolCategory = toolType; + switch (toolType) { + case TOOL_UNSPECIFIED: + datronCategoryName = "Unspecified"; + break; + case TOOL_DRILL: + datronCategoryName = "Drill"; + break; + case TOOL_DRILL_CENTER: + datronCategoryName = "DrillCenter"; + break; + case TOOL_DRILL_SPOT: + datronCategoryName = "DrillSpot"; + break; + case TOOL_DRILL_BLOCK: + datronCategoryName = "DrillBlock"; + break; + case TOOL_MILLING_END_FLAT: + datronCategoryName = "MillingEndFlat"; + break; + case TOOL_MILLING_END_BALL: + datronCategoryName = "MillingEndBall"; + break; + case TOOL_MILLING_END_BULLNOSE: + datronCategoryName = "MillingEndBullnose"; + break; + case TOOL_MILLING_CHAMFER: + datronCategoryName = "Graver"; + break; + case TOOL_MILLING_FACE: + datronCategoryName = "MillingFace"; + break; + case TOOL_MILLING_SLOT: + datronCategoryName = "MillingSlot"; + break; + case TOOL_MILLING_RADIUS: + datronCategoryName = "MillingRadius"; + break; + case TOOL_MILLING_DOVETAIL: + datronCategoryName = "MillingDovetail"; + break; + case TOOL_MILLING_TAPERED: + datronCategoryName = "MillingTapered"; + break; + case TOOL_MILLING_LOLLIPOP: + datronCategoryName = "MillingLollipop"; + break; + case TOOL_TAP_RIGHT_HAND: + datronCategoryName = "TapRightHand"; + break; + case TOOL_TAP_LEFT_HAND: + datronCategoryName = "TapLeftHand"; + break; + case TOOL_REAMER: + datronCategoryName = "Reamer"; + break; + case TOOL_BORING_BAR: + datronCategoryName = "BoringBar"; + break; + case TOOL_COUNTER_BORE: + datronCategoryName = "CounterBore"; + break; + case TOOL_COUNTER_SINK: + datronCategoryName = "CounterSink"; + break; + case TOOL_HOLDER_ONLY: + datronCategoryName = "HolderOnly"; + break; + case TOOL_PROBE: + datronCategoryName = "XYZSensor"; + break; + default: + datronCategoryName = "Unspecified"; + } + return datronCategoryName; +} + +function writeProgramHeader() { + // write creation Date + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + SetWriteRedirection(SimPLProgram.moduleName); + writeComment("!File ; generated at " + date + " - " + time); + if (programComment) { + writeComment(formatComment(programComment)); + } + writeComment("####################### "); + writeComment(" DATRON NEXT "); + writeComment(" Dispensing Program"); + writeComment(""); + writeComment(" | |"); + writeComment(" | |"); + writeComment(" ==> \\ /"); + writeComment(" ||"); + writeComment(" ||"); + writeComment(" ==========="); + writeComment("#######################"); + writeBlock(" "); + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + writeBlock("module " + "CamGeneratedDispensingModule"); + writeBlock(" "); + + writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); + ResetWriteRedirection(); + + // set the table of used tools in the header of the program + //SimPLProgram.toolDescriptionList = createToolDescriptionTable(); + + // set the workpiece information + SimPLProgram.workpieceGeometry = writeWorkpiece(); + + // set the sequence header in the program file + if (properties.useSequences) { + var sequences = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (!isProbeOperation(section)) { + sequences.push("sequence " + getSequenceName(section)); + } + } + if (properties.useExternalSequencesFiles) { + writeBlock("@ EmbeddedSequences = false @"); + } + + SimPLProgram.sequenceList = sequences; + } + + // set usings + SimPLProgram.usingList.push("using Base"); + SimPLProgram.usingList.push("using DispensingCycles"); + + if ((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ + SimPLProgram.usingList.push("using Rtcp"); + } + if (properties.waitAfterOperation) { + SimPLProgram.usingList.push("import System"); + } + + // set paramtric feed variables + //var feedDeclaration = new Array(); + var currentMovements = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (properties.useParametricFeed && (!useDatronFeedCommand)) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(FeedContextTranslator(feedContext.description)); + if (SimPLProgram.globalVariableList.indexOf(feedDescription + ":number") == -1) { + SimPLProgram.globalVariableList.push(feedDescription + ":number"); + } + } + } + } + + // if (!useDatronFeedCommand) { + // if (feedDeclaration != 0) { + // SimPLProgram.globalVariableList.push(feedDeclaration); + // } + // } + SetWriteRedirection(SimPLProgram.mainProgram); + writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + spacingDepth += 1; + writeBlock("Absolute"); + + writeBlock("DispensingTechnology P=1 D=0.025"); + writeBlock("DispensingVolume crossSection=2"); + writeBlock(""); + + + // set the parameter tool table + SimPLProgram.globalVariableList.push(createToolVariables()); + + if (!properties.writeToolTable) { + var tools = getToolTable(); + writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + dimensionFormat.format(tool.diameter) + " " + + "L2:" + dimensionFormat.format(tool.fluteLength) + " " + + "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + + "ProductID:" + formatComment(tool.productId); + writeBlock(toolAsigment); + } + writeBlock(" "); + } + } + ResetWriteRedirection(); +} + + +function writeWorkpiece() { + var workpieceString = new StringBuffer(); + SetWriteRedirection(workpieceString); + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + + writeBlock("# Workpiece dimensions"); + writeBlock( + "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z)); + writeBlock( + "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z)); + writeBlock( + "# Part size X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z)); + + writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + + "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + + " @"); + ResetWriteRedirection(); + return workpieceString; +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, datronFeedName, feed) { + this.id = id; + this.description = description; + this.datronFeedName = datronFeedName; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + if (useDatronFeedCommand) { + return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); + } else { + return ("Feed=" + formatVariable(FeedContextTranslator( feedContext.description))); + } + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return "Feed=" + feedFormat.format(f); + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + addFeedContext(feedContext, activeFeeds); + } + ++id; + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + + // this part allows us to use feedContext also for the cycles + if (hasParameter("operation:cycleType")) { + var cycleType = getParameter("operation:cycleType"); + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + + switch (cycleType) { + case "thread-milling": + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + case "bore-milling": + if (section.hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (section.hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + } + } + + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +/** Check that all elements are only one time in the result list. */ +function addFeedContext(feedContext, activeFeeds) { + if (activeFeeds.indexOf(feedContext) == -1) { + activeFeeds.push(feedContext); + } +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function setWorkPlane(abc) { + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + forceWorkPlane(); // always need the new workPlane + forceABC(); + if((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ + writeBlock("MoveZToTopPosition"); + }else{ + writeBlock("MoveToSafetyPosition"); + } + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function onSection() { + // this is the container that hold all operation informations... + currentOperation = new NewOperation(getOperationName(currentSection)) + SetWriteRedirection(currentOperation.operationProgram); + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + var tool = currentSection.getTool(); + + if (!isProbeOperation(currentSection)) { + writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); + } + + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + zRange.expandToRange(currentSection.getGlobalZRange()); + writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); + } + } + // create sub program + writeBlock("program " + getOperationName(currentSection)); + spacingDepth += 1; + + if (passThrough) { + var joinString = "\r\n" + getSpacing(); + var passThroughString = passThrough.join(joinString); + if (passThroughString != "") { + writeBlock(passThroughString); + } + passThrough = []; + } + + // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. + writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); + var operationTolerance = tolerance; + if (hasParameter("operation:tolerance")) { + if (operationTolerance < getParameter("operation:tolerance")) { + operationTolerance = getParameter("operation:tolerance"); + } + } + + //load the matching workOffset + var workOffset = currentSection.getWorkOffset(); + if (workOffset != 0) { + writeBlock("LoadWcs name=\"" + workOffset +"\""); + } + + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); + } else + { + writeBlock("Smoothing Off"); + } + + if (properties.useDynamic) { + var dynamic = 5; + // set machine type specific dynamic sets + /* + switch(properties.machineType){ + case 'NEO': + dynamic =5; + break; + case 'MX': + case 'CUBE': + if (operationTolerance <= (unit == MM ? 0.04 : (0.04/25.4))) { + dynamic = 4; + } + if (operationTolerance <= (unit == MM ? 0.02 : (0.02/25.4))) { + dynamic = 3; + } + if (operationTolerance <= (unit == MM ? 0.005 : (0.005/25.4))) { + dynamic = 2; + } + if (operationTolerance <= (unit == MM ? 0.003 : (0.003/25.4))) { + dynamic = 1; + } + break; + } + */ + writeBlock("Dynamic = " + dynamic); + } + if (properties.waitAfterOperation) { + showWaitDialog(); + } + + if (machineConfiguration.isMultiAxisConfiguration()) { + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + if((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ + writeBlock("Rtcp On"); + } + writeBlock("MoveToSafetyPosition"); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + } else { + forceWorkPlane(); + var abc = getWorkPlaneMachineABC(currentSection.workPlane); + + setWorkPlane(abc); + if((properties.got5thAxis || properties.got4thAxis) && properties.useRtcp){ + writeBlock("Rtcp On"); + } + } + } else { + // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + error("\r\n_________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| Tool orientation detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis, otherwise you can only post|" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|________________________________________|\r\n"); + return; + } + setRotation(remaining); + } + + forceAny(); + + if (properties.showNotes && currentSection.hasParameter("notes")) { + var notes = currentSection.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + + var clearance = getFramePosition(currentSection.getInitialPosition()).z; + writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); + + // radius Compensation + var compensationType + if(hasParameter('operation:compensationType')){ + compensationType = getParameter('operation:compensationType'); + } else { + compensationType = 'computer'; + } + + var wearCompensation + if(hasParameter('operation:compensationDeltaRadius')){ + wearCompensation = getParameter('operation:compensationDeltaRadius'); + } else { + wearCompensation = 0; + } + + if(properties.writePathOffset){ + switch( compensationType){ + case 'computer': + break; + case 'control': + writeBlock("PathOffset = 0") + break; + case 'wear': + + writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); + break; + case 'inverseWear': + writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation * -1)); + break; + } + } + + if (!isProbeOperation(currentSection)) { + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + + // // tool changer command + // if (properties.writeToolTable) { + // writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + + // " newRpm=" + rpmFormat.format(spindleSpeed) + + // " skipRestoring" + // ); + // } else { + // writeBlock("Tool = " + toolOutput.format(tool.number) + + // " newRpm=" + rpmFormat.format(spindleSpeed) + + // " skipRestoring" + // ); + // } + + // //preload the next tool for the Datron tool assist + // if(properties.preloadTool){ + // var nextTool = getNextTool(tool.number); + // if(nextTool){ + // if (properties.writeToolTable) { + // writeBlock("ProvideTool name=" + "\"" + createToolName(nextTool) + "\""); + // } else { + // writeBlock("ProvideTool = " + toolOutput.format(nextTool.number)); + // } + // } + // } + + + // write dispense specific paramters + SimPLProgram.globalVariableList.push("rampLength:number"); + SimPLProgram.globalVariableList.push("zBindingDepth:number"); + + writeBlock("rampLength = " + properties.rampLength); + writeBlock("zBindingDepth = " + properties.rampZBindingDepth); + + + // set the current feed + // replace by the default feed command + if (properties.useParametricFeed && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + if (useDatronFeedCommand) { + var datronFeedParameter = new Array(); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var datronFeedCommand = { + name : feedContext.datronFeedName, + feed : feedFormat.format(feedContext.feed) + }; +/*eslint-disable*/ + var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); +/*eslint-enable*/ + if (indexOfFeedContext == -1) { + datronFeedParameter.push(datronFeedCommand); + } else { + var existingFeedContext = datronFeedParameter[indexOfFeedContext]; + if (existingFeedContext.feed < datronFeedCommand.feed) { + existingFeedContext.feed = datronFeedCommand.feed; + } + } + } + var datronFeedCommand = "SetFeedTechnology"; + for (var i = 0; i < datronFeedParameter.length; i++) { + datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; + } + writeBlock(datronFeedCommand); + + } else { + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(FeedContextTranslator(feedContext.description)) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); + } + } + } + } + + // parameter for the sequences + var sequenceParamter = new Array(); + + if (hasParameter("operation:cycleType")) { + + //Reset all movements to suppress older entries... + activeMovements = new Array(); + + var cycleType = getParameter("operation:cycleType"); + writeComment("Parameter " + cycleType + " cycle"); + + switch (cycleType) { + case "thread-milling": + writeBlock("SetFeedTechnology" + " ramp=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:finish_cutting"))); + var diameter = currentSection.getParameter("diameter"); + var pitch = currentSection.getParameter("pitch"); + var finishing = currentSection.getParameter("stepover"); + + writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); + sequenceParamter.push("nominalDiameter=nominalDiameter"); + writeBlock("pitch=" + xyzFormat.format(pitch)); + sequenceParamter.push("pitch=pitch"); + if (xyzFormat.isSignificant(finishing)) { + writeBlock("finishing=" + xyzFormat.format(finishing)); + sequenceParamter.push("finishing=finishing"); + } else { + sequenceParamter.push("finishing=0"); + } +/* + writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); + sequenceParamter.push('threadName=threadName'); + writeBlock("threading = " + currentSection.getParameter("threading")); + sequenceParamter.push("threading=threading"); + + TAG: den Standard auch mit Imperial unterstuezten + sequenceParamter.push("threadStandard=ThreadStandards.Metric"); + sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); + sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); + sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); + writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); + sequenceParamter.push("direction=direction"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); +*/ + break; + case "bore-milling": + writeBlock("SetFeedTechnology roughing=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:cutting"))); + writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); + sequenceParamter.push("diameter=diameter"); + + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); + sequenceParamter.push("infeedZ=infeedZ"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); + break; + case "drilling": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge"))); + break; + case "chip-breaking": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge")) + " roughing=" + feedFormat.format(getParameter("movement:cutting"))); + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); + sequenceParamter.push("infeedZ=infeedZ"); + break; + } + } + + if (properties.useSequences && !isProbeOperation(currentSection)) { + sequenceParamter.push("rampLength=rampLength"); + sequenceParamter.push("zBindingDepth=zBindingDepth"); + + // call sequence + if (properties.useParametricFeed && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + sequenceParamter.push(formatVariable(FeedContextTranslator(feedContext.description)) + "=" + formatVariable(FeedContextTranslator(feedContext.description))); + } + } + var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); + writeBlock(currentSectionCall); + + // write sequence + var currentSequenceName = getSequenceName(currentSection); + if (properties.useExternalSequencesFiles) { + spacingDepth -= 1; + var filename = getOutputPath(); + //sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; + sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; + sequenceFilePath += currentSequenceName + ".seq"; + redirectToFile(sequenceFilePath); + } else { + SetWriteRedirection(sequenceBuffer); + writeBlock(" "); + // TAG: modify parameter + spacingDepth -= 1; + writeBlock("$$$ " + currentSequenceName); + } + } + + if (!isProbeOperation(currentSection)) { + writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); + } else { + writeBlock("Spindle Off"); + writeBlock("PrepareXyzSensor"); + } + + // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); + + writeBlock("PrePositioning" + xyz); + + // adds support for suction + if(properties.useSuction){ + writeBlock("Suction On"); + } + +} + +function FeedContextTranslator(feed){ + if(feed= "Cutting") + return "dispenseFeed"; + else + return feed; + +} + +function showWaitDialog(operationName) { + writeBlock("showWaitDialog"); +} + +function writeWaitProgram() { + writeBlock("#Show the wait dialog for the next operation"); + writeBlock("program showWaitDialog optional operationName:string"); + writeBlock(""); + writeBlock(" if not operationName hasvalue "); + writeBlock(" operationName =" + "\"" + "\""); + writeBlock(" endif"); + writeBlock(""); + writeBlock(" messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName "); + writeBlock(" dialogResult = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel"); + writeBlock(" if dialogResult == System::DialogResult.Cancel"); + writeBlock(" exit"); + writeBlock(" endif"); + writeBlock(""); + writeBlock("endprogram"); +} + +function onDwell(seconds) { + writeBlock("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + // writeBlock("Rpm=" + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed)); + writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("Rapid" + xyz); + forceFeed(); + } +} + +function onPrePositioning(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("PrePositioning" + xyz); + forceFeed(); + } +} + +function onLinear(x, y, z, feed) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + var f = getFeed(feed); + + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > 99) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + // TAG: um die Ebenen kuemmern + // writeBlock(gPlaneModal.format(17)); + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock("ToolCompensation Left"); + writeBlock("PathCorrection Left"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock("ToolCompensation Right"); + writeBlock("PathCorrection Right"); + break; + case RADIUS_COMPENSATION_OFF: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + } + + if (xyz) { + if (f) { + writeBlock(f); + } + writeBlock("Line" + xyz); + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + + if (pendingRadiusCompensation >= 0) { + error(localize("radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + yOutput.format(y) + + zOutput.format(z) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + + forceABC(); + var xyzabc = x + y + z + a + b + c; + writeBlock("Rapid" + xyzabc); + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + var f = getFeed(feed); + + writeBlock(f); + if (x || y || z || a || b || c) { + var xyzabc = x + y + z + a + b + c; + writeBlock("Line" + xyzabc); + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onRewindMachine(a, b, c) { + writeBlock("MoveToSafetyPosition"); + var abc = aOutput.format(a) + bOutput.format(b) + cOutput.format(c); + writeBlock("Line" + abc); +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + return; + // if (properties.writeCoolantCommands) { + // if (coolant == COOLANT_OFF) { + // writeBlock("SpraySystem Off"); + // currentCoolantMode = COOLANT_OFF; + // return; + // } + + // switch (coolant) { + // case COOLANT_FLOOD: + // case COOLANT_MIST: + // writeBlock("SprayTechnology External"); + // writeBlock("Coolant Alcohol"); + // break; + // case COOLANT_AIR: + // writeBlock("SprayTechnology External"); + // writeBlock("Coolant Air"); + // break; + // case COOLANT_THROUGH_TOOL: + // writeBlock("SprayTechnology Internal"); + // writeBlock("Coolant Alcohol"); + // break; + // case COOLANT_AIR_THROUGH_TOOL: + // writeBlock("SprayTechnology Internal"); + // writeBlock("Coolant Air"); + // break; + + // default: + // onUnsupportedCoolant(coolant); + // } + // writeBlock("SpraySystem On"); + // currentCoolantMode = coolant; + // } +} + +var isInsideProgramDeclaration = false; +var directNcOperation; +function ParseManualNc(text){ + + var modulePattern = new RegExp("\.*(using|import)"); + var isModuleImport = modulePattern.test(text); + if(isModuleImport){ + SimPLProgram.usingList.push(text); + return; + } + + var programPattern = /(?:\s*program\s+)(\w+)/; + var isProgramDeclaration = programPattern.test(text); + + if(isProgramDeclaration){ + var subProgramName = programPattern.exec(text); + if(subProgramName == undefined) return; + directNcOperation = {operationCall:subProgramName[1],operationProgram: new StringBuffer()}; + SimPLProgram.operationList.push(directNcOperation); + isInsideProgramDeclaration = true; + } + + var isEndProgram = /\s*endprogram/.test(text); + if(isEndProgram){ + isInsideProgramDeclaration = false; + directNcOperation.operationProgram.append(text + "\r\n"); + return; + } + + if (isInsideProgramDeclaration){ + directNcOperation.operationProgram.append(text + "\r\n"); + return; + } + + return text; +} + +function onManualNC(command, value) { + switch (command) { + case 42: // Manual NC enumeration code ??? + value = ParseManualNc(value); + break; + case 40: // Comment + value = "# " + value; + break; + case 41: //wait + value = "Sleep seconds=" + value; + break; + case COMMAND_COOLANT_OFF: + value = "SpraySystem Off"; + break; + case COMMAND_COOLANT_ON: + value = "SpraySystem On"; + break; + case COMMAND_STOP: + value = "break"; + break; + case COMMAND_START_SPINDLE: + value = "Spindle On"; + break; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + value = "ChipConveyor On"; + break; + case COMMAND_STOP_CHIP_TRANSPORT: + value = "ChipConveyor Off"; + break; + case COMMAND_OPEN_DOOR: //open door + value = "ReleaseDoor"; + break; + case COMMAND_CLOSE_DOOR: //close door not needed + return; + case COMMAND_CALIBRATE: //calibrate + value = "# calibration currently not supported!"; + break; + case COMMAND_VERIFY: // check part + value = 'Dialog message="Please check workpiece!" Ok Cancel caption="Cam generated dialog"' + break; + case COMMAND_CLEAN: // clean part + value = 'Dialog message="Please clean workpiece!" Ok Cancel caption="Cam generated dialog"' + break; + case 43: // action no idea for what has a paramter + return; + //value = "# Action currently not supported!" + //break; + case 44: // print message + // value = 'Dialog message="' + value + '" Ok Cancel caption="Cam generated dialog"' + SimPLProgram.usingList.push('using File'); + SimPLProgram.usingList.push('using DateTimeModule') + var message = (' value=(GetNow + "\t' + value + '")') + value = 'FileWriteLine filename="' + getFilename() + '.log"' + message; + break; + case 46: // show message + value = 'StatusMessage message="' + value + '"'; + break; + case COMMAND_ALARM: // alarm + value = 'Dialog message="Alarm!" Ok Cancel caption="Cam generated dialog"' + break; + case COMMAND_ALERT: // alarm + value = 'Dialog message="Warning!" Ok Cancel caption="Cam generated dialog"' + break; + case COMMAND_BREAK_CONTROL: + value = "MeasureToolLength" + break; + case COMMAND_TOOL_MEASURE: + value = "MeasureToolLength" + break; + case COMMAND_OPTIONAL_STOP: + value = "OptionalBreak"; + break; + case 45: //call subprogram + var subprogramName = "SubProgram_" + SimPLProgram.externalUsermodules.length; + SimPLProgram.externalUsermodules.push('usermodule ' + subprogramName + '="' + value + '"'); + value = subprogramName; + break; + } + + if(value != undefined){ + var operation = {operationCall: value, operationProgram:""} + SimPLProgram.operationList.push(operation); + } +} + +var mapCommand = {}; + +var passThrough = new Array(); +function onPassThrough(text) { + passThrough.push(text); +} + +function onCommand(command) { + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + if(properties.useClosedContour){ + if(command == COMMAND_POWER_ON ){ + writeBlock("BeginClosedContour rampLength=rampLength zBindingDepth=zBindingDepth"); + } + if(command == COMMAND_POWER_OFF ){ + writeBlock("EndClosedContour"); + } + }else{ + if(command == COMMAND_POWER_ON ){ + writeBlock("DispensingPump On"); + } + if(command == COMMAND_POWER_OFF ){ + writeBlock("DispensingPump Off"); + } + } + + // onUnsupportedCommand(command); + } +} + +function onCycle() { +} + +function onCycleEnd() { +} + +function isProbeOperation(section) { + return (section.hasParameter("operation-strategy") && section.getParameter("operation-strategy") == "probe"); +} + +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + var feedString = feedOutput.format(cycle.feedrate); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + + var startPositionOffset = cycle.probeClearance + tool.cornerRadius; + } + + switch (cycleType) { + case "bore-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onRapid(x, y, cycle.clearance); + boreMilling(cycle); + onRapid(x, y, cycle.clearance); + } + break; + case "thread-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onRapid(x, y, cycle.clearance); + threadMilling(cycle); + onRapid(x, y, cycle.clearance); + } + break; + case "drilling": + forceXYZ(); + onRapid(x, y, cycle.clearance); + drilling(cycle); + onRapid(x, y, cycle.clearance); + break; +/* + case "chip-breaking": + forceXYZ(); + onRapid(x, y, null); + onRapid(x, y, cycle.retract); + chipBreaking(cycle); + onRapid(x, y, cycle.clearance); + break; +*/ + + case "tapping": + case "left-tapping": + case "right-tapping": + case "tapping-with-chip-breaking": + case "left-tapping-with-chip-breaking": + case "right-tapping-with-chip-breaking": + forceXYZ(); + onRapid(x, y, cycle.clearance); + tapping(cycle); + onRapid(x, y, cycle.clearance); + break; + case "probing-x": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + break; + case "probing-y": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + break; + case "probing-z": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); + + var measureString = "SurfaceMeasure "; + measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); + writeBlock(measureString); + break; + case "probing-x-wall": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-y-wall": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-x-channel": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-x-channel-with-island": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-y-channel": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-y-channel-with-island": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-boss": + var measureString = "CircleMeasure"; + measureString += " diameter=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-hole": + var measureString = "CircleMeasure"; + measureString += " diameter=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-hole-with-island": + var measureString = "CircleMeasure"; + measureString += " diameter=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-boss": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + cycle.width1; + measureString += " dimensionY=" + cycle.width2; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " Center"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-hole": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + cycle.width1; + measureString += " dimensionY=" + cycle.width2; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " Center"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-hole-with-island": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + cycle.width1; + measureString += " dimensionY=" + cycle.width2; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " Center"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-inner-corner": + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "EdgeMeasure "; + + zOutput.reset(); + onRapid(x, y, cycle.stock); + onLinear(x, y, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + + forceXYZ(); + //zOutput.reset(); + onRapid(x, y, cycle.stock); + onLinear(x, y, probingDepth, cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; + // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; + + // var orientation = "" + // if (!isXNeagtive && !isYNeagtive) orientation = "BackRight"; + // if (isXNeagtive && !isYNeagtive) orientation = "BackLeft"; + // if (!isXNeagtive && isYNeagtive) orientation = "FrontRight"; + // if (isXNeagtive && isYNeagtive) orientation = "FrontLeft"; + + // var measureString = "CornerMeasure"; + // measureString += " " + orientation; + // measureString += " Inside"; + // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " forceSafeHeight" + // measureString += " skipZMeasure"; + // measureString += " originXShift=" + xyzFormat.format(-x); + // measureString += " originYShift=" + xyzFormat.format(-y); + // writeBlock(measureString); + break; + case "probing-xy-outer-corner": + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var measureString = "EdgeMeasure "; + + zOutput.reset(); + onRapid(x, y, probingDepth); + onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + onLinear(x, y, probingDepth, cycle.feedrate); + //forceXYZ(); + //zOutput.reset(); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onLinear(x, y, probingDepth, cycle.feedrate); + + // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; + // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; + + // var orientation = "" + // if (!isXNeagtive && !isYNeagtive) orientation = "FrontLeft"; + // if (isXNeagtive && !isYNeagtive) orientation = "FrontRight"; + // if (!isXNeagtive && isYNeagtive) orientation = "BackLeft"; + // if (isXNeagtive && isYNeagtive) orientation = "BackRight"; + + // var measureString = "CornerMeasure"; + // measureString += " " + orientation; + // measureString += " Outside"; + // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " forceSafeHeight" + // measureString += " skipZMeasure"; + // measureString += " originXShift=" + xyzFormat.format(-x); + // measureString += " originYShift=" + xyzFormat.format(-y); + // writeBlock(measureString); + break; + case "probing-x-plane-angle": + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + // var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + // var touchPositionX2 = touchPositionX1; + // writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + // writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + // writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + // writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + // writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + // var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + // var touchPositionY2 = touchPositionY1; + // writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + // writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + // writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + // writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + // writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + return; + } + + // save probing result in defined wcs + if(currentSection.workOffset != null){ + writeBlock('SaveWcs name="' + currentSection.workOffset + '"'); + } + + return; +} + +function drilling(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + writeBlock(boreCommandString.join(" ")); +} + +function chipBreaking(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + boreCommandString.push("infeedZ=infeedZ"); + writeBlock(boreCommandString.join(" ")); +} + +function boreMilling(cycle) { + if (cycle.numberOfSteps > 2) { + error("Only 2 steps are allowed for bore-milling."); + } + + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + boreCommandString.push("DrillMilling"); + boreCommandString.push("diameter=diameter"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("infeedZ=infeedZ"); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + + if (cycle.numberOfSteps == 2) { + var xycleaning = cycle.stepover; + var maxzdepthperstep = tool.fluteLength * 0.8; + boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); + boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); + } + var bottomcleaning = 0; + // finishingZ = 1; + writeBlock(boreCommandString.join(" ")); +} + +function threadMilling(cycle) { + var threadString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + threadString.push("SpecialThread"); + // threadString.push('threadName=threadName'); + threadString.push("nominalDiameter=nominalDiameter"); + threadString.push("pitch=pitch"); + threadString.push("depth=" + depth); + threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + // threadString.push("threadStandard=threadStandard"); + if(properties.createThreadChamfer){ + threadString.push("Deburring"); + } + // ; + // threadString.push("insideOutside=ThreadMillingSide.Inside"); + threadString.push("finishing=finishing"); + if (cycle.threading == "left") { + threadString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + threadString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(threadString.join(" ")); +} + +function tapping(cycle) { + var tappingString = new Array(); + var depth = xyzFormat.format(cycle.depth); + tappingString.push("ThreadCutting"); + tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); + tappingString.push("depth=" + depth); + tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); + if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { + tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); + } + if (tool.type == TOOL_TAP_LEFT_HAND) { + tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + tappingString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(tappingString.join(" ")); +} + +function formatCycleTime(cycleTime) { + // cycleTime = cycleTime + 0.5; // round up + var seconds = cycleTime % 60 | 0; + var minutes = ((cycleTime - seconds)/60 | 0) % 60; + var hours = (cycleTime - minutes * 60 - seconds)/(60 * 60) | 0; + if (hours > 0) { + return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); + } else if (minutes > 0) { + return subst(localize("%1m:%2s"), minutes, seconds); + } else { + return subst(localize("%1s"), seconds); + } +} + +function dump(name, _arguments) { + var result = getCurrentRecordId() + ": " + name + "("; + for (var i = 0; i < _arguments.length; ++i) { + if (i > 0) { + result += ", "; + } + if (typeof _arguments[i] == "string") { + result += "'" + _arguments[i] + "'"; + } else { + result += _arguments[i]; + } + } + result += ")"; + writeln(result); +} + +function onSectionEnd() { + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + if (currentSection.isMultiAxis && (properties.got4thAxis || properties.got5thAxis) && properties.useRtcp){ + writeBlock("Rtcp Off"); + } + + // adds support for suction + if(properties.useSuction){ + writeBlock("Suction Off"); + } + + if (properties.useSequences && !isProbeOperation(currentSection)) { + if (!properties.useExternalSequencesFiles) { + ResetWriteRedirection(); + } + spacingDepth += 1; + } + + + writeBlock("EndBlock"); + + spacingDepth -= 1; + + writeBlock("endprogram " + "# " + getOperationName(currentSection)); + ResetWriteRedirection(); + SimPLProgram.operationList.push(currentOperation); + forceAny(); +} + +function onClose() { + + if (properties.waitAfterOperation) { + writeWaitProgram(); + } + + writeBlock(SimPLProgram.moduleName); + writeBlock(""); + writeBlock(SimPLProgram.toolDescriptionList.join("\r\n") ); + writeBlock(""); + writeBlock(SimPLProgram.workpieceGeometry); + writeBlock(""); + writeBlock(SimPLProgram.sequenceList.join("\r\n") ); + writeBlock(""); + writeBlock(SimPLProgram.usingList.join("\r\n") ); + writeBlock(""); + writeBlock(SimPLProgram.externalUsermodules.join("\r\n")); + writeBlock(""); + writeBlock(SimPLProgram.globalVariableList.join("\r\n") ); + writeBlock(""); + + finishMainProgram(); + writeBlock(SimPLProgram.mainProgram); + writeBlock(""); + + SimPLProgram.operationList.forEach(function (operation){ + if(operation != undefined){ + writeBlock(operation.operationProgram); + } + }) + + writeBlock("end"); + + if (properties.useSequences && !properties.useExternalSequencesFiles) { + writeComment(spacing); + writeBlock(sequenceBuffer.toString()); + } +} + +// after all the oiperation calls are set close the main program with all the calls +function finishMainProgram(){ + // write the main program footer + SetWriteRedirection(SimPLProgram.mainProgram); + spacingDepth += 1; + + // write all subprogram calls in the main Program + SimPLProgram.operationList.forEach(function(operation){ + if(operation!=undefined){ + writeBlock(operation.operationCall); + } + + }) + + //writeBlock("SpraySystem Off"); + //writeBlock("Spindle Off"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + if (properties.useParkPosition) { + writeBlock("MoveToParkPosition"); + } else { + writeBlock("MoveToSafetyPosition"); + zOutput.reset(); + } + + spacingDepth -= 1; + writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + ResetWriteRedirection(); +} + + diff --git a/datron next.cps b/deprecated/datron next.cps old mode 100755 new mode 100644 similarity index 97% rename from datron next.cps rename to deprecated/datron next.cps index 557c3f2..9937f92 --- a/datron next.cps +++ b/deprecated/datron next.cps @@ -1,2436 +1,2436 @@ -/** - Copyright (C) 2012-2018 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} -*/ - -description = "DATRON next"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 40783; - -longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; - -extension = "simpl"; -setCodePage("utf-8"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(120); -allowHelicalMoves = true; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - - -// user-defined properties -properties = { - writeMachine : true, // write machine - showNotes : false, // specifies that operation notes should be output - useSmoothing : true, // specifies if smoothing should be used or not - useDynamic : true, // specifies using dynamic mode or not - machineType : "NEO", // specifiees the DATRON machine type - useParkPosition : true, // specifies to use park position at the end of the program - writeToolTable : true, // write the table with the geometric tool informations - useSequences : true, // this use a sequence in the output format to perform on large files - useExternalSequencesFiles : false, // this property create one external sequence files for each operation - writeCoolantCommands : true, // disable the coolant commands in the file - useParametricFeed : true, // specifies that feed should be output using parameters - waitAfterOperation : false, // optional stop - rotationAxisSetup : "none", // define the rotatry axis setup for the machine - useSuction: false, // activate suction support - createThreadChamfer: false, // create a chamfer with the thread milling tool - preloadTool : false, //prepare a Tool for the DATROn tool assist - writePathOffset : true, //write the definition for the PathOffset variable for every Operation - useZAxisOffset : false, - useRtcp : false // use the NEXT feature RTCP for multiaxis operations -}; - - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Specifies if smoothing should be used or not.", type:"boolean"}, - useDynamic: {title:"Dynamic mode", description:"Specifies the using of dynamic mode or not.", type:"boolean"}, - machineType:{title:"Machine type", description:"Specifies the DATRON machine type.", type:"enum", - values:[ - {title:"NEO",id:"NEO"}, - {title:"MX Cube",id:"MX"}, - {title:"Cube",id:"Cube"} - ]}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - writeToolTable: {title:"Write tool table", description:"Write a tool table containing geometric tool information.", group:0, type:"boolean"}, - useSequences: {title:"Use sequences", description:"If enables, sequences are used in the output format on large files.", type:"boolean"}, - useExternalSequencesFiles: {title:"Use external sequence files", description:"If enabled, an external sequence file is created for each operation.", type:"boolean"}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - waitAfterOperation: {title:"Wait after operation", description:"If enabled, an optional stop is outputted to pause after each operation.", type:"boolean"}, - rotationAxisSetup : {title:"Setup rotary axis",description:"define if the machine is setup with additional rotary axis.", type:"enum", - values:[ - {title:"No rotary axis",id:"NONE"}, - {title:"4th axis along X+",id:"4th"}, - {title:"DST (4th & 5th axis)",id:"DST"} - ]}, - useSuction: {title:"Use Suction", description:"Enable the suction for every operation.", type:"boolean"}, - createThreadChamfer: {title:"Create a Thread Chamfer",description:"create a chamfer with the thread milling tool", type:"boolean"}, - preloadTool:{title:"Preload the next Tool", description:"Preload the next Tool in the DATRON Tool assist.", type: "boolean"}, - writePathOffset:{title:"Write Path Offset", description:"Write the PathOffset declaration.", type: "boolean"}, - useZAxisOffset:{title:"Output Z Offset command",description:"This creates a command to allow a manual Z offset for each operation.",type:"boolean"}, - useRtcp:{title:"Use RTCP", description:"Use the NEXT 5axis setup correction.",type:"boolean"} -} - -var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); -var toolFormat = createFormat({decimals:0}); -var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); -var rpmFormat = createFormat({decimals:0, scale:1}); -var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); - -var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); -var feedOutput = createVariable({prefix:""}, feedFormat); - -var xOutput = createVariable({prefix:" X="}, xyzFormat); -var yOutput = createVariable({prefix:" Y="}, xyzFormat); -var zOutput = createVariable({prefix:" Z="}, xyzFormat); -var aOutput = createVariable({prefix:" A="}, abcFormat); -var bOutput = createVariable({prefix:" B="}, abcFormat); -var cOutput = createVariable({prefix:" C="}, abcFormat); - -var iOutput = createVariable({prefix:" dX=", force : true}, xyzFormat); -var jOutput = createVariable({prefix:" dY=", force : true}, xyzFormat); -var kOutput = createVariable({prefix:" dZ="}, xyzFormat); - -// fixed settings -var useDatronFeedCommand = false; // unsupported for now, keep false -var language = "de"; // specifies the language, replace with getLangId() -var spacingDepth = 0; -var spacingString = " "; -var spacing = "##########################################################"; - -// buffer for building up a program not serial created -var sequenceBuffer = new StringBuffer(); - -function NewOperation(operationCall){ - this.operationCall = operationCall; - this.operationProgram = new StringBuffer(); - this.operationProgram.append(""); -} -var currentOperation; -function NewSimPLProgram(){ - this.moduleName = new StringBuffer(); - this.measuringSystem = "Metric"; - this.toolDescriptionList = new Array(); - this.workpieceGeometry = ""; - this.sequenceList = new Array(); - this.usingList = new Array(); - this.externalUsermodules = new Array(); - this.globalVariableList = new Array(); - this.mainProgram = new StringBuffer(); - this.operationList = new Array(); -} - -var SimPLProgram = new NewSimPLProgram(); - -// collected state -var currentFeedValue = -1; -var optionalSection = false; -var activeMovements; // do not use by default -var currentFeedId; - -// format date + time -var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -function getSequenceName(section) { - var sequenceName = ""; - if (properties.useExternalSequencesFiles) { - sequenceName += FileSystem.getFilename(getOutputPath().substr(0, getOutputPath().lastIndexOf("."))) + "_"; - } - sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); - return sequenceName; -} - -function getFilename(){ - var filePath = getOutputPath(); - var filename = filePath.slice(filePath.lastIndexOf("\\")+1, filePath.lastIndexOf(".")); - return filename; -} - -function getOperationName(section) { - return "Operation_" + getOperationDescription(section); -} - -function capitalizeFirstLetter(text) { - return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); -} - -function getSpacing() { - var space = ""; - for (var i = 0; i < spacingDepth; i++) { - space += spacingString; - } - return space; -} - -/** - Redirect the output to an infinite number of buffers ;-) - works like a stack you can use many redirection levels and go back again -*/ -var writeRedirectionStack = new Array(); - -function SetWriteRedirection(redirectionbuffer){ - writeRedirectionStack.push(redirectionbuffer); -} - -function ResetWriteRedirection(){ - return writeRedirectionStack.pop(); -} - -/** - Writes the specified block. -*/ -function writeBlock(arguments) { - var text = getSpacing() + formatWords(arguments); - if (writeRedirectionStack.length == 0){ - writeWords(text); - } else { - writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); - } -} - -/** - Output a comment. -*/ -function writeComment(text) { - if (text) { - text = getSpacing() + "# " + text; - if (writeRedirectionStack.length == 0){ - writeln(text); - } else { - writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); - } - } -} - -var charMap = { - "\u00c4" : "Ae", - "\u00e4" : "ae", - "\u00dc" : "Ue", - "\u00fc" : "ue", - "\u00d6" : "Oe", - "\u00f6" : "oe", - "\u00df" : "ss", - "\u002d" : "_", - "\u0020" : "_" -}; - -/** Map specific chars. */ -function mapComment(text) { - text = formatVariable(text); - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); -} - -function onOpen() { - // note: setup your machine here - if (properties.rotationAxisSetup == "4th") { - var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis); - machineConfiguration.setVendor("DATRON"); - machineConfiguration.setModel("NEO with A Axis"); - machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis - } - - // note: setup your machine here - if (properties.rotationAxisSetup == "DST") { - var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0}); - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis,cAxis); - machineConfiguration.setVendor("DATRON"); - machineConfiguration.setModel("NEXT with DST"); - machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - // header of the main program - writeProgramHeader(); - spacingDepth -= 1; - ResetWriteRedirection(); - - // the rest of program main will be set at closing when all the code is analysed -} - -function getOperationDescription(section) { - // creates the name of the operation - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -function createToolVariables() { - var tools = getToolTable(); - var toolVariables = new Array(); - if (tools.getNumberOfTools() > 0 && !properties.writeToolTable) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - toolVariables.push(toolOutput.format(tool.number) + ":number"); - } - } - return toolVariables; -} - -function getNextTool(number) { - var currentSectionId = getCurrentSectionId(); - if (currentSectionId < 0) { - return null; - } - for (var i = currentSectionId + 1; i < getNumberOfSections(); ++i) { - var section = getSection(i); - var sectionTool = section.getTool(); - if (number != sectionTool.number) { - return sectionTool; // found next tool - } - } - return null; // not found -} - -function createToolDescriptionTable() { - if (!properties.writeToolTable) { - return; - } - - var toolDescriptionArray = new Array(); - var toolNameList = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var tool = section.getTool(); - if (tool.type != TOOL_PROBE) { - var toolName = createToolName(tool); - var toolProgrammed = createToolDescription(tool); - if (toolNameList.indexOf(toolName) == -1) { - toolNameList.push(toolName); - toolDescriptionArray.push(toolProgrammed); - } else { -/* - if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { - error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + - toolNameList.join("\r\n") + "#####################################\r\n"); - } -*/ - } - } - } - - return toolDescriptionArray; -} - -function createToolDescription(tool) { - var toolProgrammed = "@ ToolDescription : " + - "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + - "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + - "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + - "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + - "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + - "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + - "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + - "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + - "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + - "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + - "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + - "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + - "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + - "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + - "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + - " @"; - return toolProgrammed; -} - -/** - Generate the logical tool name for the assignment table of used tools. -*/ -function createToolName(tool) { - var toolName = toolFormat.format(tool.number); - toolName += "_" + translateToolType(tool.type); - if (tool.comment) { - toolName += "_" + tool.comment; - } - if (tool.diameter) { - toolName += "_D" + tool.diameter; - } - var description = tool.getDescription(); - if (description) { - toolName += "_" + description; - } - toolName = formatVariable(toolName); - return toolName; -} - -/** - Translate HSM tools to Datron tool categories. -*/ -function translateToolType(toolType) { - - var datronCategoryName = ""; - - toolCategory = toolType; - switch (toolType) { - case TOOL_UNSPECIFIED: - datronCategoryName = "Unspecified"; - break; - case TOOL_DRILL: - datronCategoryName = "Drill"; - break; - case TOOL_DRILL_CENTER: - datronCategoryName = "DrillCenter"; - break; - case TOOL_DRILL_SPOT: - datronCategoryName = "DrillSpot"; - break; - case TOOL_DRILL_BLOCK: - datronCategoryName = "DrillBlock"; - break; - case TOOL_MILLING_END_FLAT: - datronCategoryName = "MillingEndFlat"; - break; - case TOOL_MILLING_END_BALL: - datronCategoryName = "MillingEndBall"; - break; - case TOOL_MILLING_END_BULLNOSE: - datronCategoryName = "MillingEndBullnose"; - break; - case TOOL_MILLING_CHAMFER: - datronCategoryName = "Graver"; - break; - case TOOL_MILLING_FACE: - datronCategoryName = "MillingFace"; - break; - case TOOL_MILLING_SLOT: - datronCategoryName = "MillingSlot"; - break; - case TOOL_MILLING_RADIUS: - datronCategoryName = "MillingRadius"; - break; - case TOOL_MILLING_DOVETAIL: - datronCategoryName = "MillingDovetail"; - break; - case TOOL_MILLING_TAPERED: - datronCategoryName = "MillingTapered"; - break; - case TOOL_MILLING_LOLLIPOP: - datronCategoryName = "MillingLollipop"; - break; - case TOOL_TAP_RIGHT_HAND: - datronCategoryName = "TapRightHand"; - break; - case TOOL_TAP_LEFT_HAND: - datronCategoryName = "TapLeftHand"; - break; - case TOOL_REAMER: - datronCategoryName = "Reamer"; - break; - case TOOL_BORING_BAR: - datronCategoryName = "BoringBar"; - break; - case TOOL_COUNTER_BORE: - datronCategoryName = "CounterBore"; - break; - case TOOL_COUNTER_SINK: - datronCategoryName = "CounterSink"; - break; - case TOOL_HOLDER_ONLY: - datronCategoryName = "HolderOnly"; - break; - case TOOL_PROBE: - datronCategoryName = "XYZSensor"; - break; - default: - datronCategoryName = "Unspecified"; - } - return datronCategoryName; -} - -function writeProgramHeader() { - // write creation Date - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - SetWriteRedirection(SimPLProgram.moduleName); - writeComment("!File ; generated at " + date + " - " + time); - if (programComment) { - writeComment(formatComment(programComment)); - } - - writeBlock(" "); - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - - writeBlock("module " + "CamGeneratedModule"); - writeBlock(" "); - - writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); - ResetWriteRedirection(); - - // set the table of used tools in the header of the program - SimPLProgram.toolDescriptionList = createToolDescriptionTable(); - - // set the workpiece information - SimPLProgram.workpieceGeometry = writeWorkpiece(); - - // set the sequence header in the program file - if (properties.useSequences) { - var sequences = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (!isProbeOperation(section)) { - sequences.push("sequence " + getSequenceName(section)); - } - } - if (properties.useExternalSequencesFiles) { - writeBlock("@ EmbeddedSequences = false @"); - } - - SimPLProgram.sequenceList = sequences; - } - - // set usings - SimPLProgram.usingList.push("using Base"); - if (properties.rotationAxisSetup != "NONE"){ - SimPLProgram.usingList.push("using Rtcp"); - } - if (properties.waitAfterOperation) { - SimPLProgram.usingList.push("import System"); - } - - // set paramtric feed variables - //var feedDeclaration = new Array(); - var currentMovements = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (properties.useParametricFeed && (!useDatronFeedCommand)) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (SimPLProgram.globalVariableList.indexOf(feedDescription + ":number") == -1) { - SimPLProgram.globalVariableList.push(feedDescription + ":number"); - } - } - } - } - - // if (!useDatronFeedCommand) { - // if (feedDeclaration != 0) { - // SimPLProgram.globalVariableList.push(feedDeclaration); - // } - // } - SetWriteRedirection(SimPLProgram.mainProgram); - writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); - spacingDepth += 1; - writeBlock("Absolute"); - - // ste the multiaxis mode - if(properties.rotationAxisSetup != "NONE" && properties.useRtcp){ - writeBlock("MultiAxisMode On"); - } - - // set the parameter tool table - SimPLProgram.globalVariableList.push(createToolVariables()); - - if (!properties.writeToolTable) { - var tools = getToolTable(); - writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + dimensionFormat.format(tool.diameter) + " " + - "L2:" + dimensionFormat.format(tool.fluteLength) + " " + - "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + - "ProductID:" + formatComment(tool.productId); - writeBlock(toolAsigment); - } - writeBlock(" "); - } - } - ResetWriteRedirection(); -} - - -function writeWorkpiece() { - var workpieceString = new StringBuffer(); - SetWriteRedirection(workpieceString); - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - - writeBlock("# Workpiece dimensions"); - writeBlock( - "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z)); - writeBlock( - "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z)); - writeBlock( - "# Part size X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z)); - - writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + - "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + - " @"); - ResetWriteRedirection(); - return workpieceString; -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, datronFeedName, feed) { - this.id = id; - this.description = description; - this.datronFeedName = datronFeedName; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; - } -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - if (useDatronFeedCommand) { - return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); - } else { - return ("Feed=" + formatVariable(feedContext.description)); - } - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return "Feed=" + feedFormat.format(f); - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - var id = 0; - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - addFeedContext(feedContext, activeFeeds); - } - ++id; - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - - // this part allows us to use feedContext also for the cycles - if (hasParameter("operation:cycleType")) { - var cycleType = getParameter("operation:cycleType"); - if (hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - - switch (cycleType) { - case "thread-milling": - if (hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:ramp")) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:finish_cutting")) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - break; - case "bore-milling": - if (section.hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (section.hasParameter("movement:ramp")) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:finish_cutting")) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - break; - } - } - - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -/** Check that all elements are only one time in the result list. */ -function addFeedContext(feedContext, activeFeeds) { - if (activeFeeds.indexOf(feedContext) == -1) { - activeFeeds.push(feedContext); - } -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - forceWorkPlane(); // always need the new workPlane - forceABC(); - if((properties.rotationAxisSetup != "NONE") && properties.useRtcp){ - writeBlock("MoveToSafetyPosition"); - }else{ - writeBlock("MoveToSafetyPosition"); - } - writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); - - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function onSection() { - // this is the container that hold all operation informations... - currentOperation = new NewOperation(getOperationName(currentSection)) - SetWriteRedirection(currentOperation.operationProgram); - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - var tool = currentSection.getTool(); - - if (!isProbeOperation(currentSection) && hasParameter("operation:cycleTime")) { - writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); - } - - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = currentSection.getGlobalZRange(); - var number = tool.number; - zRange.expandToRange(currentSection.getGlobalZRange()); - writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); - } - } - - // create sub program - writeBlock("program " + getOperationName(currentSection)); - spacingDepth += 1; - - if (passThrough) { - var joinString = "\r\n" + getSpacing(); - var passThroughString = passThrough.join(joinString); - if (passThroughString != "") { - writeBlock(passThroughString); - } - passThrough = []; - } - - // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. - writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); - var operationTolerance = tolerance; - if (hasParameter("operation:tolerance")) { - if (operationTolerance < getParameter("operation:tolerance")) { - operationTolerance = getParameter("operation:tolerance"); - } - } - - //load the matching workOffset - var workOffset = currentSection.getWorkOffset(); - if (workOffset != 0) { - writeBlock("LoadWcs name=\"" + workOffset +"\""); - } - - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); - } else - { - writeBlock("Smoothing Off"); - } - - if (properties.useDynamic) { - var dynamic = 5; - operationName = getOperationName(currentSection).toUpperCase(); - dynamicIndex = operationName.lastIndexOf("DYN") + 3; - expliciteDynamic = parseInt(operationName.substring(dynamicIndex,dynamicIndex+1)) - if ((expliciteDynamic != NaN) && (expliciteDynamic> 0 && expliciteDynamic < 6)){ - writeBlock("Dynamic = " + expliciteDynamic + " # Created from Operation Name"); - dynamic = expliciteDynamic - } else { - // set machine type specific dynamic sets - switch(properties.machineType){ - case 'NEO': - dynamic =5; - break; - case 'MX': - case 'CUBE': - if (operationTolerance <= (unit == MM ? 0.04 : (0.04/25.4))) { - dynamic = 4; - } - if (operationTolerance <= (unit == MM ? 0.02 : (0.02/25.4))) { - dynamic = 3; - } - if (operationTolerance <= (unit == MM ? 0.005 : (0.005/25.4))) { - dynamic = 2; - } - if (operationTolerance <= (unit == MM ? 0.003 : (0.003/25.4))) { - dynamic = 1; - } - break; - } - writeBlock("Dynamic = " + dynamic); - } - } - - if (properties.waitAfterOperation) { - showWaitDialog(getOperationName(currentSection)); - } - - if (machineConfiguration.isMultiAxisConfiguration()) { - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - if((properties.rotationAxisSetup != "NONE") && properties.useRtcp){ - writeBlock("Rtcp On"); - } - writeBlock("MoveToSafetyPosition"); - writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); - } else { - forceWorkPlane(); - var abc = getWorkPlaneMachineABC(currentSection.workPlane); - - setWorkPlane(abc); - if((properties.rotationAxisSetup != "NONE") && properties.useRtcp){ - writeBlock("Rtcp On"); - } - } - } else { - // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - error("\r\n_________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| Tool orientation detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| rotationAxisSetup |" + - "\r\n| rotherwise you can only post |" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|________________________________________|\r\n"); - return; - } - setRotation(remaining); - } - - forceAny(); - - if (properties.showNotes && currentSection.hasParameter("notes")) { - var notes = currentSection.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - - var clearance = getFramePosition(currentSection.getInitialPosition()).z; - writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); - - - // write the optional length offset for each operation - if(properties.useZAxisOffset){ - writeBlock("ZAxisOffset = 0"); - } - - // radius Compensation - var compensationType - if(hasParameter('operation:compensationType')){ - compensationType = getParameter('operation:compensationType'); - } else { - compensationType = 'computer'; - } - - var wearCompensation - if(hasParameter('operation:compensationDeltaRadius')){ - wearCompensation = getParameter('operation:compensationDeltaRadius'); - } else { - wearCompensation = 0; - } - - if(properties.writePathOffset){ - switch( compensationType){ - case 'computer': - break; - case 'control': - writeBlock("PathOffset = 0") - break; - case 'wear': - writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); - break; - case 'inverseWear': - writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); - break; - } - } - - if (!isProbeOperation(currentSection)) { - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - - // tool changer command - if (properties.writeToolTable) { - writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + - " newRpm=" + rpmFormat.format(spindleSpeed) + - " skipRestoring" - ); - } else { - writeBlock("Tool = " + toolOutput.format(tool.number) + - " newRpm=" + rpmFormat.format(spindleSpeed) + - " skipRestoring" - ); - } - - //preload the next tool for the Datron tool assist - if(properties.preloadTool){ - var nextTool = getNextTool(tool.number); - if(nextTool){ - if (properties.writeToolTable) { - writeBlock("ProvideTool name=" + "\"" + createToolName(nextTool) + "\""); - } else { - writeBlock("ProvideTool = " + toolOutput.format(nextTool.number)); - } - } - } - - // set the current feed - // replace by the default feed command - if (properties.useParametricFeed && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - activeFeeds = initializeActiveFeeds(currentSection); - if (useDatronFeedCommand) { - var datronFeedParameter = new Array(); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var datronFeedCommand = { - name : feedContext.datronFeedName, - feed : feedFormat.format(feedContext.feed) - }; -/*eslint-disable*/ - var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); -/*eslint-enable*/ - if (indexOfFeedContext == -1) { - datronFeedParameter.push(datronFeedCommand); - } else { - var existingFeedContext = datronFeedParameter[indexOfFeedContext]; - if (existingFeedContext.feed < datronFeedCommand.feed) { - existingFeedContext.feed = datronFeedCommand.feed; - } - } - } - var datronFeedCommand = "SetFeedTechnology"; - for (var i = 0; i < datronFeedParameter.length; i++) { - datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; - } - writeBlock(datronFeedCommand); - - } else { - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); - } - } - } - } - - // parameter for the sequences - var sequenceParamter = new Array(); - - if (hasParameter("operation:cycleType")) { - - //Reset all movements to suppress older entries... - activeMovements = new Array(); - - var cycleType = getParameter("operation:cycleType"); - writeComment("Parameter " + cycleType + " cycle"); - - switch (cycleType) { - case "thread-milling": - writeBlock("SetFeedTechnology" + " ramp=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:finish_cutting"))); - var diameter = currentSection.getParameter("diameter"); - var pitch = currentSection.getParameter("pitch"); - var finishing = parseFloat(currentSection.getParameter("stepover")); - - writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); - sequenceParamter.push("nominalDiameter=nominalDiameter"); - writeBlock("pitch=" + xyzFormat.format(pitch)); - sequenceParamter.push("pitch=pitch"); - - if (!isNaN(finishing)) { - writeBlock("finishing=" + xyzFormat.format(finishing)); - sequenceParamter.push("finishing=finishing"); - } else { - sequenceParamter.push("finishing=0"); - } -/* - writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); - sequenceParamter.push('threadName=threadName'); - writeBlock("threading = " + currentSection.getParameter("threading")); - sequenceParamter.push("threading=threading"); - - TAG: den Standard auch mit Imperial unterstuezten - sequenceParamter.push("threadStandard=ThreadStandards.Metric"); - sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); - sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); - sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); - writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); - sequenceParamter.push("direction=direction"); - writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); - sequenceParamter.push("repeatPass=repeatPass"); -*/ - break; - case "bore-milling": - writeBlock("SetFeedTechnology roughing=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:cutting"))); - writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); - sequenceParamter.push("diameter=diameter"); - - writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); - sequenceParamter.push("infeedZ=infeedZ"); - writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); - sequenceParamter.push("repeatPass=repeatPass"); - break; - case "drilling": - writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge"))); - break; - case "chip-breaking": - writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge")) + " roughing=" + feedFormat.format(getParameter("movement:plunge"))); - writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); - sequenceParamter.push("infeedZ=infeedZ"); - break; - } - } - - if (properties.useSequences && !isProbeOperation(currentSection)) { - // call sequence - if (properties.useParametricFeed && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - activeFeeds = initializeActiveFeeds(currentSection); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - sequenceParamter.push(formatVariable(feedContext.description) + "=" + formatVariable(feedContext.description)); - } - } - var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); - writeBlock(currentSectionCall); - - // write sequence - var currentSequenceName = getSequenceName(currentSection); - if (properties.useExternalSequencesFiles) { - spacingDepth -= 1; - var filename = getOutputPath(); - //sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; - sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; - sequenceFilePath += currentSequenceName + ".seq"; - redirectToFile(sequenceFilePath); - } else { - SetWriteRedirection(sequenceBuffer); - writeBlock(" "); - // TAG: modify parameter - spacingDepth -= 1; - writeBlock("$$$ " + currentSequenceName); - } - } - - if (!isProbeOperation(currentSection)) { - writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); - } else { - writeBlock("Spindle Off"); - writeBlock("PrepareXyzSensor"); - } - - // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); - - writeBlock("PrePositioning" + xyz); - - // adds support for suction - if(properties.useSuction){ - writeBlock("Suction On"); - } - -} - - -function showWaitDialog(operationName) { - writeBlock("showWaitDialog operationName=\"" + operationName + "\""); -} - -function writeWaitProgram() { - waitProgram = new Array(); - waitProgram.push("#Show the wait dialog for the next operation\r\n"); - waitProgram.push("program showWaitDialog optional operationName:string\r\n"); - waitProgram.push(" if not operationName hasvalue \r\n"); - waitProgram.push(" operationName =" + "\"" + "\"\r\n"); - waitProgram.push(" endif\r\n"); - waitProgram.push("\r\n"); - waitProgram.push(" messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName \r\n"); - waitProgram.push(" dialogRes = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel\r\n"); - waitProgram.push(" if dialogRes == System::DialogResult.Cancel\r\n"); - waitProgram.push(" exit\r\n"); - waitProgram.push(" endif\r\n"); - waitProgram.push("endprogram\r\n"); - - waitProgramOperation = {operationProgram: waitProgram}; - SimPLProgram.operationList.push(waitProgramOperation) -} - -function onDwell(seconds) { - writeBlock("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); -} - -function onSpindleSpeed(spindleSpeed) { - // writeBlock("Rpm=" + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed)); - writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(x, y, z) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock("Rapid" + xyz); - forceFeed(); - } -} - -function onPrePositioning(x, y, z) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock("PrePositioning" + xyz); - forceFeed(); - } -} - -function onLinear(x, y, z, feed) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - var f = getFeed(feed); - - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - var d = tool.diameterOffset; - if (d > 99) { - warning(localize("The diameter offset exceeds the maximum value.")); - } - // TAG: um die Ebenen kuemmern - // writeBlock(gPlaneModal.format(17)); - var compensationType = null; - if( currentSection.hasParameter("operation:compensationType")){ - compensationType = currentSection.getParameter("operation:compensationType"); - } - - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - switch(compensationType){ - case 'control': - writeBlock("ToolCompensation Left"); - writeBlock("PathCorrection Left"); - break; - case 'wear': - case 'inverseWear': - writeBlock("PathCorrection Left"); - break; - default: - writeBlock("ToolCompensation Off"); - writeBlock("PathCorrection Off"); - break; - } - break; - case RADIUS_COMPENSATION_RIGHT: - switch(compensationType){ - case 'control': - writeBlock("ToolCompensation Rigth"); - writeBlock("PathCorrection Rigth"); - break; - case 'wear': - case 'inverseWear': - writeBlock("PathCorrection Rigth"); - break; - default: - writeBlock("ToolCompensation Off"); - writeBlock("PathCorrection Off"); - break; - } - break; - case RADIUS_COMPENSATION_OFF: - writeBlock("ToolCompensation Off"); - writeBlock("PathCorrection Off"); - break; - } - } - - if (xyz) { - if (f) { - writeBlock(f); - } - writeBlock("Line" + xyz); - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - // one of X/Y and I/J are required and likewise - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - - if (pendingRadiusCompensation >= 0) { - error(localize("radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (isHelical()) { - linearize(tolerance); - return; - } - // TAG: are 360deg arcs supported - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } else { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - yOutput.format(y) + - zOutput.format(z) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = aOutput.format(_a); - var b = bOutput.format(_b); - var c = cOutput.format(_c); - - forceABC(); - var xyzabc = x + y + z + a + b + c; - writeBlock("Rapid" + xyzabc); - forceFeed(); -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = aOutput.format(_a); - var b = bOutput.format(_b); - var c = cOutput.format(_c); - var f = getFeed(feed); - - if(f){ - writeBlock(f); - } - if (x || y || z || a || b || c) { - var xyzabc = x + y + z + a + b + c; - writeBlock("Line" + xyzabc); - }; - //else if (f) { - // if (getNextRecord().isMotion()) { // try not to output feed without motion - // forceFeed(); // force feed on next line - // } else { - // writeBlock(getFeed(feed)); - // } - // } -} - -function onRewindMachine(a, b, c) { - writeBlock("MoveToSafetyPosition"); - var abc = aOutput.format(a) + bOutput.format(b) + cOutput.format(c); - writeBlock("Line" + abc); -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (properties.writeCoolantCommands) { - if (coolant == COOLANT_OFF) { - writeBlock("SpraySystem Off"); - currentCoolantMode = COOLANT_OFF; - return; - } - - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - writeBlock("SprayTechnology External"); - writeBlock("Coolant Alcohol"); - break; - case COOLANT_AIR: - writeBlock("SprayTechnology External"); - writeBlock("Coolant Air"); - break; - case COOLANT_THROUGH_TOOL: - writeBlock("SprayTechnology Internal"); - writeBlock("Coolant Alcohol"); - break; - case COOLANT_AIR_THROUGH_TOOL: - writeBlock("SprayTechnology Internal"); - writeBlock("Coolant Air"); - break; - - default: - onUnsupportedCoolant(coolant); - } - writeBlock("SpraySystem On"); - currentCoolantMode = coolant; - } -} - -var isInsideProgramDeclaration = false; -var directNcOperation; -function ParseManualNc(text){ - - var modulePattern = new RegExp("\.*(using|import)"); - var isModuleImport = modulePattern.test(text); - if(isModuleImport){ - SimPLProgram.usingList.push(text); - return; - } - - var programPattern = /(?:\s*program\s+)(\w+)/; - var isProgramDeclaration = programPattern.test(text); - - if(isProgramDeclaration){ - var subProgramName = programPattern.exec(text); - if(subProgramName == undefined) return; - directNcOperation = {operationCall:subProgramName[1],operationProgram: new StringBuffer()}; - SimPLProgram.operationList.push(directNcOperation); - isInsideProgramDeclaration = true; - } - - var isEndProgram = /\s*endprogram/.test(text); - if(isEndProgram){ - isInsideProgramDeclaration = false; - directNcOperation.operationProgram.append(text + "\r\n"); - return; - } - - if (isInsideProgramDeclaration){ - directNcOperation.operationProgram.append(text + "\r\n"); - return; - } - - return text; -} - -function onManualNC(command, value) { - switch (command) { - case 42: // Manual NC enumeration code ??? - value = ParseManualNc(value); - break; - case 40: // Comment - value = "# " + value; - break; - case 41: //wait - value = "Sleep seconds=" + value; - break; - case COMMAND_COOLANT_OFF: - value = "SpraySystem Off"; - break; - case COMMAND_COOLANT_ON: - value = "SpraySystem On"; - break; - case COMMAND_STOP: - value = "break"; - break; - case COMMAND_START_SPINDLE: - value = "Spindle On"; - break; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - value = "ChipConveyor On"; - break; - case COMMAND_STOP_CHIP_TRANSPORT: - value = "ChipConveyor Off"; - break; - case COMMAND_OPEN_DOOR: //open door - value = "ReleaseDoor"; - break; - case COMMAND_CLOSE_DOOR: //close door not needed - return; - case COMMAND_CALIBRATE: //calibrate - value = "# calibration currently not supported!"; - break; - case COMMAND_VERIFY: // check part - value = 'Dialog message="Please check workpiece!" Ok Cancel caption="Cam generated dialog"' - break; - case COMMAND_CLEAN: // clean part - value = 'Dialog message="Please clean workpiece!" Ok Cancel caption="Cam generated dialog"' - break; - case 43: // action no idea for what has a paramter - value = "# Action currently not supported!" - break; - case 44: // print message - // value = 'Dialog message="' + value + '" Ok Cancel caption="Cam generated dialog"' - SimPLProgram.usingList.push('using File'); - SimPLProgram.usingList.push('using DateTimeModule') - var message = (' value=(GetNow + "\t' + value + '")') - value = 'FileWriteLine filename="' + getFilename() + '.log"' + message; - break; - case 46: // show message - value = 'StatusMessage message="' + value + '"'; - break; - case COMMAND_ALARM: // alarm - value = 'Dialog message="Alarm!" Ok Cancel caption="Cam generated dialog"' - break; - case COMMAND_ALERT: // alarm - value = 'Dialog message="Warning!" Ok Cancel caption="Cam generated dialog"' - break; - case COMMAND_BREAK_CONTROL: - value = "MeasureToolLength" - break; - case COMMAND_TOOL_MEASURE: - value = "MeasureToolLength" - break; - case COMMAND_OPTIONAL_STOP: - value = "OptionalBreak"; - break; - case 45: //call subprogram - var subprogramName = "SubProgram_" + SimPLProgram.externalUsermodules.length; - SimPLProgram.externalUsermodules.push('usermodule ' + subprogramName + '="' + value + '"'); - value = subprogramName; - break; - } - - if(value != undefined){ - var operation = {operationCall: value, operationProgram:""} - SimPLProgram.operationList.push(operation); - } -} - -var mapCommand = {}; - -var passThrough = new Array(); -function onPassThrough(text) { - passThrough.push(text); -} - -function onCommand(command) { - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onCycle() { -} - -function onCycleEnd() { -} - -function isProbeOperation(section) { - return (section.hasParameter("operation-strategy") && section.getParameter("operation-strategy") == "probe"); -} - -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - var feedString = feedOutput.format(cycle.feedrate); - - if (isProbeOperation(currentSection)) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } - - var startPositionOffset = cycle.probeClearance + tool.cornerRadius; - } - - switch (cycleType) { - case "bore-milling": - for (var i = 0; i <= cycle.repeatPass; ++i) { - forceXYZ(); - onRapid(x, y, cycle.clearance); - boreMilling(cycle); - onRapid(x, y, cycle.clearance); - } - break; - case "thread-milling": - for (var i = 0; i <= cycle.repeatPass; ++i) { - forceXYZ(); - onRapid(x, y, cycle.clearance); - threadMilling(cycle); - onRapid(x, y, cycle.clearance); - } - break; - case "drilling": - forceXYZ(); - onRapid(x, y, cycle.clearance); - drilling(cycle); - onRapid(x, y, cycle.clearance); - break; -/* - case "chip-breaking": - forceXYZ(); - onRapid(x, y, null); - onRapid(x, y, cycle.retract); - chipBreaking(cycle); - onRapid(x, y, cycle.clearance); - break; -*/ - - case "tapping": - case "left-tapping": - case "right-tapping": - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceXYZ(); - onRapid(x, y, cycle.clearance); - tapping(cycle); - onRapid(x, y, cycle.clearance); - break; - case "probing-x": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - break; - case "probing-y": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - break; - case "probing-z": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); - - var measureString = "SurfaceMeasure "; - measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); - writeBlock(measureString); - break; - case "probing-x-wall": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " YAligned"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-y-wall": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " XAligned"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-x-channel": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " YAligned"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-x-channel-with-island": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " YAligned"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-y-channel": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " XAligned"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-y-channel-with-island": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " XAligned"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-boss": - var measureString = "CircleMeasure"; - measureString += " diameter=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-hole": - var measureString = "CircleMeasure"; - measureString += " diameter=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-hole-with-island": - var measureString = "CircleMeasure"; - measureString += " diameter=" + xyzFormat.format(cycle.width1); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-boss": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + xyzFormat.format(cycle.width1); - measureString += " dimensionY=" + xyzFormat.format(cycle.width2); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " Center"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-hole": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + xyzFormat.format(cycle.width1); - measureString += " dimensionY=" + xyzFormat.format(cycle.width2); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " Center"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-hole-with-island": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + xyzFormat.format(cycle.width1); - measureString += " dimensionY=" + xyzFormat.format(cycle.width2); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " Center"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-inner-corner": - var probingDepth = (z - cycle.depth + tool.cornerRadius); - var measureString = "EdgeMeasure "; - - zOutput.reset(); - onRapid(x, y, cycle.stock); - onLinear(x, y, probingDepth, cycle.feedrate); - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + cycle.probeClearance; - writeBlock(measureString); - - forceXYZ(); - //zOutput.reset(); - onRapid(x, y, cycle.stock); - onLinear(x, y, probingDepth, cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; - // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; - - // var orientation = "" - // if (!isXNeagtive && !isYNeagtive) orientation = "BackRight"; - // if (isXNeagtive && !isYNeagtive) orientation = "BackLeft"; - // if (!isXNeagtive && isYNeagtive) orientation = "FrontRight"; - // if (isXNeagtive && isYNeagtive) orientation = "FrontLeft"; - - // var measureString = "CornerMeasure"; - // measureString += " " + orientation; - // measureString += " Inside"; - // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " forceSafeHeight" - // measureString += " skipZMeasure"; - // measureString += " originXShift=" + xyzFormat.format(-x); - // measureString += " originYShift=" + xyzFormat.format(-y); - // writeBlock(measureString); - break; - case "probing-xy-outer-corner": - var probingDepth = (z - cycle.depth + tool.cornerRadius); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var measureString = "EdgeMeasure "; - - zOutput.reset(); - onRapid(x, y, probingDepth); - onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - writeBlock(measureString); - forceXYZ(); - onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); - onLinear(x, y, probingDepth, cycle.feedrate); - //forceXYZ(); - //zOutput.reset(); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - measureString += " retractDistance=" + xyzFormat.format(cycle.retract); - writeBlock(measureString); - forceXYZ(); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - onLinear(x, y, probingDepth, cycle.feedrate); - - // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; - // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; - - // var orientation = "" - // if (!isXNeagtive && !isYNeagtive) orientation = "FrontLeft"; - // if (isXNeagtive && !isYNeagtive) orientation = "FrontRight"; - // if (!isXNeagtive && isYNeagtive) orientation = "BackLeft"; - // if (isXNeagtive && isYNeagtive) orientation = "BackRight"; - - // var measureString = "CornerMeasure"; - // measureString += " " + orientation; - // measureString += " Outside"; - // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " forceSafeHeight" - // measureString += " skipZMeasure"; - // measureString += " originXShift=" + xyzFormat.format(-x); - // measureString += " originYShift=" + xyzFormat.format(-y); - // writeBlock(measureString); - break; - case "probing-x-plane-angle": - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - // var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - // var touchPositionX2 = touchPositionX1; - // writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - // writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - // writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - // writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - // writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - // var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - // var touchPositionY2 = touchPositionY1; - // writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - // writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - // writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - // writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - // writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - return; - } - - // save probing result in defined wcs - if(isProbeOperation(currentSection) && currentSection.workOffset != null){ - writeBlock('SaveWcs name="' + currentSection.workOffset + '"'); - } - - return; -} - -function drilling(cycle) { - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - boreCommandString.push("Drill"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - writeBlock(boreCommandString.join(" ")); -} - -function chipBreaking(cycle) { - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - boreCommandString.push("Drill"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - boreCommandString.push("infeedZ=infeedZ"); - writeBlock(boreCommandString.join(" ")); -} - -function boreMilling(cycle) { - if (cycle.numberOfSteps > 2) { - error("Only 2 steps are allowed for bore-milling."); - } - - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - boreCommandString.push("DrillMilling"); - boreCommandString.push("diameter=diameter"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("infeedZ=infeedZ"); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - - if (cycle.numberOfSteps == 2) { - var xycleaning = cycle.stepover; - var maxzdepthperstep = tool.fluteLength * 0.8; - boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); - boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); - } - var bottomcleaning = 0; - // finishingZ = 1; - writeBlock(boreCommandString.join(" ")); -} - -function threadMilling(cycle) { - var threadString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - threadString.push("SpecialThread"); - // threadString.push('threadName=threadName'); - threadString.push("nominalDiameter=nominalDiameter"); - threadString.push("pitch=pitch"); - threadString.push("depth=" + depth); - threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - // threadString.push("threadStandard=threadStandard"); - if(properties.createThreadChamfer){ - threadString.push("Deburring"); - } - // ; - // threadString.push("insideOutside=ThreadMillingSide.Inside"); - threadString.push("finishing=finishing"); - if (cycle.threading == "left") { - threadString.push("direction=ThreadMillingDirection.LeftHandThread"); - } else { - threadString.push("direction=ThreadMillingDirection.RightHandThread"); - } - writeBlock(threadString.join(" ")); -} - -function tapping(cycle) { - var tappingString = new Array(); - var depth = xyzFormat.format(cycle.depth); - tappingString.push("ThreadCutting"); - tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); - tappingString.push("depth=" + depth); - tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); - if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { - tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); - } - if (tool.type == TOOL_TAP_LEFT_HAND) { - tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); - } else { - tappingString.push("direction=ThreadMillingDirection.RightHandThread"); - } - writeBlock(tappingString.join(" ")); -} - -function formatCycleTime(cycleTime) { - // cycleTime = cycleTime + 0.5; // round up - var seconds = cycleTime % 60 | 0; - var minutes = ((cycleTime - seconds)/60 | 0) % 60; - var hours = (cycleTime - minutes * 60 - seconds)/(60 * 60) | 0; - if (hours > 0) { - return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); - } else if (minutes > 0) { - return subst(localize("%1m:%2s"), minutes, seconds); - } else { - return subst(localize("%1s"), seconds); - } -} - -function dump(name, _arguments) { - var result = getCurrentRecordId() + ": " + name + "("; - for (var i = 0; i < _arguments.length; ++i) { - if (i > 0) { - result += ", "; - } - if (typeof _arguments[i] == "string") { - result += "'" + _arguments[i] + "'"; - } else { - result += _arguments[i]; - } - } - result += ")"; - writeln(result); -} - -function onSectionEnd() { - writeBlock("ToolCompensation Off"); - writeBlock("PathCorrection Off"); - - // reset Z Offset value - if(properties.useZAxisOffset){ - writeBlock("ZAxisOffset = 0"); - } - - - if (currentSection.isMultiAxis && (properties.rotationAxisSetup != "NONE") && properties.useRtcp){ - writeBlock("Rtcp Off"); - } - - // adds support for suction - if(properties.useSuction){ - writeBlock("Suction Off"); - } - - if (properties.useSequences && !isProbeOperation(currentSection)) { - if (!properties.useExternalSequencesFiles) { - ResetWriteRedirection(); - } - spacingDepth += 1; - } - - - writeBlock("EndBlock"); - - spacingDepth -= 1; - - writeBlock("endprogram " + "# " + getOperationName(currentSection)); - ResetWriteRedirection(); - SimPLProgram.operationList.push(currentOperation); - forceAny(); -} - -function onClose() { - - if (properties.waitAfterOperation) { - writeWaitProgram(); - } - - writeBlock(SimPLProgram.moduleName); - writeBlock(""); - writeBlock(SimPLProgram.toolDescriptionList.join("\r\n") + "\r\n"); - writeBlock(""); - writeBlock(SimPLProgram.workpieceGeometry); - writeBlock(""); - writeBlock(SimPLProgram.sequenceList.join("\r\n") + "\r\n"); - writeBlock(""); - writeBlock(SimPLProgram.usingList.join("\r\n") + "\r\n"); - writeBlock(""); - writeBlock(SimPLProgram.externalUsermodules.join("\r\n") + "\r\n"); - writeBlock(""); - writeBlock(SimPLProgram.globalVariableList.join("\r\n") + "\r\n"); - writeBlock(""); - - finishMainProgram(); - writeBlock(SimPLProgram.mainProgram); - writeBlock(""); - - SimPLProgram.operationList.forEach(function (operation){ - if(operation != undefined){ - writeBlock(operation.operationProgram); - } - }) - - writeBlock("end"); - - if (properties.useSequences && !properties.useExternalSequencesFiles) { - writeComment(spacing); - writeBlock(sequenceBuffer.toString()); - } -} - -// after all the oiperation calls are set close the main program with all the calls -function finishMainProgram(){ - // write the main program footer - SetWriteRedirection(SimPLProgram.mainProgram); - spacingDepth += 1; - - // write all subprogram calls in the main Program - SimPLProgram.operationList.forEach(function(operation){ - if(operation!=undefined){ - writeBlock(operation.operationCall); - } - }) - - if (properties.writeCoolantCommands) { - writeBlock("SpraySystem Off"); - } - - if(properties.rotationAxisSetup != "NONE" && properties.useRtcp){ - writeBlock("MultiAxisMode Off"); - writeBlock("Rtcp Off"); - } - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - if (properties.useParkPosition) { - writeBlock("Spindle Off"); - writeBlock("MoveToParkPosition"); - } else { - writeBlock("MoveToSafetyPosition"); - zOutput.reset(); - } - - spacingDepth -= 1; - writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); - ResetWriteRedirection(); -} - - +/** + Copyright (C) 2012-2018 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} +*/ + +description = "DATRON next"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 40783; + +longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; + +extension = "simpl"; +setCodePage("utf-8"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = true; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + + +// user-defined properties +properties = { + writeMachine : true, // write machine + showNotes : false, // specifies that operation notes should be output + useSmoothing : true, // specifies if smoothing should be used or not + useDynamic : true, // specifies using dynamic mode or not + machineType : "NEO", // specifiees the DATRON machine type + useParkPosition : true, // specifies to use park position at the end of the program + writeToolTable : true, // write the table with the geometric tool informations + useSequences : true, // this use a sequence in the output format to perform on large files + useExternalSequencesFiles : false, // this property create one external sequence files for each operation + writeCoolantCommands : true, // disable the coolant commands in the file + useParametricFeed : true, // specifies that feed should be output using parameters + waitAfterOperation : false, // optional stop + rotationAxisSetup : "none", // define the rotatry axis setup for the machine + useSuction: false, // activate suction support + createThreadChamfer: false, // create a chamfer with the thread milling tool + preloadTool : false, //prepare a Tool for the DATROn tool assist + writePathOffset : true, //write the definition for the PathOffset variable for every Operation + useZAxisOffset : false, + useRtcp : false // use the NEXT feature RTCP for multiaxis operations +}; + + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Specifies if smoothing should be used or not.", type:"boolean"}, + useDynamic: {title:"Dynamic mode", description:"Specifies the using of dynamic mode or not.", type:"boolean"}, + machineType:{title:"Machine type", description:"Specifies the DATRON machine type.", type:"enum", + values:[ + {title:"NEO",id:"NEO"}, + {title:"MX Cube",id:"MX"}, + {title:"Cube",id:"Cube"} + ]}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + writeToolTable: {title:"Write tool table", description:"Write a tool table containing geometric tool information.", group:0, type:"boolean"}, + useSequences: {title:"Use sequences", description:"If enables, sequences are used in the output format on large files.", type:"boolean"}, + useExternalSequencesFiles: {title:"Use external sequence files", description:"If enabled, an external sequence file is created for each operation.", type:"boolean"}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + waitAfterOperation: {title:"Wait after operation", description:"If enabled, an optional stop is outputted to pause after each operation.", type:"boolean"}, + rotationAxisSetup : {title:"Setup rotary axis",description:"define if the machine is setup with additional rotary axis.", type:"enum", + values:[ + {title:"No rotary axis",id:"NONE"}, + {title:"4th axis along X+",id:"4th"}, + {title:"DST (4th & 5th axis)",id:"DST"} + ]}, + useSuction: {title:"Use Suction", description:"Enable the suction for every operation.", type:"boolean"}, + createThreadChamfer: {title:"Create a Thread Chamfer",description:"create a chamfer with the thread milling tool", type:"boolean"}, + preloadTool:{title:"Preload the next Tool", description:"Preload the next Tool in the DATRON Tool assist.", type: "boolean"}, + writePathOffset:{title:"Write Path Offset", description:"Write the PathOffset declaration.", type: "boolean"}, + useZAxisOffset:{title:"Output Z Offset command",description:"This creates a command to allow a manual Z offset for each operation.",type:"boolean"}, + useRtcp:{title:"Use RTCP", description:"Use the NEXT 5axis setup correction.",type:"boolean"} +} + +var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); +var toolFormat = createFormat({decimals:0}); +var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); +var rpmFormat = createFormat({decimals:0, scale:1}); +var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); + +var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); +var feedOutput = createVariable({prefix:""}, feedFormat); + +var xOutput = createVariable({prefix:" X="}, xyzFormat); +var yOutput = createVariable({prefix:" Y="}, xyzFormat); +var zOutput = createVariable({prefix:" Z="}, xyzFormat); +var aOutput = createVariable({prefix:" A="}, abcFormat); +var bOutput = createVariable({prefix:" B="}, abcFormat); +var cOutput = createVariable({prefix:" C="}, abcFormat); + +var iOutput = createVariable({prefix:" dX=", force : true}, xyzFormat); +var jOutput = createVariable({prefix:" dY=", force : true}, xyzFormat); +var kOutput = createVariable({prefix:" dZ="}, xyzFormat); + +// fixed settings +var useDatronFeedCommand = false; // unsupported for now, keep false +var language = "de"; // specifies the language, replace with getLangId() +var spacingDepth = 0; +var spacingString = " "; +var spacing = "##########################################################"; + +// buffer for building up a program not serial created +var sequenceBuffer = new StringBuffer(); + +function NewOperation(operationCall){ + this.operationCall = operationCall; + this.operationProgram = new StringBuffer(); + this.operationProgram.append(""); +} +var currentOperation; +function NewSimPLProgram(){ + this.moduleName = new StringBuffer(); + this.measuringSystem = "Metric"; + this.toolDescriptionList = new Array(); + this.workpieceGeometry = ""; + this.sequenceList = new Array(); + this.usingList = new Array(); + this.externalUsermodules = new Array(); + this.globalVariableList = new Array(); + this.mainProgram = new StringBuffer(); + this.operationList = new Array(); +} + +var SimPLProgram = new NewSimPLProgram(); + +// collected state +var currentFeedValue = -1; +var optionalSection = false; +var activeMovements; // do not use by default +var currentFeedId; + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +function getSequenceName(section) { + var sequenceName = ""; + if (properties.useExternalSequencesFiles) { + sequenceName += FileSystem.getFilename(getOutputPath().substr(0, getOutputPath().lastIndexOf("."))) + "_"; + } + sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); + return sequenceName; +} + +function getFilename(){ + var filePath = getOutputPath(); + var filename = filePath.slice(filePath.lastIndexOf("\\")+1, filePath.lastIndexOf(".")); + return filename; +} + +function getOperationName(section) { + return "Operation_" + getOperationDescription(section); +} + +function capitalizeFirstLetter(text) { + return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); +} + +function getSpacing() { + var space = ""; + for (var i = 0; i < spacingDepth; i++) { + space += spacingString; + } + return space; +} + +/** + Redirect the output to an infinite number of buffers ;-) + works like a stack you can use many redirection levels and go back again +*/ +var writeRedirectionStack = new Array(); + +function SetWriteRedirection(redirectionbuffer){ + writeRedirectionStack.push(redirectionbuffer); +} + +function ResetWriteRedirection(){ + return writeRedirectionStack.pop(); +} + +/** + Writes the specified block. +*/ +function writeBlock(arguments) { + var text = getSpacing() + formatWords(arguments); + if (writeRedirectionStack.length == 0){ + writeWords(text); + } else { + writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); + } +} + +/** + Output a comment. +*/ +function writeComment(text) { + if (text) { + text = getSpacing() + "# " + text; + if (writeRedirectionStack.length == 0){ + writeln(text); + } else { + writeRedirectionStack[writeRedirectionStack.length-1].append(text + "\r\n"); + } + } +} + +var charMap = { + "\u00c4" : "Ae", + "\u00e4" : "ae", + "\u00dc" : "Ue", + "\u00fc" : "ue", + "\u00d6" : "Oe", + "\u00f6" : "oe", + "\u00df" : "ss", + "\u002d" : "_", + "\u0020" : "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + text = formatVariable(text); + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); +} + +function onOpen() { + // note: setup your machine here + if (properties.rotationAxisSetup == "4th") { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEO with A Axis"); + machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis + } + + // note: setup your machine here + if (properties.rotationAxisSetup == "DST") { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis,cAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEXT with DST"); + machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + // header of the main program + writeProgramHeader(); + spacingDepth -= 1; + ResetWriteRedirection(); + + // the rest of program main will be set at closing when all the code is analysed +} + +function getOperationDescription(section) { + // creates the name of the operation + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +function createToolVariables() { + var tools = getToolTable(); + var toolVariables = new Array(); + if (tools.getNumberOfTools() > 0 && !properties.writeToolTable) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + toolVariables.push(toolOutput.format(tool.number) + ":number"); + } + } + return toolVariables; +} + +function getNextTool(number) { + var currentSectionId = getCurrentSectionId(); + if (currentSectionId < 0) { + return null; + } + for (var i = currentSectionId + 1; i < getNumberOfSections(); ++i) { + var section = getSection(i); + var sectionTool = section.getTool(); + if (number != sectionTool.number) { + return sectionTool; // found next tool + } + } + return null; // not found +} + +function createToolDescriptionTable() { + if (!properties.writeToolTable) { + return; + } + + var toolDescriptionArray = new Array(); + var toolNameList = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var tool = section.getTool(); + if (tool.type != TOOL_PROBE) { + var toolName = createToolName(tool); + var toolProgrammed = createToolDescription(tool); + if (toolNameList.indexOf(toolName) == -1) { + toolNameList.push(toolName); + toolDescriptionArray.push(toolProgrammed); + } else { +/* + if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { + error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + + toolNameList.join("\r\n") + "#####################################\r\n"); + } +*/ + } + } + } + + return toolDescriptionArray; +} + +function createToolDescription(tool) { + var toolProgrammed = "@ ToolDescription : " + + "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + + "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + + "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + + "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + + "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + + "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + + "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + + "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + + "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + + "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + + "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + + "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + + "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + + "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + + "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + + " @"; + return toolProgrammed; +} + +/** + Generate the logical tool name for the assignment table of used tools. +*/ +function createToolName(tool) { + var toolName = toolFormat.format(tool.number); + toolName += "_" + translateToolType(tool.type); + if (tool.comment) { + toolName += "_" + tool.comment; + } + if (tool.diameter) { + toolName += "_D" + tool.diameter; + } + var description = tool.getDescription(); + if (description) { + toolName += "_" + description; + } + toolName = formatVariable(toolName); + return toolName; +} + +/** + Translate HSM tools to Datron tool categories. +*/ +function translateToolType(toolType) { + + var datronCategoryName = ""; + + toolCategory = toolType; + switch (toolType) { + case TOOL_UNSPECIFIED: + datronCategoryName = "Unspecified"; + break; + case TOOL_DRILL: + datronCategoryName = "Drill"; + break; + case TOOL_DRILL_CENTER: + datronCategoryName = "DrillCenter"; + break; + case TOOL_DRILL_SPOT: + datronCategoryName = "DrillSpot"; + break; + case TOOL_DRILL_BLOCK: + datronCategoryName = "DrillBlock"; + break; + case TOOL_MILLING_END_FLAT: + datronCategoryName = "MillingEndFlat"; + break; + case TOOL_MILLING_END_BALL: + datronCategoryName = "MillingEndBall"; + break; + case TOOL_MILLING_END_BULLNOSE: + datronCategoryName = "MillingEndBullnose"; + break; + case TOOL_MILLING_CHAMFER: + datronCategoryName = "Graver"; + break; + case TOOL_MILLING_FACE: + datronCategoryName = "MillingFace"; + break; + case TOOL_MILLING_SLOT: + datronCategoryName = "MillingSlot"; + break; + case TOOL_MILLING_RADIUS: + datronCategoryName = "MillingRadius"; + break; + case TOOL_MILLING_DOVETAIL: + datronCategoryName = "MillingDovetail"; + break; + case TOOL_MILLING_TAPERED: + datronCategoryName = "MillingTapered"; + break; + case TOOL_MILLING_LOLLIPOP: + datronCategoryName = "MillingLollipop"; + break; + case TOOL_TAP_RIGHT_HAND: + datronCategoryName = "TapRightHand"; + break; + case TOOL_TAP_LEFT_HAND: + datronCategoryName = "TapLeftHand"; + break; + case TOOL_REAMER: + datronCategoryName = "Reamer"; + break; + case TOOL_BORING_BAR: + datronCategoryName = "BoringBar"; + break; + case TOOL_COUNTER_BORE: + datronCategoryName = "CounterBore"; + break; + case TOOL_COUNTER_SINK: + datronCategoryName = "CounterSink"; + break; + case TOOL_HOLDER_ONLY: + datronCategoryName = "HolderOnly"; + break; + case TOOL_PROBE: + datronCategoryName = "XYZSensor"; + break; + default: + datronCategoryName = "Unspecified"; + } + return datronCategoryName; +} + +function writeProgramHeader() { + // write creation Date + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + SetWriteRedirection(SimPLProgram.moduleName); + writeComment("!File ; generated at " + date + " - " + time); + if (programComment) { + writeComment(formatComment(programComment)); + } + + writeBlock(" "); + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + writeBlock("module " + "CamGeneratedModule"); + writeBlock(" "); + + writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); + ResetWriteRedirection(); + + // set the table of used tools in the header of the program + SimPLProgram.toolDescriptionList = createToolDescriptionTable(); + + // set the workpiece information + SimPLProgram.workpieceGeometry = writeWorkpiece(); + + // set the sequence header in the program file + if (properties.useSequences) { + var sequences = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (!isProbeOperation(section)) { + sequences.push("sequence " + getSequenceName(section)); + } + } + if (properties.useExternalSequencesFiles) { + writeBlock("@ EmbeddedSequences = false @"); + } + + SimPLProgram.sequenceList = sequences; + } + + // set usings + SimPLProgram.usingList.push("using Base"); + if (properties.rotationAxisSetup != "NONE"){ + SimPLProgram.usingList.push("using Rtcp"); + } + if (properties.waitAfterOperation) { + SimPLProgram.usingList.push("import System"); + } + + // set paramtric feed variables + //var feedDeclaration = new Array(); + var currentMovements = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (properties.useParametricFeed && (!useDatronFeedCommand)) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (SimPLProgram.globalVariableList.indexOf(feedDescription + ":number") == -1) { + SimPLProgram.globalVariableList.push(feedDescription + ":number"); + } + } + } + } + + // if (!useDatronFeedCommand) { + // if (feedDeclaration != 0) { + // SimPLProgram.globalVariableList.push(feedDeclaration); + // } + // } + SetWriteRedirection(SimPLProgram.mainProgram); + writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + spacingDepth += 1; + writeBlock("Absolute"); + + // ste the multiaxis mode + if(properties.rotationAxisSetup != "NONE" && properties.useRtcp){ + writeBlock("MultiAxisMode On"); + } + + // set the parameter tool table + SimPLProgram.globalVariableList.push(createToolVariables()); + + if (!properties.writeToolTable) { + var tools = getToolTable(); + writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + dimensionFormat.format(tool.diameter) + " " + + "L2:" + dimensionFormat.format(tool.fluteLength) + " " + + "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + + "ProductID:" + formatComment(tool.productId); + writeBlock(toolAsigment); + } + writeBlock(" "); + } + } + ResetWriteRedirection(); +} + + +function writeWorkpiece() { + var workpieceString = new StringBuffer(); + SetWriteRedirection(workpieceString); + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + + writeBlock("# Workpiece dimensions"); + writeBlock( + "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z)); + writeBlock( + "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z)); + writeBlock( + "# Part size X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z)); + + writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + + "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + + " @"); + ResetWriteRedirection(); + return workpieceString; +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, datronFeedName, feed) { + this.id = id; + this.description = description; + this.datronFeedName = datronFeedName; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + if (useDatronFeedCommand) { + return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); + } else { + return ("Feed=" + formatVariable(feedContext.description)); + } + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return "Feed=" + feedFormat.format(f); + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + addFeedContext(feedContext, activeFeeds); + } + ++id; + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + + // this part allows us to use feedContext also for the cycles + if (hasParameter("operation:cycleType")) { + var cycleType = getParameter("operation:cycleType"); + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + + switch (cycleType) { + case "thread-milling": + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + case "bore-milling": + if (section.hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (section.hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + } + } + + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +/** Check that all elements are only one time in the result list. */ +function addFeedContext(feedContext, activeFeeds) { + if (activeFeeds.indexOf(feedContext) == -1) { + activeFeeds.push(feedContext); + } +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function setWorkPlane(abc) { + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + forceWorkPlane(); // always need the new workPlane + forceABC(); + if((properties.rotationAxisSetup != "NONE") && properties.useRtcp){ + writeBlock("MoveToSafetyPosition"); + }else{ + writeBlock("MoveToSafetyPosition"); + } + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function onSection() { + // this is the container that hold all operation informations... + currentOperation = new NewOperation(getOperationName(currentSection)) + SetWriteRedirection(currentOperation.operationProgram); + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + var tool = currentSection.getTool(); + + if (!isProbeOperation(currentSection) && hasParameter("operation:cycleTime")) { + writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); + } + + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + zRange.expandToRange(currentSection.getGlobalZRange()); + writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); + } + } + + // create sub program + writeBlock("program " + getOperationName(currentSection)); + spacingDepth += 1; + + if (passThrough) { + var joinString = "\r\n" + getSpacing(); + var passThroughString = passThrough.join(joinString); + if (passThroughString != "") { + writeBlock(passThroughString); + } + passThrough = []; + } + + // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. + writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); + var operationTolerance = tolerance; + if (hasParameter("operation:tolerance")) { + if (operationTolerance < getParameter("operation:tolerance")) { + operationTolerance = getParameter("operation:tolerance"); + } + } + + //load the matching workOffset + var workOffset = currentSection.getWorkOffset(); + if (workOffset != 0) { + writeBlock("LoadWcs name=\"" + workOffset +"\""); + } + + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); + } else + { + writeBlock("Smoothing Off"); + } + + if (properties.useDynamic) { + var dynamic = 5; + operationName = getOperationName(currentSection).toUpperCase(); + dynamicIndex = operationName.lastIndexOf("DYN") + 3; + expliciteDynamic = parseInt(operationName.substring(dynamicIndex,dynamicIndex+1)) + if ((expliciteDynamic != NaN) && (expliciteDynamic> 0 && expliciteDynamic < 6)){ + writeBlock("Dynamic = " + expliciteDynamic + " # Created from Operation Name"); + dynamic = expliciteDynamic + } else { + // set machine type specific dynamic sets + switch(properties.machineType){ + case 'NEO': + dynamic =5; + break; + case 'MX': + case 'CUBE': + if (operationTolerance <= (unit == MM ? 0.04 : (0.04/25.4))) { + dynamic = 4; + } + if (operationTolerance <= (unit == MM ? 0.02 : (0.02/25.4))) { + dynamic = 3; + } + if (operationTolerance <= (unit == MM ? 0.005 : (0.005/25.4))) { + dynamic = 2; + } + if (operationTolerance <= (unit == MM ? 0.003 : (0.003/25.4))) { + dynamic = 1; + } + break; + } + writeBlock("Dynamic = " + dynamic); + } + } + + if (properties.waitAfterOperation) { + showWaitDialog(getOperationName(currentSection)); + } + + if (machineConfiguration.isMultiAxisConfiguration()) { + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + if((properties.rotationAxisSetup != "NONE") && properties.useRtcp){ + writeBlock("Rtcp On"); + } + writeBlock("MoveToSafetyPosition"); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + } else { + forceWorkPlane(); + var abc = getWorkPlaneMachineABC(currentSection.workPlane); + + setWorkPlane(abc); + if((properties.rotationAxisSetup != "NONE") && properties.useRtcp){ + writeBlock("Rtcp On"); + } + } + } else { + // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + error("\r\n_________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| Tool orientation detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| rotationAxisSetup |" + + "\r\n| rotherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|________________________________________|\r\n"); + return; + } + setRotation(remaining); + } + + forceAny(); + + if (properties.showNotes && currentSection.hasParameter("notes")) { + var notes = currentSection.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + + var clearance = getFramePosition(currentSection.getInitialPosition()).z; + writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); + + + // write the optional length offset for each operation + if(properties.useZAxisOffset){ + writeBlock("ZAxisOffset = 0"); + } + + // radius Compensation + var compensationType + if(hasParameter('operation:compensationType')){ + compensationType = getParameter('operation:compensationType'); + } else { + compensationType = 'computer'; + } + + var wearCompensation + if(hasParameter('operation:compensationDeltaRadius')){ + wearCompensation = getParameter('operation:compensationDeltaRadius'); + } else { + wearCompensation = 0; + } + + if(properties.writePathOffset){ + switch( compensationType){ + case 'computer': + break; + case 'control': + writeBlock("PathOffset = 0") + break; + case 'wear': + writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); + break; + case 'inverseWear': + writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); + break; + } + } + + if (!isProbeOperation(currentSection)) { + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + + // tool changer command + if (properties.writeToolTable) { + writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } else { + writeBlock("Tool = " + toolOutput.format(tool.number) + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } + + //preload the next tool for the Datron tool assist + if(properties.preloadTool){ + var nextTool = getNextTool(tool.number); + if(nextTool){ + if (properties.writeToolTable) { + writeBlock("ProvideTool name=" + "\"" + createToolName(nextTool) + "\""); + } else { + writeBlock("ProvideTool = " + toolOutput.format(nextTool.number)); + } + } + } + + // set the current feed + // replace by the default feed command + if (properties.useParametricFeed && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + if (useDatronFeedCommand) { + var datronFeedParameter = new Array(); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var datronFeedCommand = { + name : feedContext.datronFeedName, + feed : feedFormat.format(feedContext.feed) + }; +/*eslint-disable*/ + var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); +/*eslint-enable*/ + if (indexOfFeedContext == -1) { + datronFeedParameter.push(datronFeedCommand); + } else { + var existingFeedContext = datronFeedParameter[indexOfFeedContext]; + if (existingFeedContext.feed < datronFeedCommand.feed) { + existingFeedContext.feed = datronFeedCommand.feed; + } + } + } + var datronFeedCommand = "SetFeedTechnology"; + for (var i = 0; i < datronFeedParameter.length; i++) { + datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; + } + writeBlock(datronFeedCommand); + + } else { + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); + } + } + } + } + + // parameter for the sequences + var sequenceParamter = new Array(); + + if (hasParameter("operation:cycleType")) { + + //Reset all movements to suppress older entries... + activeMovements = new Array(); + + var cycleType = getParameter("operation:cycleType"); + writeComment("Parameter " + cycleType + " cycle"); + + switch (cycleType) { + case "thread-milling": + writeBlock("SetFeedTechnology" + " ramp=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:finish_cutting"))); + var diameter = currentSection.getParameter("diameter"); + var pitch = currentSection.getParameter("pitch"); + var finishing = parseFloat(currentSection.getParameter("stepover")); + + writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); + sequenceParamter.push("nominalDiameter=nominalDiameter"); + writeBlock("pitch=" + xyzFormat.format(pitch)); + sequenceParamter.push("pitch=pitch"); + + if (!isNaN(finishing)) { + writeBlock("finishing=" + xyzFormat.format(finishing)); + sequenceParamter.push("finishing=finishing"); + } else { + sequenceParamter.push("finishing=0"); + } +/* + writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); + sequenceParamter.push('threadName=threadName'); + writeBlock("threading = " + currentSection.getParameter("threading")); + sequenceParamter.push("threading=threading"); + + TAG: den Standard auch mit Imperial unterstuezten + sequenceParamter.push("threadStandard=ThreadStandards.Metric"); + sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); + sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); + sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); + writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); + sequenceParamter.push("direction=direction"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); +*/ + break; + case "bore-milling": + writeBlock("SetFeedTechnology roughing=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:cutting"))); + writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); + sequenceParamter.push("diameter=diameter"); + + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); + sequenceParamter.push("infeedZ=infeedZ"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); + break; + case "drilling": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge"))); + break; + case "chip-breaking": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge")) + " roughing=" + feedFormat.format(getParameter("movement:plunge"))); + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); + sequenceParamter.push("infeedZ=infeedZ"); + break; + } + } + + if (properties.useSequences && !isProbeOperation(currentSection)) { + // call sequence + if (properties.useParametricFeed && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + sequenceParamter.push(formatVariable(feedContext.description) + "=" + formatVariable(feedContext.description)); + } + } + var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); + writeBlock(currentSectionCall); + + // write sequence + var currentSequenceName = getSequenceName(currentSection); + if (properties.useExternalSequencesFiles) { + spacingDepth -= 1; + var filename = getOutputPath(); + //sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; + sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; + sequenceFilePath += currentSequenceName + ".seq"; + redirectToFile(sequenceFilePath); + } else { + SetWriteRedirection(sequenceBuffer); + writeBlock(" "); + // TAG: modify parameter + spacingDepth -= 1; + writeBlock("$$$ " + currentSequenceName); + } + } + + if (!isProbeOperation(currentSection)) { + writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); + } else { + writeBlock("Spindle Off"); + writeBlock("PrepareXyzSensor"); + } + + // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); + + writeBlock("PrePositioning" + xyz); + + // adds support for suction + if(properties.useSuction){ + writeBlock("Suction On"); + } + +} + + +function showWaitDialog(operationName) { + writeBlock("showWaitDialog operationName=\"" + operationName + "\""); +} + +function writeWaitProgram() { + waitProgram = new Array(); + waitProgram.push("#Show the wait dialog for the next operation\r\n"); + waitProgram.push("program showWaitDialog optional operationName:string\r\n"); + waitProgram.push(" if not operationName hasvalue \r\n"); + waitProgram.push(" operationName =" + "\"" + "\"\r\n"); + waitProgram.push(" endif\r\n"); + waitProgram.push("\r\n"); + waitProgram.push(" messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName \r\n"); + waitProgram.push(" dialogRes = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel\r\n"); + waitProgram.push(" if dialogRes == System::DialogResult.Cancel\r\n"); + waitProgram.push(" exit\r\n"); + waitProgram.push(" endif\r\n"); + waitProgram.push("endprogram\r\n"); + + waitProgramOperation = {operationProgram: waitProgram}; + SimPLProgram.operationList.push(waitProgramOperation) +} + +function onDwell(seconds) { + writeBlock("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + // writeBlock("Rpm=" + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed)); + writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("Rapid" + xyz); + forceFeed(); + } +} + +function onPrePositioning(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("PrePositioning" + xyz); + forceFeed(); + } +} + +function onLinear(x, y, z, feed) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + var f = getFeed(feed); + + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > 99) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + // TAG: um die Ebenen kuemmern + // writeBlock(gPlaneModal.format(17)); + var compensationType = null; + if( currentSection.hasParameter("operation:compensationType")){ + compensationType = currentSection.getParameter("operation:compensationType"); + } + + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + switch(compensationType){ + case 'control': + writeBlock("ToolCompensation Left"); + writeBlock("PathCorrection Left"); + break; + case 'wear': + case 'inverseWear': + writeBlock("PathCorrection Left"); + break; + default: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + break; + case RADIUS_COMPENSATION_RIGHT: + switch(compensationType){ + case 'control': + writeBlock("ToolCompensation Rigth"); + writeBlock("PathCorrection Rigth"); + break; + case 'wear': + case 'inverseWear': + writeBlock("PathCorrection Rigth"); + break; + default: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + break; + case RADIUS_COMPENSATION_OFF: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + } + + if (xyz) { + if (f) { + writeBlock(f); + } + writeBlock("Line" + xyz); + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + + if (pendingRadiusCompensation >= 0) { + error(localize("radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + yOutput.format(y) + + zOutput.format(z) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + + forceABC(); + var xyzabc = x + y + z + a + b + c; + writeBlock("Rapid" + xyzabc); + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + var f = getFeed(feed); + + if(f){ + writeBlock(f); + } + if (x || y || z || a || b || c) { + var xyzabc = x + y + z + a + b + c; + writeBlock("Line" + xyzabc); + }; + //else if (f) { + // if (getNextRecord().isMotion()) { // try not to output feed without motion + // forceFeed(); // force feed on next line + // } else { + // writeBlock(getFeed(feed)); + // } + // } +} + +function onRewindMachine(a, b, c) { + writeBlock("MoveToSafetyPosition"); + var abc = aOutput.format(a) + bOutput.format(b) + cOutput.format(c); + writeBlock("Line" + abc); +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (properties.writeCoolantCommands) { + if (coolant == COOLANT_OFF) { + writeBlock("SpraySystem Off"); + currentCoolantMode = COOLANT_OFF; + return; + } + + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + writeBlock("SprayTechnology External"); + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR: + writeBlock("SprayTechnology External"); + writeBlock("Coolant Air"); + break; + case COOLANT_THROUGH_TOOL: + writeBlock("SprayTechnology Internal"); + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR_THROUGH_TOOL: + writeBlock("SprayTechnology Internal"); + writeBlock("Coolant Air"); + break; + + default: + onUnsupportedCoolant(coolant); + } + writeBlock("SpraySystem On"); + currentCoolantMode = coolant; + } +} + +var isInsideProgramDeclaration = false; +var directNcOperation; +function ParseManualNc(text){ + + var modulePattern = new RegExp("\.*(using|import)"); + var isModuleImport = modulePattern.test(text); + if(isModuleImport){ + SimPLProgram.usingList.push(text); + return; + } + + var programPattern = /(?:\s*program\s+)(\w+)/; + var isProgramDeclaration = programPattern.test(text); + + if(isProgramDeclaration){ + var subProgramName = programPattern.exec(text); + if(subProgramName == undefined) return; + directNcOperation = {operationCall:subProgramName[1],operationProgram: new StringBuffer()}; + SimPLProgram.operationList.push(directNcOperation); + isInsideProgramDeclaration = true; + } + + var isEndProgram = /\s*endprogram/.test(text); + if(isEndProgram){ + isInsideProgramDeclaration = false; + directNcOperation.operationProgram.append(text + "\r\n"); + return; + } + + if (isInsideProgramDeclaration){ + directNcOperation.operationProgram.append(text + "\r\n"); + return; + } + + return text; +} + +function onManualNC(command, value) { + switch (command) { + case 42: // Manual NC enumeration code ??? + value = ParseManualNc(value); + break; + case 40: // Comment + value = "# " + value; + break; + case 41: //wait + value = "Sleep seconds=" + value; + break; + case COMMAND_COOLANT_OFF: + value = "SpraySystem Off"; + break; + case COMMAND_COOLANT_ON: + value = "SpraySystem On"; + break; + case COMMAND_STOP: + value = "break"; + break; + case COMMAND_START_SPINDLE: + value = "Spindle On"; + break; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + value = "ChipConveyor On"; + break; + case COMMAND_STOP_CHIP_TRANSPORT: + value = "ChipConveyor Off"; + break; + case COMMAND_OPEN_DOOR: //open door + value = "ReleaseDoor"; + break; + case COMMAND_CLOSE_DOOR: //close door not needed + return; + case COMMAND_CALIBRATE: //calibrate + value = "# calibration currently not supported!"; + break; + case COMMAND_VERIFY: // check part + value = 'Dialog message="Please check workpiece!" Ok Cancel caption="Cam generated dialog"' + break; + case COMMAND_CLEAN: // clean part + value = 'Dialog message="Please clean workpiece!" Ok Cancel caption="Cam generated dialog"' + break; + case 43: // action no idea for what has a paramter + value = "# Action currently not supported!" + break; + case 44: // print message + // value = 'Dialog message="' + value + '" Ok Cancel caption="Cam generated dialog"' + SimPLProgram.usingList.push('using File'); + SimPLProgram.usingList.push('using DateTimeModule') + var message = (' value=(GetNow + "\t' + value + '")') + value = 'FileWriteLine filename="' + getFilename() + '.log"' + message; + break; + case 46: // show message + value = 'StatusMessage message="' + value + '"'; + break; + case COMMAND_ALARM: // alarm + value = 'Dialog message="Alarm!" Ok Cancel caption="Cam generated dialog"' + break; + case COMMAND_ALERT: // alarm + value = 'Dialog message="Warning!" Ok Cancel caption="Cam generated dialog"' + break; + case COMMAND_BREAK_CONTROL: + value = "MeasureToolLength" + break; + case COMMAND_TOOL_MEASURE: + value = "MeasureToolLength" + break; + case COMMAND_OPTIONAL_STOP: + value = "OptionalBreak"; + break; + case 45: //call subprogram + var subprogramName = "SubProgram_" + SimPLProgram.externalUsermodules.length; + SimPLProgram.externalUsermodules.push('usermodule ' + subprogramName + '="' + value + '"'); + value = subprogramName; + break; + } + + if(value != undefined){ + var operation = {operationCall: value, operationProgram:""} + SimPLProgram.operationList.push(operation); + } +} + +var mapCommand = {}; + +var passThrough = new Array(); +function onPassThrough(text) { + passThrough.push(text); +} + +function onCommand(command) { + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onCycle() { +} + +function onCycleEnd() { +} + +function isProbeOperation(section) { + return (section.hasParameter("operation-strategy") && section.getParameter("operation-strategy") == "probe"); +} + +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + var feedString = feedOutput.format(cycle.feedrate); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + + var startPositionOffset = cycle.probeClearance + tool.cornerRadius; + } + + switch (cycleType) { + case "bore-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onRapid(x, y, cycle.clearance); + boreMilling(cycle); + onRapid(x, y, cycle.clearance); + } + break; + case "thread-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onRapid(x, y, cycle.clearance); + threadMilling(cycle); + onRapid(x, y, cycle.clearance); + } + break; + case "drilling": + forceXYZ(); + onRapid(x, y, cycle.clearance); + drilling(cycle); + onRapid(x, y, cycle.clearance); + break; +/* + case "chip-breaking": + forceXYZ(); + onRapid(x, y, null); + onRapid(x, y, cycle.retract); + chipBreaking(cycle); + onRapid(x, y, cycle.clearance); + break; +*/ + + case "tapping": + case "left-tapping": + case "right-tapping": + case "tapping-with-chip-breaking": + case "left-tapping-with-chip-breaking": + case "right-tapping-with-chip-breaking": + forceXYZ(); + onRapid(x, y, cycle.clearance); + tapping(cycle); + onRapid(x, y, cycle.clearance); + break; + case "probing-x": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + break; + case "probing-y": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + break; + case "probing-z": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); + + var measureString = "SurfaceMeasure "; + measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); + writeBlock(measureString); + break; + case "probing-x-wall": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-y-wall": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-x-channel": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-x-channel-with-island": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-y-channel": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-y-channel-with-island": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-boss": + var measureString = "CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-hole": + var measureString = "CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-hole-with-island": + var measureString = "CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-boss": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " Center"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-hole": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " Center"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-hole-with-island": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " Center"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-inner-corner": + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "EdgeMeasure "; + + zOutput.reset(); + onRapid(x, y, cycle.stock); + onLinear(x, y, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + cycle.probeClearance; + writeBlock(measureString); + + forceXYZ(); + //zOutput.reset(); + onRapid(x, y, cycle.stock); + onLinear(x, y, probingDepth, cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; + // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; + + // var orientation = "" + // if (!isXNeagtive && !isYNeagtive) orientation = "BackRight"; + // if (isXNeagtive && !isYNeagtive) orientation = "BackLeft"; + // if (!isXNeagtive && isYNeagtive) orientation = "FrontRight"; + // if (isXNeagtive && isYNeagtive) orientation = "FrontLeft"; + + // var measureString = "CornerMeasure"; + // measureString += " " + orientation; + // measureString += " Inside"; + // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " forceSafeHeight" + // measureString += " skipZMeasure"; + // measureString += " originXShift=" + xyzFormat.format(-x); + // measureString += " originYShift=" + xyzFormat.format(-y); + // writeBlock(measureString); + break; + case "probing-xy-outer-corner": + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var measureString = "EdgeMeasure "; + + zOutput.reset(); + onRapid(x, y, probingDepth); + onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + writeBlock(measureString); + forceXYZ(); + onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + onLinear(x, y, probingDepth, cycle.feedrate); + //forceXYZ(); + //zOutput.reset(); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " retractDistance=" + xyzFormat.format(cycle.retract); + writeBlock(measureString); + forceXYZ(); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onLinear(x, y, probingDepth, cycle.feedrate); + + // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; + // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; + + // var orientation = "" + // if (!isXNeagtive && !isYNeagtive) orientation = "FrontLeft"; + // if (isXNeagtive && !isYNeagtive) orientation = "FrontRight"; + // if (!isXNeagtive && isYNeagtive) orientation = "BackLeft"; + // if (isXNeagtive && isYNeagtive) orientation = "BackRight"; + + // var measureString = "CornerMeasure"; + // measureString += " " + orientation; + // measureString += " Outside"; + // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " forceSafeHeight" + // measureString += " skipZMeasure"; + // measureString += " originXShift=" + xyzFormat.format(-x); + // measureString += " originYShift=" + xyzFormat.format(-y); + // writeBlock(measureString); + break; + case "probing-x-plane-angle": + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + // var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + // var touchPositionX2 = touchPositionX1; + // writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + // writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + // writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + // writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + // writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + // var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + // var touchPositionY2 = touchPositionY1; + // writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + // writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + // writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + // writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + // writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + return; + } + + // save probing result in defined wcs + if(isProbeOperation(currentSection) && currentSection.workOffset != null){ + writeBlock('SaveWcs name="' + currentSection.workOffset + '"'); + } + + return; +} + +function drilling(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + writeBlock(boreCommandString.join(" ")); +} + +function chipBreaking(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + boreCommandString.push("infeedZ=infeedZ"); + writeBlock(boreCommandString.join(" ")); +} + +function boreMilling(cycle) { + if (cycle.numberOfSteps > 2) { + error("Only 2 steps are allowed for bore-milling."); + } + + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + boreCommandString.push("DrillMilling"); + boreCommandString.push("diameter=diameter"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("infeedZ=infeedZ"); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + + if (cycle.numberOfSteps == 2) { + var xycleaning = cycle.stepover; + var maxzdepthperstep = tool.fluteLength * 0.8; + boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); + boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); + } + var bottomcleaning = 0; + // finishingZ = 1; + writeBlock(boreCommandString.join(" ")); +} + +function threadMilling(cycle) { + var threadString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + threadString.push("SpecialThread"); + // threadString.push('threadName=threadName'); + threadString.push("nominalDiameter=nominalDiameter"); + threadString.push("pitch=pitch"); + threadString.push("depth=" + depth); + threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + // threadString.push("threadStandard=threadStandard"); + if(properties.createThreadChamfer){ + threadString.push("Deburring"); + } + // ; + // threadString.push("insideOutside=ThreadMillingSide.Inside"); + threadString.push("finishing=finishing"); + if (cycle.threading == "left") { + threadString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + threadString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(threadString.join(" ")); +} + +function tapping(cycle) { + var tappingString = new Array(); + var depth = xyzFormat.format(cycle.depth); + tappingString.push("ThreadCutting"); + tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); + tappingString.push("depth=" + depth); + tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); + if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { + tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); + } + if (tool.type == TOOL_TAP_LEFT_HAND) { + tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + tappingString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(tappingString.join(" ")); +} + +function formatCycleTime(cycleTime) { + // cycleTime = cycleTime + 0.5; // round up + var seconds = cycleTime % 60 | 0; + var minutes = ((cycleTime - seconds)/60 | 0) % 60; + var hours = (cycleTime - minutes * 60 - seconds)/(60 * 60) | 0; + if (hours > 0) { + return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); + } else if (minutes > 0) { + return subst(localize("%1m:%2s"), minutes, seconds); + } else { + return subst(localize("%1s"), seconds); + } +} + +function dump(name, _arguments) { + var result = getCurrentRecordId() + ": " + name + "("; + for (var i = 0; i < _arguments.length; ++i) { + if (i > 0) { + result += ", "; + } + if (typeof _arguments[i] == "string") { + result += "'" + _arguments[i] + "'"; + } else { + result += _arguments[i]; + } + } + result += ")"; + writeln(result); +} + +function onSectionEnd() { + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + + // reset Z Offset value + if(properties.useZAxisOffset){ + writeBlock("ZAxisOffset = 0"); + } + + + if (currentSection.isMultiAxis && (properties.rotationAxisSetup != "NONE") && properties.useRtcp){ + writeBlock("Rtcp Off"); + } + + // adds support for suction + if(properties.useSuction){ + writeBlock("Suction Off"); + } + + if (properties.useSequences && !isProbeOperation(currentSection)) { + if (!properties.useExternalSequencesFiles) { + ResetWriteRedirection(); + } + spacingDepth += 1; + } + + + writeBlock("EndBlock"); + + spacingDepth -= 1; + + writeBlock("endprogram " + "# " + getOperationName(currentSection)); + ResetWriteRedirection(); + SimPLProgram.operationList.push(currentOperation); + forceAny(); +} + +function onClose() { + + if (properties.waitAfterOperation) { + writeWaitProgram(); + } + + writeBlock(SimPLProgram.moduleName); + writeBlock(""); + writeBlock(SimPLProgram.toolDescriptionList.join("\r\n") + "\r\n"); + writeBlock(""); + writeBlock(SimPLProgram.workpieceGeometry); + writeBlock(""); + writeBlock(SimPLProgram.sequenceList.join("\r\n") + "\r\n"); + writeBlock(""); + writeBlock(SimPLProgram.usingList.join("\r\n") + "\r\n"); + writeBlock(""); + writeBlock(SimPLProgram.externalUsermodules.join("\r\n") + "\r\n"); + writeBlock(""); + writeBlock(SimPLProgram.globalVariableList.join("\r\n") + "\r\n"); + writeBlock(""); + + finishMainProgram(); + writeBlock(SimPLProgram.mainProgram); + writeBlock(""); + + SimPLProgram.operationList.forEach(function (operation){ + if(operation != undefined){ + writeBlock(operation.operationProgram); + } + }) + + writeBlock("end"); + + if (properties.useSequences && !properties.useExternalSequencesFiles) { + writeComment(spacing); + writeBlock(sequenceBuffer.toString()); + } +} + +// after all the oiperation calls are set close the main program with all the calls +function finishMainProgram(){ + // write the main program footer + SetWriteRedirection(SimPLProgram.mainProgram); + spacingDepth += 1; + + // write all subprogram calls in the main Program + SimPLProgram.operationList.forEach(function(operation){ + if(operation!=undefined){ + writeBlock(operation.operationCall); + } + }) + + if (properties.writeCoolantCommands) { + writeBlock("SpraySystem Off"); + } + + if(properties.rotationAxisSetup != "NONE" && properties.useRtcp){ + writeBlock("MultiAxisMode Off"); + writeBlock("Rtcp Off"); + } + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + if (properties.useParkPosition) { + writeBlock("Spindle Off"); + writeBlock("MoveToParkPosition"); + } else { + writeBlock("MoveToSafetyPosition"); + zOutput.reset(); + } + + spacingDepth -= 1; + writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + ResetWriteRedirection(); +} + + diff --git a/datron next.cps.orig b/deprecated/datron next.cps.orig similarity index 97% rename from datron next.cps.orig rename to deprecated/datron next.cps.orig index 23cc142..0e1f921 100644 --- a/datron next.cps.orig +++ b/deprecated/datron next.cps.orig @@ -1,2055 +1,2055 @@ -/** - Copyright (C) 2012-2018 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} -*/ - -description = "DATRON next"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 40783; - -longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; - -extension = "simpl"; -setCodePage("utf-8"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(120); -allowHelicalMoves = true; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine : true, // write machine - showNotes : false, // specifies that operation notes should be output - useSmoothing : true, // specifies if smoothing should be used or not - useDynamic : true, // specifies using dynamic mode or not - useParkPosition : true, // specifies to use park position at the end of the program - writeToolTable : true, // write the table with the geometric tool informations - useSequences : true, // this use a sequence in the output format to perform on large files - useExternalSequencesFiles : false, // this property create one external sequence files for each operation - writeCoolantCommands : true, // disable the coolant commands in the file - useParametricFeed : true, // specifies that feed should be output using parameters - waitAfterOperation : false, // optional stop - got4thAxis: true, // specifies if the machine has a rotational 4th axis - got5thAxis: true, // aktivate the RTCP options - useSuction: false, // aktivate suction support -}; - -// user-defined property definitions -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, - useSmoothing: {title:"Use smoothing", description:"Specifies if smoothing should be used or not.", type:"boolean"}, - useDynamic: {title:"Dynamic mode", description:"Specifies the using of dynamic mode or not.", type:"boolean"}, - useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, - writeToolTable: {title:"Write tool table", description:"Write a tool table containing geometric tool information.", group:0, type:"boolean"}, - useSequences: {title:"Use sequences", description:"If enables, sequences are used in the output format on large files.", type:"boolean"}, - useExternalSequencesFiles: {title:"Use external sequence files", description:"If enabled, an external sequence file is created for each operation.", type:"boolean"}, - writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, - useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, - waitAfterOperation: {title:"Wait after operation", description:"If enabled, an optional stop is outputted to pause after each operation.", type:"boolean"}, - got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, - got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with a DST.", type:"boolean"} -}; - -var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); -var toolFormat = createFormat({decimals:0}); -var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); -var rpmFormat = createFormat({decimals:0, scale:1}); -var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); - -var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); -var feedOutput = createVariable({prefix:""}, feedFormat); - -var xOutput = createVariable({prefix:" X="}, xyzFormat); -var yOutput = createVariable({prefix:" Y="}, xyzFormat); -var zOutput = createVariable({prefix:" Z="}, xyzFormat); -var aOutput = createVariable({prefix:" A="}, abcFormat); -var bOutput = createVariable({prefix:" B="}, abcFormat); -var cOutput = createVariable({prefix:" C="}, abcFormat); - -var iOutput = createVariable({prefix:" dX=", force : true}, feedFormat); -var jOutput = createVariable({prefix:" dY=", force : true}, feedFormat); -var kOutput = createVariable({prefix:" dZ="}, feedFormat); - -// fixed settings -var useDatronFeedCommand = false; // unsupported for now, keep false -var language = "de"; // specifies the language, replace with getLangId() -var spacingDepth = 0; -var spacingString = " "; -var sequenceFile = new StringBuffer(); -var spacing = "##########################################################"; - -// collected state -var currentFeedValue = -1; -var optionalSection = false; -var activeMovements; // do not use by default -var currentFeedId; - -// format date + time -var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -function getSequenceName(section) { - var sequenceName = ""; - if (properties.useExternalSequencesFiles) { - sequenceName += FileSystem.getFilename(getOutputPath().substr(0, getOutputPath().lastIndexOf("."))) + "_"; - } - sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); - return sequenceName; -} - -function getOperationName(section) { - return "Operation_" + getOperationDescription(section); -} - -function capitalizeFirstLetter(text) { - return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); -} - -function getSpacing() { - var space = ""; - for (var i = 0; i < spacingDepth; i++) { - space += spacingString; - } - return space; -} - -/** - Writes the specified block. -*/ -function writeBlock() { - var text = formatWords(arguments); - writeWords(getSpacing() + text); -} - -/** - Output a comment. -*/ -function writeComment(text) { - if (text) { - writeln(getSpacing() + "# " + text); - } -} - -var charMap = { - "\u00c4" : "Ae", - "\u00e4" : "ae", - "\u00dc" : "Ue", - "\u00fc" : "ue", - "\u00d6" : "Oe", - "\u00f6" : "oe", - "\u00df" : "ss", - "\u002d" : "_", - "\u0020" : "_" -}; - -/** Map specific chars. */ -function mapComment(text) { - text = formatVariable(text); - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); -} - -function onOpen() { - // note: setup your machine here - if (properties.got4thAxis && !properties.got5thAxis) { - var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis); - machineConfiguration.setVendor("DATRON"); - machineConfiguration.setModel("NEO with A Axis"); - machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis - } - - // note: setup your machine here - if (properties.got4thAxis && properties.got5thAxis) { - var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0}); - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis,cAxis); - machineConfiguration.setVendor("DATRON"); - machineConfiguration.setModel("NEXT with DST"); - machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - // header - writeProgramHeader(); - - // write program calls - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var opName = getOperationName(section); - var sectionID = i + 1; - writeBlock(opName); - } - - onCommand(COMMAND_COOLANT_OFF); - - writeBlock("Spindle Off"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - if (properties.useParkPosition) { - writeBlock("MoveToParkPosition"); - } else { - writeBlock("MoveToSafetyPosition"); - zOutput.reset(); - } - - spacingDepth -= 1; - writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); - writeln(""); -} - -function getOperationDescription(section) { - // creates the name of the operation - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -function createToolVariables() { - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0 && !properties.writeToolTable) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - writeBlock(toolOutput.format(tool.number) + ":number"); - } - writeBlock(" "); - } -} - -function createToolDescriptionTable() { - if (!properties.writeToolTable) { - return; - } - var toolDescriptionArray = new Array(); - var toolNameList = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var tool = section.getTool(); - if (tool.type != TOOL_PROBE) { - var toolName = createToolName(tool); - var toolProgrammed = createToolDescription(tool); - if (toolNameList.indexOf(toolName) == -1) { - toolNameList.push(toolName); - toolDescriptionArray.push(toolProgrammed); - } else { -/* - if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { - error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + - toolNameList.join("\r\n") + "#####################################\r\n"); - } -*/ - } - } - } - - writeBlock(toolDescriptionArray.join("\r\n")); -} - -function createToolDescription(tool) { - var toolProgrammed = "@ ToolDescription : " + - "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + - "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + - "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + - "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + - "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + - "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + - "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + - "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + - "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + - "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + - "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + - "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + - "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + - "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + - "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + - "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + - " @"; - return toolProgrammed; -} - -/** - Generate the logical tool name for the assignment table of used tools. -*/ -function createToolName(tool) { - var toolName = toolFormat.format(tool.number); - toolName += "_" + translateToolType(tool.type); - if (tool.comment) { - toolName += "_" + tool.comment; - } - if (tool.diameter) { - toolName += "_D" + tool.diameter; - } - var description = tool.getDescription(); - if (description) { - toolName += "_" + description; - } - toolName = formatVariable(toolName); - return toolName; -} - -/** - Translate HSM tools to Datron tool categories. -*/ -function translateToolType(toolType) { - - var datronCategoryName = ""; - - toolCategory = toolType; - switch (toolType) { - case TOOL_UNSPECIFIED: - datronCategoryName = "Unspecified"; - break; - case TOOL_DRILL: - datronCategoryName = "Drill"; - break; - case TOOL_DRILL_CENTER: - datronCategoryName = "DrillCenter"; - break; - case TOOL_DRILL_SPOT: - datronCategoryName = "DrillSpot"; - break; - case TOOL_DRILL_BLOCK: - datronCategoryName = "DrillBlock"; - break; - case TOOL_MILLING_END_FLAT: - datronCategoryName = "MillingEndFlat"; - break; - case TOOL_MILLING_END_BALL: - datronCategoryName = "MillingEndBall"; - break; - case TOOL_MILLING_END_BULLNOSE: - datronCategoryName = "MillingEndBullnose"; - break; - case TOOL_MILLING_CHAMFER: - datronCategoryName = "Graver"; - break; - case TOOL_MILLING_FACE: - datronCategoryName = "MillingFace"; - break; - case TOOL_MILLING_SLOT: - datronCategoryName = "MillingSlot"; - break; - case TOOL_MILLING_RADIUS: - datronCategoryName = "MillingRadius"; - break; - case TOOL_MILLING_DOVETAIL: - datronCategoryName = "MillingDovetail"; - break; - case TOOL_MILLING_TAPERED: - datronCategoryName = "MillingTapered"; - break; - case TOOL_MILLING_LOLLIPOP: - datronCategoryName = "MillingLollipop"; - break; - case TOOL_TAP_RIGHT_HAND: - datronCategoryName = "TapRightHand"; - break; - case TOOL_TAP_LEFT_HAND: - datronCategoryName = "TapLeftHand"; - break; - case TOOL_REAMER: - datronCategoryName = "Reamer"; - break; - case TOOL_BORING_BAR: - datronCategoryName = "BoringBar"; - break; - case TOOL_COUNTER_BORE: - datronCategoryName = "CounterBore"; - break; - case TOOL_COUNTER_SINK: - datronCategoryName = "CounterSink"; - break; - case TOOL_HOLDER_ONLY: - datronCategoryName = "HolderOnly"; - break; - case TOOL_PROBE: - datronCategoryName = "XYZSensor"; - break; - default: - datronCategoryName = "Unspecified"; - } - return datronCategoryName; -} - -function writeProgramHeader() { - // write creation Date - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - writeComment("!File ; generated at " + date + " - " + time); - if (programComment) { - writeComment(formatComment(programComment)); - } - - writeBlock(" "); - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - - writeBlock("module " + "CamGeneratedModule"); - writeBlock(" "); - - writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); - - // write the table of used tools in the header of the program - createToolDescriptionTable(); - writeBlock(""); - - writeWorkpiece(); - - // Creates the sequence header in the program file - if (properties.useSequences) { - var sequences = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (!isProbeOperation(section)) { - sequences.push(getSequenceName(section)); - } - } - if (properties.useExternalSequencesFiles) { - writeBlock("@ EmbeddedSequences = false @"); - } - if (sequences.length > 0) { - writeBlock("sequence " + sequences.join("\r\nsequence ")); - writeBlock(" "); - } - } - - // dont ask why the control need it - writeBlock("using Base"); - if (properties.got5thAxis){ - writeBlock("using Rtcp"); - } - if (properties.waitAfterOperation) { - writeBlock("import System"); - } - writeBlock(" "); - - // scan all operations for the parametric feed commands - var feedDeclaration = new Array(); - var currentMovements = new Array(); - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (properties.useParametricFeed && (!useDatronFeedCommand)) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (feedDeclaration.indexOf(feedDescription) == -1) { - feedDeclaration.push(feedDescription); - } - } - } - } - - // write all the variable declarations in the header of the program - if (!useDatronFeedCommand) { - writeComment("feed variables declaration"); - if (feedDeclaration != 0) { - writeBlock(feedDeclaration.join(":number\r\n") + ":number\r\n"); - } - } - - createToolVariables(); - - writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); - spacingDepth += 1; - - writeBlock("Absolute"); - - // write the parameter tool table - if (!properties.writeToolTable) { - var tools = getToolTable(); - writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + dimensionFormat.format(tool.diameter) + " " + - "L2:" + dimensionFormat.format(tool.fluteLength) + " " + - "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + - "ProductID:" + formatComment(tool.productId); - writeBlock(toolAsigment); - } - writeBlock(" "); - } - } -} - - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("# Workpiece dimensions"); - writeBlock( - "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z)); - writeBlock( - "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z)); - writeBlock( - "# Part size X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z)); - - writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + - "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + - "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + - "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + - " @"); - writeBlock(" "); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, datronFeedName, feed) { - this.id = id; - this.description = description; - this.datronFeedName = datronFeedName; - if (revision < 41759) { - this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution - } else { - this.feed = feed; - } -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - if (useDatronFeedCommand) { - return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); - } else { - return ("Feed=" + formatVariable(feedContext.description)); - } - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return "Feed=" + feedFormat.format(f); - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - var id = 0; - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - addFeedContext(feedContext, activeFeeds); - } - ++id; - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - - // this part allows us to use feedContext also for the cycles - if (hasParameter("operation:cycleType")) { - var cycleType = getParameter("operation:cycleType"); - if (hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - - switch (cycleType) { - case "thread-milling": - if (hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:ramp")) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:finish_cutting")) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - break; - case "bore-milling": - if (section.hasParameter("movement:plunge")) { - var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (section.hasParameter("movement:ramp")) { - var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - if (hasParameter("movement:finish_cutting")) { - var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); - addFeedContext(feedContext, activeFeeds); - ++id; - } - break; - } - } - - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); - addFeedContext(feedContext, activeFeeds); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -/** Check that all elements are only one time in the result list. */ -function addFeedContext(feedContext, activeFeeds) { - if (activeFeeds.indexOf(feedContext) == -1) { - activeFeeds.push(feedContext); - } -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - forceWorkPlane(); // always need the new workPlane - forceABC(); - - writeBlock("MoveToSafetyPosition"); - writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); - - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - var tool = currentSection.getTool(); - - if (!isProbeOperation(currentSection)) { - writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); - } - - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = currentSection.getGlobalZRange(); - var number = tool.number; - zRange.expandToRange(currentSection.getGlobalZRange()); - writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); - } - } - - // create sub program - writeBlock("program " + getOperationName(currentSection)); - spacingDepth += 1; - - if (passThrough) { - var joinString = "\r\n" + getSpacing(); - var passThroughString = passThrough.join(joinString); - if (passThroughString != "") { - writeBlock(passThroughString); - } - passThrough = []; - } - - // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. - writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); - var operationTolerance = tolerance; - if (hasParameter("operation:tolerance")) { - if (operationTolerance < getParameter("operation:tolerance")) { - operationTolerance = getParameter("operation:tolerance"); - } - } - - //load the matching workOffset - var workOffset = currentSection.getWorkOffset(); - if (workOffset != 0) { - writeBlock("LoadWcs name=\"" + workOffset +"\""); - } - - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); - } else - { - writeBlock("Smoothing Off"); - } - - if (properties.useDynamic) { - - var dynamic = 5; - /* - if (operationTolerance <= 0.02) { - dynamic = 4; - } - if (operationTolerance <= 0.01) { - dynamic = 3; - } - if (operationTolerance <= 0.005) { - dynamic = 2; - } - if (operationTolerance <= 0.003) { - dynamic = 1; - } - */ - writeBlock("Dynamic = " + dynamic); - } - if (properties.waitAfterOperation) { - showWaitDialog(); - } - - if (machineConfiguration.isMultiAxisConfiguration()) { - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - if(properties.got5thAxis){ - writeBlock("Rtcp On"); - } - - writeBlock("MoveToSafetyPosition"); - writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); - } else { - forceWorkPlane(); - var abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - if(properties.got5thAxis){ - writeBlock("Rtcp On"); - } - - } - } else { - // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - error("\r\n_________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| Tool orientation detected. |" + - "\r\n| You have to enable the property |" + - "\r\n| got4thAxis, otherwise you can only post|" + - "\r\n| 3 Axis programs. |" + - "\r\n| If you still have issues, |" + - "\r\n| please contact www.DATRON.com! |" + - "\r\n|________________________________________|\r\n"); - return; - } - setRotation(remaining); - } - - forceAny(); - - if (properties.showNotes && currentSection.hasParameter("notes")) { - var notes = currentSection.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - - var clearance = getFramePosition(currentSection.getInitialPosition()).z; - writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); - - if (!isProbeOperation(currentSection)) { -<<<<<<< HEAD -======= - // set rpm - /* - if ((spindleSpeed < 6000) && (spindleSpeed > 0)) { - spindleSpeed = 6000; - } - */ ->>>>>>> b96761ab7bb85d33b42496678b6eac58498e9d70 - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - - // tool changer command - if (properties.writeToolTable) { - writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + - " newRpm=" + rpmFormat.format(spindleSpeed) + - " skipRestoring" - ); - } else { - writeBlock("Tool = " + toolOutput.format(tool.number) + - " newRpm=" + rpmFormat.format(spindleSpeed) + - " skipRestoring" - ); - } - - // set the current feed - // replace by the default feed command - if (properties.useParametricFeed && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - activeFeeds = initializeActiveFeeds(currentSection); - if (useDatronFeedCommand) { - var datronFeedParameter = new Array(); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var datronFeedCommand = { - name : feedContext.datronFeedName, - feed : feedFormat.format(feedContext.feed) - }; -/*eslint-disable*/ - var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); -/*eslint-enable*/ - if (indexOfFeedContext == -1) { - datronFeedParameter.push(datronFeedCommand); - } else { - var existingFeedContext = datronFeedParameter[indexOfFeedContext]; - if (existingFeedContext.feed < datronFeedCommand.feed) { - existingFeedContext.feed = datronFeedCommand.feed; - } - } - } - var datronFeedCommand = "SetFeedTechnology"; - for (var i = 0; i < datronFeedParameter.length; i++) { - datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; - } - writeBlock(datronFeedCommand); - - } else { - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); - } - } - } - } - - // parameter for the sequences - var sequenceParamter = new Array(); - - if (hasParameter("operation:cycleType")) { - - //Reset all movements to suppress older entries... - activeMovements = new Array(); - - var cycleType = getParameter("operation:cycleType"); - writeComment("Parameter " + cycleType + " cycle"); - - switch (cycleType) { - case "thread-milling": - writeBlock("SetFeedTechnology" + " ramp=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:finish_cutting"))); - var diameter = currentSection.getParameter("diameter"); - var pitch = currentSection.getParameter("pitch"); - var finishing = currentSection.getParameter("stepover"); - - writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); - sequenceParamter.push("nominalDiameter=nominalDiameter"); - writeBlock("pitch=" + xyzFormat.format(pitch)); - sequenceParamter.push("pitch=pitch"); - if (xyzFormat.isSignificant(finishing)) { - writeBlock("finishing=" + xyzFormat.format(finishing)); - sequenceParamter.push("finishing=finishing"); - } else { - sequenceParamter.push("finishing=0"); - } -/* - writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); - sequenceParamter.push('threadName=threadName'); - writeBlock("threading = " + currentSection.getParameter("threading")); - sequenceParamter.push("threading=threading"); - - TAG: den Standard auch mit Imperial unterstuezten - sequenceParamter.push("threadStandard=ThreadStandards.Metric"); - sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); - sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); - sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); - writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); - sequenceParamter.push("direction=direction"); - writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); - sequenceParamter.push("repeatPass=repeatPass"); -*/ - break; - case "bore-milling": - writeBlock("SetFeedTechnology roughing=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:cutting"))); - writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); - sequenceParamter.push("diameter=diameter"); - - writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); - sequenceParamter.push("infeedZ=infeedZ"); - writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); - sequenceParamter.push("repeatPass=repeatPass"); - break; - case "drilling": - writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge"))); - break; - case "chip-breaking": - writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge")) + " roughing=" + feedFormat.format(getParameter("movement:cutting"))); - writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); - sequenceParamter.push("infeedZ=infeedZ"); - break; - } - } - - if (properties.useSequences && !isProbeOperation(currentSection)) { - // call sequence - if (properties.useParametricFeed && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - activeFeeds = initializeActiveFeeds(currentSection); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - sequenceParamter.push(formatVariable(feedContext.description) + "=" + formatVariable(feedContext.description)); - } - } - var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); - writeBlock(currentSectionCall); - - // write sequence - var currentSequenceName = getSequenceName(currentSection); - if (properties.useExternalSequencesFiles) { - spacingDepth -= 1; - var filename = getOutputPath(); - //sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; - sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; - sequenceFilePath += currentSequenceName + ".seq"; - redirectToFile(sequenceFilePath); - } else { - redirectToBuffer(); - writeBlock(" "); - // TAG: modify parameter - spacingDepth -= 1; - writeBlock("$$$ " + currentSequenceName); - } - } - - if (!isProbeOperation(currentSection)) { - writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); - } else { - writeBlock("Spindle Off"); - writeBlock("PrepareXyzSensor"); - } - - // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); - - writeBlock("PrePositioning" + xyz); - - // adds support for suction - if(properties.useSuction){ - writeBlock("Suction On"); - } - -} - - -function showWaitDialog(operationName) { - writeBlock("showWaitDialog"); -} - -function writeWaitProgram() { - writeBlock("#Show the wait dialog for the next operation"); - writeBlock("program showWaitDialog optional operationName:string"); - writeBlock(""); - writeBlock(" if not operationName hasvalue "); - writeBlock(" operationName =" + "\"" + "\""); - writeBlock(" endif"); - writeBlock(""); - writeBlock(" messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName "); - writeBlock(" dialogResult = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel"); - writeBlock(" if dialogResult == System::DialogResult.Cancel"); - writeBlock(" exit"); - writeBlock(" endif"); - writeBlock(""); - writeBlock("endprogram"); -} - -function onDwell(seconds) { - writeln("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); -} - -function onSpindleSpeed(spindleSpeed) { - // writeBlock("Rpm=" + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed)); - writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(x, y, z) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock("Rapid" + xyz); - forceFeed(); - } -} - -function onPrePositioning(x, y, z) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock("PrePositioning" + xyz); - forceFeed(); - } -} - -function onLinear(x, y, z, feed) { - var xyz = ""; - xyz += (x !== null) ? xOutput.format(x) : ""; - xyz += (y !== null) ? yOutput.format(y) : ""; - xyz += (z !== null) ? zOutput.format(z) : ""; - - var f = getFeed(feed); - - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - var d = tool.diameterOffset; - if (d > 99) { - warning(localize("The diameter offset exceeds the maximum value.")); - } - // TAG: um die Ebenen kuemmern - // writeBlock(gPlaneModal.format(17)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock("ToolCompensation Left"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock("ToolCompensation Right"); - break; - case RADIUS_COMPENSATION_OFF: - writeBlock("ToolCompensation Off"); - break; - } - } - - if (xyz) { - if (f) { - writeBlock(f); - } - writeBlock("Line" + xyz); - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - // one of X/Y and I/J are required and likewise - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - - if (pendingRadiusCompensation >= 0) { - error(localize("radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (isHelical()) { - linearize(tolerance); - return; - } - // TAG: are 360deg arcs supported - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } else { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock("Arc" + - (clockwise ? " CW" : " CCW") + - xOutput.format(x) + - yOutput.format(y) + - zOutput.format(z) + - iOutput.format(cx - start.x) + - jOutput.format(cy - start.y) - ); - break; - default: - linearize(tolerance); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = aOutput.format(_a); - var b = bOutput.format(_b); - var c = cOutput.format(_c); - - forceABC(); - var xyzabc = x + y + z + a + b + c; - writeBlock("Rapid" + xyzabc); - forceFeed(); -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = aOutput.format(_a); - var b = bOutput.format(_b); - var c = cOutput.format(_c); - var f = getFeed(feed); - - writeBlock(f); - if (x || y || z || a || b || c) { - var xyzabc = x + y + z + a + b + c; - writeBlock("Line" + xyzabc); - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } -} - -function onRewindMachine(a, b, c) { - writeBlock("MoveToSafetyPosition"); - var abc = aOutput.format(a) + bOutput.format(b) + cOutput.format(c); - writeBlock("Line" + abc); -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (properties.writeCoolantCommands) { - if (coolant == COOLANT_OFF) { - writeBlock("SpraySystem Off"); - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - writeBlock("Coolant Alcohol"); - break; - case COOLANT_AIR: - writeBlock("Coolant Air"); - break; - default: - onUnsupportedCoolant(coolant); - } - writeBlock("SpraySystem On"); - currentCoolantMode = coolant; - } -} - -var mapCommand = {}; - -var passThrough = new Array(); - -function onPassThrough(text) { - passThrough.push(text); -} - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onCycle() { -} - -function onCycleEnd() { -} - -function isProbeOperation(section) { - return (section.hasParameter("operation-strategy") && section.getParameter("operation-strategy") == "probe"); -} - -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - var feedString = feedOutput.format(cycle.feedrate); - - if (isProbeOperation(currentSection)) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } - - var startPositionOffset = cycle.probeClearance + tool.cornerRadius; - } - - switch (cycleType) { - case "bore-milling": - for (var i = 0; i <= cycle.repeatPass; ++i) { - forceXYZ(); - onRapid(x, y, cycle.clearance); - boreMilling(cycle); - onRapid(x, y, cycle.clearance); - } - break; - case "thread-milling": - for (var i = 0; i <= cycle.repeatPass; ++i) { - forceXYZ(); - onRapid(x, y, cycle.clearance); - threadMilling(cycle); - onRapid(x, y, cycle.clearance); - } - break; - case "drilling": - forceXYZ(); - onRapid(x, y, cycle.clearance); - drilling(cycle); - onRapid(x, y, cycle.clearance); - break; -/* - case "chip-breaking": - forceXYZ(); - onRapid(x, y, null); - onRapid(x, y, cycle.retract); - chipBreaking(cycle); - onRapid(x, y, cycle.clearance); - break; -*/ - case "tapping": - case "left-tapping": - case "right-tapping": - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceXYZ(); - onRapid(x, y, cycle.clearance); - tapping(cycle); - onRapid(x, y, cycle.clearance); - break; - case "probing-x": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - break; - case "probing-y": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - break; - case "probing-z": - forceXYZ(); - onRapid(x, y, cycle.stock); - onLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); - - var measureString = "SurfaceMeasure "; - measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); - writeBlock(measureString); - break; - case "probing-x-wall": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " YAligned"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-y-wall": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " XAligned"; - measureString += " skipZMeasure"; - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-x-channel": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " YAligned"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-x-channel-with-island": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " YAligned"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - writeBlock(measureString); - break; - case "probing-y-channel": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " XAligned"; - measureString += " skipZMeasure"; - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-y-channel-with-island": - var measureString = "SymmetryAxisMeasure"; - measureString += " width=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " XAligned"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-boss": - var measureString = "CircleMeasure"; - measureString += " diameter=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-hole": - var measureString = "CircleMeasure"; - measureString += " diameter=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-circular-hole-with-island": - var measureString = "CircleMeasure"; - measureString += " diameter=" + cycle.width1; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-boss": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + cycle.width1; - measureString += " dimensionY=" + cycle.width2; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Outside"; - measureString += " Center"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-hole": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + cycle.width1; - measureString += " dimensionY=" + cycle.width2; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " Center"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-rectangular-hole-with-island": - var measureString = "RectangleMeasure"; - measureString += " dimensionX=" + cycle.width1; - measureString += " dimensionY=" + cycle.width2; - measureString += " searchDistance=" + cycle.probeClearance; - measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - measureString += " Inside"; - measureString += " Center"; - measureString += " forceSafeHeight"; - measureString += " skipZMeasure"; - measureString += " originXShift=" + xyzFormat.format(-x); - measureString += " originYShift=" + xyzFormat.format(-y); - writeBlock(measureString); - break; - case "probing-xy-inner-corner": - var probingDepth = (z - cycle.depth + tool.cornerRadius); - var measureString = "EdgeMeasure "; - - zOutput.reset(); - onRapid(x, y, cycle.stock); - onLinear(x, y, probingDepth, cycle.feedrate); - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - - forceXYZ(); - //zOutput.reset(); - onRapid(x, y, cycle.stock); - onLinear(x, y, probingDepth, cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; - // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; - - // var orientation = "" - // if (!isXNeagtive && !isYNeagtive) orientation = "BackRight"; - // if (isXNeagtive && !isYNeagtive) orientation = "BackLeft"; - // if (!isXNeagtive && isYNeagtive) orientation = "FrontRight"; - // if (isXNeagtive && isYNeagtive) orientation = "FrontLeft"; - - // var measureString = "CornerMeasure"; - // measureString += " " + orientation; - // measureString += " Inside"; - // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " forceSafeHeight" - // measureString += " skipZMeasure"; - // measureString += " originXShift=" + xyzFormat.format(-x); - // measureString += " originYShift=" + xyzFormat.format(-y); - // writeBlock(measureString); - break; - case "probing-xy-outer-corner": - var probingDepth = (z - cycle.depth + tool.cornerRadius); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var measureString = "EdgeMeasure "; - - zOutput.reset(); - onRapid(x, y, probingDepth); - onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); - measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - forceXYZ(); - onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); - onLinear(x, y, probingDepth, cycle.feedrate); - //forceXYZ(); - //zOutput.reset(); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - - var measureString = "EdgeMeasure "; - measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); - measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); - measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - writeBlock(measureString); - forceXYZ(); - onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); - onLinear(x, y, probingDepth, cycle.feedrate); - - // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; - // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; - - // var orientation = "" - // if (!isXNeagtive && !isYNeagtive) orientation = "FrontLeft"; - // if (isXNeagtive && !isYNeagtive) orientation = "FrontRight"; - // if (!isXNeagtive && isYNeagtive) orientation = "BackLeft"; - // if (isXNeagtive && isYNeagtive) orientation = "BackRight"; - - // var measureString = "CornerMeasure"; - // measureString += " " + orientation; - // measureString += " Outside"; - // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); - // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); - // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); - // measureString += " forceSafeHeight" - // measureString += " skipZMeasure"; - // measureString += " originXShift=" + xyzFormat.format(-x); - // measureString += " originYShift=" + xyzFormat.format(-y); - // writeBlock(measureString); - break; - case "probing-x-plane-angle": - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - // var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - // var touchPositionX2 = touchPositionX1; - // writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - // writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - // writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - // writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - // writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - // var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - // var touchPositionY2 = touchPositionY1; - // writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - // writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - // writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - // writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - // writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } - return; -} - -function drilling(cycle) { - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - boreCommandString.push("Drill"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - writeBlock(boreCommandString.join(" ")); -} - -function chipBreaking(cycle) { - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - boreCommandString.push("Drill"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - boreCommandString.push("infeedZ=infeedZ"); - writeBlock(boreCommandString.join(" ")); -} - -function boreMilling(cycle) { - if (cycle.numberOfSteps > 2) { - error("Only 2 steps are allowed for bore-milling."); - } - - var boreCommandString = new Array(); - var depth = xyzFormat.format(cycle.depth); - boreCommandString.push("DrillMilling"); - boreCommandString.push("diameter=diameter"); - boreCommandString.push("depth=" + depth); - boreCommandString.push("infeedZ=infeedZ"); - boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - - if (cycle.numberOfSteps == 2) { - var xycleaning = cycle.stepover; - var maxzdepthperstep = tool.fluteLength * 0.8; - boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); - boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); - } - var bottomcleaning = 0; - // finishingZ = 1; - writeBlock(boreCommandString.join(" ")); -} - -function threadMilling(cycle) { - var threadString = new Array(); - var depth = xyzFormat.format(cycle.depth); - - threadString.push("SpecialThread"); - // threadString.push('threadName=threadName'); - threadString.push("nominalDiameter=nominalDiameter"); - threadString.push("pitch=pitch"); - threadString.push("depth=" + depth); - threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - // threadString.push("threadStandard=threadStandard"); - // threadString.push("deburring=ThreadMillingDeburring.NoDeburring"); - // threadString.push("insideOutside=ThreadMillingSide.Inside"); - threadString.push("finishing=finishing"); - if (cycle.threading == "left") { - threadString.push("direction=ThreadMillingDirection.LeftHandThread"); - } else { - threadString.push("direction=ThreadMillingDirection.RightHandThread"); - } - writeBlock(threadString.join(" ")); -} - -function tapping(cycle) { - var tappingString = new Array(); - var depth = xyzFormat.format(cycle.depth); - tappingString.push("ThreadCutting"); - tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); - tappingString.push("depth=" + depth); - tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); - tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); - tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); - if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { - tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); - } - if (tool.type == TOOL_TAP_LEFT_HAND) { - tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); - } else { - tappingString.push("direction=ThreadMillingDirection.RightHandThread"); - } - writeBlock(tappingString.join(" ")); -} - -function formatCycleTime(cycleTime) { - // cycleTime = cycleTime + 0.5; // round up - var seconds = cycleTime % 60 | 0; - var minutes = ((cycleTime - seconds)/60 | 0) % 60; - var hours = (cycleTime - minutes * 60 - seconds)/(60 * 60) | 0; - if (hours > 0) { - return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); - } else if (minutes > 0) { - return subst(localize("%1m:%2s"), minutes, seconds); - } else { - return subst(localize("%1s"), seconds); - } -} - -function dump(name, _arguments) { - var result = getCurrentRecordId() + ": " + name + "("; - for (var i = 0; i < _arguments.length; ++i) { - if (i > 0) { - result += ", "; - } - if (typeof _arguments[i] == "string") { - result += "'" + _arguments[i] + "'"; - } else { - result += _arguments[i]; - } - } - result += ")"; - writeln(result); -} - -function onSectionEnd() { - writeBlock("ToolCompensation Off"); - if (currentSection.isMultiAxis && (properties.got4thAxis && properties.got5thAxis)){ - writeBlock("Rtcp Off"); - } - - // adds support for suction - if(properties.useSuction){ - writeBlock("Suction Off"); - } - - if (properties.useSequences && !isProbeOperation(currentSection)) { - if (!properties.useExternalSequencesFiles) { - sequenceFile.append(getRedirectionBuffer()); - } - closeRedirection(); - spacingDepth += 1; - } - - - writeBlock("EndBlock"); - - spacingDepth -= 1; - - writeBlock("endprogram " + "# " + getOperationName(currentSection)); - - writeBlock(" "); - forceAny(); -} - -function onClose() { - - if (properties.waitAfterOperation) { - writeWaitProgram(); - } - - writeBlock("end"); - - if (properties.useSequences && !properties.useExternalSequencesFiles) { - writeComment(spacing); - writeBlock(sequenceFile.toString()); - } -} +/** + Copyright (C) 2012-2018 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} +*/ + +description = "DATRON next"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 40783; + +longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; + +extension = "simpl"; +setCodePage("utf-8"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = true; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine : true, // write machine + showNotes : false, // specifies that operation notes should be output + useSmoothing : true, // specifies if smoothing should be used or not + useDynamic : true, // specifies using dynamic mode or not + useParkPosition : true, // specifies to use park position at the end of the program + writeToolTable : true, // write the table with the geometric tool informations + useSequences : true, // this use a sequence in the output format to perform on large files + useExternalSequencesFiles : false, // this property create one external sequence files for each operation + writeCoolantCommands : true, // disable the coolant commands in the file + useParametricFeed : true, // specifies that feed should be output using parameters + waitAfterOperation : false, // optional stop + got4thAxis: true, // specifies if the machine has a rotational 4th axis + got5thAxis: true, // aktivate the RTCP options + useSuction: false, // aktivate suction support +}; + +// user-defined property definitions +propertyDefinitions = { + writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, + showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"}, + useSmoothing: {title:"Use smoothing", description:"Specifies if smoothing should be used or not.", type:"boolean"}, + useDynamic: {title:"Dynamic mode", description:"Specifies the using of dynamic mode or not.", type:"boolean"}, + useParkPosition: {title: "Park at end of program", description:"Enable to use the park position at end of program.", type:"boolean"}, + writeToolTable: {title:"Write tool table", description:"Write a tool table containing geometric tool information.", group:0, type:"boolean"}, + useSequences: {title:"Use sequences", description:"If enables, sequences are used in the output format on large files.", type:"boolean"}, + useExternalSequencesFiles: {title:"Use external sequence files", description:"If enabled, an external sequence file is created for each operation.", type:"boolean"}, + writeCoolantCommands: {title:"Write coolant commands", description:"Enable/disable coolant code outputs for the entire program.", type:"boolean"}, + useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"}, + waitAfterOperation: {title:"Wait after operation", description:"If enabled, an optional stop is outputted to pause after each operation.", type:"boolean"}, + got4thAxis: {title:"Has 4th axis", description:"Enable if the machine is equipped with a 4-axis.", type:"boolean"}, + got5thAxis: {title:"Has 5th axis", description:"Enable if the machine is equipped with a DST.", type:"boolean"} +}; + +var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); +var toolFormat = createFormat({decimals:0}); +var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); +var rpmFormat = createFormat({decimals:0, scale:1}); +var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); + +var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); +var feedOutput = createVariable({prefix:""}, feedFormat); + +var xOutput = createVariable({prefix:" X="}, xyzFormat); +var yOutput = createVariable({prefix:" Y="}, xyzFormat); +var zOutput = createVariable({prefix:" Z="}, xyzFormat); +var aOutput = createVariable({prefix:" A="}, abcFormat); +var bOutput = createVariable({prefix:" B="}, abcFormat); +var cOutput = createVariable({prefix:" C="}, abcFormat); + +var iOutput = createVariable({prefix:" dX=", force : true}, feedFormat); +var jOutput = createVariable({prefix:" dY=", force : true}, feedFormat); +var kOutput = createVariable({prefix:" dZ="}, feedFormat); + +// fixed settings +var useDatronFeedCommand = false; // unsupported for now, keep false +var language = "de"; // specifies the language, replace with getLangId() +var spacingDepth = 0; +var spacingString = " "; +var sequenceFile = new StringBuffer(); +var spacing = "##########################################################"; + +// collected state +var currentFeedValue = -1; +var optionalSection = false; +var activeMovements; // do not use by default +var currentFeedId; + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +function getSequenceName(section) { + var sequenceName = ""; + if (properties.useExternalSequencesFiles) { + sequenceName += FileSystem.getFilename(getOutputPath().substr(0, getOutputPath().lastIndexOf("."))) + "_"; + } + sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); + return sequenceName; +} + +function getOperationName(section) { + return "Operation_" + getOperationDescription(section); +} + +function capitalizeFirstLetter(text) { + return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); +} + +function getSpacing() { + var space = ""; + for (var i = 0; i < spacingDepth; i++) { + space += spacingString; + } + return space; +} + +/** + Writes the specified block. +*/ +function writeBlock() { + var text = formatWords(arguments); + writeWords(getSpacing() + text); +} + +/** + Output a comment. +*/ +function writeComment(text) { + if (text) { + writeln(getSpacing() + "# " + text); + } +} + +var charMap = { + "\u00c4" : "Ae", + "\u00e4" : "ae", + "\u00dc" : "Ue", + "\u00fc" : "ue", + "\u00d6" : "Oe", + "\u00f6" : "oe", + "\u00df" : "ss", + "\u002d" : "_", + "\u0020" : "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + text = formatVariable(text); + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); +} + +function onOpen() { + // note: setup your machine here + if (properties.got4thAxis && !properties.got5thAxis) { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEO with A Axis"); + machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis + } + + // note: setup your machine here + if (properties.got4thAxis && properties.got5thAxis) { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis,cAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEXT with DST"); + machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode 0:Full TCP 1: Map Tool Tip to Axis + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + // header + writeProgramHeader(); + + // write program calls + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var opName = getOperationName(section); + var sectionID = i + 1; + writeBlock(opName); + } + + onCommand(COMMAND_COOLANT_OFF); + + writeBlock("Spindle Off"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + if (properties.useParkPosition) { + writeBlock("MoveToParkPosition"); + } else { + writeBlock("MoveToSafetyPosition"); + zOutput.reset(); + } + + spacingDepth -= 1; + writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + writeln(""); +} + +function getOperationDescription(section) { + // creates the name of the operation + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +function createToolVariables() { + var tools = getToolTable(); + if (tools.getNumberOfTools() > 0 && !properties.writeToolTable) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + writeBlock(toolOutput.format(tool.number) + ":number"); + } + writeBlock(" "); + } +} + +function createToolDescriptionTable() { + if (!properties.writeToolTable) { + return; + } + var toolDescriptionArray = new Array(); + var toolNameList = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var tool = section.getTool(); + if (tool.type != TOOL_PROBE) { + var toolName = createToolName(tool); + var toolProgrammed = createToolDescription(tool); + if (toolNameList.indexOf(toolName) == -1) { + toolNameList.push(toolName); + toolDescriptionArray.push(toolProgrammed); + } else { +/* + if (toolDescriptionArray.indexOf(toolProgrammed) == -1) { + error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" + + toolNameList.join("\r\n") + "#####################################\r\n"); + } +*/ + } + } + } + + writeBlock(toolDescriptionArray.join("\r\n")); +} + +function createToolDescription(tool) { + var toolProgrammed = "@ ToolDescription : " + + "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + + "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + + "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + + "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + + "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + + "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + + "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + + "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + + "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + + "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + + "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + + "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + + "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + + "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + + "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + + " @"; + return toolProgrammed; +} + +/** + Generate the logical tool name for the assignment table of used tools. +*/ +function createToolName(tool) { + var toolName = toolFormat.format(tool.number); + toolName += "_" + translateToolType(tool.type); + if (tool.comment) { + toolName += "_" + tool.comment; + } + if (tool.diameter) { + toolName += "_D" + tool.diameter; + } + var description = tool.getDescription(); + if (description) { + toolName += "_" + description; + } + toolName = formatVariable(toolName); + return toolName; +} + +/** + Translate HSM tools to Datron tool categories. +*/ +function translateToolType(toolType) { + + var datronCategoryName = ""; + + toolCategory = toolType; + switch (toolType) { + case TOOL_UNSPECIFIED: + datronCategoryName = "Unspecified"; + break; + case TOOL_DRILL: + datronCategoryName = "Drill"; + break; + case TOOL_DRILL_CENTER: + datronCategoryName = "DrillCenter"; + break; + case TOOL_DRILL_SPOT: + datronCategoryName = "DrillSpot"; + break; + case TOOL_DRILL_BLOCK: + datronCategoryName = "DrillBlock"; + break; + case TOOL_MILLING_END_FLAT: + datronCategoryName = "MillingEndFlat"; + break; + case TOOL_MILLING_END_BALL: + datronCategoryName = "MillingEndBall"; + break; + case TOOL_MILLING_END_BULLNOSE: + datronCategoryName = "MillingEndBullnose"; + break; + case TOOL_MILLING_CHAMFER: + datronCategoryName = "Graver"; + break; + case TOOL_MILLING_FACE: + datronCategoryName = "MillingFace"; + break; + case TOOL_MILLING_SLOT: + datronCategoryName = "MillingSlot"; + break; + case TOOL_MILLING_RADIUS: + datronCategoryName = "MillingRadius"; + break; + case TOOL_MILLING_DOVETAIL: + datronCategoryName = "MillingDovetail"; + break; + case TOOL_MILLING_TAPERED: + datronCategoryName = "MillingTapered"; + break; + case TOOL_MILLING_LOLLIPOP: + datronCategoryName = "MillingLollipop"; + break; + case TOOL_TAP_RIGHT_HAND: + datronCategoryName = "TapRightHand"; + break; + case TOOL_TAP_LEFT_HAND: + datronCategoryName = "TapLeftHand"; + break; + case TOOL_REAMER: + datronCategoryName = "Reamer"; + break; + case TOOL_BORING_BAR: + datronCategoryName = "BoringBar"; + break; + case TOOL_COUNTER_BORE: + datronCategoryName = "CounterBore"; + break; + case TOOL_COUNTER_SINK: + datronCategoryName = "CounterSink"; + break; + case TOOL_HOLDER_ONLY: + datronCategoryName = "HolderOnly"; + break; + case TOOL_PROBE: + datronCategoryName = "XYZSensor"; + break; + default: + datronCategoryName = "Unspecified"; + } + return datronCategoryName; +} + +function writeProgramHeader() { + // write creation Date + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + writeComment("!File ; generated at " + date + " - " + time); + if (programComment) { + writeComment(formatComment(programComment)); + } + + writeBlock(" "); + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + writeBlock("module " + "CamGeneratedModule"); + writeBlock(" "); + + writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); + + // write the table of used tools in the header of the program + createToolDescriptionTable(); + writeBlock(""); + + writeWorkpiece(); + + // Creates the sequence header in the program file + if (properties.useSequences) { + var sequences = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (!isProbeOperation(section)) { + sequences.push(getSequenceName(section)); + } + } + if (properties.useExternalSequencesFiles) { + writeBlock("@ EmbeddedSequences = false @"); + } + if (sequences.length > 0) { + writeBlock("sequence " + sequences.join("\r\nsequence ")); + writeBlock(" "); + } + } + + // dont ask why the control need it + writeBlock("using Base"); + if (properties.got5thAxis){ + writeBlock("using Rtcp"); + } + if (properties.waitAfterOperation) { + writeBlock("import System"); + } + writeBlock(" "); + + // scan all operations for the parametric feed commands + var feedDeclaration = new Array(); + var currentMovements = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (properties.useParametricFeed && (!useDatronFeedCommand)) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (feedDeclaration.indexOf(feedDescription) == -1) { + feedDeclaration.push(feedDescription); + } + } + } + } + + // write all the variable declarations in the header of the program + if (!useDatronFeedCommand) { + writeComment("feed variables declaration"); + if (feedDeclaration != 0) { + writeBlock(feedDeclaration.join(":number\r\n") + ":number\r\n"); + } + } + + createToolVariables(); + + writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + spacingDepth += 1; + + writeBlock("Absolute"); + + // write the parameter tool table + if (!properties.writeToolTable) { + var tools = getToolTable(); + writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + dimensionFormat.format(tool.diameter) + " " + + "L2:" + dimensionFormat.format(tool.fluteLength) + " " + + "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + + "ProductID:" + formatComment(tool.productId); + writeBlock(toolAsigment); + } + writeBlock(" "); + } + } +} + + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("# Workpiece dimensions"); + writeBlock( + "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z)); + writeBlock( + "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z)); + writeBlock( + "# Part size X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z)); + + writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + + "\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + + " @"); + writeBlock(" "); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, datronFeedName, feed) { + this.id = id; + this.description = description; + this.datronFeedName = datronFeedName; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + if (useDatronFeedCommand) { + return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); + } else { + return ("Feed=" + formatVariable(feedContext.description)); + } + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return "Feed=" + feedFormat.format(f); + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + addFeedContext(feedContext, activeFeeds); + } + ++id; + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + + // this part allows us to use feedContext also for the cycles + if (hasParameter("operation:cycleType")) { + var cycleType = getParameter("operation:cycleType"); + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + + switch (cycleType) { + case "thread-milling": + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + case "bore-milling": + if (section.hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (section.hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + } + } + + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +/** Check that all elements are only one time in the result list. */ +function addFeedContext(feedContext, activeFeeds) { + if (activeFeeds.indexOf(feedContext) == -1) { + activeFeeds.push(feedContext); + } +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function setWorkPlane(abc) { + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + forceWorkPlane(); // always need the new workPlane + forceABC(); + + writeBlock("MoveToSafetyPosition"); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + var tool = currentSection.getTool(); + + if (!isProbeOperation(currentSection)) { + writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); + } + + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + zRange.expandToRange(currentSection.getGlobalZRange()); + writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); + } + } + + // create sub program + writeBlock("program " + getOperationName(currentSection)); + spacingDepth += 1; + + if (passThrough) { + var joinString = "\r\n" + getSpacing(); + var passThroughString = passThrough.join(joinString); + if (passThroughString != "") { + writeBlock(passThroughString); + } + passThrough = []; + } + + // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. + writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); + var operationTolerance = tolerance; + if (hasParameter("operation:tolerance")) { + if (operationTolerance < getParameter("operation:tolerance")) { + operationTolerance = getParameter("operation:tolerance"); + } + } + + //load the matching workOffset + var workOffset = currentSection.getWorkOffset(); + if (workOffset != 0) { + writeBlock("LoadWcs name=\"" + workOffset +"\""); + } + + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); + } else + { + writeBlock("Smoothing Off"); + } + + if (properties.useDynamic) { + + var dynamic = 5; + /* + if (operationTolerance <= 0.02) { + dynamic = 4; + } + if (operationTolerance <= 0.01) { + dynamic = 3; + } + if (operationTolerance <= 0.005) { + dynamic = 2; + } + if (operationTolerance <= 0.003) { + dynamic = 1; + } + */ + writeBlock("Dynamic = " + dynamic); + } + if (properties.waitAfterOperation) { + showWaitDialog(); + } + + if (machineConfiguration.isMultiAxisConfiguration()) { + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + if(properties.got5thAxis){ + writeBlock("Rtcp On"); + } + + writeBlock("MoveToSafetyPosition"); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + } else { + forceWorkPlane(); + var abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + if(properties.got5thAxis){ + writeBlock("Rtcp On"); + } + + } + } else { + // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + error("\r\n_________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| Tool orientation detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis, otherwise you can only post|" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|________________________________________|\r\n"); + return; + } + setRotation(remaining); + } + + forceAny(); + + if (properties.showNotes && currentSection.hasParameter("notes")) { + var notes = currentSection.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + + var clearance = getFramePosition(currentSection.getInitialPosition()).z; + writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); + + if (!isProbeOperation(currentSection)) { +<<<<<<< HEAD +======= + // set rpm + /* + if ((spindleSpeed < 6000) && (spindleSpeed > 0)) { + spindleSpeed = 6000; + } + */ +>>>>>>> b96761ab7bb85d33b42496678b6eac58498e9d70 + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + + // tool changer command + if (properties.writeToolTable) { + writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } else { + writeBlock("Tool = " + toolOutput.format(tool.number) + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } + + // set the current feed + // replace by the default feed command + if (properties.useParametricFeed && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + if (useDatronFeedCommand) { + var datronFeedParameter = new Array(); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var datronFeedCommand = { + name : feedContext.datronFeedName, + feed : feedFormat.format(feedContext.feed) + }; +/*eslint-disable*/ + var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); +/*eslint-enable*/ + if (indexOfFeedContext == -1) { + datronFeedParameter.push(datronFeedCommand); + } else { + var existingFeedContext = datronFeedParameter[indexOfFeedContext]; + if (existingFeedContext.feed < datronFeedCommand.feed) { + existingFeedContext.feed = datronFeedCommand.feed; + } + } + } + var datronFeedCommand = "SetFeedTechnology"; + for (var i = 0; i < datronFeedParameter.length; i++) { + datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; + } + writeBlock(datronFeedCommand); + + } else { + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); + } + } + } + } + + // parameter for the sequences + var sequenceParamter = new Array(); + + if (hasParameter("operation:cycleType")) { + + //Reset all movements to suppress older entries... + activeMovements = new Array(); + + var cycleType = getParameter("operation:cycleType"); + writeComment("Parameter " + cycleType + " cycle"); + + switch (cycleType) { + case "thread-milling": + writeBlock("SetFeedTechnology" + " ramp=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:finish_cutting"))); + var diameter = currentSection.getParameter("diameter"); + var pitch = currentSection.getParameter("pitch"); + var finishing = currentSection.getParameter("stepover"); + + writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); + sequenceParamter.push("nominalDiameter=nominalDiameter"); + writeBlock("pitch=" + xyzFormat.format(pitch)); + sequenceParamter.push("pitch=pitch"); + if (xyzFormat.isSignificant(finishing)) { + writeBlock("finishing=" + xyzFormat.format(finishing)); + sequenceParamter.push("finishing=finishing"); + } else { + sequenceParamter.push("finishing=0"); + } +/* + writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); + sequenceParamter.push('threadName=threadName'); + writeBlock("threading = " + currentSection.getParameter("threading")); + sequenceParamter.push("threading=threading"); + + TAG: den Standard auch mit Imperial unterstuezten + sequenceParamter.push("threadStandard=ThreadStandards.Metric"); + sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); + sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); + sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); + writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); + sequenceParamter.push("direction=direction"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); +*/ + break; + case "bore-milling": + writeBlock("SetFeedTechnology roughing=" + feedFormat.format(getParameter("movement:cutting")) + " finishing=" + feedFormat.format(getParameter("movement:cutting"))); + writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); + sequenceParamter.push("diameter=diameter"); + + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); + sequenceParamter.push("infeedZ=infeedZ"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); + break; + case "drilling": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge"))); + break; + case "chip-breaking": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(getParameter("movement:plunge")) + " roughing=" + feedFormat.format(getParameter("movement:cutting"))); + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); + sequenceParamter.push("infeedZ=infeedZ"); + break; + } + } + + if (properties.useSequences && !isProbeOperation(currentSection)) { + // call sequence + if (properties.useParametricFeed && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + sequenceParamter.push(formatVariable(feedContext.description) + "=" + formatVariable(feedContext.description)); + } + } + var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); + writeBlock(currentSectionCall); + + // write sequence + var currentSequenceName = getSequenceName(currentSection); + if (properties.useExternalSequencesFiles) { + spacingDepth -= 1; + var filename = getOutputPath(); + //sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; + sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; + sequenceFilePath += currentSequenceName + ".seq"; + redirectToFile(sequenceFilePath); + } else { + redirectToBuffer(); + writeBlock(" "); + // TAG: modify parameter + spacingDepth -= 1; + writeBlock("$$$ " + currentSequenceName); + } + } + + if (!isProbeOperation(currentSection)) { + writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); + } else { + writeBlock("Spindle Off"); + writeBlock("PrepareXyzSensor"); + } + + // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); + + writeBlock("PrePositioning" + xyz); + + // adds support for suction + if(properties.useSuction){ + writeBlock("Suction On"); + } + +} + + +function showWaitDialog(operationName) { + writeBlock("showWaitDialog"); +} + +function writeWaitProgram() { + writeBlock("#Show the wait dialog for the next operation"); + writeBlock("program showWaitDialog optional operationName:string"); + writeBlock(""); + writeBlock(" if not operationName hasvalue "); + writeBlock(" operationName =" + "\"" + "\""); + writeBlock(" endif"); + writeBlock(""); + writeBlock(" messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName "); + writeBlock(" dialogResult = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel"); + writeBlock(" if dialogResult == System::DialogResult.Cancel"); + writeBlock(" exit"); + writeBlock(" endif"); + writeBlock(""); + writeBlock("endprogram"); +} + +function onDwell(seconds) { + writeln("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + // writeBlock("Rpm=" + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed)); + writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("Rapid" + xyz); + forceFeed(); + } +} + +function onPrePositioning(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("PrePositioning" + xyz); + forceFeed(); + } +} + +function onLinear(x, y, z, feed) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + var f = getFeed(feed); + + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > 99) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + // TAG: um die Ebenen kuemmern + // writeBlock(gPlaneModal.format(17)); + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock("ToolCompensation Left"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock("ToolCompensation Right"); + break; + case RADIUS_COMPENSATION_OFF: + writeBlock("ToolCompensation Off"); + break; + } + } + + if (xyz) { + if (f) { + writeBlock(f); + } + writeBlock("Line" + xyz); + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + + if (pendingRadiusCompensation >= 0) { + error(localize("radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + yOutput.format(y) + + zOutput.format(z) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + + forceABC(); + var xyzabc = x + y + z + a + b + c; + writeBlock("Rapid" + xyzabc); + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + var f = getFeed(feed); + + writeBlock(f); + if (x || y || z || a || b || c) { + var xyzabc = x + y + z + a + b + c; + writeBlock("Line" + xyzabc); + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onRewindMachine(a, b, c) { + writeBlock("MoveToSafetyPosition"); + var abc = aOutput.format(a) + bOutput.format(b) + cOutput.format(c); + writeBlock("Line" + abc); +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (properties.writeCoolantCommands) { + if (coolant == COOLANT_OFF) { + writeBlock("SpraySystem Off"); + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR: + writeBlock("Coolant Air"); + break; + default: + onUnsupportedCoolant(coolant); + } + writeBlock("SpraySystem On"); + currentCoolantMode = coolant; + } +} + +var mapCommand = {}; + +var passThrough = new Array(); + +function onPassThrough(text) { + passThrough.push(text); +} + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onCycle() { +} + +function onCycleEnd() { +} + +function isProbeOperation(section) { + return (section.hasParameter("operation-strategy") && section.getParameter("operation-strategy") == "probe"); +} + +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + var feedString = feedOutput.format(cycle.feedrate); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) && (!cycle.probeMode || (cycle.probeMode == 0))) { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + + var startPositionOffset = cycle.probeClearance + tool.cornerRadius; + } + + switch (cycleType) { + case "bore-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onRapid(x, y, cycle.clearance); + boreMilling(cycle); + onRapid(x, y, cycle.clearance); + } + break; + case "thread-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onRapid(x, y, cycle.clearance); + threadMilling(cycle); + onRapid(x, y, cycle.clearance); + } + break; + case "drilling": + forceXYZ(); + onRapid(x, y, cycle.clearance); + drilling(cycle); + onRapid(x, y, cycle.clearance); + break; +/* + case "chip-breaking": + forceXYZ(); + onRapid(x, y, null); + onRapid(x, y, cycle.retract); + chipBreaking(cycle); + onRapid(x, y, cycle.clearance); + break; +*/ + case "tapping": + case "left-tapping": + case "right-tapping": + case "tapping-with-chip-breaking": + case "left-tapping-with-chip-breaking": + case "right-tapping-with-chip-breaking": + forceXYZ(); + onRapid(x, y, cycle.clearance); + tapping(cycle); + onRapid(x, y, cycle.clearance); + break; + case "probing-x": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + break; + case "probing-y": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + break; + case "probing-z": + forceXYZ(); + onRapid(x, y, cycle.stock); + onLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); + + var measureString = "SurfaceMeasure "; + measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); + writeBlock(measureString); + break; + case "probing-x-wall": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-y-wall": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-x-channel": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-x-channel-with-island": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + break; + case "probing-y-channel": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-y-channel-with-island": + var measureString = "SymmetryAxisMeasure"; + measureString += " width=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-boss": + var measureString = "CircleMeasure"; + measureString += " diameter=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-hole": + var measureString = "CircleMeasure"; + measureString += " diameter=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-circular-hole-with-island": + var measureString = "CircleMeasure"; + measureString += " diameter=" + cycle.width1; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " measureZPos=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-boss": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + cycle.width1; + measureString += " dimensionY=" + cycle.width2; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Outside"; + measureString += " Center"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-hole": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + cycle.width1; + measureString += " dimensionY=" + cycle.width2; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " Center"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-rectangular-hole-with-island": + var measureString = "RectangleMeasure"; + measureString += " dimensionX=" + cycle.width1; + measureString += " dimensionY=" + cycle.width2; + measureString += " searchDistance=" + cycle.probeClearance; + measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + measureString += " Inside"; + measureString += " Center"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + break; + case "probing-xy-inner-corner": + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "EdgeMeasure "; + + zOutput.reset(); + onRapid(x, y, cycle.stock); + onLinear(x, y, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + + forceXYZ(); + //zOutput.reset(); + onRapid(x, y, cycle.stock); + onLinear(x, y, probingDepth, cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; + // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; + + // var orientation = "" + // if (!isXNeagtive && !isYNeagtive) orientation = "BackRight"; + // if (isXNeagtive && !isYNeagtive) orientation = "BackLeft"; + // if (!isXNeagtive && isYNeagtive) orientation = "FrontRight"; + // if (isXNeagtive && isYNeagtive) orientation = "FrontLeft"; + + // var measureString = "CornerMeasure"; + // measureString += " " + orientation; + // measureString += " Inside"; + // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " forceSafeHeight" + // measureString += " skipZMeasure"; + // measureString += " originXShift=" + xyzFormat.format(-x); + // measureString += " originYShift=" + xyzFormat.format(-y); + // writeBlock(measureString); + break; + case "probing-xy-outer-corner": + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var measureString = "EdgeMeasure "; + + zOutput.reset(); + onRapid(x, y, probingDepth); + onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + onLinear(x, y, probingDepth, cycle.feedrate); + //forceXYZ(); + //zOutput.reset(); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + + var measureString = "EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onLinear(x, y, probingDepth, cycle.feedrate); + + // var isXNeagtive = (cycle.approach1 == "negative") ? true : false; + // var isYNeagtive = (cycle.approach2 == "negative") ? true : false; + + // var orientation = "" + // if (!isXNeagtive && !isYNeagtive) orientation = "FrontLeft"; + // if (isXNeagtive && !isYNeagtive) orientation = "FrontRight"; + // if (!isXNeagtive && isYNeagtive) orientation = "BackLeft"; + // if (isXNeagtive && isYNeagtive) orientation = "BackRight"; + + // var measureString = "CornerMeasure"; + // measureString += " " + orientation; + // measureString += " Outside"; + // measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + // measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + // measureString += " xMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " yMeasureZOffset=" + (z - cycle.depth + tool.diameter / 2); + // measureString += " forceSafeHeight" + // measureString += " skipZMeasure"; + // measureString += " originXShift=" + xyzFormat.format(-x); + // measureString += " originYShift=" + xyzFormat.format(-y); + // writeBlock(measureString); + break; + case "probing-x-plane-angle": + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + // var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + // var touchPositionX2 = touchPositionX1; + // writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + // writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + // writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + // writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + // writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + // var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + // var touchPositionY2 = touchPositionY1; + // writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + // writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + // writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + // writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + // writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + // writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + // writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } + return; +} + +function drilling(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + writeBlock(boreCommandString.join(" ")); +} + +function chipBreaking(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + boreCommandString.push("infeedZ=infeedZ"); + writeBlock(boreCommandString.join(" ")); +} + +function boreMilling(cycle) { + if (cycle.numberOfSteps > 2) { + error("Only 2 steps are allowed for bore-milling."); + } + + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + boreCommandString.push("DrillMilling"); + boreCommandString.push("diameter=diameter"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("infeedZ=infeedZ"); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + + if (cycle.numberOfSteps == 2) { + var xycleaning = cycle.stepover; + var maxzdepthperstep = tool.fluteLength * 0.8; + boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); + boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); + } + var bottomcleaning = 0; + // finishingZ = 1; + writeBlock(boreCommandString.join(" ")); +} + +function threadMilling(cycle) { + var threadString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + threadString.push("SpecialThread"); + // threadString.push('threadName=threadName'); + threadString.push("nominalDiameter=nominalDiameter"); + threadString.push("pitch=pitch"); + threadString.push("depth=" + depth); + threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + // threadString.push("threadStandard=threadStandard"); + // threadString.push("deburring=ThreadMillingDeburring.NoDeburring"); + // threadString.push("insideOutside=ThreadMillingSide.Inside"); + threadString.push("finishing=finishing"); + if (cycle.threading == "left") { + threadString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + threadString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(threadString.join(" ")); +} + +function tapping(cycle) { + var tappingString = new Array(); + var depth = xyzFormat.format(cycle.depth); + tappingString.push("ThreadCutting"); + tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); + tappingString.push("depth=" + depth); + tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); + if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { + tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); + } + if (tool.type == TOOL_TAP_LEFT_HAND) { + tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + tappingString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(tappingString.join(" ")); +} + +function formatCycleTime(cycleTime) { + // cycleTime = cycleTime + 0.5; // round up + var seconds = cycleTime % 60 | 0; + var minutes = ((cycleTime - seconds)/60 | 0) % 60; + var hours = (cycleTime - minutes * 60 - seconds)/(60 * 60) | 0; + if (hours > 0) { + return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); + } else if (minutes > 0) { + return subst(localize("%1m:%2s"), minutes, seconds); + } else { + return subst(localize("%1s"), seconds); + } +} + +function dump(name, _arguments) { + var result = getCurrentRecordId() + ": " + name + "("; + for (var i = 0; i < _arguments.length; ++i) { + if (i > 0) { + result += ", "; + } + if (typeof _arguments[i] == "string") { + result += "'" + _arguments[i] + "'"; + } else { + result += _arguments[i]; + } + } + result += ")"; + writeln(result); +} + +function onSectionEnd() { + writeBlock("ToolCompensation Off"); + if (currentSection.isMultiAxis && (properties.got4thAxis && properties.got5thAxis)){ + writeBlock("Rtcp Off"); + } + + // adds support for suction + if(properties.useSuction){ + writeBlock("Suction Off"); + } + + if (properties.useSequences && !isProbeOperation(currentSection)) { + if (!properties.useExternalSequencesFiles) { + sequenceFile.append(getRedirectionBuffer()); + } + closeRedirection(); + spacingDepth += 1; + } + + + writeBlock("EndBlock"); + + spacingDepth -= 1; + + writeBlock("endprogram " + "# " + getOperationName(currentSection)); + + writeBlock(" "); + forceAny(); +} + +function onClose() { + + if (properties.waitAfterOperation) { + writeWaitProgram(); + } + + writeBlock("end"); + + if (properties.useSequences && !properties.useExternalSequencesFiles) { + writeComment(spacing); + writeBlock(sequenceFile.toString()); + } +} diff --git a/datron trunnion mcr english.cps b/deprecated/datron trunnion mcr english.cps similarity index 97% rename from datron trunnion mcr english.cps rename to deprecated/datron trunnion mcr english.cps index da233b2..9b58aba 100644 --- a/datron trunnion mcr english.cps +++ b/deprecated/datron trunnion mcr english.cps @@ -1,2283 +1,2283 @@ -/** - Copyright (C) 2012-2017 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision$ - $Date$ - - FORKID {6884BEFE-3BAF-4433-BD9A-A3130BEBB2CD} -*/ - -description = "Generic DATRON Trunnion MCR (English)"; -vendor = "DATRON"; -vendorUrl = "http://www.datron.com"; -legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -longDescription = "Generic post for DATRON CNCs. This post works with DATRON M7, DATRON M8, DATRON M8Cube, DATRON M10, and DATRON M35 with the 5-axis trunnion table."; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - writeVersion: false, // include version info - showOperationDialog: true, // shows a start dialog on the control to select the operation to start with - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - useTimeStamp: false, // specifies to output time stamp - writeCoolantCommands: false // en/disable coolant code output for the entire program -}; - -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); -var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); - -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... - -// fixed settings -var language = "en"; // supported languages are: "en", "de" -var useRTCPSimu = true; // use TCP "light" or not -var useInverseTime = false; // enable inverseTime output here if needed - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var containsProbingOperations = false; -var previousABC = new Vector(0, 0, 0); - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -// Start of Multi-axis Feed Rate logic -/***** Be sure to add 'useInverseTime' to post properties if necessary *****/ -/***** 'previousABC' must be added throughout to maintain previous rotary positions *****/ -/***** 'headOffset' should be defined when a head rotary axis is defined *****/ -/***** The feed rate mode must be included in motion block output (linear, circular, etc. *****/ -var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations -var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds -var maxInverseTime = 9999.999 * 2.9; // maximum value to output for Inverse Time feeds - -/** Calculate the multi-axis feed rate number */ -function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { - var f = {frn:0, fmode:0}; - if (feed <= 0) { - error(localize("Feedrate is less than or equal to 0.")); - return f; - } - - var length = getMoveLength(_x, _y, _z, _a, _b, _c); - - if (useInverseTime) { // inverse time - var time = getInverseTime(length[0], feed); - f.frn = inverseTimeFormat.format(time); - f.fmode = 93; - feedOutput.reset(); - } else { // degrees per minute - f.frn = feedOutput.format(getFeedDPM(length, feed)); - f.fmode = 94; - } - return f; -} - -/** Calculate the DPM feed rate number */ -function getFeedDPM(_moveLength, _feed) { - // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC - - if (properties.useTCPMode) { // TCP mode is supported, output feed as FPM - return feed; - } else { // DPM feed rate calculation - var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; - var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); - return length / moveTime; - } -} - -/** Calculate the Inverse time feed rate number */ -function getInverseTime(_length, _feed) { - var inverseTime; - if (_length < 1.e-6) { // tool doesn't move - if (typeof (maxInverseTime) == "number") { - inverseTime = maxInverseTime; - } else { - inverseTime = 999999; - } - } else { - inverseTime = _feed / _length / inverseTimeUnits; - if (typeof (maxInverseTime) == "number") { - if (inverseTime > maxInverseTime) { - inverseTime = maxInverseTime; - } - } - } - return inverseTime; -} - -/** Calculate the distance of the tool position to the center of a rotary axis */ -function getRotaryRadius(center, direction, toolPosition) { - var normal = direction.getNormalized(); - var d1 = toolPosition.x - center.x; - var d2 = toolPosition.y - center.y; - var d3 = toolPosition.z - center.z; - var radius = Math.sqrt( - Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + - Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + - Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) - ); - return radius; -} - -/** Calculate the linear distance based on the rotation of a rotary axis */ -function getRadialDistance(axis, startTool, endTool, startABC, endABC) { - // rotary axis does not exist - if (!axis.isEnabled()) { - return 0.0; - } - - // calculate the rotary center based on head/table - var center; - if (axis.isHead()) { - var pivot; - if (typeof (headOffset) == "number") { - pivot = headOffset; - } else { - pivot = tool.getBodyLength(); - } - center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); - center = Vector.sum(center, axis.getOffset()); - } else { - center = axis.getOffset(); - } - - // calculate the radius of the tool end point compared to the rotary center - var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); - var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); - - // calculate length of radial move - var radius = Math.max(startRadius, endRadius); - var delta = Math.abs(endABC[axis.getCoordinate()] - startABC[axis.getCoordinate()]); - if (delta > Math.PI) { - delta = 2*Math.PI - delta; - } - var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); - return radialLength; -} - -/** Calculate tooltip, XYZ, and rotary move lengths. */ -function getMoveLength(_x, _y, _z, _a, _b, _c) { - // get starting and ending positions - var moveLength = new Array(); - var startTool; - var endTool; - var startXYZ; - var endXYZ; - var startABC = new Array(previousABC.x, previousABC.y, previousABC.z); - var endABC = new Array(_a, _b, _c); - - if (currentSection.getOptimizedTCPMode() == 0) { - startTool = getCurrentPosition(); - endTool = new Vector(_x, _y, _z); - startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); - endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); - } else { - startXYZ = getCurrentPosition(); - endXYZ = new Vector(_x, _y, _z); - startTool = machineConfiguration.getOrientation(previousABC).multiply(startXYZ); - endTool = machineConfiguration.getOrientation(new Vector(_a, _b, _c)).multiply(endXYZ); - } - - // calculate the radial portion of the move - var radialLength = Math.sqrt( - Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + - Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) - ); - - // calculate the lengths of move - // tool tip distance is the move distance based on a combination of linear and rotary axes movement - var linearLength = Vector.diff(endXYZ, startXYZ).length; - moveLength[0] = linearLength + radialLength; - moveLength[1] = Vector.diff(endXYZ, startXYZ).length; - moveLength[2] = Vector.diff( - new Vector(endABC[0], endABC[1], endABC[2]), - new Vector(startABC[0], startABC[1], startABC[2]) - ).length; - return moveLength; -} -// End of Multi-axis Feed Rate logic - -/** - Writes the specified block. -*/ -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - - if (true) { // trunnion table - var aAxis = createAxis({coordinate:0, table:true, axis:[-1, 0, 0], range:[-102.5, 0], preference:-1}); - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (isProbeOperation(section)) { - containsProbingOperations = true; - break; - } - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if (section.hasParameter("operation:cycleType")) { - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; - return description; -} - -/** Writes the tool table. */ -function writeToolTable() { - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - if (properties.useTimeStamp) { - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - } else { - writeBlock("!Makro file ; V9.09F!"); - } - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); - switch (language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - if (properties.showOperationDialog) { - variablesDeclaration.push("optional_stop"); - } - variablesDeclaration.push("$Message"); - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.showOperationDialog) { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - if (properties.showOperationDialog) { - var dropDownElements = new Array(); - variablesDeclaration.push("startOperation"); - } - - var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var sectionID = i + 1; - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (properties.showOperationDialog) { - dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (properties.showOperationDialog) { - dropDownDialog += dropDownElements.join(", "); - dropDownDialog += ">\", \"Select the operation to start with. \""; - dialogsDeclaration.push(dropDownDialog); - } - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - variablesDeclaration.push("A_delta"); - variablesDeclaration.push("B_delta"); - variablesDeclaration.push("C_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - variablesDeclaration.push("A_temp"); - variablesDeclaration.push("B_temp"); - variablesDeclaration.push("C_temp"); - variablesDeclaration.push("Isinitialposition"); - variablesDeclaration.push("timefeed"); - - - submacrosDeclaration.push("Initposition"); - submacrosDeclaration.push("Endmacro"); - } - - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - submacrosDeclaration.push("Transformpath"); - } - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - submacrosDeclaration.push("Transformoffset"); - } - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - if (containsProbingOperations) { - variablesDeclaration.push("Xvalue1"); - variablesDeclaration.push("Xvalue2"); - variablesDeclaration.push("Yvalue1"); - variablesDeclaration.push("Yvalue2"); - variablesDeclaration.push("Zvalue"); - variablesDeclaration.push("Newpos"); - variablesDeclaration.push("Rotationvalue"); - } - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("_exit Endmacro;"); - writeln(""); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - } - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); - writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); - writeln(""); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - createPositionInitSubmacro(); - createEndmacro(); - } - - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - createRtcpTransformationSubmacro(); - } - - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - //writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - writeBlock(translate("Label") + " " + sectionID + ";"); - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - if (!isProbeOperation(section)) { - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) { - dynamic = 4; - } - if (t <= 0.01) { - dynamic = 3; - } - if (t <= 0.005) { - dynamic = 2; - } - if (t <= 0.003) { - dynamic = 1; - } - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); - } - } - - // wcs - var workOffset; - if (!is3D()) { - workOffset = 19; - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } else { - workOffset = section.workOffset; - if (workOffset != 0 && workOffset < 41) { - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - } - } - } - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - // insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } - return ""; -} - -function initializeActiveFeeds(section) { - var activeFeeds = new Array(); - if (section.hasAnyCycle && section.hasAnyCycle()) { - return activeFeeds; - } - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function onRewindMachine() { - writeComment("REWIND"); -} - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - if (true) { - writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); - writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); - writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); - writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); - } - - if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { - writeBlock(translate("Submacro") + " Transformoffset 0, ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.y) +", ", - abcFormat.format(abc.z) +";"); - } - - currentWorkPlaneABC = abc; - previousABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return undefined; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - return undefined; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - // error(localize("RTCP is not supported.")); - // return; - - writeBlock("("); - if (useInverseTime) { - writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); - } - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); - - writeBlock("A_temp = A - A_delta;"); - writeBlock("B_temp = B - B_delta;"); - writeBlock("C_temp = C - C_delta;"); - - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, B_temp, C_temp;"); - writeBlock(") Transformpath;"); - -} - -function createRtcpTransformationSubmacro() { - writeBlock("("); - writeBlock("Position 19, 2;"); - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X6p + X_trans;"); - writeBlock("Y_new = Y6p + Y_trans;"); - writeBlock("Z_new = Z6p + Z_trans;"); - writeBlock(";!set new position!;"); - writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); - writeBlock(") Transformoffset;"); -} - -function createPositionInitSubmacro() { - // get initial offset - writeBlock("("); - writeBlock("X_initial_pos = X6p;"); - writeBlock("Y_initial_pos = Y6p;"); - writeBlock("Z_initial_pos = Z6p;"); - writeBlock("A_initial_pos = A6p;"); - writeBlock("B_initial_pos = B6p;"); - writeBlock("C_initial_pos = C6p;"); - writeBlock("Position 19, 2;"); - writeBlock("X_delta = X_initial_pos - X6p;"); - writeBlock("Y_delta = Y_initial_pos - Y6p;"); - writeBlock("Z_delta = Z_initial_pos - Z6p;"); - writeBlock("A_delta = A_initial_pos - A6p;"); - writeBlock("B_delta = B_initial_pos - B6p;"); - writeBlock("C_delta = C_initial_pos - C6p;"); - writeBlock(") Initposition;"); -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - 10;"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - - -function createEndmacro() { - writeBlock("("); - if (useInverseTime) { - mcrSetTimeFeed(); - } - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -function isProbeOperation(section) { - return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); -} - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); - - writeBlock("("); - if (isProbeOperation(currentSection)) { - writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // enable probe - writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); - } else { - writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // disable probe - } - - if (insertToolCall || newWorkOffset || newWorkPlane) { - - // retract to safe plane - retracted = true; - writeBlock(translate("Submacro") + " Retractzmax;"); - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - retracted = true; - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\n________________________________________" + - "\r\n| error |"+ - "\r\n| |"+ - "\r\n| 5 axis operations require adjustments |"+ - "\r\n| to the postprocessor for your |"+ - "\r\n| machining system. |"+ - "\r\n| Please contact www.DATRON.com! |"+ - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - - if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { - writeBlock("Position 19, 2;"); - writeBlock(translate("Submacro") + " Retractzmax;"); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ",0;" - ); - } else { - if (!retracted) { - writeBlock(translate("Submacro") + " Retractzmax;"); - } - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/ && - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - (getPreviousSection().getPatternId() == currentSection.getPatternId())) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - - if (isProbeOperation(currentSection)) { - forceXYZ(); - } - - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - case "probing-x": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - break; - case "probing-y": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - break; - case "probing-z": - var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); - writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); - break; - case "probing-x-wall": - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-wall": - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel": - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel": - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-channel-with-island": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-circular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-boss": - // X positions - var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); - var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole": - // X positions - var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y positions - forceXYZ(); - var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); - - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-rectangular-hole-with-island": - // X positions - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - - // Y positions - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; - writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; - writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); - writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); - writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-inner-corner": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-xy-outer-corner": - // X position - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); - writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); - - // Y position - forceXYZ(); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); - writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-x-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionX2 = touchPositionX1; - writeBlock("Xvalue1 = " + touchPositionX1 + ";"); - writeBlock("Xvalue2 = " + touchPositionX2 + ";"); - writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - case "probing-y-plane-angle": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - - var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); - var touchPositionY2 = touchPositionY1; - writeBlock("Yvalue1 = " + touchPositionY1 + ";"); - writeBlock("Yvalue2 = " + touchPositionY2 + ";"); - writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); - writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); - writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); - writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); - writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); - break; - default: - expandCyclePoint(x, y, z); - } -} - -function mcrBoreMilling(cycle) { - - if (cycle.numberOfSteps > 2) { - error(localize("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixCycles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var threadDirection = (cycle.threading == "right") ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); - stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -//Implement G93 command -function mcrSetInverseTimeFeed() { - directWriteToCNC("G93"); -} - -//Implement G94 command -function mcrSetTimeFeed() { - directWriteToCNC("G94"); -} - -//write a command to the cnc kernel without interpretation from the control DANGEROUS -function directWriteToCNC(command) { - error(localize("Inverse Time feed is currently not supported.")); - return; -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } - - var probeWorkOffsetCode; - if (isProbeOperation(currentSection)) { - var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; - if (workOffset != 0) { - if (workOffset >= 19) { - error(localize("Work offset is out of range.")); - return; - } - probeWorkOffsetCode = workOffset; - writeBlock("Position " + probeWorkOffsetCode + ", 3;"); - } - forceXYZ(); - } -} - -var probeOutputWorkOffset = 1; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - if (currentSection.isOptimizedForMachine() && (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration())) { - // non TCP - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); - } else { - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); - previousABC = new Vector(_a, _b, _c); -} - -var currentFMode; -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); - - // get feed rate number - if (useInverseTime) { - var f = {frn:0, fmode:0}; - if (a || b || c) { - f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); - } else { - f.frn = feedOutput.format(feed); - f.fmode = 94; - } - } - - if (x || y || z || a || b || c) { - if (useRTCPSimu) { - if (useInverseTime) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - } else { - writeBlock(getFeed(feed)); - } - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTime ? f.frn : 0) + ";"); - } else { - if (useInverseTime) { - if (currentFMode != f.fmode) { - directWriteToCNC("G" + f.fmode); - currentFMode = f.fmode; - } - writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); - } else { - writeBlock(getFeed(feed)); - } - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(getFeed(feed)); - } - } - previousABC = new Vector(_a, _b, _c); -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Zheight": - return "Zhmess"; - case "Rotation": - return "Drehung"; - case "\r\n________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 5 axis operations require adjustments |" + - "\r\n| to the postprocessor for your |" + - "\r\n| machining system. |" + - "\r\n| Please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\n________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 5 Achs Operationen erfordern |" + - "\r\n| eine Anpassung des Postprozessors |" + - "\r\n| auf Ihre Maschine. |" + - "\r\n| Bitte wenden Sie sich an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - break; // end of German - } - return text; // use English -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (!properties.writeCoolantCommands) { - return; // do not output coolants - } - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - if (useInverseTime && currentSection.isMultiAxis()) { - directWriteToCNC("G" + 94); - currentFMode = 94; - } - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - if (isProbeOperation(currentSection)) { - writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); - } - if (!isLastSection() && properties.showOperationDialog) { - writeBlock("$Message = \"Start next Operation\";"); - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";"); - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); - forceAny(); -} - -function onClose() { - writeln(""); - - if (properties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - if (!is3D()) { - writeBlock(translate("Submacro") + " Initposition;"); - } - //write jump to start operation - if (properties.showOperationDialog) { - writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); - } - - writeMainProgram(); - writeComment("###############################################"); - // onCommand(COMMAND_COOLANT_OFF); - - if (!is3D()) { - writeBlock(translate("Submacro") + " Endmacro;"); - } - - writeBlock(translate("Submacro") + " Retractzmax;"); - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - if (properties.useParkPosition) { - writeBlock("Park;"); - } else { - writeBlock(translate("Submacro") + " Retractzmax;"); - zOutput.reset(); - } -} +/** + Copyright (C) 2012-2017 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {6884BEFE-3BAF-4433-BD9A-A3130BEBB2CD} +*/ + +description = "Generic DATRON Trunnion MCR (English)"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2017 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +longDescription = "Generic post for DATRON CNCs. This post works with DATRON M7, DATRON M8, DATRON M8Cube, DATRON M10, and DATRON M35 with the 5-axis trunnion table."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + writeVersion: false, // include version info + showOperationDialog: true, // shows a start dialog on the control to select the operation to start with + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + useTimeStamp: false, // specifies to output time stamp + writeCoolantCommands: false // en/disable coolant code output for the entire program +}; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var language = "en"; // supported languages are: "en", "de" +var useRTCPSimu = true; // use TCP "light" or not +var useInverseTime = false; // enable inverseTime output here if needed + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; +var previousABC = new Vector(0, 0, 0); + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of Multi-axis Feed Rate logic +/***** Be sure to add 'useInverseTime' to post properties if necessary *****/ +/***** 'previousABC' must be added throughout to maintain previous rotary positions *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined *****/ +/***** The feed rate mode must be included in motion block output (linear, circular, etc. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 9999.999 * 2.9; // maximum value to output for Inverse Time feeds + +/** Calculate the multi-axis feed rate number */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTime) { // inverse time + var time = getInverseTime(length[0], feed); + f.frn = inverseTimeFormat.format(time); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = feedOutput.format(getFeedDPM(length, feed)); + f.fmode = 94; + } + return f; +} + +/** Calculate the DPM feed rate number */ +function getFeedDPM(_moveLength, _feed) { + // moveLength[0] = Tool tip, [1] = XYZ, [2] = ABC + + if (properties.useTCPMode) { // TCP mode is supported, output feed as FPM + return feed; + } else { // DPM feed rate calculation + var moveTime = ((_moveLength[0] < 1.e-6) ? 0.001 : _moveLength[0]) / _feed; + var length = Math.sqrt(Math.pow(_moveLength[1], 2.0) + Math.pow((toDeg(_moveLength[2]) * dpmBPW), 2.0)); + return length / moveTime; + } +} + +/** Calculate the Inverse time feed rate number */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof (maxInverseTime) == "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof (maxInverseTime) == "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate the distance of the tool position to the center of a rotary axis */ +function getRotaryRadius(center, direction, toolPosition) { + var normal = direction.getNormalized(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis */ +function getRadialDistance(axis, startTool, endTool, startABC, endABC) { + // rotary axis does not exist + if (!axis.isEnabled()) { + return 0.0; + } + + // calculate the rotary center based on head/table + var center; + if (axis.isHead()) { + var pivot; + if (typeof (headOffset) == "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + center = Vector.sum(startTool, Vector.product(machineConfiguration.getSpindleAxis(), pivot)); + center = Vector.sum(center, axis.getOffset()); + } else { + center = axis.getOffset(); + } + + // calculate the radius of the tool end point compared to the rotary center + var startRadius = getRotaryRadius(center, axis.getEffectiveAxis(), startTool); + var endRadius = getRotaryRadius(center, axis.getEffectiveAxis(), endTool); + + // calculate length of radial move + var radius = Math.max(startRadius, endRadius); + var delta = Math.abs(endABC[axis.getCoordinate()] - startABC[axis.getCoordinate()]); + if (delta > Math.PI) { + delta = 2*Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = new Array(); + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC = new Array(previousABC.x, previousABC.y, previousABC.z); + var endABC = new Array(_a, _b, _c); + + if (currentSection.getOptimizedTCPMode() == 0) { + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = machineConfiguration.getOrientation(startABC).getTransposed().multiply(startTool); + endXYZ = machineConfiguration.getOrientation(endABC).getTransposed().multiply(endTool); + } else { + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(previousABC).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(new Vector(_a, _b, _c)).multiply(endXYZ); + } + + // calculate the radial portion of the move + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(machineConfiguration.getAxisU(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisV(), startTool, endTool, startABC, endABC), 2.0) + + Math.pow(getRadialDistance(machineConfiguration.getAxisW(), startTool, endTool, startABC, endABC), 2.0) + ); + + // calculate the lengths of move + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + var linearLength = Vector.diff(endXYZ, startXYZ).length; + moveLength[0] = linearLength + radialLength; + moveLength[1] = Vector.diff(endXYZ, startXYZ).length; + moveLength[2] = Vector.diff( + new Vector(endABC[0], endABC[1], endABC[2]), + new Vector(startABC[0], startABC[1], startABC[2]) + ).length; + return moveLength; +} +// End of Multi-axis Feed Rate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + + if (true) { // trunnion table + var aAxis = createAxis({coordinate:0, table:true, axis:[-1, 0, 0], range:[-102.5, 0], preference:-1}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (properties.useTimeStamp) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); + switch (language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (properties.showOperationDialog) { + variablesDeclaration.push("optional_stop"); + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.showOperationDialog) { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (properties.showOperationDialog) { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (properties.showOperationDialog) { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (properties.showOperationDialog) { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + submacrosDeclaration.push("Transformpath"); + } + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + submacrosDeclaration.push("Transformoffset"); + } + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + } + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + createRtcpTransformationSubmacro(); + } + + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + //writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + writeBlock(translate("Label") + " " + sectionID + ";"); + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset; + if (!is3D()) { + workOffset = 19; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } else { + workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + this.feed = feed; +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function onRewindMachine() { + writeComment("REWIND"); +} + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + if (true) { + writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); + writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); + writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); + } + + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.y) +", ", + abcFormat.format(abc.z) +";"); + } + + currentWorkPlaneABC = abc; + previousABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + // error(localize("RTCP is not supported.")); + // return; + + writeBlock("("); + if (useInverseTime) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, B_temp, C_temp;"); + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + writeBlock("A_initial_pos = A6p;"); + writeBlock("B_initial_pos = B6p;"); + writeBlock("C_initial_pos = C6p;"); + writeBlock("Position 19, 2;"); + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + writeBlock("A_delta = A_initial_pos - A6p;"); + writeBlock("B_delta = B_initial_pos - B6p;"); + writeBlock("C_delta = C_initial_pos - C6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - 10;"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + + +function createEndmacro() { + writeBlock("("); + if (useInverseTime) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); + + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10, 0;"); // disable probe + } + + if (insertToolCall || newWorkOffset || newWorkPlane) { + + // retract to safe plane + retracted = true; + writeBlock(translate("Submacro") + " Retractzmax;"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + retracted = true; + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |"+ + "\r\n| |"+ + "\r\n| 5 axis operations require adjustments |"+ + "\r\n| to the postprocessor for your |"+ + "\r\n| machining system. |"+ + "\r\n| Please contact www.DATRON.com! |"+ + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration()) { + writeBlock("Position 19, 2;"); + writeBlock(translate("Submacro") + " Retractzmax;"); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + } else { + if (!retracted) { + writeBlock(translate("Submacro") + " Retractzmax;"); + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + (getPreviousSection().getPatternId() == currentSection.getPatternId())) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + + if (cycle.numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth/cycle.pitch); // needs to be tested + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +//Implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +//Implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +//write a command to the cnc kernel without interpretation from the control DANGEROUS +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var probeOutputWorkOffset = 1; + +function onParameter(name, value) { + if (name == "probe-output-work-offset") { + probeOutputWorkOffset = (value > 0) ? value : 1; + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCPSimu && machineConfiguration.isMultiAxisConfiguration())) { + // non TCP + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); + previousABC = new Vector(_a, _b, _c); +} + +var currentFMode; +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); + + // get feed rate number + if (useInverseTime) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCPSimu) { + if (useInverseTime) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTime ? f.frn : 0) + ";"); + } else { + if (useInverseTime) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } + previousABC = new Vector(_a, _b, _c); +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 5 axis operations require adjustments |" + + "\r\n| to the postprocessor for your |" + + "\r\n| machining system. |" + + "\r\n| Please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 5 Achs Operationen erfordern |" + + "\r\n| eine Anpassung des Postprozessors |" + + "\r\n| auf Ihre Maschine. |" + + "\r\n| Bitte wenden Sie sich an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (!properties.writeCoolantCommands) { + return; // do not output coolants + } + if (coolant == currentCoolantMode) { + return; // coolant is already active + } + + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTime && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && properties.showOperationDialog) { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +function onClose() { + writeln(""); + + if (properties.writeVersion) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (!is3D()) { + writeBlock(translate("Submacro") + " Initposition;"); + } + //write jump to start operation + if (properties.showOperationDialog) { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // onCommand(COMMAND_COOLANT_OFF); + + if (!is3D()) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeBlock(translate("Submacro") + " Retractzmax;"); + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (properties.useParkPosition) { + writeBlock("Park;"); + } else { + writeBlock(translate("Submacro") + " Retractzmax;"); + zOutput.reset(); + } +} diff --git a/datron_RTCP_rotate.cps b/deprecated/datron_RTCP_rotate.cps similarity index 97% rename from datron_RTCP_rotate.cps rename to deprecated/datron_RTCP_rotate.cps index 9fe20e8..0c14d51 100644 --- a/datron_RTCP_rotate.cps +++ b/deprecated/datron_RTCP_rotate.cps @@ -1,1670 +1,1670 @@ -/** - Copyright (C) 2012-2015 by Autodesk, Inc. - All rights reserved. - - DATRON post processor configuration. - - $Revision: 37972 $ - $Date: 2014-10-18 23:40:07 +0200 (lø, 18 okt 2014) $ - - FORKID {1FDF0D08-45B6-4EAD-A71D-7BA04089886D} -*/ - -// version = V10 - -//Hier müssen wir noch einfügen das das speichern in mp18 bei jedem neuen laden eines NP in der Oparation oder dem Progammstart erfolgt. - - -description = "Generic DATRON MCR"; -vendor = "Autodesk, Inc."; -vendorUrl = "http://www.autodesk.com"; -legal = "Copyright (C) 2012-2015 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 24000; - -extension = "mcr"; -setCodePage("ascii"); - -capabilities = CAPABILITY_MILLING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.01, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(120); -allowHelicalMoves = false; -allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only - -// user-defined properties -properties = { - writeMachine: true, // write machine - optionalStop: true, // optional stop - useParametricFeed: true, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output - useSmoothing: true, // specifies if smoothing should be used or not - useDynamic: true, // specifies using dynamic mode or not - useParkPosition: true, // specifies to use park position at the end of the program - writeCoolantCommands: true, // disable the coolant commands in the file - useDialog : true, -}; - -var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); -var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); -var angleFormat = createFormat({decimals:5, scale:DEG}); -var abcFormat = createFormat({decimals:5, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:0.001}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0, scale:0.001}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); - -var xOutput = createVariable({force:true}, xyzFormat); -var yOutput = createVariable({force:true}, xyzFormat); -var zOutput = createVariable({force:true}, xyzFormat); -var aOutput = createVariable({force:true}, abcFormat); -var bOutput = createVariable({force:true}, abcFormat); -var cOutput = createVariable({force:true}, abcFormat); -var feedOutput = createVariable({}, feedFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); - -var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... -var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 - -// fixed settings -var language = "de" // specifies the language, replace with getLangId() -var maxMaskLength = 40; -var useRTCP_simu = true; // BETA, use TCP "light" or not - -// collected state -var currentWorkOffset; -var currentFeedValue = -1; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; - -// format date + time -var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); -var now = new Date(); -var nowDay = now.getDate(); -var nowMonth = now.getMonth() + 1; -var nowHour = now.getHours(); -var nowMin = now.getMinutes(); -var nowSec = now.getSeconds(); - -/** - Writes the specified block. -*/ - -function writeBlock() { - writeWords(arguments); -} - -var charMap = { - "\u00c4":"Ae", - "\u00e4":"ae", - "\u00dc":"Ue", - "\u00fc":"ue", - "\u00d6":"Oe", - "\u00f6":"oe", - "\u00df":"ss", - "\u002d":"_" -}; - -/** Map specific chars. */ -function mapComment(text) { - var result = ""; - for (var i = 0; i < text.length; ++i) { - var ch = charMap[text[i]]; - result += ch ? ch : text[i]; - } - return result; -} - -function formatComment(text) { - return mapComment(text); -} - -function formatVariable(text) { - text = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); - return text.replace(/[^A-Za-z0-9\-_]/g, ''); -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln("; !" + formatComment(text) + "!"); -} - -function onOpen() { - - if (true) { // note: setup your machine here - var aAxis = createAxis({coordinate:0, table:true, axis:[-1, 0, 0], range:[-102.5,0], preference:-1}); - var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360,360], cyclic:true, preference:0}); - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - - setMachineConfiguration(machineConfiguration); - optimizeMachineAngles2(1); // TCP mode - } - - if (!machineConfiguration.isMachineCoordinate(0)) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1)) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2)) { - cOutput.disable(); - } - - // header - writeProgramHeader(); -} - -function getOperationDescription(section) { - var operationComment = ""; - if (section.hasParameter("operation-comment")) { - operationComment = section.getParameter("operation-comment"); - operationComment = formatComment(operationComment); - } - - var cycleTypeString = ""; - if(section.hasParameter("operation:cycleType")){ - cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); - cycleTypeString = formatComment(cycleTypeString); - } - - var sectionID = section.getId() + 1; - var description = operationComment + "_" + cycleTypeString + "_" + sectionID; - return description; -} - -/** Writes the tool table. */ -function writeToolTable(){ - var tools = getToolTable(); - writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + - formatComment(getToolTypeName(tool.type)) + " " + - "D:" + xyzFormat.format(tool.diameter) + " " + - "L2:" + xyzFormat.format(tool.fluteLength) + " " + - "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; - writeBlock(comment); - } - } -} - -/** Writes the program header. */ -function writeProgramHeader() { - var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); - var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); - - writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); - if (programComment) { - writeBlock("!" + formatComment(programComment) + "!"); - } else { - writeBlock("!Makroprojekt description!"); - } - writeln(""); - - writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); - switch (language) { - case "en": - writeBlock("_sprache 1;"); - break; - case "de": - writeBlock("_sprache 0;"); - break; - default: - writeBlock("_sprache 1;"); - } - - writeln(""); - switch (unit) { - case IN: - writeBlock("Dimension 2;"); - break; - case MM: - writeBlock("Dimension 1;"); - break; - } - - writeln(""); - - var variablesDeclaration = new Array(); - var submacrosDeclaration = new Array(); - var dialogsDeclaration = new Array(); - - variablesDeclaration.push("optional_stop"); - variablesDeclaration.push("$Message"); - if (getNumberOfSections() >= maxMaskLength) { - submacrosDeclaration.push("Initvariables"); - } - - dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); - if (properties.optionalStop) { - dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); - } - - //write variables declaration - var tools = getToolTable(); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - variablesDeclaration.push("T" + tool.number); - } - - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); - submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); - if (getNumberOfSections() < maxMaskLength) { - dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + - formatVariable(getOperationDescription(section)) + "\"" - ); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - var feedDescription = formatVariable(feedContext.description); - if (variablesDeclaration.indexOf(feedDescription) == -1) { - variablesDeclaration.push(feedDescription); - } - } - } - } - - if (!is3D()) { - variablesDeclaration.push("X_initial_pos"); - variablesDeclaration.push("Y_initial_pos"); - variablesDeclaration.push("Z_initial_pos"); - variablesDeclaration.push("A_initial_pos"); - variablesDeclaration.push("B_initial_pos"); - variablesDeclaration.push("C_initial_pos"); - variablesDeclaration.push("X_delta"); - variablesDeclaration.push("Y_delta"); - variablesDeclaration.push("Z_delta"); - variablesDeclaration.push("A_delta"); - variablesDeclaration.push("B_delta"); - variablesDeclaration.push("C_delta"); - variablesDeclaration.push("X"); - variablesDeclaration.push("Y"); - variablesDeclaration.push("Z"); - variablesDeclaration.push("A"); - variablesDeclaration.push("B"); - variablesDeclaration.push("C"); - variablesDeclaration.push("Israpid"); - variablesDeclaration.push("X_trans"); - variablesDeclaration.push("Y_trans"); - variablesDeclaration.push("Z_trans"); - variablesDeclaration.push("X_new"); - variablesDeclaration.push("Y_new"); - variablesDeclaration.push("Z_new"); - variablesDeclaration.push("X_temp"); - variablesDeclaration.push("Y_temp"); - variablesDeclaration.push("Z_temp"); - variablesDeclaration.push("A_temp"); - variablesDeclaration.push("B_temp"); - variablesDeclaration.push("C_temp"); - variablesDeclaration.push("Isinitialposition"); - - submacrosDeclaration.push("Endmacro"); - } - - - submacrosDeclaration.push("Retractzmax"); - variablesDeclaration.push("Curr_zpno"); - variablesDeclaration.push("Zpos"); - - writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); - writeln(""); - writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); - writeln(""); - writeBlock(dialogsDeclaration.join(EOL) + ";"); - writeln(""); - - - if (useRTCP_simu && !is3D()) { - writeBlock("_maske Transformpath, 8, 0, \"create a new coordinate system with the given rotation values\""); - writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); - writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); - writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); - writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); - writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); - writeBlock("_feld A, 4, 8, 0, -120, 120, 0, 1, \"alpha\", \"rotation around x axis\""); - writeBlock("_feld B, 4, 8, 0, -120, 120, 0, 1, \"beta\", \"rotation around Y\""); - writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); - writeln(""); - } - - if (numberOfSections >= maxMaskLength) { - writeBlock("("); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); - } - writeln(") Initvariables;"); - } - - // if (!is3D()) { - // createPositionInitSubmacro(); - // createEndmacro(); - // } - - // if (!is3D()) { - // createRtcpTransformationSubmacro(); - // } - - if (useRTCP_simu) { - createRtcpSimuSubmacro(); - } - - createRetractMacro(); -} - -function writeMainProgram() { - - var numberOfSections = getNumberOfSections(); - if (numberOfSections >= maxMaskLength) { - writeBlock(translate("Submacro") + " Initvariables;"); - } - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var Description = getOperationDescription(section); - var sectionID = i+1; - - var sectionName = formatVariable("Sm_" + Description); - var maskName = formatVariable("Op_" + Description); - - writeComment("##########" + Description + "##########"); - writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); - - var tool = section.getTool(); - if (properties.showNotes && section.hasParameter("notes")) { - var notes = section.getParameter("notes"); - if (notes) { - var lines = String(notes).split("\n"); - var r1 = new RegExp("^[\\s]+", "g"); - var r2 = new RegExp("[\\s]+$", "g"); - for (line in lines) { - var comment = lines[line].replace(r1, "").replace(r2, ""); - if (comment) { - writeComment(comment); - } - } - } - } - var showToolZMin = true; - if (showToolZMin) { - if (is3D()) { - var zRange = section.getGlobalZRange(); - var number = tool.number; - if (section.getTool().number != number) { - break; - } - zRange.expandToRange(section.getGlobalZRange()); - writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); - } - } - writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - onSpindleSpeed(tool.spindleRPM); - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - var t = tolerance; - if (section.hasParameter("operation:tolerance")) { - t = section.getParameter("operation:tolerance"); - } - if (properties.useDynamic) { - var dynamic = 5; - if (t <= 0.02) dynamic = 4; - if (t <= 0.01) dynamic = 3; - if (t <= 0.005) dynamic = 2; - if (t <= 0.003) dynamic = 1; - writeBlock(translate("Dynamics") + " " + dynamic + ";"); - } - if (properties.useParametricFeed) { - activeFeeds = initializeActiveFeeds(section); - for (var j = 0; j < activeFeeds.length; ++j) { - var feedContext = activeFeeds[j]; - writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + ";!m/min!"); - } - } - - // wcs - setWorkOffset(section.workOffset); - - writeBlock(translate("Submacro") + " " + sectionName + ";"); - writeBlock(translate("Label") + " " + sectionID + ";"); - } -} - -function setWorkOffset(workOffset){ - if (workOffset != currentWorkOffset) { - writeBlock("Position " + workOffset + ", 2;"); - currentWorkOffset = workOffset; - if (!is3D()) { - writeBlock("Store_zp_18;"); - } - } -} - -function writeWorkpiece() { - var workpiece = getWorkpiece(); - var delta = Vector.diff(workpiece.upper, workpiece.lower); - - writeBlock("; !" + translate("Workpiece dimensions") + ":!"); - writeBlock( - "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" - ); - writeBlock( - "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + - " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + - " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" - ); - writeBlock( - "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + - " Y: " + workpieceFormat.format(delta.y) + ";" + - " Z: " + workpieceFormat.format(delta.z) + "!" - ); - - //insert maximum deep of the hole program - - writeBlock( - "Wdef " + - xyzFormat.format(delta.getX()) + ", " + - xyzFormat.format(delta.getY()) + ", " + - xyzFormat.format(delta.getZ()) + ", " + - xyzFormat.format(workpiece.lower.x) + ", " + - xyzFormat.format(workpiece.lower.y) + ", " + - xyzFormat.format(workpiece.upper.z) + ", 0;" - ); -} - -function onComment(message) { - var comments = String(message).split(";"); - for (comment in comments) { - writeComment(comments[comment]); - } -} - -var passThrough= new Array(); -function onPassThrough(text){ - passThrough.push(text); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); - currentFeedValue = -1; -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -/** Maps the specified feed value to Q feed or formatted feed. */ -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); - } - } - currentFeedId = undefined; // force Q feed next time - } - if (feedFormat.areDifferent(currentFeedValue, f)) { - currentFeedValue = f; - return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; - } -} - - -function initializeActiveFeeds(section) { - activeMovements = new Array(); - var movements = section.getMovements(); - - var id = 0; - var activeFeeds = new Array(); - - if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - - if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { - var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - } - ++id; - - } - - if (section.hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (section.hasParameter("operation:tool_feedCutting") && - section.hasParameter("operation:tool_feedEntry") && - section.hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (section.hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (section.hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - return activeFeeds; -} - -var currentWorkPlaneABC = undefined; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function setWorkPlane(abc) { - forceWorkPlane(); // always need the new workPlane - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - return; // no change - } - - gMotionModal.reset(); - - if (!is3D() && !currentSection.isMultiAxis()) { - writeComment("****** Move to Plane Orientation ************"); - - writeBlock("Rotate_ac_18_19_20 ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.z) +", 0;"); - - writeBlock("Axyzabc 1, x6p, y6p, z6p, ", - abcFormat.format(abc.x) +", ", - abcFormat.format(abc.y) +", ", - abcFormat.format(abc.z) +";"); - - writeComment("*********************************************"); - - - } - - currentWorkPlaneABC = abc; -} - -var closestABC = false; // choose closest machine angles -var currentMachineABC; - -function getWorkPlaneMachineABC(workPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = machineConfiguration.remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - currentMachineABC = abc; - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - var direction = machineConfiguration.getDirection(abc); - if (!isSameDirection(direction, W.forward)) { - error(localize("Orientation not supported.")); - return; - } - - if (!machineConfiguration.isABCSupported(abc)) { - error( - localize("Work plane is not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - + "\r\nYou may try to machine the fixture side of the Part" - ); - return; - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function createRtcpSimuSubmacro() { - // error(localize("RTCP is not supported.")); - // return; - - if(!is3D()){ - writeBlock("("); - writeBlock("X_temp = X_delta;"); - writeBlock("Y_temp = Y_delta;"); - writeBlock("Z_temp = Z_delta;"); - - writeBlock(";!Rotation around C!;"); - writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); - writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); - writeBlock("Z_trans = Z_temp;"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Rotation around A!;"); - writeBlock("X_trans = X_temp;"); - writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); - writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); - writeBlock("X_temp = X_trans;"); - writeBlock("Y_temp = Y_trans;"); - writeBlock("Z_temp = Z_trans;"); - - // writeBlock(";!Rotation around B!;"); - // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); - // writeBlock("Y_trans = Y_temp;"); - // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); - // writeBlock("X_temp = X_trans;"); - // writeBlock("Y_temp = Y_trans;"); - // writeBlock("Z_temp = Z_trans;"); - - writeBlock(";!Calc new Position!;"); - writeBlock("X_new = X - X_trans;"); - writeBlock("Y_new = Y - Y_trans;"); - writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); - - writeBlock("A_temp = A - A_delta;"); - writeBlock("B_temp = B - B_delta;"); - writeBlock("C_temp = C - C_delta;"); - - writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, B_temp, C_temp;"); - writeBlock(") Transformpath;"); - } -} - -function createRetractMacro() { - writeBlock("("); - writeBlock("Curr_zpno = Zeromemnr;"); - writeBlock(translate("Zeromem") + " 0;"); - writeBlock("Zpos = - Wzl - 10;"); - writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); - writeBlock(translate("Zeromem") + " Curr_zpno;"); - writeBlock(") Retractzmax;"); -} - -function createEndmacro() { - writeBlock("("); - writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); - writeBlock(") Endmacro;"); -} - -var currentSectionID = 0 - -function onSection() { - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); - - writeBlock("("); - - if (insertToolCall || newWorkOffset || newWorkPlane) { - - // retract to safe plane - retracted = true; - writeBlock(translate("Submacro") + " Retractzmax;") - forceXYZ(); - } - - if (insertToolCall) { - forceWorkPlane(); - retracted = true; - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - } - - if (insertToolCall || - forceSpindleSpeed || - isFirstSection() || - (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)) { - forceSpindleSpeed = false; - - if (tool.spindleRPM < 6000) { - tool.spindleRPM = 6000; - } - if (tool.spindleRPM > 60000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - if (!tool.clockwise) { - error(localize("Spindle direction not supported.")); - return; - } - - //onCommand(COMMAND_START_CHIP_TRANSPORT); - if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { - // writeBlock(mFormat.format(xxx)); // shortest path traverse - } - } - - forceXYZ(); - - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (currentSection.isMultiAxis()) { - forceWorkPlane(); - cancelTransformation(); - var abc = currentSection.getInitialToolAxisABC(); - setWorkPlane(abc); // pre-positioning ABC - } else { - var abc = new Vector(0, 0, 0); - abc = getWorkPlaneMachineABC(currentSection.workPlane); - setWorkPlane(abc); - } - } else { // pure 3D - var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - //error(localize("Tool orientation is not supported.")); - error(translate( - "\r\________________________________________" + - "\r\n| error |"+ - "\r\n| |"+ - "\r\n| 5 axis operations require adjustments |"+ - "\r\n| to the postprocessor for your |"+ - "\r\n| machining system. |"+ - "\r\n| Please contact www.DATRON.com! |"+ - "\r\n|_______________________________________|\r\n")); - return; - } - setRotation(remaining); - } - - forceAny(); - - var t = tolerance; - if (hasParameter("operation:tolerance")) { - if (t < getParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - } - if (properties.useSmoothing && !currentSection.isMultiAxis()) { - writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); - } - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(translate("Submacro") + " Retractzmax;") - } - } - - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 1;"); - } - - if (currentSection.isMultiAxis()) { - var abc = currentSection.getInitialToolAxisABC(); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); - - if (useRTCP_simu) { - writeBlock("Position 19, 2;"); - writeBlock(translate("Submacro") + " Retractzmax;") - writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } else { - if (!retracted) { - writeBlock(translate("Submacro") + " Retractzmax;") - } - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - "z6p" + ", " + - a + ", " + - b + ", " + - c + ";" - ); - writeBlock("Axyzabc 1, " + - xOutput.format(initialPosition.x) + ", " + - yOutput.format(initialPosition.y) + ", " + - zOutput.format(initialPosition.z) + ", " + - a + ", " + - b + ", " + - c + ";" - ); - } - //writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); - //writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); - } else { - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); - writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); - } - - if (properties.useParametricFeed /*&& - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill")*/) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - (getPreviousSection().getPatternId() == currentSection.getPatternId())) { - // use the current feeds - } else { - initializeActiveFeeds(currentSection); - } - } else { - activeMovements = undefined; - } -} - -function onDwell(seconds) { - writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); -} - -function onCycle() { - //writeBlock(gPlaneModal.format(17)); -} - -function getCommonCycle(x, y, z, r) { - forceXYZ(); // force xyz on first drill hole of any cycle - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + xyzFormat.format(r)]; -} - -function onCyclePoint(x, y, z) { - writeBlock(getFeed(cycle.feedrate)); - switch (cycleType) { - case "bore-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrBoreMilling(cycle); - break; - case "thread-milling": - writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); - mcrThreadMilling(cycle); - break; - default: - expandCyclePoint(x, y, z); - } - return; - - // drill cycles not supported - /* - if (isFirstCyclePoint()) { - repositionToCycleClearance(cycle, x, y, z); - - // return to initial Z which is clearance plane and set absolute mode - - var F = cycle.feedrate; - var P = (cycle.dwell == 0) ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds - - switch (cycleType) { - case "drilling": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "chip-breaking": - // cycle.accumulatedDepth is ignored - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract), - "Q" + xyzFormat.format(cycle.incrementalDepth), - feedOutput.format(F) - ); - } - break; - case "deep-drilling": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract), - "Q" + xyzFormat.format(cycle.incrementalDepth), - // conditional(P > 0, "P" + milliFormat.format(P)), - feedOutput.format(F) - ); - } - break; - case "tapping": - writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(F) - ); - break; - case "left-tapping": - writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(74), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(tool.getTappingFeedrate()) - ); - break; - case "right-tapping": - writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(tool.getTappingFeedrate()) - ); - break; - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 74 : 84)), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - "Q" + xyzFormat.format(cycle.incrementalDepth), - feedOutput.format(tool.getTappingFeedrate()) - ); - break; - case "fine-boring": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(76), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), // not optional - "Q" + xyzFormat.format(cycle.shift), - feedOutput.format(F) - ); - break; - case "back-boring": - var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0; - var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0; - var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0; - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87), - getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom), - "Q" + xyzFormat.format(cycle.shift), - "P" + milliFormat.format(P), // not optional - feedOutput.format(F) - ); - break; - case "reaming": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "stop-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "manual-boring": - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), // not optional - feedOutput.format(F) - ); - break; - case "boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), // not optional - feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - } - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - writeBlock(xOutput.format(x), yOutput.format(y)); - } - } - */ -} - -function mcrBoreMilling(cycle){ - - if (cycle.numberOfSteps > 2) { - error(translate("Only 2 steps are allowed for bore-milling")); - return; - } - - var helixZykles = cycle.depth / cycle.pitch; - var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; - var bottomCleaning = 0; - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var maxZDepthPerStep = tool.fluteLength * 0.8; - - var block = subst(translate("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", - xyzFormat.format(fastZPlunge), - xyzFormat.format(cycle.diameter), - helixZykles, - xyzFormat.format(XYCleaning), - xyzFormat.format(slowZPlunge), - bottomCleaning, - xyzFormat.format(cycle.depth), - xyzFormat.format(maxZDepthPerStep) - ); - - writeBlock(block); -} - -function mcrThreadMilling(cycle) { - var fastZPlunge = cycle.clearance - cycle.retract; - var slowZPlunge = cycle.retract - cycle.stock; - var chamferOffset = cycle.pitch * 0.3; - chamferOffset = (slowZPlunge > chamferOffset)? slowZPlunge - chamferOffset: chamferOffset; - var threadDirection = (cycle.threading == 'right') ? 1 : -1; - - var stringSubst = new StringSubstitution(); - stringSubst.setValue("ThreadNorm", 0); - stringSubst.setValue("ThreadMillingDirection", 0); - stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); - stringSubst.setValue("InnerOuter", 1); - stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); - stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 2 + chamferOffset)); - stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth + chamferOffset)); - stringSubst.setValue("CleanXY", 0); - stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); - stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge - chamferOffset)); - stringSubst.setValue("ThreadMillAngle", 60); - stringSubst.setValue("Predrill", 0); - stringSubst.setValue("ThreadID", 0); - stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink - - writeBlock( - stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") - ); -} - -function onCycleEnd() { - if (!cycleExpanded) { - zOutput.reset(); - } -} - -var pendingRadiusCompensation = -1; -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -function onRapid(_x, _y, _z) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - if (xyz) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); - forceFeed(); - } -} - -function onLinear(_x, _y, _z, feed) { - var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); - var f = getFeed(feed); - - if (f) { - writeBlock(f); - } - if (xyz) { - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - break; - default: - writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else { - writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); - - if (currentSection.isOptimizedForMachine() && useRTCP_simu) { - // non tcp - writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } else { - forceXYZ(); - writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - forceFeed(); -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); - var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); - var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); - - writeBlock(getFeed(feed)); - if (x || y || z || a || b || c) { - if (useRTCP_simu) { - writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } else { - writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(0), f); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - var f = getFeed(feed); - if (isHelical() || (getCircularPlane() != PLANE_XY)) { - var t = tolerance; - if (hasParameter("operation:tolerance")) { - t = getParameter("operation:tolerance"); - } - linearize(t); - return; - } - - var start = getCurrentPosition(); - var startAngle = Math.atan2(start.y - cy, start.x - cx); - var endAngle = Math.atan2(y - cy, x - cx); - - if (f) { - writeBlock(f); - } - - writeln( - translate("Circle") + " " + - xyzFormat.format(2 * getCircularRadius()) + ", " + - "0, " + // hs - "0, " + // hl - (clockwise ? -360 : 0) + ", " + - angleFormat.format(startAngle) + ", " + // begin angle - angleFormat.format(endAngle) + ", " + // end angle - "0, " + // do not connect start/end - "0, " + // center - "2, " + // fk - "1, " + // yf - xyzFormat.format(getHelicalPitch()) + ";" // zb - ); -} - -function translate(text) { - switch (language) { - case "en": - return text; - case "de": - switch (text) { - case "Coolant": - return "Sprueh"; - case "Condition": - return "Bedingung"; - case "Submacro": - return "Submakro"; - case "Dynamics": - return "Dynamik"; - case "Contour_smoothing": - return "Konturglaettung"; - case "Label": - return "Markierung"; - case "Tcomp": - return "Fkomp"; - case "Message": - return "Melde"; - case "Feed": - return "Vorschub"; - case "Rpm": - return "Drehzahl"; - case "Number of tools in use": - return "Anzahl der benutzten Werkzeuge"; - case "Tool": - return "Werkzeug"; - case "Drill": - return "Bohren"; - case "Circle": - return "Kreis"; - case "Thread": - return "Gewinde"; - case "Setzp": - return "Setrel"; - case "Workpiece dimensions": - return "Abmessungen Werkstueck"; - case "Zeromem": - return "Relsp"; - case "Description": - return "Beschreibung"; - case "Part size": - return "Groesse"; - case "Drill": - return "Bohren"; - case "Only 2 steps are allowed for bore-milling": - return "Beim Bohrfräsen sind nur 2 Zustellungen erlaubt!"; - case "\r\________________________________________" + - "\r\n| error |" + - "\r\n| |" + - "\r\n| 5 axis operations require adjustments |" + - "\r\n| to the postprocessor for your |" + - "\r\n| machining system. |" + - "\r\n| Please contact www.DATRON.com! |" + - "\r\n|_______________________________________|\r\n": - return "\r\________________________________________" + - "\r\n| Fehler |" + - "\r\n| |" + - "\r\n| 5 Achs Operationen erfordern |" + - "\r\n| eine Anpassung des Postprozessors |" + - "\r\n| auf Ihre Maschine. |" + - "\r\n| Bitte wenden Sie sich an www.datron.de |" + - "\r\n|________________________________________|\r\n"; - } - default: - return text; - } -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if(properties.writeCoolantCommands){ - if (coolant == COOLANT_OFF) { - writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off - currentCoolantMode = COOLANT_OFF; - return; - } - - var m; - switch (coolant) { - case COOLANT_FLOOD: - case COOLANT_MIST: - m = 1; - break; - case COOLANT_AIR: - m = 3; - break; - default: - onUnsupportedCoolant(coolant); - m = 2; - } - if (m) { - writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off - currentCoolantMode = coolant; - } - } -} - -var mapCommand = { -}; - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_COOLANT_ON: - return; - case COMMAND_STOP: - return; - case COMMAND_START_SPINDLE: - return; - case COMMAND_LOCK_MULTI_AXIS: - return; - case COMMAND_UNLOCK_MULTI_AXIS: - return; - case COMMAND_START_CHIP_TRANSPORT: - return; - case COMMAND_STOP_CHIP_TRANSPORT: - return; - case COMMAND_BREAK_CONTROL: - return; - case COMMAND_TOOL_MEASURE: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -function onSectionEnd() { - if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { - writeBlock("rtcp 0;"); - } - - if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) { - onCommand(COMMAND_BREAK_CONTROL); - } - - if (!isLastSection() && properties.optionalStop) { - writeBlock("$Message = \"Start next Operation\";") - writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); - writeBlock(translate("Message") + " $Message, 0, 0, 0;"); - writeBlock("$Message = \"OK\";") - } - writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";" ); - forceAny(); -} - -function onClose() { - writeln(""); - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); - if (properties.writeMachine && (vendor || model || description)) { - writeComment(localize("Machine")); - if (vendor) { - writeComment(" " + localize("vendor") + ": " + vendor); - } - if (model) { - writeComment(" " + localize("model") + ": " + model); - } - if (description) { - writeComment(" " + localize("description") + ": " + description); - } - } - writeToolTable(); - writeWorkpiece(); - - //write the setup WKS on the beginning of the program not in the first section - if (getNumberOfSections() >= 0) { - var section = getSection(0); - if(section.workOffset != 0){ - setWorkOffset(section.workOffset); - } - } - - if (!is3D()) { - writeBlock("Store_zp_18;"); - } - - writeMainProgram(); - writeComment("###############################################"); - onCommand(COMMAND_COOLANT_OFF); - - //no need in rotate - // if (!is3D()) { - // writeBlock(translate("Submacro") + " Endmacro;"); - // } - - writeBlock(translate("Submacro") + " Retractzmax;") - - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - - if (properties.useParkPosition) { - writeBlock("Park;"); - } else { - writeBlock(translate("Submacro") + " Retractzmax;") - zOutput.reset(); - } -} +/** + Copyright (C) 2012-2015 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision: 37972 $ + $Date: 2014-10-18 23:40:07 +0200 (lø, 18 okt 2014) $ + + FORKID {1FDF0D08-45B6-4EAD-A71D-7BA04089886D} +*/ + +// version = V10 + +//Hier müssen wir noch einfügen das das speichern in mp18 bei jedem neuen laden eines NP in der Oparation oder dem Progammstart erfolgt. + + +description = "Generic DATRON MCR"; +vendor = "Autodesk, Inc."; +vendorUrl = "http://www.autodesk.com"; +legal = "Copyright (C) 2012-2015 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 24000; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.01, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: true, // write machine + optionalStop: true, // optional stop + useParametricFeed: true, // specifies that feed should be output using Q values + showNotes: false, // specifies that operation notes should be output + useSmoothing: true, // specifies if smoothing should be used or not + useDynamic: true, // specifies using dynamic mode or not + useParkPosition: true, // specifies to use park position at the end of the program + writeCoolantCommands: true, // disable the coolant commands in the file + useDialog : true, +}; + +var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:0.001}); +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... +var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 +var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 +var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... +var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 + +// fixed settings +var language = "de" // specifies the language, replace with getLangId() +var maxMaskLength = 40; +var useRTCP_simu = true; // BETA, use TCP "light" or not + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; + +// format date + time +var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +/** + Writes the specified block. +*/ + +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4":"Ae", + "\u00e4":"ae", + "\u00dc":"Ue", + "\u00fc":"ue", + "\u00d6":"Oe", + "\u00f6":"oe", + "\u00df":"ss", + "\u002d":"_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + text = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return text.replace(/[^A-Za-z0-9\-_]/g, ''); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + + if (true) { // note: setup your machine here + var aAxis = createAxis({coordinate:0, table:true, axis:[-1, 0, 0], range:[-102.5,0], preference:-1}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360,360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if(section.hasParameter("operation:cycleType")){ + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +/** Writes the tool table. */ +function writeToolTable(){ + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); + switch (language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + variablesDeclaration.push("optional_stop"); + variablesDeclaration.push("$Message"); + if (getNumberOfSections() >= maxMaskLength) { + submacrosDeclaration.push("Initvariables"); + } + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (properties.optionalStop) { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (getNumberOfSections() < maxMaskLength) { + dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + ); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (!is3D()) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + + submacrosDeclaration.push("Endmacro"); + } + + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + + if (useRTCP_simu && !is3D()) { + writeBlock("_maske Transformpath, 8, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -120, 120, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -120, 120, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + } + + if (numberOfSections >= maxMaskLength) { + writeBlock("("); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); + } + writeln(") Initvariables;"); + } + + // if (!is3D()) { + // createPositionInitSubmacro(); + // createEndmacro(); + // } + + // if (!is3D()) { + // createRtcpTransformationSubmacro(); + // } + + if (useRTCP_simu) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + if (numberOfSections >= maxMaskLength) { + writeBlock(translate("Submacro") + " Initvariables;"); + } + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i+1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + + var tool = section.getTool(); + if (properties.showNotes && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + onSpindleSpeed(tool.spindleRPM); + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (properties.useDynamic) { + var dynamic = 5; + if (t <= 0.02) dynamic = 4; + if (t <= 0.01) dynamic = 3; + if (t <= 0.005) dynamic = 2; + if (t <= 0.003) dynamic = 1; + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (properties.useParametricFeed) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + ";!m/min!"); + } + } + + // wcs + setWorkOffset(section.workOffset); + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + writeBlock(translate("Label") + " " + sectionID + ";"); + } +} + +function setWorkOffset(workOffset){ + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + if (!is3D()) { + writeBlock("Store_zp_18;"); + } + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + //insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +var passThrough= new Array(); +function onPassThrough(text){ + passThrough.push(text); +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + this.feed = feed; +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } +} + + +function initializeActiveFeeds(section) { + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + var activeFeeds = new Array(); + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + + if (!is3D() && !currentSection.isMultiAxis()) { + writeComment("****** Move to Plane Orientation ************"); + + writeBlock("Rotate_ac_18_19_20 ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.z) +", 0;"); + + writeBlock("Axyzabc 1, x6p, y6p, z6p, ", + abcFormat.format(abc.x) +", ", + abcFormat.format(abc.y) +", ", + abcFormat.format(abc.z) +";"); + + writeComment("*********************************************"); + + + } + + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + + "\r\nYou may try to machine the fixture side of the Part" + ); + return; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + // error(localize("RTCP is not supported.")); + // return; + + if(!is3D()){ + writeBlock("("); + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, B_temp, C_temp;"); + writeBlock(") Transformpath;"); + } +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - 10;"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + +function createEndmacro() { + writeBlock("("); + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +var currentSectionID = 0 + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + var retracted = false; // specifies that the tool has been retracted to the safe plane + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); + + writeBlock("("); + + if (insertToolCall || newWorkOffset || newWorkPlane) { + + // retract to safe plane + retracted = true; + writeBlock(translate("Submacro") + " Retractzmax;") + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + retracted = true; + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (tool.spindleRPM < 6000) { + tool.spindleRPM = 6000; + } + if (tool.spindleRPM > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\________________________________________" + + "\r\n| error |"+ + "\r\n| |"+ + "\r\n| 5 axis operations require adjustments |"+ + "\r\n| to the postprocessor for your |"+ + "\r\n| machining system. |"+ + "\r\n| Please contact www.DATRON.com! |"+ + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (properties.useSmoothing && !currentSection.isMultiAxis()) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(translate("Submacro") + " Retractzmax;") + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCP_simu) { + writeBlock("Position 19, 2;"); + writeBlock(translate("Submacro") + " Retractzmax;") + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } else { + if (!retracted) { + writeBlock(translate("Submacro") + " Retractzmax;") + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + //writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + //writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (properties.useParametricFeed /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + (getPreviousSection().getPatternId() == currentSection.getPatternId())) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { + //writeBlock(gPlaneModal.format(17)); +} + +function getCommonCycle(x, y, z, r) { + forceXYZ(); // force xyz on first drill hole of any cycle + return [xOutput.format(x), yOutput.format(y), + zOutput.format(z), + "R" + xyzFormat.format(r)]; +} + +function onCyclePoint(x, y, z) { + writeBlock(getFeed(cycle.feedrate)); + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + default: + expandCyclePoint(x, y, z); + } + return; + + // drill cycles not supported + /* + if (isFirstCyclePoint()) { + repositionToCycleClearance(cycle, x, y, z); + + // return to initial Z which is clearance plane and set absolute mode + + var F = cycle.feedrate; + var P = (cycle.dwell == 0) ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds + + switch (cycleType) { + case "drilling": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "counter-boring": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + case "chip-breaking": + // cycle.accumulatedDepth is ignored + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(73), + getCommonCycle(x, y, z, cycle.retract), + "Q" + xyzFormat.format(cycle.incrementalDepth), + feedOutput.format(F) + ); + } + break; + case "deep-drilling": + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), + getCommonCycle(x, y, z, cycle.retract), + "Q" + xyzFormat.format(cycle.incrementalDepth), + // conditional(P > 0, "P" + milliFormat.format(P)), + feedOutput.format(F) + ); + } + break; + case "tapping": + writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), + feedOutput.format(F) + ); + break; + case "left-tapping": + writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(74), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), + feedOutput.format(tool.getTappingFeedrate()) + ); + break; + case "right-tapping": + writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), + feedOutput.format(tool.getTappingFeedrate()) + ); + break; + case "tapping-with-chip-breaking": + case "left-tapping-with-chip-breaking": + case "right-tapping-with-chip-breaking": + writeBlock(mFormat.format(29), sOutput.format(tool.spindleRPM)); + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 74 : 84)), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), + "Q" + xyzFormat.format(cycle.incrementalDepth), + feedOutput.format(tool.getTappingFeedrate()) + ); + break; + case "fine-boring": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(76), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), // not optional + "Q" + xyzFormat.format(cycle.shift), + feedOutput.format(F) + ); + break; + case "back-boring": + var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0; + var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0; + var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0; + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87), + getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom), + "Q" + xyzFormat.format(cycle.shift), + "P" + milliFormat.format(P), // not optional + feedOutput.format(F) + ); + break; + case "reaming": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + case "stop-boring": + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + case "manual-boring": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), // not optional + feedOutput.format(F) + ); + break; + case "boring": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), + getCommonCycle(x, y, z, cycle.retract), + "P" + milliFormat.format(P), // not optional + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + } + } else { + if (cycleExpanded) { + expandCyclePoint(x, y, z); + } else { + writeBlock(xOutput.format(x), yOutput.format(y)); + } + } + */ +} + +function mcrBoreMilling(cycle){ + + if (cycle.numberOfSteps > 2) { + error(translate("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixZykles = cycle.depth / cycle.pitch; + var XYCleaning = (cycle.numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(translate("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixZykles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var chamferOffset = cycle.pitch * 0.3; + chamferOffset = (slowZPlunge > chamferOffset)? slowZPlunge - chamferOffset: chamferOffset; + var threadDirection = (cycle.threading == 'right') ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 2 + chamferOffset)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth + chamferOffset)); + stringSubst.setValue("CleanXY", 0); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge - chamferOffset)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } +} + +var pendingRadiusCompensation = -1; +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && useRTCP_simu) { + // non tcp + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); + + writeBlock(getFeed(feed)); + if (x || y || z || a || b || c) { + if (useRTCP_simu) { + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } else { + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Drill": + return "Bohren"; + case "Only 2 steps are allowed for bore-milling": + return "Beim Bohrfräsen sind nur 2 Zustellungen erlaubt!"; + case "\r\________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 5 axis operations require adjustments |" + + "\r\n| to the postprocessor for your |" + + "\r\n| machining system. |" + + "\r\n| Please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 5 Achs Operationen erfordern |" + + "\r\n| eine Anpassung des Postprozessors |" + + "\r\n| auf Ihre Maschine. |" + + "\r\n| Bitte wenden Sie sich an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + default: + return text; + } +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if(properties.writeCoolantCommands){ + if (coolant == COOLANT_OFF) { + writeBlock(translate("Coolant") + " 4, 0" + ", 2" + ", 0;"); // coolant off + currentCoolantMode = COOLANT_OFF; + return; + } + + var m; + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + m = 1; + break; + case COOLANT_AIR: + m = 3; + break; + default: + onUnsupportedCoolant(coolant); + m = 2; + } + if (m) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + m + ", 0;"); // coolant off + currentCoolantMode = coolant; + } + } +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + + if (!isLastSection() && properties.optionalStop) { + writeBlock("$Message = \"Start next Operation\";") + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";") + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";" ); + forceAny(); +} + +function onClose() { + writeln(""); + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); + if (properties.writeMachine && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + //write the setup WKS on the beginning of the program not in the first section + if (getNumberOfSections() >= 0) { + var section = getSection(0); + if(section.workOffset != 0){ + setWorkOffset(section.workOffset); + } + } + + if (!is3D()) { + writeBlock("Store_zp_18;"); + } + + writeMainProgram(); + writeComment("###############################################"); + onCommand(COMMAND_COOLANT_OFF); + + //no need in rotate + // if (!is3D()) { + // writeBlock(translate("Submacro") + " Endmacro;"); + // } + + writeBlock(translate("Submacro") + " Retractzmax;") + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (properties.useParkPosition) { + writeBlock("Park;"); + } else { + writeBlock(translate("Submacro") + " Retractzmax;") + zOutput.reset(); + } +} From ab3908c48d86fc4aca74131f29b431e4c4b06710 Mon Sep 17 00:00:00 2001 From: Achim Nacke Date: Thu, 12 Jan 2023 12:25:35 +0100 Subject: [PATCH 2/2] Added latest official Datron posts from Autodesk post library --- datron c5.cps | 1987 ++++++++++++++++++ datron iso.cps | 1015 ++++++++++ datron mcr.cps | 2727 +++++++++++++++++++++++++ datron next inspect surface.cps | 3373 +++++++++++++++++++++++++++++++ datron next.cps | 3090 ++++++++++++++++++++++++++++ 5 files changed, 12192 insertions(+) create mode 100644 datron c5.cps create mode 100644 datron iso.cps create mode 100644 datron mcr.cps create mode 100644 datron next inspect surface.cps create mode 100644 datron next.cps diff --git a/datron c5.cps b/datron c5.cps new file mode 100644 index 0000000..0ff4aca --- /dev/null +++ b/datron c5.cps @@ -0,0 +1,1987 @@ +/** + Copyright (C) 2012-2021 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {DC597035-3395-48C2-BA86-28EFF6A7E339} +*/ + +description = "DATRON C5"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2021 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 45702; + +longDescription = "Post for DATRON C5."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only +mapWorkOrigin = false; + +// user-defined properties +properties = { + writeMachine: { + title : "Write machine", + description: "Output the machine settings in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + writeVersion: { + title : "Write version", + description: "Write the version number in the header of the code.", + group : "formats", + type : "boolean", + value : false, + scope : "post" + }, + showOperationDialog: { + title : "Show operation dialog", + description: "Shows a start dialog on the control which allows you to select the operation to start with.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useParametricFeed: { + title : "Parametric feed", + description: "Specifies the feed value that should be output using a Q value.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + showNotes: { + title : "Show notes", + description: "Writes operation notes as comments in the outputted code.", + group : "formats", + type : "boolean", + value : false, + scope : "post" + }, + useSmoothing: { + title : "Use smoothing", + description: "Specifies if smoothing should be used or not.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useDynamic: { + title : "Dynamic mode", + description: "Specifies the using of dynamic mode or not.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useTimeStamp: { + title : "Time stamp", + description: "Specifies whether to output a time stamp.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useCoolant: { + title : "Write coolant commands", + description: "Enable/disable coolant code outputs for the entire program.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + } +}; + +// samples: +// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} +// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} +var coolants = [ + {id:COOLANT_FLOOD, on:1}, + {id:COOLANT_MIST, on:1}, + {id:COOLANT_THROUGH_TOOL}, + {id:COOLANT_AIR, on:3}, + {id:COOLANT_AIR_THROUGH_TOOL}, + {id:COOLANT_SUCTION}, + {id:COOLANT_FLOOD_MIST}, + {id:COOLANT_FLOOD_THROUGH_TOOL}, + {id:COOLANT_OFF, off:2} +]; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({onchange:function () {retracted = false;}, force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var language = "en"; // supported languages are: "en", "de" +var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; +var retracted = false; // specifies that the tool has been retracted to the safe plane + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4": "Ae", + "\u00e4": "ae", + "\u00dc": "Ue", + "\u00fc": "ue", + "\u00d6": "Oe", + "\u00f6": "oe", + "\u00df": "ss", + "\u002d": "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + + if (true) { // note: setup your machine here + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 100.001], preference:0}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[0, 360], cyclic:true, preference:0}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(0); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (getProperty("useTimeStamp")) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.85D!"); + } else { + writeBlock("!Makro file ; V9.85D!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!"); + switch (language) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (getProperty("showOperationDialog")) { + variablesDeclaration.push("optional_stop"); + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (getProperty("showOperationDialog")) { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + + // Write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (getProperty("showOperationDialog")) { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (getProperty("showOperationDialog")) { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } + if (getProperty("useParametricFeed")) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (getProperty("showOperationDialog")) { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // submacrosDeclaration.push("Initposition"); + // submacrosDeclaration.push("Endmacro"); + } + + // variablesDeclaration.push("Curr_zpno"); + // variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock("_exit Endmacro;"); + // writeln(""); + } + + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // createEndmacro(); + } +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i + 1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + // writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + writeBlock(translate("Label") + " " + sectionID + ";"); + + var tool = section.getTool(); + if (getProperty("showNotes") && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format((section.getInitialSpindleSpeed() < 6000) ? 6000 : section.getInitialSpindleSpeed()) + ", 0, 30;"); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (getProperty("useDynamic")) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (getProperty("useParametricFeed")) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + /* + // wcs + var workOffset; + if (!is3D()) { + workOffset = 19; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } else { + workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + } +*/ + writeBlock(translate("Submacro") + " " + sectionName + ";"); + } +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + this.feed = feed; +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if ((movements & (1 << MOVEMENT_HIGH_FEED)) || (highFeedMapping != HIGH_FEED_NO_MAPPING)) { + var feed; + if (hasParameter("operation:highFeedrateMode") && getParameter("operation:highFeedrateMode") != "disabled") { + feed = getParameter("operation:highFeedrate"); + } else { + feed = this.highFeedrate; + } + var feedContext = new FeedContext(id, localize("High Feed"), feed); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + activeMovements[MOVEMENT_RAPID] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function onRewindMachine() { + writeComment("REWIND OF MACHINE AXIS"); +} + +function setWorkPlane(abc, turn) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + gMotionModal.reset(); + + var st = turn ? 1 : 0; + // move origin + var initialPosition = getFramePosition((currentSection.getInitialPosition())); + var xv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.x : currentSection.workOrigin.x) : xyzFormat.format(0); + var yv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.y : currentSection.workOrigin.y) : xyzFormat.format(0); + var zv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.z : currentSection.workOrigin.z) : xyzFormat.format(0); + + // rotate workplane and axis + var xs = abcFormat.format(abc.x); + var ys = abcFormat.format(abc.y); + var zs = abcFormat.format(abc.z); + var wz = turn ? 0 : 2; // 0 = indexing with retract 1= indexing with moving tool 2 = coordinate system rotation only + var vr = feedFormat.format(10000); // feed for indexing + + if (turn) { + writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";"); + writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";"); + } else { + writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";"); + writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";"); + } + + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + retracted = false; + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || + (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || + getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations + writeBlock("("); + + if (insertToolCall || newWorkOffset || newWorkPlane) { + // retract to safe plane + writeBlock(translate("ToolRetraction") + ";"); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (spindleSpeed > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + if (!retracted) { + writeRetract(Z); + } + } else { + var eulerXYZ = currentSection.workPlane.getTransposed().eulerZYX_R; + var abc = new Vector(-eulerXYZ.x, -eulerXYZ.y, -eulerXYZ.z); + setWorkPlane(abc, true); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (getProperty("useSmoothing") && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeRetract(Z); + } + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + writeComment("Prepositioning start"); + setWorkPlane(abc, true); + writeBlock(gMotionModal.format(1), xyzFormat.format(0) + ", " + xyzFormat.format(0) + ", " + "z6p" + ";"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + xyzFormat.format(0) + ";"); + setWorkPlane(new Vector(0, 0, 0), false); + writeComment("Prepositioning end"); + cancelTransformation(); + forceWorkPlane(); + if (currentSection.getOptimizedTCPMode() == 0) { + writeBlock("Rtcp 1;"); + } + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (getProperty("useParametricFeed") /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + (getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0)) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } +} + +function onDwell(seconds) { + writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format((spindleSpeed < 6000) ? 6000 : spindleSpeed) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { + expandCyclePoint(x, y, z); + return; + } + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { + if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + } + + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + var numberOfSteps = (cycle.numberOfSteps != undefined) ? cycle.numberOfSteps : 0; + if (numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth / cycle.pitch); // needs to be tested + var XYCleaning = (numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(localize("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +/** Implement G93 command. */ +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +/** Implement G94 command. */ +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +/** Write a command to the cnc kernel without interpretation from the control DANGEROUS. */ +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var probeOutputWorkOffset = currentSection.probeWorkOffset; + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? aOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? aOutput.format(_c) : "c6p"); + + if (x || y || z || a || b || c) { + writeBlock(getFeed(feed)); + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + var f = getFeed(feed); + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (language) { + case "en": + return text; + case "de": + switch (text) { + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "ToolRetraction": + return "Wzrueckzug"; + case "Shift": + return "Verschieben"; + case "Tilt": + return "Schwenken"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; +var coolantOff = undefined; + +function setCoolant(coolant) { + var coolantCodes = getCoolantCodes(coolant); + if (Array.isArray(coolantCodes)) { + for (var c in coolantCodes) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + coolantCodes[c] + ", 0;"); + } + return undefined; + } + return coolantCodes; +} + +function getCoolantCodes(coolant) { + var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line + if ((getProperty("useCoolant") != undefined) && !getProperty("useCoolant")) { + return undefined; + } + if (!coolants) { + error(localize("Coolants have not been defined.")); + } + if (tool.type == TOOL_PROBE) { // avoid coolant output for probing + coolant = COOLANT_OFF; + } + if (coolant == currentCoolantMode) { + return undefined; // coolant is already active + } + if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && (coolantOff != undefined)) { + if (Array.isArray(coolantOff)) { + for (var i in coolantOff) { + multipleCoolantBlocks.push(coolantOff[i]); + } + } else { + multipleCoolantBlocks.push(coolantOff); + } + } + + var m; + var coolantCodes = {}; + for (var c in coolants) { // find required coolant codes into the coolants array + if (coolants[c].id == coolant) { + coolantCodes.on = coolants[c].on; + if (coolants[c].off != undefined) { + coolantCodes.off = coolants[c].off; + break; + } else { + for (var i in coolants) { + if (coolants[i].id == COOLANT_OFF) { + coolantCodes.off = coolants[i].off; + break; + } + } + } + } + } + if (coolant == COOLANT_OFF) { + m = !coolantOff ? coolantCodes.off : coolantOff; // use the default coolant off command when an 'off' value is not specified + } else { + coolantOff = coolantCodes.off; + m = coolantCodes.on; + } + + if (!m) { + onUnsupportedCoolant(coolant); + m = 9; + } else { + if (Array.isArray(m)) { + for (var i in m) { + multipleCoolantBlocks.push(m[i]); + } + } else { + multipleCoolantBlocks.push(m); + } + currentCoolantMode = coolant; + return multipleCoolantBlocks; // return the single formatted coolant value + } + return undefined; +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("Rtcp 0;"); + } + + // the code below gets the machine angles from previous operation. closestABC must also be set to true + if (currentSection.isMultiAxis() && currentSection.isOptimizedForMachine()) { + currentMachineABC = currentSection.getFinalToolAxisABC(); + } + + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + + writeBlock(translate("ToolRetraction") + ";"); // optional + setWorkPlane(new Vector(0, 0, 0), false); // optional + forceWorkPlane(); // optional + + if (!isLastSection() && getProperty("showOperationDialog")) { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +/** Output block to do safe retract and/or move to home position. */ +function writeRetract() { + if (arguments.length == 0) { + error(localize("No axis specified for writeRetract().")); + return; + } + var words = []; // store all retracted axes in an array + for (var i = 0; i < arguments.length; ++i) { + let instances = 0; // checks for duplicate retract calls + for (var j = 0; j < arguments.length; ++j) { + if (arguments[i] == arguments[j]) { + ++instances; + } + } + if (instances > 1) { // error if there are multiple retract calls for the same axis + error(localize("Cannot retract the same axis twice in one line")); + return; + } + switch (arguments[i]) { + case X: + words.push("X" + xyzFormat.format(machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : 0)); + break; + case Y: + words.push("Y" + xyzFormat.format(machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : 0)); + break; + case Z: + writeBlock(translate("ToolRetraction") + ";"); + retracted = true; // specifies that the tool has been retracted to the safe plane + zOutput.reset(); + break; + default: + error(localize("Bad axis specified for writeRetract().")); + return; + } + } + if (words.length > 0) { + writeBlock("Clamping_position"); + } +} + +function onClose() { + writeln(""); + + if (getProperty("writeVersion")) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + language + "\""); + if (getProperty("writeMachine") && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + + // write jump to start operation + if (getProperty("showOperationDialog")) { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + + writeRetract(Z); + + // setWorkPlane(new Vector(0, 0, 0), false); // reset working plane + writeRetract(X, Y); + zOutput.reset(); +} + +function setProperty(property, value) { + properties[property].current = value; +} diff --git a/datron iso.cps b/datron iso.cps new file mode 100644 index 0000000..a68029d --- /dev/null +++ b/datron iso.cps @@ -0,0 +1,1015 @@ +/** + Copyright (C) 2012-2022 by Autodesk, Inc. + All rights reserved. + + Datron ISO post processor configuration. + + $Revision$ + $Date$ + + FORKID {F11922C3-2811-46AF-A97E-2A47B59CFA6D} +*/ + +description = "Datron ISO"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2022 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 45702; + +longDescription = "Generic milling post for Datron ISO."; + +extension = "nc"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(180); +allowHelicalMoves = true; +allowedCircularPlanes = undefined; // allow any circular motion + +// user-defined properties +properties = { + writeMachine: { + title : "Write machine", + description: "Output the machine settings in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + writeTools: { + title : "Write tool list", + description: "Output a tool list in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + showSequenceNumbers: { + title : "Use sequence numbers", + description: "'Yes' outputs sequence numbers on each block, 'Only on tool change' outputs sequence numbers on tool change blocks only, and 'No' disables the output of sequence numbers.", + group : "formats", + type : "enum", + values : [ + {title:"Yes", id:"true"}, + {title:"No", id:"false"}, + {title:"Only on tool change", id:"toolChange"} + ], + value: "true", + scope: "post" + }, + sequenceNumberStart: { + title : "Start sequence number", + description: "The number at which to start the sequence numbers.", + group : "formats", + type : "integer", + value : 10, + scope : "post" + }, + sequenceNumberIncrement: { + title : "Sequence number increment", + description: "The amount by which the sequence number is incremented by in each block.", + group : "formats", + type : "integer", + value : 5, + scope : "post" + }, + optionalStop: { + title : "Optional stop", + description: "Outputs optional stop code during when necessary in the code.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + separateWordsWithSpace: { + title : "Separate words with space", + description: "Adds spaces between words if 'yes' is selected.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + safePositionMethod: { + title : "Safe Retracts", + description: "Select your desired retract option. 'Clearance Height' retracts to the operation clearance height.", + group : "homePositions", + type : "enum", + values : [ + {title:"G28", id:"G28"}, + {title:"G53", id:"G53"}, + {title:"Clearance Height", id:"clearanceHeight"} + ], + value: "G28", + scope: "post" + } +}; + +// wcs definiton +wcsDefinitions = { + useZeroOffset: false, + wcs : [ + {name:"Standard", format:"G", range:[54, 59]}, + {name:"Extended", format:"G59.", range:[1, 3]} + ] +}; + +var numberOfToolSlots = 9999; + +var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines +// samples: +// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} +// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} +// {id: COOLANT_THROUGH_TOOL, on: "M88 P3 (myComment)", off: "M89"} +var coolants = [ + {id:COOLANT_FLOOD, on:8}, + {id:COOLANT_MIST, on:7}, + {id:COOLANT_THROUGH_TOOL}, + {id:COOLANT_AIR}, + {id:COOLANT_AIR_THROUGH_TOOL}, + {id:COOLANT_SUCTION}, + {id:COOLANT_FLOOD_MIST}, + {id:COOLANT_FLOOD_THROUGH_TOOL}, + {id:COOLANT_OFF, off:9} +]; + +var gFormat = createFormat({prefix:"G", decimals:0}); +var mFormat = createFormat({prefix:"M", decimals:0}); +var hFormat = createFormat({prefix:"H", decimals:0}); +var dFormat = createFormat({prefix:"D", decimals:0}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4)}); +var feedFormat = createFormat({decimals:(unit == MM ? 1 : 2)}); +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 +var taperFormat = createFormat({decimals:1, scale:DEG}); + +var xOutput = createVariable({prefix:"X"}, xyzFormat); +var yOutput = createVariable({prefix:"Y"}, xyzFormat); +var zOutput = createVariable({onchange:function() {retracted = false;}, prefix:"Z"}, xyzFormat); +var feedOutput = createVariable({prefix:"F"}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); +var dOutput = createVariable({}, dFormat); + +// circular output +var iOutput = createReferenceVariable({prefix:"I"}, xyzFormat); +var jOutput = createReferenceVariable({prefix:"J"}, xyzFormat); + +var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... +var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 +var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 +var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 +var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 +var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... +var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 + +var WARNING_WORK_OFFSET = 0; + +// collected state +var sequenceNumber; +var forceSpindleSpeed = false; +var currentWorkOffset; +var retracted = false; // specifies that the tool has been retracted to the safe plane + +/** + Writes the specified block. +*/ +function writeBlock() { + var text = formatWords(arguments); + if (!text) { + return; + } + if (getProperty("showSequenceNumbers") == "true") { + writeWords2("N" + sequenceNumber, arguments); + sequenceNumber += getProperty("sequenceNumberIncrement"); + } else { + writeWords(arguments); + } +} + +function formatComment(text) { + return "(" + String(text).replace(/[()]/g, "") + ")"; +} + +/** + Writes the specified block - used for tool changes only. +*/ +function writeToolBlock() { + var show = getProperty("showSequenceNumbers"); + setProperty("showSequenceNumbers", (show == "true" || show == "toolChange") ? "true" : "false"); + writeBlock(arguments); + setProperty("showSequenceNumbers", show); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln(formatComment(text)); +} + +function onOpen() { + if (!getProperty("separateWordsWithSpace")) { + setWordSeparator(""); + } + + sequenceNumber = getProperty("sequenceNumberStart"); + writeln("%"); + + if (programName) { + writeComment(programName); + } + if (programComment) { + writeComment(programComment); + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (getProperty("writeMachine") && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + // dump tool information + if (getProperty("writeTools")) { + var zRanges = {}; + if (is3D()) { + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var zRange = section.getGlobalZRange(); + var tool = section.getTool(); + if (zRanges[tool.number]) { + zRanges[tool.number].expandToRange(zRange); + } else { + zRanges[tool.number] = zRange; + } + } + } + + var tools = getToolTable(); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + toolFormat.format(tool.number) + " " + + "D=" + xyzFormat.format(tool.diameter) + " " + + localize("CR") + "=" + xyzFormat.format(tool.cornerRadius); + if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) { + comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg"); + } + if (zRanges[tool.number]) { + comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum()); + } + comment += " - " + getToolTypeName(tool.type); + writeComment(comment); + } + } + } + + if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { + for (var i = 0; i < getNumberOfSections(); ++i) { + if (getSection(i).workOffset > 0) { + error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); + return; + } + } + } + + // absolute coordinates and feed per min + writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94)); + writeBlock(gPlaneModal.format(17)); + + switch (unit) { + case IN: + writeBlock(gUnitModal.format(20)); + break; + case MM: + writeBlock(gUnitModal.format(21)); + break; + } +} + +function onComment(message) { + writeComment(message); +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of X, Y, Z, and F on next output. */ +function forceAny() { + forceXYZ(); + feedOutput.reset(); +} + +function isProbeOperation() { + return hasParameter("operation-strategy") && (getParameter("operation-strategy") == "probe"); +} + +function onSection() { + var insertToolCall = isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + retracted = false; + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || + (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || + getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations + if (insertToolCall || newWorkOffset || newWorkPlane) { + + // stop spindle before retract during tool change + if (insertToolCall && !isFirstSection()) { + onCommand(COMMAND_STOP_SPINDLE); + } + + // retract to safe plane + writeRetract(Z); + } + + if (hasParameter("operation-comment")) { + var comment = getParameter("operation-comment"); + if (comment) { + writeComment(comment); + } + } + + if (insertToolCall) { + setCoolant(COOLANT_OFF); + + if (!isFirstSection() && getProperty("optionalStop")) { + onCommand(COMMAND_OPTIONAL_STOP); + } + + if (tool.number > numberOfToolSlots) { + warning(localize("Tool number exceeds maximum value.")); + } + + writeToolBlock("T" + toolFormat.format(tool.number)); + if (tool.comment) { + writeComment(tool.comment); + } + var showToolZMin = false; + if (showToolZMin) { + if (is3D()) { + var numberOfSections = getNumberOfSections(); + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) { + var section = getSection(i); + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + } + writeComment(localize("ZMIN") + "=" + zRange.getMinimum()); + } + } + + /* Pre-load tool not supported + if (getProperty("preloadTool")) { + var nextTool = getNextTool(tool.number); + if (nextTool) { + writeBlock("T" + toolFormat.format(nextTool.number)); + } else { + // preload first tool + var section = getSection(0); + var firstToolNumber = section.getTool().number; + if (tool.number != firstToolNumber) { + writeBlock("T" + toolFormat.format(firstToolNumber)); + } + } + } +*/ + } + + var spindleChanged = tool.type != TOOL_PROBE && + (insertToolCall || forceSpindleSpeed || isFirstSection() || + (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)); + if (spindleChanged) { + forceSpindleSpeed = false; + if (spindleSpeed < 1) { + error(localize("Spindle speed out of range.")); + } + if (spindleSpeed > 99999) { + warning(localize("Spindle speed exceeds maximum value.")); + } + writeBlock( + sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4) + ); + } + + // wcs + if (insertToolCall) { // force work offset when changing tool + currentWorkOffset = undefined; + } + + if (currentSection.workOffset != currentWorkOffset) { + writeBlock(currentSection.wcs); + currentWorkOffset = currentSection.workOffset; + } + + forceXYZ(); + + { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { + error(localize("Tool orientation is not supported.")); + return; + } + setRotation(remaining); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + + forceAny(); + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted && !insertToolCall) { + if (getCurrentPosition().z < initialPosition.z) { + writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); + } + } + + if (insertToolCall || retracted) { + var lengthOffset = tool.lengthOffset; + if (lengthOffset > numberOfToolSlots) { + error(localize("Length offset out of range.")); + } + + if (!machineConfiguration.isHeadConfiguration()) { + writeBlock( + gAbsIncModal.format(90), + gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y) + ); + writeBlock(gMotionModal.format(0), gFormat.format(43), zOutput.format(initialPosition.z), hFormat.format(lengthOffset)); + } else { + writeBlock( + gAbsIncModal.format(90), + gMotionModal.format(0), + gFormat.format(43), xOutput.format(initialPosition.x), + yOutput.format(initialPosition.y), + zOutput.format(initialPosition.z), hFormat.format(lengthOffset) + ); + } + } else { + writeBlock( + gAbsIncModal.format(90), + gMotionModal.format(0), + xOutput.format(initialPosition.x), + yOutput.format(initialPosition.y) + ); + } + + if (insertToolCall) { + gPlaneModal.reset(); + } +} + +function onDwell(seconds) { + if (seconds > 99999.999) { + warning(localize("Dwelling time is out of range.")); + } + seconds = clamp(0.001, seconds, 99999.999); + writeBlock(gFormat.format(4), "P" + secFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock(sOutput.format(spindleSpeed)); +} + +function onCycle() { + // writeBlock(gPlaneModal.format(17)); +} + +function getCommonCycle(x, y, z, r) { + forceXYZ(); + return [xOutput.format(x), yOutput.format(y), + zOutput.format(z), + "R" + xyzFormat.format(r)]; +} + +function onCyclePoint(x, y, z) { + if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { + expandCyclePoint(x, y, z); + return; + } + expandCyclePoint(x, y, z); + return; +/* + if (isFirstCyclePoint()) { + repositionToCycleClearance(cycle, x, y, z); + + // return to initial Z which is clearance plane and set absolute mode + + var F = cycle.feedrate; + var P = !cycle.dwell ? 0 : clamp(0.001, cycle.dwell, 99999.999); // in seconds + + switch (cycleType) { + case "drilling": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "counter-boring": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82), + getCommonCycle(x, y, z, cycle.retract), + "P" + secFormat.format(P), // not optional + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + case "chip-breaking": + expandCyclePoint(x, y, z); + break; + case "deep-drilling": + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), + getCommonCycle(x, y, z, cycle.retract), + "Q" + xyzFormat.format(cycle.incrementalDepth), + feedOutput.format(F) + ); + } + break; + case "tapping": + if (!F) { + F = tool.getTappingFeedrate(); + } + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "left-tapping": + if (!F) { + F = tool.getTappingFeedrate(); + } + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(74), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "right-tapping": + if (!F) { + F = tool.getTappingFeedrate(); + } + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "fine-boring": // not supported + expandCyclePoint(x, y, z); + break; + case "back-boring": + if (P > 0) { + expandCyclePoint(x, y, z); + } else { + var I = cycle.shift * 1; + var J = cycle.shift * 0; + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87), + getCommonCycle(x, y, z, cycle.retract), + "I" + xyzFormat.format(I), + "J" + xyzFormat.format(J), + "K" + xyzFormat.format(cycle.bottom - cycle.backBoreDistance), + feedOutput.format(F) + ); + } + break; + case "reaming": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + break; + case "stop-boring": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F), + // conditional(P > 0, "P" + secFormat.format(P)), + "P" + secFormat.format(P) // not optional + ); + break; + case "manual-boring": + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88), + getCommonCycle(x, y, z, cycle.retract), + "P" + secFormat.format(P), // not optional + feedOutput.format(F) + ); + break; + case "boring": + if (P > 0) { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), + getCommonCycle(x, y, z, cycle.retract), + "P" + secFormat.format(P), // not optional + feedOutput.format(F) + ); + } else { + writeBlock( + gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), + getCommonCycle(x, y, z, cycle.retract), + feedOutput.format(F) + ); + } + break; + default: + expandCyclePoint(x, y, z); + } + } else { + if (cycleExpanded) { + expandCyclePoint(x, y, z); + } else { + var _x = xOutput.format(x); + var _y = yOutput.format(y); + if (!_x && !_y) { + xOutput.reset(); // at least one axis is required + _x = xOutput.format(x); + } + writeBlock(_x, _y); + } + } +*/ +} + +function onCycleEnd() { + if (!cycleExpanded) { + writeBlock(gCycleModal.format(80)); + zOutput.reset(); + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + if (x || y || z) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(0), x, y, z); + feedOutput.reset(); + } +} + +function onLinear(_x, _y, _z, feed) { + // at least one axis is required + if (pendingRadiusCompensation >= 0) { + // ensure that we end at desired position when compensation is turned off + xOutput.reset(); + yOutput.reset(); + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var f = feedOutput.format(feed); + if (x || y || z) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > numberOfToolSlots) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + writeBlock(gPlaneModal.format(17)); + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + dOutput.reset(); + writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); + break; + case RADIUS_COMPENSATION_RIGHT: + dOutput.reset(); + writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); + break; + default: + writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); + } + } else { + writeBlock(gMotionModal.format(1), x, y, z, f); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + feedOutput.reset(); // force feed on next line + } else { + writeBlock(gMotionModal.format(1), f); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); + break; + default: + linearize(tolerance); + } + } +} + +var currentCoolantMode = COOLANT_OFF; +var coolantOff = undefined; +var forceCoolant = false; + +function setCoolant(coolant) { + var coolantCodes = getCoolantCodes(coolant); + if (Array.isArray(coolantCodes)) { + if (singleLineCoolant) { + writeBlock(coolantCodes.join(getWordSeparator())); + } else { + for (var c in coolantCodes) { + writeBlock(coolantCodes[c]); + } + } + return undefined; + } + return coolantCodes; +} + +function getCoolantCodes(coolant) { + var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line + if (!coolants) { + error(localize("Coolants have not been defined.")); + } + if (tool.type == TOOL_PROBE) { // avoid coolant output for probing + coolant = COOLANT_OFF; + } + if (coolant == currentCoolantMode && (!forceCoolant || coolant == COOLANT_OFF)) { + return undefined; // coolant is already active + } + if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && (coolantOff != undefined) && !forceCoolant) { + if (Array.isArray(coolantOff)) { + for (var i in coolantOff) { + multipleCoolantBlocks.push(coolantOff[i]); + } + } else { + multipleCoolantBlocks.push(coolantOff); + } + } + forceCoolant = false; + + var m; + var coolantCodes = {}; + for (var c in coolants) { // find required coolant codes into the coolants array + if (coolants[c].id == coolant) { + coolantCodes.on = coolants[c].on; + if (coolants[c].off != undefined) { + coolantCodes.off = coolants[c].off; + break; + } else { + for (var i in coolants) { + if (coolants[i].id == COOLANT_OFF) { + coolantCodes.off = coolants[i].off; + break; + } + } + } + } + } + if (coolant == COOLANT_OFF) { + m = !coolantOff ? coolantCodes.off : coolantOff; // use the default coolant off command when an 'off' value is not specified + } else { + coolantOff = coolantCodes.off; + m = coolantCodes.on; + } + + if (!m) { + onUnsupportedCoolant(coolant); + m = 9; + } else { + if (Array.isArray(m)) { + for (var i in m) { + multipleCoolantBlocks.push(m[i]); + } + } else { + multipleCoolantBlocks.push(m); + } + currentCoolantMode = coolant; + for (var i in multipleCoolantBlocks) { + if (typeof multipleCoolantBlocks[i] == "number") { + multipleCoolantBlocks[i] = mFormat.format(multipleCoolantBlocks[i]); + } + } + return multipleCoolantBlocks; // return the single formatted coolant value + } + return undefined; +} + +var mapCommand = { + COMMAND_STOP : 0, + COMMAND_OPTIONAL_STOP : 1, + COMMAND_END : 2, + COMMAND_SPINDLE_CLOCKWISE : 3, + COMMAND_SPINDLE_COUNTERCLOCKWISE: 4, + COMMAND_STOP_SPINDLE : 5 +}; + +function onCommand(command) { + switch (command) { + case COMMAND_STOP: + writeBlock(mFormat.format(0)); + forceSpindleSpeed = true; + forceCoolant = true; + return; + case COMMAND_OPTIONAL_STOP: + writeBlock(mFormat.format(1)); + forceSpindleSpeed = true; + forceCoolant = true; + return; + case COMMAND_START_SPINDLE: + onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + writeBlock(gPlaneModal.format(17)); + if (!isLastSection() && (getNextSection().getTool().coolant != tool.coolant)) { + setCoolant(COOLANT_OFF); + } + forceAny(); +} + +/** Output block to do safe retract and/or move to home position. */ +function writeRetract() { + var words = []; // store all retracted axes in an array + var retractAxes = new Array(false, false, false); + var method = getProperty("safePositionMethod"); + if (method == "clearanceHeight") { + if (!is3D()) { + error(localize("Safe retract option 'Clearance Height' is only supported when all operations are along the setup Z-axis.")); + } + return; + } + validate(arguments.length != 0, "No axis specified for writeRetract()."); + + for (i in arguments) { + retractAxes[arguments[i]] = true; + } + if ((retractAxes[0] || retractAxes[1]) && !retracted) { // retract Z first before moving to X/Y home + error(localize("Retracting in X/Y is not possible without being retracted in Z.")); + return; + } + // special conditions + if (retractAxes[2]) { // Z doesn't use G53 + method = "G28"; + } + + // define home positions + var _xHome; + var _yHome; + var _zHome; + if (method == "G28") { + _xHome = toPreciseUnit(0, MM); + _yHome = toPreciseUnit(0, MM); + _zHome = toPreciseUnit(0, MM); + } else { + _xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM); + _yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM); + _zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM); + } + for (var i = 0; i < arguments.length; ++i) { + switch (arguments[i]) { + case X: + words.push("X" + xyzFormat.format(_xHome)); + xOutput.reset(); + break; + case Y: + words.push("Y" + xyzFormat.format(_yHome)); + yOutput.reset(); + break; + case Z: + words.push("Z" + xyzFormat.format(_zHome)); + zOutput.reset(); + retracted = true; + break; + default: + error(localize("Unsupported axis specified for writeRetract().")); + return; + } + } + if (words.length > 0) { + switch (method) { + case "G28": + gMotionModal.reset(); + gAbsIncModal.reset(); + writeBlock(gFormat.format(28), gAbsIncModal.format(91), words); + writeBlock(gAbsIncModal.format(90)); + break; + case "G53": + gMotionModal.reset(); + writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words); + break; + default: + error(localize("Unsupported safe position method.")); + return; + } + } +} + +function onClose() { + setCoolant(COOLANT_OFF); + + writeRetract(Z); + + writeRetract(X, Y); + + onImpliedCommand(COMMAND_END); + onImpliedCommand(COMMAND_STOP_SPINDLE); + writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off + writeln("%"); +} + +function setProperty(property, value) { + properties[property].current = value; +} diff --git a/datron mcr.cps b/datron mcr.cps new file mode 100644 index 0000000..8ae19d1 --- /dev/null +++ b/datron mcr.cps @@ -0,0 +1,2727 @@ +/** + Copyright (C) 2012-2022 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {1FDF0D08-45B6-4EAD-A71D-7BA04089886D} +*/ + +description = "DATRON MCR"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2022 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 45702; + +longDescription = "Generic post for DATRON CNCs. This post works with all the common Datron CNCs like DATRON M7, DATRON M75, DATRON M10, DATRON M8Cube, and DATRON MLCube."; + +extension = "mcr"; +setCodePage("ascii"); + +capabilities = CAPABILITY_MILLING; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC +allowHelicalMoves = false; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only + +// user-defined properties +properties = { + writeMachine: { + title : "Write machine", + description: "Output the machine settings in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + writeVersion: { + title : "Write version", + description: "Write the version number in the header of the code.", + group : "formats", + type : "boolean", + value : false, + scope : "post" + }, + showOperationDialog: { + title : "Show operation dialog", + description: "Shows a start dialog on the control which allows you to select the operation to start with.", + group : "preferences", + type : "enum", + values : [ + {id:"disabled", title:"Disabled"}, + {id:"dropdown", title:"Dropdown style"}, + {id:"checkbox", title:"Checkbox style"} + ], + value: "dropdown", + scope: "post" + }, + useParametricFeed: { + title : "Parametric feed", + description: "Specifies the feed value that should be output using a Q value.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + showNotes: { + title : "Show notes", + description: "Writes operation notes as comments in the outputted code.", + group : "formats", + type : "boolean", + value : false, + scope : "post" + }, + useSmoothing: { + title : "Use smoothing", + description: "Enable to use smoothing in the NC program.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useDynamic: { + title : "Use dynamic mode", + description: "Enable to use dynamic mode.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useParkPosition: { + title : "Park at end of program", + description: "Enable to use the park position at end of program.", + group : "homePositions", + type : "boolean", + value : true, + scope : "post" + }, + useTimeStamp: { + title : "Use timestamp", + description: "Enable to include timestamp in program header.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + language: { + title : "Language", + description: "Specifies the language to use in the NC program.", + group : "formats", + type : "enum", + values : [ + {id:"en", title:"English"}, + {id:"de", title:"German"} + ], + value: "en", + scope: "post" + }, + useCoolant: { + title : "Write coolant commands", + description: "Enable/disable coolant code outputs for the entire program.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + fourthAxis: { + title : "Has 4th axis", + description: "Enable if the machine is equipped with a 4-axis.", + group : "configuration", + type : "boolean", + value : false, + scope : "post" + }, + _4thAxisRotatesAroundX: { + title : "4th axis rotates around X", + description: "Enable if the 4th axis rotates around the X axis, disable if it rotates around the Y axis.", + group : "configuration", + type : "boolean", + value : true, + scope : "post" + }, + fifthAxis: { + title : "Has 5th axis", + description: "Enable if the machine is equipped with 5-axis capabilities.", + group : "configuration", + type : "boolean", + value : false, + scope : "post" + }, + minimumSpindleSpeed: { + title : "Minimum spindle RPM", + description: "Specifies the lowest available rpm for the spindle.", + group : "configuration", + type : "integer", + range : [ + 0, + 999999999 + ], + value: 6000, + scope: "post" + } +}; + +// samples: +// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} +// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} +var coolants = [ + {id:COOLANT_FLOOD, on:1}, + {id:COOLANT_MIST, on:1}, + {id:COOLANT_THROUGH_TOOL}, + {id:COOLANT_AIR, on:3}, + {id:COOLANT_AIR_THROUGH_TOOL}, + {id:COOLANT_SUCTION}, + {id:COOLANT_FLOOD_MIST}, + {id:COOLANT_FLOOD_THROUGH_TOOL}, + {id:COOLANT_OFF, off:2} +]; + +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var angleFormat = createFormat({decimals:5, scale:DEG}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)}); + +var toolFormat = createFormat({decimals:0}); +var rpmFormat = createFormat({decimals:0, scale:0.001}); +var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 +var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false}); + +var xOutput = createVariable({force:true}, xyzFormat); +var yOutput = createVariable({force:true}, xyzFormat); +var zOutput = createVariable({onchange:function () {retracted = false;}, force:true}, xyzFormat); +var aOutput = createVariable({force:true}, abcFormat); +var bOutput = createVariable({force:true}, abcFormat); +var cOutput = createVariable({force:true}, abcFormat); +var feedOutput = createVariable({}, feedFormat); +var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); + +var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ... + +// fixed settings +var useRTCP = true; // en/disable calculation for having the datum origin out of center of rotary axis for 5 axis kinematics +var maxMaskLength = 40; +var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported + +// collected state +var currentWorkOffset; +var currentFeedValue = -1; +var optionalSection = false; +var forceSpindleSpeed = false; +var activeMovements; // do not use by default +var currentFeedId; +var containsProbingOperations = false; +var retracted = false; // specifies that the tool has been retracted to the safe plane + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +// Start of multi-axis feedrate logic +/***** You can add 'getProperty("useInverseTime'") if desired. *****/ +/***** 'previousABC' can be added throughout to maintain previous rotary positions. Required for Mill/Turn machines. *****/ +/***** 'headOffset' should be defined when a head rotary axis is defined. *****/ +/***** The feedrate mode must be included in motion block output (linear, circular, etc.) for Inverse Time feedrate support. *****/ +var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations +var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds +var maxInverseTime = 45000; // maximum value to output for Inverse Time feeds +var maxDPM = 9999.99; // maximum value to output for DPM feeds +var useInverseTimeFeed = false; // use 1/T feeds +var inverseTimeFormat = createFormat({decimals:5, scale:0.001}); +var inverseTimeOutput = createVariable({prefix:"F", force:true}, inverseTimeFormat); +var previousDPMFeed = 0; // previously output DPM feed +var dpmFeedToler = 0.5; // tolerance to determine when the DPM feed has changed +// var previousABC = new Vector(0, 0, 0); // previous ABC position if maintained in post, don't define if not used +var forceOptimized = undefined; // used to override optimized-for-angles points (XZC-mode) + +/** Calculate the multi-axis feedrate number. */ +function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) { + var f = {frn:0, fmode:0}; + if (feed <= 0) { + error(localize("Feedrate is less than or equal to 0.")); + return f; + } + + var length = getMoveLength(_x, _y, _z, _a, _b, _c); + + if (useInverseTimeFeed) { // inverse time + f.frn = getInverseTime(length.tool, feed); + f.fmode = 93; + feedOutput.reset(); + } else { // degrees per minute + f.frn = getFeedDPM(length, feed); + f.fmode = 94; + } + return f; +} + +/** Returns point optimization mode. */ +function getOptimizedMode() { + if (forceOptimized != undefined) { + return forceOptimized; + } + // return (currentSection.getOptimizedTCPMode() != 0); // TAG:doesn't return correct value + return true; // always return false for non-TCP based heads +} + +/** Calculate the DPM feedrate number. */ +function getFeedDPM(_moveLength, _feed) { + if ((_feed == 0) || (_moveLength.tool < 0.0001) || (toDeg(_moveLength.abcLength) < 0.0005)) { + previousDPMFeed = 0; + return _feed; + } + var moveTime = _moveLength.tool / _feed; + if (moveTime == 0) { + previousDPMFeed = 0; + return _feed; + } + + var dpmFeed; + var tcp = false; // !getOptimizedMode() && (forceOptimized == undefined); // set to false for rotary heads + if (tcp) { // TCP mode is supported, output feed as FPM + dpmFeed = _feed; + } else if (false) { // standard DPM + dpmFeed = Math.min(toDeg(_moveLength.abcLength) / moveTime, maxDPM); + if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) { + dpmFeed = previousDPMFeed; + } + } else if (true) { // combination FPM/DPM + var length = Math.sqrt(Math.pow(_moveLength.xyzLength, 2.0) + Math.pow((toDeg(_moveLength.abcLength) * dpmBPW), 2.0)); + dpmFeed = Math.min((length / moveTime), maxDPM); + if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) { + dpmFeed = previousDPMFeed; + } + } else { // machine specific calculation + dpmFeed = _feed; + } + previousDPMFeed = dpmFeed; + return dpmFeed; +} + +/** Calculate the Inverse time feedrate number. */ +function getInverseTime(_length, _feed) { + var inverseTime; + if (_length < 1.e-6) { // tool doesn't move + if (typeof maxInverseTime === "number") { + inverseTime = maxInverseTime; + } else { + inverseTime = 999999; + } + } else { + inverseTime = _feed / _length / inverseTimeUnits; + if (typeof maxInverseTime === "number") { + if (inverseTime > maxInverseTime) { + inverseTime = maxInverseTime; + } + } + } + return inverseTime; +} + +/** Calculate radius for each rotary axis. */ +function getRotaryRadii(startTool, endTool, startABC, endABC) { + var radii = new Vector(0, 0, 0); + var startRadius; + var endRadius; + var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); + for (var i = 0; i < 3; ++i) { + if (axis[i].isEnabled()) { + var startRadius = getRotaryRadius(axis[i], startTool, startABC); + var endRadius = getRotaryRadius(axis[i], endTool, endABC); + radii.setCoordinate(axis[i].getCoordinate(), Math.max(startRadius, endRadius)); + } + } + return radii; +} + +/** Calculate the distance of the tool position to the center of a rotary axis. */ +function getRotaryRadius(axis, toolPosition, abc) { + if (!axis.isEnabled()) { + return 0; + } + + var direction = axis.getEffectiveAxis(); + var normal = direction.getNormalized(); + // calculate the rotary center based on head/table + var center; + var radius; + if (axis.isHead()) { + var pivot; + if (typeof headOffset === "number") { + pivot = headOffset; + } else { + pivot = tool.getBodyLength(); + } + if (axis.getCoordinate() == machineConfiguration.getAxisU().getCoordinate()) { // rider + center = Vector.sum(toolPosition, Vector.product(machineConfiguration.getDirection(abc), pivot)); + center = Vector.sum(center, axis.getOffset()); + radius = Vector.diff(toolPosition, center).length; + } else { // carrier + var angle = abc.getCoordinate(machineConfiguration.getAxisU().getCoordinate()); + radius = Math.abs(pivot * Math.sin(angle)); + radius += axis.getOffset().length; + } + } else { + center = axis.getOffset(); + var d1 = toolPosition.x - center.x; + var d2 = toolPosition.y - center.y; + var d3 = toolPosition.z - center.z; + var radius = Math.sqrt( + Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) + ); + } + return radius; +} + +/** Calculate the linear distance based on the rotation of a rotary axis. */ +function getRadialDistance(radius, startABC, endABC) { + // calculate length of radial move + var delta = Math.abs(endABC - startABC); + if (delta > Math.PI) { + delta = 2 * Math.PI - delta; + } + var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI)); + return radialLength; +} + +/** Calculate tooltip, XYZ, and rotary move lengths. */ +function getMoveLength(_x, _y, _z, _a, _b, _c) { + // get starting and ending positions + var moveLength = {}; + var startTool; + var endTool; + var startXYZ; + var endXYZ; + var startABC; + if (typeof previousABC !== "undefined") { + startABC = new Vector(previousABC.x, previousABC.y, previousABC.z); + } else { + startABC = getCurrentDirection(); + } + var endABC = new Vector(_a, _b, _c); + + if (!getOptimizedMode()) { // calculate XYZ from tool tip + startTool = getCurrentPosition(); + endTool = new Vector(_x, _y, _z); + startXYZ = startTool; + endXYZ = endTool; + + // adjust points for tables + if (!machineConfiguration.getTableABC(startABC).isZero() || !machineConfiguration.getTableABC(endABC).isZero()) { + startXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).getTransposed().multiply(startXYZ); + endXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).getTransposed().multiply(endXYZ); + } + + // adjust points for heads + if (machineConfiguration.getAxisU().isEnabled() && machineConfiguration.getAxisU().isHead()) { + if (typeof getOptimizedHeads === "function") { // use post processor function to adjust heads + startXYZ = getOptimizedHeads(startXYZ.x, startXYZ.y, startXYZ.z, startABC.x, startABC.y, startABC.z); + endXYZ = getOptimizedHeads(endXYZ.x, endXYZ.y, endXYZ.z, endABC.x, endABC.y, endABC.z); + } else { // guess at head adjustments + var startDisplacement = machineConfiguration.getDirection(startABC); + startDisplacement.multiply(headOffset); + var endDisplacement = machineConfiguration.getDirection(endABC); + endDisplacement.multiply(headOffset); + startXYZ = Vector.sum(startTool, startDisplacement); + endXYZ = Vector.sum(endTool, endDisplacement); + } + } + } else { // calculate tool tip from XYZ, heads are always programmed in TCP mode, so not handled here + startXYZ = getCurrentPosition(); + endXYZ = new Vector(_x, _y, _z); + startTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).multiply(startXYZ); + endTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).multiply(endXYZ); + } + + // calculate axes movements + moveLength.xyz = Vector.diff(endXYZ, startXYZ).abs; + moveLength.xyzLength = moveLength.xyz.length; + moveLength.abc = Vector.diff(endABC, startABC).abs; + for (var i = 0; i < 3; ++i) { + if (moveLength.abc.getCoordinate(i) > Math.PI) { + moveLength.abc.setCoordinate(i, 2 * Math.PI - moveLength.abc.getCoordinate(i)); + } + } + moveLength.abcLength = moveLength.abc.length; + + // calculate radii + moveLength.radius = getRotaryRadii(startTool, endTool, startABC, endABC); + + // calculate the radial portion of the tool tip movement + var radialLength = Math.sqrt( + Math.pow(getRadialDistance(moveLength.radius.x, startABC.x, endABC.x), 2.0) + + Math.pow(getRadialDistance(moveLength.radius.y, startABC.y, endABC.y), 2.0) + + Math.pow(getRadialDistance(moveLength.radius.z, startABC.z, endABC.z), 2.0) + ); + + // calculate the tool tip move length + // tool tip distance is the move distance based on a combination of linear and rotary axes movement + moveLength.tool = moveLength.xyzLength + radialLength; + + // debug + if (false) { + writeComment("DEBUG - tool = " + moveLength.tool); + writeComment("DEBUG - xyz = " + moveLength.xyz); + var temp = Vector.product(moveLength.abc, 180 / Math.PI); + writeComment("DEBUG - abc = " + temp); + writeComment("DEBUG - radius = " + moveLength.radius); + } + return moveLength; +} +// End of multi-axis feedrate logic + +/** + Writes the specified block. +*/ +function writeBlock() { + writeWords(arguments); +} + +var charMap = { + "\u00c4": "Ae", + "\u00e4": "ae", + "\u00dc": "Ue", + "\u00fc": "ue", + "\u00d6": "Oe", + "\u00f6": "oe", + "\u00df": "ss", + "\u002d": "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()); + return mapped.replace(/[^A-Za-z0-9\-_]/g, ""); +} + +/** + Output a comment. +*/ +function writeComment(text) { + writeln("; !" + formatComment(text) + "!"); +} + +function onOpen() { + if (getProperty("fourthAxis") || getProperty("fifthAxis")) { // note: setup your machine here + var aAxis; + if (getProperty("fourthAxis") && getProperty("fifthAxis")) { + aAxis = createAxis( + { + coordinate: getProperty("fifthAxis") ? 0 : 1, + table : true, + axis : [getProperty("_4thAxisRotatesAroundX") ? -1 : 0, getProperty("_4thAxisRotatesAroundX") ? 0 : -1, 0], + range : [getProperty("fifthAxis") ? -100 : -360, getProperty("fifthAxis") ? 0 : 360], + preference: -1 + } + ); + } else { + aAxis = createAxis({coordinate:1, table:true, axis:[getProperty("_4thAxisRotatesAroundX") ? 1 : 0, getProperty("_4thAxisRotatesAroundX") ? 0 : 1, 0], range:[-360, 360], preference:1}); + } + + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, -1], range:[-360, 360], cyclic:true, preference:0}); + + if (getProperty("fourthAxis")) { + if (getProperty("fifthAxis")) { + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + } else { + machineConfiguration = new MachineConfiguration(aAxis); + } + } + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // TCP mode + } + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isProbeOperation(section)) { + containsProbingOperations = true; + break; + } + } + + // header + writeProgramHeader(); +} + +function getOperationDescription(section) { + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +/** Writes the tool table. */ +function writeToolTable() { + var tools = getToolTable(); + writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!"); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + xyzFormat.format(tool.diameter) + " " + + "L2:" + xyzFormat.format(tool.fluteLength) + " " + + "L3:" + xyzFormat.format(tool.shoulderLength) + "!"; + writeBlock(comment); + } + } +} + +/** Writes the program header. */ +function writeProgramHeader() { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + + if (getProperty("useTimeStamp")) { + writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.09F!"); + } else { + writeBlock("!Makro file ; V9.09F!"); + } + if (programComment) { + writeBlock("!" + formatComment(programComment) + "!"); + } else { + writeBlock("!Makroprojekt description!"); + } + writeln(""); + + writeln("!Please make sure that the language on your control is set to " + "\"" + getProperty("language") + "\"" + "!"); + switch (getProperty("language")) { + case "en": + writeBlock("_sprache 1;"); + break; + case "de": + writeBlock("_sprache 0;"); + break; + default: + writeBlock("_sprache 1;"); + } + + writeln(""); + switch (unit) { + case IN: + writeBlock("Dimension 2;"); + break; + case MM: + writeBlock("Dimension 1;"); + break; + } + + writeln(""); + + var variablesDeclaration = new Array(); + var submacrosDeclaration = new Array(); + var dialogsDeclaration = new Array(); + + if (getProperty("showOperationDialog") != "disabled") { + variablesDeclaration.push("optional_stop"); + if (getProperty("showOperationDialog") == "checkbox") { + if (getNumberOfSections() >= maxMaskLength) { + submacrosDeclaration.push("Initvariables"); + } + } + } + variablesDeclaration.push("$Message"); + + dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\""); + if (getProperty("showOperationDialog") != "disabled") { + if (getProperty("showOperationDialog") == "dropdown") { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } else { + dialogsDeclaration.push("_feld optional_stop, 1, 0, 1, 0, 1, 2, 1," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\""); + } + } + + //write variables declaration + var tools = getToolTable(); + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + variablesDeclaration.push("T" + tool.number); + } + + var numberOfSections = getNumberOfSections(); + if (getProperty("showOperationDialog") == "dropdown") { + var dropDownElements = new Array(); + variablesDeclaration.push("startOperation"); + } + + var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <"; + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var sectionID = i + 1; + variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section))); + submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section))); + if (getProperty("showOperationDialog") == "dropdown") { + dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">"); + } else if (getProperty("showOperationDialog") == "checkbox") { + if (getNumberOfSections() < maxMaskLength) { + dialogsDeclaration.push("_feld Op_" + formatVariable(getOperationDescription(section)) + ", 1, 0, 1, 0, 1, 2, 1," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + "," + " \"" + + formatVariable(getOperationDescription(section)) + "\"" + ); + } + } + if (getProperty("useParametricFeed")) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (variablesDeclaration.indexOf(feedDescription) == -1) { + variablesDeclaration.push(feedDescription); + } + } + } + } + + if (getProperty("showOperationDialog") == "dropdown") { + dropDownDialog += dropDownElements.join(", "); + dropDownDialog += ">\", \"Select the operation to start with. \""; + dialogsDeclaration.push(dropDownDialog); + } + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + variablesDeclaration.push("X_initial_pos"); + variablesDeclaration.push("Y_initial_pos"); + variablesDeclaration.push("Z_initial_pos"); + variablesDeclaration.push("A_initial_pos"); + variablesDeclaration.push("B_initial_pos"); + variablesDeclaration.push("C_initial_pos"); + variablesDeclaration.push("X_delta"); + variablesDeclaration.push("Y_delta"); + variablesDeclaration.push("Z_delta"); + variablesDeclaration.push("A_delta"); + variablesDeclaration.push("B_delta"); + variablesDeclaration.push("C_delta"); + variablesDeclaration.push("X"); + variablesDeclaration.push("Y"); + variablesDeclaration.push("Z"); + variablesDeclaration.push("A"); + variablesDeclaration.push("B"); + variablesDeclaration.push("C"); + variablesDeclaration.push("Israpid"); + variablesDeclaration.push("X_trans"); + variablesDeclaration.push("Y_trans"); + variablesDeclaration.push("Z_trans"); + variablesDeclaration.push("X_new"); + variablesDeclaration.push("Y_new"); + variablesDeclaration.push("Z_new"); + variablesDeclaration.push("X_temp"); + variablesDeclaration.push("Y_temp"); + variablesDeclaration.push("Z_temp"); + variablesDeclaration.push("A_temp"); + variablesDeclaration.push("B_temp"); + variablesDeclaration.push("C_temp"); + variablesDeclaration.push("Isinitialposition"); + variablesDeclaration.push("timefeed"); + + submacrosDeclaration.push("Initposition"); + submacrosDeclaration.push("Endmacro"); + } + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + submacrosDeclaration.push("Transformpath"); + } + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + submacrosDeclaration.push("Transformoffset"); + } + + submacrosDeclaration.push("Retractzmax"); + variablesDeclaration.push("Curr_zpno"); + variablesDeclaration.push("Zpos"); + + if (containsProbingOperations) { + variablesDeclaration.push("Xvalue1"); + variablesDeclaration.push("Xvalue2"); + variablesDeclaration.push("Yvalue1"); + variablesDeclaration.push("Yvalue2"); + variablesDeclaration.push("Zvalue"); + variablesDeclaration.push("Newpos"); + variablesDeclaration.push("Rotationvalue"); + } + + writeBlock("Variable " + variablesDeclaration.join(", ") + ";"); + writeln(""); + writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";"); + writeln(""); + writeBlock(dialogsDeclaration.join(EOL) + ";"); + writeln(""); + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + writeBlock("_exit Endmacro;"); + writeln(""); + } + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + writeBlock("_maske Transformoffset, 4, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\";"); + writeln(""); + writeBlock("_maske Transformpath, 9, 0, \"create a new coordinate system with the given rotation values\""); + writeBlock("_feld Israpid, 4, 5, 0, -9999, 9999, 2, 0, \"Is rapid\", \"is rapid\""); + writeBlock("_feld Isinitialposition, 4, 3, 0, -9999, 9999, 2, 1, \"Isinitialposition\", \"If set machine positioning with z max height\""); + writeBlock("_feld X, 4, 5, 0, -9999, 9999, 0, 1, \"X Value\", \"X Position\""); + writeBlock("_feld Y, 4, 5, 0, -9999, 9999, 0, 1, \"Y Value\", \"Y Position\""); + writeBlock("_feld Z, 4, 5, 0, -9999, 9999, 0, 1, \"Z Value\", \"Z Position\""); + writeBlock("_feld A, 4, 8, 0, -9999, 9999, 0, 1, \"alpha\", \"rotation around x axis\""); + writeBlock("_feld B, 4, 8, 0, -9999, 9999, 0, 1, \"beta\", \"rotation around Y\""); + writeBlock("_feld C, 4, 8, 0, -9999, 9999, 0, 1, \"gamma\", \"rotation around Z\""); + writeBlock("_feld timefeed, 4, 8, 0, 0, " + maxInverseTime + ", 0, 1, \"time in seconds\", \"movement duration for the current line segment\";"); + writeln(""); + } + + if (getProperty("showOperationDialog") == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock("("); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + writeBlock("Op_" + formatVariable(getOperationDescription(section)) + " = 1"); + } + writeln(") Initvariables;"); + } + } + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + createPositionInitSubmacro(); + createEndmacro(); + } + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + createRtcpTransformationSubmacro(); + } + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + createRtcpSimuSubmacro(); + } + + createRetractMacro(); +} + +function writeMainProgram() { + + var numberOfSections = getNumberOfSections(); + if (getProperty("showOperationDialog") == "checkbox") { + if (numberOfSections >= maxMaskLength) { + writeBlock(translate("Submacro") + " Initvariables;"); + } + } + + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var Description = getOperationDescription(section); + var sectionID = i + 1; + + var sectionName = formatVariable("Sm_" + Description); + var maskName = formatVariable("Op_" + Description); + + writeComment("##########" + Description + "##########"); + if (getProperty("showOperationDialog") == "checkbox") { + writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";"); + } else if (getProperty("showOperationDialog") == "dropdown") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + + var tool = section.getTool(); + if (getProperty("showNotes") && section.hasParameter("notes")) { + var notes = section.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = section.getGlobalZRange(); + var number = tool.number; + if (section.getTool().number != number) { + break; + } + zRange.expandToRange(section.getGlobalZRange()); + writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!"); + } + } + if (!isProbeOperation(section)) { + writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;"); + var _spindleSpeed = section.getInitialSpindleSpeed(); + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(Math.max(_spindleSpeed, getProperty("minimumSpindleSpeed"))) + ", 0, 30;"); + } + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + var t = tolerance; + if (section.hasParameter("operation:tolerance")) { + t = section.getParameter("operation:tolerance"); + } + if (getProperty("useDynamic")) { + var dynamic = 5; + if (t <= 0.02) { + dynamic = 4; + } + if (t <= 0.01) { + dynamic = 3; + } + if (t <= 0.005) { + dynamic = 2; + } + if (t <= 0.003) { + dynamic = 1; + } + writeBlock(translate("Dynamics") + " " + dynamic + ";"); + } + if (getProperty("useParametricFeed")) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!")); + } + } + + // wcs + var workOffset = section.workOffset; + if (workOffset != 0 && workOffset < 41) { + workOffset = (getProperty("fourthAxis") && getProperty("fifthAxis")) ? 19 : workOffset; + if (workOffset != currentWorkOffset) { + writeBlock("Position " + workOffset + ", 2;"); + currentWorkOffset = workOffset; + } + } + + writeBlock(translate("Submacro") + " " + sectionName + ";"); + if (getProperty("showOperationDialog") == "checkbox") { + writeBlock(translate("Label") + " " + sectionID + ";"); + } + } +} + +function writeWorkpiece() { + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("; !" + translate("Workpiece dimensions") + ":!"); + writeBlock( + "; !min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z) + "!" + ); + writeBlock( + "; !max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z) + "!" + ); + writeBlock( + "; !" + translate("Part size") + " X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z) + "!" + ); + + // insert maximum deep of the hole program + + writeBlock( + "Wdef " + + xyzFormat.format(delta.getX()) + ", " + + xyzFormat.format(delta.getY()) + ", " + + xyzFormat.format(delta.getZ()) + ", " + + xyzFormat.format(workpiece.lower.x) + ", " + + xyzFormat.format(workpiece.lower.y) + ", " + + xyzFormat.format(workpiece.upper.z) + ", 0;" + ); +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + previousDPMFeed = 0; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, feed) { + this.id = id; + this.description = description; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";"); + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";"; + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + activeFeeds.push(feedContext); + } + ++id; + + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge")); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + if (true) { // high feed + if ((movements & (1 << MOVEMENT_HIGH_FEED)) || (highFeedMapping != HIGH_FEED_NO_MAPPING)) { + var feed; + if (hasParameter("operation:highFeedrateMode") && getParameter("operation:highFeedrateMode") != "disabled") { + feed = getParameter("operation:highFeedrate"); + } else { + feed = this.highFeedrate; + } + var feedContext = new FeedContext(id, localize("High Feed"), feed); + activeFeeds.push(feedContext); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + activeMovements[MOVEMENT_RAPID] = feedContext; + } + ++id; + } + return activeFeeds; +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +/* +function onRewindMachine() { + writeComment("REWIND"); +} +*/ + +function setWorkPlane(abc) { + forceWorkPlane(); // always need the new workPlane + + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + + if (!((currentWorkPlaneABC == undefined) || + abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || + abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || + abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { + return; // no change + } + + if (!retracted) { + writeRetract(Z); + } + + gMotionModal.reset(); + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + writeBlock("A_temp = " + (machineConfiguration.isMachineCoordinate(0) ? abcFormat.format(abc.x) : "a6p") + " - A_delta;"); + writeBlock("B_temp = " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + " - B_delta;"); + writeBlock("C_temp = " + (machineConfiguration.isMachineCoordinate(2) ? abcFormat.format(abc.z) : "c6p") + " - C_delta;"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, A_temp, B_temp, C_temp;"); + // writeBlock("Axyzabc 1, x6p, y6p, z6p, a6p, " + (machineConfiguration.isMachineCoordinate(1) ? abcFormat.format(abc.y) : "b6p") + ", c6p;"); + if (machineConfiguration.isMultiAxisConfiguration() && !currentSection.isMultiAxis()) { + writeBlock(translate("Submacro") + " Transformoffset 0, ", + abcFormat.format(abc.x) + ", ", + abcFormat.format(abc.y) + ", ", + abcFormat.format(abc.z) + ";"); + } + } else { + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + writeBlock("Axyzabc 1, x6p, y6p, z6p, " + a + ", " + b + ", " + c + ";"); + } + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + return undefined; + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) + ); + return undefined; + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function createRtcpSimuSubmacro() { + + writeBlock("("); + if (useInverseTimeFeed) { + writeBlock(translate("Feed") + " timefeed" + (Array(4).join(", timefeed")) + ";"); + } + + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + if (getProperty("fifthAxis")) { + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + } + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X - X_trans;"); + writeBlock("Y_new = Y - Y_trans;"); + writeBlock("Z_new = ( ( Isinitialposition + 1 ) % 2 ) * ( Z - Z_trans ) + Isinitialposition * Z6max;"); + + writeBlock("A_temp = A - A_delta;"); + writeBlock("B_temp = B - B_delta;"); + writeBlock("C_temp = C - C_delta;"); + + if (getProperty("fourthAxis") && getProperty("fifthAxis")) { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, A_temp, 0, C_temp;"); + } else { + writeBlock("Axyzabc Israpid, X_new, Y_new, Z_new, 0, A_temp, 0;"); + } + + writeBlock(") Transformpath;"); + +} + +function createRtcpTransformationSubmacro() { + writeBlock("("); + writeBlock("Position 19, 2;"); + /* + if (getProperty("fifthAxis")) { + writeBlock("Position 19, 2;"); + } else if (getProperty("fourthAxis") && getProperty("fifthAxis")) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_temp = X_delta;"); + writeBlock("Y_temp = Y_delta;"); + writeBlock("Z_temp = Z_delta;"); + + writeBlock(";!Rotation around C!;"); + writeBlock("X_trans = X_temp * Cos ( C ) - Y_temp * Sin ( C );"); + writeBlock("Y_trans = X_temp * Sin ( C ) + Y_temp * Cos ( C );"); + writeBlock("Z_trans = Z_temp;"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Rotation around A!;"); + writeBlock("X_trans = X_temp;"); + writeBlock("Y_trans = Y_temp * Cos ( A ) - Z_temp * Sin ( A );"); + writeBlock("Z_trans = Y_temp * Sin ( A ) + Z_temp * Cos ( A );"); + writeBlock("X_temp = X_trans;"); + writeBlock("Y_temp = Y_trans;"); + writeBlock("Z_temp = Z_trans;"); + + // writeBlock(";!Rotation around B!;"); + // writeBlock("X_trans = Z_temp * Sin ( B ) + X_temp * Cos ( B );"); + // writeBlock("Y_trans = Y_temp;"); + // writeBlock("Z_trans = Z_temp * Cos ( B ) - X_temp * Sin ( B );"); + // writeBlock("X_temp = X_trans;"); + // writeBlock("Y_temp = Y_trans;"); + // writeBlock("Z_temp = Z_trans;"); + + writeBlock(";!Calc new Position!;"); + writeBlock("X_new = X6p + X_trans;"); + writeBlock("Y_new = Y6p + Y_trans;"); + writeBlock("Z_new = Z6p + Z_trans;"); + writeBlock(";!set new position!;"); + writeBlock(translate("Setzp") + " X_new, Y_new, Z_new;"); + writeBlock(") Transformoffset;"); +} + +function createPositionInitSubmacro() { + // get initial offset + writeBlock("("); + writeBlock("X_initial_pos = X6p;"); + writeBlock("Y_initial_pos = Y6p;"); + writeBlock("Z_initial_pos = Z6p;"); + writeBlock("A_initial_pos = A6p;"); + writeBlock("B_initial_pos = B6p;"); + writeBlock("C_initial_pos = C6p;"); + + writeBlock("Position 19, 2;"); + /* + if (getProperty("fifthAxis")) { + writeBlock("Position 19, 2;"); + } else if (getProperty("fourthAxis") && getProperty("fifthAxis")) { + writeBlock("Position 21, 2;"); + } +*/ + writeBlock("X_delta = X_initial_pos - X6p;"); + writeBlock("Y_delta = Y_initial_pos - Y6p;"); + writeBlock("Z_delta = Z_initial_pos - Z6p;"); + writeBlock("A_delta = A_initial_pos - A6p;"); + writeBlock("B_delta = B_initial_pos - B6p;"); + writeBlock("C_delta = C_initial_pos - C6p;"); + writeBlock(") Initposition;"); +} + +function createRetractMacro() { + writeBlock("("); + writeBlock("Curr_zpno = Zeromemnr;"); + writeBlock(translate("Zeromem") + " 0;"); + writeBlock("Zpos = - Wzl - " + (unit == MM ? 10 : 0.5) + ";"); + writeBlock("Axyz 1, Xp, Yp, Zpos, 0, 0;"); + writeBlock(translate("Zeromem") + " Curr_zpno;"); + writeBlock(") Retractzmax;"); +} + +function createEndmacro() { + writeBlock("("); + if (useInverseTimeFeed) { + mcrSetTimeFeed(); + } + writeBlock(translate("Submacro") + " Transformoffset 0, 0, 0, 0;"); + writeBlock(") Endmacro;"); +} + +function isProbeOperation(section) { + return section.getTool().type == TOOL_PROBE; +} + +function onSection() { + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + var insertToolCall = forceToolAndRetract || isFirstSection() || + currentSection.getForceToolChange && currentSection.getForceToolChange() || + (tool.number != getPreviousSection().getTool().number); + + retracted = false; + var newWorkOffset = isFirstSection() || + (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes + var newWorkPlane = isFirstSection() || + !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || + (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && + Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || + (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || + (getPreviousSection().isMultiAxis() != currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations + writeBlock("("); + if (isProbeOperation(currentSection)) { + writeBlock("T3d 9, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // enable probe + writeBlock(translate("Rpm") + " 0, 30, 0, 30;"); + } else { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + + if (newWorkOffset || newWorkPlane) { + // retract to safe plane + writeRetract(Z); + forceXYZ(); + } + + if (insertToolCall) { + forceWorkPlane(); + + if (tool.number > 99) { + warning(localize("Tool number exceeds maximum value.")); + } + } + + if (insertToolCall || + forceSpindleSpeed || + isFirstSection() || + (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || + (tool.clockwise != getPreviousSection().getTool().clockwise)) { + forceSpindleSpeed = false; + + if (spindleSpeed < getProperty("minimumSpindleSpeed")) { + warning(localize("Spindle speed is below the minimum value.")); + } + if (spindleSpeed > 60000) { + warning(localize("Spindle speed exceeds maximum value.")); + } + if (!tool.clockwise) { + error(localize("Spindle direction not supported.")); + return; + } + + //onCommand(COMMAND_START_CHIP_TRANSPORT); + if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { + // writeBlock(mFormat.format(xxx)); // shortest path traverse + } + } + + forceXYZ(); + + if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode + // set working plane after datum shift + + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + setWorkPlane(abc); // pre-positioning ABC + } else { + var abc = new Vector(0, 0, 0); + abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + //error(localize("Tool orientation is not supported.")); + error(translate( + "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n")); + return; + } + setRotation(remaining); + } + + forceAny(); + + var t = tolerance; + if (hasParameter("operation:tolerance")) { + if (t < getParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + } + if (getProperty("useSmoothing") && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;"); + } + + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + if (!retracted) { + if (getCurrentPosition().z < initialPosition.z) { + writeRetract(Z); + } + } + + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 1;"); + } + + if (currentSection.isMultiAxis()) { + var abc = currentSection.getInitialToolAxisABC(); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(abc.x) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(abc.y) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(abc.z) : "c6p"); + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + writeBlock("Position 19, 2;"); + /* + if (getProperty("fifthAxis")) { + writeBlock("Position 19, 2;"); + } else if (getProperty("fourthAxis") && getProperty("fifthAxis")) { + writeBlock("Position 21, 2;"); + } +*/ + writeRetract(Z); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ",0;" + ); + } else { + if (!retracted) { + writeRetract(Z); + } + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + "z6p" + ", " + + a + ", " + + b + ", " + + c + ";" + ); + writeBlock("Axyzabc 1, " + + xOutput.format(initialPosition.x) + ", " + + yOutput.format(initialPosition.y) + ", " + + zOutput.format(initialPosition.z) + ", " + + a + ", " + + b + ", " + + c + ";" + ); + } + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0,0;"); + // writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ",0,0;"); + } else { + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;"); + } + + if (getProperty("useParametricFeed") /*&& + hasParameter("operation-strategy") && + (getParameter("operation-strategy") != "drill")*/ && + !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + if (!insertToolCall && + activeMovements && + (getCurrentSectionId() > 0) && + ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { + // use the current feeds + } else { + initializeActiveFeeds(currentSection); + } + } else { + activeMovements = undefined; + } + retracted = false; +} + +function onDwell(seconds) { + writeln(translate("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;"); +} + +function onSpindleSpeed(spindleSpeed) { + var _spindleSpeed = spindleSpeed; + writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(Math.max(_spindleSpeed, getProperty("minimumSpindleSpeed"))) + ", 0, 30;"); +} + +function onCycle() { +} + +/** Convert approach to sign. */ +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { + expandCyclePoint(x, y, z); + return; + } + writeBlock(getFeed(cycle.feedrate)); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { + if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + } + forceXYZ(); + } + + switch (cycleType) { + case "bore-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrBoreMilling(cycle); + break; + case "thread-milling": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;"); + mcrThreadMilling(cycle); + break; + case "probing-x": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + break; + case "probing-y": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + break; + case "probing-z": + var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;"); + writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";"); + break; + case "probing-x-wall": + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-wall": + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel": + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel": + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-channel-with-island": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-circular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-boss": + // X positions + var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); // this might be wrong + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + var touchPositionY1 = y + cycle.width2 / 2 + (tool.diameter / 2 - cycle.probeOvertravel); + var touchPositionY2 = y - cycle.width2 / 2 - (tool.diameter / 2 - cycle.probeOvertravel); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole": + // X positions + var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y positions + forceXYZ(); + var touchPositionY1 = y + (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + var touchPositionY2 = y - (cycle.width2 / 2 + cycle.probeOvertravel - tool.diameter / 2); + + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-rectangular-hole-with-island": + // X positions + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX2 = xOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + + // Y positions + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width2 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = yOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel; + writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width2 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY2 = yOutput.getCurrent() - cycle.probeClearance - cycle.probeOvertravel; + writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";"); + writeBlock("Taxyz 2, x6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;"); + writeBlock(translate("Setzp") + " x6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-inner-corner": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-xy-outer-corner": + // X position + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y * -1) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;"); + writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;"); + + // Y position + forceXYZ(); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x * -1) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;"); + writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-x-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionX2 = touchPositionX1; + writeBlock("Xvalue1 = " + touchPositionX1 + ";"); + writeBlock("Xvalue2 = " + touchPositionX2 + ";"); + writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.probeSpacing / 2) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Xvalue2 - Xvalue1 ) / " + "(" + (y + cycle.probeSpacing / 2) + "-" + (y - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + case "probing-y-plane-angle": + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + + var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY2 = touchPositionY1; + writeBlock("Yvalue1 = " + touchPositionY1 + ";"); + writeBlock("Yvalue2 = " + touchPositionY2 + ";"); + writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.probeSpacing / 2) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;"); + writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;"); + writeBlock("Rotationvalue = Arctan ( ( Yvalue2 - Yvalue1 ) / " + "(" + (x + cycle.probeSpacing / 2) + "-" + (x - cycle.probeSpacing / 2) + ") );"); + writeBlock(translate("Rotation") + " Rotationvalue, 1, 1, 1, 0, 0;"); + writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;"); + break; + default: + expandCyclePoint(x, y, z); + } +} + +function mcrBoreMilling(cycle) { + var numberOfSteps = (cycle.numberOfSteps != undefined) ? cycle.numberOfSteps : 0; + if (numberOfSteps > 2) { + error(localize("Only 2 steps are allowed for bore-milling")); + return; + } + + var helixCycles = Math.floor(cycle.depth / cycle.pitch); // needs to be tested + var XYCleaning = (numberOfSteps == 2) ? cycle.stepover : 0; + var bottomCleaning = 0; + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var maxZDepthPerStep = tool.fluteLength * 0.8; + + var block = subst(translate("Drill") + " %1, %5, %2, %3, %4, 1, %6, %7, %8;", + xyzFormat.format(fastZPlunge), + xyzFormat.format(cycle.diameter), + helixCycles, + xyzFormat.format(XYCleaning), + xyzFormat.format(slowZPlunge), + bottomCleaning, + xyzFormat.format(cycle.depth), + xyzFormat.format(maxZDepthPerStep) + ); + + writeBlock(block); +} + +function mcrThreadMilling(cycle) { + var fastZPlunge = cycle.clearance - cycle.retract; + var slowZPlunge = cycle.retract - cycle.stock; + var threadDirection = (cycle.threading == "right") ? 1 : -1; + + var stringSubst = new StringSubstitution(); + stringSubst.setValue("ThreadNorm", 0); + stringSubst.setValue("ThreadMillingDirection", 0); + stringSubst.setValue("ThreadDiameter", xyzFormat.format(cycle.diameter * threadDirection)); + stringSubst.setValue("InnerOuter", 1); + stringSubst.setValue("Pitch", xyzFormat.format(cycle.pitch)); + stringSubst.setValue("HoleDepth", xyzFormat.format(cycle.depth + 1)); + stringSubst.setValue("ThreadDepth", xyzFormat.format(cycle.depth)); + stringSubst.setValue("CleanXY", xyzFormat.format(cycle.repeatPass)); + stringSubst.setValue("FastZMove", xyzFormat.format(fastZPlunge)); + stringSubst.setValue("SlowZMove", xyzFormat.format(slowZPlunge)); + stringSubst.setValue("ThreadMillAngle", 60); + stringSubst.setValue("Predrill", 0); + stringSubst.setValue("ThreadID", 0); + stringSubst.setValue("Sink", 1); // 0 = with sink, 1 = without sink + + writeBlock( + stringSubst.substitute(translate("Thread") + " ${ThreadNorm}, ${ThreadMillingDirection}, ${ThreadDiameter}, ${InnerOuter}, ${Pitch}, ${HoleDepth}, ${ThreadDepth}, ${CleanXY}, ${FastZMove}, ${SlowZMove}, ${ThreadMillAngle}, ${Predrill}, ${Sink}, ${ThreadID};") + ); +} + +// implement G93 command +function mcrSetInverseTimeFeed() { + directWriteToCNC("G93"); +} + +// implement G94 command +function mcrSetTimeFeed() { + directWriteToCNC("G94"); +} + +// write a command to the cnc kernel without interpretation from the control +function directWriteToCNC(command) { + error(localize("Inverse Time feed is currently not supported.")); + return; +} + +function onCycleEnd() { + if (!cycleExpanded) { + zOutput.reset(); + } + + var probeWorkOffsetCode; + if (isProbeOperation(currentSection)) { + var probeOutputWorkOffset = currentSection.probeWorkOffset; + var workOffset = probeOutputWorkOffset ? probeOutputWorkOffset : currentWorkOffset; + if (workOffset != 0) { + if (workOffset >= 19) { + error(localize("Work offset is out of range.")); + return; + } + probeWorkOffsetCode = workOffset; + writeBlock("Position " + probeWorkOffsetCode + ", 3;"); + } + forceXYZ(); + } +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(_x, _y, _z) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock(gMotionModal.format(1), xyz + ", 0, 0;"); + forceFeed(); + } +} + +function onLinear(_x, _y, _z, feed) { + var xyz = xOutput.format(_x) + ", " + yOutput.format(_y) + ", " + zOutput.format(_z); + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + if (xyz) { + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + writeBlock(translate("Tcomp") + " 1," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + case RADIUS_COMPENSATION_RIGHT: + writeBlock(translate("Tcomp") + " 2," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + break; + default: + writeBlock(translate("Tcomp") + " 0," + " 0, 0, 1, 1;"); + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else { + writeBlock(gMotionModal.format(0), xyz + ", 0, 0;"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(gMotionModal.format(0), f); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + if (currentSection.isOptimizedForMachine() && (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis")))) { + // non TCP + writeBlock(translate("Submacro") + " Transformpath 0, 1, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", 0;"); + } else { + forceXYZ(); + writeBlock("Axyzabc 1, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + forceFeed(); +} + +var currentFMode; + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = (machineConfiguration.isMachineCoordinate(0) ? aOutput.format(_a) : "a6p"); + var b = (machineConfiguration.isMachineCoordinate(1) ? bOutput.format(_b) : "b6p"); + var c = (machineConfiguration.isMachineCoordinate(2) ? cOutput.format(_c) : "c6p"); + + // get feed rate number + if (useInverseTimeFeed) { + var f = {frn:0, fmode:0}; + if (a || b || c) { + f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed); + if (useInverseTimeFeed) { + f.frn = inverseTimeOutput.format(f.frn); + } else { + f.frn = feedOutput.format(f.frn); + } + } else { + f.frn = feedOutput.format(feed); + f.fmode = 94; + } + } + + if (x || y || z || a || b || c) { + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + } else { + writeBlock(getFeed(feed)); + } + writeBlock(translate("Submacro") + " Transformpath 0, 0, 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ", " + (useInverseTimeFeed ? f.frn : 0) + ";"); + } else { + if (useInverseTimeFeed) { + if (currentFMode != f.fmode) { + directWriteToCNC("G" + f.fmode); + currentFMode = f.fmode; + } + writeBlock(translate("Feed") + " " + f.frn + (Array(4).join(", " + f.frn)) + ";"); + } else { + writeBlock(getFeed(feed)); + } + writeBlock("Axyzabc 0, " + x + ", " + y + ", " + z + ", " + a + ", " + b + ", " + c + ";"); + } + } else if (f) { + if (getNextRecord().isMotion()) { // try not to output feed without motion + forceFeed(); // force feed on next line + } else { + writeBlock(getFeed(feed)); + } + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + if (isHelical() || (getCircularPlane() != PLANE_XY)) { + var t = tolerance; + if (hasParameter("operation:tolerance")) { + t = getParameter("operation:tolerance"); + } + linearize(t); + return; + } + var f = getFeed(feed); + var start = getCurrentPosition(); + var startAngle = Math.atan2(start.y - cy, start.x - cx); + var endAngle = Math.atan2(y - cy, x - cx); + + if (f) { + writeBlock(f); + } + + writeln( + translate("Circle") + " " + + xyzFormat.format(2 * getCircularRadius()) + ", " + + "0, " + // hs + "0, " + // hl + (clockwise ? -360 : 0) + ", " + + angleFormat.format(startAngle) + ", " + // begin angle + angleFormat.format(endAngle) + ", " + // end angle + "0, " + // do not connect start/end + "0, " + // center + "2, " + // fk + "1, " + // yf + xyzFormat.format(getHelicalPitch()) + ";" // zb + ); +} + +function translate(text) { + switch (getProperty("language")) { + case "en": + return text; + case "de": + switch (text) { + case "Dwell": + return "Verweile"; + case "Coolant": + return "Sprueh"; + case "Condition": + return "Bedingung"; + case "Submacro": + return "Submakro"; + case "Dynamics": + return "Dynamik"; + case "Contour_smoothing": + return "Konturglaettung"; + case "Label": + return "Markierung"; + case "Tcomp": + return "Fkomp"; + case "Message": + return "Melde"; + case "Feed": + return "Vorschub"; + case "Rpm": + return "Drehzahl"; + case "Number of tools in use": + return "Anzahl der benutzten Werkzeuge"; + case "Tool": + return "Werkzeug"; + case "Drill": + return "Bohren"; + case "Circle": + return "Kreis"; + case "Thread": + return "Gewinde"; + case "Setzp": + return "Setrel"; + case "Workpiece dimensions": + return "Abmessungen Werkstueck"; + case "Zeromem": + return "Relsp"; + case "Description": + return "Beschreibung"; + case "Part size": + return "Groesse"; + case "Zheight": + return "Zhmess"; + case "Rotation": + return "Drehung"; + case "\r\n________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| 4/5 axis operations detected. |" + + "\r\n| You have to enable the property |" + + "\r\n| got4thAxis or got5Axis, |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 Axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|_______________________________________|\r\n": + return "\r\n________________________________________" + + "\r\n| Fehler |" + + "\r\n| |" + + "\r\n| 4/5 Achs Operationen gefunden. |" + + "\r\n| Sie muessen die Property |" + + "\r\n| got4thAxis bzw. got5thAxis aktivieren, |" + + "\r\n| andernfalls koennen Sie lediglich |" + + "\r\n| 3 Achsen Programme erzeugen. |" + + "\r\n| Besteht das Problem weiterhin, |" + + "\r\n| wenden Sie sich bitte an www.datron.de |" + + "\r\n|________________________________________|\r\n"; + } + break; // end of German + } + return text; // use English +} + +var currentCoolantMode = COOLANT_OFF; +var coolantOff = undefined; + +function setCoolant(coolant) { + var coolantCodes = getCoolantCodes(coolant); + if (Array.isArray(coolantCodes)) { + for (var c in coolantCodes) { + writeBlock(translate("Coolant") + " 4, 0" + ", " + coolantCodes[c] + ", 0;"); // coolant off + } + return undefined; + } + return coolantCodes; +} + +function getCoolantCodes(coolant) { + var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line + if ((getProperty("useCoolant") != undefined) && !getProperty("useCoolant")) { + return undefined; + } + if (!coolants) { + error(localize("Coolants have not been defined.")); + } + if (tool.type == TOOL_PROBE) { // avoid coolant output for probing + coolant = COOLANT_OFF; + } + if (coolant == currentCoolantMode) { + return undefined; // coolant is already active + } + if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && (coolantOff != undefined)) { + if (Array.isArray(coolantOff)) { + for (var i in coolantOff) { + multipleCoolantBlocks.push(coolantOff[i]); + } + } else { + multipleCoolantBlocks.push(coolantOff); + } + } + + var m; + var coolantCodes = {}; + for (var c in coolants) { // find required coolant codes into the coolants array + if (coolants[c].id == coolant) { + coolantCodes.on = coolants[c].on; + if (coolants[c].off != undefined) { + coolantCodes.off = coolants[c].off; + break; + } else { + for (var i in coolants) { + if (coolants[i].id == COOLANT_OFF) { + coolantCodes.off = coolants[i].off; + break; + } + } + } + } + } + if (coolant == COOLANT_OFF) { + m = !coolantOff ? coolantCodes.off : coolantOff; // use the default coolant off command when an 'off' value is not specified + } else { + coolantOff = coolantCodes.off; + m = coolantCodes.on; + } + + if (!m) { + onUnsupportedCoolant(coolant); + m = 9; + } else { + if (Array.isArray(m)) { + for (var i in m) { + multipleCoolantBlocks.push(m[i]); + } + } else { + multipleCoolantBlocks.push(m); + } + currentCoolantMode = coolant; + return multipleCoolantBlocks; // return the single formatted coolant value + } + return undefined; +} + +var mapCommand = { +}; + +function onCommand(command) { + switch (command) { + case COMMAND_COOLANT_OFF: + setCoolant(COOLANT_OFF); + return; + case COMMAND_COOLANT_ON: + return; + case COMMAND_STOP: + return; + case COMMAND_OPTIONAL_STOP: + return; + case COMMAND_START_SPINDLE: + return; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + return; + case COMMAND_STOP_CHIP_TRANSPORT: + return; + case COMMAND_BREAK_CONTROL: + return; + case COMMAND_TOOL_MEASURE: + return; + } + + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onSectionEnd() { + if (currentSection.isMultiAxis() && (currentSection.getOptimizedTCPMode() == 0)) { + writeBlock("rtcp 0;"); + } + if (useInverseTimeFeed && currentSection.isMultiAxis()) { + directWriteToCNC("G" + 94); + currentFMode = 94; + } + // the code below gets the machine angles from previous operation. closestABC must also be set to true + if (currentSection.isMultiAxis() && currentSection.isOptimizedForMachine()) { + currentMachineABC = currentSection.getFinalToolAxisABC(); + } + if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || + (tool.number != getNextSection().getTool().number)) { + onCommand(COMMAND_BREAK_CONTROL); + } + if (isProbeOperation(currentSection)) { + writeBlock(translate("Rpm") + " 1, 30, 0, 30;"); + } + if (!isLastSection() && getProperty("showOperationDialog") != "disabled") { + writeBlock("$Message = \"Start next Operation\";"); + writeBlock(translate("Condition") + " optional_stop, 0, 1, 0, 9999;"); + writeBlock(translate("Message") + " $Message, 0, 0, 0;"); + writeBlock("$Message = \"OK\";"); + } + if (isProbeOperation(currentSection) && (hasNextSection() && !isProbeOperation(getNextSection()))) { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + writeBlock(") " + formatVariable("Sm_" + formatVariable(getOperationDescription(currentSection))) + ";"); + forceAny(); +} + +/** Output block to do safe retract and/or move to home position. */ +function writeRetract() { + if (arguments.length == 0) { + error(localize("No axis specified for writeRetract().")); + return; + } + var words = []; // store all retracted axes in an array + for (var i = 0; i < arguments.length; ++i) { + let instances = 0; // checks for duplicate retract calls + for (var j = 0; j < arguments.length; ++j) { + if (arguments[i] == arguments[j]) { + ++instances; + } + } + if (instances > 1) { // error if there are multiple retract calls for the same axis + error(localize("Cannot retract the same axis twice in one line")); + return; + } + switch (arguments[i]) { + case X: + words.push("X" + xyzFormat.format(machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : 0)); + break; + case Y: + words.push("Y" + xyzFormat.format(machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : 0)); + break; + case Z: + writeBlock(translate("Submacro") + " Retractzmax;"); + retracted = true; // specifies that the tool has been retracted to the safe plane + zOutput.reset(); + break; + default: + error(localize("Bad axis specified for writeRetract().")); + return; + } + } + if (words.length > 0) { + if (getProperty("useParkPosition")) { + writeBlock("Park;"); + } + } +} + +function onClose() { + writeln(""); + + if (getProperty("writeVersion")) { + if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { + writeComment(localize("post version") + ": " + getHeaderVersion()); + } + if ((typeof getHeaderDate == "function") && getHeaderDate()) { + writeComment(localize("post modified") + ": " + getHeaderDate()); + } + } + + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + writeComment("Please make sure that the language on your control is set to " + "\"" + getProperty("language") + "\""); + if (getProperty("writeMachine") && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + writeToolTable(); + writeWorkpiece(); + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + writeBlock(translate("Submacro") + " Initposition;"); + } + + // write jump to start operation + if (getProperty("showOperationDialog") == "dropdown") { + writeBlock(translate("Condition") + " 0, 0, 0 , startOperation, startOperation;"); + } + + writeMainProgram(); + writeComment("###############################################"); + // setCoolant(COOLANT_OFF); + + if (useRTCP && (getProperty("fourthAxis") && getProperty("fifthAxis"))) { + writeBlock(translate("Submacro") + " Endmacro;"); + } + + writeRetract(Z); + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + + if (isProbeOperation(currentSection)) { + writeBlock("T3d 0, 0, 1, 15, 17, 10, 10, 10, 10, 10, 10;"); // disable probe + } + + writeRetract(X, Y); +} + +function setProperty(property, value) { + properties[property].current = value; +} diff --git a/datron next inspect surface.cps b/datron next inspect surface.cps new file mode 100644 index 0000000..5de42f6 --- /dev/null +++ b/datron next inspect surface.cps @@ -0,0 +1,3373 @@ +/** + Copyright (C) 2012-2020 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} +*/ + +// >>>>> INCLUDED FROM generic_posts/datron next.cps +description = "DATRON next"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2022 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 45793; + +longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; + +extension = "simpl"; +setCodePage("utf-8"); + +capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = true; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only +probeMultipleFeatures = true; + +// user-defined properties +properties = { + writeMachine: { + title : "Write machine", + description: "Output the machine settings in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + writeDateAndTime: { + title : "Write date and time", + description: "Output date and time in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + showNotes: { + title : "Show notes", + description: "Writes operation notes as comments in the outputted code.", + group : "formats", + type : "boolean", + value : false, + scope : "post" + }, + useSmoothing: { + title : "Use smoothing", + description: "Specifies that smoothing mode should be used.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useDynamic: { + title : "Dynamic mode", + description: "Specifies that dynamic mode should be used.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + machineModel: { + title : "Machine type", + description: "Specifies the DATRON machine type.", + group : "configuration", + type : "enum", + values : [ + {title:"NEO", id:"NEO"}, + {title:"MX Cube", id:"MX"}, + {title:"Cube", id:"Cube"} + ], + value: "NEO", + scope: "post" + }, + useParkPosition: { + title : "Park at end of program", + description: "Enable to use the park position at end of program.", + group : "homePositions", + type : "boolean", + value : true, + scope : "post" + }, + writeToolTable: { + title : "Write tool table", + description: "Write a tool table containing geometric tool information.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + useSequences: { + title : "Use sequences", + description: "If enabled, sequences are used in the output format on large files.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useExternalSequencesFiles: { + title : "Use external sequence files", + description: "If enabled, an external sequence file is created for each operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useCoolant: { + title : "Write coolant commands", + description: "Enable/disable coolant code outputs for the entire program.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useParametricFeed: { + title : "Parametric feed", + description: "Specifies that parametric feedrates should be used.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + waitAfterOperation: { + title : "Wait after operation", + description: "If enabled, an optional stop will get generated to pause after each operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + rotaryAxisSetup: { + title : "Rotary axis setup", + description: "Specifies the rotary axis setup.", + group : "configuration", + type : "enum", + values : [ + {title:"No rotary axis", id:"NONE"}, + {title:"4th axis along X+", id:"4X"}, + {title:"DST (5 axis)", id:"DST"} + ], + value: "NONE", + scope: "post" + }, + useSuction: { + title : "Use Suction", + description: "Enable the suction for every operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + createThreadChamfer: { + title : "Create a Thread Chamfer", + description: "Create a chamfer with the thread milling tool", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + preloadTool: { + title : "Preload tool", + description: "Preload the next Tool in the DATRON Tool assist.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useZAxisOffset: { + title : "Output Z Offset command", + description: "This creates a command to allow a manual Z offset for each operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useTCP: { + title : "Use RTCP", + description: "Use the NEXT 5axis setup correction.", + group : "multiAxis", + type : "boolean", + value : false, + scope : "post" + } +}; + +// wcs definiton +wcsDefinitions = { + useZeroOffset: true, + wcs : [ + {name:"Zero Offset", format:"", range:[0, 0]}, + {name:"Standard", format:"LoadWcs name=\"#\"", range:[1, 999]} + ] +}; + +var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); +var toolFormat = createFormat({decimals:0}); +var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); +var rpmFormat = createFormat({decimals:0, scale:1}); +var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); + +var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); +var feedOutput = createVariable({prefix:""}, feedFormat); + +var xOutput = createVariable({prefix:" X="}, xyzFormat); +var yOutput = createVariable({prefix:" Y="}, xyzFormat); +var zOutput = createVariable({prefix:" Z="}, xyzFormat); +var aOutput = createVariable({prefix:" A="}, abcFormat); +var bOutput = createVariable({prefix:" B="}, abcFormat); +var cOutput = createVariable({prefix:" C="}, abcFormat); + +var iOutput = createVariable({prefix:" dX=", force:true}, xyzFormat); +var jOutput = createVariable({prefix:" dY=", force:true}, xyzFormat); +var kOutput = createVariable({prefix:" dZ="}, xyzFormat); + +// fixed settings +var useDatronFeedCommand = false; // unsupported for now, keep false +var spacingDepth = 0; +var spacingString = " "; +var spacing = "##########################################################"; +var currentWorkOffset; +var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported + +// buffer for building up a program not serial created +var sequenceBuffer = new StringBuffer(); + +function NewOperation(operationCall) { + this.operationCall = operationCall; + this.operationProgram = new StringBuffer(); + this.operationProgram.append(""); +} +var currentOperation; +function NewSimPLProgram() { + this.moduleName = new StringBuffer(); + this.measuringSystem = "Metric"; + this.toolDescriptionList = new Array(); + this.workpieceGeometry = ""; + this.sequenceList = new Array(); + this.usingList = new Array(); + this.externalUsermodules = new Array(); + this.globalVariableList = new Array(); + this.mainProgram = new StringBuffer(); + this.operationList = new Array(); +} + +var SimPLProgram = new NewSimPLProgram(); + +// collected state +var currentFeedValue = -1; +var optionalSection = false; +var activeMovements; // do not use by default +var currentFeedId; +var multiAxisCommandsEnabled = false; + +var TCP_OFF = 0; +var TCP_ON = 1; + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +function getSequenceName(section) { + var sequenceName = ""; + if (getProperty("useExternalSequencesFiles")) { + sequenceName += getProgramFilename(); + } + sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); + return sequenceName; +} + +function getProgramFilename() { + var outputPath = getOutputPath(); + var programFilename = FileSystem.getFilename(outputPath.substr(0, outputPath.lastIndexOf("."))) + "_"; + return programFilename; +} + +function getOperationName(section) { + return "Operation_" + getOperationDescription(section); +} + +function capitalizeFirstLetter(text) { + return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); +} + +function getSpacing() { + var space = ""; + for (var i = 0; i < spacingDepth; i++) { + space += spacingString; + } + return space; +} + +/** + Redirect the output to an infinite number of buffers +*/ +var writeRedirectionStack = new Array(); + +function setWriteRedirection(redirectionBuffer) { + writeRedirectionStack.push(redirectionBuffer); +} + +function resetWriteRedirection() { + writeRedirectionStack.pop(); +} + +/** + Writes the specified block. +*/ +function writeBlock() { + var text = getSpacing() + formatWords(arguments); + if (writeRedirectionStack.length == 0) { + writeWords(text); + } else { + writeRedirectionStack[writeRedirectionStack.length - 1].append(text + EOL); + } +} + +/** + Output a comment. +*/ +function writeComment(text) { + if (text) { + text = getSpacing() + "# " + text; + if (writeRedirectionStack.length == 0) { + writeln(text); + } else { + writeRedirectionStack[writeRedirectionStack.length - 1].append(text + EOL); + } + } +} + +var charMap = { + "\u00c4": "Ae", + "\u00e4": "ae", + "\u00dc": "Ue", + "\u00fc": "ue", + "\u00d6": "Oe", + "\u00f6": "oe", + "\u00df": "ss", + "\u002d": "_", + "\u0020": "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + text = formatVariable(text); + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); +} + +// Start of machine configuration logic +var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads +var useMultiAxisFeatures = false; // enable to use control enabled tilted plane, can be overridden with a property +var useABCPrepositioning = false; // enable to preposition rotary axes prior to tilted plane output, can be overridden with a property +var forceMultiAxisIndexing = false; // force multi-axis indexing for 3D programs +var eulerConvention = EULER_ZXZ_R; // euler angle convention for 3+2 operations + +// internal variables, do not change +var receivedMachineConfiguration; +var operationSupportsTCP; +var multiAxisFeedrate; + +/** + Activates the machine configuration (both from CAM and hardcoded) +*/ +function activateMachine() { + // disable unsupported rotary axes output + if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined")) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined")) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined")) { + cOutput.disable(); + } + + // setup usage of multiAxisFeatures + useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") : + (typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false); + useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") : + (typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false); + + // don't need to modify any settings if 3-axis machine + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; + } + + if (false) { // set to false to disable the warning message below + var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; + for (var i in axes) { + if (machineConfiguration.isTableConfiguration() && axes[i].isEnabled() && axes[i].getOffset().isNonZero() && !axes[i].isTCPEnabled()) { + warning(localize("A rotary axis offset is defined in the machine configuration on a non-TCP machine which will influence the NC output." + EOL + + "The setup origin should be defined appropriately, probably at the table center, and not at the center of the rotary axes.")); + break; + } + } + } + + // save multi-axis feedrate settings from machine configuration + var mode = machineConfiguration.getMultiAxisFeedrateMode(); + var type = mode == FEED_INVERSE_TIME ? machineConfiguration.getMultiAxisFeedrateInverseTimeUnits() : + (mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateDPMType() : DPM_STANDARD); + multiAxisFeedrate = { + mode : mode, + maximum : machineConfiguration.getMultiAxisFeedrateMaximum(), + type : type, + tolerance: mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateOutputTolerance() : 0, + bpwRatio : mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateBpwRatio() : 1 + }; + + // setup of retract/reconfigure TAG: Only needed until post kernel supports these machine config settings + if (receivedMachineConfiguration && machineConfiguration.performRewinds()) { + safeRetractDistance = machineConfiguration.getSafeRetractDistance(); + safePlungeFeed = machineConfiguration.getSafePlungeFeedrate(); + safeRetractFeed = machineConfiguration.getSafeRetractFeedrate(); + } + if (typeof safeRetractDistance == "number" && getProperty("safeRetractDistance") != undefined && getProperty("safeRetractDistance") != 0) { + safeRetractDistance = getProperty("safeRetractDistance"); + } + + // setup for head configurations + if (machineConfiguration.isHeadConfiguration()) { + compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength; + } + + // calculate the ABC angles and adjust the points for multi-axis operations + // rotary heads may require the tool length be added to the pivot length + // so we need to optimize each section individually + if (machineConfiguration.isHeadConfiguration() && compensateToolLength) { + for (var i = 0; i < getNumberOfSections(); ++i) { + var section = getSection(i); + if (section.isMultiAxis()) { + machineConfiguration.setToolLength(getBodyLength(section.getTool())); // define the tool length for head adjustments + section.optimizeMachineAnglesByMachine(machineConfiguration, OPTIMIZE_AXIS); + } + } + } else { // tables and rotary heads with TCP support can be optimized with a single call + optimizeMachineAngles2(OPTIMIZE_AXIS); + } +} + +function getBodyLength(tool) { + for (var i = 0; i < getNumberOfSections(); ++i) { + var section = getSection(i); + if (tool.number == section.getTool().number) { + return section.getParameter("operation:tool_overallLength", tool.bodyLength + tool.holderLength); + } + } + return tool.bodyLength + tool.holderLength; +} + +/** + Defines a hardcoded machine configuration +*/ +function defineMachine() { + var useTCP = getProperty("useTCP"); + if (getProperty("rotaryAxisSetup") != "NONE") { + if (receivedMachineConfiguration && machineConfiguration.isMultiAxisConfiguration()) { + error(localize("You can only select either a machine in the CAM setup or use the properties to define your kinematics.")); + return; + } + if (getProperty("rotaryAxisSetup") == "4X") { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0, tcp:false}); + machineConfiguration = new MachineConfiguration(aAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEO with A Axis"); + machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); + } else if (getProperty("rotaryAxisSetup") == "DST") { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0, tcp:useTCP}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0, tcp:useTCP}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEXT with DST"); + machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); + } + setMachineConfiguration(machineConfiguration); + if (receivedMachineConfiguration) { + warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); + receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten + } + } else { + if (false) { // note: setup your machine here + var aAxis = createAxis({coordinate:X, table:true, axis:[1, 0, 0], offset:[0, 0, 0], range:[-120, 30], cyclic:false, preference:-1, tcp:useTCP}); + var cAxis = createAxis({coordinate:Z, table:true, axis:[0, 0, 1], offset:[0, 0, 0], cyclic:true, reset:0, tcp:useTCP}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + + setMachineConfiguration(machineConfiguration); + if (receivedMachineConfiguration) { + warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); + receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten + } + } + } + + if (!receivedMachineConfiguration) { + // multiaxis settings + if (machineConfiguration.isHeadConfiguration()) { + machineConfiguration.setVirtualTooltip(false); // translate the pivot point to the virtual tool tip for nonTCP rotary heads + } + + // retract / reconfigure + var performRewinds = true; // set to true to enable the retract/reconfigure logic + if (performRewinds) { + machineConfiguration.enableMachineRewinds(); // enables the retract/reconfigure logic + safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock, can be overridden with a property + safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate + safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate + machineConfiguration.setSafeRetractDistance(safeRetractDistance); + machineConfiguration.setSafeRetractFeedrate(safeRetractFeed); + machineConfiguration.setSafePlungeFeedrate(safePlungeFeed); + var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values + machineConfiguration.setRewindStockExpansion(stockExpansion); + } + + // multi-axis feedrates + if (machineConfiguration.isMultiAxisConfiguration()) { + var useDPMFeeds = false; + machineConfiguration.setMultiAxisFeedrate( + // useTCP ? FEED_FPM : useDPMFeeds ? FEED_DPM : FEED_INVERSE_TIME, + FEED_FPM, // only FPM feedrate is supported + useDPMFeeds ? 9999.99 : 99999.99, // maximum output value for inverse time feed rates + useDPMFeeds ? DPM_COMBINATION : INVERSE_MINUTES, // INVERSE_MINUTES/INVERSE_SECONDS or DPM_COMBINATION/DPM_STANDARD + 0.5, // tolerance to determine when the DPM feed has changed + (unit == MM) ? 1.0 : 0.1 // ratio of rotary accuracy to linear accuracy for DPM calculations + ); + setMachineConfiguration(machineConfiguration); + } + } +} +// End of machine configuration logic + +function onOpen() { + // define and enable machine configuration + receivedMachineConfiguration = machineConfiguration.isReceived(); + if (typeof defineMachine == "function") { + defineMachine(); // hardcoded machine configuration + } + activateMachine(); // enable the machine optimizations and settings + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + // header + writeProgramHeader(); + spacingDepth -= 1; + resetWriteRedirection(); + + // surface inspection + if (typeof inspectionWriteVariables == "function") { + inspectionWriteVariables(); + } +} + +function getOperationDescription(section) { + // creates the name of the operation + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +function createToolVariables() { + var tools = getToolTable(); + var toolVariables = new Array(); + if (tools.getNumberOfTools() > 0 && !getProperty("writeToolTable")) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + toolVariables.push(toolOutput.format(tool.number) + ":number"); + } + } + return toolVariables; +} + +function createToolDescriptionTable() { + if (!getProperty("writeToolTable")) { + return; + } + var toolDescriptionArray = new Array(); + var toolNameList = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var tool = section.getTool(); + if (tool.type != TOOL_PROBE) { + var toolName = createToolName(tool); + var toolProgrammed = createToolDescription(tool); + if (toolNameList.indexOf(toolName) == -1) { + toolNameList.push(toolName); + toolDescriptionArray.push(toolProgrammed); + } + } + } + + SimPLProgram.toolDescriptionList = toolDescriptionArray; +} + +function createToolDescription(tool) { + var toolProgrammed = "@ ToolDescription : " + + "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + + "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + + "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + + "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + + "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + + "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + + "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + + "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + + "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + + "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + + "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + + "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + + "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + + "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + + "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + + " @"; + return toolProgrammed; +} + +/** + Generate the logical tool name for the assignment table of used tools. +*/ +function createToolName(tool) { + var toolName = toolFormat.format(tool.number); + toolName += "_" + translateToolType(tool.type); + if (tool.comment) { + toolName += "_" + tool.comment; + } + if (tool.diameter) { + toolName += "_D" + dimensionFormat.format(tool.diameter); + } + var description = tool.getDescription(); + if (description) { + toolName += "_" + description; + } + toolName = formatVariable(toolName); + return toolName; +} + +/** + Translate HSM tools to Datron tool categories. +*/ +function translateToolType(toolType) { + + var datronCategoryName = ""; + + toolCategory = toolType; + switch (toolType) { + case TOOL_UNSPECIFIED: + datronCategoryName = "Unspecified"; + break; + case TOOL_DRILL: + datronCategoryName = "Drill"; + break; + case TOOL_DRILL_CENTER: + datronCategoryName = "DrillCenter"; + break; + case TOOL_DRILL_SPOT: + datronCategoryName = "DrillSpot"; + break; + case TOOL_DRILL_BLOCK: + datronCategoryName = "DrillBlock"; + break; + case TOOL_MILLING_END_FLAT: + datronCategoryName = "MillingEndFlat"; + break; + case TOOL_MILLING_END_BALL: + datronCategoryName = "MillingEndBall"; + break; + case TOOL_MILLING_END_BULLNOSE: + datronCategoryName = "MillingEndBullnose"; + break; + case TOOL_MILLING_CHAMFER: + datronCategoryName = "Graver"; + break; + case TOOL_MILLING_FACE: + datronCategoryName = "MillingFace"; + break; + case TOOL_MILLING_SLOT: + datronCategoryName = "MillingSlot"; + break; + case TOOL_MILLING_RADIUS: + datronCategoryName = "MillingRadius"; + break; + case TOOL_MILLING_DOVETAIL: + datronCategoryName = "MillingDovetail"; + break; + case TOOL_MILLING_TAPERED: + datronCategoryName = "MillingTapered"; + break; + case TOOL_MILLING_LOLLIPOP: + datronCategoryName = "MillingLollipop"; + break; + case TOOL_TAP_RIGHT_HAND: + datronCategoryName = "TapRightHand"; + break; + case TOOL_TAP_LEFT_HAND: + datronCategoryName = "TapLeftHand"; + break; + case TOOL_REAMER: + datronCategoryName = "Reamer"; + break; + case TOOL_BORING_BAR: + datronCategoryName = "BoringBar"; + break; + case TOOL_COUNTER_BORE: + datronCategoryName = "CounterBore"; + break; + case TOOL_COUNTER_SINK: + datronCategoryName = "CounterSink"; + break; + case TOOL_HOLDER_ONLY: + datronCategoryName = "HolderOnly"; + break; + case TOOL_PROBE: + datronCategoryName = "XYZSensor"; + break; + default: + datronCategoryName = "Unspecified"; + } + return datronCategoryName; +} + +function writeProgramHeader() { + // write creation Date + setWriteRedirection(SimPLProgram.moduleName); + if (getProperty("writeDateAndTime")) { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + writeComment("!File ; generated at " + date + " - " + time); + } else { + writeComment("!File ;"); + } + + if (programComment) { + writeComment(formatComment(programComment)); + } + + writeBlock(" "); + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (getProperty("writeMachine") && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + writeBlock("module " + "CamGeneratedModule"); + writeBlock(" "); + + writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); + resetWriteRedirection(); + + // set the table of used tools in the header of the program + createToolDescriptionTable(); + + // set the workpiece information + SimPLProgram.workpieceGeometry = writeWorkpiece(); + + // set the sequence header in the program file + if (getProperty("useSequences")) { + var sequences = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (!isProbeOperation(section)) { + sequences.push("sequence " + getSequenceName(section)); + } + } + if (getProperty("useExternalSequencesFiles")) { + writeBlock("@ EmbeddedSequences = false @"); + } + + SimPLProgram.sequenceList = sequences; + } + + // set usings + SimPLProgram.usingList.push("using Base"); + if (getProperty("waitAfterOperation")) { + SimPLProgram.usingList.push("import System"); + } + + if (typeof inspectionCycleInspect == "function") { + addInspectionReferences(); + } + + // set paramtric feed variables + for (var i = 0; i < getNumberOfSections(); ++i) { + var section = getSection(i); + if (getProperty("useParametricFeed") && (!useDatronFeedCommand)) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (SimPLProgram.globalVariableList.indexOf(feedDescription + ":number") == -1) { + SimPLProgram.globalVariableList.push(feedDescription + ":number"); + } + } + } + } + + setWriteRedirection(SimPLProgram.mainProgram); + writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + spacingDepth += 1; + writeBlock("Absolute"); + + // set the parameter tool table + SimPLProgram.globalVariableList.push(createToolVariables()); + + // write the parameter tool table + if (!getProperty("writeToolTable")) { + var tools = getToolTable(); + writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + dimensionFormat.format(tool.diameter) + " " + + "L2:" + dimensionFormat.format(tool.fluteLength) + " " + + "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + + "ProductID:" + formatComment(tool.productId); + writeBlock(toolAsigment); + } + writeBlock(" "); + } + } + resetWriteRedirection(); +} + +function writeWorkpiece() { + var workpieceString = new StringBuffer(); + setWriteRedirection(workpieceString); + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("# Workpiece dimensions"); + writeBlock( + "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z)); + writeBlock( + "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z)); + writeBlock( + "# Part size X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z)); + + writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + + "\"" + "MaxEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + + " @"); + resetWriteRedirection(); + return workpieceString; +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, datronFeedName, feed) { + this.id = id; + this.description = description; + this.datronFeedName = datronFeedName; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + if (useDatronFeedCommand) { + return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); + } else { + return ("Feed=" + formatVariable(feedContext.description)); + } + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return "Feed=" + feedFormat.format(f); + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + addFeedContext(feedContext, activeFeeds); + } + ++id; + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + + // this part allows us to use feedContext also for the cycles + if (hasParameter("operation:cycleType")) { + var cycleType = getParameter("operation:cycleType"); + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + + switch (cycleType) { + case "thread-milling": + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + case "bore-milling": + if (section.hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (section.hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + } + } + + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +/** Check that all elements are only one time in the result list. */ +function addFeedContext(feedContext, activeFeeds) { + if (activeFeeds.indexOf(feedContext) == -1) { + activeFeeds.push(feedContext); + } +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function setWorkPlane(abc) { + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + if (isInspectionOperation(currentSection) && !is3D()) { + error(localize("Multi axis Inspect surface is not supported.")); + return; + } + forceWorkPlane(); // always need the new workPlane + forceABC(); + + writeBlock("MoveToSafetyPosition"); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + + setCurrentABC(abc); // required for machine simulation + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function setTCPMode(mode) { + if (getProperty("useTCP") || operationSupportsTCP) { + writeBlock(mode == TCP_ON ? "Rtcp On" : "Rtcp Off"); + } +} + +function onSection() { + currentOperation = new NewOperation(getOperationName(currentSection)); + setWriteRedirection(currentOperation.operationProgram); + + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + if (!isProbeOperation(currentSection)) { + writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); + } + + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + zRange.expandToRange(currentSection.getGlobalZRange()); + writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); + } + } + + // create sub program + writeBlock("program " + getOperationName(currentSection)); + spacingDepth += 1; + + if (passThrough) { + var joinString = EOL + getSpacing(); + var passThroughString = passThrough.join(joinString); + if (passThroughString != "") { + writeBlock(passThroughString); + } + passThrough = []; + } + + // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. + writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); + var operationTolerance = tolerance; + if (hasParameter("operation:tolerance")) { + operationTolerance = Math.max(getParameter("operation:tolerance"), 0); + } + + // wcs + currentWorkOffset = undefined; // force wcs output + if (currentSection.workOffset > 0) { + if (currentSection.workOffset != currentWorkOffset) { + writeBlock(currentSection.wcs); + currentWorkOffset = currentSection.workOffset; + } + } + + if (getProperty("useSmoothing") && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); + } else { + writeBlock("Smoothing Off"); + } + + if (getProperty("useDynamic")) { + var dynamic = 5; + operationName = getOperationName(currentSection).toUpperCase(); + dynamicIndex = operationName.lastIndexOf("DYN"); + explicitDynamic = parseInt(operationName.substring(dynamicIndex + 3, dynamicIndex + 4), 5); + if (!isNaN(explicitDynamic) && ((explicitDynamic > 0 && explicitDynamic < 6))) { + writeBlock("Dynamic = " + explicitDynamic + " # Created from operation name"); + dynamic = explicitDynamic; + } else { + // set machine type specific dynamic sets + switch (getProperty("machineModel")) { + case "NEO": + dynamic = 5; + break; + case "MX": + case "Cube": + if (operationTolerance <= toPreciseUnit(0.04, MM)) { + dynamic = 4; + } + if (operationTolerance <= toPreciseUnit(0.02, MM)) { + dynamic = 3; + } + if (operationTolerance <= toPreciseUnit(0.005, MM)) { + dynamic = 2; + } + if (operationTolerance <= toPreciseUnit(0.003, MM)) { + dynamic = 1; + } + break; + } + writeBlock("Dynamic = " + dynamic); + } + } + if (getProperty("waitAfterOperation")) { + showWaitDialog(getOperationName(currentSection)); + } + + if (machineConfiguration.isMultiAxisConfiguration()) { + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + writeBlock("MoveToSafetyPosition"); + forceABC(); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + } else { + forceWorkPlane(); + var abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { + // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + error("\r\n_________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| Tool orientation detected. |" + + "\r\n| You have to specify your kinematic |" + + "\r\n| by using property 'Rotary axis setup', |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|________________________________________|\r\n"); + return; + } + setRotation(remaining); + } + operationSupportsTCP = currentSection.getOptimizedTCPMode() == OPTIMIZE_NONE && currentSection.isMultiAxis(); + if (!currentSection.isMultiAxis() && (useMultiAxisFeatures || isSameDirection(machineConfiguration.getSpindleAxis(), currentSection.workPlane.forward))) { + operationSupportsTCP = false; + } + if (machineConfiguration.isMultiAxisConfiguration()) { + setTCPMode(TCP_ON); + if (!multiAxisCommandsEnabled) { + SimPLProgram.usingList.push("using Rtcp"); // always required when using -MultiAxisMode on/off- since MultiAxisMode is part of library Rtcp + setWriteRedirection(SimPLProgram.mainProgram); + writeBlock("MultiAxisMode On"); + resetWriteRedirection(); + multiAxisCommandsEnabled = true; + } + } + + forceAny(); + + if (getProperty("showNotes") && currentSection.hasParameter("notes")) { + var notes = currentSection.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + + var clearance = getFramePosition(currentSection.getInitialPosition()).z; + writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); + + // write the optional length offset for each operation + if (getProperty("useZAxisOffset")) { + writeBlock("ZAxisOffset = 0"); + } + + // radius compensation + var compensationType; + if (hasParameter("operation:compensationType")) { + compensationType = getParameter("operation:compensationType"); + } else { + compensationType = "computer"; + } + + var wearCompensation; + if (hasParameter("operation:compensationDeltaRadius")) { + wearCompensation = getParameter("operation:compensationDeltaRadius"); + } else { + wearCompensation = 0; + } + + if (true /*getProperty("writePathOffset")*/) { + switch (compensationType) { + case "computer": + break; + case "control": + writeBlock("PathOffset = 0"); + break; + case "wear": + case "inverseWear": + writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); + break; + } + } + + if (!isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + + // tool changer command + if (getProperty("writeToolTable")) { + writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } else { + writeBlock("Tool = " + toolOutput.format(tool.number) + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } + + // preload the next tool for the Datron tool assist + if (getProperty("preloadTool")) { + var nextTool = getNextTool(tool.number); + if (nextTool) { + if (getProperty("writeToolTable")) { + writeBlock("ProvideTool name=" + "\"" + createToolName(nextTool) + "\""); + } else { + writeBlock("ProvideTool = " + toolOutput.format(nextTool.number)); + } + } + } + + // set the current feed + // replace by the default feed command + if (getProperty("useParametricFeed") && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + if (useDatronFeedCommand) { + var datronFeedParameter = new Array(); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var datronFeedCommand = { + name: feedContext.datronFeedName, + feed: feedFormat.format(feedContext.feed) + }; +/*eslint-disable*/ + var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); + /*eslint-enable*/ + if (indexOfFeedContext == -1) { + datronFeedParameter.push(datronFeedCommand); + } else { + var existingFeedContext = datronFeedParameter[indexOfFeedContext]; + if (existingFeedContext.feed < datronFeedCommand.feed) { + existingFeedContext.feed = datronFeedCommand.feed; + } + } + } + var datronFeedCommand = "SetFeedTechnology"; + for (var i = 0; i < datronFeedParameter.length; i++) { + datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; + } + writeBlock(datronFeedCommand); + + } else { + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); + } + } + } + } + + // parameter for the sequences + var sequenceParamter = new Array(); + + if (hasParameter("operation:cycleType")) { + // reset all movements to suppress older entries... + activeMovements = new Array(); + var cycleType = getParameter("operation:cycleType"); + writeComment("Parameter " + cycleType + " cycle"); + var cycleFeedrate = currentSection.getParameter("feedrate"); + var cyclePlungeFeedrate = currentSection.getParameter("plungeFeedrate"); + var cycleRampingFeedrate = currentSection.getParameter("operation:tool_feedRamp"); + + switch (cycleType) { + case "thread-milling": + writeBlock("SetFeedTechnology ramp=" + feedFormat.format(cycleRampingFeedrate) + " finishing=" + feedFormat.format(cycleFeedrate)); + var diameter = currentSection.getParameter("diameter"); + var pitch = currentSection.getParameter("pitch"); + var finishing = currentSection.getParameter("stepover"); + + writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); + sequenceParamter.push("nominalDiameter=nominalDiameter"); + writeBlock("pitch=" + xyzFormat.format(pitch)); + sequenceParamter.push("pitch=pitch"); + if (xyzFormat.isSignificant(parseInt(finishing, 10))) { + writeBlock("finishing=" + xyzFormat.format(finishing)); + sequenceParamter.push("finishing=finishing"); + } else { + sequenceParamter.push("finishing=0"); + } + /* + writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); + sequenceParamter.push('threadName=threadName'); + writeBlock("threading = " + currentSection.getParameter("threading")); + sequenceParamter.push("threading=threading"); + + TAG: den Standard auch mit Imperial unterstuezten + sequenceParamter.push("threadStandard=ThreadStandards.Metric"); + sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); + sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); + sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); + writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); + sequenceParamter.push("direction=direction"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); +*/ + break; + case "bore-milling": + writeBlock("SetFeedTechnology roughing=" + feedFormat.format(cycleFeedrate) + " finishing=" + feedFormat.format(cycleFeedrate)); + writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); + sequenceParamter.push("diameter=diameter"); + + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); + sequenceParamter.push("infeedZ=infeedZ"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); + break; + case "drilling": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(cyclePlungeFeedrate)); + break; + case "chip-breaking": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(cyclePlungeFeedrate) + " roughing=" + feedFormat.format(cycleFeedrate)); + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); + sequenceParamter.push("infeedZ=infeedZ"); + break; + } + } + + if (getProperty("useSequences") && !isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + // call sequence + if (getProperty("useParametricFeed") && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + sequenceParamter.push(formatVariable(feedContext.description) + "=" + formatVariable(feedContext.description)); + } + } + var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); + writeBlock(currentSectionCall); + + // write sequence + var currentSequenceName = getSequenceName(currentSection); + if (getProperty("useExternalSequencesFiles")) { + spacingDepth -= 1; + var filename = getOutputPath(); + // sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; + sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; + sequenceFilePath += currentSequenceName + ".seq"; + redirectToFile(sequenceFilePath); + } else { + setWriteRedirection(sequenceBuffer); + writeBlock(" "); + // TAG: modify parameter + spacingDepth -= 1; + writeBlock("$$$ " + currentSequenceName); + } + } + + if (!isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); + } else { + writeBlock("Spindle Off"); + writeBlock("PrepareXyzSensor"); + } + + // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); + writeBlock("PrePositioning" + xyz); + + if (getProperty("useSuction")) { + writeBlock("Suction On"); + } + // surface Inspection + if (isInspectionOperation(currentSection) && (typeof inspectionProcessSectionStart == "function")) { + inspectionProcessSectionStart(); + } + +} + +function showWaitDialog(operationName) { + writeBlock("showWaitDialog operationName=\"" + operationName + "\""); +} + +function writeWaitProgram() { + var waitProgram = + ["# Show the wait dialog for the next operation", + "program showWaitDialog optional operationName:string", + " if not operationName hasvalue", + " operationName = " + "\"" + "\"", + " endif", + "", + " messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName", + " dialogRes = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel", + " if dialogRes == System::DialogResult.Cancel", + " exit", + " endif", + "endprogram" + ]; + waitProgramOperation = {operationProgram:waitProgram.join(EOL)}; + SimPLProgram.operationList.push(waitProgramOperation); +} + +function onDwell(seconds) { + writeBlock("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("Rapid" + xyz); + forceFeed(); + } +} + +function onPrePositioning(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("PrePositioning" + xyz); + forceFeed(); + } +} + +function onLinear(x, y, z, feed) { + if (isInspectionOperation(currentSection)) { + onExpandedRapid(x, y, z); + return; + } + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + var f = getFeed(feed); + + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > 99) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + var compensationType = undefined; + if (currentSection.hasParameter("operation:compensationType")) { + compensationType = currentSection.getParameter("operation:compensationType"); + } + + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + switch (compensationType) { + case "control": + writeBlock("ToolCompensation Left"); + writeBlock("PathCorrection Left"); + break; + case "wear": + case "inverseWear": + writeBlock("PathCorrection Left"); + break; + default: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + break; + case RADIUS_COMPENSATION_RIGHT: + switch (compensationType) { + case "control": + writeBlock("ToolCompensation Right"); + writeBlock("PathCorrection Right"); + break; + case "wear": + case "inverseWear": + writeBlock("PathCorrection Right"); + break; + default: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + break; + case RADIUS_COMPENSATION_OFF: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + } + + if (xyz) { + if (f) { + writeBlock(f); + } + writeBlock("Line" + xyz); + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + yOutput.format(y) + + zOutput.format(z) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + + forceABC(); + var xyzabc = x + y + z + a + b + c; + writeBlock("Rapid" + xyzabc); + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + var f = getFeed(feed); + + writeBlock(f); + if (x || y || z || a || b || c) { + var xyzabc = x + y + z + a + b + c; + writeBlock("Line" + xyzabc); + } +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (getProperty("useCoolant")) { + if (coolant == COOLANT_OFF) { + writeBlock("SpraySystem Off"); + currentCoolantMode = COOLANT_OFF; + return; + } + + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + writeBlock("SprayTechnology External"); + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR: + writeBlock("SprayTechnology External"); + writeBlock("Coolant Air"); + break; + case COOLANT_THROUGH_TOOL: + writeBlock("SprayTechnology Internal"); + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR_THROUGH_TOOL: + writeBlock("SprayTechnology Internal"); + writeBlock("Coolant Air"); + break; + + default: + onUnsupportedCoolant(coolant); + } + writeBlock("SpraySystem On"); + currentCoolantMode = coolant; + } +} + +/* +var isInsideProgramDeclaration = false; +var directNcOperation; +function parseManualNc(text) { // todo + var modulePattern = new RegExp(".*(using|import)"); + var isModuleImport = modulePattern.test(text); + if (isModuleImport) { + SimPLProgram.usingList.push(text); + return; + } + + var programPattern = /(?:\s*program\s+)(\w+)/; + var isProgramDeclaration = programPattern.test(text); + if (isProgramDeclaration) { + var subProgramName = programPattern.exec(text); + if (subProgramName == undefined) { + return; + } + directNcOperation = {operationCall:subProgramName[1], operationProgram: new StringBuffer()}; + SimPLProgram.operationList.push(directNcOperation); + isInsideProgramDeclaration = true; + } + + var isEndProgram = (/\s*endprogram/).test(text); + if (isEndProgram) { + isInsideProgramDeclaration = false; + directNcOperation.operationProgram.append(text + EOL); + return; + } + + if (isInsideProgramDeclaration) { + directNcOperation.operationProgram.append(text + EOL); + return; + } + return; +} +*/ + +function onManualNC(command, value) { + if (command == COMMAND_PASS_THROUGH) { + error(localize("Manual NC pass through is currently not supported.")); + return; + } + switch (command) { + // case COMMAND_PASS_THROUGH: + // value = parseManualNc(value); + // break; + case COMMAND_COMMENT: + value = "# " + value; + break; + case COMMAND_DWELL: + value = "Sleep seconds=" + value; + break; + case COMMAND_COOLANT_OFF: + value = "SpraySystem Off"; + break; + case COMMAND_COOLANT_ON: + value = "SpraySystem On"; + break; + case COMMAND_STOP: + value = "break"; + break; + case COMMAND_START_SPINDLE: + value = "Spindle On"; + break; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + value = "ChipConveyor On"; + break; + case COMMAND_STOP_CHIP_TRANSPORT: + value = "ChipConveyor Off"; + break; + case COMMAND_OPEN_DOOR: + value = "ReleaseDoor"; + break; + case COMMAND_CLOSE_DOOR: + return; + case COMMAND_CALIBRATE: + value = "# calibration currently not supported!"; + break; + case COMMAND_VERIFY: + value = "Dialog message=\"Please check workpiece!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_CLEAN: + value = "Dialog message=\"Please clean workpiece!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_ACTION: + value = "# Action currently not supported!"; + break; + case COMMAND_PRINT_MESSAGE: + // value = 'Dialog message="' + value + '" Ok Cancel caption="Cam generated dialog"' + SimPLProgram.usingList.push("using File"); + SimPLProgram.usingList.push("using DateTimeModule"); + var message = (" value=(GetNow + \"\t" + value + "\")"); + value = "FileWriteLine filename=\"" + getProgramFilename() + ".log\"" + message; + break; + case COMMAND_DISPLAY_MESSAGE: + value = "StatusMessage message=\"" + value + "\""; + break; + case COMMAND_ALARM: + value = "Dialog message=\"Alarm!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_ALERT: + value = "Dialog message=\"Warning!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_BREAK_CONTROL: + value = "MeasureToolLength"; + break; + case COMMAND_TOOL_MEASURE: + value = "MeasureToolLength"; + break; + case COMMAND_OPTIONAL_STOP: + value = "OptionalBreak"; + break; + case COMMAND_CALL_PROGRAM: + var subprogramName = "SubProgram_" + SimPLProgram.externalUsermodules.length; + SimPLProgram.externalUsermodules.push("usermodule " + subprogramName + "=\"" + value + "\""); + value = subprogramName; + break; + } + + if (value != undefined) { + var operation = {operationCall:value, operationProgram:""}; + SimPLProgram.operationList.push(operation); + } +} + +var mapCommand = {}; + +var passThrough = new Array(); +function onPassThrough(text) { + passThrough.push(text); +} + +function onCommand(command) { + switch (command) { + case COMMAND_PROBE_ON: + return; + case COMMAND_PROBE_OFF: + return; + } + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onCycle() { +} + +function onCycleEnd() { +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && ((section.getParameter("operation-strategy") == "probe" || section.getParameter("operation-strategy") == "probe_geometry")); +} + +function isInspectionOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "inspectSurface"); +} + +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "probe_geometry")) { + error(localize("Probe Geometry is not supported.")); + return; + } + if (cycleType == "inspect") { + if (typeof inspectionCycleInspect == "function") { + inspectionCycleInspect(cycle, x, y, z); + return; + } else { + cycleNotSupported(); + } + } + var feedString = feedOutput.format(cycle.feedrate); + var probeWCS = hasParameter("operation-strategy") && (getParameter("operation-strategy") == "probe"); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { + if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + } + forceXYZ(); + onPrePositioning(x, y, z); // TAG would be needed for probeMultipleFeatures, but generates duplicated Prepositioning output, acceptable? + var startPositionOffset = cycle.probeClearance + tool.cornerRadius; + } + + switch (cycleType) { + case "bore-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + boreMilling(cycle); + onExpandedRapid(x, y, cycle.clearance); + } + break; + case "thread-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + threadMilling(cycle); + onExpandedRapid(x, y, cycle.clearance); + } + break; + case "drilling": + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + drilling(cycle); + onExpandedRapid(x, y, cycle.clearance); + break; + /* + case "chip-breaking": + forceXYZ(); + onExpandedRapid(x, y, null); + onExpandedRapid(x, y, cycle.retract); + chipBreaking(cycle); + onExpandedRapid(x, y, cycle.clearance); + break; +*/ + + case "tapping": + case "left-tapping": + case "right-tapping": + case "tapping-with-chip-breaking": + case "left-tapping-with-chip-breaking": + case "right-tapping-with-chip-breaking": + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + tapping(cycle); + onExpandedRapid(x, y, cycle.clearance); + break; + case "probing-x": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + if (probeWCS) { + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionX=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + if (probeWCS) { + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionY=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-z": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); + + var measureString = "measResult = SurfaceMeasure "; + if (probeWCS) { + measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedZPos=" + xyzFormat.format(z - cycle.depth); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-wall": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-wall": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionY=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-channel": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-channel-with-island": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-channel": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionY=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-channel-with-island": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionY=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-circular-boss": + var measureString = "measResult = CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-circular-hole": + var measureString = "measResult = CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-circular-hole-with-island": + var measureString = "measResult = CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-rectangular-boss": + var measureString = "measResult = RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " Center"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1) + + " expectedDimensionY=" + xyzFormat.format(cycle.width2); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-rectangular-hole": + var measureString = "measResult = RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " Center"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1) + + " expectedDimensionY=" + xyzFormat.format(cycle.width2); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-rectangular-hole-with-island": + var measureString = "measResult = RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " Center"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1) + + " expectedDimensionY=" + xyzFormat.format(cycle.width2); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-inner-corner": + /* + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "measResult = EdgeMeasure "; + zOutput.reset(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + //zOutput.reset(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + */ + var isXNegative = (cycle.approach1 == "negative"); + var isYNegative = (cycle.approach2 == "negative"); + + var orientation = ""; + + if (isXNegative) { + orientation = isYNegative ? "FrontLeft" : "BackLeft"; + } else { + orientation = isYNegative ? "FrontRight" : "BackRight"; + } + + var measureString = "measResult = CornerMeasure"; + measureString += " " + orientation; + measureString += " Inside"; + measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " measureDirectionX=" + cycle.approach1 + + " measureDirectionY=" + cycle.approach2; + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-outer-corner": + /* + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var measureString = "measResult = EdgeMeasure "; + zOutput.reset(); + onExpandedRapid(x, y, probingDepth); + onExpandedLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onExpandedLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + //forceXYZ(); + //zOutput.reset(); + onExpandedLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onExpandedLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + */ + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onExpandedLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + + var isXNegative = (cycle.approach1 == "negative"); + var isYNegative = (cycle.approach2 == "negative"); + + var orientation = ""; + if (isXNegative) { + orientation = isYNegative ? "BackRight" : "FrontRight"; + } else { + orientation = isYNegative ? "BackLeft" : "FrontLeft"; + } + + var measureString = "measResult = CornerMeasure"; + measureString += " " + orientation; + measureString += " Outside"; + measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " measureDirectionX=" + cycle.approach1 + + " measureDirectionY=" + cycle.approach2; + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-plane-angle": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasureV2 "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " offsetForRotation=" + xyzFormat.format(cycle.probeSpacing); + measureString += " setRotationOnly=true"; + if (probeWCS) { + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionX=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-plane-angle": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasureV2 "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " offsetForRotation=" + xyzFormat.format(cycle.probeSpacing); + measureString += " setRotationOnly=true"; + if (probeWCS) { + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(x + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionY=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + default: + expandCyclePoint(x, y, z); + return; + } + + // save probing result in defined wcs + if (probeWCS && currentSection.workOffset !== undefined) { + writeBlock("SaveWcs name=\"" + currentSection.workOffset + "\""); + } + return; +} + +function getProbingArguments(cycle, probeWorkOffsetCode, additionalArguments) { + var toolToCompensate; + var tools = getToolTable(); + if (tools.getNumberOfTools()) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + if (tool.number == cycle.toolWearNumber) { + toolToCompensate = tool; + } + } + } + + return [ + "ProbeGeometry measResult=measResult", + (cycle.angleAskewAction == "stop-message" ? "angleTolerance=" + xyzFormat.format(cycle.toleranceAngle ? cycle.toleranceAngle : 0) : undefined), + ((cycle.updateToolWear && cycle.toolWearErrorCorrection < 100) ? "toolWearErrorCorrection=" + xyzFormat.format(cycle.toolWearErrorCorrection ? cycle.toolWearErrorCorrection / 100 : 100) : undefined), + (cycle.wrongSizeAction == "stop-message" ? "sizeTolerance=" + xyzFormat.format(cycle.toleranceSize ? cycle.toleranceSize : 0) : undefined), + (cycle.outOfPositionAction == "stop-message" ? "positionTolerance=" + xyzFormat.format(cycle.tolerancePosition ? cycle.tolerancePosition : 0) : undefined), + (cycle.updateToolWear ? "toolToUpdateWear=\"" + createToolName(toolToCompensate) + "\"" : undefined), + ((cycle.updateToolWear && cycleType == "probing-z") ? "Length" : undefined), + ((cycle.updateToolWear && cycleType !== "probing-z") ? "Diameter" : undefined), + (cycle.updateToolWear ? "toolUpdateTreshold=" + xyzFormat.format(cycle.toolWearUpdateThreshold ? cycle.toolWearUpdateThreshold : 0) : undefined), + (cycle.printResults ? "printResults" : undefined), + conditional(probeWorkOffsetCode && probeWCS, "S" + probeWorkOffsetCode), + additionalArguments + ]; +} + +function programIncludesOperationType(operationType) { + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (operationType == "probe") { + if (isProbeOperation(section)) { + return true; + } + } else if (operationType == "inspection") { + if (isInspectionOperation(section)) { + return true; + } + } else { + error(localize("Unsupported operation type.")); + } + } + return false; +} + +function writeProbingProgram() { + + addVariable("enumeration toolWearGeometry (Diameter, Length)"); + addVariable("enumeration direction (positive, negative)"); + + addModuleReference("import Math"); + addModuleReference("import ToolChangingUtilities"); + addModuleReference("import ToolParameter"); + addModuleReference("import ToolData"); + + // TAG add import Math + probingProgram = [ + "program ProbeGeometry(", + " measResult:MeasuringDataWithInfo", + " optional expectedDimensionX:number", + " optional expectedDimensionY:number", + " optional expectedXPos:number", + " optional expectedYPos:number", + " optional expectedZPos:number ", + " optional measureDirectionX:direction ", + " optional measureDirectionY:direction ", + " optional toolUpdateTreshold:number", + " optional toolWearErrorCorrection:number", + " optional positionTolerance:number ", + " optional angleTolerance:number", + " optional sizeTolerance:number", + " optional toolToUpdateWear:string", + " optional updateToolWear:toolWearGeometry", + " optional printResults:boolean)", + "", + " # Tolerance check", + " if sizeTolerance hasvalue ", + " outOfDimension:boolean", + " if expectedDimensionX hasvalue", + " outOfDimension = Math::Abs(expectedDimensionX - measResult.DimensionX) > sizeTolerance ", + " endif", + " if expectedDimensionY hasvalue", + " outOfDimension = Math::Abs(expectedDimensionY - measResult.DimensionY) > sizeTolerance ", + " endif", + " ", + " if outOfDimension", + " Dialog message=\"Geometrie out of tolerance\" caption=\"Geometrie out of tolerance\" Error", + " endif", + " endif", + " ", + " # Angle check", + " if angleTolerance hasvalue", + " if measResult.MeasuredTransformation.RotationZ > angleTolerance", + " Dialog message=\"Angle out of tolerance\" caption=\"Angle out of tolerance\" Error ", + " endif", + " endif", + " ", + " # Tool wear", + " if updateToolWear hasvalue and toolToUpdateWear hasvalue", + " if updateToolWear == toolWearGeometry.Diameter", + " # get the radius correction from dimension otherwise from position ", + " radiusCorrection:number", + " if (expectedDimensionX hasvalue or expectedDimensionY hasvalue)", + " if (expectedDimensionX hasvalue and expectedDimensionY hasvalue)", + " radiusCorrection = (", + " (expectedDimensionX - measResult.DimensionX) +", + " (expectedDimensionX - measResult.DimensionX)) / 4", + " endif", + " if (expectedDimensionX hasvalue and not expectedDimensionY hasvalue)", + " radiusCorrection = (expectedDimensionX - measResult.DimensionX) / 2", + " endif", + " if (not expectedDimensionX hasvalue and expectedDimensionY hasvalue)", + " radiusCorrection = (expectedDimensionY - measResult.DimensionY) / 2", + " endif ", + " else ", + " isXMeasure = expectedXPos hasvalue and measureDirectionX hasvalue", + " isYMeasure = expectedYPos hasvalue and measureDirectionY hasvalue ", + " if (isXMeasure or isYMeasure)", + " if (isXMeasure and not isYMeasure)", + " radiusCorrection = (expectedXPos - measResult.MeasuredPosition.X) * GetSignFromDirection(measureDirectionX)", + " endif", + " if (isYMeasure and not isXMeasure)", + " radiusCorrection = (expectedYPos - measResult.MeasuredPosition.Y) * GetSignFromDirection(measureDirectionY)", + " endif", + " if( isXMeasure and isYMeasure)", + " radiusCorrection = (", + " (expectedXPos - measResult.MeasuredPosition.X) * GetSignFromDirection(measureDirectionX) + ", + " (expectedYPos - measResult.MeasuredPosition.Y) * GetSignFromDirection(measureDirectionY) ", + " ) / 2 ", + " endif ", + " endif ", + " endif", + " ", + // TAG code below needs to get fixed for type we, + " toolId = ToolChangingUtilities::GetToolIdFromToolName(toolToUpdateWear)", + " newDiameter = ToolParameter::GetToolDiameter(toolNumber=toolId) - radiusCorrection * 2", + " ToolData::SetToolGeometry Diameter=newDiameter toolId=toolId", + " else", + " # length correction", + " ", + " endif", + " endif ", + " ", + " # Position", + " if positionTolerance hasvalue", + " isOutOfTolerance: boolean", + " if expectedXPos hasvalue", + " isOutOfTolerance = Math::Abs(expectedXPos - measResult.MeasuredPosition.X) > positionTolerance ", + " endif", + " if expectedYPos hasvalue", + " isOutOfTolerance = Math::Abs(expectedYPos - measResult.MeasuredPosition.Y) > positionTolerance ", + " endif", + " if expectedZPos hasvalue", + " isOutOfTolerance = Math::Abs(expectedZPos - measResult.MeasuredPosition.Z) > positionTolerance ", + " endif ", + " if isOutOfTolerance", + " Dialog message=\"Position out of tolerance\" caption=\"Position out of tolerance\" Error", + " endif", + " endif ", + "endprogram", + "", + "function GetSignFromDirection(dir:direction) returns number", + " if dir == direction.positive", + " return 1", + " endif ", + " return -1 ", + "endfunction" + ]; + + probingProgramOperation = {operationProgram:probingProgram.join(EOL)}; + SimPLProgram.operationList.push(probingProgramOperation); +} + +function drilling(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + writeBlock(boreCommandString.join(" ")); +} + +function chipBreaking(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + boreCommandString.push("infeedZ=infeedZ"); + writeBlock(boreCommandString.join(" ")); +} + +function boreMilling(cycle) { + var numberOfSteps = (cycle.numberOfSteps != undefined) ? cycle.numberOfSteps : 0; + if (numberOfSteps > 2) { + error("Only 2 steps are allowed for bore-milling."); + } + + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + boreCommandString.push("DrillMilling"); + boreCommandString.push("diameter=diameter"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("infeedZ=infeedZ"); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + + if (numberOfSteps == 2) { + var xycleaning = cycle.stepover; + var maxzdepthperstep = tool.fluteLength * 0.8; + boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); + boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); + } + var bottomcleaning = 0; + // finishingZ = 1; + writeBlock(boreCommandString.join(" ")); +} + +function threadMilling(cycle) { + var threadString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + threadString.push("SpecialThread"); + // threadString.push('threadName=threadName'); + threadString.push("nominalDiameter=nominalDiameter"); + threadString.push("pitch=pitch"); + threadString.push("depth=" + depth); + threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + if (getProperty("createThreadChamfer")) { + threadString.push("Deburring"); + } + // threadString.push("insideOutside=ThreadMillingSide.Inside"); + threadString.push("finishing=finishing"); + if (cycle.threading == "left") { + threadString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + threadString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(threadString.join(" ")); +} + +function tapping(cycle) { + var tappingString = new Array(); + var depth = xyzFormat.format(cycle.depth); + tappingString.push("ThreadCutting"); + tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); + tappingString.push("depth=" + depth); + tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); + if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { + tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); + } + if (tool.type == TOOL_TAP_LEFT_HAND) { + tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + tappingString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(tappingString.join(" ")); +} + +function formatCycleTime(cycleTime) { + // cycleTime = cycleTime + 0.5; // round up + var seconds = cycleTime % 60 | 0; + var minutes = ((cycleTime - seconds) / 60 | 0) % 60; + var hours = (cycleTime - minutes * 60 - seconds) / (60 * 60) | 0; + if (hours > 0) { + return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); + } else if (minutes > 0) { + return subst(localize("%1m:%2s"), minutes, seconds); + } else { + return subst(localize("%1s"), seconds); + } +} + +function dump(name, _arguments) { + var result = getCurrentRecordId() + ": " + name + "("; + for (var i = 0; i < _arguments.length; ++i) { + if (i > 0) { + result += ", "; + } + if (typeof _arguments[i] == "string") { + result += "'" + _arguments[i] + "'"; + } else { + result += _arguments[i]; + } + } + result += ")"; + writeln(result); +} + +function onSectionEnd() { + if (typeof inspectionProcessSectionEnd == "function") { + inspectionProcessSectionEnd(); + } + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + if (getProperty("useZAxisOffset")) { + writeBlock("ZAxisOffset = 0"); + } + setTCPMode(TCP_OFF); + + if (getProperty("useSuction")) { + writeBlock("Suction Off"); + } + + if (getProperty("useSequences") && !isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + if (!getProperty("useExternalSequencesFiles")) { + resetWriteRedirection(); + } + spacingDepth += 1; + } + + writeBlock("EndBlock"); + + spacingDepth -= 1; + + writeBlock("endprogram " + "# " + getOperationName(currentSection)); + resetWriteRedirection(); + SimPLProgram.operationList.push(currentOperation); + forceAny(); +} + +function writeBuffer(buffer) { + if (buffer.length > 0) { + writeBlock(buffer.join(EOL) + EOL); + writeBlock(""); + } +} + +// after all the oiperation calls are set close the main program with all the calls +function finishMainProgram() { + // write the main program footer + setWriteRedirection(SimPLProgram.mainProgram); + spacingDepth += 1; + + // write all subprogram calls in the main Program + for (var i = 0; i < SimPLProgram.operationList.length; ++i) { + writeBlock(SimPLProgram.operationList[i].operationCall); + } + + if (getProperty("useCoolant")) { + writeBlock("SpraySystem Off"); + } + + if (multiAxisCommandsEnabled) { + writeBlock("MultiAxisMode Off"); + setTCPMode(TCP_OFF); + } + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + if (getProperty("useParkPosition")) { + writeBlock("Spindle Off"); + writeBlock("MoveToParkPosition"); + } else { + writeBlock("MoveToSafetyPosition"); + zOutput.reset(); + } + + spacingDepth -= 1; + writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + resetWriteRedirection(); +} + +// add a varibale to the global declarations +function addVariable(value) { + if (SimPLProgram.globalVariableList.indexOf(value) == -1) { + SimPLProgram.globalVariableList.push(value); + } +} +// add a varibale to the global declarations +function addModuleReference(value) { + if (SimPLProgram.usingList.indexOf(value) == -1) { + SimPLProgram.usingList.push(value); + } +} + +// Start of onRewindMachine logic +/** Allow user to override the onRewind logic. */ +function onRewindMachineEntry(_a, _b, _c) { + return false; +} + +/** Retract to safe position before indexing rotaries. */ +function onMoveToSafeRetractPosition() { + writeBlock("MoveToSafetyPosition"); + // cancel TCP so that tool doesn't follow rotaries + setTCPMode(TCP_OFF); +} + +/** Rotate axes to new position above reentry position */ +function onRotateAxes(_x, _y, _z, _a, _b, _c) { + // position rotary axes + xOutput.disable(); + yOutput.disable(); + zOutput.disable(); + invokeOnRapid5D(_x, _y, _z, _a, _b, _c); + setCurrentABC(new Vector(_a, _b, _c)); + xOutput.enable(); + yOutput.enable(); + zOutput.enable(); +} + +/** Return from safe position after indexing rotaries. */ +function onReturnFromSafeRetractPosition(_x, _y, _z) { + // reinstate TCP / tool length compensation + setTCPMode(TCP_ON); + forceXYZ(); + onPrePositioning(_x, _y, _z); +} +// End of onRewindMachine logic + +function onClose() { + + if (getProperty("waitAfterOperation")) { + writeWaitProgram(); + } + spacingDepth = 0; + + // check for additional subprograms + if (programIncludesOperationType("inspection") && typeof writeInspectionProgram == "function") { + writeInspectionProgram(); + } + + if (programIncludesOperationType("probe")) { + writeProbingProgram(); + } + + writeBlock(SimPLProgram.moduleName); + writeBlock(""); + writeBuffer(SimPLProgram.toolDescriptionList); + writeBlock(SimPLProgram.workpieceGeometry); + writeBlock(""); + writeBuffer(SimPLProgram.sequenceList); + writeBuffer(SimPLProgram.usingList); + writeBuffer(SimPLProgram.externalUsermodules); + writeBuffer(SimPLProgram.globalVariableList); + + finishMainProgram(); + writeBlock(SimPLProgram.mainProgram); + writeBlock(""); + + for (var i = 0; i < SimPLProgram.operationList.length; ++i) { + writeBlock(SimPLProgram.operationList[i].operationProgram); + } + + writeBlock("end"); + + if (getProperty("useSequences") && !getProperty("useExternalSequencesFiles")) { + writeComment(spacing); + writeBlock(sequenceBuffer.toString()); + } +} + +function setProperty(property, value) { + properties[property].current = value; +} +// <<<<< INCLUDED FROM generic_posts/datron next.cps + +capabilities |= CAPABILITY_INSPECTION; +description = "DATRON next Inspect Surface"; +minimumRevision = minimumRevision < 45793 ? 45793 : minimumRevision; +longDescription = "Generic post for Datron next with Inspect Surface capabilities."; + +// code for inspection support +properties.singleResultsFile = { + title : "Create Single Results File", + description: "Set to false if you want to store the measurement results for each inspection toolpath in a seperate file", + group : "probing", + type : "boolean", + value : true, + scope : "post" +}; +properties.toolOffsetType = { + title : "Tool offset type", + description: "Select the which offsets are available on the tool offset page", + group : "probing", + type : "enum", + values : [ + {id:"geomWear", title:"Geometry & Wear"}, + {id:"geomOnly", title:"Geometry only"} + ], + value: "geomOnly", + scope: "post" +}; +properties.stopOnInspectionEnd = { + title : "Stop on Inspection End", + description: "Set to ON to output M0 at the end of each inspection toolpath", + group : "probing", + type : "boolean", + value : true, + scope : "post" +}; + +var ijkInspectionFormat = createFormat({decimals:5, forceDecimal:true}); +// inspection variables +var inspectionVariables = { + localVariablePrefix : "#", + probeRadius : 0, + pointNumber : 1, + inspectionSections : 0, + inspectionSectionCount: 0, + workpieceOffset : "", +}; + +var macroFormat = createFormat({prefix:inspectionVariables.localVariablePrefix, decimals:0}); +function inspectionProcessSectionStart() { + // only write header once if user selects a single results file + if (inspectionVariables.inspectionSectionCount == 0 || !getProperty("singleResultsFile") || (currentSection.workOffset != inspectionVariables.workpieceOffset)) { + inspectionCreateResultsFileHeader(); + } + inspectionVariables.inspectionSectionCount += 1; + // write the toolpath name as a comment + writeBlock("FileWriteLine filename=InspectionFilename value=\";TOOLPATH " + getParameter("operation-comment") + "\""); + inspectionWriteWorkplaneTransform(); + if (getProperty("toolOffsetType") == "geomOnly") { + writeComment("Geometry Only"); + // TAG fill + } else { + writeComment("Geometry and Wear"); + // TAG fill + } +} + +function inspectionCreateResultsFileHeader() { + // add the filename to the global variables declarations + addVariable("InspectionFilename:string"); + + writeBlock("InspectionFilename = \"" + getInspectionFilename() + "\""); + writeComment("delete existing old file"); + writeBlock("if FileExists filename=InspectionFilename"); + writeBlock(" FileDelete filename=InspectionFilename"); + writeBlock("endif"); + + writeBlock(""); + if (inspectionVariables.inspectionSectionCount == 0 || !getProperty("singleResultsFile")) { + writeBlock("FileWriteLine filename=InspectionFilename value=\"START\""); + if (hasGlobalParameter("document-id")) { + writeBlock("FileWriteLine filename=InspectionFilename value=\"DOCUMENTID " + getGlobalParameter("document-id") + "\""); + } + if (hasGlobalParameter("model-version")) { + writeBlock("FileWriteLine filename=InspectionFilename value=\"MODELVERSION " + getGlobalParameter("model-version") + "\""); + } + } + // write the toolpath id in the results file + writeBlock("FileWriteLine filename=InspectionFilename value=\"TOOLPATHID " + getParameter("autodeskcam:operation-id") + "\""); + inspectionWriteCADTransform(); + inspectionVariables.workpieceOffset = currentSection.workOffset; +} + +function inspectionWriteCADTransform() { + var cadOrigin = currentSection.getModelOrigin(); + var cadWorkPlane = currentSection.getModelPlane().getTransposed(); + var cadEuler = cadWorkPlane.getEuler2(EULER_XYZ_S); + writeBlock( + "FileWriteLine filename=InspectionFilename value=\"G331" + + " N" + inspectionVariables.pointNumber + + " A" + abcFormat.format(cadEuler.x) + + " B" + abcFormat.format(cadEuler.y) + + " C" + abcFormat.format(cadEuler.z) + + " X" + xyzFormat.format(-cadOrigin.x) + + " Y" + xyzFormat.format(-cadOrigin.y) + + " Z" + xyzFormat.format(-cadOrigin.z) + + "\"" + ); +} + +function inspectionWriteWorkplaneTransform() { + var euler = currentSection.workPlane.getEuler2(EULER_XYZ_S); + var abc = new Vector(euler.x, euler.y, euler.z); + writeBlock("FileWriteLine filename=InspectionFilename value=\"G330" + + " N" + inspectionVariables.pointNumber + + " A" + abcFormat.format(abc.x) + + " B" + abcFormat.format(abc.y) + + " C" + abcFormat.format(abc.z) + + " X0 Y0 Z0 I0 R0\"" + ); +} + +function inspectionProcessSectionEnd() { + if (isInspectionOperation(currentSection)) { + // close inspection results file if the NC has inspection toolpaths + if ((!getProperty("singleResultsFile")) || (inspectionVariables.inspectionSectionCount == inspectionVariables.inspectionSections)) { + // TAG add commisioning mode + } + writeBlock("FileWriteLine filename=InspectionFilename value=\"END\""); + writeBlock(getProperty("stopOnInspectionEnd") == true ? "Dialog message=\"Finish Inspection\" Yes No caption=\"Inspection\" Info" : ""); + } +} + +function onProbe(status) { + if (status) {// probe ON + writeBlock("PrepareXyzSensor"); // command for switching the probe on + } else { // probe OFF + writeBlock("UnprepareXyzSensor"); // command for switching the probe off + } +} + +function inspectionCycleInspect(cycle, epx, epy, epz) { + if (getNumberOfCyclePoints() != 3) { + error(localize("Missing Endpoint in Inspection Cycle, check Approach and Retract heights")); + } + + if (!isLastCyclePoint()) { + return; + } + + forceFeed(); // ensure feed is always output - just in case. + if (currentSection.isMultiAxis()) { + error(localize("Multi axis inspect surface is not supported.")); + return; + } + + var m = getRotation(); + var v = new Vector(cycle.nominalX, cycle.nominalY, cycle.nominalZ); + var targetPoint = m.multiply(v); + var pathVector = new Vector(cycle.nominalI, cycle.nominalJ, cycle.nominalK); + var measureDirection = m.multiply(pathVector).normalized.getNegated(); + var searchDistance = cycle.probeClearance; + + // call inspection subprogram + writeBlock("MeasurePoint("); + spacingDepth += 1; + writeBlock("pointID=" + cycle.pointID); + writeBlock("surfacePos=" + vectorToDatronPosString(targetPoint)); + writeBlock("measureDirection=" + vectorToDatronPosString(measureDirection)); + writeBlock("searchDistance=" + xyzFormat.format(searchDistance)); + writeBlock("surfaceOffset=" + xyzFormat.format(getParameter("operation:inspectSurfaceOffset"))); + writeBlock("upper=" + xyzFormat.format(getParameter("operation:inspectUpperTolerance"))); + writeBlock("lower=" + xyzFormat.format(getParameter("operation:inspectLowerTolerance")) + ")"); + spacingDepth -= 1; + writeBlock(""); + zOutput.reset(); +} + +// convert the hsm vector to the datron simpl position initilizer. +function vectorToDatronPosString(vec) { + return "NewPos(" + xyzFormat.format(vec.x) + ", " + xyzFormat.format(vec.y) + ", " + xyzFormat.format(vec.z) + ")"; +} + +// adds the necessary references for inspection to the program header +function addInspectionReferences() { + if (hasProgramInspectionOperations()) { + SimPLProgram.usingList.push("using File, LinearAlgebra, LinearAlgebraHelper, MeasuringCyclesExecutor, XyzSensor, String"); + SimPLProgram.usingList.push("import AxisSystem"); + } +} + +function hasProgramInspectionOperations() { + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (isInspectionOperation(section)) { + return true; + } + } + return false; +} + +// create the subprogram that makes the inspection probing and the output to the result file. +function writeInspectionProgram() { + // not triggered is captured by the NEXT Control + var inspectProgram = [ + "program MeasurePoint pointID:number surfacePos:Position measureDirection:Position searchDistance:number surfaceOffset:number upper:number lower:number", + "", + " # measure", + " measureResult = GetMeasuringResultCompensation(", + " ArrangeMeasuring(", + " targetPosition=surfacePos", + " direction=measureDirection", + " distance=searchDistance),", + " AxisSystem::GetRcsMatrix)", + "", + " # Trigger not found", + " if measureResult.active == false", + " Dialog message=\"Target Point not found\" caption=\"Inspection error\" Error", + " endif", + "", + + " # write nominal values", + " measureNominalString = \"G800 N\" + ValueToString(pointID) + \" X\" + ValueToString(surfacePos.X) + \" Y\" + ValueToString(surfacePos.Y) + \" Z\" + ValueToString(surfacePos.Z) + \" I\" + ValueToString(measureDirection.X * -1) + \" J\"+ ValueToString(measureDirection.Y * -1) + \" K\" + ValueToString(measureDirection.Z * -1) + \" O\" + ValueToString(surfaceOffset) + \" U\" + ValueToString(upper) + \" L\" + ValueToString(lower)", + " measureNominalString = StringReplace(measureNominalString, \",\", \".\")", + " FileWriteLine filename=InspectionFilename value=measureNominalString", + "", + + " # write result values", + " measureResultString = StringFormat(", + " baseString=\"G801 N{0} X{1:f3} Y{2:f3} Z{3:f3} R{4:f3}\"", + " p0=pointID", + " p1=(measureResult.measuredPoint.X + ((measureDirection.X*(-1))*GetProbeTipRadius))", + " p2=(measureResult.measuredPoint.Y + ((measureDirection.Y*(-1))*GetProbeTipRadius))", + " p3=(measureResult.measuredPoint.Z + ((measureDirection.Z*(-1))*GetProbeTipRadius))", + " p4=GetProbeTipRadius)", + " measureResultString = StringReplace(measureResultString, \",\", \".\")", + "", + + "FileWriteLine filename=InspectionFilename value=measureResultString", + "", + " # check result", + " measuredPosition = NewPos(", + " measureResult.measuredPoint.X,", + " measureResult.measuredPoint.Y,", + " measureResult.measuredPoint.Z)", + "", + " measuredDifferenceVector = SubPosition(surfacePos, measuredPosition)", + " deltaDirection = Normalize(measuredDifferenceVector)", + " distance = GetPositionDistance(measuredDifferenceVector)", + "", + " # check deviation direction", + " if(GetPositionDistance(SubPosition(Normalize(measuredDifferenceVector),measureDirection))>1)", + " distance = distance * -1", + " endif", + "", + " if(distance > lower and distance < upper)", + " return", + " endif", + "", + " # Position out of tolerance", + " Dialog message=\"Position out of tolerance\" caption=\"Position out of tolerance\" Error", + "", + "endprogram" + ]; + + inspectProgramOperation = {operationProgram:inspectProgram.join(EOL)}; + SimPLProgram.operationList.push(inspectProgramOperation); +} + +function getInspectionFilename() { + var resFile; + if (getProperty("singleResultsFile")) { + resFile = getParameter("job-description") + " RESULTS"; + } else { + resFile = getParameter("operation-comment") + " RESULTS"; + } + + resFile = resFile.replace(/[^a-zA-Z0-9_ ]/g, ""); + resFile += ".txt"; + return resFile; +} diff --git a/datron next.cps b/datron next.cps new file mode 100644 index 0000000..b181deb --- /dev/null +++ b/datron next.cps @@ -0,0 +1,3090 @@ +/** + Copyright (C) 2012-2022 by Autodesk, Inc. + All rights reserved. + + DATRON post processor configuration. + + $Revision$ + $Date$ + + FORKID {21ADEFBF-939E-4D3F-A935-4E61F5958698} +*/ + +description = "DATRON next"; +vendor = "DATRON"; +vendorUrl = "http://www.datron.com"; +legal = "Copyright (C) 2012-2022 by Autodesk, Inc."; +certificationLevel = 2; +minimumRevision = 45793; + +longDescription = "Post for Datron next control. This post is for use with the Datron neo CNC."; + +extension = "simpl"; +setCodePage("utf-8"); + +capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION; +tolerance = spatial(0.002, MM); + +minimumChordLength = spatial(0.25, MM); +minimumCircularRadius = spatial(0.01, MM); +maximumCircularRadius = spatial(1000, MM); +minimumCircularSweep = toRad(0.01); +maximumCircularSweep = toRad(120); +allowHelicalMoves = true; +allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only +probeMultipleFeatures = true; + +// user-defined properties +properties = { + writeMachine: { + title : "Write machine", + description: "Output the machine settings in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + writeDateAndTime: { + title : "Write date and time", + description: "Output date and time in the header of the code.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + showNotes: { + title : "Show notes", + description: "Writes operation notes as comments in the outputted code.", + group : "formats", + type : "boolean", + value : false, + scope : "post" + }, + useSmoothing: { + title : "Use smoothing", + description: "Specifies that smoothing mode should be used.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useDynamic: { + title : "Dynamic mode", + description: "Specifies that dynamic mode should be used.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + machineModel: { + title : "Machine type", + description: "Specifies the DATRON machine type.", + group : "configuration", + type : "enum", + values : [ + {title:"NEO", id:"NEO"}, + {title:"MX Cube", id:"MX"}, + {title:"Cube", id:"Cube"} + ], + value: "NEO", + scope: "post" + }, + useParkPosition: { + title : "Park at end of program", + description: "Enable to use the park position at end of program.", + group : "homePositions", + type : "boolean", + value : true, + scope : "post" + }, + writeToolTable: { + title : "Write tool table", + description: "Write a tool table containing geometric tool information.", + group : "formats", + type : "boolean", + value : true, + scope : "post" + }, + useSequences: { + title : "Use sequences", + description: "If enabled, sequences are used in the output format on large files.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useExternalSequencesFiles: { + title : "Use external sequence files", + description: "If enabled, an external sequence file is created for each operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useCoolant: { + title : "Write coolant commands", + description: "Enable/disable coolant code outputs for the entire program.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + useParametricFeed: { + title : "Parametric feed", + description: "Specifies that parametric feedrates should be used.", + group : "preferences", + type : "boolean", + value : true, + scope : "post" + }, + waitAfterOperation: { + title : "Wait after operation", + description: "If enabled, an optional stop will get generated to pause after each operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + rotaryAxisSetup: { + title : "Rotary axis setup", + description: "Specifies the rotary axis setup.", + group : "configuration", + type : "enum", + values : [ + {title:"No rotary axis", id:"NONE"}, + {title:"4th axis along X+", id:"4X"}, + {title:"DST (5 axis)", id:"DST"} + ], + value: "NONE", + scope: "post" + }, + useSuction: { + title : "Use Suction", + description: "Enable the suction for every operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + createThreadChamfer: { + title : "Create a Thread Chamfer", + description: "Create a chamfer with the thread milling tool", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + preloadTool: { + title : "Preload tool", + description: "Preload the next Tool in the DATRON Tool assist.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useZAxisOffset: { + title : "Output Z Offset command", + description: "This creates a command to allow a manual Z offset for each operation.", + group : "preferences", + type : "boolean", + value : false, + scope : "post" + }, + useTCP: { + title : "Use RTCP", + description: "Use the NEXT 5axis setup correction.", + group : "multiAxis", + type : "boolean", + value : false, + scope : "post" + } +}; + +// wcs definiton +wcsDefinitions = { + useZeroOffset: true, + wcs : [ + {name:"Zero Offset", format:"", range:[0, 0]}, + {name:"Standard", format:"LoadWcs name=\"#\"", range:[1, 999]} + ] +}; + +var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1}); +var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1}); + +var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false}); +var abcFormat = createFormat({decimals:5, scale:DEG}); +var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2)}); +var toolFormat = createFormat({decimals:0}); +var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false}); +var rpmFormat = createFormat({decimals:0, scale:1}); +var sleepFormat = createFormat({decimals:0, scale:1000}); // milliseconds +var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false}); + +var toolOutput = createVariable({prefix:"Tool_", force:true}, toolFormat); +var feedOutput = createVariable({prefix:""}, feedFormat); + +var xOutput = createVariable({prefix:" X="}, xyzFormat); +var yOutput = createVariable({prefix:" Y="}, xyzFormat); +var zOutput = createVariable({prefix:" Z="}, xyzFormat); +var aOutput = createVariable({prefix:" A="}, abcFormat); +var bOutput = createVariable({prefix:" B="}, abcFormat); +var cOutput = createVariable({prefix:" C="}, abcFormat); + +var iOutput = createVariable({prefix:" dX=", force:true}, xyzFormat); +var jOutput = createVariable({prefix:" dY=", force:true}, xyzFormat); +var kOutput = createVariable({prefix:" dZ="}, xyzFormat); + +// fixed settings +var useDatronFeedCommand = false; // unsupported for now, keep false +var spacingDepth = 0; +var spacingString = " "; +var spacing = "##########################################################"; +var currentWorkOffset; +var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported + +// buffer for building up a program not serial created +var sequenceBuffer = new StringBuffer(); + +function NewOperation(operationCall) { + this.operationCall = operationCall; + this.operationProgram = new StringBuffer(); + this.operationProgram.append(""); +} +var currentOperation; +function NewSimPLProgram() { + this.moduleName = new StringBuffer(); + this.measuringSystem = "Metric"; + this.toolDescriptionList = new Array(); + this.workpieceGeometry = ""; + this.sequenceList = new Array(); + this.usingList = new Array(); + this.externalUsermodules = new Array(); + this.globalVariableList = new Array(); + this.mainProgram = new StringBuffer(); + this.operationList = new Array(); +} + +var SimPLProgram = new NewSimPLProgram(); + +// collected state +var currentFeedValue = -1; +var optionalSection = false; +var activeMovements; // do not use by default +var currentFeedId; +var multiAxisCommandsEnabled = false; + +var TCP_OFF = 0; +var TCP_ON = 1; + +// format date + time +var timeFormat = createFormat({decimals:0, width:2, zeropad:true}); +var now = new Date(); +var nowDay = now.getDate(); +var nowMonth = now.getMonth() + 1; +var nowHour = now.getHours(); +var nowMin = now.getMinutes(); +var nowSec = now.getSeconds(); + +function getSequenceName(section) { + var sequenceName = ""; + if (getProperty("useExternalSequencesFiles")) { + sequenceName += getProgramFilename(); + } + sequenceName += "SEQUENCE_" + mapComment(getOperationDescription(section)); + return sequenceName; +} + +function getProgramFilename() { + var outputPath = getOutputPath(); + var programFilename = FileSystem.getFilename(outputPath.substr(0, outputPath.lastIndexOf("."))) + "_"; + return programFilename; +} + +function getOperationName(section) { + return "Operation_" + getOperationDescription(section); +} + +function capitalizeFirstLetter(text) { + return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); +} + +function getSpacing() { + var space = ""; + for (var i = 0; i < spacingDepth; i++) { + space += spacingString; + } + return space; +} + +/** + Redirect the output to an infinite number of buffers +*/ +var writeRedirectionStack = new Array(); + +function setWriteRedirection(redirectionBuffer) { + writeRedirectionStack.push(redirectionBuffer); +} + +function resetWriteRedirection() { + writeRedirectionStack.pop(); +} + +/** + Writes the specified block. +*/ +function writeBlock() { + var text = getSpacing() + formatWords(arguments); + if (writeRedirectionStack.length == 0) { + writeWords(text); + } else { + writeRedirectionStack[writeRedirectionStack.length - 1].append(text + EOL); + } +} + +/** + Output a comment. +*/ +function writeComment(text) { + if (text) { + text = getSpacing() + "# " + text; + if (writeRedirectionStack.length == 0) { + writeln(text); + } else { + writeRedirectionStack[writeRedirectionStack.length - 1].append(text + EOL); + } + } +} + +var charMap = { + "\u00c4": "Ae", + "\u00e4": "ae", + "\u00dc": "Ue", + "\u00fc": "ue", + "\u00d6": "Oe", + "\u00f6": "oe", + "\u00df": "ss", + "\u002d": "_", + "\u0020": "_" +}; + +/** Map specific chars. */ +function mapComment(text) { + text = formatVariable(text); + var result = ""; + for (var i = 0; i < text.length; ++i) { + var ch = charMap[text[i]]; + result += ch ? ch : text[i]; + } + return result; +} + +function formatComment(text) { + return mapComment(text); +} + +function formatVariable(text) { + return String(text).replace(/[^A-Za-z0-9\-_]/g, ""); +} + +// Start of machine configuration logic +var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads +var useMultiAxisFeatures = false; // enable to use control enabled tilted plane, can be overridden with a property +var useABCPrepositioning = false; // enable to preposition rotary axes prior to tilted plane output, can be overridden with a property +var forceMultiAxisIndexing = false; // force multi-axis indexing for 3D programs +var eulerConvention = EULER_ZXZ_R; // euler angle convention for 3+2 operations + +// internal variables, do not change +var receivedMachineConfiguration; +var operationSupportsTCP; +var multiAxisFeedrate; + +/** + Activates the machine configuration (both from CAM and hardcoded) +*/ +function activateMachine() { + // disable unsupported rotary axes output + if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined")) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined")) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined")) { + cOutput.disable(); + } + + // setup usage of multiAxisFeatures + useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") : + (typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false); + useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") : + (typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false); + + // don't need to modify any settings if 3-axis machine + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; + } + + if (false) { // set to false to disable the warning message below + var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; + for (var i in axes) { + if (machineConfiguration.isTableConfiguration() && axes[i].isEnabled() && axes[i].getOffset().isNonZero() && !axes[i].isTCPEnabled()) { + warning(localize("A rotary axis offset is defined in the machine configuration on a non-TCP machine which will influence the NC output." + EOL + + "The setup origin should be defined appropriately, probably at the table center, and not at the center of the rotary axes.")); + break; + } + } + } + + // save multi-axis feedrate settings from machine configuration + var mode = machineConfiguration.getMultiAxisFeedrateMode(); + var type = mode == FEED_INVERSE_TIME ? machineConfiguration.getMultiAxisFeedrateInverseTimeUnits() : + (mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateDPMType() : DPM_STANDARD); + multiAxisFeedrate = { + mode : mode, + maximum : machineConfiguration.getMultiAxisFeedrateMaximum(), + type : type, + tolerance: mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateOutputTolerance() : 0, + bpwRatio : mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateBpwRatio() : 1 + }; + + // setup of retract/reconfigure TAG: Only needed until post kernel supports these machine config settings + if (receivedMachineConfiguration && machineConfiguration.performRewinds()) { + safeRetractDistance = machineConfiguration.getSafeRetractDistance(); + safePlungeFeed = machineConfiguration.getSafePlungeFeedrate(); + safeRetractFeed = machineConfiguration.getSafeRetractFeedrate(); + } + if (typeof safeRetractDistance == "number" && getProperty("safeRetractDistance") != undefined && getProperty("safeRetractDistance") != 0) { + safeRetractDistance = getProperty("safeRetractDistance"); + } + + // setup for head configurations + if (machineConfiguration.isHeadConfiguration()) { + compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength; + } + + // calculate the ABC angles and adjust the points for multi-axis operations + // rotary heads may require the tool length be added to the pivot length + // so we need to optimize each section individually + if (machineConfiguration.isHeadConfiguration() && compensateToolLength) { + for (var i = 0; i < getNumberOfSections(); ++i) { + var section = getSection(i); + if (section.isMultiAxis()) { + machineConfiguration.setToolLength(getBodyLength(section.getTool())); // define the tool length for head adjustments + section.optimizeMachineAnglesByMachine(machineConfiguration, OPTIMIZE_AXIS); + } + } + } else { // tables and rotary heads with TCP support can be optimized with a single call + optimizeMachineAngles2(OPTIMIZE_AXIS); + } +} + +function getBodyLength(tool) { + for (var i = 0; i < getNumberOfSections(); ++i) { + var section = getSection(i); + if (tool.number == section.getTool().number) { + return section.getParameter("operation:tool_overallLength", tool.bodyLength + tool.holderLength); + } + } + return tool.bodyLength + tool.holderLength; +} + +/** + Defines a hardcoded machine configuration +*/ +function defineMachine() { + var useTCP = getProperty("useTCP"); + if (getProperty("rotaryAxisSetup") != "NONE") { + if (receivedMachineConfiguration && machineConfiguration.isMultiAxisConfiguration()) { + error(localize("You can only select either a machine in the CAM setup or use the properties to define your kinematics.")); + return; + } + if (getProperty("rotaryAxisSetup") == "4X") { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 360], cyclic:true, preference:0, tcp:false}); + machineConfiguration = new MachineConfiguration(aAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEO with A Axis"); + machineConfiguration.setDescription("DATRON NEXT Control with additional A-Axis"); + } else if (getProperty("rotaryAxisSetup") == "DST") { + var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-10, 110], cyclic:false, preference:0, tcp:useTCP}); + var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], cyclic:true, preference:0, tcp:useTCP}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + machineConfiguration.setVendor("DATRON"); + machineConfiguration.setModel("NEXT with DST"); + machineConfiguration.setDescription("DATRON NEXT Control with additional DST"); + } + setMachineConfiguration(machineConfiguration); + if (receivedMachineConfiguration) { + warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); + receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten + } + } else { + if (false) { // note: setup your machine here + var aAxis = createAxis({coordinate:X, table:true, axis:[1, 0, 0], offset:[0, 0, 0], range:[-120, 30], cyclic:false, preference:-1, tcp:useTCP}); + var cAxis = createAxis({coordinate:Z, table:true, axis:[0, 0, 1], offset:[0, 0, 0], cyclic:true, reset:0, tcp:useTCP}); + machineConfiguration = new MachineConfiguration(aAxis, cAxis); + + setMachineConfiguration(machineConfiguration); + if (receivedMachineConfiguration) { + warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); + receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten + } + } + } + + if (!receivedMachineConfiguration) { + // multiaxis settings + if (machineConfiguration.isHeadConfiguration()) { + machineConfiguration.setVirtualTooltip(false); // translate the pivot point to the virtual tool tip for nonTCP rotary heads + } + + // retract / reconfigure + var performRewinds = true; // set to true to enable the retract/reconfigure logic + if (performRewinds) { + machineConfiguration.enableMachineRewinds(); // enables the retract/reconfigure logic + safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock, can be overridden with a property + safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate + safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate + machineConfiguration.setSafeRetractDistance(safeRetractDistance); + machineConfiguration.setSafeRetractFeedrate(safeRetractFeed); + machineConfiguration.setSafePlungeFeedrate(safePlungeFeed); + var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values + machineConfiguration.setRewindStockExpansion(stockExpansion); + } + + // multi-axis feedrates + if (machineConfiguration.isMultiAxisConfiguration()) { + var useDPMFeeds = false; + machineConfiguration.setMultiAxisFeedrate( + // useTCP ? FEED_FPM : useDPMFeeds ? FEED_DPM : FEED_INVERSE_TIME, + FEED_FPM, // only FPM feedrate is supported + useDPMFeeds ? 9999.99 : 99999.99, // maximum output value for inverse time feed rates + useDPMFeeds ? DPM_COMBINATION : INVERSE_MINUTES, // INVERSE_MINUTES/INVERSE_SECONDS or DPM_COMBINATION/DPM_STANDARD + 0.5, // tolerance to determine when the DPM feed has changed + (unit == MM) ? 1.0 : 0.1 // ratio of rotary accuracy to linear accuracy for DPM calculations + ); + setMachineConfiguration(machineConfiguration); + } + } +} +// End of machine configuration logic + +function onOpen() { + // define and enable machine configuration + receivedMachineConfiguration = machineConfiguration.isReceived(); + if (typeof defineMachine == "function") { + defineMachine(); // hardcoded machine configuration + } + activateMachine(); // enable the machine optimizations and settings + + if (!machineConfiguration.isMachineCoordinate(0)) { + aOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(1)) { + bOutput.disable(); + } + if (!machineConfiguration.isMachineCoordinate(2)) { + cOutput.disable(); + } + + // header + writeProgramHeader(); + spacingDepth -= 1; + resetWriteRedirection(); + + // surface inspection + if (typeof inspectionWriteVariables == "function") { + inspectionWriteVariables(); + } +} + +function getOperationDescription(section) { + // creates the name of the operation + var operationComment = ""; + if (section.hasParameter("operation-comment")) { + operationComment = section.getParameter("operation-comment"); + operationComment = formatComment(operationComment); + } + + var cycleTypeString = ""; + if (section.hasParameter("operation:cycleType")) { + cycleTypeString = localize(section.getParameter("operation:cycleType")).toString(); + cycleTypeString = formatComment(cycleTypeString); + } + + var sectionID = section.getId() + 1; + var description = operationComment + "_" + cycleTypeString + "_" + sectionID; + return description; +} + +function createToolVariables() { + var tools = getToolTable(); + var toolVariables = new Array(); + if (tools.getNumberOfTools() > 0 && !getProperty("writeToolTable")) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + toolVariables.push(toolOutput.format(tool.number) + ":number"); + } + } + return toolVariables; +} + +function createToolDescriptionTable() { + if (!getProperty("writeToolTable")) { + return; + } + var toolDescriptionArray = new Array(); + var toolNameList = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + var tool = section.getTool(); + if (tool.type != TOOL_PROBE) { + var toolName = createToolName(tool); + var toolProgrammed = createToolDescription(tool); + if (toolNameList.indexOf(toolName) == -1) { + toolNameList.push(toolName); + toolDescriptionArray.push(toolProgrammed); + } + } + } + + SimPLProgram.toolDescriptionList = toolDescriptionArray; +} + +function createToolDescription(tool) { + var toolProgrammed = "@ ToolDescription : " + + "\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " + + "\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " + + "\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " + + "\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " + + "\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " + + "\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " + + "\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " + + "\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " + + "\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " + + "\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " + + "\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " + + "\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " + + "\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " + + "\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " + + "\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " + + "\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) + + " @"; + return toolProgrammed; +} + +/** + Generate the logical tool name for the assignment table of used tools. +*/ +function createToolName(tool) { + var toolName = toolFormat.format(tool.number); + toolName += "_" + translateToolType(tool.type); + if (tool.comment) { + toolName += "_" + tool.comment; + } + if (tool.diameter) { + toolName += "_D" + dimensionFormat.format(tool.diameter); + } + var description = tool.getDescription(); + if (description) { + toolName += "_" + description; + } + toolName = formatVariable(toolName); + return toolName; +} + +/** + Translate HSM tools to Datron tool categories. +*/ +function translateToolType(toolType) { + + var datronCategoryName = ""; + + toolCategory = toolType; + switch (toolType) { + case TOOL_UNSPECIFIED: + datronCategoryName = "Unspecified"; + break; + case TOOL_DRILL: + datronCategoryName = "Drill"; + break; + case TOOL_DRILL_CENTER: + datronCategoryName = "DrillCenter"; + break; + case TOOL_DRILL_SPOT: + datronCategoryName = "DrillSpot"; + break; + case TOOL_DRILL_BLOCK: + datronCategoryName = "DrillBlock"; + break; + case TOOL_MILLING_END_FLAT: + datronCategoryName = "MillingEndFlat"; + break; + case TOOL_MILLING_END_BALL: + datronCategoryName = "MillingEndBall"; + break; + case TOOL_MILLING_END_BULLNOSE: + datronCategoryName = "MillingEndBullnose"; + break; + case TOOL_MILLING_CHAMFER: + datronCategoryName = "Graver"; + break; + case TOOL_MILLING_FACE: + datronCategoryName = "MillingFace"; + break; + case TOOL_MILLING_SLOT: + datronCategoryName = "MillingSlot"; + break; + case TOOL_MILLING_RADIUS: + datronCategoryName = "MillingRadius"; + break; + case TOOL_MILLING_DOVETAIL: + datronCategoryName = "MillingDovetail"; + break; + case TOOL_MILLING_TAPERED: + datronCategoryName = "MillingTapered"; + break; + case TOOL_MILLING_LOLLIPOP: + datronCategoryName = "MillingLollipop"; + break; + case TOOL_TAP_RIGHT_HAND: + datronCategoryName = "TapRightHand"; + break; + case TOOL_TAP_LEFT_HAND: + datronCategoryName = "TapLeftHand"; + break; + case TOOL_REAMER: + datronCategoryName = "Reamer"; + break; + case TOOL_BORING_BAR: + datronCategoryName = "BoringBar"; + break; + case TOOL_COUNTER_BORE: + datronCategoryName = "CounterBore"; + break; + case TOOL_COUNTER_SINK: + datronCategoryName = "CounterSink"; + break; + case TOOL_HOLDER_ONLY: + datronCategoryName = "HolderOnly"; + break; + case TOOL_PROBE: + datronCategoryName = "XYZSensor"; + break; + default: + datronCategoryName = "Unspecified"; + } + return datronCategoryName; +} + +function writeProgramHeader() { + // write creation Date + setWriteRedirection(SimPLProgram.moduleName); + if (getProperty("writeDateAndTime")) { + var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear(); + var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin); + writeComment("!File ; generated at " + date + " - " + time); + } else { + writeComment("!File ;"); + } + + if (programComment) { + writeComment(formatComment(programComment)); + } + + writeBlock(" "); + // dump machine configuration + var vendor = machineConfiguration.getVendor(); + var model = machineConfiguration.getModel(); + var description = machineConfiguration.getDescription(); + + if (getProperty("writeMachine") && (vendor || model || description)) { + writeComment(localize("Machine")); + if (vendor) { + writeComment(" " + localize("vendor") + ": " + vendor); + } + if (model) { + writeComment(" " + localize("model") + ": " + model); + } + if (description) { + writeComment(" " + localize("description") + ": " + description); + } + } + + writeBlock("module " + "CamGeneratedModule"); + writeBlock(" "); + + writeBlock("@ MeasuringSystem = " + (unit == MM ? "\"" + "Metric" + "\"" + " @" : "\"" + "Imperial" + "\"" + " @")); + resetWriteRedirection(); + + // set the table of used tools in the header of the program + createToolDescriptionTable(); + + // set the workpiece information + SimPLProgram.workpieceGeometry = writeWorkpiece(); + + // set the sequence header in the program file + if (getProperty("useSequences")) { + var sequences = new Array(); + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (!isProbeOperation(section)) { + sequences.push("sequence " + getSequenceName(section)); + } + } + if (getProperty("useExternalSequencesFiles")) { + writeBlock("@ EmbeddedSequences = false @"); + } + + SimPLProgram.sequenceList = sequences; + } + + // set usings + SimPLProgram.usingList.push("using Base"); + if (getProperty("waitAfterOperation")) { + SimPLProgram.usingList.push("import System"); + } + + if (typeof inspectionCycleInspect == "function") { + addInspectionReferences(); + } + + // set paramtric feed variables + for (var i = 0; i < getNumberOfSections(); ++i) { + var section = getSection(i); + if (getProperty("useParametricFeed") && (!useDatronFeedCommand)) { + activeFeeds = initializeActiveFeeds(section); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var feedDescription = formatVariable(feedContext.description); + if (SimPLProgram.globalVariableList.indexOf(feedDescription + ":number") == -1) { + SimPLProgram.globalVariableList.push(feedDescription + ":number"); + } + } + } + } + + setWriteRedirection(SimPLProgram.mainProgram); + writeBlock("export program Main # " + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + spacingDepth += 1; + writeBlock("Absolute"); + + // set the parameter tool table + SimPLProgram.globalVariableList.push(createToolVariables()); + + // write the parameter tool table + if (!getProperty("writeToolTable")) { + var tools = getToolTable(); + writeComment("Number of tools in use" + ": " + tools.getNumberOfTools()); + if (tools.getNumberOfTools() > 0) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + var toolAsigment = toolOutput.format(tool.number) + " = " + (tool.number) + "# " + + formatComment(getToolTypeName(tool.type)) + " " + + "D:" + dimensionFormat.format(tool.diameter) + " " + + "L2:" + dimensionFormat.format(tool.fluteLength) + " " + + "L3:" + dimensionFormat.format(tool.shoulderLength) + " " + + "ProductID:" + formatComment(tool.productId); + writeBlock(toolAsigment); + } + writeBlock(" "); + } + } + resetWriteRedirection(); +} + +function writeWorkpiece() { + var workpieceString = new StringBuffer(); + setWriteRedirection(workpieceString); + var workpiece = getWorkpiece(); + var delta = Vector.diff(workpiece.upper, workpiece.lower); + + writeBlock("# Workpiece dimensions"); + writeBlock( + "# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.lower.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.lower.z)); + writeBlock( + "# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" + + " Y: " + workpieceFormat.format(workpiece.upper.y) + ";" + + " Z: " + workpieceFormat.format(workpiece.upper.z)); + writeBlock( + "# Part size X: " + workpieceFormat.format(delta.x) + ";" + + " Y: " + workpieceFormat.format(delta.y) + ";" + + " Z: " + workpieceFormat.format(delta.z)); + + writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," + + "\"" + "MaxEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," + + "\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," + + "\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" + + " @"); + resetWriteRedirection(); + return workpieceString; +} + +function onComment(message) { + var comments = String(message).split(";"); + for (comment in comments) { + writeComment(comments[comment]); + } +} + +/** Force output of X, Y, and Z. */ +function forceXYZ() { + xOutput.reset(); + yOutput.reset(); + zOutput.reset(); +} + +/** Force output of A, B, and C. */ +function forceABC() { + aOutput.reset(); + bOutput.reset(); + cOutput.reset(); +} + +function forceFeed() { + currentFeedId = undefined; + feedOutput.reset(); + currentFeedValue = -1; +} + +/** Force output of X, Y, Z, A, B, C, and F on next output. */ +function forceAny() { + forceXYZ(); + forceABC(); + forceFeed(); +} + +function FeedContext(id, description, datronFeedName, feed) { + this.id = id; + this.description = description; + this.datronFeedName = datronFeedName; + if (revision < 41759) { + this.feed = (unit == MM ? feed : toPreciseUnit(feed, MM)); // temporary solution + } else { + this.feed = feed; + } +} + +/** Maps the specified feed value to Q feed or formatted feed. */ +function getFeed(f) { + if (activeMovements) { + var feedContext = activeMovements[movement]; + if (feedContext != undefined) { + if (!feedFormat.areDifferent(feedContext.feed, f)) { + if (feedContext.id == currentFeedId) { + return ""; // nothing has changed + } + forceFeed(); + currentFeedId = feedContext.id; + if (useDatronFeedCommand) { + return ("Feed " + capitalizeFirstLetter(feedContext.datronFeedName)); + } else { + return ("Feed=" + formatVariable(feedContext.description)); + } + } + } + currentFeedId = undefined; // force Q feed next time + } + if (feedFormat.areDifferent(currentFeedValue, f)) { + currentFeedValue = f; + return "Feed=" + feedFormat.format(f); + } + return ""; +} + +function initializeActiveFeeds(section) { + var activeFeeds = new Array(); + if (section.hasAnyCycle && section.hasAnyCycle()) { + return activeFeeds; + } + activeMovements = new Array(); + var movements = section.getMovements(); + var id = 0; + + if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; + activeMovements[MOVEMENT_EXTENDED] = feedContext; + } + ++id; + if (movements & (1 << MOVEMENT_PREDRILL)) { + feedContext = new FeedContext(id, localize("Predrilling"), "plunge", section.getParameter("operation:tool_feedCutting")); + activeMovements[MOVEMENT_PREDRILL] = feedContext; + addFeedContext(feedContext, activeFeeds); + } + ++id; + if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) { + var feedContext = new FeedContext(id, localize("Cutting"), "roughing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:finishFeedrate")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:finishFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting")) { + if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("operation:tool_feedCutting")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedEntry")) { + if (movements & (1 << MOVEMENT_LEAD_IN)) { + var feedContext = new FeedContext(id, localize("Entry"), "approach", section.getParameter("operation:tool_feedEntry")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_IN] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LEAD_OUT)) { + var feedContext = new FeedContext(id, localize("Exit"), "approach", section.getParameter("operation:tool_feedExit")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LEAD_OUT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:noEngagementFeedrate")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", section.getParameter("operation:noEngagementFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } else if (section.hasParameter("operation:tool_feedCutting") && + section.hasParameter("operation:tool_feedEntry") && + section.hasParameter("operation:tool_feedExit")) { + if (movements & (1 << MOVEMENT_LINK_DIRECT)) { + var feedContext = new FeedContext(id, localize("Direct"), "approach", Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit"))); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:reducedFeedrate")) { + if (movements & (1 << MOVEMENT_REDUCED)) { + var feedContext = new FeedContext(id, localize("Reduced"), "finishing", section.getParameter("operation:reducedFeedrate")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_REDUCED] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedRamp")) { + if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("operation:tool_feedRamp")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_RAMP] = feedContext; + activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; + activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; + activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; + } + ++id; + } + if (section.hasParameter("operation:tool_feedPlunge")) { + if (movements & (1 << MOVEMENT_PLUNGE)) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("operation:tool_feedPlunge")); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_PLUNGE] = feedContext; + } + ++id; + } + + // this part allows us to use feedContext also for the cycles + if (hasParameter("operation:cycleType")) { + var cycleType = getParameter("operation:cycleType"); + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + + switch (cycleType) { + case "thread-milling": + if (hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + case "bore-milling": + if (section.hasParameter("movement:plunge")) { + var feedContext = new FeedContext(id, localize("Plunge"), "plunge", section.getParameter("movement:plunge")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (section.hasParameter("movement:ramp")) { + var feedContext = new FeedContext(id, localize("Ramping"), "ramp", section.getParameter("movement:ramp")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + if (hasParameter("movement:finish_cutting")) { + var feedContext = new FeedContext(id, localize("Finish"), "finishing", section.getParameter("movement:finish_cutting")); + addFeedContext(feedContext, activeFeeds); + ++id; + } + break; + } + } + + if (true) { // high feed + if (movements & (1 << MOVEMENT_HIGH_FEED)) { + var feedContext = new FeedContext(id, localize("High Feed"), "roughing", this.highFeedrate); + addFeedContext(feedContext, activeFeeds); + activeMovements[MOVEMENT_HIGH_FEED] = feedContext; + } + ++id; + } + return activeFeeds; +} + +/** Check that all elements are only one time in the result list. */ +function addFeedContext(feedContext, activeFeeds) { + if (activeFeeds.indexOf(feedContext) == -1) { + activeFeeds.push(feedContext); + } +} + +var currentWorkPlaneABC = undefined; + +function forceWorkPlane() { + currentWorkPlaneABC = undefined; +} + +function setWorkPlane(abc) { + if (!machineConfiguration.isMultiAxisConfiguration()) { + return; // ignore + } + if (isInspectionOperation(currentSection) && !is3D()) { + error(localize("Multi axis Inspect surface is not supported.")); + return; + } + forceWorkPlane(); // always need the new workPlane + forceABC(); + + writeBlock("MoveToSafetyPosition"); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + + setCurrentABC(abc); // required for machine simulation + currentWorkPlaneABC = abc; +} + +var closestABC = false; // choose closest machine angles +var currentMachineABC; + +function getWorkPlaneMachineABC(workPlane) { + var W = workPlane; // map to global frame + + var abc = machineConfiguration.getABC(W); + if (closestABC) { + if (currentMachineABC) { + abc = machineConfiguration.remapToABC(abc, currentMachineABC); + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + } else { + abc = machineConfiguration.getPreferredABC(abc); + } + + try { + abc = machineConfiguration.remapABC(abc); + currentMachineABC = abc; + } catch (e) { + error( + localize("Machine angles not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var direction = machineConfiguration.getDirection(abc); + if (!isSameDirection(direction, W.forward)) { + error(localize("Orientation not supported.")); + } + + if (!machineConfiguration.isABCSupported(abc)) { + error( + localize("Work plane is not supported") + ":" + + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) + + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) + + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))); + } + + var tcp = false; + if (tcp) { + setRotation(W); // TCP mode + } else { + var O = machineConfiguration.getOrientation(abc); + var R = machineConfiguration.getRemainingOrientation(abc, W); + setRotation(R); + } + + return abc; +} + +function setTCPMode(mode) { + if (getProperty("useTCP") || operationSupportsTCP) { + writeBlock(mode == TCP_ON ? "Rtcp On" : "Rtcp Off"); + } +} + +function onSection() { + currentOperation = new NewOperation(getOperationName(currentSection)); + setWriteRedirection(currentOperation.operationProgram); + + var forceToolAndRetract = optionalSection && !currentSection.isOptional(); + optionalSection = currentSection.isOptional(); + + if (!isProbeOperation(currentSection)) { + writeComment("Operation Time: " + formatCycleTime(currentSection.getCycleTime())); + } + + var showToolZMin = true; + if (showToolZMin) { + if (is3D()) { + var zRange = currentSection.getGlobalZRange(); + var number = tool.number; + zRange.expandToRange(currentSection.getGlobalZRange()); + writeComment("ZMIN = " + xyzFormat.format(zRange.getMinimum())); + } + } + + // create sub program + writeBlock("program " + getOperationName(currentSection)); + spacingDepth += 1; + + if (passThrough) { + var joinString = EOL + getSpacing(); + var passThroughString = passThrough.join(joinString); + if (passThroughString != "") { + writeBlock(passThroughString); + } + passThrough = []; + } + + // this control structure allows us to show the user the operation from the CAM application as a block of within the whole program similarly to Heidenhain structure. + writeBlock("BeginBlock name=" + "\"" + getOperationDescription(currentSection) + "\""); + var operationTolerance = tolerance; + if (hasParameter("operation:tolerance")) { + operationTolerance = Math.max(getParameter("operation:tolerance"), 0); + } + + // wcs + currentWorkOffset = undefined; // force wcs output + if (currentSection.workOffset > 0) { + if (currentSection.workOffset != currentWorkOffset) { + writeBlock(currentSection.wcs); + currentWorkOffset = currentSection.workOffset; + } + } + + if (getProperty("useSmoothing") && !currentSection.isMultiAxis() && !isProbeOperation(currentSection)) { + writeBlock("Smoothing On allowedDeviation=" + xyzFormat.format(operationTolerance * 1.2)); + } else { + writeBlock("Smoothing Off"); + } + + if (getProperty("useDynamic")) { + var dynamic = 5; + operationName = getOperationName(currentSection).toUpperCase(); + dynamicIndex = operationName.lastIndexOf("DYN"); + explicitDynamic = parseInt(operationName.substring(dynamicIndex + 3, dynamicIndex + 4), 5); + if (!isNaN(explicitDynamic) && ((explicitDynamic > 0 && explicitDynamic < 6))) { + writeBlock("Dynamic = " + explicitDynamic + " # Created from operation name"); + dynamic = explicitDynamic; + } else { + // set machine type specific dynamic sets + switch (getProperty("machineModel")) { + case "NEO": + dynamic = 5; + break; + case "MX": + case "Cube": + if (operationTolerance <= toPreciseUnit(0.04, MM)) { + dynamic = 4; + } + if (operationTolerance <= toPreciseUnit(0.02, MM)) { + dynamic = 3; + } + if (operationTolerance <= toPreciseUnit(0.005, MM)) { + dynamic = 2; + } + if (operationTolerance <= toPreciseUnit(0.003, MM)) { + dynamic = 1; + } + break; + } + writeBlock("Dynamic = " + dynamic); + } + } + if (getProperty("waitAfterOperation")) { + showWaitDialog(getOperationName(currentSection)); + } + + if (machineConfiguration.isMultiAxisConfiguration()) { + if (currentSection.isMultiAxis()) { + forceWorkPlane(); + cancelTransformation(); + var abc = currentSection.getInitialToolAxisABC(); + writeBlock("MoveToSafetyPosition"); + forceABC(); + writeBlock("Rapid" + aOutput.format(abc.x) + bOutput.format(abc.y) + cOutput.format(abc.z)); + } else { + forceWorkPlane(); + var abc = getWorkPlaneMachineABC(currentSection.workPlane); + setWorkPlane(abc); + } + } else { + // pure 3D + var remaining = currentSection.workPlane; + if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) { + error("\r\n_________________________________________" + + "\r\n| error |" + + "\r\n| |" + + "\r\n| Tool orientation detected. |" + + "\r\n| You have to specify your kinematic |" + + "\r\n| by using property 'Rotary axis setup', |" + + "\r\n| otherwise you can only post |" + + "\r\n| 3 axis programs. |" + + "\r\n| If you still have issues, |" + + "\r\n| please contact www.DATRON.com! |" + + "\r\n|________________________________________|\r\n"); + return; + } + setRotation(remaining); + } + operationSupportsTCP = currentSection.getOptimizedTCPMode() == OPTIMIZE_NONE && currentSection.isMultiAxis(); + if (!currentSection.isMultiAxis() && (useMultiAxisFeatures || isSameDirection(machineConfiguration.getSpindleAxis(), currentSection.workPlane.forward))) { + operationSupportsTCP = false; + } + if (machineConfiguration.isMultiAxisConfiguration()) { + setTCPMode(TCP_ON); + if (!multiAxisCommandsEnabled) { + SimPLProgram.usingList.push("using Rtcp"); // always required when using -MultiAxisMode on/off- since MultiAxisMode is part of library Rtcp + setWriteRedirection(SimPLProgram.mainProgram); + writeBlock("MultiAxisMode On"); + resetWriteRedirection(); + multiAxisCommandsEnabled = true; + } + } + + forceAny(); + + if (getProperty("showNotes") && currentSection.hasParameter("notes")) { + var notes = currentSection.getParameter("notes"); + if (notes) { + var lines = String(notes).split("\n"); + var r1 = new RegExp("^[\\s]+", "g"); + var r2 = new RegExp("[\\s]+$", "g"); + for (line in lines) { + var comment = lines[line].replace(r1, "").replace(r2, ""); + if (comment) { + writeComment(comment); + } + } + } + } + + var clearance = getFramePosition(currentSection.getInitialPosition()).z; + writeBlock("SafeZHeightForWorkpiece=" + xyzFormat.format(clearance)); + + // write the optional length offset for each operation + if (getProperty("useZAxisOffset")) { + writeBlock("ZAxisOffset = 0"); + } + + // radius compensation + var compensationType; + if (hasParameter("operation:compensationType")) { + compensationType = getParameter("operation:compensationType"); + } else { + compensationType = "computer"; + } + + var wearCompensation; + if (hasParameter("operation:compensationDeltaRadius")) { + wearCompensation = getParameter("operation:compensationDeltaRadius"); + } else { + wearCompensation = 0; + } + + if (true /*getProperty("writePathOffset")*/) { + switch (compensationType) { + case "computer": + break; + case "control": + writeBlock("PathOffset = 0"); + break; + case "wear": + case "inverseWear": + writeBlock("PathOffset = " + dimensionFormat.format(wearCompensation)); + break; + } + } + + if (!isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + + // set coolant after we have positioned at Z + setCoolant(tool.coolant); + + // tool changer command + if (getProperty("writeToolTable")) { + writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } else { + writeBlock("Tool = " + toolOutput.format(tool.number) + + " newRpm=" + rpmFormat.format(spindleSpeed) + + " skipRestoring" + ); + } + + // preload the next tool for the Datron tool assist + if (getProperty("preloadTool")) { + var nextTool = getNextTool(tool.number); + if (nextTool) { + if (getProperty("writeToolTable")) { + writeBlock("ProvideTool name=" + "\"" + createToolName(nextTool) + "\""); + } else { + writeBlock("ProvideTool = " + toolOutput.format(nextTool.number)); + } + } + } + + // set the current feed + // replace by the default feed command + if (getProperty("useParametricFeed") && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + if (useDatronFeedCommand) { + var datronFeedParameter = new Array(); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + var datronFeedCommand = { + name: feedContext.datronFeedName, + feed: feedFormat.format(feedContext.feed) + }; +/*eslint-disable*/ + var indexOfFeedContext = datronFeedParameter.map(function(e) {return e.name;}).indexOf(datronFeedCommand.name); + /*eslint-enable*/ + if (indexOfFeedContext == -1) { + datronFeedParameter.push(datronFeedCommand); + } else { + var existingFeedContext = datronFeedParameter[indexOfFeedContext]; + if (existingFeedContext.feed < datronFeedCommand.feed) { + existingFeedContext.feed = datronFeedCommand.feed; + } + } + } + var datronFeedCommand = "SetFeedTechnology"; + for (var i = 0; i < datronFeedParameter.length; i++) { + datronFeedCommand += " " + datronFeedParameter[i].name + "=" + datronFeedParameter[i].feed; + } + writeBlock(datronFeedCommand); + + } else { + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? " # mm/min!" : " # in/min!")); + } + } + } + } + + // parameter for the sequences + var sequenceParamter = new Array(); + + if (hasParameter("operation:cycleType")) { + // reset all movements to suppress older entries... + activeMovements = new Array(); + var cycleType = getParameter("operation:cycleType"); + writeComment("Parameter " + cycleType + " cycle"); + var cycleFeedrate = currentSection.getParameter("feedrate"); + var cyclePlungeFeedrate = currentSection.getParameter("plungeFeedrate"); + var cycleRampingFeedrate = currentSection.getParameter("operation:tool_feedRamp"); + + switch (cycleType) { + case "thread-milling": + writeBlock("SetFeedTechnology ramp=" + feedFormat.format(cycleRampingFeedrate) + " finishing=" + feedFormat.format(cycleFeedrate)); + var diameter = currentSection.getParameter("diameter"); + var pitch = currentSection.getParameter("pitch"); + var finishing = currentSection.getParameter("stepover"); + + writeBlock("nominalDiameter=" + xyzFormat.format(diameter)); + sequenceParamter.push("nominalDiameter=nominalDiameter"); + writeBlock("pitch=" + xyzFormat.format(pitch)); + sequenceParamter.push("pitch=pitch"); + if (xyzFormat.isSignificant(parseInt(finishing, 10))) { + writeBlock("finishing=" + xyzFormat.format(finishing)); + sequenceParamter.push("finishing=finishing"); + } else { + sequenceParamter.push("finishing=0"); + } + /* + writeBlock('threadName="M' + toolFormat.format(diameter) + '"'); + sequenceParamter.push('threadName=threadName'); + writeBlock("threading = " + currentSection.getParameter("threading")); + sequenceParamter.push("threading=threading"); + + TAG: den Standard auch mit Imperial unterstuezten + sequenceParamter.push("threadStandard=ThreadStandards.Metric"); + sequenceParamter.push("deburring=ThreadMillingDeburring.NoDeburring"); + sequenceParamter.push("insideOutside=ThreadMillingSide.Inside"); + sequenceParamter.push("direction=ThreadMillingDirection.RightHandThread"); + writeBlock("direction = " + dimensionFormat.format(currentSection.getParameter("direction"))); + sequenceParamter.push("direction=direction"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); +*/ + break; + case "bore-milling": + writeBlock("SetFeedTechnology roughing=" + feedFormat.format(cycleFeedrate) + " finishing=" + feedFormat.format(cycleFeedrate)); + writeBlock("diameter = " + dimensionFormat.format(currentSection.getParameter("diameter"))); + sequenceParamter.push("diameter=diameter"); + + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("pitch"))); + sequenceParamter.push("infeedZ=infeedZ"); + writeBlock("repeatPass = " + dimensionFormat.format(currentSection.getParameter("repeatPass"))); + sequenceParamter.push("repeatPass=repeatPass"); + break; + case "drilling": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(cyclePlungeFeedrate)); + break; + case "chip-breaking": + writeBlock("SetFeedTechnology plunge=" + feedFormat.format(cyclePlungeFeedrate) + " roughing=" + feedFormat.format(cycleFeedrate)); + writeBlock("infeedZ = " + dimensionFormat.format(currentSection.getParameter("incrementalDepth"))); + sequenceParamter.push("infeedZ=infeedZ"); + break; + } + } + + if (getProperty("useSequences") && !isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + // call sequence + if (getProperty("useParametricFeed") && (!useDatronFeedCommand) && !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { + activeFeeds = initializeActiveFeeds(currentSection); + for (var j = 0; j < activeFeeds.length; ++j) { + var feedContext = activeFeeds[j]; + sequenceParamter.push(formatVariable(feedContext.description) + "=" + formatVariable(feedContext.description)); + } + } + var currentSectionCall = getSequenceName(currentSection) + " " + sequenceParamter.join(" "); + writeBlock(currentSectionCall); + + // write sequence + var currentSequenceName = getSequenceName(currentSection); + if (getProperty("useExternalSequencesFiles")) { + spacingDepth -= 1; + var filename = getOutputPath(); + // sequenceFilePath = filename.substr(0, filename.lastIndexOf(".")) + "_" + currentSequenceName + ".seq"; + sequenceFilePath = FileSystem.getFolderPath(getOutputPath()) + "\\"; + sequenceFilePath += currentSequenceName + ".seq"; + redirectToFile(sequenceFilePath); + } else { + setWriteRedirection(sequenceBuffer); + writeBlock(" "); + // TAG: modify parameter + spacingDepth -= 1; + writeBlock("$$$ " + currentSequenceName); + } + } + + if (!isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + writeBlock(spindleSpeed > 100 ? "Spindle On" : "Spindle Off"); + } else { + writeBlock("Spindle Off"); + writeBlock("PrepareXyzSensor"); + } + + // move to initial Position (this command move the Z Axis to safe high and repositioning in safe high after that drive Z to end position) + var initialPosition = getFramePosition(currentSection.getInitialPosition()); + var xyz = xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z); + writeBlock("PrePositioning" + xyz); + + if (getProperty("useSuction")) { + writeBlock("Suction On"); + } + // surface Inspection + if (isInspectionOperation(currentSection) && (typeof inspectionProcessSectionStart == "function")) { + inspectionProcessSectionStart(); + } + +} + +function showWaitDialog(operationName) { + writeBlock("showWaitDialog operationName=\"" + operationName + "\""); +} + +function writeWaitProgram() { + var waitProgram = + ["# Show the wait dialog for the next operation", + "program showWaitDialog optional operationName:string", + " if not operationName hasvalue", + " operationName = " + "\"" + "\"", + " endif", + "", + " messageString = " + "\"" + "Start next Operation\r" + "\"" + " + operationName", + " dialogRes = System::Dialog message=messageString caption=" + "\"" + "Start next Operation?" + "\"" + "Yes Cancel", + " if dialogRes == System::DialogResult.Cancel", + " exit", + " endif", + "endprogram" + ]; + waitProgramOperation = {operationProgram:waitProgram.join(EOL)}; + SimPLProgram.operationList.push(waitProgramOperation); +} + +function onDwell(seconds) { + writeBlock("Sleep " + "milliseconds=" + sleepFormat.format(seconds)); +} + +function onSpindleSpeed(spindleSpeed) { + writeBlock("Rpm=" + rpmFormat.format(spindleSpeed)); +} + +var pendingRadiusCompensation = -1; + +function onRadiusCompensation() { + pendingRadiusCompensation = radiusCompensation; +} + +function onRapid(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("Rapid" + xyz); + forceFeed(); + } +} + +function onPrePositioning(x, y, z) { + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + if (xyz) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + writeBlock("PrePositioning" + xyz); + forceFeed(); + } +} + +function onLinear(x, y, z, feed) { + if (isInspectionOperation(currentSection)) { + onExpandedRapid(x, y, z); + return; + } + var xyz = ""; + xyz += (x !== null) ? xOutput.format(x) : ""; + xyz += (y !== null) ? yOutput.format(y) : ""; + xyz += (z !== null) ? zOutput.format(z) : ""; + + var f = getFeed(feed); + + if (pendingRadiusCompensation >= 0) { + pendingRadiusCompensation = -1; + var d = tool.diameterOffset; + if (d > 99) { + warning(localize("The diameter offset exceeds the maximum value.")); + } + var compensationType = undefined; + if (currentSection.hasParameter("operation:compensationType")) { + compensationType = currentSection.getParameter("operation:compensationType"); + } + + switch (radiusCompensation) { + case RADIUS_COMPENSATION_LEFT: + switch (compensationType) { + case "control": + writeBlock("ToolCompensation Left"); + writeBlock("PathCorrection Left"); + break; + case "wear": + case "inverseWear": + writeBlock("PathCorrection Left"); + break; + default: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + break; + case RADIUS_COMPENSATION_RIGHT: + switch (compensationType) { + case "control": + writeBlock("ToolCompensation Right"); + writeBlock("PathCorrection Right"); + break; + case "wear": + case "inverseWear": + writeBlock("PathCorrection Right"); + break; + default: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + break; + case RADIUS_COMPENSATION_OFF: + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + break; + } + } + + if (xyz) { + if (f) { + writeBlock(f); + } + writeBlock("Line" + xyz); + } +} + +function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { + // one of X/Y and I/J are required and likewise + var f = getFeed(feed); + + if (f) { + writeBlock(f); + } + + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); + return; + } + + var start = getCurrentPosition(); + + if (isFullCircle()) { + if (isHelical()) { + linearize(tolerance); + return; + } + // TAG: are 360deg arcs supported + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } else { + switch (getCircularPlane()) { + case PLANE_XY: + writeBlock("Arc" + + (clockwise ? " CW" : " CCW") + + xOutput.format(x) + + yOutput.format(y) + + zOutput.format(z) + + iOutput.format(cx - start.x) + + jOutput.format(cy - start.y) + ); + break; + default: + linearize(tolerance); + } + } +} + +function onRapid5D(_x, _y, _z, _a, _b, _c) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation mode cannot be changed at rapid traversal.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + + forceABC(); + var xyzabc = x + y + z + a + b + c; + writeBlock("Rapid" + xyzabc); + forceFeed(); +} + +function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { + if (pendingRadiusCompensation >= 0) { + error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); + return; + } + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + var f = getFeed(feed); + + writeBlock(f); + if (x || y || z || a || b || c) { + var xyzabc = x + y + z + a + b + c; + writeBlock("Line" + xyzabc); + } +} + +var currentCoolantMode = COOLANT_OFF; + +function setCoolant(coolant) { + if (getProperty("useCoolant")) { + if (coolant == COOLANT_OFF) { + writeBlock("SpraySystem Off"); + currentCoolantMode = COOLANT_OFF; + return; + } + + switch (coolant) { + case COOLANT_FLOOD: + case COOLANT_MIST: + writeBlock("SprayTechnology External"); + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR: + writeBlock("SprayTechnology External"); + writeBlock("Coolant Air"); + break; + case COOLANT_THROUGH_TOOL: + writeBlock("SprayTechnology Internal"); + writeBlock("Coolant Alcohol"); + break; + case COOLANT_AIR_THROUGH_TOOL: + writeBlock("SprayTechnology Internal"); + writeBlock("Coolant Air"); + break; + + default: + onUnsupportedCoolant(coolant); + } + writeBlock("SpraySystem On"); + currentCoolantMode = coolant; + } +} + +/* +var isInsideProgramDeclaration = false; +var directNcOperation; +function parseManualNc(text) { // todo + var modulePattern = new RegExp(".*(using|import)"); + var isModuleImport = modulePattern.test(text); + if (isModuleImport) { + SimPLProgram.usingList.push(text); + return; + } + + var programPattern = /(?:\s*program\s+)(\w+)/; + var isProgramDeclaration = programPattern.test(text); + if (isProgramDeclaration) { + var subProgramName = programPattern.exec(text); + if (subProgramName == undefined) { + return; + } + directNcOperation = {operationCall:subProgramName[1], operationProgram: new StringBuffer()}; + SimPLProgram.operationList.push(directNcOperation); + isInsideProgramDeclaration = true; + } + + var isEndProgram = (/\s*endprogram/).test(text); + if (isEndProgram) { + isInsideProgramDeclaration = false; + directNcOperation.operationProgram.append(text + EOL); + return; + } + + if (isInsideProgramDeclaration) { + directNcOperation.operationProgram.append(text + EOL); + return; + } + return; +} +*/ + +function onManualNC(command, value) { + if (command == COMMAND_PASS_THROUGH) { + error(localize("Manual NC pass through is currently not supported.")); + return; + } + switch (command) { + // case COMMAND_PASS_THROUGH: + // value = parseManualNc(value); + // break; + case COMMAND_COMMENT: + value = "# " + value; + break; + case COMMAND_DWELL: + value = "Sleep seconds=" + value; + break; + case COMMAND_COOLANT_OFF: + value = "SpraySystem Off"; + break; + case COMMAND_COOLANT_ON: + value = "SpraySystem On"; + break; + case COMMAND_STOP: + value = "break"; + break; + case COMMAND_START_SPINDLE: + value = "Spindle On"; + break; + case COMMAND_LOCK_MULTI_AXIS: + return; + case COMMAND_UNLOCK_MULTI_AXIS: + return; + case COMMAND_START_CHIP_TRANSPORT: + value = "ChipConveyor On"; + break; + case COMMAND_STOP_CHIP_TRANSPORT: + value = "ChipConveyor Off"; + break; + case COMMAND_OPEN_DOOR: + value = "ReleaseDoor"; + break; + case COMMAND_CLOSE_DOOR: + return; + case COMMAND_CALIBRATE: + value = "# calibration currently not supported!"; + break; + case COMMAND_VERIFY: + value = "Dialog message=\"Please check workpiece!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_CLEAN: + value = "Dialog message=\"Please clean workpiece!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_ACTION: + value = "# Action currently not supported!"; + break; + case COMMAND_PRINT_MESSAGE: + // value = 'Dialog message="' + value + '" Ok Cancel caption="Cam generated dialog"' + SimPLProgram.usingList.push("using File"); + SimPLProgram.usingList.push("using DateTimeModule"); + var message = (" value=(GetNow + \"\t" + value + "\")"); + value = "FileWriteLine filename=\"" + getProgramFilename() + ".log\"" + message; + break; + case COMMAND_DISPLAY_MESSAGE: + value = "StatusMessage message=\"" + value + "\""; + break; + case COMMAND_ALARM: + value = "Dialog message=\"Alarm!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_ALERT: + value = "Dialog message=\"Warning!\" Ok Cancel caption=\"Cam generated dialog\""; + break; + case COMMAND_BREAK_CONTROL: + value = "MeasureToolLength"; + break; + case COMMAND_TOOL_MEASURE: + value = "MeasureToolLength"; + break; + case COMMAND_OPTIONAL_STOP: + value = "OptionalBreak"; + break; + case COMMAND_CALL_PROGRAM: + var subprogramName = "SubProgram_" + SimPLProgram.externalUsermodules.length; + SimPLProgram.externalUsermodules.push("usermodule " + subprogramName + "=\"" + value + "\""); + value = subprogramName; + break; + } + + if (value != undefined) { + var operation = {operationCall:value, operationProgram:""}; + SimPLProgram.operationList.push(operation); + } +} + +var mapCommand = {}; + +var passThrough = new Array(); +function onPassThrough(text) { + passThrough.push(text); +} + +function onCommand(command) { + switch (command) { + case COMMAND_PROBE_ON: + return; + case COMMAND_PROBE_OFF: + return; + } + var stringId = getCommandStringId(command); + var mcode = mapCommand[stringId]; + if (mcode != undefined) { + writeBlock(mFormat.format(mcode)); + } else { + onUnsupportedCommand(command); + } +} + +function onCycle() { +} + +function onCycleEnd() { +} + +function isProbeOperation(section) { + return section.hasParameter("operation-strategy") && ((section.getParameter("operation-strategy") == "probe" || section.getParameter("operation-strategy") == "probe_geometry")); +} + +function isInspectionOperation(section) { + return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "inspectSurface"); +} + +function approach(value) { + validate((value == "positive") || (value == "negative"), "Invalid approach."); + return (value == "positive") ? 1 : -1; +} + +function onCyclePoint(x, y, z) { + if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "probe_geometry")) { + error(localize("Probe Geometry is not supported.")); + return; + } + if (cycleType == "inspect") { + if (typeof inspectionCycleInspect == "function") { + inspectionCycleInspect(cycle, x, y, z); + return; + } else { + cycleNotSupported(); + } + } + var feedString = feedOutput.format(cycle.feedrate); + var probeWCS = hasParameter("operation-strategy") && (getParameter("operation-strategy") == "probe"); + + if (isProbeOperation(currentSection)) { + if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { + if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { + error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); + return; + } + } + forceXYZ(); + onPrePositioning(x, y, z); // TAG would be needed for probeMultipleFeatures, but generates duplicated Prepositioning output, acceptable? + var startPositionOffset = cycle.probeClearance + tool.cornerRadius; + } + + switch (cycleType) { + case "bore-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + boreMilling(cycle); + onExpandedRapid(x, y, cycle.clearance); + } + break; + case "thread-milling": + for (var i = 0; i <= cycle.repeatPass; ++i) { + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + threadMilling(cycle); + onExpandedRapid(x, y, cycle.clearance); + } + break; + case "drilling": + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + drilling(cycle); + onExpandedRapid(x, y, cycle.clearance); + break; + /* + case "chip-breaking": + forceXYZ(); + onExpandedRapid(x, y, null); + onExpandedRapid(x, y, cycle.retract); + chipBreaking(cycle); + onExpandedRapid(x, y, cycle.clearance); + break; +*/ + + case "tapping": + case "left-tapping": + case "right-tapping": + case "tapping-with-chip-breaking": + case "left-tapping-with-chip-breaking": + case "right-tapping-with-chip-breaking": + forceXYZ(); + onExpandedRapid(x, y, cycle.clearance); + tapping(cycle); + onExpandedRapid(x, y, cycle.clearance); + break; + case "probing-x": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + if (probeWCS) { + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionX=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + if (probeWCS) { + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionY=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-z": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)), cycle.feedrate); + + var measureString = "measResult = SurfaceMeasure "; + if (probeWCS) { + measureString += " originZShift=" + xyzFormat.format(z - cycle.depth); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedZPos=" + xyzFormat.format(z - cycle.depth); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-wall": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-wall": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionY=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-channel": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-channel-with-island": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " YAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-channel": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionY=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-channel-with-island": + var measureString = "measResult = SymmetryAxisMeasure"; + measureString += " width=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " XAligned"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionY=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-circular-boss": + var measureString = "measResult = CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-circular-hole": + var measureString = "measResult = CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-circular-hole-with-island": + var measureString = "measResult = CircleMeasure"; + measureString += " diameter=" + xyzFormat.format(cycle.width1); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " measureZPos=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-rectangular-boss": + var measureString = "measResult = RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Outside"; + measureString += " Center"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1) + + " expectedDimensionY=" + xyzFormat.format(cycle.width2); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-rectangular-hole": + var measureString = "measResult = RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " Center"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1) + + " expectedDimensionY=" + xyzFormat.format(cycle.width2); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-rectangular-hole-with-island": + var measureString = "measResult = RectangleMeasure"; + measureString += " dimensionX=" + xyzFormat.format(cycle.width1); + measureString += " dimensionY=" + xyzFormat.format(cycle.width2); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " Inside"; + measureString += " Center"; + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " expectedDimensionX=" + xyzFormat.format(cycle.width1) + + " expectedDimensionY=" + xyzFormat.format(cycle.width2); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-inner-corner": + /* + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "measResult = EdgeMeasure "; + zOutput.reset(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + //zOutput.reset(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + */ + var isXNegative = (cycle.approach1 == "negative"); + var isYNegative = (cycle.approach2 == "negative"); + + var orientation = ""; + + if (isXNegative) { + orientation = isYNegative ? "FrontLeft" : "BackLeft"; + } else { + orientation = isYNegative ? "FrontRight" : "BackRight"; + } + + var measureString = "measResult = CornerMeasure"; + measureString += " " + orientation; + measureString += " Inside"; + measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " measureDirectionX=" + cycle.approach1 + + " measureDirectionY=" + cycle.approach2; + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-xy-outer-corner": + /* + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var touchPositionY1 = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var measureString = "measResult = EdgeMeasure "; + zOutput.reset(); + onExpandedRapid(x, y, probingDepth); + onExpandedLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (x + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onExpandedLinear(x, touchPositionY1, probingDepth, cycle.feedrate); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + //forceXYZ(); + //zOutput.reset(); + onExpandedLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onExpandedLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + */ + var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel); + var probingDepth = (z - cycle.depth + tool.cornerRadius); + var measureString = "measResult = EdgeMeasure "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " originShift=" + xyzFormat.format(-1 * (y + approach(cycle.approach1) * startPositionOffset)); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + writeBlock(measureString); + forceXYZ(); + onExpandedLinear(touchPositionX1, y, probingDepth, cycle.feedrate); + onExpandedLinear(x, y, probingDepth, cycle.feedrate); + + var isXNegative = (cycle.approach1 == "negative"); + var isYNegative = (cycle.approach2 == "negative"); + + var orientation = ""; + if (isXNegative) { + orientation = isYNegative ? "BackRight" : "FrontRight"; + } else { + orientation = isYNegative ? "BackLeft" : "FrontLeft"; + } + + var measureString = "measResult = CornerMeasure"; + measureString += " " + orientation; + measureString += " Outside"; + measureString += " xMeasureYOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " yMeasureXOffset=" + xyzFormat.format(cycle.probeClearance); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " xMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " yMeasureZOffset=" + xyzFormat.format((z - cycle.depth + tool.diameter / 2)); + measureString += " forceSafeHeight"; + measureString += " skipZMeasure"; + if (probeWCS) { + measureString += " originXShift=" + xyzFormat.format(-x); + measureString += " originYShift=" + xyzFormat.format(-y); + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x) + + " expectedYPos=" + xyzFormat.format(y) + + " measureDirectionX=" + cycle.approach1 + + " measureDirectionY=" + cycle.approach2; + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-x-plane-angle": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasureV2 "; + measureString += (cycle.approach1 == "positive" ? "XPositive" : "XNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " offsetForRotation=" + xyzFormat.format(cycle.probeSpacing); + measureString += " setRotationOnly=true"; + if (probeWCS) { + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedXPos=" + xyzFormat.format(x + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionX=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + case "probing-y-plane-angle": + forceXYZ(); + onExpandedRapid(x, y, cycle.stock); + onExpandedLinear(x, y, (z - cycle.depth + tool.cornerRadius), cycle.feedrate); + + var measureString = "measResult = EdgeMeasureV2 "; + measureString += (cycle.approach1 == "positive" ? "YPositive" : "YNegative"); + measureString += " searchDistance=" + xyzFormat.format(cycle.probeClearance); + measureString += " offsetForRotation=" + xyzFormat.format(cycle.probeSpacing); + measureString += " setRotationOnly=true"; + if (probeWCS) { + writeBlock(measureString); + } else { + measureString += " None"; + writeBlock(measureString); + expectedArgs = "expectedYPos=" + xyzFormat.format(x + approach(cycle.approach1) * startPositionOffset) + + " measureDirectionY=" + (cycle.approach1 == "positive" ? "positive" : "negative"); + writeBlock(getProbingArguments(cycle, undefined, expectedArgs)); + } + break; + default: + expandCyclePoint(x, y, z); + return; + } + + // save probing result in defined wcs + if (probeWCS && currentSection.workOffset !== undefined) { + writeBlock("SaveWcs name=\"" + currentSection.workOffset + "\""); + } + return; +} + +function getProbingArguments(cycle, probeWorkOffsetCode, additionalArguments) { + var toolToCompensate; + var tools = getToolTable(); + if (tools.getNumberOfTools()) { + for (var i = 0; i < tools.getNumberOfTools(); ++i) { + var tool = tools.getTool(i); + if (tool.number == cycle.toolWearNumber) { + toolToCompensate = tool; + } + } + } + + return [ + "ProbeGeometry measResult=measResult", + (cycle.angleAskewAction == "stop-message" ? "angleTolerance=" + xyzFormat.format(cycle.toleranceAngle ? cycle.toleranceAngle : 0) : undefined), + ((cycle.updateToolWear && cycle.toolWearErrorCorrection < 100) ? "toolWearErrorCorrection=" + xyzFormat.format(cycle.toolWearErrorCorrection ? cycle.toolWearErrorCorrection / 100 : 100) : undefined), + (cycle.wrongSizeAction == "stop-message" ? "sizeTolerance=" + xyzFormat.format(cycle.toleranceSize ? cycle.toleranceSize : 0) : undefined), + (cycle.outOfPositionAction == "stop-message" ? "positionTolerance=" + xyzFormat.format(cycle.tolerancePosition ? cycle.tolerancePosition : 0) : undefined), + (cycle.updateToolWear ? "toolToUpdateWear=\"" + createToolName(toolToCompensate) + "\"" : undefined), + ((cycle.updateToolWear && cycleType == "probing-z") ? "Length" : undefined), + ((cycle.updateToolWear && cycleType !== "probing-z") ? "Diameter" : undefined), + (cycle.updateToolWear ? "toolUpdateTreshold=" + xyzFormat.format(cycle.toolWearUpdateThreshold ? cycle.toolWearUpdateThreshold : 0) : undefined), + (cycle.printResults ? "printResults" : undefined), + conditional(probeWorkOffsetCode && probeWCS, "S" + probeWorkOffsetCode), + additionalArguments + ]; +} + +function programIncludesOperationType(operationType) { + var numberOfSections = getNumberOfSections(); + for (var i = 0; i < numberOfSections; ++i) { + var section = getSection(i); + if (operationType == "probe") { + if (isProbeOperation(section)) { + return true; + } + } else if (operationType == "inspection") { + if (isInspectionOperation(section)) { + return true; + } + } else { + error(localize("Unsupported operation type.")); + } + } + return false; +} + +function writeProbingProgram() { + + addVariable("enumeration toolWearGeometry (Diameter, Length)"); + addVariable("enumeration direction (positive, negative)"); + + addModuleReference("import Math"); + addModuleReference("import ToolChangingUtilities"); + addModuleReference("import ToolParameter"); + addModuleReference("import ToolData"); + + // TAG add import Math + probingProgram = [ + "program ProbeGeometry(", + " measResult:MeasuringDataWithInfo", + " optional expectedDimensionX:number", + " optional expectedDimensionY:number", + " optional expectedXPos:number", + " optional expectedYPos:number", + " optional expectedZPos:number ", + " optional measureDirectionX:direction ", + " optional measureDirectionY:direction ", + " optional toolUpdateTreshold:number", + " optional toolWearErrorCorrection:number", + " optional positionTolerance:number ", + " optional angleTolerance:number", + " optional sizeTolerance:number", + " optional toolToUpdateWear:string", + " optional updateToolWear:toolWearGeometry", + " optional printResults:boolean)", + "", + " # Tolerance check", + " if sizeTolerance hasvalue ", + " outOfDimension:boolean", + " if expectedDimensionX hasvalue", + " outOfDimension = Math::Abs(expectedDimensionX - measResult.DimensionX) > sizeTolerance ", + " endif", + " if expectedDimensionY hasvalue", + " outOfDimension = Math::Abs(expectedDimensionY - measResult.DimensionY) > sizeTolerance ", + " endif", + " ", + " if outOfDimension", + " Dialog message=\"Geometrie out of tolerance\" caption=\"Geometrie out of tolerance\" Error", + " endif", + " endif", + " ", + " # Angle check", + " if angleTolerance hasvalue", + " if measResult.MeasuredTransformation.RotationZ > angleTolerance", + " Dialog message=\"Angle out of tolerance\" caption=\"Angle out of tolerance\" Error ", + " endif", + " endif", + " ", + " # Tool wear", + " if updateToolWear hasvalue and toolToUpdateWear hasvalue", + " if updateToolWear == toolWearGeometry.Diameter", + " # get the radius correction from dimension otherwise from position ", + " radiusCorrection:number", + " if (expectedDimensionX hasvalue or expectedDimensionY hasvalue)", + " if (expectedDimensionX hasvalue and expectedDimensionY hasvalue)", + " radiusCorrection = (", + " (expectedDimensionX - measResult.DimensionX) +", + " (expectedDimensionX - measResult.DimensionX)) / 4", + " endif", + " if (expectedDimensionX hasvalue and not expectedDimensionY hasvalue)", + " radiusCorrection = (expectedDimensionX - measResult.DimensionX) / 2", + " endif", + " if (not expectedDimensionX hasvalue and expectedDimensionY hasvalue)", + " radiusCorrection = (expectedDimensionY - measResult.DimensionY) / 2", + " endif ", + " else ", + " isXMeasure = expectedXPos hasvalue and measureDirectionX hasvalue", + " isYMeasure = expectedYPos hasvalue and measureDirectionY hasvalue ", + " if (isXMeasure or isYMeasure)", + " if (isXMeasure and not isYMeasure)", + " radiusCorrection = (expectedXPos - measResult.MeasuredPosition.X) * GetSignFromDirection(measureDirectionX)", + " endif", + " if (isYMeasure and not isXMeasure)", + " radiusCorrection = (expectedYPos - measResult.MeasuredPosition.Y) * GetSignFromDirection(measureDirectionY)", + " endif", + " if( isXMeasure and isYMeasure)", + " radiusCorrection = (", + " (expectedXPos - measResult.MeasuredPosition.X) * GetSignFromDirection(measureDirectionX) + ", + " (expectedYPos - measResult.MeasuredPosition.Y) * GetSignFromDirection(measureDirectionY) ", + " ) / 2 ", + " endif ", + " endif ", + " endif", + " ", + // TAG code below needs to get fixed for type we, + " toolId = ToolChangingUtilities::GetToolIdFromToolName(toolToUpdateWear)", + " newDiameter = ToolParameter::GetToolDiameter(toolNumber=toolId) - radiusCorrection * 2", + " ToolData::SetToolGeometry Diameter=newDiameter toolId=toolId", + " else", + " # length correction", + " ", + " endif", + " endif ", + " ", + " # Position", + " if positionTolerance hasvalue", + " isOutOfTolerance: boolean", + " if expectedXPos hasvalue", + " isOutOfTolerance = Math::Abs(expectedXPos - measResult.MeasuredPosition.X) > positionTolerance ", + " endif", + " if expectedYPos hasvalue", + " isOutOfTolerance = Math::Abs(expectedYPos - measResult.MeasuredPosition.Y) > positionTolerance ", + " endif", + " if expectedZPos hasvalue", + " isOutOfTolerance = Math::Abs(expectedZPos - measResult.MeasuredPosition.Z) > positionTolerance ", + " endif ", + " if isOutOfTolerance", + " Dialog message=\"Position out of tolerance\" caption=\"Position out of tolerance\" Error", + " endif", + " endif ", + "endprogram", + "", + "function GetSignFromDirection(dir:direction) returns number", + " if dir == direction.positive", + " return 1", + " endif ", + " return -1 ", + "endfunction" + ]; + + probingProgramOperation = {operationProgram:probingProgram.join(EOL)}; + SimPLProgram.operationList.push(probingProgramOperation); +} + +function drilling(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + writeBlock(boreCommandString.join(" ")); +} + +function chipBreaking(cycle) { + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + boreCommandString.push("Drill"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + boreCommandString.push("infeedZ=infeedZ"); + writeBlock(boreCommandString.join(" ")); +} + +function boreMilling(cycle) { + var numberOfSteps = (cycle.numberOfSteps != undefined) ? cycle.numberOfSteps : 0; + if (numberOfSteps > 2) { + error("Only 2 steps are allowed for bore-milling."); + } + + var boreCommandString = new Array(); + var depth = xyzFormat.format(cycle.depth); + boreCommandString.push("DrillMilling"); + boreCommandString.push("diameter=diameter"); + boreCommandString.push("depth=" + depth); + boreCommandString.push("infeedZ=infeedZ"); + boreCommandString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + boreCommandString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + + if (numberOfSteps == 2) { + var xycleaning = cycle.stepover; + var maxzdepthperstep = tool.fluteLength * 0.8; + boreCommandString.push("finishingXY=" + xyzFormat.format(xycleaning)); + boreCommandString.push("infeedFinishingZ=" + xyzFormat.format(maxzdepthperstep)); + } + var bottomcleaning = 0; + // finishingZ = 1; + writeBlock(boreCommandString.join(" ")); +} + +function threadMilling(cycle) { + var threadString = new Array(); + var depth = xyzFormat.format(cycle.depth); + + threadString.push("SpecialThread"); + // threadString.push('threadName=threadName'); + threadString.push("nominalDiameter=nominalDiameter"); + threadString.push("pitch=pitch"); + threadString.push("depth=" + depth); + threadString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + threadString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + if (getProperty("createThreadChamfer")) { + threadString.push("Deburring"); + } + // threadString.push("insideOutside=ThreadMillingSide.Inside"); + threadString.push("finishing=finishing"); + if (cycle.threading == "left") { + threadString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + threadString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(threadString.join(" ")); +} + +function tapping(cycle) { + var tappingString = new Array(); + var depth = xyzFormat.format(cycle.depth); + tappingString.push("ThreadCutting"); + tappingString.push("pitch=" + xyzFormat.format(tool.threadPitch)); + tappingString.push("depth=" + depth); + tappingString.push("strokeRapidZ=" + xyzFormat.format(cycle.clearance - cycle.retract)); + tappingString.push("strokeCuttingZ=" + xyzFormat.format(cycle.retract - cycle.stock)); + tappingString.push("threadRpm=" + rpmFormat.format(spindleSpeed)); + if (cycleType == "tapping-with-chip-breaking" || cycleType == "left-tapping-with-chip-breaking" || cycleType == "right-tapping-with-chip-breaking") { + tappingString.push("breakChipInfeed=" + xyzFormat.format(cycle.incrementalDepth)); + } + if (tool.type == TOOL_TAP_LEFT_HAND) { + tappingString.push("direction=ThreadMillingDirection.LeftHandThread"); + } else { + tappingString.push("direction=ThreadMillingDirection.RightHandThread"); + } + writeBlock(tappingString.join(" ")); +} + +function formatCycleTime(cycleTime) { + // cycleTime = cycleTime + 0.5; // round up + var seconds = cycleTime % 60 | 0; + var minutes = ((cycleTime - seconds) / 60 | 0) % 60; + var hours = (cycleTime - minutes * 60 - seconds) / (60 * 60) | 0; + if (hours > 0) { + return subst(localize("%1h:%2m:%3s"), hours, minutes, seconds); + } else if (minutes > 0) { + return subst(localize("%1m:%2s"), minutes, seconds); + } else { + return subst(localize("%1s"), seconds); + } +} + +function dump(name, _arguments) { + var result = getCurrentRecordId() + ": " + name + "("; + for (var i = 0; i < _arguments.length; ++i) { + if (i > 0) { + result += ", "; + } + if (typeof _arguments[i] == "string") { + result += "'" + _arguments[i] + "'"; + } else { + result += _arguments[i]; + } + } + result += ")"; + writeln(result); +} + +function onSectionEnd() { + if (typeof inspectionProcessSectionEnd == "function") { + inspectionProcessSectionEnd(); + } + writeBlock("ToolCompensation Off"); + writeBlock("PathCorrection Off"); + if (getProperty("useZAxisOffset")) { + writeBlock("ZAxisOffset = 0"); + } + setTCPMode(TCP_OFF); + + if (getProperty("useSuction")) { + writeBlock("Suction Off"); + } + + if (getProperty("useSequences") && !isProbeOperation(currentSection) && !isInspectionOperation(currentSection)) { + if (!getProperty("useExternalSequencesFiles")) { + resetWriteRedirection(); + } + spacingDepth += 1; + } + + writeBlock("EndBlock"); + + spacingDepth -= 1; + + writeBlock("endprogram " + "# " + getOperationName(currentSection)); + resetWriteRedirection(); + SimPLProgram.operationList.push(currentOperation); + forceAny(); +} + +function writeBuffer(buffer) { + if (buffer.length > 0) { + writeBlock(buffer.join(EOL) + EOL); + writeBlock(""); + } +} + +// after all the oiperation calls are set close the main program with all the calls +function finishMainProgram() { + // write the main program footer + setWriteRedirection(SimPLProgram.mainProgram); + spacingDepth += 1; + + // write all subprogram calls in the main Program + for (var i = 0; i < SimPLProgram.operationList.length; ++i) { + writeBlock(SimPLProgram.operationList[i].operationCall); + } + + if (getProperty("useCoolant")) { + writeBlock("SpraySystem Off"); + } + + if (multiAxisCommandsEnabled) { + writeBlock("MultiAxisMode Off"); + setTCPMode(TCP_OFF); + } + + setWorkPlane(new Vector(0, 0, 0)); // reset working plane + if (getProperty("useParkPosition")) { + writeBlock("Spindle Off"); + writeBlock("MoveToParkPosition"); + } else { + writeBlock("MoveToSafetyPosition"); + zOutput.reset(); + } + + spacingDepth -= 1; + writeBlock("endprogram #" + (programName ? (SP + formatComment(programName)) : "") + ((unit == MM) ? " MM" : " INCH")); + resetWriteRedirection(); +} + +// add a varibale to the global declarations +function addVariable(value) { + if (SimPLProgram.globalVariableList.indexOf(value) == -1) { + SimPLProgram.globalVariableList.push(value); + } +} +// add a varibale to the global declarations +function addModuleReference(value) { + if (SimPLProgram.usingList.indexOf(value) == -1) { + SimPLProgram.usingList.push(value); + } +} + +// Start of onRewindMachine logic +/** Allow user to override the onRewind logic. */ +function onRewindMachineEntry(_a, _b, _c) { + return false; +} + +/** Retract to safe position before indexing rotaries. */ +function onMoveToSafeRetractPosition() { + writeBlock("MoveToSafetyPosition"); + // cancel TCP so that tool doesn't follow rotaries + setTCPMode(TCP_OFF); +} + +/** Rotate axes to new position above reentry position */ +function onRotateAxes(_x, _y, _z, _a, _b, _c) { + // position rotary axes + xOutput.disable(); + yOutput.disable(); + zOutput.disable(); + invokeOnRapid5D(_x, _y, _z, _a, _b, _c); + setCurrentABC(new Vector(_a, _b, _c)); + xOutput.enable(); + yOutput.enable(); + zOutput.enable(); +} + +/** Return from safe position after indexing rotaries. */ +function onReturnFromSafeRetractPosition(_x, _y, _z) { + // reinstate TCP / tool length compensation + setTCPMode(TCP_ON); + forceXYZ(); + onPrePositioning(_x, _y, _z); +} +// End of onRewindMachine logic + +function onClose() { + + if (getProperty("waitAfterOperation")) { + writeWaitProgram(); + } + spacingDepth = 0; + + // check for additional subprograms + if (programIncludesOperationType("inspection") && typeof writeInspectionProgram == "function") { + writeInspectionProgram(); + } + + if (programIncludesOperationType("probe")) { + writeProbingProgram(); + } + + writeBlock(SimPLProgram.moduleName); + writeBlock(""); + writeBuffer(SimPLProgram.toolDescriptionList); + writeBlock(SimPLProgram.workpieceGeometry); + writeBlock(""); + writeBuffer(SimPLProgram.sequenceList); + writeBuffer(SimPLProgram.usingList); + writeBuffer(SimPLProgram.externalUsermodules); + writeBuffer(SimPLProgram.globalVariableList); + + finishMainProgram(); + writeBlock(SimPLProgram.mainProgram); + writeBlock(""); + + for (var i = 0; i < SimPLProgram.operationList.length; ++i) { + writeBlock(SimPLProgram.operationList[i].operationProgram); + } + + writeBlock("end"); + + if (getProperty("useSequences") && !getProperty("useExternalSequencesFiles")) { + writeComment(spacing); + writeBlock(sequenceBuffer.toString()); + } +} + +function setProperty(property, value) { + properties[property].current = value; +}