终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

136 rindas
3.9 KiB

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