Table of Contents

Class SoftNcUtil

Namespace
Hi.NcParsers
Assembly
HiMech.dll

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

string

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

json JsonObject

Returns

string

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

json JsonObject
sectionKey string

Returns

Vec3d

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

json JsonObject
sectionKey string
fallback Vec3d

Returns

Vec3d

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

text string

text

tag string

tag

enableIntegerShrink bool

If 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

text string

The NC text to search and modify.

regexTag string

The flag tag to search for.

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

text string
tags IEnumerable<string>

Returns

bool

true if 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

text string
flags IEnumerable<string>

Returns

bool

HasAnyFlag(string, string)

True if text contains flag as a whole token (see RegexFlagPrefix).

public static bool HasAnyFlag(string text, string flag)

Parameters

text string
flag string

Returns

bool

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

parsing JsonObject
flag string

Returns

bool

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

node JsonNode

Returns

double

RemoveFlagFromArray(JsonObject, string)

Removes a specific flag string from the Parsing.Flags JsonArray.

public static void RemoveFlagFromArray(this JsonObject parsing, string flag)

Parameters

parsing JsonObject
flag string

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

root JsonObject

Block JSON object.

unparsedText string

Raw 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

json JsonObject
sectionKey string
v Vec3d