Class SoftNcOptProc
SoftNc NC-optimization orchestrator: classifies the final-layer SyntaxPiece stream (NcOptPieceClassifier), solves the per-step feed adjustments (StepFeedSolver), regenerates the NC text through the mixed patch/splition writeback (NcOptMixedPatchConverter over NcPatchWriter) and writes the optimized files.
public class SoftNcOptProc
- Inheritance
-
SoftNcOptProc
- Inherited Members
- Extension Methods
Remarks
Ported from HiNc NcOptProc.Optimize / OptimizeToFiles /
GetOptNcLines (frozen HardNc baseline). Message ids
and stage ordering mirror the HardNc pipeline. Text regeneration replaces
the HardNc line re-synthesis with anchored token edits over the verbatim
block text (patch mode) — untouched lines round-trip byte-identically —
and, for SplitionPiecePack pieces, with the per-fragment
text rewrite planned by BuildSplitionPlan(SplitionPiecePack, List<INcOptPiecePack>, int, SortedList<int, NcOptOption>, int, List<MachiningStep>, string, NcTagValueKind, FileWritebackGroup, NcOutputDecimalDigits, double, ref double, ref double, IMachineKinematics, IProgress<IMessage>, NcDiagnosticProgress, ref bool, ref bool) (P2).
Compensation stage: when any seed option carries a non-zero CompensationMask, BuildCompensation(ICuttingPara, List<INcOptPiecePack>, List<MachiningStep>, SortedList<int, NcOptOption>, IProgress<IMessage>) fills the PACK adjustments (the fixed handoff — the HardNc baseline wrote the context side the output never read, see the method remarks) and the splition plan builder consumes them: the essential filter keeps compensated fragments and their neighbors, and each fragment endpoint is offset by the tool-running compensation vector rotated into the program frame (CdnTransformToolRunningToProgram). With no mask set anywhere the build call is skipped (only the stage-parity message is emitted) and every adjustment keeps its null compensation — the whole flow is a strict no-op.
Methods
GetMachineRapidFeedrate_mmds(MachiningSession)
Resolves the machine rapid traverse feedrate in mm/s from the session's
effective dependency list — the SoftNc equivalent of
HardNcEnv.RapidFeedrate_mmds.
public static double GetMachineRapidFeedrate_mmds(MachiningSession machiningSession)
Parameters
machiningSessionMachiningSessionThe machining session; may be null.
Returns
Remarks
The source is the maximum linear-axis (X/Y/Z) rate of the pipeline's
IRapidFeedrateConfig (the brand parameter table, e.g.
Fanuc #1420). For legacy projects this equals the HardNc value exactly:
SoftNcRunner.PopulateLegacyMachineConfig writes the legacy
HardNcEnv XML RapidFeedrate_mmdmin onto all three linear
axes, and the unconfigured-table default (20000 mm/min,
ControllerParameterTableBase) matches the
HardNcEnv default. Returns NaN when no
config is reachable (no played session state); callers then fall back
per piece via
ResolveRapidFeedrate_mmds(double, List<MachiningStep>, IndexSegment), or — for
the modal-F register seeds and the pre-first-F modal fallback — to the
20000 mm/min sentinel via
GetEffectiveMachineRapidFeedrate_mmds(double).
OptimizeToFiles(ICuttingPara, MachiningSession, IReadOnlyList<SyntaxPiece>, List<MachiningStep>, MachiningToolHouse, string, string, IProgress<IMessage>, NcDiagnosticProgress, CancellationToken, ReadBulkDelegate<StepLuggage>, ReadBulkDelegate<StepBrief>)
Optimizes the played NC program and writes the optimized files.
public List<NcConversion> OptimizeToFiles(ICuttingPara millingPara, MachiningSession machiningSession, IReadOnlyList<SyntaxPiece> finalLayerPieces, List<MachiningStep> machiningSteps, MachiningToolHouse machiningToolHouse, string baseDirectory, string relFileTemplate, IProgress<IMessage> mixedProgress, NcDiagnosticProgress conversionProgress, CancellationToken cancellationToken, ReadBulkDelegate<StepLuggage> readStepLuggages, ReadBulkDelegate<StepBrief> readStepBriefs)
Parameters
millingParaICuttingParaThe cutting parameters; null disables physics-computable optimization.
machiningSessionMachiningSessionThe machining session; supplies StepIndexToNcOptOptionSortedList, the writeback identity counters and the NcOptimizations retention list (cleared at the start of each run).
finalLayerPiecesIReadOnlyList<SyntaxPiece>Final-layer syntax pieces in execution order, init seed filtered.
machiningStepsList<MachiningStep>The raw strip-pose step projection, UNFILTERED, in strip order (a strip pos without a machining step contributes a null entry) — mirrors the oracle's unfiltered read (
NcOptProc), so a step's list position always equals StepIndex; every step-keyed dictionary of the pipeline lives in that single index space.machiningToolHouseMachiningToolHouseThe machining tool house.
baseDirectorystringBase directory the output paths are combined against.
relFileTemplatestringRelative output path template; RelNcFileTemplateReplacingKeyword and NcNameTemplateReplacingKeyword are expanded per source file.
mixedProgressIProgress<IMessage>The message host for lifecycle / progress logging.
conversionProgressNcDiagnosticProgressDiagnostic home for piece-anchored optimization diagnostics.
cancellationTokenCancellationTokenEnds the run without throwing at its next check – before each piece of the scan, between the steps of the feed solve, after the scan, the feed solve, the extended-segment constraint and the compensation build, and before each output file and each destination piece; a pass between two checks runs to its end, so a cancellation after the compensation build is seen only at the first file – after which it reports
OptimizeToFiles–Canceledbefore the closingOptimizeToFiles–Done, whose count is of the files begun; a file the cancellation came in the middle of is left short.readStepLuggagesReadBulkDelegate<StepLuggage>Reads the stored StepLuggage rows of a step index range; the solver reads one segment of steps at a time on its own thread, before each parallel pass over the segment, with no cache in front of the store.
readStepBriefsReadBulkDelegate<StepBrief>Reads the stored briefs' rows (StepBrief) of a step index range, 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 faulted read the delegate reports and answers null for leaves the segment's 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<NcConversion>
The writeback conversions of the written files (also retained in NcOptimizations); after a cancellation, those of the files begun.
Exceptions
- UnauthorizedAccessException
OptNcNoLimit is not logged in (ThrowIfNotLicensed(IProgress<IMessage>):
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 (EnableStepAdjustmentLog: at the feed solve's start, before any step is solved or any file written). To tell the licence apart ahead of the call, ask ReportIfNotLicensed(IProgress<IMessage>).- 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).
ReportIfNotLicensed(IProgress<IMessage>)
Internal Use Only.
Reports OptimizeNc–NotLicensed to messageHost
when this process holds no OptNcNoLimit login.
The login is normally the one LogInAll() takes at
start-up, so a feature that becomes available later counts only after a
restart.
public static bool ReportIfNotLicensed(IProgress<IMessage> messageHost)
Parameters
Returns
- bool
True when the optimization is refused (and reported); false when the login is there.
ThrowIfNotLicensed(IProgress<IMessage>)
Internal Use Only. ReportIfNotLicensed(IProgress<IMessage>), then throws when it refused, so only the call fails. The native check this replaces (AbortIfNotLoggedIn(AuthFeature)) ended the process, and with it every session the process served.
public static void ThrowIfNotLicensed(IProgress<IMessage> messageHost)
Parameters
Exceptions
- UnauthorizedAccessException
OptNcNoLimit is not logged in; the message is the diagnostic's text.