Class MachiningSession
- Namespace
- Hi.MachiningProcs
- Assembly
- HiMech.dll
Represents a machining session that manages the execution and optimization of machining operations. Provides functionality for controlling the machining process, handling optimization options, and managing session state. Implements IDisposable to clean up SessionWriters on session end.
public class MachiningSession : IDisposable
- Inheritance
-
MachiningSession
- Implements
- Inherited Members
- Extension Methods
Constructors
MachiningSession(IMachiningService)
Creates a machining session bound to its hosting IMachiningService. Its physics record starts at the count of the host's strip positions then (BeginRecordAt(int); 0 without a host or a strip): the steps already there were played before this session, and no record it takes speaks for them (PhysicsInputFingerprints).
public MachiningSession(IMachiningService host)
Parameters
hostIMachiningService
Properties
CurrentSourceCommand
Gets or sets the current source command being processed.
public IIndexedFileLine CurrentSourceCommand { get; set; }
Property Value
CwePhasePairing
Whether the milling-parameter trainings read the rotation phase of the steps built
from here on by the CWE block pairing instead of the self-bootstrapped lead parameter
(Train) or the seed (ReTrain). Set by a session script or an NC-embedded script and in
effect from that position of the play on, as NcOptOption is: the change
points are recorded by step index (StepIndexToCwePhasePairingSortedList)
and the trainings read each step's value back. Null when this session never set it: the
steps then follow the process-wide default of the training
(MillingTraining.EnableCwePhasePairing) at training time, as before.
public bool? CwePhasePairing { get; set; }
Property Value
- bool?
FileIndexOnRunCommand
File index counter, auto-incremented per RunNcLines(string, IEnumerable<string>, MachiningSession, StepDiagnosticProgress, NcDiagnosticProgress, CancellationToken) call within this session.
Legacy use only. Read and incremented by
HardNcRunner and CsvRunner. SoftNcRunner
no longer touches this field — it allocates file indices through
FileIndexCounterDependency,
which both the runner and inlined-subprogram syntaxes
(SubProgramCallSyntax) share so
every loaded file (top-level program plus every M98 / M198 inline,
including each L repetition) gets a distinct index.
Do not introduce new readers; the field will be removed once the
legacy runners retire.
public int FileIndexOnRunCommand { get; set; }
Property Value
Host
The project-level service hosting this session — injected so the session can reach project-level resources (act runner, NC runners, player, sinks, base directory, …) it needs to run NC program lines.
public IMachiningService Host { get; }
Property Value
IsNcOptOptionListUpdatedByStep
Internal Use Only.
public bool IsNcOptOptionListUpdatedByStep { get; set; }
Property Value
IsNestedNcLines
Whether a run started on the calling thread now is nested in a run of this session: an NC-embedded script of
the session is running on the thread, so a PlayNc(string, string), PlayNcFile or RunNc it calls
plays inside the line of the run that plays the script. A nested run does not wait for the live pipeline at
its start, and leaves at its end what the run around it holds on its open line. Internal use only: the host
reads it at BeginNcRunner(), which every run calls, to drop at an outermost
run's start the selection begins a stopped run left open.
public bool IsNestedNcLines { get; }
Property Value
IsResetPendingAfterStop
Internal Use Only. Whether a reset stands for the next outermost run of this session (a stop, a fault, a run cut short): what the runner consumes when it starts that run from the reset state at the pose the machine stopped at.
public bool IsResetPendingAfterStop { get; }
Property Value
IsRunningNcLines
True while a run of this session is in flight on some thread: a paced play
(PlayNcFile(string, string, NcKind) and its forms, PlayNc(string, string)) for its
paced loop, and every enumeration of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken) – a mission's program file through
RunNcFile(string, string, NcKind), a host's RunNc(string, string) – from its first
MoveNext to its end or its Dispose, pauses included. A runner-suit
switch must not run
while this is true: the runner's RunNcLines iterator is
mid-enumeration and holds this session's SyntaxPieceLayers, so
resetting NcRunnerSessionState underneath it would corrupt the
in-flight walk. The switch entry point checks this and refuses otherwise.
The flag alone does not say WHOSE run it is. A mission's program file and a mission script's
PlayNcFile("...") raise it on the PLAYER thread (the play is paced
and parks at every Pace()), while a host request
that calls PlayNcFile(string, string, NcKind) directly
raises it on that request's own thread, where nothing can interleave with
the growing strip. Callers that may legitimately run inside the former ask
IsRunningNcLinesOnThisThread instead.
public bool IsRunningNcLines { get; }
Property Value
IsRunningNcLinesOffThePlayerThread
Internal Use Only. True when a thread other than the host player's thread is inside a run of this session – a
direct play on a request thread (PlayNcFile(string, string, NcKind), PlayNc(string, string)), an
enumeration of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken) on a thread of the host's own – whether or not the player thread is inside
one too (a mission's program file). TryBeginSessionTeardown() asks this under the gate, for the host's
player reset: the player's own run the reset stops and waits for first, a run on another thread it cannot, and its
reset handlers would end the session under that run. The
player thread is the one that registered while PacePlayer.IsOnPlayerThread was true (AddNcLinesLevel(int)).
public bool IsRunningNcLinesOffThePlayerThread { get; }
Property Value
IsRunningNcLinesOnOtherThreads
True when a thread OTHER than the calling one is inside a run of this session (a paced play, or an enumeration of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)) — whether or not the calling thread is inside one too. This is the exact question a strip sweep on the player thread has to ask: the play parked at the pace point that called it is harmless, any other play keeps growing the strip underneath it. (IsRunningNcLinesOnThisThread alone cannot tell “mine only” from “mine and someone else's”.)
public bool IsRunningNcLinesOnOtherThreads { get; }
Property Value
IsRunningNcLinesOnThisThread
True when the CALLING thread owns a run in flight – it is inside PlayNcFile(string, string, NcKind) /
PlayNc(string, string), or inside an enumeration of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken) (a mission's program file, a host's
RunNc(string, string) / RunNcFile(string, string, NcKind)) – whether parked at one of its pace points
or inside the enumeration itself (an NC-embedded script's act, a SourcedActEntry handler, the loop
body of a script that enumerates RunNcFile). False both when no run is in flight and when the only runs in
flight belong to other threads.
public bool IsRunningNcLinesOnThisThread { get; }
Property Value
Remarks
Parked at a pace point, the strip is not growing underneath the thread: the step-physics recompute rides a pace
point of the player thread – inside a mission's play this is true and the recompute is safe, whereas a direct
play on a request thread leaves it false and the recompute is refused. Inside the enumeration itself the steps
of the block in play may still be building: the host's runtime reset and power reset refuse on it
(ResetRuntime–Refused, PowerReset–Refused).
IsSteppingSentence
True while the player is stepping sentence-by-sentence (pauses at each source-command boundary). Session-run state.
public bool IsSteppingSentence { get; set; }
Property Value
NcConversions
Writeback conversions retained from the latest ConvertClToNcFiles(string, string, IProgress<IMessage>) run (one per written NC file, in written order): the destination SyntaxPiece streams plus the src↔dst NcPieceMaps. This is the hook point for GUI cross-navigation (click a source line ↔ jump to its converted lines). Cleared at the start of each conversion run.
public List<NcConversion> NcConversions { get; }
Property Value
NcLinesPlayingThreadCount
The number of threads currently inside a run of this session (a paced play, or an enumeration of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public int NcLinesPlayingThreadCount { get; }
Property Value
NcOptOption
Gets or sets the NC optimization options for UI operations.
public NcOptOption NcOptOption { get; set; }
Property Value
NcOptimizations
Writeback conversions retained from the latest OptimizeNcFiles(string, string, ICuttingPara, IProgress<IMessage>, CancellationToken, ReadBulkDelegate<StepLuggage>, ReadBulkDelegate<StepBrief>) run (one per written optimized NC file, in written order; after a cancellation during the writing, the last is the file the cancellation left short): the destination SyntaxPiece streams plus the src↔dst NcPieceMaps, for GUI cross-navigation. Deliberately separate from NcConversions so a conversion run and an optimization run do not clear each other's results. Cleared at the start of each optimization run.
public List<NcConversion> NcOptimizations { get; }
Property Value
NcRunnerSessionState
Per-session NC pipeline state shared across RunNcLines(string, IEnumerable<string>, MachiningSession, StepDiagnosticProgress, NcDiagnosticProgress, CancellationToken) calls. Holds lazy-initialized NcDiagnosticProgress and the per-layer LazyLinkedList<T> chain used for cross-file modal continuity.
public NcRunnerSessionState NcRunnerSessionState { get; }
Property Value
PacePlayee
Internal set only. The playee of the player's counted run, set by the host at the run's start and kept after the run ends (its player is the host's one player; a pace through it between runs returns at once); a stop or a reset of that run arms the reset the next outermost run starts from (ArmResetAfterStop()).
public PacePlayee PacePlayee { get; set; }
Property Value
PausedByLease
Internal Use Only.
Whether the run on this session is parked by the cloud lease: MachiningParallelProc.RunStep
met LeaseExpired (MachiningStep–LeaseExpired or
MachiningStep–LeaseEnded) or LeaseStepsExhausted – the steps the
lease reserved are used up (MachiningStep–LeaseStepsExhausted, or, when the account has
nothing left beyond them, MachiningStep–WeeklyQuotaExhausted or
MachiningStep–TrialGrantExhausted) – and paused the player on the refused step. True only
while the run is parked there: cleared when its pace point returns – on the resume that asks for
the step again, the lease restore's or the user's, and on a stop or a reset (the pace point
throws). The project service (HiNc) resumes the player on LeaseRestored
– raised by the install that makes the lease valid again and by the one that brings steps to a
used-up grant – while this is set and never otherwise, so a user's own pause is not overridden.
Written by the player thread, read by the lease client's thread.
public bool PausedByLease { get; set; }
Property Value
PhysicsInputFingerprints
The physics input fingerprints of this session — per mounted tool id, the
workpiece and the environment, each with every distinct value the steps
were computed with. The workpiece and the tool are recorded at every run
start (RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)) and every tool change, right after the
physics packs are invalidated, and the tool at every pack build
(GetToolPhysicsPack(int)); the environment twice per step a play
issues whose sequential physics runs (MachiningParallelProc: as the
step is issued, with the value its spindle-speed cache is built or kept
under, and once its sequential physics has run, with the capability values,
coolant fields and wear switch of that moment), and a recompute writes every
environment its steps carry at its end. RecomputeStepPhysics(StepPhysicsRecomputeOptions)
classifies the current inputs against it and writes it at its end: a
completed recompute leaves the values the steps now carry, one that
rewrote some steps and not the others (cancelled after it wrote, or the
workpiece of one scoped to a tool) adds its inputs beside the earlier
ones. The builds of an NC optimization after the play record the tool too
(OptimizeNcFiles(string, string, ICuttingPara, IProgress<IMessage>, CancellationToken, ReadBulkDelegate<StepLuggage>, ReadBulkDelegate<StepBrief>) drops the packs before its solve): an edit
made since the play is then on record beside the play's value although no
step carries it, so an input put back to the play's value afterwards still
reads as changed to the next recompute with the tool in scope, whose
completion replaces the record (the default scope takes every tool on the
strip; a recompute scoped to another tool leaves it).
No workpiece record is taken per step: a value written in place on the
workpiece's material or cutting parameter and written back between two
records of the workpiece (a run start, a tool change, a recompute that
rewrote steps) is on no record, though steps may have been computed with
it — the material is read by every step as its physics runs, and the
parameter's values are taken by the pack at its build (the minimum uncut
chip thickness, at the tool's first step) and by its native sessions at
the first force step and the first thermal step the pack serves. The host
clears it whenever it clears the steps (its runtime reset), and its record
starts at the strip's count the session is created on
(RecordedFromStepIndex): a
session begun on a kept strip — EndSession then BeginSession
without a runtime reset — cannot vouch for the steps it found there,
whatever it records later.
public PhysicsInputFingerprintTable PhysicsInputFingerprints { get; }
Property Value
PostBlockScripts
Per-line scripts injected externally (without modifying NC files). Key: FileLineIndex of the NC block. Value: C# script text to execute after the NC block. Consumed by CsScriptEndSemantic.
public Dictionary<FileLineIndex, string> PostBlockScripts { get; }
Property Value
PreBlockScripts
Per-line scripts injected externally (without modifying NC files). Key: FileLineIndex of the NC block. Value: C# script text to execute before the NC block. Consumed by CsScriptBeginSemantic.
public Dictionary<FileLineIndex, string> PreBlockScripts { get; }
Property Value
SessionWriters
StreamWriters registered during the session (e.g. by diagnostic output methods). Key: relative output file path. Disposed automatically when the session ends.
public Dictionary<string, StreamWriter> SessionWriters { get; }
Property Value
ShellProgress
Session-level routine / lifecycle message sink on the IMessage
channel (cache reset, file progress, session start/done). Owned here so it is
truly session-scoped — created with the session, released at EndSession.
public ShellProgress ShellProgress { get; }
Property Value
StepIndexToCwePhasePairingSortedList
The change points of CwePhasePairing: the step index a value took effect at, to the value; a sparse list its readers resolve by floor (the entry at or before a step's index). Internal use only: written by UpdateCwePhasePairingMapIfNeeded(int), read by GetCwePhasePairingAt(int).
public SortedList<int, bool> StepIndexToCwePhasePairingSortedList { get; }
Property Value
StepIndexToNcOptOptionSortedList
Gets or sets the mapping of step indices to NC optimization options. For internal use only. Takes effect during internal optimization process.
public SortedList<int, NcOptOption> StepIndexToNcOptOptionSortedList { get; set; }
Property Value
StepTaskBundle
Gets or sets the current step task bundle: the bundle the act runner answered the last step act
with. Null until the session's first step act, the previous play's last bundle after a runtime reset
the session survives (a session script's ResetRuntime()) until the next built step, and one
step ahead of the strip after a stop until the next act carries the chain on from the strip's last
step. What the shell keys by a step reads ShellThreadStepIndex, not this.
public MachiningParallelProc.StepTaskBundle StepTaskBundle { get; set; }
Property Value
WarnedCutterGeometryTools
Tools already surfaced via an unreasonable cutter-geometry
ConfigurationError (see
WarnIfCurrentToolCutterGeometryUnreasonable(MachiningSession, StepDiagnosticProgress, int?)).
Same keying and emission-point rationale as
WarnedFluteMaterialMissingTools.
public HashSet<IMachiningTool> WarnedCutterGeometryTools { get; }
Property Value
WarnedFluteCountZeroTools
Tools already surfaced via a zero-flute-count
ConfigurationWarning (see
WarnIfCurrentToolFluteCountZero(MachiningSession, StepDiagnosticProgress, int?)).
Same keying and emission-point rationale as
WarnedFluteMaterialMissingTools.
public HashSet<IMachiningTool> WarnedFluteCountZeroTools { get; }
Property Value
WarnedFluteMaterialMissingTools
Tools already surfaced via “FluteMaterial not set”
warning. Keyed by IMachiningTool reference so the dedup is stable
across the two emission points: ProcAct(IAct, MachiningSession, IMachiningService, ISentenceCarrier, CancellationToken, StepDiagnosticProgress) at each
IActTooling, and BeginSession for the tool that may already
be equipped before the session begins (which has no tool ID to dedup with).
Reference equality is more precise than tool ID — the same tool object equipped
twice should warn once, regardless of how it was reached.
public HashSet<IMachiningTool> WarnedFluteMaterialMissingTools { get; }
Property Value
WarnedShankMaterialMissingTools
Tools already surfaced via the “ShankMaterial
not set” warning (Tool-ShankMaterial–Missing, see
WarnIfCurrentToolFluteMaterialMissing(MachiningSession, StepDiagnosticProgress, int?)). Same keying
and emission-point rationale as WarnedFluteMaterialMissingTools.
public HashSet<IMachiningTool> WarnedShankMaterialMissingTools { get; }
Property Value
WarnedShaperProfileTools
Tools already surfaced via an APT shaper-profile self-agreement
ConfigurationError / ConfigurationWarning (see
WarnIfCurrentToolShaperProfileInconsistent(MachiningSession, StepDiagnosticProgress, int?)).
Same keying and emission-point rationale as
WarnedFluteMaterialMissingTools.
public HashSet<IMachiningTool> WarnedShaperProfileTools { get; }
Property Value
WarnedStickConvexTools
Tools already surfaced via a Cutter-StickConvex–Unavailable
ConfigurationError – the cloud licence server did not provide the
cutting shape of the tool's APT profile (see
WarnIfCurrentToolStickConvexUnavailable(MachiningSession, StepDiagnosticProgress, int?)).
Same keying and emission-point rationale as
WarnedFluteMaterialMissingTools.
public HashSet<IMachiningTool> WarnedStickConvexTools { get; }
Property Value
WarnedThermalConstantMaterials
Materials already surfaced via a thermal-constants warning
(Material-ThermalConstants–NotGiven / –NotFinitePositive /
–OutOfRange) or, for a cutter material, the wear-curves warning
(Material-WearCurves–NotGiven), see
WarnIfThermalConstantsUnreasonable(MachiningSession, StepDiagnosticProgress, int?), keyed by
the owner — the tool as the warning names it (tool [3], or the currently
equipped tool at the session begin), or the workpiece — and the content
(GetContentKey(IStructureMaterial): the name, the
three constants and whether the wear curves are given,
HasWearCurves). The values
are the cause, so the content and not the object: a solid-end cutter's flute and
shank, one object or two equal ones, are one warning, and an edit to other values
— a constant, a curve given or dropped — is named again, by both checks; the
owner, so every tool that carries a bad material is named, each once.
public HashSet<(string Owner, (string Name, double HeatConductivity_WdmK, double Density_gdcm3, double HeatCapacity_JdgK, bool WearCurvesGiven) Content)> WarnedThermalConstantMaterials { get; }
Property Value
- HashSet<(string Owner, (string Name, double HeatConductivity_WdmK, double Density_gdcm3, double HeatCapacity_JdgK, bool WearCurvesGiven) Content)>
WarnedUnreadableMaterialFiles
Material side files already surfaced via a “could not be read” warning
(Tool-FluteMaterial–Unreadable / Tool-ShankMaterial–Unreadable),
keyed flute: / shank: + the file. The cause is the file,
not the tool: the tool equipped at BeginSession (the runtime
face's copy) and the one a T-code mounts from the tool house are
different objects referencing the same file, so a reference-keyed
dedup would name the same unreadable file twice.
public HashSet<string> WarnedUnreadableMaterialFiles { get; }
Property Value
Methods
ArmResetAfterStop()
Internal Use Only. Arms the reset the next outermost run starts from, and the alignment of the machine to the
pose the pipeline executed last (MachiningActRunner.ArmPoseAlignment), as a stop of the player's
run does (a test's host without a player, a caller that stops a run outside the player).
public void ArmResetAfterStop()
BeginPreserve()
Begins a preserve section in the optimization process. A run that stops inside the section closes it as it ends, as a run that ends with the section still open does.
public void BeginPreserve()
ClearCwePhasePairingMap()
Forgets the change points of CwePhasePairing: a runtime reset starts the strip again at step 0, so the points recorded for the previous strip would apply to the steps of the next one at the wrong positions (and a value equal to the last recorded one would not be recorded again). The current CwePhasePairing stays and is recorded afresh at the next play's first act. Internal use only: called by the runtime reset.
public void ClearCwePhasePairingMap()
ClearNcOptOptionMap()
Forgets the change points of NcOptOption: a runtime reset starts the strip again at step 0, so the points recorded for the previous strip would resolve the steps of the next one at the wrong positions – and since UpdateNcOptOptionMapIfNeeded(int) records only a change from the last recorded option, the next play's first steps would fall to an older point whenever the current option equals the previous strip's last. The current NcOptOption stays and is recorded afresh at the next play's first act. Internal use only: called by the runtime reset, as ClearCwePhasePairingMap() is.
public void ClearNcOptOptionMap()
ConvertClToNcFiles(string, string, IProgress<IMessage>)
Converts the CLSF play of this session into Fanuc NC files —
writeback synthesis mode, two stages
(NcSynthesisConverter over
FanucNcSentenceComposer):
walks the final SyntaxPieceLayers
layer, groups pieces per source file, converts each group into a
destination piece stream with the src↔dst map (stage one; retained in
NcConversions), and serializes the destination stream
to text (stage two, ToLines(IEnumerable<SyntaxPiece>)). The
synthesis re-serializes the brand-neutral sections into Fanuc
vocabulary (MSYS tilt → G68.2, RTCP → G43.4, motions →
G00/G01/G02/G03 with rotary words). Requires a prior play
(e.g. PlayClFile(string, string)) on an XYZABC machine chain — a
pure-CL milling device leaves no machine-solved sections to
serialize.
Conversion diagnostics go to the manipulation home
(NcManipulationDiagnosticProgress,
cleared at run start) — not to the play-time
NcDiagnosticProgress. GUI consumers
observe that home directly (webservice: NC Manipulation message tab);
messageProgress carries only the lifecycle
messages.
public IReadOnlyList<string> ConvertClToNcFiles(string baseDirectory, string relNcFileTemplate = "Output/[NcName].nc", IProgress<IMessage> messageProgress = null)
Parameters
baseDirectorystringProject root; null falls back to BaseDirectory.
relNcFileTemplatestringOutput path template;
[NcName]is replaced by the source file name,[NcFile]by its slash-flattened relative path.messageProgressIProgress<IMessage>Optional message sink for lifecycle reporting; session callers inject the shell sink, out-of-session callers pass their own (or null).
Returns
- IReadOnlyList<string>
Written NC file paths, relative to
baseDirectory.
CreateStepPhysicsRecomputeJob(StepPhysicsRecomputeOptions)
RecomputeStepPhysics(StepPhysicsRecomputeOptions) as a resumable job: the same recompute, but the caller drives it chunk by chunk (TryRunNextChunk()) and paces between the chunks itself — the player's pace-point queue runs it so that Pause parks it at a chunk boundary and Stop cancels it there. Nothing runs until the first chunk is asked for. Pace is ignored by this form.
public StepPhysicsRecomputer CreateStepPhysicsRecomputeJob(StepPhysicsRecomputeOptions options)
Parameters
optionsStepPhysicsRecomputeOptionsScope override, luggage access, progress and cancellation.
Returns
- StepPhysicsRecomputer
The job; drive it to its end and read Result.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
EndPreserve()
Ends a preserve section in the optimization process.
public void EndPreserve()
EndSessionTeardown()
Internal Use Only. Ends a teardown marked by TryBeginSessionTeardown() (the session may be disposed by then).
public void EndSessionTeardown()
FindPacedCallRefusal()
Internal Use Only. Why a call that rides this session from outside its NC play – an act (IsPacedActAdmitted()),
the host's runtime reset or session end – is refused on the calling thread, in the order of the play
gate's two conditions and without a report: PlayerLockedOnAnotherThread when the player is
locked (a mission's run – playing, paused or between its commands – or a job on the player such as the step-physics
recompute) and this is not the player thread, else AnotherThreadPlaying when another thread
is inside a run of this session, else None. A call on the step pipeline's pump thread (a
step-built handler's) is None whatever the player does: the runner refuses it itself
(ThrowIfOnPump), on the step it belongs to, so an answer from here would only tell the handler to wait for its own play. The host's session begin, made with no session to ask, reads the player's lock alone (HiNc LocalProjectService.BeginSession).
public MachiningSession.PacedPlayRefusal FindPacedCallRefusal()
Returns
GetCwePhasePairingAt(int)
The CwePhasePairing value in effect for the step at
stepIndex: the change point at or before it; null when the session
had not set the value by then (the step follows the training's process-wide default).
public bool? GetCwePhasePairingAt(int stepIndex)
Parameters
stepIndexintThe step index.
Returns
- bool?
The value in effect, or null.
GetToolPhysicsPack(int)
Gets the frozen physics pack for a tool id — building it on first access — or null when the id is not in the tool house. The para-dependent members are keyed to the current workpiece cutting para. Safe to call from parallel step tasks: the pack is immutable and published atomically, and a concurrent rebuild computes identical content.
public MillingToolPhysicsPack GetToolPhysicsPack(int toolId)
Parameters
toolIdintThe tool-house id of the tool.
Returns
- MillingToolPhysicsPack
The frozen pack, or null for an unknown tool id.
InvalidateToolPhysicsPacks()
Drops every cached physics pack so the next access rebuilds from the live objects. Called by the paths that know the tool/cutter/para state may have changed: every run-op start (RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken), so edits made between plays always take effect), the tool-change act, a step-physics recompute before it computes (RecomputeStepPhysics(StepPhysicsRecomputeOptions)), and the start of an NC optimization when no NC lines run on this session (OptimizeNcFiles(string, string, ICuttingPara, IProgress<IMessage>, CancellationToken, ReadBulkDelegate<StepLuggage>, ReadBulkDelegate<StepBrief>)), so the solver's probes read packs built from the tool and the para as they are then, not the ones the play froze. An editor that must take effect in the middle of a running play calls this explicitly — otherwise a mid-play edit of what a pack freezes lands at the play's next tool change, at a recompute that computes during the play, or on the next play, the latter also the only mode with a deterministic outcome. The workpiece material is in no pack: the steps read it as their physics is computed, so a field written on it in place takes effect from the next such step.
public void InvalidateToolPhysicsPacks()
IsPacedActAdmitted()
Internal Use Only. The gate of an act played outside an NC play – a session script's PlayAct and the teleports, a
host's Act – under the conditions of a second play. Answers false, with one Play–BusyAct on
ShellProgress, when the player is locked (a mission's run – playing, paused or between its commands – or a
job on the player such as the step-physics recompute) and the caller is not the player thread, or with one
Play–BusyActAnotherThread when another thread is inside a run of this session (PlayNcFile(string, string, NcKind) and its brand, CSV and CL forms,
PlayNc(string, string), or an enumeration of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken) – a mission's program file). Admitted: a mission's
own call on the player thread; an NC-embedded script's call on the thread of
its play (the player thread, or a direct play's thread while the player is idle); a call while the player is idle and no
other thread plays; and a call on the step pipeline's pump thread (a step-built handler's), which
FindPacedCallRefusal() passes and the act runner refuses itself. The act registers no play of its own, so
two acts from two threads while nothing plays are both admitted, and so is
a play that starts on another thread while an act is in flight; in either window a count one thread reads may name a
position the other thread's step takes (ShellThreadStepIndex).
public bool IsPacedActAdmitted()
Returns
NoteResumeConsumed()
Internal Use Only. Called by the runner once it has consumed the session's resume request (Resume): the resume seed appended, or a fresh pipeline's init seed placed at the pose. The reset no longer stands.
public void NoteResumeConsumed()
OptimizeNcFiles(string, string, ICuttingPara, IProgress<IMessage>, CancellationToken, ReadBulkDelegate<StepLuggage>, ReadBulkDelegate<StepBrief>)
Optimizes the NC program played in this session (SoftNc pipeline) and
writes the optimized NC files: classifies the final
SyntaxPieceLayers layer, solves the
per-step feed adjustments from milling physics, patches the F words
onto the verbatim source text and writes one output file per source NC
file by relNcFileTemplate. Conversions are retained
in NcOptimizations; piece-anchored diagnostics go to the
manipulation home
(NcManipulationDiagnosticProgress,
cleared at run start).
Requires a prior play and a logged-in
OptNcNoLimit license; without the license it
reports OptimizeNc–NotLicensed and throws
(Hi.NcOpt.SoftNcOptProc.ThrowIfNotLicensed). Refused as well, with
OptimizeNc–StripSpansPipelineReset on messageProgress and
nothing written, while the strip's steps were built under more than one NC
pipeline (NcPipelineResetStepIndex: a mission
script's PowerReset(), a switch of the controller brand or preset, or a
session ended between two plays, the strip kept): the last layer holds the pieces
of the files played since the reset, numbered from 0 again, and the classifier
would match them to the earlier files' steps and options from step 0. Optimize
before the reset, or clear the strip (the runtime reset, the player's reset) before
playing the files to optimize.
public List<string> OptimizeNcFiles(string baseDirectory, string relNcFileTemplate, ICuttingPara millingPara, IProgress<IMessage> messageProgress, CancellationToken cancellationToken, ReadBulkDelegate<StepLuggage> readStepLuggages, ReadBulkDelegate<StepBrief> readStepBriefs)
Parameters
baseDirectorystringProject root; null falls back to BaseDirectory.
relNcFileTemplatestringOutput path template;
[NcName]is replaced by the source file name,[NcFile]by its slash-flattened relative path.millingParaICuttingParaThe cutting parameters; null disables physics-computable optimization.
messageProgressIProgress<IMessage>Optional message sink for lifecycle / progress reporting.
cancellationTokenCancellationTokenEnds the run without throwing at its next check, which reports
OptimizeToFiles–Canceledbefore the closingOptimizeToFiles–Done; the files begun are returned, a file the cancellation came in the middle of left short.readStepLuggagesReadBulkDelegate<StepLuggage>Required. Reads the stored StepLuggage rows of a step index range from the step cache; the solver reads the steps it works on one segment of StepLuggageSegmentSize indices at a time, on its own thread, with no cache in front of the store. A read the delegate reports and answers null for leaves its steps without luggage (a touched one keeps its simulated feedrate; one that cuts nothing is set no limit, as ever).
readStepBriefsReadBulkDelegate<StepBrief>Required. Reads the stored briefs' rows (StepBrief) of a step index range from the step cache, read beside the luggage rows the same way: the solver's physics constraints and its compensation read the stored briefs, not the steps' resident copies (the brief-into-DB chain's C4a). A read the delegate reports and answers null for leaves its touched steps with their simulated feedrate in the feed solve (a step that cuts nothing is set no limit, as ever), as a faulted luggage read does, and, in the compensation build, without a compensation where their destination feed is still the commanded one when the build runs (a step whose feed the run changed, by the solve or by the constraints after it, recomputes its deflection from the luggage).
Returns
- List<string>
Written NC file paths, relative to
baseDirectory; after a cancellation, those of the files begun.
Exceptions
- UnauthorizedAccessException
OptNcNoLimit is not logged in (
OptimizeNc–NotLicensedwas reported and nothing was touched), or an output file could not be written (no diagnostic; files written before it stay), or a per-step adjustment log could not be opened (at the feed solve's start, before any step is solved or any file written). To tell the licence apart ahead of the call, askHi.NcOpt.SoftNcOptProc.ReportIfNotLicensed.- IOException
An output file is held open by another process (no diagnostic; files written before it stay), or a per-step adjustment log is (at the feed solve's start, before any step is solved or any file written).
PlayBrandNcFile(string, string)
Plays a famous-brand NC code file with pace control (no kind dispatch — always ActiveNcRunner). A play that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public void PlayBrandNcFile(string baseDirectory, string relFilePath)
Parameters
PlayClFile(string, string)
Plays an NX-CL (CLSF) file with pace control. A play that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public void PlayClFile(string baseDirectory, string relFilePath)
Parameters
PlayCsvFile(string, string)
Plays a CSV file with pace control. A play that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public void PlayCsvFile(string baseDirectory, string relFilePath)
Parameters
PlayNc(string, string)
Plays NC text with pace control. A play that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public void PlayNc(string ncText, string fileNameAlternative = "--")
Parameters
PlayNcFile(string, string, NcKind)
Plays an NC program file with pace control, the runner picked by
kind (Auto = by file
extension, see DetectByPath(string)). A play that follows a stop in this session
starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public void PlayNcFile(string baseDirectory, string relFilePath, NcKind kind = NcKind.Auto)
Parameters
Preserve()
Preserves one line of NC code in the optimization process: an NC-embedded command, whose line is the one that carries it. The option is turned on again at the line's end (OnCurrentLineEnd); a run stopped before that end turns it on again as it ends, so the next run's first line is optimized as its program says.
public void Preserve()
RearmOneShotToolWarnings()
Empties the one-shot tool and material warning sets above (WarnedFluteMaterialMissingTools, WarnedShankMaterialMissingTools, WarnedUnreadableMaterialFiles, WarnedCutterGeometryTools, WarnedShaperProfileTools, WarnedStickConvexTools, WarnedFluteCountZeroTools, WarnedThermalConstantMaterials): a runtime reset clears the messages they were said in while the session lives on, so the re-play says them again when it meets the same thing.
public void RearmOneShotToolWarnings()
RecomputeStepPhysics(StepPhysicsRecomputeOptions)
Recomputes the step physics of the finished steps from the stored
cutter-workpiece engagement with the CURRENT inputs, in place — no
replay. Call on the player thread, or when no play is live. Classifies
what differs from what the steps carry, by the record in PhysicsInputFingerprints
(cutting para / flute geometry / flute offset or setup angle → the force kernel reruns on
the touched steps; tool or workpiece material → the briefs are rebuilt
from the stored force luggage without the kernel; environment, which is
the ambient temperature, the coolant condition, the spindle capability
and the wear and initial spindle temperature settings → the sequential
chain alone, from the first step), then does the runner's WaitAll, the cutter
cache clears, the pack invalidation, the compute (reading each chunk's
stored rows once through LuggageReader and
BriefReader), the amendments' write-back
through AmendmentWriter (the force column and
the briefs' rows, one transaction a chunk),
the drawing refresh and the last-bundle patch itself.
The host forwards the authored workpiece physics onto the runtime
equipment BEFORE calling, and drains the runner's pipeline (its
WaitAll) before that forward, so no step still in flight is computed
with what the forward brings; the WaitAll here then finds the
pipeline drained and is cheap. See StepPhysicsRecomputeResult
for the outcomes.
public StepPhysicsRecomputeResult RecomputeStepPhysics(StepPhysicsRecomputeOptions options)
Parameters
optionsStepPhysicsRecomputeOptionsScope override, luggage access, progress, cancellation and pacing.
Returns
- StepPhysicsRecomputeResult
What was done, with the replaced strip range and the counts.
ResetNcPipeline()
Internal Use Only. Resets the NC pipeline of this session – Reset(): the next
RunNcLines(string, IEnumerable<string>, MachiningSession, StepDiagnosticProgress, NcDiagnosticProgress, CancellationToken) re-initialises from scratch, its file and sentence indices from 0 – and, when
the pipeline had been initialised, notes the drop on the host's act runner first
(NoteNcPipelineReset(): the strip keeps its steps, so over a non-empty strip the
steps built from here on are numbered by a pipeline the earlier ones were not, which OptimizeNcFiles(string, string, ICuttingPara, IProgress<IMessage>, CancellationToken, ReadBulkDelegate<StepLuggage>, ReadBulkDelegate<StepBrief>)
refuses to match). The host's one reset seam calls it – a mission script's PowerReset(), a switch of the
NC runner (a brand or preset switch, a runner suit read), and the runtime reset, whose strip clear comes first
and takes the note with it – and so does Dispose(). A pipeline not initialised since its last reset
built none of the strip's steps and is not noted.
public void ResetNcPipeline()
RunBrandNcFile(string, string)
Runs a famous-brand NC code file (no pacing, no kind dispatch — always ActiveNcRunner); returns the player actions (gated as RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)). A run that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public IEnumerable<Action> RunBrandNcFile(string baseDirectory, string relFilePath)
Parameters
Returns
RunClFile(string, string)
Runs an NX-CL (CLSF) file (no pacing); returns the player actions (gated as RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)). A run that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public IEnumerable<Action> RunClFile(string baseDirectory, string relFilePath)
Parameters
Returns
RunCsvFile(string, string)
Runs a CSV file (no pacing); returns the player actions (gated as RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)). A run that follows a stop in this session starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public IEnumerable<Action> RunCsvFile(string baseDirectory, string relFilePath)
Parameters
Returns
RunMachiningStepBuilt(MachiningStep, MachiningStep)
Internal use only. Invokes MachiningStepBuilt.
public void RunMachiningStepBuilt(MachiningStep preStep, MachiningStep curStep)
Parameters
preStepMachiningStepcurStepMachiningStep
RunMachiningStepSelected(MachiningStep)
Internal use only. Invokes MachiningStepSelected.
public void RunMachiningStepSelected(MachiningStep machiningStep)
Parameters
machiningStepMachiningStep
RunNc(string, string)
Runs NC text (no pacing); returns the player actions. Refused, with Play–Busy, Play–BusyAnotherThread or Play–BusyReset on
ShellProgress and an empty sequence, under the conditions of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken) – decided
at the first enumeration, where the run is registered as the calling thread's for the enumeration
(IsRunningNcLines; an enumerator dropped without Dispose keeps the level). The text is
registered as the line source of fileNameAlternative at the call, ahead of that decision: a
refused run has still replaced what the name served before. A run that follows a stop in this session
starts in the program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public IEnumerable<Action> RunNc(string ncText, string fileNameAlternative = "--")
Parameters
Returns
RunNcFile(string, string, NcKind)
Runs an NC program file (no pacing), the runner picked by
kind (Auto = by file
extension, see DetectByPath(string)); returns the
player actions. Refused, with Play–Busy, Play–BusyAnotherThread or Play–BusyReset on ShellProgress and an empty sequence,
under the conditions of RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken) – decided at the first enumeration, where the run is
registered as the calling thread's for the enumeration (IsRunningNcLines; an enumerator
dropped without Dispose keeps the level). A run that follows a stop in this session starts in the
program-end reset state, at the pose the machine stopped at (see RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)).
public IEnumerable<Action> RunNcFile(string baseDirectory, string relFilePath, NcKind kind = NcKind.Auto)
Parameters
Returns
RunNcFileRan()
Internal use only. Invokes NcFileRan.
public void RunNcFileRan()
RunNcLines(INcRunner, string, IEnumerable<string>, CancellationToken)
Runs the NC program lines through ncRunner, producing
the player actions. Session-scoped run loop; reaches project-level resources
via Host. Every run of the session converges here, so this is where a run is admitted
and registered: refused, with one Play–Busy, Play–BusyAnotherThread or Play–BusyReset on ShellProgress and nothing of the
program run, under the two conditions of PlayNcFile(string, string, NcKind) – the player
locked (a mission's run, playing, paused or between its commands, or a job on the player such as the
step-physics recompute) and the caller not the player thread (Play–Busy); another thread inside a run of this
session (Play–BusyAnotherThread) – and, at the registration, under a third: a host's teardown of the session in
flight and the caller not the player thread (Play–BusyReset, TryBeginSessionTeardown()) – and
otherwise registered as a run of the calling thread for the whole enumeration
(IsRunningNcLines and its siblings read it). A thread already inside a run of its own
(IsRunningNcLinesOnThisThread: inside PlayNcFile / PlayNc(string, string), which judged the
two conditions ahead of their materialise, or inside another enumeration of this method) is not judged
again, the lock clause included – the outer run's admission stands – and adds a level. The method is an
iterator: the admission is decided at the first enumeration, not by the call, and the level is released
when the enumeration completes or is disposed, on the thread that started it. An enumerator dropped
without Dispose keeps its thread's level until the session object dies: every other thread's run
is refused meanwhile, and that thread's own runs are not judged (foreach and LINQ dispose).
The run that follows a stop in the same session -- a stopped run (the player's run stopped wherever the stop landed, a stop pressed while the player stood finished, an enumeration its consumer disposed before its end), a faulted one, or one a licence refusal cut short -- starts as a run after the stopped program's end would: in HiNC's program-end reset state, modelled on a controller's RESET -- tool length compensation (Fanuc's G43 / G44 / G43.4, Siemens' TRAORI, Heidenhain's M128 / TCPM; Siemens' D and Heidenhain's TOOL CALL compensation stay), cutter radius compensation, the tilted plane, the canned cycle, the modal macro call and the volatile variables cancelled; the positioning, plane, feed, spindle and work-offset modals kept -- HiNC's choices where each controller's reset keeps or returns its own set (ProgramEndSyntax lists the differences) -- at the position the machine stopped at, which is the pose of the last motion the pipeline executed (a step whose cut ran, a motion with no step to build, a teleport), with the tool that was in the spindle there, and with the kept modals as the block before the first motion that did not execute left them: what the shell had run ahead of that motion -- blocks, a tool change -- is dropped, as a controller drops the blocks it read ahead of the motion in progress; when every motion executed, as the last block the shell executed left them -- after a nested run the outer program's, as a controller's reset inside a subprogram returns to the main program. A run that ended at its last block hands its modal state and position on as before (a convention of a mission split over files: a controller stops at a file's end without M02/M30 and wants a RESET first). Only a hosted session with the SoftNc runner has this; a session without a host, and the HardNc runner, keep the runner's own boundary (RunNcLines(string, IEnumerable<string>, MachiningSession, StepDiagnosticProgress, NcDiagnosticProgress, CancellationToken)). A fresh NC pipeline after a stop (a power reset, a runner switch) starts its first program at the stopped pose too, in the power-on state its init seed is; without a stop it starts at the configured home as before; a cutter-location or CSV pipeline's first record repositions as a new session's does. Without a stop nothing is aligned: the run goes on behind the one before it as before -- the NC stream from that run's last block, the chain where the play or a setup edit left it, the tool the run's, the valve as the play left it. A runtime reset drops the ledger, re-homes the chain and rebuilds the pipeline, so the next run starts at home (the session object stays; the player's Reset ends it as well).
public IEnumerable<Action> RunNcLines(INcRunner ncRunner, string relNcFilePath, IEnumerable<string> lines, CancellationToken cancellationToken)
Parameters
ncRunnerINcRunnerThe NC runner that parses and runs the lines.
relNcFilePathstringName/path associated with the program.
linesIEnumerable<string>The NC/CSV lines to run.
cancellationTokenCancellationTokenCancellation token.
Returns
- IEnumerable<Action>
The sequence of player actions.
Exceptions
- ErrorTermRoleException
A role branch of the machining chain is marked as an error term (RequireRoleBranchesNotErrorTerm(IMachiningChain)). The method is an iterator: it is thrown when the sequence is first enumerated, not by the call.
RunSourcedActEntry(SourcedActEntry)
Internal use only. Invokes SourcedActEntry.
public void RunSourcedActEntry(SourcedActEntry entry)
Parameters
entrySourcedActEntry
RunSyntaxPieceRan(SyntaxPiece)
Internal use only. Invokes SyntaxPieceRan.
public void RunSyntaxPieceRan(SyntaxPiece syntaxPiece)
Parameters
syntaxPieceSyntaxPiece
TryBeginSessionTeardown()
Internal Use Only. Marks a host's teardown of this session in flight – the player reset (HiNc
LocalProjectService.ResetPlayer), whose handler ends the session and clears its runtime – unless a thread
other than the host player's is inside a run of the session (IsRunningNcLinesOffThePlayerThread): the
check and the mark are one step under the gate the runs register at, so from the mark on, a run such a thread
starts is refused at its registration (Play–BusyReset), after the play's own admission and its
materialise – which an entrance check made before the mark would have let through. The player thread's own runs
(a mission's program file) are not refused: the reset stops that run itself. Pair with
EndSessionTeardown() in a finally.
public bool TryBeginSessionTeardown()
Returns
- bool
True when marked; false when another thread's run is registered, and nothing is marked.
UpdateCwePhasePairingMapIfNeeded(int)
Records the current CwePhasePairing at stepIndex when
the session has set it and it differs from the most recently recorded value – the map
stays a sparse list of change points, like UpdateNcOptOptionMapIfNeeded(int)'s.
Called where that one is: at every act entry of a run and after an NC-embedded script.
Internal use only.
public bool UpdateCwePhasePairingMapIfNeeded(int stepIndex)
Parameters
stepIndexintThe index the next built step gets.
Returns
- bool
True if the map was updated; otherwise, false.
UpdateNcOptOptionMapIfNeeded(int)
Records the current NcOptOption at stepIndex
when it differs from the most recently recorded one, so the map stays a
sparse list of change points — which is what its readers expect: they
resolve a step's option by GetFloor (see
UpdateNcOptOption(Action<NcOptOption>) and the
optimization procs), so an unchanged stretch needs no entries at all.
Internal use only.
public bool UpdateNcOptOptionMapIfNeeded(int stepIndex)
Parameters
stepIndexintThe index of the step to update.
Returns
- bool
True if the map was updated; otherwise, false.
Events
MachiningStepBuilt
Event triggered when a machining step is built.
public event MachiningActRunner.MachiningStepBuiltDelegate MachiningStepBuilt
Event Type
MachiningStepSelected
Event triggered when a machining step is selected.
public event Action<MachiningStep> MachiningStepSelected
Event Type
NcFileRan
Event triggered after an NC/CSV file finishes running (session-scoped).
Bridged to the app-lifetime LocalProjectService.OnNcFileRan in BeginSession.
public event Action NcFileRan
Event Type
OnCurrentLineEnd
Event raised when the current line ends. The event buffer is cleared on every line change, and at the end of every run that is not nested in another: a handler belongs to the line that subscribed it, and a run a stop cut short on a line never reached that line's end.
public event Action<CancellationToken> OnCurrentLineEnd
Event Type
SourcedActEntry
Event triggered for each SourcedActEntry produced during NC/CSV execution.
public event Action<SourcedActEntry> SourcedActEntry
Event Type
SyntaxPieceRan
Event triggered when a syntax piece has been executed.
public event Action<SyntaxPiece> SyntaxPieceRan