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;
}
}
///
/// LesionInfoSelector.xaml 的交互逻辑
///
public partial class LesionInfoSelector : UserControl
{
#region private variables
private volatile LesionInfo _lesion;
#endregion
#region event
public event EventHandler NotifyLesionInfoEventArgs;
#endregion
#region 界面响应
///
/// 形状描述 修改
///
///
///
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));
}
}
///
/// 生长方向 修改
///
///
///
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));
}
}
///
/// 回声类型修改
///
///
///
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));
}
}
///
/// 边界 修改
///
///
///
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));
}
}
///
/// 边缘 修改
///
///
///
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));
}
}
///
/// 画轮廓
///
///
///
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*/));
}
///
/// 画横径
///
///
///
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));
}
///
/// 画纵径
///
///
///
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 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
///
/// 初始化下拉列表框
///
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("不光整");
}
///
/// 病灶信息更新
///
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;
}
///
/// 轮廓更新
///
private void ContourUpdated()
{
string strContour = "";
if (_lesion != null)
{
foreach (var point in _lesion.Contour)
{
strContour += "{" + point.X + "," + point.Y + "}";
}
}
TextBlockContours.Text = strContour;
}
///
/// 横径更新
///
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;
}
///
/// 纵径更新
///
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
///
/// 是否为空
///
public bool IsEmpty => _lesion == null;
///
/// 病灶
///
public LesionInfo Lesion => _lesion;
#endregion
}
}