Class CircularMotionSyntax
- Namespace
- Hi.NcParsers.LogicSyntaxs
- Assembly
- HiMech.dll
Writes McArc motion for circular commands (ISO G02/G03). Detects motion mode from Flags, reads I/J/K center offsets or R radius from Parsing, computes arc center in program coordinates, and writes a one-shot MotionEvent (form + arc params) plus a modal MotionState (Term).
G02/G03 mode is modal (Group 01) — persists across blocks via Term. Arc parameters (I/J/K/R) are per-block and must be present in every arc block.
Must be placed before LinearMotionSyntax in the syntax chain. Both share the Group 01 motion slot; whichever writes a MotionEvent first claims it.
public class CircularMotionSyntax : ISituNcSyntax, INcSyntax, IMakeXmlSource
- Inheritance
-
CircularMotionSyntax
- Implements
- Inherited Members
- Extension Methods
Examples
All cases below have the current block's ProgramXyz already
set (as a prior ProgramXyzSyntax would have produced)
and run with no #Previous:, so GetLastProgramXyz
returns Vec3d.Zero. The G17 XY plane is implicit
(no PlaneSelect section means PlaneNormalDir = 2).
G02 with I/J — quarter arc from (0,0,0) to (10,0,0)
around (5,0,0); I=5 J=0 are incremental offsets from start
to center. The G02 flag is consumed (Parsing removed
once empty); MotionState + MotionEvent are written:
{
"Parsing": { "Flags": ["G02"], "I": 5, "J": 0 },
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
"MotionState": { "Term": "G02" },
"MotionEvent": {
"Form": "McArc",
"ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
"PlaneNormalDir": 2,
"IsCcw": false,
"AdditionalCircleNum": 0
}
}
Modal carry of G02: no motion flag on the current block but a
#Previous: MotionState.Term = "G02" tells us we are
still in circular mode. I/J on the current block describe the arc
the same way:
#Previous:
{ "MotionState": { "Term": "G02" } }
#BeforeBuild:
{
"Parsing": { "I": 5, "J": 0 },
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
"MotionState": { "Term": "G02" },
"MotionEvent": {
"Form": "McArc",
"ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
"PlaneNormalDir": 2,
"IsCcw": false,
"AdditionalCircleNum": 0
}
}
No I/J/K/R on the block — the per-block arc data is missing, so
the syntax bails out early; the G02 flag stays in
Parsing.Flags for some other syntax to act on (or to surface
as residue if no one does):
#BeforeBuild:
{
"Parsing": { "Flags": ["G02"] },
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
"Parsing": { "Flags": ["G02"] },
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
R-format degenerate (chord = 2R, semicircle): start (0,0,0)
→ end (10,0,0), R=5. perpDistSq resolves to 0 so the
computed center collapses to the chord midpoint (5,0,0); no
sqrt drift on this branch:
#BeforeBuild:
{
"Parsing": { "Flags": ["G02"], "R": 5 },
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
"MotionState": { "Term": "G02" },
"MotionEvent": {
"Form": "McArc",
"ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
"PlaneNormalDir": 2,
"IsCcw": false,
"AdditionalCircleNum": 0
}
}
R-format non-trivial: G02 90° arc from (0,0,0) to
(10,10,0) with R=10. The center comes from the cross-product
+ sqrt + normalize path inside ResolveCenterFromR(Vec3d, Vec3d, int, bool, double),
but for this particular axis-aligned chord the rounding errors
cancel and the center lands at exactly (10, 0, 0) — i.e.
no ULP drift here, in contrast to e.g.
McAbcCyclicPathSyntax's rad/deg round-trip:
#BeforeBuild:
{
"Parsing": { "Flags": ["G02"], "R": 10 },
"ProgramXyz": { "X": 10, "Y": 10, "Z": 0 }
}
#AfterBuild:
{
"ProgramXyz": { "X": 10, "Y": 10, "Z": 0 },
"MotionState": { "Term": "G02" },
"MotionEvent": {
"Form": "McArc",
"ArcCenter": { "X": 10, "Y": 0, "Z": 0 },
"PlaneNormalDir": 2,
"IsCcw": false,
"AdditionalCircleNum": 0
}
}
G03 CCW with I/J — same geometry as case 0 (start (0,0,0),
end (10,0,0), I=5 J=0 → center (5,0,0)) but the G03
flag flips IsCcw to true. Direction is the only
differentiating output; arc-center math is unchanged:
#BeforeBuild:
{
"Parsing": { "Flags": ["G03"], "I": 5, "J": 0 },
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
"ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
"MotionState": { "Term": "G03" },
"MotionEvent": {
"Form": "McArc",
"ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
"PlaneNormalDir": 2,
"IsCcw": true,
"AdditionalCircleNum": 0
}
}
Full circle G02 — start == end (both (0,0,0)), I=5 J=0
places center off-start at (5,0,0). The
isFullCircle guard (chord length < 1e-6 and
center-to-start > 1e-6) flips AdditionalCircleNum to 1
so a downstream motion semantic knows to draw the closed loop:
#BeforeBuild:
{
"Parsing": { "Flags": ["G02"], "I": 5, "J": 0 },
"ProgramXyz": { "X": 0, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
"ProgramXyz": { "X": 0, "Y": 0, "Z": 0 },
"MotionState": { "Term": "G02" },
"MotionEvent": {
"Form": "McArc",
"ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
"PlaneNormalDir": 2,
"IsCcw": false,
"AdditionalCircleNum": 1
}
}
Constructors
CircularMotionSyntax()
Initializes a new instance with default settings.
public CircularMotionSyntax()
CircularMotionSyntax(XElement)
Initializes a new instance by deserializing from the given XML element.
public CircularMotionSyntax(XElement src)
Parameters
srcXElementSource XML element.
Properties
Name
Syntax kind name (typically the concrete type name).
public string Name { get; }
Property Value
XName
XML element name used to register this syntax with XFactory.
public static string XName { get; }
Property Value
Methods
Build(LazyLinkedListNode<SyntaxPiece>, List<INcDependency>, NcDiagnosticProgress)
Build syntax arrangement into the
syntaxPieceNode in-place.
public void Build(LazyLinkedListNode<SyntaxPiece> syntaxPieceNode, List<INcDependency> ncDependencyList, NcDiagnosticProgress ncDiagnosticProgress)
Parameters
syntaxPieceNodeLazyLinkedListNode<SyntaxPiece>ncDependencyListList<INcDependency>ncDiagnosticProgressNcDiagnosticProgress
MakeXmlSource(string, string, bool)
Creates an XML representation of the object. This method may also generate additional resources such as related files.
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
Parameters
baseDirectorystringThe base directory for resolving relative paths
relFilestringThe relative file path for the XML source
exhibitionOnlyboolif true, the extended file creation is suppressed.
Returns
- XElement
An XML element representing the object's state
Remarks
For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied.
The baseDirectory is typically the folder at the nearest configuration file folder.
Since the folder can be moving with the configuration file.