Class NumericNCWord
"NumericNCWord", or in other words "Register", is an object that helps you quickly and conveniently convert numeric values to a text format that the CNC machine understands. For example, you can easily convert the coordinate value x = 5.18 to the string "X0005.180". This corresponds approximately to one word in the output G-code.
Optionally, NumericNCWord can also help you to filter the output. It contains two values - current v and previous v0 (which has already been output earlier). If both of these values are the same, then re-output the value can be skipped automatically.
Inherited Members
Namespace: SprutTechnology.SCPostprocessor
Assembly: SCPostprocessor.dll
Syntax
public class NumericNCWord : NCWord
Constructors
NumericNCWord(String, Double)
The main constructor to create a new instance of the NumericNCWord.
It is used the "format"
string parameter to define the all formatting rules
for the NumericNCWord.
For example, the "format"
parameter can be: "X = {-####!0##};".
The formatting rules are below.
- The curly braces divide the expression into three parts.
- Anything to the left of the braces is assigned to the Address property and passed to the output line unchanged (here is "X = ").
- Anything to the right of the braces is assigned to the TailString property and also goes to the output string as it is (here is ";").
- The expression inside the braces defines the formatting rules applied to the current v value (here is "-####!0##"). It can only include these characters "-+.!_#0".
- If the first character in braces is "-", then the sign of the number will output only for negative numbers. It corresponds to SignMode property value Minus.
- If the first character in braces is "+", then the sign of the number will output both for positive and negative numbers. It corresponds to SignMode property value PlusAndMinus.
- If the first character in braces is not "+" or "-", then the sign of the number will not output at all. It corresponds to SignMode property value No.
- One of the characters ".!_" in curly braces separates the integer part from the fractional part and determines how to output the decimal point.
- The point "." means the optional output, so the decimal point will output for fractional numbers, and for integers it will be skipped. It corresponds to the property PointMode = No.
- An exclamation point "!" indicates a required output, so the decimal point will output both for fractional and integer numbers. It corresponds to the property PointMode = Always.
- The underscore "_" or the absence of any of the characters ".!_" at all means that the decimal point will never be output. It corresponds to the property PointMode = No.
- The number of characters "0" or "#" before the characters ".!_" indicates the number of characters allowed before the decimal point. It corresponds to the property DigitsBeforePoint.
- If at least one of the characters before the point is zero "0", then non-significant zeros are required. It corresponds to the property LeadingZeroes = true.
- If all characters before the point are "#", then non-significant zeros will not output. It corresponds to the property LeadingZeroes = false.
- The number of characters "0" or "#" after the characters ".!_" indicates the number of characters allowed after the decimal point. It corresponds to the property DigitsAfterPoint. The number will be rounded to the specified number of digits before output.
- If all characters after the point are "#", then non-significant zeros will not output. It corresponds to the property TrailingZeroes = No.
- If all characters after the point are "0", then non-significant zeros are required. It corresponds to the property TrailingZeroes = Yes.
- If the first character after the point is "0" and the rest are "#", then only first non-significant zero will output and the rest will be skipped. It corresponds to the property TrailingZeroes = OneOnly.
Declaration
public NumericNCWord(string format, double defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The string that defines the formatting rules for the NumericNCWord. For example: "X = {-####!0##};". See description of the constructor for more details. |
System.Double | defaultValue | The parameter to define a default value for the NumericNCWord. It is used to assing initial values to the current v and the previous v0 values just after creation of the NumericNCWord or when you call RestoreDefaultValue(Boolean) method manually. |
NumericNCWord(String, String, NCWordSign, NCWordDecPoint, Int32, Int32, Double)
Creates a new instance of a NumericNCWord register with the given parameters.
Declaration
public NumericNCWord(string address, string tailString, NCWordSign signMode, NCWordDecPoint pointMode, int digitsBefore, int digitsAfter, double defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | address | Address - start part of the register's output string. |
System.String | tailString | TailString - final part of the register's output string. |
NCWordSign | signMode | SignMode - defines how to output the sign of the number. |
NCWordDecPoint | pointMode | PointMode - defines how to output the decimal point of the number. |
System.Int32 | digitsBefore | DigitsBeforePoint - count of digits before decimal point of the number. |
System.Int32 | digitsAfter | DigitsAfterPoint - count of digits after decimal point of the number. |
System.Double | defaultValue | DefaultValue - default value of the register. |
NumericNCWord(String, String, NCWordSign, NCWordDecPoint, Int32, Int32, Double, Boolean)
Creates a new instance of a NumericNCWord register with the given parameters.
Declaration
public NumericNCWord(string address, string tailString, NCWordSign signMode, NCWordDecPoint pointMode, int digitsBefore, int digitsAfter, double defaultValue, bool autoUpdateState)
Parameters
Type | Name | Description |
---|---|---|
System.String | address | Address - start part of the register's output string. |
System.String | tailString | TailString - final part of the register's output string. |
NCWordSign | signMode | SignMode - defines how to output the sign of the number. |
NCWordDecPoint | pointMode | PointMode - defines how to output the decimal point of the number. |
System.Int32 | digitsBefore | DigitsBeforePoint - count of digits before decimal point of the number. |
System.Int32 | digitsAfter | DigitsAfterPoint - count of digits after decimal point of the number. |
System.Double | defaultValue | DefaultValue - default value of the register. |
System.Boolean | autoUpdateState | AutoUpdateState - determines whether the State should be automatically updated when the current v or previous v0 value changes. |
Fields
defaultValue
The field to store a default value for the NumericNCWord.
Declaration
protected double defaultValue
Field Value
Type | Description |
---|---|
System.Double |
fWordBuilder
This object helps to efficiently unite strings when we make an output string for the NumericNCWord.
Declaration
protected StringBuilder fWordBuilder
Field Value
Type | Description |
---|---|
System.Text.StringBuilder |
Properties
DecimalSeparator
The decimal separator char that be used to output fractional numbers.
Declaration
public static string DecimalSeparator { get; set; }
Property Value
Type | Description |
---|---|
System.String |
DefaultValue
The property to store a default value for the NumericNCWord. It is used to assing initial values to the current v and the previous v0 values just after creation of the NCWord or when you call RestoreDefaultValue(Boolean) method manually.
Declaration
public double DefaultValue { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
DigitsAfterPoint
The count of digits after decimal point to output. The value of the register will be rounded to this count of digits before output.
If TrailingZeroes property is enabled and the actual number of meaningfull digits is less than defined in this property then missing digits will be filled by zeroes.
Declaration
public int DigitsAfterPoint { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
DigitsBeforePoint
The count of digits before decimal point to output.
It affects only if the LeadingZeroes property enabled and the actual count of digits of the register's value is less than defined in this property. In this case missing digits will be filled by zeroes. It doesn't truncate numbers which actual count of digits is more than defined in the property.
For the CountingNCWord it defines the maximal possible value after exceeding which the value of the register will be changed to default again.
Declaration
public int DigitsBeforePoint { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
LeadingZeroes
This property in connection with the DigitsBeforePoint property determines whether
leading insignificant zeros of the number should be output (like "005.249"
or like "5.249"
).
Declaration
public bool LeadingZeroes { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
PointMode
The property defines how to output decimal point for numbers: don't output, output for fractional numbers only or output it always for fractional and integer numbers.
Declaration
public NCWordDecPoint PointMode { get; set; }
Property Value
Type | Description |
---|---|
NCWordDecPoint |
SignMode
The property shows how to output a sign for numbers: don't output, minus only or plus and minus always.
Declaration
public NCWordSign SignMode { get; set; }
Property Value
Type | Description |
---|---|
NCWordSign |
TrailingZeroes
This property in connection with the DigitsAfterPoint property determines whether
trailing insignificant zeros of the number should be output (like "27.000"
, "27.0"
or like "27"
).
Declaration
public TrailingZeroesMode TrailingZeroes { get; set; }
Property Value
Type | Description |
---|---|
TrailingZeroesMode |
Unstable
Returns "True" if the NCWord is in the so-called "Unstable" state after the call of Reset() method. Actually it checks that the previous v0 value is equal to the "undefined" value ("double.MaxValue"). This state means that the NCWord will NOT output on the next call of Out() or Form(). But it will output just after the first change of the current v value.
Declaration
public override bool Unstable { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
v
The current v value of the NumericNCWord. It is used to make the output string using the all formatting rules (numbers before and after decimal point, leading and trailing zeroes, etc.). Together with the previous v0 value and the NCBlock, it can be used to filter the output. If v == v0, then the output line formed by the NCBlock.Out and NCBlock.Form commands will not include this NumericNCWord (it will be skipped).
Declaration
public double v { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
v0
The previous v0 value of the NumericNCWord. Together with the current v value and the NCBlock, it can be used to filter the output. If v == v0, then the output line formed by the NCBlock.Out and NCBlock.Form commands will not include this NumericNCWord (it will be skipped).
Declaration
public double v0 { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
ValuesDiffer
The property is "True" only if the current value v and the previous value v0 form a different output string.
Declaration
public override bool ValuesDiffer { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
ValuesSame
The property is "True" only if the current value v and the previous value v0 form a completely identical output string.
Declaration
public override bool ValuesSame { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
Methods
Hide(Double)
Switches the NCWord to the Unchanged state. It means that the NCWord will NOT output on the next call of Out() or Form().
Additionally it assigns the speciefied number to the current v value of the register.
It doesn't change the previous v0 value of the NCWord.
Later you can use the UpdateState() method to restore the changed-unchanged state depend on equality ot the v and v0.
Declaration
public void Hide(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value |
Init()
This method initializes an internal state of the NumericNCWord just after creation.
Declaration
protected override void Init()
Overrides
Reset()
Switches the NCWord to the Unchanged state and changes the previous v0 value to an undefined value ("double.MaxValue"). It means that the NCWord will NOT output on the next call of Out() or Form(). But it will output just after the first change of the current v value.
It is the so-called "Unstable" state.
It doesn't change the current v value of the NCWord.
Declaration
public override void Reset()
Overrides
Reset(Double)
Switches the NCWord to the Unchanged state and changes the previous v0 value to an undefined value ("double.MaxValue"). It means that the NCWord will NOT output on the next call of Out() or Form(). But it will output just after the first change of the current v value.
It is the so-called "Unstable" state.
Additionally it assigns the speciefied number to the current v value of the register.
Declaration
public void Reset(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value |
RestoreDefaultValue(Boolean)
Assigns the default value of the NCWord to it's current value v and previous value v0. Depend on the "show" parameter it switches the state to Unchanged (show=false) or Changed (show=true).
Declaration
public override void RestoreDefaultValue(bool show)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | show | If "show" is "false" then it switches the state to Unchanged. If "show" is "true" then it switches the state to Changed. |
Overrides
Show(Double)
Switches the NCWord to the Changed state. It means that the NCWord will output on the next call of Out() or Form().
Additionally it assigns the speciefied number to the current v value of the register.
It doesn't change the previous v0 value of the NCWord.
Declaration
public void Show(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value |
ToString()
Converts the current v value of the NumericNCWord to the output string using all the rules of formatting like in calls of Out() or Form(). But this method does not check the State of the NumericNCWord (changed it or not), so you will get the output string anyway.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | Returns the current v value with all the formatting rules defined for the NumericNCWord (Address, TailString, PointMode, etc.) |
Overrides
ToString(Double)
Converts the specified value to the output string using all the rules of formatting like in calls of Out() or Form(). But this method does not check the State of the NumericNCWord (changed it or not), so you will get the output string anyway.
It doesn't change the current v or previous v0 value of the NCWord.
Declaration
public string ToString(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value |
Returns
Type | Description |
---|---|
System.String | Returns the specified value with all the formatting rules defined for the NumericNCWord (Address, TailString, PointMode, etc.) |
UpdateState()
Switches the State of the NCWord to Changed or Unchanged depend on the current v and previous v0 values. If the values are same then the state will be "Unchanged", otherwise it will be "Changed".
If the NCWord is Disabled or has the AutoUpdateState=false then the method does nothing.
Declaration
public override void UpdateState()
Overrides
Operators
Implicit(NumericNCWord to Double)
Implements a trivial casting of the current v value of the register to a double type number.
Declaration
public static implicit operator double (NumericNCWord nw)
Parameters
Type | Name | Description |
---|---|---|
NumericNCWord | nw | The register which value to cast. |
Returns
Type | Description |
---|---|
System.Double |
Implicit(NumericNCWord to Int32)
Implements a trivial casting of the current v value of the register to an integer type number.
Declaration
public static implicit operator int (NumericNCWord nw)
Parameters
Type | Name | Description |
---|---|---|
NumericNCWord | nw | The register which value to cast. |
Returns
Type | Description |
---|---|
System.Int32 |