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;
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();
}
///
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);
}
///
/// Table Buckle if existed; otherwise, return null.
public Anchor GetAnchor()
{
return MillingEquipmentFunc?.Invoke()?.GetMachiningChain()?.GetAnchor();
}
}