LesionInfoSelector.xaml.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using AI.Common.Interface;
  16. namespace AILesionDescriptionGTGenerator
  17. {
  18. public enum EnumLesionInfoEventType
  19. {
  20. DrawContour,
  21. DrawHorizontal,
  22. DrawVertical,
  23. LesionInfoUpdated,
  24. DrawPoint,
  25. }
  26. public class LesionInfoEventArgs : EventArgs
  27. {
  28. public EnumLesionInfoEventType EventType { get; }
  29. public LesionInfoEventArgs(EnumLesionInfoEventType eventType)
  30. {
  31. EventType = eventType;
  32. }
  33. }
  34. /// <summary>
  35. /// LesionInfoSelector.xaml 的交互逻辑
  36. /// </summary>
  37. public partial class LesionInfoSelector : UserControl
  38. {
  39. #region private variables
  40. private volatile LesionInfo _lesion;
  41. #endregion
  42. #region event
  43. public event EventHandler<LesionInfoEventArgs> NotifyLesionInfoEventArgs;
  44. #endregion
  45. #region 界面响应
  46. /// <summary>
  47. /// 形状描述 修改
  48. /// </summary>
  49. /// <param name="sender"></param>
  50. /// <param name="e"></param>
  51. private void OnShapeSelectionChanged(object sender, SelectionChangedEventArgs e)
  52. {
  53. if (ComboBoxShape.SelectedIndex != -1)
  54. {
  55. if (_lesion == null)
  56. {
  57. _lesion = new LesionInfo();
  58. LesionInfoUpdated();
  59. }
  60. _lesion.Shape = (EnumDesShapeValue)ComboBoxShape.SelectedIndex;
  61. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  62. }
  63. }
  64. /// <summary>
  65. /// 生长方向 修改
  66. /// </summary>
  67. /// <param name="sender"></param>
  68. /// <param name="e"></param>
  69. private void OnOrientationSelectionChanged(object sender, SelectionChangedEventArgs e)
  70. {
  71. if (ComboBoxOrientation.SelectedIndex != -1)
  72. {
  73. if (_lesion == null)
  74. {
  75. _lesion = new LesionInfo();
  76. LesionInfoUpdated();
  77. }
  78. _lesion.Orientation = (EnumDesOrientationValue)ComboBoxOrientation.SelectedIndex;
  79. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  80. }
  81. }
  82. /// <summary>
  83. /// 回声类型修改
  84. /// </summary>
  85. /// <param name="sender"></param>
  86. /// <param name="e"></param>
  87. private void OnEchoPatternSelectionChanged(object sender, SelectionChangedEventArgs e)
  88. {
  89. if (ComboBoxEchoPattern.SelectedIndex != -1)
  90. {
  91. if (_lesion == null)
  92. {
  93. _lesion = new LesionInfo();
  94. LesionInfoUpdated();
  95. }
  96. _lesion.EchoPattern = (EnumDesEchoPatternValue)ComboBoxEchoPattern.SelectedIndex;
  97. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  98. }
  99. }
  100. /// <summary>
  101. /// 边界 修改
  102. /// </summary>
  103. /// <param name="sender"></param>
  104. /// <param name="e"></param>
  105. private void OnBoundarySelectionChanged(object sender, SelectionChangedEventArgs e)
  106. {
  107. if (ComboBoxBoundary.SelectedIndex != -1)
  108. {
  109. if (_lesion == null)
  110. {
  111. _lesion = new LesionInfo();
  112. LesionInfoUpdated();
  113. }
  114. _lesion.Boundary = (EnumDesLesionBoundaryValue)ComboBoxBoundary.SelectedIndex;
  115. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  116. }
  117. }
  118. /// <summary>
  119. /// 边缘 修改
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. private void OnMarginSelectionChanged(object sender, SelectionChangedEventArgs e)
  124. {
  125. if (ComboBoxMargin.SelectedIndex != -1)
  126. {
  127. if (_lesion == null)
  128. {
  129. _lesion = new LesionInfo();
  130. LesionInfoUpdated();
  131. }
  132. _lesion.Margin = (EnumDesMarginValue)ComboBoxMargin.SelectedIndex;
  133. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  134. }
  135. }
  136. /// <summary>
  137. /// 画轮廓
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void OnBtnDrawContourClicked(object sender, RoutedEventArgs e)
  142. {
  143. if (_lesion == null)
  144. {
  145. _lesion = new LesionInfo();
  146. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  147. LesionInfoUpdated();
  148. }
  149. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.DrawPoint/*DrawContour*/));
  150. }
  151. /// <summary>
  152. /// 画横径
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. /// <param name="e"></param>
  156. private void OnBtnDrawHorizontalClicked(object sender, RoutedEventArgs e)
  157. {
  158. if (_lesion == null)
  159. {
  160. _lesion = new LesionInfo();
  161. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  162. LesionInfoUpdated();
  163. }
  164. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.DrawHorizontal));
  165. }
  166. /// <summary>
  167. /// 画纵径
  168. /// </summary>
  169. /// <param name="sender"></param>
  170. /// <param name="e"></param>
  171. private void OnBtnDrawVerticalClicked(object sender, RoutedEventArgs e)
  172. {
  173. if (_lesion == null)
  174. {
  175. _lesion = new LesionInfo();
  176. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  177. LesionInfoUpdated();
  178. }
  179. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.DrawVertical));
  180. }
  181. #endregion
  182. #region public
  183. public LesionInfoSelector()
  184. {
  185. InitializeComponent();
  186. InitializeComboBox();
  187. _lesion = null;
  188. LesionInfoUpdated();
  189. }
  190. public void SetLesionEmpty()
  191. {
  192. _lesion = null;
  193. LesionInfoUpdated();
  194. }
  195. public void SetLesion(LesionInfo lesion)
  196. {
  197. _lesion = lesion;
  198. LesionInfoUpdated();
  199. }
  200. public void SetContour(List<Point2D> contour)
  201. {
  202. if (_lesion == null)
  203. {
  204. _lesion = new LesionInfo();
  205. LesionInfoUpdated();
  206. }
  207. _lesion.Contour = contour;
  208. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  209. ContourUpdated();
  210. }
  211. public void SetHorizontalAxis(Point2D horizontalP1, Point2D horizontalP2)
  212. {
  213. if (_lesion == null)
  214. {
  215. _lesion = new LesionInfo();
  216. LesionInfoUpdated();
  217. }
  218. _lesion.HorizontalPoint1 = horizontalP1;
  219. _lesion.HorizontalPoint2 = horizontalP2;
  220. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  221. HorizontalAxisUpdated();
  222. }
  223. public void SetVerticalAxis(Point2D verticalP1, Point2D verticalP2)
  224. {
  225. if (_lesion == null)
  226. {
  227. _lesion = new LesionInfo();
  228. LesionInfoUpdated();
  229. }
  230. _lesion.VerticalPoint1 = verticalP1;
  231. _lesion.VerticalPoint2 = verticalP2;
  232. NotifyLesionInfoEventArgs?.Invoke(this, new LesionInfoEventArgs(EnumLesionInfoEventType.LesionInfoUpdated));
  233. VerticalAxisUpdated();
  234. }
  235. #endregion
  236. #region private
  237. /// <summary>
  238. /// 初始化下拉列表框
  239. /// </summary>
  240. private void InitializeComboBox()
  241. {
  242. // 形状
  243. ComboBoxShape.Items.Add("椭圆形");
  244. ComboBoxShape.Items.Add("类圆形");
  245. ComboBoxShape.Items.Add("不规则形");
  246. // 生长方向
  247. ComboBoxOrientation.Items.Add("平行");
  248. ComboBoxOrientation.Items.Add("非平行");
  249. // 回声类型
  250. ComboBoxEchoPattern.Items.Add("无回声");
  251. ComboBoxEchoPattern.Items.Add("低回声");
  252. ComboBoxEchoPattern.Items.Add("等回声");
  253. ComboBoxEchoPattern.Items.Add("高回声");
  254. ComboBoxEchoPattern.Items.Add("混合回声");
  255. // 边界
  256. ComboBoxBoundary.Items.Add("清晰");
  257. ComboBoxBoundary.Items.Add("模糊");
  258. // 边缘
  259. ComboBoxMargin.Items.Add("光整");
  260. ComboBoxMargin.Items.Add("不光整");
  261. }
  262. /// <summary>
  263. /// 病灶信息更新
  264. /// </summary>
  265. private void LesionInfoUpdated()
  266. {
  267. ContourUpdated();
  268. HorizontalAxisUpdated();
  269. VerticalAxisUpdated();
  270. ComboBoxShape.SelectionChanged -= OnShapeSelectionChanged;
  271. ComboBoxOrientation.SelectionChanged -= OnOrientationSelectionChanged;
  272. ComboBoxEchoPattern.SelectionChanged -= OnEchoPatternSelectionChanged;
  273. ComboBoxBoundary.SelectionChanged -= OnBoundarySelectionChanged;
  274. ComboBoxMargin.SelectionChanged -= OnMarginSelectionChanged;
  275. if (_lesion != null)
  276. {
  277. ComboBoxShape.SelectedIndex = (int)_lesion.Shape;
  278. ComboBoxOrientation.SelectedIndex = (int)_lesion.Orientation;
  279. ComboBoxEchoPattern.SelectedIndex = (int)_lesion.EchoPattern;
  280. ComboBoxBoundary.SelectedIndex = (int)_lesion.Boundary;
  281. ComboBoxMargin.SelectedIndex = (int)_lesion.Margin;
  282. }
  283. else
  284. {
  285. ComboBoxShape.SelectedIndex = -1;
  286. ComboBoxOrientation.SelectedIndex = -1;
  287. ComboBoxEchoPattern.SelectedIndex = -1;
  288. ComboBoxBoundary.SelectedIndex = -1;
  289. ComboBoxMargin.SelectedIndex = -1;
  290. }
  291. ComboBoxShape.SelectionChanged += OnShapeSelectionChanged;
  292. ComboBoxOrientation.SelectionChanged += OnOrientationSelectionChanged;
  293. ComboBoxEchoPattern.SelectionChanged += OnEchoPatternSelectionChanged;
  294. ComboBoxBoundary.SelectionChanged += OnBoundarySelectionChanged;
  295. ComboBoxMargin.SelectionChanged += OnMarginSelectionChanged;
  296. }
  297. /// <summary>
  298. /// 轮廓更新
  299. /// </summary>
  300. private void ContourUpdated()
  301. {
  302. string strContour = "";
  303. if (_lesion != null)
  304. {
  305. foreach (var point in _lesion.Contour)
  306. {
  307. strContour += "{" + point.X + "," + point.Y + "}";
  308. }
  309. }
  310. TextBlockContours.Text = strContour;
  311. }
  312. /// <summary>
  313. /// 横径更新
  314. /// </summary>
  315. private void HorizontalAxisUpdated()
  316. {
  317. string strHorizon = "";
  318. if (_lesion != null)
  319. {
  320. if (_lesion.HorizontalPoint1 != null && _lesion.HorizontalPoint2 != null)
  321. {
  322. strHorizon = "{" + _lesion.HorizontalPoint1.X + "," + _lesion.HorizontalPoint1.Y + "}," +
  323. "{" + _lesion.HorizontalPoint2.X + "," + _lesion.HorizontalPoint2.Y + "}";
  324. }
  325. }
  326. TextBlockHorizontal.Text = strHorizon;
  327. }
  328. /// <summary>
  329. /// 纵径更新
  330. /// </summary>
  331. private void VerticalAxisUpdated()
  332. {
  333. string strVertical = "";
  334. if (_lesion != null)
  335. {
  336. if (_lesion.VerticalPoint1 != null && _lesion.VerticalPoint2 != null)
  337. {
  338. strVertical = "{" + _lesion.VerticalPoint1.X + "," + _lesion.VerticalPoint1.Y + "}," +
  339. "{" + _lesion.VerticalPoint2.X + "," + _lesion.VerticalPoint2.Y + "}";
  340. }
  341. }
  342. TextBlockVertical.Text = strVertical;
  343. }
  344. #endregion
  345. #region properties
  346. /// <summary>
  347. /// 是否为空
  348. /// </summary>
  349. public bool IsEmpty => _lesion == null;
  350. /// <summary>
  351. /// 病灶
  352. /// </summary>
  353. public LesionInfo Lesion => _lesion;
  354. #endregion
  355. }
  356. }