91 lines
2.5 KiB
C#
91 lines
2.5 KiB
C#
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();
|
|
}
|
|
}
|