Render Topology
Read Kinematic Topology Rendering for the prerequisite.
A Asmb is a group to render its descendent Anchors.
Several ways to render with the topology:
- Render by Anchoring Matrix Map
- Render by Anchored Displayee
Render by Anchoring Matrix Map
Render by Anchored Displayee
Inherit IAnchoredDisplayee or apply AnchoredDisplayee to Asmb.Display().
Inherit ITopoDisplayee to manage the object with Asmb and plural anchors .
The base logic is also by the anchoring matrix. Here is some class and function wrapping the logic.
The sample code shows the topology rendering for a MillingTool editing helper:
using Hi.Common;
using Hi.Common.Messages;
using Hi.Disp;
using Hi.Disp.Flag;
using Hi.Geom;
using Hi.Mech.Topo;
using Hi.Milling.Cutters;
using Hi.NcMech.Holders;
using System;
using System.Collections.Generic;
namespace Hi.Milling.MillingTools;
/// <summary>
/// Display host for a milling tool composed of a cutter and a holder.
/// </summary>
/// <remarks>
/// The GL drawings of the cutter shown here belong to this displayee, through
/// <see cref="MillingCutterEditorDisplayee"/>, and not to the tool; the holder's
/// displayee holds none (the holder's solid is the holder's). Whoever shows it on
/// a canvas disposes it once that canvas is gone, never while a frame may still be
/// displaying it: displayed again, the cutter's displayee makes its drawings anew.
/// </remarks>
public class MillingToolEditorDisplayee : ITopoDisplayee, IClearCache, IDisposable
{
/// <summary>
/// Gets or sets the delegate that provides the <see cref="MillingTool"/> instance.
/// </summary>
public Func<MillingTool> MillingToolGetter { get; set; }
/// <summary>
/// Gets the current <see cref="MillingTool"/> instance.
/// </summary>
public MillingTool MillingTool => MillingToolGetter?.Invoke();
/// <summary>
/// Gets or sets whether to show the cutter.
/// </summary>
public bool ShowCutter { get; set; } = true;
/// <summary>
/// Gets or sets whether to show the holder.
/// </summary>
public bool ShowHolder { get; set; } = true;
/// <summary>
/// Gets the displayee for the milling cutter.
/// </summary>
public MillingCutterEditorDisplayee MillingCutterEditorDisplayee { get; }
= new MillingCutterEditorDisplayee();
/// <summary>
/// Gets the displayee for the holder.
/// </summary>
public HolderEditorDisplayee HolderEditorDisplayee { get; }
= new HolderEditorDisplayee();
/// <inheritdoc/>
public List<IAnchoredDisplayee> GetAnchoredDisplayeeList()
{
var dst = new List<IAnchoredDisplayee>();
//disposed: nothing is listed, so the cutter's displayee is never asked to
//make its drawings again for a canvas that is gone
if (disposedValue)
return dst;
var millingTool = MillingTool;
if (millingTool == null)
return dst;
if (ShowCutter)
{
var cutter = millingTool.Cutter;
if (cutter is MillingCutter millingCutter)
{
//MessageKit.AddMessage($"MillingTool.Cutter: {MillingTool?.Cutter?.GetHashCode()}");
MillingCutterEditorDisplayee.MillingCutterSourceFunc
= () => MillingTool?.Cutter as MillingCutter;
dst.Add(MillingCutterEditorDisplayee);
}
else if(cutter!=null)
dst.Add(cutter);
}
if (ShowHolder)
{
HolderEditorDisplayee.Holder = millingTool.Holder;
dst.Add(HolderEditorDisplayee);
}
return dst;
}
/// <inheritdoc/>
public void Display(Bind bind)
{
if (disposedValue)
return;
bind.PushCoveringPixelMode();
DimensionBar.Display(bind, "mm");
bind.ModelMatStack.Pop();
TopoDisplayeeUtil.Display(this, bind);
}
/// <inheritdoc/>
public void ExpandToBox3d(ref box3d_t dst)
{
TopoDisplayeeUtil.ExpandToBox3d(this, ref dst);
}
/// <inheritdoc/>
public Asmb GetAsmb() => MillingTool?.Asmb;
/// <inheritdoc/>
public Anchor GetAnchor() => MillingTool?.GetAnchor();
/// <inheritdoc/>
public void ClearCache()
{
MillingCutterEditorDisplayee?.ClearCache();
}
private bool disposedValue;
/// <summary>
/// Disposes of <see cref="MillingCutterEditorDisplayee"/>, which holds the drawings
/// of the cutter shown here. A second call does nothing.
/// </summary>
/// <param name="disposing">True if disposing, false if finalizing</param>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
MillingCutterEditorDisplayee?.Dispose();
disposedValue = true;
}
}
/// <summary>
/// Disposes of the drawings this displayee holds (see the class remarks); a second
/// call does nothing.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
See Also
- Kinematic Topology — the assembly and anchors this renders through