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.
public MachiningSession(IMachiningService host)
Parameters
hostIMachiningService
Properties
CurrentSourceCommand
Gets or sets the current source command being processed.
public IIndexedFileLine CurrentSourceCommand { get; set; }
Property Value
FileIndexOnRunCommand
File index counter, auto-incremented per RunControlLines(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, control runners, player, sinks, base directory, …) it needs to run NC/CSV control lines.
public IMachiningService Host { get; }
Property Value
IsNcOptOptionListUpdatedByStep
Internal Use Only.
public bool IsNcOptOptionListUpdatedByStep { get; set; }
Property Value
IsRunningControlLines
True while a control file is actively being played through the runner (the
paced PlayControlFile(IControlRunner, string, string) loop). A runner-suit switch must not run
while this is true: the runner's RunControlLines 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.
public bool IsRunningControlLines { get; }
Property Value
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
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, Func<int, MillingStepLuggage>, Action) run (one per written optimized NC file, in written order): 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 RunControlLines(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.
public PacePlayee PacePlayee { get; set; }
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
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.
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
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
Methods
BeginPreserve()
Begins a preserve section in the optimization process.
public void BeginPreserve()
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.
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()
OptimizeNcFiles(string, string, ICuttingPara, IProgress<IMessage>, CancellationToken, Func<int, MillingStepLuggage>, Action)
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.
public List<string> OptimizeNcFiles(string baseDirectory, string relNcFileTemplate, ICuttingPara millingPara, IProgress<IMessage> messageProgress, CancellationToken cancellationToken, Func<int, MillingStepLuggage> luggageGetter = null, Action clearLuggageCache = 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.millingParaICuttingParaThe cutting parameters; null disables physics-computable optimization.
messageProgressIProgress<IMessage>Optional message sink for lifecycle / progress reporting.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
luggageGetterFunc<int, MillingStepLuggage>Optional thread-safe map from step index to MillingStepLuggage; defaults to MillingStepLuggageReader.
clearLuggageCacheActionOptional end-of-run cache clear hook; defaults to the luggage reader's cache clear.
Returns
PlayClFile(string, string)
Plays an NX-CL (CLSF) file with pace control.
public void PlayClFile(string baseDirectory, string relFilePath)
Parameters
PlayCsvFile(string, string)
Plays a CSV file with pace control.
public void PlayCsvFile(string baseDirectory, string relFilePath)
Parameters
PlayNc(string, string)
Plays NC text with pace control.
public void PlayNc(string ncText, string fileNameAlternative = "--")
Parameters
PlayNcFile(string, string)
Plays an NC file with pace control.
public void PlayNcFile(string baseDirectory, string relFilePath)
Parameters
Preserve()
Preserves one line of NC code in the optimization process.
public void Preserve()
RunClFile(string, string)
Runs an NX-CL (CLSF) file (no pacing); returns the player actions.
public IEnumerable<Action> RunClFile(string baseDirectory, string relFilePath)
Parameters
Returns
RunControlLines(IControlRunner, string, IEnumerable<string>, CancellationToken)
Runs the control lines through controlRunner, producing
the player actions. Session-scoped run loop; reaches project-level resources
via Host.
public IEnumerable<Action> RunControlLines(IControlRunner controlRunner, string relNcFilePath, IEnumerable<string> lines, CancellationToken cancellationToken)
Parameters
controlRunnerIControlRunnerThe control 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.
RunCsvFile(string, string)
Runs a CSV file (no pacing); returns the player actions.
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.
public IEnumerable<Action> RunNc(string ncText, string fileNameAlternative = "--")
Parameters
Returns
RunNcFile(string, string)
Runs an NC file (no pacing); returns the player actions.
public IEnumerable<Action> RunNcFile(string baseDirectory, string relFilePath)
Parameters
Returns
RunNcFileRan()
Internal use only. Invokes NcFileRan.
public void RunNcFileRan()
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
UpdateNcOptOptionMapIfNeeded(int)
Updates the NC optimization option map if needed. 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.
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