终端一体化运控平台
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.
 
 
 

134 lines
3.7 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.SCADAControl;
  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 BeDesignerSCADA.Controls
  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 void Run(List<FrameworkElement> canvas)
  43. {
  44. RootCanvas.Children.Clear();
  45. foreach (FrameworkElement element in canvas)
  46. {
  47. //if (element.GetType().GetInterface("IExecutable")!=null)
  48. //{
  49. // element.GetType().GetProperty("IsExecuteState").SetValue(element, true);
  50. //}
  51. if (element is IExecutable executable)
  52. executable.IsExecuteState = true;
  53. RootCanvas.Children.Add(element);
  54. RegisterJsName(element);
  55. }
  56. }
  57. // 注册名称到Js
  58. static void RegisterJsName(FrameworkElement element)
  59. {
  60. Config.GetInstance().SetVariable(element.Name, element);
  61. if (element is Panel panel)
  62. {
  63. foreach (var item in panel.Children)
  64. {
  65. RegisterJsName(item as FrameworkElement);
  66. }
  67. }
  68. }
  69. #region 拖动与缩放
  70. private void RootCanvas_MouseMove(object sender, MouseEventArgs e)
  71. {
  72. if (DragEnable.IsChecked == false)
  73. {
  74. return;
  75. }
  76. if (e.LeftButton == MouseButtonState.Pressed && isPressed)
  77. {
  78. Point point = e.GetPosition(this);
  79. var movex = (point.X - last.X);
  80. var movey = (point.Y - last.Y);
  81. Translate.X += movex;
  82. Translate.Y += movey;
  83. last = point;
  84. }
  85. }
  86. bool isPressed = false;
  87. Point last;//记录上次鼠标坐标位置
  88. private void RootCanvas_MouseLeftButtoDown(object sender, MouseButtonEventArgs e)
  89. {
  90. last = e.GetPosition(this);
  91. isPressed = true;
  92. }
  93. private void RootCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  94. {
  95. isPressed = false;
  96. }
  97. // 缩放
  98. private void RootCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
  99. {
  100. if (ZoomEnable.IsChecked == false)
  101. {
  102. return;
  103. }
  104. var zoomS = (e.Delta / 960d);
  105. var zoom = zoomS + Scale.ScaleX;
  106. if (zoom > 3 || zoom < 0.8)
  107. {
  108. return;
  109. }
  110. Scale.ScaleX = Scale.ScaleY = zoom;
  111. Point mouse = e.GetPosition(RootCanvas);
  112. Point newMouse = new Point(mouse.X * zoomS, mouse.Y * zoomS);
  113. Translate.X -= newMouse.X;
  114. Translate.Y -= newMouse.Y;
  115. }
  116. #endregion
  117. }
  118. }