终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RunCanvas.xaml.cs 4.1 KiB

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.MessageName.接收消息Model;
  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.Navigation;
  16. using System.Windows.Shapes;
  17. namespace SCADA.Test
  18. {
  19. /// <summary>
  20. /// RunCanvas.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class RunCanvas : UserControl
  23. {
  24. public RunCanvas()
  25. {
  26. InitializeComponent();
  27. Unloaded += (s, e) => Destory();
  28. }
  29. /// <summary>
  30. /// Dispose子集
  31. /// </summary>
  32. public void Destory()
  33. {
  34. foreach (var item in RootCanvas.Children)
  35. {
  36. if (item is IDisposable disposable)
  37. {
  38. disposable.Dispose();
  39. }
  40. }
  41. }
  42. public List<EventReceiveMessage> Run(List<FrameworkElement> canvas)
  43. {
  44. List<EventReceiveMessage> messages=new List<EventReceiveMessage>();
  45. RootCanvas.Children.Clear();
  46. foreach (FrameworkElement element in canvas)
  47. {
  48. //if (element.GetType().GetInterface("IExecutable") != null)
  49. //{
  50. // element.GetType().GetProperty("IsExecuteState").SetValue(element, true);
  51. //}
  52. if (element is IExecutable executable)
  53. {
  54. executable.IsExecuteState = true;
  55. //if (executable.EventNameList != null && executable.EventNameList.Count > 0)
  56. //{
  57. // messages.AddRange(executable.EventNameList);
  58. //}
  59. }
  60. RootCanvas.Children.Add(element);
  61. RegisterJsName(element);
  62. }
  63. return messages;
  64. }
  65. // 注册名称到Js
  66. static void RegisterJsName(FrameworkElement element)
  67. {
  68. Config.GetInstance().SetVariable(element.Name, element);
  69. if (element is Panel panel)
  70. {
  71. foreach (var item in panel.Children)
  72. {
  73. RegisterJsName(item as FrameworkElement);
  74. }
  75. }
  76. }
  77. #region 拖动与缩放
  78. private void RootCanvas_MouseMove(object sender, MouseEventArgs e)
  79. {
  80. if (DragEnable.IsChecked == false)
  81. {
  82. return;
  83. }
  84. if (e.LeftButton == MouseButtonState.Pressed && isPressed)
  85. {
  86. Point point = e.GetPosition(this);
  87. var movex = (point.X - last.X);
  88. var movey = (point.Y - last.Y);
  89. Translate.X += movex;
  90. Translate.Y += movey;
  91. last = point;
  92. }
  93. }
  94. bool isPressed = false;
  95. Point last;//记录上次鼠标坐标位置
  96. private void RootCanvas_MouseLeftButtoDown(object sender, MouseButtonEventArgs e)
  97. {
  98. last = e.GetPosition(this);
  99. isPressed = true;
  100. }
  101. private void RootCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  102. {
  103. isPressed = false;
  104. }
  105. // 缩放
  106. private void RootCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
  107. {
  108. if (ZoomEnable.IsChecked == false)
  109. {
  110. return;
  111. }
  112. var zoomS = (e.Delta / 960d);
  113. var zoom = zoomS + Scale.ScaleX;
  114. if (zoom > 3 || zoom < 0.8)
  115. {
  116. return;
  117. }
  118. Scale.ScaleX = Scale.ScaleY = zoom;
  119. Point mouse = e.GetPosition(RootCanvas);
  120. Point newMouse = new Point(mouse.X * zoomS, mouse.Y * zoomS);
  121. Translate.X -= newMouse.X;
  122. Translate.Y -= newMouse.Y;
  123. }
  124. #endregion
  125. }
  126. }