123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using AI.Common.Interface;
- namespace AILesionDescriptionGTGenerator
- {
- public enum EnumLesionInfoEventType
- {
- DrawContour,
- DrawHorizontal,
- DrawVertical,
- LesionInfoUpdated,
- DrawPoint,
- }
- public class LesionInfoEventArgs : EventArgs
- {
- public EnumLesionInfoEventType EventType { get; }
- public LesionInfoEventArgs(EnumLesionInfoEventType eventType)
- {
- EventType = eventType;
- }
- }
- /// <summary>
- /// LesionInfoSelector.xaml 的交互逻辑
- /// </summary>
- public partial class LesionInfoSelector : UserControl
- {
- #region private variables
- private volatile LesionInfo _lesion;
- #endregion
- #region event
- public event EventHandler<LesionInfoEventArgs> NotifyLesionInfoEventArgs;
- #endregion
- #region 界面响应
- /// <summary>
- /// 形状描述 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnShapeSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ComboBoxShape.SelectedIndex != -1)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.Shape = (EnumDesShapeValue)ComboBoxShape.SelectedIndex;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- }
- }
- /// <summary>
- /// 生长方向 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnOrientationSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ComboBoxOrientation.SelectedIndex != -1)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.Orientation = (EnumDesOrientationValue)ComboBoxOrientation.SelectedIndex;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- }
- }
- /// <summary>
- /// 回声类型修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnEchoPatternSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ComboBoxEchoPattern.SelectedIndex != -1)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.EchoPattern = (EnumDesEchoPatternValue)ComboBoxEchoPattern.SelectedIndex;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- }
- }
- /// <summary>
- /// 边界 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnBoundarySelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ComboBoxBoundary.SelectedIndex != -1)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.Boundary = (EnumDesLesionBoundaryValue)ComboBoxBoundary.SelectedIndex;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- }
- }
- /// <summary>
- /// 边缘 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnMarginSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ComboBoxMargin.SelectedIndex != -1)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.Margin = (EnumDesMarginValue)ComboBoxMargin.SelectedIndex;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- }
- }
-
- /// <summary>
- /// 画轮廓
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnBtnDrawContourClicked(object sender, RoutedEventArgs e)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- LesionInfoUpdated();
- }
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.DrawPoint/*DrawContour*/));
- }
- /// <summary>
- /// 画横径
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnBtnDrawHorizontalClicked(object sender, RoutedEventArgs e)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- LesionInfoUpdated();
- }
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.DrawHorizontal));
- }
- /// <summary>
- /// 画纵径
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnBtnDrawVerticalClicked(object sender, RoutedEventArgs e)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- LesionInfoUpdated();
- }
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.DrawVertical));
- }
- #endregion
- #region public
- public LesionInfoSelector()
- {
- InitializeComponent();
- InitializeComboBox();
- _lesion = null;
- LesionInfoUpdated();
- }
- public void SetLesionEmpty()
- {
- _lesion = null;
- LesionInfoUpdated();
- }
- public void SetLesion(LesionInfo lesion)
- {
- _lesion = lesion;
- LesionInfoUpdated();
- }
- public void SetContour(List<Point2D> contour)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.Contour = contour;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- ContourUpdated();
- }
- public void SetHorizontalAxis(Point2D horizontalP1, Point2D horizontalP2)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.HorizontalPoint1 = horizontalP1;
- _lesion.HorizontalPoint2 = horizontalP2;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- HorizontalAxisUpdated();
- }
- public void SetVerticalAxis(Point2D verticalP1, Point2D verticalP2)
- {
- if (_lesion == null)
- {
- _lesion = new LesionInfo();
- LesionInfoUpdated();
- }
- _lesion.VerticalPoint1 = verticalP1;
- _lesion.VerticalPoint2 = verticalP2;
- NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
- VerticalAxisUpdated();
- }
- #endregion
- #region private
- /// <summary>
- /// 初始化下拉列表框
- /// </summary>
- private void InitializeComboBox()
- {
- // 形状
- ComboBoxShape.Items.Add("椭圆形");
- ComboBoxShape.Items.Add("类圆形");
- ComboBoxShape.Items.Add("不规则形");
- // 生长方向
- ComboBoxOrientation.Items.Add("平行");
- ComboBoxOrientation.Items.Add("非平行");
- // 回声类型
- ComboBoxEchoPattern.Items.Add("无回声");
- ComboBoxEchoPattern.Items.Add("低回声");
- ComboBoxEchoPattern.Items.Add("等回声");
- ComboBoxEchoPattern.Items.Add("高回声");
- ComboBoxEchoPattern.Items.Add("混合回声");
- // 边界
- ComboBoxBoundary.Items.Add("清晰");
- ComboBoxBoundary.Items.Add("模糊");
- // 边缘
- ComboBoxMargin.Items.Add("光整");
- ComboBoxMargin.Items.Add("不光整");
- }
- /// <summary>
- /// 病灶信息更新
- /// </summary>
- private void LesionInfoUpdated()
- {
- ContourUpdated();
- HorizontalAxisUpdated();
- VerticalAxisUpdated();
- ComboBoxShape.SelectionChanged -= OnShapeSelectionChanged;
- ComboBoxOrientation.SelectionChanged -= OnOrientationSelectionChanged;
- ComboBoxEchoPattern.SelectionChanged -= OnEchoPatternSelectionChanged;
- ComboBoxBoundary.SelectionChanged -= OnBoundarySelectionChanged;
- ComboBoxMargin.SelectionChanged -= OnMarginSelectionChanged;
- if (_lesion != null)
- {
- ComboBoxShape.SelectedIndex = (int)_lesion.Shape;
- ComboBoxOrientation.SelectedIndex = (int)_lesion.Orientation;
- ComboBoxEchoPattern.SelectedIndex = (int)_lesion.EchoPattern;
- ComboBoxBoundary.SelectedIndex = (int)_lesion.Boundary;
- ComboBoxMargin.SelectedIndex = (int)_lesion.Margin;
- }
- else
- {
- ComboBoxShape.SelectedIndex = -1;
- ComboBoxOrientation.SelectedIndex = -1;
- ComboBoxEchoPattern.SelectedIndex = -1;
- ComboBoxBoundary.SelectedIndex = -1;
- ComboBoxMargin.SelectedIndex = -1;
- }
- ComboBoxShape.SelectionChanged += OnShapeSelectionChanged;
- ComboBoxOrientation.SelectionChanged += OnOrientationSelectionChanged;
- ComboBoxEchoPattern.SelectionChanged += OnEchoPatternSelectionChanged;
- ComboBoxBoundary.SelectionChanged += OnBoundarySelectionChanged;
- ComboBoxMargin.SelectionChanged += OnMarginSelectionChanged;
- }
- /// <summary>
- /// 轮廓更新
- /// </summary>
- private void ContourUpdated()
- {
- string strContour = "";
- if (_lesion != null)
- {
- foreach (var point in _lesion.Contour)
- {
- strContour += "{" + point.X + "," + point.Y + "}";
- }
- }
- TextBlockContours.Text = strContour;
- }
- /// <summary>
- /// 横径更新
- /// </summary>
- private void HorizontalAxisUpdated()
- {
- string strHorizon = "";
- if (_lesion != null)
- {
- if (_lesion.HorizontalPoint1 != null && _lesion.HorizontalPoint2 != null)
- {
- strHorizon = "{" + _lesion.HorizontalPoint1.X + "," + _lesion.HorizontalPoint1.Y + "}," +
- "{" + _lesion.HorizontalPoint2.X + "," + _lesion.HorizontalPoint2.Y + "}";
- }
- }
- TextBlockHorizontal.Text = strHorizon;
- }
- /// <summary>
- /// 纵径更新
- /// </summary>
- private void VerticalAxisUpdated()
- {
- string strVertical = "";
- if (_lesion != null)
- {
- if (_lesion.VerticalPoint1 != null && _lesion.VerticalPoint2 != null)
- {
- strVertical = "{" + _lesion.VerticalPoint1.X + "," + _lesion.VerticalPoint1.Y + "}," +
- "{" + _lesion.VerticalPoint2.X + "," + _lesion.VerticalPoint2.Y + "}";
- }
- }
- TextBlockVertical.Text = strVertical;
- }
- #endregion
- #region properties
- /// <summary>
- /// 是否为空
- /// </summary>
- public bool IsEmpty => _lesion == null;
- /// <summary>
- /// 病灶
- /// </summary>
- public LesionInfo Lesion => _lesion;
- #endregion
- }
- }
|