ShapeAddWindow.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using NEIntelligentControl2.Service.Station;
  2. using SVGViewer.Models.Info;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace NEIntelligentControl2.Windows.BoostStation
  17. {
  18. /// <summary>
  19. /// 图形标记窗口
  20. /// </summary>
  21. public partial class ShapeAddWindow : Window
  22. {
  23. public ShapeInfo Info { get; set; }
  24. /// <summary>
  25. /// 编辑类型
  26. /// </summary>
  27. public BoostStationEditType EditType { get; set; }
  28. private StationManager _StationManager;
  29. public ShapeAddWindow(List<ShapeInfo> customizeShapes)
  30. {
  31. InitializeComponent();
  32. _StationManager = App.ServiceProvider.GetService(typeof(StationManager)) as StationManager;
  33. _esv.CustomizeShapes = customizeShapes;
  34. _esv.CustomizeEdited = OnCustomizeEdited;
  35. }
  36. public ShapeAddWindow(ShapeInfo info, List<ShapeInfo> customizeShapes) : this(customizeShapes)
  37. {
  38. Info = info;
  39. _esv.SwitchShapeInfo(info);
  40. }
  41. private void Button_Click(object sender, RoutedEventArgs e)
  42. {
  43. switch (((Control)sender).Tag)
  44. {
  45. case "ok": // 确认
  46. Ok();
  47. break;
  48. case "cancel": // 取消
  49. this.DialogResult = false;
  50. break;
  51. case "output":
  52. Output();
  53. break;
  54. default: return;
  55. }
  56. }
  57. private void Output()
  58. {
  59. SVGViewer.Manager.SVGOutput2 so = new SVGViewer.Manager.SVGOutput2(_esv.Canvas, _esv.CustomizeShapes);
  60. Task.Run(output);
  61. void output()
  62. {
  63. var v = so.GetSvgFileInfo();
  64. var info = so.SvgInfo;
  65. string s = _StationManager.OutputSvgInfo(v, info);
  66. if (s == "success")
  67. {
  68. Dispatcher.Invoke(() => MessageWindow.ShowMessage("导出成功!"));
  69. return;
  70. }
  71. Dispatcher.Invoke(() => MessageWindow.ShowMessage(s));
  72. }
  73. }
  74. /// <summary>
  75. /// 自定义控件编辑
  76. /// </summary>
  77. private bool OnCustomizeEdited(ShapeInfo arg1, string arg2)
  78. {
  79. var v = _StationManager.AddOrRemoveCustomizeShape(arg1, arg2);
  80. if (v != "success")
  81. {
  82. MessageWindow.ShowMessage(v);
  83. return false;
  84. }
  85. return true;
  86. }
  87. private void Ok()
  88. {
  89. var info = _esv.SharpInfo;
  90. var v = _StationManager.AddOrUpdateStation(info, this.EditType);
  91. if (v != "success")
  92. {
  93. MessageWindow.ShowMessage(v);
  94. return;
  95. }
  96. Info = _esv.SharpInfo;
  97. this.DialogResult = true;
  98. }
  99. public static ShapeInfo Show(BoostStationEditType type, string title, List<ShapeInfo> customizeShapes, Func<ShapeInfo, string, bool> shapeAdding, ShapeInfo info = null)
  100. {
  101. ShapeAddWindow saw = info == null ? new ShapeAddWindow(customizeShapes) : new ShapeAddWindow(info, customizeShapes);
  102. saw.EditType = type;
  103. saw.Owner = Application.Current.MainWindow;
  104. saw.Title = title;
  105. //saw.CustomizeEdited = shapeAdding;
  106. var b = saw.ShowDialog();
  107. if (b == true)
  108. {
  109. return saw.Info;
  110. }
  111. return null;
  112. }
  113. private void Undo_CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  114. {
  115. _esv.Undo();
  116. }
  117. private void Redo_CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  118. {
  119. _esv.Redo();
  120. }
  121. }
  122. /// <summary>
  123. /// 升压站编辑类型
  124. /// </summary>
  125. public enum BoostStationEditType
  126. {
  127. /// <summary>
  128. /// 升压站编辑
  129. /// </summary>
  130. BoostStationEdit,
  131. /// <summary>
  132. /// 升压站添加
  133. /// </summary>
  134. BoostStationAdd,
  135. /// <summary>
  136. /// 二次图编辑
  137. /// </summary>
  138. SubStationEdit,
  139. /// <summary>
  140. /// 二次图添加
  141. /// </summary>
  142. SubStationAdd,
  143. }
  144. }