refactor(demos): Hi.Sample.Wpf owns Disp/ displayee copies decoupled from HiNc/HiUniNc

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 08:58:03 +08:00
co-authored by Claude Fable 5
parent 3c4f552d5a
commit e7880d7c06
5 changed files with 450 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
using Hi.Disp;
using Hi.Disp.Flag;
using Hi.Geom;
using Hi.Machining.MachiningEquipmentUtils;
using Hi.Mech.Topo;
using Hi.Numerical;
using System;
namespace Sample.Disp;
/// <summary>
/// Displayee for ISO coordinate entry visualization.
/// </summary>
public class IsoCoordinateEntryDisplayee : IAnchoredDisplayee
{
/// <summary>
/// Gets or sets the ISO coordinate key (e.g. "G54", "G59.2").
/// </summary>
public string IsoCoordinateId { get; set; } = "G54";
/// <summary>
/// Gets or sets the function that provides the NcEnv instance.
/// </summary>
public Func<HardNcEnv> NcEnvFunc { get; set; }
/// <summary>
/// Gets or sets the function that provides the machining equipment.
/// </summary>
public Func<IMachiningEquipment> MillingEquipmentFunc { get; set; }
HardNcEnv NcEnv => NcEnvFunc?.Invoke();
/// <summary>
/// Initializes a new instance of the <see cref="IsoCoordinateEntryDisplayee"/> class.
/// </summary>
/// <param name="ncEnvFunc">The function that provides the NcEnv instance.</param>
/// <param name="millingEquipmentSource">The function that provides the machining equipment.</param>
public IsoCoordinateEntryDisplayee(Func<HardNcEnv> ncEnvFunc,
Func<IMachiningEquipment> millingEquipmentSource)
{
NcEnvFunc = ncEnvFunc;
MillingEquipmentFunc = millingEquipmentSource;
}
/// <inheritdoc/>
public void Display(Bind bind)
{
HardNcEnv ncEnv = NcEnv;
if (ncEnv == null)
return;
Vec3d coordinateMove;
string text;
if (ncEnv.IsoCoordinateTable?.TryGetValue(
IsoCoordinateId, out coordinateMove) != true
|| coordinateMove == null)
return;
if (coordinateMove == null)
return;
text = IsoCoordinateId ?? "";
Vec3d attacherPos = MillingEquipmentFunc?.Invoke()
?.GetIsoCoordinatePosition(coordinateMove);
bind.ModelMatStack.Push();
bind.ModelMatStack.Trans(attacherPos);
CoordinateDrawing.Display(bind, text);
bind.ModelMatStack.Pop();
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
HardNcEnv ncEnv = NcEnv;
if (ncEnv == null)
return;
Vec3d coordinateMove;
if (ncEnv.IsoCoordinateTable?.TryGetValue(IsoCoordinateId, out coordinateMove) != true
|| coordinateMove == null)
return;
Vec3d attacherPos = MillingEquipmentFunc?.Invoke()
?.GetIsoCoordinatePosition(coordinateMove);
if (attacherPos == null)
return;
dst.Expand(attacherPos);
}
/// <inheritdoc/>
/// <returns>Table Buckle if existed; otherwise, return null.</returns>
public Anchor GetAnchor()
{
return MillingEquipmentFunc?.Invoke()?.GetMachiningChain()?.GetAnchor();
}
}