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;
///
/// Displayee for ISO coordinate entry visualization.
///
public class IsoCoordinateEntryDisplayee : IAnchoredDisplayee
{
///
/// Gets or sets the ISO coordinate key (e.g. "G54", "G59.2").
///
public string IsoCoordinateId { get; set; } = "G54";
///
/// Gets or sets the function that provides the NcEnv instance.
///
public Func NcEnvFunc { get; set; }
///
/// Gets or sets the function that provides the machining equipment.
///
public Func MillingEquipmentFunc { get; set; }
HardNcEnv NcEnv => NcEnvFunc?.Invoke();
///
/// Initializes a new instance of the class.
///
/// The function that provides the NcEnv instance.
/// The function that provides the machining equipment.
public IsoCoordinateEntryDisplayee(Func ncEnvFunc,
Func millingEquipmentSource)
{
NcEnvFunc = ncEnvFunc;
MillingEquipmentFunc = millingEquipmentSource;
}
///
public void Display(Bind bind)
{
HardNcEnv ncEnv = NcEnv;
if (ncEnv == null)
return;
if (ncEnv.IsoCoordinateTable?.TryGetValue(IsoCoordinateId, out vec3d_t coordinateMove) != true)
return;
string text = IsoCoordinateId ?? "";
IMachiningEquipment equipment = MillingEquipmentFunc?.Invoke();
if (equipment == null || !equipment.TryGetIsoCoordinatePosition(coordinateMove, out vec3d_t attacherPos))
return;
bind.ModelMatStack.Push();
bind.ModelMatStack.Trans(attacherPos);
CoordinateDrawing.Display(bind, text);
bind.ModelMatStack.Pop();
}
///
public void ExpandToBox3d(Box3d dst)
{
HardNcEnv ncEnv = NcEnv;
if (ncEnv == null)
return;
if (ncEnv.IsoCoordinateTable?.TryGetValue(IsoCoordinateId, out vec3d_t coordinateMove) != true)
return;
IMachiningEquipment equipment = MillingEquipmentFunc?.Invoke();
if (equipment == null || !equipment.TryGetIsoCoordinatePosition(coordinateMove, out vec3d_t attacherPos))
return;
dst.Expand(attacherPos);
}
///
/// Table Mount if existed; otherwise, return null.
public Anchor GetAnchor()
{
return MillingEquipmentFunc?.Invoke()?.GetMachiningChain()?.GetAnchor();
}
}