Class ClStrip
- Namespace
- Hi.CutterLocations.ClStrips
- Assembly
- HiMech.dll
Represents a CL (Cutter Location) strip for 3D display. This class manages the display and interaction of cutter location points and lines.
public class ClStrip : IDisplayee, IExpandToBox3d, IDisposable
- Inheritance
-
ClStrip
- Implements
- Inherited Members
- Extension Methods
Remarks
The strip draws itself in slices of slice_distance positions: a line drawing for each complete slice (and a point drawing beside it while IsShowDot is set), and a head and a tail drawing for the partial slices at the two ends of the display range. They are rebuildable drawings: none of them keeps the GL share group alive, and once the group died (the process held no GL context any more, as after its last canvas closed) they are stale and draw nothing. The next Display(Bind) finds that out from ShareGroupGeneration, lets them go and makes them again from the positions, which keep everything a drawing is made of: the program CL, the color and the picking id. Every drawing is made inside Display(Bind), where a context is current, under the read side of StripPosesClearLock. A long strip is made a few slices a frame, the displayed ones first, and the engine is asked for the next frame at once until the strip is complete; a snapshot, which is a single frame, makes all of it in that frame.
Constructors
ClStrip(int)
Initializes a new instance of the ClStrip class.
public ClStrip(int cap = 2048)
Parameters
capintThe initial capacity of the strip
Fields
InternalMachiningStepSelected
Host wiring hook invoked when a strip position selects a machining step (low-level; prefer MachiningStepSelected for UI).
public Action<MachiningStep> InternalMachiningStepSelected
Field Value
slice_distance
The distance between slices for efficient rendering.
public const int slice_distance = 8192
Field Value
Properties
AbsDispEnd
Gets the absolute display end position. If the display end is set to -1, returns the total number of positions.
public int AbsDispEnd { get; }
Property Value
CallRefreshDrawing
internal use
public bool CallRefreshDrawing { get; }
Property Value
ChartRange
Synchoronized Chart Time Range. Always not null. The members' value is possible to be null for the un-available status.
public Range<TimeSpan?> ChartRange { get; }
Property Value
IsKeepingDispAlive
Keep the disp range to at least two dots while the stripe length enough.
public bool IsKeepingDispAlive { get; set; }
Property Value
IsShowDot
Gets or sets whether to display dots at each position.
public bool IsShowDot { get; set; }
Property Value
LastRefreshHadUncoveredRecolor
True when the last RefreshDrawingInRendering(bool) re-stamped at least one position whose attachment is not covered by the native color table. Only then do stale colors remain baked in the workpiece display caches, so the whole-tree clean after the re-stamp is still required; covered recolors reach the screen through the table without any clean.
public bool LastRefreshHadUncoveredRecolor { get; }
Property Value
StripPoses
Gets the list of strip positions. Do not add or remove elements directly.
public SynList<ClStripPos> StripPoses { get; }
Property Value
StripPosesClearLock
Gets the lock for thread-safe operations on strip positions.
public ReaderWriterLockSlim StripPosesClearLock { get; }
Property Value
StripPosesCount
Gets the thread-safe count of strip positions.
public int StripPosesCount { get; }
Property Value
StripPosesRetirer
Optional sink for retiring abandoned ClStripPos when the strip is cleared. Injected by the owner (MachiningActRunner) to route through WorkpieceService.RetireAttachments — detach the poses from the live runtime tree under its render barrier, then free them in the background. When null, the poses are freed directly on CubeTree's background chain.
public Action<IReadOnlyList<ClStripPos>> StripPosesRetirer { get; set; }
Property Value
Methods
Add(object, dvec3d_t?)
Adds a new position to the strip.
public ClStripPos Add(object state, dvec3d_t? programCl)
Parameters
stateobjectThe state object associated with the position
programCldvec3d_t?The cutter location; null when the position has none of its own, in which case the new position takes the previous position's CL (NaN for the first)
Returns
- ClStripPos
The newly created strip position
AddRange(IReadOnlyList<(object State, dvec3d_t? ProgramCl)>)
Internal Use Only (the NC play result review). Adds items as positions in one batch, in order:
made and appended under one hold of the read side of StripPosesClearLock, each with the state it is
given (a state that answers a colour colours its position there, as Add(object, dvec3d_t?) does) and a CL that is its
own or, for a null one, the previous position's (NaN for the first of the strip); the strip's box grown by every
CL; then, after the lock, PosAdded raised for each position in order and, when the display end
follows the strip's end (GetDispEnd() is -1), AbsDispEndChanged raised once for the
batch instead of once per position. An empty list adds nothing and raises nothing. A review that rebuilds a strip
of millions of positions from a result file adds them a bin at a time this way, where Add(object, dvec3d_t?) would
raise the range event, and the host's broadcast behind it, once per position.
public int AddRange(IReadOnlyList<(object State, dvec3d_t? ProgramCl)> items)
Parameters
itemsIReadOnlyList<(object State, dvec3d_t? ProgramCl)>The positions' states and CLs, in strip order.
Returns
- int
The index the first position added took, which is the strip's count before the call.
Exceptions
- ArgumentNullException
itemsis null.
Clear(object)
Clears all strip positions and resets the display state.
public void Clear(object sender)
Parameters
senderobjectThe object that initiated this clear operation
Display(Bind)
Displays the strip.
public void Display(Bind bind)
Parameters
bindBindThe binding context for display
Remarks
Called inside a frame (a render thread's, or a snapshot's): a context is current and the share-group generation cannot change until it returns. Drawings of an earlier generation are let go first; then the head and the tail of the display range and the slices still missing are made here (see the class remarks).
Dispose()
Disposes of the resources used by this strip.
public void Dispose()
Dispose(bool)
Disposes of the resources used by this strip.
protected virtual void Dispose(bool disposing)
Parameters
disposingboolWhether this is being called from Dispose
ExpandToBox3d(ref box3d_t)
Expands the given box to include all strip positions.
public void ExpandToBox3d(ref box3d_t dst)
Parameters
dstbox3d_tThe box to expand
GetDispBegin()
Gets the current display begin position.
public int GetDispBegin()
Returns
- int
The display begin position
GetDispEnd()
Gets the current display end position. A value of -1 indicates that the display should follow the end of the strip.
public int GetDispEnd()
Returns
- int
The display end position
GetEnteredPos()
Gets the currently entered position.
public ClStripPos GetEnteredPos()
Returns
- ClStripPos
The entered position
GetFittingView(mat4d_t)
Gets a scaled fitting view based on the strip display range, with the strip zero on the root (identity strip-zero-to-root).
public mat4d_t GetFittingView(mat4d_t sketchView)
Parameters
sketchViewmat4d_tThe sketch view matrix
Returns
- mat4d_t
The scaled fitting view matrix
GetFittingView(mat4d_t, mat4d_t)
Gets a scaled fitting view based on the strip display range.
public mat4d_t GetFittingView(mat4d_t sketchView, mat4d_t clStripZeroToRoot)
Parameters
sketchViewmat4d_tThe sketch view matrix
clStripZeroToRootmat4d_tThe transformation from strip zero to root
Returns
- mat4d_t
The scaled fitting view matrix
GetSelectedPos()
Gets the currently selected position.
public ClStripPos GetSelectedPos()
Returns
- ClStripPos
The selected position
GetStripPos(int, bool)
Gets a strip position by index.
public ClStripPos GetStripPos(int index, bool isLocked = false)
Parameters
Returns
- ClStripPos
The strip position at the specified index
LimitChartRange(bool)
Limits the chart range based on the time range of the strip positions.
public void LimitChartRange(bool isLocked)
Parameters
isLockedboolWhether the strip positions are locked.
RecolorRange(int, int)
Internal Use Only. Re-stamps the colors of the positions of [begin, end) from their
states now (ClStripPos.RefreshColorByState), on the calling thread, under the
strip's read lock: the host's recolor of the few steps whose inspecting slot it refilled
outside a scan (a run of the overload fold closed, InternalStepsRevised).
A position the native picking color table covers reaches the screen by its re-stamp alone; when
a re-stamped position is not covered, the whole strip is flagged (RefreshDrawing())
and the render thread's refresh takes the uncovered path — the drawings dropped and made again,
DrawingRefreshed raised for the host to clean the workpiece's display caches — as
for any recolor. Indices outside the strip are clipped. The lock order is the one
Add(object, dvec3d_t?) takes outside a frame — the strip's read lock, then the native color setter's
picking mutex per position — and, as for Add, its callers never overlap a Clear(object):
the sequencing thread is drained before the reset clears the strip, and the player thread calls
after the runner's WaitAll.
public void RecolorRange(int begin, int end)
Parameters
RefreshDrawing()
Marks the drawing for refresh.
public void RefreshDrawing()
RefreshDrawingInRendering(bool)
internal use
public void RefreshDrawingInRendering(bool isLocked)
Parameters
isLockedbool
SetDispBegin(int, object)
Sets the display begin position.
public void SetDispBegin(int value, object caller)
Parameters
SetDispEnd(int, object)
Sets the display end position. A value of -1 indicates that the display should follow the end of the strip.
public void SetDispEnd(int value, object caller)
Parameters
SetDispSegment(int, int, object)
Sets the display range for the cutter location strip. This method sets both the beginning and ending positions of the display range.
public void SetDispSegment(int beginIndex, int endIndex, object caller)
Parameters
beginIndexintThe beginning index of the display range. Will be clamped to [0, StripPoses.Count - 1].
endIndexintThe ending index of the display range. A value of -1 indicates that the display should follow the end of the strip. Values greater than or equal to StripPoses.Count will be converted to -1. Will be clamped to [-1, StripPoses.Count].
callerobjectThe caller object that requests the display range change. Used for event notifications.
SetEnteredPos(ClStripPos, object)
Sets the currently entered position.
public void SetEnteredPos(ClStripPos value, object sender)
Parameters
valueClStripPosThe new entered position
senderobjectThe object that initiated this change
SetSelectedPos(ClStripPos, object)
Sets the currently selected position.
public void SetSelectedPos(ClStripPos value, object sender)
Parameters
valueClStripPosThe new selected position
senderobjectThe object that initiated this change
ShrinkAttachmentMemory(CancellationToken?)
Shrinks the attachment memory for all positions.
public void ShrinkAttachmentMemory(CancellationToken? cancellationToken = null)
Parameters
cancellationTokenCancellationToken?
StripPosesThreadSafeSelect<T>(Func<ClStripPos, T>)
Thread-safe selection of strip positions.
public List<T> StripPosesThreadSafeSelect<T>(Func<ClStripPos, T> func)
Parameters
funcFunc<ClStripPos, T>The function to transform each strip position
Returns
- List<T>
A list of transformed strip positions
Type Parameters
TThe type of the selected data
UpdateDispSegmentByChartRange(object)
Updates the display segment based on the current chart range.
public void UpdateDispSegmentByChartRange(object caller)
Parameters
callerobjectThe caller object that triggered the update.
Events
AbsDispEndChanged
Event raised when the absolute display end position changes.
public event EventHandler AbsDispEndChanged
Event Type
Cleared
Event raised after Clear(object) has emptied StripPoses, so list-style consumers (e.g. a step table) can reset without polling.
public event Action Cleared
Event Type
DispBeginChanged
Event raised when the display begin position changes.
public event EventHandler DispBeginChanged
Event Type
DispEndChanged
Event raised when the display end position changes.
public event EventHandler DispEndChanged
Event Type
DrawingRefreshed
Event raised after RefreshDrawingInRendering(bool) re-stamped the pos colors from their states. When the re-stamp hit a position the native color table does not cover (LastRefreshHadUncoveredRecolor), the strip's drawings, which bake that color, were let go with it and are being made again from the new colors over the next frames. Subscribers that cache colors baked from the strip attachments (e.g. a meshed workpiece's display cache) should invalidate on this event.
public event EventHandler DrawingRefreshed
Event Type
MachiningStepSelected
The same effecting position as PosSelected but with more convenient arguments for the end-user.
public event Action<MachiningStep> MachiningStepSelected
Event Type
PosAdded
Event raised when a new position is added to the strip.
public event Action<ClStripPos> PosAdded
Event Type
PosClicked
Raised when a position is clicked on a canvas: the left button pressed and released on the same position, with the release at most four panel pixels from the press on each axis (the strip's slack). Only the left button counts, and the host passes HiMouseButton (JavaScript) button codes to its DispEngine. The sender is the DispEngine the click happened on, so a host with one strip shown on several canvases can answer only the canvas that was clicked. The position is already selected when this is raised (SetSelectedPos(ClStripPos, object) ran first), and it is raised on every click, including a click on the position that is already selected, for which PosSelected says nothing. A selection made from code (SetSelectedPos(ClStripPos, object)) never raises it.
public event EventHandler<ClStripPos> PosClicked
Event Type
Remarks
Raised on the engine's render thread, inside the pick dispatch, with the
native picking_id_mtx held: a handler must return at once (hand any
work to another thread) and must never throw. Pickable.Dispatch is an
[UnmanagedCallersOnly] entry with no catch, so an exception that
escapes a handler ends the process. A handler must not block on another
thread, nor create or dispose a Pickable, nor read a
PickingID: the mutex is not reentrant.
PosEntered
Event raised when the mouse enters a position.
public event EventHandler<ClStripPos> PosEntered
Event Type
PosSelected
Event raised when a position is selected. The sender is the object that called SetSelectedPos(ClStripPos, object); for a click on a canvas it is this strip, and the canvas the click came from is only known to PosClicked.
public event EventHandler<ClStripPos> PosSelected
Event Type
StaticPosSelected
Static event raised when any position is selected.
public static event EventHandler<ClStripPos> StaticPosSelected