Class SoftNcUtil
JSON helpers for soft-NC blocks: vectors under Parsing, motion-term queries, flag grab/remove on raw text, and unparsed-line trimming.
public static class SoftNcUtil
- Inheritance
-
SoftNcUtil
- Inherited Members
Properties
RegexFlagPrefix
Regex prefix pattern that matches word boundary, after digit, after whitespace, or at start of string. The whitespace/start-of-string alternatives are needed for non-word-character prefixes (e.g. Fanuc '#', Siemens '$').
public static string RegexFlagPrefix { get; }
Property Value
Methods
GetOccupiedMotionTerm(JsonObject)
Reads the occupied Group 01 term from Motion.Term. Returns null if the slot is unoccupied. Used by motion syntaxes to enforce mutual exclusion (only one Group 01 term per block).
public static string GetOccupiedMotionTerm(this JsonObject json)
Parameters
jsonJsonObject
Returns
GetVec3d(JsonObject, string)
Read Vec3d from a sub-object with X/Y/Z keys. Returns null if the section or all three keys are missing; individual missing keys are filled with NaN.
public static Vec3d GetVec3d(JsonObject json, string sectionKey)
Parameters
jsonJsonObjectsectionKeystring
Returns
GetVec3d(JsonObject, string, Vec3d)
Reads Vec3d from a sub-object with X/Y/Z keys,
substituting each missing component (or a missing section) with
the matching component of fallback.
public static Vec3d GetVec3d(JsonObject json, string sectionKey, Vec3d fallback)
Parameters
jsonJsonObjectsectionKeystringfallbackVec3d
Returns
GrabDouble(ref string, string, bool)
Grab double value with decimal point judgement: The text is changed by replacing tag and value to empty string.
If enableIntegerShrink is true and no decimal point, the value should be scale by 0.001.
public static double GrabDouble(ref string text, string tag, bool enableIntegerShrink)
Parameters
textstringtext
tagstringtag
enableIntegerShrinkboolIf true and no decimal point exists, the value will be scaled by 0.001.
Returns
- double
double value
GrabFlag(ref string, string)
Grabs and removes a flag from the NC text.
public static bool GrabFlag(ref string text, string regexTag)
Parameters
Returns
- bool
True if the flag was found and removed; otherwise, false.
GrabFlags(ref string, IEnumerable<string>)
Removes the first occurrence of any flag in tags from text (alternation regex).
public static bool GrabFlags(ref string text, IEnumerable<string> tags)
Parameters
textstringtagsIEnumerable<string>
Returns
- bool
trueif a match was removed.
HasAnyFlag(string, IEnumerable<string>)
True if text contains any flag in flags as whole tokens.
public static bool HasAnyFlag(string text, IEnumerable<string> flags)
Parameters
textstringflagsIEnumerable<string>
Returns
HasAnyFlag(string, string)
True if text contains flag as a whole token (see RegexFlagPrefix).
public static bool HasAnyFlag(string text, string flag)
Parameters
Returns
HasFlagInArray(JsonObject, string)
Checks if a specific flag string exists in the Parsing.Flags JsonArray.
public static bool HasFlagInArray(this JsonObject parsing, string flag)
Parameters
parsingJsonObjectflagstring
Returns
ParseDouble(JsonNode)
Parses a double from a JsonNode that may be a number or a string. Extends GetDouble(JsonNode) with string parsing support (needed for values from ParameterizedFlagSyntax which stores values as strings like “180”). Returns 0 if null or unparseable.
public static double ParseDouble(this JsonNode node)
Parameters
nodeJsonNode
Returns
RemoveFlagFromArray(JsonObject, string)
Removes a specific flag string from the Parsing.Flags JsonArray.
public static void RemoveFlagFromArray(this JsonObject parsing, string flag)
Parameters
parsingJsonObjectflagstring
SetAndTrimUnparsedText(JsonObject, string)
Normalises UnparsedText (trim, drop blank-only lines) and removes the property when empty.
public static void SetAndTrimUnparsedText(this JsonObject root, string unparsedText)
Parameters
rootJsonObjectBlock JSON object.
unparsedTextstringRaw tail text after structured fields were consumed.
SetVec3d(JsonObject, string, Vec3d)
Writes Vec3d to a sub-object under sectionKey,
setting only the X/Y/Z keys. If the section already exists, other
keys (e.g. A/B/C on a shared MachineCoordinate) are
preserved; if it does not exist, a new sub-object is created.
Upsert rather than replace so callers that write XYZ and ABC in separate stages (McXyzSyntax and McAbcSyntax) can cooperate on the same MachineCoordinate section without clobbering each other.
public static void SetVec3d(JsonObject json, string sectionKey, Vec3d v)
Parameters
jsonJsonObjectsectionKeystringvVec3d