using Hi.Disp.Flag; using Hi.Disp; using Hi.Machining.MachiningEquipmentUtils; using Hi.Mech.Topo; using Hi.Numerical; using Hi.Numerical.NcArgs; using System.Collections; using System; using Hi.Geom; using System.Linq; namespace Sample.Disp { /// /// Displayee for Heidenhain coordinate entry visualization. /// public class HeidenhainCoordinateEntryDisplayee : IAnchoredDisplayee { /// /// Gets or sets whether to show Heidenhain datum preset information. /// public bool ShowHeidenhainDatumPreset { get; set; } = true; /// /// Gets or sets whether to show Heidenhain datum shift information. /// public bool ShowHeidenhainDatumShift { get; set; } = true; /// /// 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(); /// /// Gets or sets the Heidenhain Cycle Def 247 Q339 value. /// public int HeidenhainCycleDef247Q339 { get; set; } /// /// Gets or sets the Heidenhain Cycle Def 7 arguments. /// public HeidenhainCycleDef7Arg HeidenhainCycleDef7Arg { get; set; } /// /// Initializes a new instance. /// /// The function that provides the NcEnv instance. /// The function that provides the machining equipment. public HeidenhainCoordinateEntryDisplayee(Func ncEnvFunc, Func millingEquipmentSource) { NcEnvFunc = ncEnvFunc; MillingEquipmentFunc = millingEquipmentSource; } /// public void Display(Bind bind) { HardNcEnv ncEnv = NcEnv; if (ncEnv == null || NcEnv.CncBrand != CncBrand.Heidenhain) return; ////Console.WriteLine($"B: {CoordinateIndex}; {coordinateMove}"); Vec3d mcXyz_AttacherAtTableBuckleZero = MillingEquipmentFunc?.Invoke() ?.GetMachinePositionAtTableBuckleZero(); if (mcXyz_AttacherAtTableBuckleZero == null) return; Vec3d coordinateMove; string text; if (HeidenhainCycleDef247Q339 == 0 && HeidenhainCycleDef7Arg == null) return; coordinateMove = NcFlagUtil.GetHeidenhainCoordinateOffset( HeidenhainCycleDef247Q339, HeidenhainCycleDef7Arg, ncEnv); //Console.WriteLine($"HeidenhainCycleDef7Arg: {HeidenhainCycleDef7Arg==null}"); string datumPresetText = null; if (HeidenhainCycleDef247Q339 != 0 && ShowHeidenhainDatumPreset) datumPresetText = $"Datum Preset Q339={HeidenhainCycleDef247Q339}"; string datumShiftText = null; if (HeidenhainCycleDef7Arg != null && ShowHeidenhainDatumShift) datumShiftText = $"Datum Shift: {HeidenhainCycleDef7Arg?.ToString() ?? "None"}"; text = string.Join(", ", (new string[] { datumPresetText, datumShiftText }). Where(v => v != null)); //text = $"Datum Preset Q339={HeidenhainCycleDef247Q339}, Datum Shift: #1"; //Console.WriteLine($"text: [{text}]"); bind.ModelMatStack.Push(); bind.ModelMatStack.Trans(coordinateMove - mcXyz_AttacherAtTableBuckleZero); CoordinateDrawing.Display(bind, text); bind.ModelMatStack.Pop(); } /// public void ExpandToBox3d(Box3d dst) { HardNcEnv ncEnv = NcEnv; if (ncEnv == null || NcEnv.CncBrand != CncBrand.Heidenhain) return; Vec3d mcXyz_AttacherAtTableBuckleZero = MillingEquipmentFunc?.Invoke() ?.GetMachinePositionAtTableBuckleZero(); if (mcXyz_AttacherAtTableBuckleZero == null) return; Vec3d coordinateMove; if (HeidenhainCycleDef247Q339 == 0 && HeidenhainCycleDef7Arg == null) return; coordinateMove = NcFlagUtil.GetHeidenhainCoordinateOffset( HeidenhainCycleDef247Q339, HeidenhainCycleDef7Arg, ncEnv); dst.Expand(-mcXyz_AttacherAtTableBuckleZero + coordinateMove); } /// public Anchor GetAnchor() { return MillingEquipmentFunc?.Invoke()?.GetMachiningChain() ?.GetTableBuckle()?.GetAnchor(); } } }