Table of Contents

Class TimeMapping

Namespace
Hi.Mapping
Assembly
HiMech.dll

Provides mapping between machining steps and time-based measurements (shots), with support for XML serialization and asynchronous loading of measurement data.

public class TimeMapping : IMakeXmlSource, IDisposable
Inheritance
TimeMapping
Implements
Inherited Members
Extension Methods

Constructors

TimeMapping(ClStrip, MachiningToolHouse, string)

Initializes a new instance of the TimeMapping class with the specified CL strip and tool house.

public TimeMapping(ClStrip clStrip, MachiningToolHouse millingToolHouse, string baseDirectory)

Parameters

clStrip ClStrip

The cutter location strip containing the machining steps.

millingToolHouse MachiningToolHouse

The machining tool house containing available tools.

baseDirectory string

The base directory for file paths.

TimeMapping(XElement, string)

Initializes a new instance of the TimeMapping class from XML data.

public TimeMapping(XElement src, string baseDirectory)

Parameters

src XElement

The XML element containing the mapping data.

baseDirectory string

The base directory for resolving relative file paths.

Remarks

This constructor supports legacy XML formats and automatically converts them to the current format. Legacy formats include:

  • NcMapping with MarkIdToFileTimeSection element
  • Entries with MarkID attributes

Properties

BaseDirectory

Gets or sets the base directory for resolving file paths. All relative file paths in the mapping are resolved against this directory.

public string BaseDirectory { get; set; }

Property Value

string

ClStrip

Gets or sets the cutter location strip containing the machining steps. This is used as a reference for mapping time shots to machining steps.

public ClStrip ClStrip { get; set; }

Property Value

ClStrip

KeyToRelFileTimeSectionDictionary

Gets or sets the dictionary mapping keys to file time sections. Each entry maps a unique identifier to a file time section that specifies which portion of a measurement file corresponds to a particular machining operation.

public Dictionary<string, FileTimeSection> KeyToRelFileTimeSectionDictionary { get; set; }

Property Value

Dictionary<string, FileTimeSection>

LineReaded

Gets or sets the callback action that is invoked when a line is read from a measurement file. This can be used to track progress during file loading operations.

public Action<int> LineReaded { get; set; }

Property Value

Action<int>

Remarks

The parameter passed to the action is the current line number being read.

MillingToolHouse

Gets or sets the machining tool house containing available tools. This is used to determine tool-specific parameters during mapping.

public MachiningToolHouse MillingToolHouse { get; set; }

Property Value

MachiningToolHouse

RelFileToTimeShotListDictionary

Gets or sets the cache of time shot lists loaded from files. This is a thread-safe dictionary that maps file paths to tasks that load and parse the files. The cache prevents multiple reads of the same file and enables concurrent access.

public ConcurrentDictionary<string, Task<List<ITimeShot>>> RelFileToTimeShotListDictionary { get; set; }

Property Value

ConcurrentDictionary<string, Task<List<ITimeShot>>>

StepToTimeShotListDictionary

Gets a concurrent dictionary mapping step indices to their corresponding time shot lists. This dictionary is populated during the mapping process.

public ConcurrentDictionary<int, List<ITimeShot>> StepToTimeShotListDictionary { get; }

Property Value

ConcurrentDictionary<int, List<ITimeShot>>

XName

Gets the XML element name used for serialization.

public static string XName { get; }

Property Value

string

Remarks

This name is used as the root element when serializing TimeMapping instances to XML. It matches the class name to maintain consistency between code and XML representation.

Methods

CallTimeShotByRelFile(string, CancellationToken?)

Retrieves time shots from a file, using cached results if available.

public List<ITimeShot> CallTimeShotByRelFile(string relFile, CancellationToken? cancellationToken = null)

Parameters

relFile string

The relative path to the file containing time shots.

cancellationToken CancellationToken?

Optional token to cancel the loading operation.

Returns

List<ITimeShot>

A list of time shots from the file. The results are cached for subsequent calls. If the file is already being loaded by another thread, waits for that operation to complete.

Remarks

This method is thread-safe and ensures each file is only read once, even with concurrent access. Any exceptions during file reading are captured and can be inspected through the task's exception property.

Clear()

Clears all mappings and data, including the key-to-file time section dictionary.

public void Clear()

ClearCache()

Clears the cache of loaded time shot data, including file-to-time shot list and step-to-time shot list dictionaries.

public void ClearCache()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

GetShots(int)

Gets the time shots associated with a specific step index.

public List<ITimeShot> GetShots(int stepIndex)

Parameters

stepIndex int

The index of the step to get shots for.

Returns

List<ITimeShot>

A list of time shots associated with the specified step, or null if no shots are found.

LoadTimeShotFiles(CancellationToken?)

Loads all time shot files referenced in the KeyToFileTimeSectionMapping.

public void LoadTimeShotFiles(CancellationToken? cancellationToken = null)

Parameters

cancellationToken CancellationToken?

Optional cancellation token to cancel the operation.

MakeXmlSource(string, string)

Creates an XML representation of the time mapping data.

public XElement MakeXmlSource(string baseDirectory, string relFile)

Parameters

baseDirectory string

The base directory for creating relative file paths.

relFile string

The relative file path (not used in current implementation).

Returns

XElement

An XML element containing the complete time mapping data.

Remarks

The XML structure includes:

  • A root TimeMapping element
  • An Entrys element containing Entry elements
  • Each Entry has a Key attribute and FileTimeSection child element

Map(Range<int>, FileTimeSection, CycleSamplingMode, CancellationToken?)

Maps the specified step section to time shots using the provided file time section and cycle sampling mode. This method is thread-safe and can be called concurrently.

public void Map(Range<int> stepSection, FileTimeSection relFileTimeSection, StepTimeShotUtil.CycleSamplingMode cycleSamplingMode, CancellationToken? cancellationToken = null)

Parameters

stepSection Range<int>

The range of step indices to process.

relFileTimeSection FileTimeSection

The file time section containing file path and time range.

cycleSamplingMode StepTimeShotUtil.CycleSamplingMode

The cycle sampling mode to use.

cancellationToken CancellationToken?

Optional cancellation token to cancel the operation.

WaitMapping()

Waits for all mapping operations to complete. This method blocks until all concurrent mapping tasks have finished.

public void WaitMapping()