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

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