using Matrox.MatroxImagingLibrary; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace MilUI { public class MilGraphics { private MIL_ID _diplayId = MIL.M_NULL; private MIL_ID _graphicListId = MIL.M_NULL; private List _graphicLabels = new List(); public MilGraphics(MIL_ID diplayId, MIL_ID graphicListId) { _diplayId = diplayId; _graphicListId = graphicListId; } public void Add() { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { _graphicLabels.Add(graphicLabel); } } public void Clear() { MIL.MdispControl(_diplayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE); for (int i = 0; i < _graphicLabels.Count; i++) { RemoveGraphic(_graphicLabels[i]); } _graphicLabels.Clear(); MIL.MdispControl(_diplayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE); } public void Clear(List gl) { MIL.MdispControl(_diplayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE); for (int i = 0; i < gl.Count; i++) { RemoveGraphic(gl[i]); } _graphicLabels.Clear(); MIL.MdispControl(_diplayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE); } public void Remove(MIL_INT graphicLabel) { RemoveGraphic(graphicLabel); } private void RemoveGraphic(MIL_INT graphicLabel) { if (graphicLabel != MIL.M_NULL) { MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_DELETE, MIL.M_DEFAULT); } } public void SetSelectable(bool enable) { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { MIL_INT milEnable = enable ? MIL.M_ENABLE : MIL.M_DISABLE; MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_SELECTABLE, milEnable); } } public void SetResizable(bool enable) { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { MIL_INT milEnable = enable ? MIL.M_ENABLE : MIL.M_DISABLE; MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_RESIZABLE, milEnable); } } public void SetRotatable(bool enable) { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { MIL_INT milEnable = enable ? MIL.M_ENABLE : MIL.M_DISABLE; MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_ROTATABLE, milEnable); } } public void SetTranslatable(bool enable) { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { MIL_INT milEnable = enable ? MIL.M_ENABLE : MIL.M_DISABLE; MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_TRANSLATABLE, milEnable); } } public void SetFixedAspectRatio(double ratio) { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_CONSTRAIN_ASPECT_RATIO, ratio); } } public void SetSpecificFeature(bool enable) { MIL_ID graphicLabel = GetLastLabel(); if (graphicLabel != MIL.M_NO_LABEL) { MIL_INT milEnable = enable ? MIL.M_ENABLE : MIL.M_DISABLE; MIL.MgraControlList( _graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_SPECIFIC_FEATURES_EDITABLE, milEnable); } } public MIL_ID GetLastLabel() { MIL_ID graphicLabel = MIL.M_NULL; MIL.MgraInquireList(_graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref graphicLabel); return graphicLabel; } public bool HasGraphicLabel(MIL_INT graphicLabel) { foreach (var gl in _graphicLabels) { if (gl == graphicLabel) { return true; } } return false; } public int GetLocalIndex(MIL_INT graphicLabel) { for (int i = 0; i < _graphicLabels.Count; i++) { if (_graphicLabels[i] == graphicLabel) { return i; } } return -1; } public MilGraphics Clone() { var milGraphics = new MilGraphics(_diplayId, _graphicListId); foreach (var label in _graphicLabels) { milGraphics._graphicLabels.Add(label); } return milGraphics; } } }