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>
public class MillingToolEditorDisplayee : ITopoDisplayee, IClearCache
{
/// <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>();
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)
{
bind.PushCoveringPixelMode();
DimensionBar.Display(bind, "mm");
bind.ModelMatStack.Pop();
TopoDisplayeeUtil.Display(this, bind);
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
TopoDisplayeeUtil.ExpandToBox3d(this, dst);
}
/// <inheritdoc/>
public Asmb GetAsmb() => MillingTool?.Asmb;
/// <inheritdoc/>
public Anchor GetAnchor() => MillingTool?.GetAnchor();
/// <inheritdoc/>
public void ClearCache()
{
MillingCutterEditorDisplayee?.ClearCache();
}
}
}