Overview

The StixCtlGenerate class functions return a string description of the current state of an StixCtlCursor object. To generate a G-code program, select the style of machine, iterate over a STEP-NC process, stopping at each event, and print the string returned by the formatEvent() function. It is easy to substitute your own logic for tool changes, program start, etc. Simply watch for the event and emit your own codes instead of the ones returned by the format object.

There are a variety of built-in styles: G-Code for Fanuc, Haas, Heidenhain, Okuma, Siemens style controls, five axis via TCP with IJK, AC, BC, or AB moves, Renishaw and native probing cycles, as well as other languages like APT, DMIS, or CRCL. Call setStyle() to start with a base style and modify many different aspects of the output.

The formatting functions take a StixCtlCursor which gives the position in the process. They also take a StixCtlGenerateState object which tracks the current commanded state of the machine tool axes and modal variables.

If you wish to augment the output with your own codes, the cat* functions (catNumber(), catParam(), etc.) and format* functions (formatBlock(), formatComment(), formatOther(), formatMoveXYZ(), etc.) can help you build codes quickly and flexibly.

Examples

The simple example below reads a STEP-NC file and calls exportCNCFile() to print Haas-style codes for the entire process to the "program.nc" file.

#include <stixctl.h>
#include <STModule.h>

int main (int argc, char **argv)
{
    stplib_init();		// initialize libraries
    ST_MODULE_FORCE_LOAD();

    // Read the STEP-NC file and recognize constructs
    RoseDesign * d = ROSE.findDesign ("datafile.stpnc");
    stix_tag_units(d);
    ARMpopulate(d);

    StixCtlGenerate fmt;
    fmt.setStyle("haas");  // set HAAS as desired style
    fmt.exportCNCFile(d, "program.nc");   // export codes
    
    return 0;
}

The example below replaces exportCNCFile() with its own loop with StixCtlCursor for more control over the output. It also creates Haas-style codes, but prints them to the console and adds some customization for the start of the program and tool changes. The tool change logic uses one of the utility functions provided by the class to print an informative tool change comment, but substitutes its own logic for the change.

#include <stixctl.h>
#include <STModule.h>

int main (int argc, char **argv)
{
    stplib_init();		// initialize libraries
    ST_MODULE_FORCE_LOAD();

    // Read the STEP-NC file and recognize constructs
    RoseDesign * d = ROSE.findDesign ("datafile.stpnc");
    stix_tag_units(d);
    ARMpopulate(d);

    StixCtlCursor ctl;
    StixCtlGenerate fmt;
    StixCtlGenerateState vars;
    fmt.setStyle("haas");  // set HAAS as desired style

    // export codes with some customization
    ctl.startProject(d);    // Start a traversal of the process
    ctl.setWantedAll(1);
    fmt.setUnitSystem(ctl);   
    
    while (ctl.next()) {
	switch (ctl.event()) {
	case STIXCTL_PROJECT_START:
	    // print a comment and follow with our logic
	    fputs(fmt.formatComment(vars,"My great program"), stdout);
	    printf("My program start logic here\n");
	    break;
    
	case STIXCTL_TOOL_CHANGE:
	    // print a description of the tool and follow with our logic
	    fputs(fmt.formatOther(vars,ctl,"tool-comment"), stdout);
	    printf("My tool change logic here\n");
	    break;

	default:
	    // print the haas codes from the formatting class
	    const char * str = fmt.formatEvent(vars, ctl);
	    if (str) fputs(str, stdout);
	    break;
	}
    }
    return 0;
}

When run against a sample process, this second example generates the following. The custom program start and tool change portions are highlighted.

(MY GREAT PROGRAM)
My program start logic here
(MSG,FACE TOP OF PART)
(WORKINGSTEP: LINE 33 WS 1)
(TOOL CHANGE: TOOL 1)
( DIAMETER: 25.4MM)
( CORNER RADIUS: 0.508MM)
( TAPER: 0DEG)
( TIP ANGLE: 0DEG)
My tool change logic here
M3S2000
M08
G0X0.Y0.Z-2.54
X-184.15Y143.51Z-55.88
Z-80.772
G1X-152.4F1016.
X152.4
Y124.46
X-152.4
[ ... and so on ... ]

If we change the style string from "haas" to "heidenhain", our program will produce rather different output:

; My great program
My program start logic here
; Workingstep: line 33 WS 1
; TOOL CHANGE: TOOL 1
;  diameter: 25.4mm
;  corner radius: 0.508mm
;  taper: 0deg
;  tip angle: 0deg
My tool change logic here
N1 S2000 M3
N2 M08
N3 G0 X0 Y0 Z-2.54 A0 C0
N4 X-184.15 Y143.51 Z-55.88
N5 Z-80.772
N6 G1 X-152.4 F1016
N7 X152.4
N8 Y124.46
N9 X-152.4
[ ... and so on ... ]

StixCtlGenerateFn (type)

typedef RoseStringObject (*StixCtlGenerateFn) (
	StixCtlGenerate &fmt,
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor
	);

The StixCtlGenerateFn typedef is a function pointer that takes a generator object, a vars object, and a cursor object. The function examines the position in the process and given state of the output and returns a string object with the result. Almost all of the formatting functions use this pattern.

StixCtlGenerateStringFn (type)

typedef RoseStringObject (*StixCtlGenerateStringFn) (
	StixCtlGenerate &fmt,
	StixCtlGenerateState &vars,
	const char *
	);

The StixCtlGenerateStringFn typedef is a function pointer that takes a generator object, a vars object, and a string. The function examines the string and given state of the output and returns a string object with the result. The comment formatting functions use this pattern.

catNumber()

void catNumber(
	RoseStringObject &s,
	double num
	);
	
void catNumber(
	RoseStringObject &s,
	double num,
	int max_digits,
	int min_digits=-1
	);

The catNumber() function formats a floating point number as a string with a given maximum and minimum digits of precision. The result is concatenated to the end of the supplied string object. The first version uses the getDigits() and getMinDigits() values.

CNC systems usually have a maximum number of digits, but some may also require a minimum number. By default the minimum digits is -1, which removes the trailing decimal point for integer values. If this is 0, the decimal point is retained.

input 1.234567
max=5, min=-1 => 1.23457
max=2, min=-1 => 1.23

input 1.2
max=5, min=-1 => 1.2
max=2, min=0  => 1.2
max=2, min=2  => 1.20

input 1
max=5, min=-1 => 1
max=2, min=0  => 1.
max=2, min=2  => 1.00

catNumberAsAngle()

void catNumberAsAngle(
	RoseStringObject &s,
	double num
	);

The catNumberAsAngle() function is a wrapper around catNumber() that formats an angle value with the getAngleDigits() and getAngleMinDigits() precision values.

catNumberAsFeed()

void catNumberAsFeed(
	RoseStringObject &s,
	double num
	);

The catNumberAsFeed() function is a wrapper around catNumber() that formats a feedrate value with the getFeedDigits() and getFeedMinDigits() precision values.

catNumberAsIJK()

void catNumberAsIJK(
	RoseStringObject &s,
	double num
	);

The catNumberAsIJK() function is a wrapper around catNumber() that formats an IJK direction component value with the getIJKDigits() and getIJKMinDigits() precision values.

catNumberAsSpindle()

void catNumberAsSpindle(
	RoseStringObject &s,
	double num
	);

The catNumberAsSpindle() function is a wrapper around catNumber() that formats a spindle speed value with the getSpindleDigits() and getSpindleMinDigits() precision values.

catParam()

void catParam(
	RoseStringObject &s,
	const char * param
	);
	
void catParam(
	RoseStringObject &s,
	const char * param,
	double num
	);

void catParam(
	RoseStringObject &s,
	const char * param,
	double num,
	int max_digits,
	int min_digits=-1
	);

The catParam() function appends a string for a parameter name and possibly a formatted number, separated by whitespace if the getUseWhitespace() preference is true. This function is simply a more concise way equivalent to add optional whitespace, add the parameter string, and then a number formatted with catNumber().

catParamAsAngle()

void catParamAsAngle(
	RoseStringObject &s,
	const char * param,
	double num
	);

The catParamAsAngle() function is a wrapper around catParam() that formats an angle value with the getAngleDigits() and getAngleMinDigits() precision values.

catParamAsFeed()

void catParamAsFeed(
	RoseStringObject &s,
	const char * param,
	double num
	);

The catParamAsFeed() function is a wrapper around catParam() that formats a feedrate value with the getFeedDigits() and getFeedMinDigits() precision values.

catParamAsIJK()

void catParamAsIJK(
	RoseStringObject &s,
	const char * param,
	double num
	);

The catParamAsIJK() function is a wrapper around catParam() that formats an IJK direction component value with the getIJKDigits() and getIJKMinDigits() precision values.

catParamAsSpindle()

void catParamAsSpindle(
	RoseStringObject &s,
	const char * param,
	double num
	);

The catParamAsSpindle() function is a wrapper around catParam() that formats a spindle speed value with the getSpindleDigits() and getSpindleMinDigits() precision values.

catRequiredSpace()

void catRequiredSpace (RoseStringObject &s);

The catRequiredSpace() function is a low-level function used to construct formatted text. It appends whitespace to the end of a string if the original string is not empty. This function is used for separating parameters when whitespace is always required.

catSpace()

void catSpace (RoseStringObject &s);

The catSpace() function is a low-level function used to construct formatted text. It appends whitespace to the end of a string if the original string is not empty and if the getUseWhitespace() flag is true. This function is used to separate parameters that may or may not have space between them, like coordinates in a G-code block.

exportCNCFile()

int exportCNCFile (
	RoseDesign * design,
	const char * filename
	);

The exportCNCFile() function is a simple wrapper that writes a file containing the output returned by formatEvent() for the contents of the given design. The output will be generated for all enabled executables using the current format settings of the StixCtlGenerate object. The function returns non-zero if the file was exported successfully.

The sample program at the top of this page shows an alternative way of making codes, where you handle the loop yourself for customized output.

formatBlock()

RoseStringObject formatBlock(
	StixCtlGenerateState &vars,
	const char * str
	);

The formatBlock() function is a low-level function used to construct formatted text. This takes a string, adds a newline, and prepends a block number (eg. "N1234") if the getUseBlocknums() flag is true. The block number is given by vars.getNextBlocknum().

formatBlockNonum()

RoseStringObject formatBlockNonum(
	StixCtlGenerateState &vars,
	const char * str
	);

The formatBlockNonum() function is a low-level function used to construct formatted text. This takes a string and adds a newline. It is used for things that must never have a block number.

formatComment()

RoseStringObject formatComment(
	StixCtlGenerateState &vars,
	const char * str
	);

RoseStringObject formatComment(
	StixCtlGenerateState &vars,
	const char * header,
	const char * str
	);

The formatComment() function is a low-level function used to encodes the input string as a comment in the manner appropriate for the output style. If two strings are given, they are concatenated with a colon separator as "header: str". The function may return a null string if an empty input string is given.

The comment formatting may convert the strings to uppercase, strip unsupported characters, and wrap the string with delimiters. You can provide your handling with setCommentFn() but this is typically used only when adding new predefined styles.

formatEvent()

RoseStringObject formatEvent (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor
	);

The formatEvent() function is the main process formatting function. This examines the most recent event() in the cursor and calls one or more formatting functions to build a string that represents it. The function may return a null string if nothing is needed.

Usually the cursor position is not changed, but sometimes formatting will advance the cursor. For example, when starting a probing operation, the formatting may iterate over the entire operation and return all of the moves necessary for the approach, touch and retract of the probe. The "vars" object is updated.

You can provide your own formatting function for an event with setEventFn(), but this is typically used only when adding new predefined styles.

StixCtlCursor ctl;
StixCtlGenerate fmt;
StixCtlGenerateState vars;

while (ctl.next()) {
    const char * str = fmt.formatEvent(vars, ctl);
    if (str) fputs(str, stdout);
}

formatMoveXYZ()

RoseStringObject formatMoveXYZ (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor,
	const RosePoint xyz
	);

The formatMoveXYZ() function returns a move command as if processing a MOVE event, but the given position is supplied by the caller rather than taken from a toolpath curve. The tool axis is not changed - use formatMoveXYZ_IJK() to change the tool direction.

The position is given in program units and "vars" is updated. The position is used exactly as passed in, no destination transform is applied. The feed rate is not changed.

The function may return a null string if no move is needed.

formatMoveXYZ_IJK()

RoseStringObject formatMoveXYZ_IJK (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor,
	const RosePoint xyz,
	const RoseDirection ijk
	);

The formatMoveXYZ() function returns a move command as if processing a MOVE event, but the given position and tool axis direction is supplied by the caller rather than taken from a toolpath curve.

The position is given in program units and "vars" is updated. The position is used exactly as passed in, no destination transform is applied. The feed rate is not changed.

The function may return a null string if no move is needed.

formatOther()

RoseStringObject formatOther (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor,
	const char * name
	);

The formatOther() function keeps a dictionary of functions used by formatEvent() to construct parts of the result text from the active state of the "cursor" and "vars" objects. The functions update "vars" as necessary and may advance the cursor. The function may return a null string if no move is needed.

The functions are called by name and the behavior associated with a given name can be changed with the setOtherFn() function.

In our earlier example we called the "tool-comment" function. A partial list of available functions is shown below:

"coolant"
Turns flood, mist, or through-spindle coolant on or off as necessary based on the coolant state held by "vars" and the state of getMoveIsCoolant(), getMoveIsMistCoolant(), and getMoveIsThruCoolant(). Calls "coolant-off" if needed to turn everything off. Called by the toolpath start event handling.
"coolant-off"
Turns off all coolant. Called by the tool change and program end event handling.
"filename"
Returns the name of the STEP-NC file as a comment. Usually called by the program start event handling.
"move-contact"
This is called by the MOVE event handling. If the cursor is currently traversing a cutter contact toolpath, this function examines the tool axis, movement direction, and surface normal direction. If it determines that the tool is contacting left or right, it will return the result of calling "refpoint-left" or "refpoint-right" respectively.
"move-feed"
This is called by the MOVE event handling. It examines the getMoveFeed() and any speed override settings and if the feedrate has changed, it returns a new feed command. Depending on the value of getFeedIsStandalone(), this is either returned on a separate line or appended to the end of the move command.
"move-ijk"
This is called by the MOVE event handling. It examines the tool axis direction returned by getOutDirZ() and formats the tool axis portion of the movement command. This function may be set to versions that format the direction as Fanic TCP IJK components, Siemens TRAORI A3/B3/C3 components, or AC/BC/AB angles for use with Okuma or Heidenhain TCP modes. It returns null if the tool axis has not changed from the last known direction held by "vars". The WCS tool axis is used, which has all setup and toolpath transforms applied. In addition the getDstXform() transform is applied if required by getUseXform().
"move-xyz"
This is called by the MOVE event handling. It examines the tool position returned by getOutXYZ() and formats the position portion of the movement command. This function returns null if the tool axis has not changed from the last known direction held by "vars". The WCS position is used, which has all setup and toolpath transforms applied. In addition the getDstXform() transform is applied if required by getUseXform().
"ncfun-exchange-pallet"
This is called by the EXEC_NCFUN event handling for an "exchange pallet" NC function.
"ncfun-extended"
This is called by the EXEC_NCFUN event handling for an "extended nc-function" NC function.
"ncfun-index-pallet"
This is called by the EXEC_NCFUN event handling for an "index pallet" NC function.
"ncfun-index-table"
This is called by the EXEC_NCFUN event handling for an "index table" NC function.
"ncfun-message"
This is called by the EXEC_NCFUN event handling for a "message" NC function.
"ncfun-optional-stop"
This is called by the EXEC_NCFUN event handling for an "optional stop" NC function. It is also called durning the workingstep end event handling if required by getStopAfterWorkingstep().
"ncfun-stop"
This is called by the EXEC_NCFUN event handling for an "stop" NC function.
"op-approach-paths"
This advances the cursor through the toolpaths in an operation until it finds a toolpath that is not marked as an "approach" path and "required". It returns all formatted MOVE events that it iterated over. This is used when processing an operation of type OP_PROBE to command the probe approach.
"op-lift-paths"
This advances the cursor through the toolpaths in an operation until it is finished or finds a toolpath that is not marked as an "lift" path and "required". It returns all formatted MOVE events that it iterated over. This is used when processing an operation of type OP_PROBE to command the probe departure after measurement.
"probe-comments"
This is used when processing an operation of type OP_PROBE. It returns a series of comments that describe the start, end, direction, and expected value of a probe.
"probe-datums"
This is only used during DMIS output to declare workpiece datums at the start of a program.
"refpoint-center"
This is called when processing the toolpath start event for a cutter location toolpath. By default, it adds a "G40" to the next move if previously in cutter contact mode. If needed, it registers the G40 as a prefix for the next move with vars.addMovePrefix() and calls vars.setRefpointCenter();
"refpoint-contact"
This is called when processing the toolpath start event for a cutter contact toolpath. By default, it and calls vars.setRefpointContact()
"refpoint-left"
This is called by "move-contact" after it has determined where the cutter is in contact. If currently not vars.isRefpointLeft(), the function calls vars.setRefpointLeft() and returns "G41".
"refpoint-right"
This is called by "move-contact" after it has determined where the cutter is in contact. If currently not vars.isRefpointRight(), the function calls vars.setRefpointRight() and returns "G42".
"spindle"
Returns codes to turn the spindle on or off as necessary based on the value of getMoveSpindle(). The spindle is set to counter clockwise if the number is positive, clockwise if the number is negative, or "spindle-off" is called if the number is zero. Called by the toolpath start event handling.
"spindle-off"
Returns codes to turn off the spindle. Called by the tool change and program end event handling.
"tap-first"
This us called when processing an operation of type OP_TAP. It returns the starting portion of the tapping.
"tap-last"
This us called when processing an operation of type OP_TAP. It returns the concluding portion of the tapping.
"tap-point"
This us called when processing an operation of type OP_TAP. It is called with a getPosEnd() position for each location that must be tapped.
"timestamp"
Returns the current time in ISO date format as a comment. Usually called by the program start event handling.
"tool-comment"
This is called by the tool change event handling to build a series of comments describing the parameters of the new tool.
"workoffset"
This is called by the project start event handling to declare the work offset frame requested by getWorkOffsetFrame().
"workplan-probe-end"
This is called by the workplan start event handling to add additional commands at the beginning of workplans that contain OP_PROBE operations.
"workplan-probe-start"
This is called by the workplan end event handling to add additional commands at the completion of workplans that contain OP_PROBE operations.

formatRapidXYZ()

RoseStringObject formatRapidXYZ (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor,
	const RosePoint xyz
	);

The formatRapidXYZ() function returns a move command as if processing a MOVE event at rapid feed, but the given position is supplied by the caller rather than taken from a toolpath curve. The tool axis is not changed - use formatRapidXYZ_IJK() to change the tool direction.

The position is given in program units and "vars" is updated. The position is used exactly as passed in, no destination transform is applied. The feed rate will return to its previous value on the next move.

The function may return a null string if no move is needed.

formatRapidXYZ_IJK()

RoseStringObject formatRapidXYZ_IJK (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor,
	const RosePoint xyz,
	const RoseDirection ijk
	);

The formatRapidXYZ() function returns a move command as if processing a MOVE event at rapid feed, but the given position and tool axis direction is supplied by the caller rather than taken from a toolpath curve.

The position is given in program units and "vars" is updated. The position is used exactly as passed in, no destination transform is applied. The feed rate will return to its previous value on the next move.

The function may return a null string if no move is needed.

formatType()

RoseStringObject formatType (
	StixCtlGenerateState &vars,
	StixCtlCursor &cursor
	);

The formatType() function calls a formatting function based on the StixCtlType returned by the getActiveType() of the process cursor. Typically this is done for MOVE and OPERATION_START events. The function may return a null string if nothing is needed or no formatting function is registered for a particular type.

You can provide your own formatting function for a type with setTypeFn(), but this is typically used only when adding new predefined styles.

getAngleDigits()

int getAngleDigits();

The getAngleDigits() function returns the maximum number of decimal digits used when formatting an angle value. The getAngleMinDigits() function gives the minimum number of digits used. These values are typically defined by the output format but may be changed to different values using the setAngleDigits() and setAngleMinDigits() functions.

getAngleMinDigits()

int getAngleMinDigits();

The getAngleMinDigits() function returns the minimum number of decimal digits used when formatting an angle value. If this value is zero, integer values will have a trailing decimal point, if negative the decimal point will be stripped. The getAngleDigits() function gives the maximum number of digits used.

These values are typically defined by the output format but may be changed to different values using the setAngleDigits() and setAngleMinDigits() functions.

getBlocknumLimit()

int getBlocknumLimit();

The getBlocknumLimit() function returns the upper limit of block numbers for a format, or zero if there is no limit. When numbering is turned on, the block numbers will wrap around if they reach the limit. The StixCtlGenerateState getLastBlocknum() function returns the last assigned number.

getChordTolerance()

double getChordTolerance();

The getChordTolerance() function returns the chordal tolerance used to break arcs and helixes into line segments when the getLinearizeAllCurves() flag is set. This is the maximum distance that the line segment is allowed to be from the original mathematical curve. The default is 0.001 and can be changed by setChordTolerance()

getCommentFn()

StixCtlGenerateStringFn getCommentFn();

The getCommentFn() function returns a pointer to the comment formatting function registered with the object. This is the function that will be used when formatComment() is called. Use setCommentFn() to change this.

getDigits()

int getDigits();

The getDigits() function returns the maximum number of decimal digits used when formatting coordinate values. This is typically defined by the output format but may be changed to different values using the setDigits() function depending on whether output is in inch, mm, etc.

The getMinDigits() value controls the minimum number of digits that are present. These two values control the output of coordinate values. Separate settings control the appearance of IJK coodinates (getIJKDigits()), angles (getIJKDigits()), feedrates (getFeedDigits()), and spindle speeds (getSpindleDigits()).

getDstXform()

const double * getDstXform()

The getDstXform() function returns a pointer to a sixteen element array of doubles containing a destination transform for the output coordinates. This transform is only applied if getUseXform() is true.

When outputting moves, the StixCtlCursor will apply all setup and toolpath transforms to get the coordinates into the WCS. This destination transform is applied afterwards to modify the output for probing results or a machine-specific transform.

getDstXformIsLeft()

int getDstXformIsLeft();

The getDstXformIsLeft() function returns true if the transform returned by getDstXform() uses a left-handed coordinate system. Any transform derived from STEP data will, by definition, only use a right-handed coordinate system.

A left-handed transform, might be used by some machines, like a left-handed lathe. This will also reverse the direction of circular motion and spindle rotation.

getEventFn()

StixCtlGenerateFn getEventFn(StixCtlEvent e);

The getEventFn() function returns a pointer to the formatting function registered for the given event. This is the function that will be used when formatEvent() is called with a cursor with a matching event(). Use setEventFn() to change this.

getFeedDigits()

int getFeedDigits();

The getFeedDigits() function returns the maximum digits of precision used when formatting feedrate values. This is typically defined by the output format but may be changed to different values using the setFeedDigits() function. The getFeedMinDigits() function controls how many digits are always used and whether the trailing decimal point is left on integer values.

getFeedIsStandalone()

int getFeedIsStandalone();

The getFeedIsStandalone() function returns true if feedrate changes should be formatted on a separate line and false if they should be appended to the end of the move command to which they apply. Use setFeedStandalone() and setFeedInline() to change this value.

getFeedMinDigits()

int getFeedMinDigits();

The getFeedMinDigits() function returns the minimum number of decimal digits that will be used for feedrate value. If this value is zero, integer values will have a trailing decimal point, if negative the decimal point will be stripped. See catNumber() for examples. The setFeedMinDigits() function changes this value.

getFeedUnit()

RoseUnit getFeedUnit()

The getFeedUnit() function returns the velocity unit used for feed rate values.

This value will be set to inch/min or millimeter/min by setUnitSystem() depending on whether getLenUnit() is set to inch or MM. The value may be also be changed with the setLenUnit() function.

getFileExt()

const char * getFileExt();

The getFileExt() function returns the preferred filename extension for the configured format. The values set by the pre-defined styles include the dot separator. For example, ".nc", ".min", etc. This value can be used by the caller to construct a filename.

getIJKDigits()

int getIJKDigits();

The getIJKDigits() function returns the maximum number of decimal digits used when formatting an IJK direction component value. The getIJKMinDigits() function gives the minimum number of digits used. These values are typically defined by the output format but may be changed to different values using the setIJKDigits() and setIJKMinDigits() functions.

getIJKMinDigits()

int getIJKMinDigits();

The getIJKMinDigits() function returns the minimum number of decimal digits used when formatting an IJK direction component value. If this value is zero, integer values will have a trailing decimal point, if negative the decimal point will be stripped. The getIJKDigits() function gives the maximum number of digits used.

These values are typically defined by the output format but may be changed to different values using the setIJKDigits() and setIJKMinDigits() functions.

getLenUnit()

RoseUnit getLenUnit()

The getLenUnit() function returns the length unit used for all coordinate values and for the G70/G71-style units declaration that may appear at the start of a program.

This value is usually initialized from the getProgramUnit() and process data by setUnitSystem() but may be manually changed with the setLenUnit() function.

If the program unit has a value of AS-IS roseunit_as_is, the length unit will be a more specific value of INCH/MM found by looking at the toolpath units used by the process. Otherwise the two values will be the same.

getLinearizeAllCurves()

int  getLinearizeAllCurves();

The getLinearizeAllCurves() function returns a boolean flag indicating how arcs and helixes will be treated in the output. If true, the output functions will break arcs and helixes into a series of linear moves. The number of segments is controlled by the getChordTolerance() value.

The default is false, and arcs and helixes are output using the circular interpolation appropriate to the format, like "G2" or "G3" codes. This may be changed by setLinearizeAllCurves()

getMinDigits()

int getMinDigits();

The getMinDigits() function returns the minimum number of decimal digits that will be used for coordinate value. If this value is zero, integer values will have a trailing decimal point, if negative the decimal point will be stripped. See catNumber() for examples. The setMinDigits() function changes this value.

getOtherFn()

StixCtlGenerateFn getOtherFn(
	const char * name
	);

The getOtherFn() function returns a pointer to the formatting function registered under the given name. This is the function that will be used when formatOther() is called with that name. Use setOtherFn() to change this.

getOutArcAxis()

void getOutArcAxis(
	StixCtlCursor &ctl,
	double ret_ijk[3],
	StixCtlPos p
	);

The getOutArcAxis() function is a convenience wrapper for StixCtlCursor::getArcAxis() that applies the destination transform to the value if needed.

getOutArcCenter()

void getOutArcCenter(
	StixCtlCursor &ctl,
	double ret_xyz[3],
	StixCtlPos p,
	RoseUnit u = roseunit_as_is
	);

The getOutArcCenter() function is a convenience wrapper for StixCtlCursor::getArcCenter() that applies the destination transform to the value if needed.

getOutDirMove()

int getOutDirMove(
	StixCtlCursor &ctl,
	double ret_ijk[3],
	StixCtlPos p
	);

The getOutDirMove() function is a convenience wrapper for StixCtlCursor::getPosDirMove() that applies the destination transform to the value if needed.

getOutDirSnorm()

int getOutDirSnorm(
	StixCtlCursor &ctl,
	double ret_ijk[3],
	StixCtlPos p
	);

The getOutDirSnorm() function is a convenience wrapper for StixCtlCursor::getPosDirSnorm() that applies the destination transform to the value if needed.

getOutDirX()

void getOutDirX(
	StixCtlCursor &ctl,
	double ret_ijk[3],
	StixCtlPos p
	);

The getOutDirX() function is a convenience wrapper for StixCtlCursor::getPosDirX() that calls getPosDefaultDirX() if no tool reference direction is defined, and then applies the destination transform to the value if needed.

getOutDirZ()

void getOutDirZ(
	StixCtlCursor &ctl,
	double ret_ijk[3],
	StixCtlPos p
	);

The getOutDirZ() function is a convenience wrapper for StixCtlCursor::getPosDirZ() that calls getPosDefaultDirZ() if no tool axis direction is defined, and then applies the destination transform to the value if needed.

getOutXYZ()

void getOutXYZ(
	StixCtlCursor &ctl,
	double ret_xyz[3],
	StixCtlPos p,
	RoseUnit u = roseunit_as_is
	);

The getOutXYZ() function is a convenience wrapper for StixCtlCursor::getPosXYZ() that applies the destination transform to the value if needed.

getOutXformedDir()

void getOutXformedDir(
	double ret_ijk[3],
	const double in_ijk[3]
	);

The getOutXformedDir() function is a convenience wrapper that applies the destination transform to a direction vector if needed.

getOutXformedPoint()

void getOutXformedPoint(
	double ret_xyz[3],
	const double in_xyz[3]
	);

The getOutXformedPoint() function is a convenience wrapper that applies the destination transform to a coordinate position if needed.

getProgramNumber()

int getProgramNumber();

The getProgramNumber() function returns the preferred number that should be used for the program when generating Fanuc-like codes. Use setProgramNumber() to change this value.

getProgramUnit()

RoseUnit getProgramUnit()

The getProgramUnit() function returns the preferred unit system that should be used for generating output. Call setProgramUnit() to change this.

The INCH value roseunit_in implies lengths in inches, feeds in inches per minute, and spindle speeds in RPM. The MILLIMETER value roseunit_mm implies lengths in mm, feeds in mm per minute, and spindle speeds in RPM.

Calling setUnitSystem() before beginning to set the actual units for length, feed, and spindle based on your preference. If the program unit is AS-IS roseunit_as_is, this will search for the first toolpath units seen and set the unit system from that.

getSpindleDigits()

int getSpindleDigits();

The getSpindleDigits() function returns the maximum digits of precision used when formatting spindle speed values. This is typically defined by the output format but may be changed to different values using the setSpindleDigits() function. The getSpindleMinDigits() function controls how many digits are always used and whether the trailing decimal point is left on integer values.

getSpindleMinDigits()

int getSpindleMinDigits();

The getSpindleMinDigits() function returns the minimum number of decimal digits that will be used for spindle speed values. If this value is zero, integer values will have a trailing decimal point, if negative the decimal point will be stripped. See catNumber() for examples.

getSpindleUnit()

RoseUnit getSpindleUnit()

The getSpindleUnit() function returns the angular velocity unit used for spindle speed values.

This value will be set to revolution/min by setUnitSystem(). The value may be also be changed with the setSpindleUnit() function.

getStopAfterWorkingstep()

int getStopAfterWorkingstep();

The getStopAfterWorkingstep() function returns true if the workingstep end event handling should insert an optional stop code into the output. Call setStopAfterWorkingstep() to change this value.

getSupressX/Y/Zpos()

int getSupressXpos();
int getSupressYpos();
int getSupressZpos();

The getSupressX/Y/Zpos() functions return a flag for each axis. When true, the move formatting code supresses all mention of that axis. This can be used to suppress the Z axis, for example, for 2D output. It is used to suppress the Y axis for lathes output. You can change these values with the setSupressX/Y/Zpos functions.

getTraceComments()

TraceComments getTraceComments();

enum TraceComments {
	TraceComments_none = 0,
	TraceComments_workplan = 1,	// before each workplan
	TraceComments_workingstep = 2,	// before each workingstep
	TraceComments_toolpath = 3,	// before each toolpath
	TraceComments_point = 4, 	// at each point.
	TraceComments_all = 5 		// all possible comments.
};

The getTraceComments() function returns an enum value that controls where descriptive comments are placed in the output. The levels go from less descriptive to more detailed, with one including the comments of the previous level. The default value is before each workingstep. Call setTraceComments() to change this.

getTypeFn()

StixCtlGenerateFn getTypeFn(StixCtlType e);

The getTypeFn() function returns a pointer to the formatting function registered for the given type. This is the function that will be used when formatType() is called with a cursor that has a matching getActiveType(). Use setTypeFn() to change this.

getUseBlocknums()

int getUseBlocknums();

The getUseBlocknums() function returns true if individual commands in the output should be preceedded by a "N" number. The formatBlock function looks at this setting and prepends the number if needed.

This setting can be changed for most styles by setUseBlocknums(). Some output styles, like "heidenhain", force this value to true because they require block numbers.

fmt.formatBlock(vars,"HELLO WORLD");  // with getUseBlocknums() false
=> HELLO WORLD

fmt.formatBlock(vars,"HELLO WORLD");  // with getUseBlocknums() true
=> N1234 HELLO WORLD

getUseWhitespace()

int getUseWhitespace();

The getUseWhitespace() function returns true if parameters assembled by the catParam() function should be separated by space characters. The catSpace() also appends a space to non-empty inputs if this value is true. This setting can be changed by setUseWhitespace().

RoseStringObject ret = "G1";
fmt.catParam(ret, "X", 1.23);
fmt.catParam(ret, "Y", 4.56);
fmt.catParam(ret, "Z", 7.89);

=> G1X1.23Y4.56Z7.89		  // with getUseWhitespace() false

=> G1 X1.23 Y4.56 Z7.89	  // with getUseWhitespace() true

getUseXform()

int getUseXform();

The getUseXform() function returns true if the destination transform given by getDstXform() should be applied to all coordinates and directions. This value can be changed by setUseXform() and affects the behavior of all of the "getOut" prefixed functions.

getWorkOffsetFrame()

int getWorkOffsetFrame();

The getWorkOffsetFrame() function returns the preferred number of the work offset frame that should be selected by the project start event handling. The actual command may change from style to style, but typical usage is "G54" for frame #1, "G55" for frame #2, etc. This value can be changed by the setWorkOffsetFrame() function.

isFormattedIJK()

int isFormattedIJK(
	const RoseDirection &dir1,
	const RoseDirection &dir2,
	int max_digits = -1
	);

The isFormattedIJK() function returns true if the two direction vectors are equal when formatted to the digits of precision given by the getDigits() value. A different formatting specification can be passed in as an optional parameter.

isFormattedNumber()

int isFormattedNumber(
	double num1,
	double num2,
	int max_digits = -1
	);

The isFormattedNumber() function returns true if the two numbers equal when formatted to the digits of precision given by the getDigits() value. A different formatting specification can be passed in as an optional parameter.

isFormattedXYZ()

int isFormattedXYZ(
	const RosePoint &pt1,
	const RosePoint &pt2,
	int max_digits = -1
	);

The isFormattedXYZ() function returns true if the two coordinates are equal when formatted to the digits of precision given by the getDigits() value. A different formatting specification can be passed in as an optional parameter.

reset()

void reset();

The reset() function returns the format object to default settings for all values, including user preferences like getWorkOffsetFrame(), getProgramUnits(), etc.

setAngleDigits()

void setAngleDigits (int d);

The setAngleDigits() function sets the maximum number of decimal digits used when formatting angle values. See getAngleDigits() for more discussion.

setAngleMinDigits()

void setAngleMinDigits (int d);

The setAngleMinDigits() function sets the minimum number of decimal digits used when formatting angle values. See getAngleMinDigits() for more discussion.

setBlocknumLimit()

void setBlocknumLimit (int max)

The setBlocknumLimit() function sets the upper limit of block numbers for a format. Set to zero to indicate no limit. See getBlocknumLimit() for more discussion on this use.

setChordTolerance()

void setChordTolerance(double val);

The setChordTolerance() function changes the chordal tolerance used to break arcs and helixes into line segments when the getLinearizeAllCurves() flag is set. This is the maximum distance that the line segment is allowed to be from the original mathematical curve.

setCommentFn()

void setCommentFn(StixCtlGenerateStringFn ptr); 

The setCommentFn() function sets the comment formatting function that will be used when formatComment() is called. See getCommentFn() for more discussion.

setDigits()

void setDigits (int d);

The setDigits() function sets the maximum digits of precision used when formatting coordinate values. See getDigits() for more discussion.

setDstXform()

void setDstXform(const double xf[16]);

The setDstXform() function sets the destination transform for the output coordinates. The input must be a sixteen element array of doubles. See getDstXform() for more discussion.

setEventFn()

void setEventFn(
	StixCtlEvent e,
	StixCtlGenerateFn ptr
	);

The setEventFn() function sets the formatting function that will be used when formatEvent() is called for a given event. See getEventFn() for more discussion.

setFeedDigits()

void setFeedDigits (int d);

The setFeedDigits() function sets the maximum digits of precision used when formatting feedrate values. See getFeedDigits() for discussion.

setFeedInline()

void setFeedInline();

The setFeedInline() function sets the value returned by getFeedIsStandalone() to false. This means that feedrate changes should be appended to the end of the move command to which they apply.

setFeedMinDigits()

void setFeedMinDigits (int d);

The setFeedMinDigits() function sets the minimum number of digits of precision used when formatting feedrate values. See getFeedMinDigits() for discussion.

setFeedStandalone()

void setFeedStandalone();

The setFeedStandalone() function sets the value returned by getFeedIsStandalone() to true. This means that feedrate changes should be formatted on a separate line preceeding the move command to which they apply.

setFeedUnit()

void setFeedUnit (RoseUnit u);

The setFeedUnit() function changes the linear velocity unit used for feed rate values. This value will be overwritten every time setUnitSystem() is called. See getFeedUnit() for more discussion.

setFileExt()

void setFileExt (const char * e);

The setFileExt() function the preferred filename extension for the configured format. See getFileExt() for more discussion.

setIJKDigits()

void setIJKDigits (int d);

The setIJKDigits() function sets the maximum number of decimal digits used when formatting IJK direction component values. See getIJKDigits() for more discussion.

setIJKMinDigits()

void setIJKMinDigits (int d);

The setIJKMinDigits() function sets the minimum number of decimal digits used when formatting IJK direction component values. See getIJKMinDigits() for more discussion.

setLenUnit()

void setLenUnit (RoseUnit u);

The setLenUnit() function changes the length unit used for all coordinate values. This value will be overwritten every time setUnitSystem() is called. See getLenUnit() for more discussion.

setLinearizeAllCurves()

void setLinearizeAllCurves(int yn)

The setLinearizeAllCurves() function changes a boolean flag indicating how arcs and helixes will be treated in the output.

If true, the output functions will break arcs and helixes into a series of linear moves. The number of segments is controlled by the getChordTolerance() value.

If false, and arcs and helixes are output using the circular interpolation appropriate to the format, like "G2" or "G3" codes. See getLinearizeAllCurves() for more information.

setMinDigits()

void setMinDigits (int d);

The setMinDigits() function sets the minimum number of digits of precision used when formatting feedrate values. See getMinDigits() for discussion.

setOtherFn()

void setOtherFn(
	const char * name,
	StixCtlGenerateFn ptr
	);

The setOtherFn() function sets the formatting function that will be used when formatOther() is called for a given string. The documentation for formatOther() includes a list of commonly used strings.

setProgramNumber()

void setProgramNumber (int d);

The setProgramNumber() function sets the program number used for the program when generating Fanuc-like codes. See getProgramNumber() for more discussion.

setProgramUnit()

void setProgramUnit (RoseUnit u);

The setProgramUnit() function sets the preferred unit system that should be used for generating output. See getProgramUnit() for more discussion.

setSpindleDigits()

void setSpindleDigits (int d);

The setSpindleDigits() function sets the maximum digits of precision used when formatting spindle speed values. See getSpindleDigits() for discussion.

setSpindleMinDigits()

void setSpindleMinDigits (int d);

The setSpindleMinDigits() function sets the minimum number of digits of precision used when formatting spindle speed values. See getSpindleMinDigits() for discussion.

setSpindleUnit()

void setSpindleUnit (RoseUnit u);

The setSpindleUnit() function changes the angular velocity unit used for spindle speed values. This value will be overwritten every time setUnitSystem() is called. See getSpindleUnit() for more discussion.

setStopAfterWorkingstep()

void setStopAfterWorkingstep (int yn);

The setStopAfterWorkingstep() function sets a flag that controls whether the workingstep end event handling inserts an optional stop code into the output. See Call getStopAfterWorkingstep() for more discussion.

setStyle()

int setStyle (const char * name);

The setStyle() function finds a built-in style with a given name and configures the format object for that. The function returns true if the style was found and false otherwise. This is equivalent to just calling the appropriate stixctl_use_style_* function.

Most styles begin by calling reset() so any prior settings will be lost.

StixCtlCursor ctl;
StixCtlGenerate fmt;
StixCtlGenerateState vars;

ctl.startProject(d);    // start process traversal
ctl.setWantedAll(1);

fmt.setStyle("haas");  // set desired style as Haas
fmt.setUnitSystem(d);   

while (ctl.next()) {
    const char * str = fmt.formatEvent(vars, ctl);
    if (str) fputs(str, stdout);
}


// generate again, but as okuma codes
ctl.startProject(d);    // restart traversal
fmt.setStyle("okuma");  // set desired style as Okuma
fmt.setUnitSystem(d);   
vars.reset();		// clear vars

while (ctl.next()) {
    const char * str = fmt.formatEvent(vars, ctl);
    if (str) fputs(str, stdout);
}

setSupressX/Y/Zpos()

int setSupressXpos (int yn);
int setSupressYpos (int yn);
int setSupressZpos (int yn);

The setSupressX/Y/Zpos() functions set a flag that supresses mention of particular axis. This may be useful for 2D output, lathes, etc. See getSupressX/Y/Zpos for more details.

setTraceComments()

void setTraceComments (TraceComments t);

The setTraceComments() function sets an enum value that controls where descriptive comments are placed in the output. See getTraceComments() for a description of the values and their effect.

setTypeFn()

void setTypeFn(
	StixCtlType e,
	StixCtlGenerateFn ptr
	);

The setTypeFn() function sets the formatting function that will be used when formatType() is for the given StixCtlType. See getTypeFn() for more discussion.

setUnitSystem()

void setUnitSystem (StixCtlCursor &ctl);

The setUnitSystem() function sets the system of length, feed, and spindle speed units. These are set to match to match the program unit preference. If this is AS-IS, the function will use the supplied cursor to find the length units used by the toolpaths process, and set the unit system accordingly. The unit system values are returned by the getLenUnit(), getFeedUnit() and getSpindleUnit() functions.

setUseBlocknums()

void setUseBlocknums (int yn);

The setUseBlocknums() function sets a flag that indicates whether the formatBlock function should prefix every line with a "N" number. See getUseBlocknums() for more discussion.

setUseWhitespace()

void setUseWhitespace (int yn);

The setUseWhitespace() function sets a flag that indicates whether numeric parameters should be separated by space characters in the output. See getUseWhitespace() for more discussion and examples.

setUseXform()

void setUseXform (int yn);

The setUseXform() function sets a flag that indicates whether the destination transform given by getDstXform() should be applied to all coordinates and directions. This affects the behavior of all of the "getOut" prefixed functions. You can query this value with the getUseXform() function.

setWorkOffsetFrame()

void setWorkOffsetFrame (int d);

The setWorkOffsetFrame() function sets the preferred number of the work offset frame that should be selected by the project start event handling. A value of -1 means "as-is", do not change any offset settings. See getWorkOffsetFrame() for more discussion.