123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Key;
- using Aitex.Core.Util;
- using DocumentFormat.OpenXml.Drawing;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Device.Bases;
- using OpenSEMI.ClientBase;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- using MECF.Framework.UI.Core.DxfScript;
- using MECF.Framework.Common;
- using System.IO;
- namespace FurnaceGasPanelUI.Views.Maintenances
- {
- /// <summary>
- /// TestView.xaml 的交互逻辑
- /// </summary>
- public partial class GasXmlView : UserControl
- {
- GasDxfDocument GasMap = null;
- private DispatcherTimer _refreshTimer;
- public GasXmlView()
- {
- InitializeComponent();
- GasMapProvider.GasMap = GasMap = new GasDxfDocument(draw, true, "GasViewXml.xml");
- draw.ClipToBounds = true;
- draw.Cursor = Cursors.Arrow;
- GasMap.LoadGas();
- GasMap.ParseConditions();
- }
- #region 画布事件
- private bool dragged = false;
- private System.Windows.Point mouseDownPoint = new System.Windows.Point(-1, -1);
- private Dictionary<UIElement, Rect> initialRect = new Dictionary<UIElement, Rect>();
- #region 鼠标操作:放大/缩小/拖拽/点击
- // 处理鼠标移动事件
- private void Canvas_MouseMove(object sender, MouseEventArgs e)
- {
- if (GasMap == null || GasMap.Lines == null) return;
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- //拖动状态
- if (mouseDownPoint.X > 0 && mouseDownPoint.Y > 0)
- {
- dragged = true;
- }
- }
- }
- // 处理鼠标左键松开事件
- private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- var endPoint = e.GetPosition(draw);
- if (dragged)
- {
- DraggedHandle(endPoint);
- return;
- }
- ClickHandle(endPoint);
- }
- // 处理鼠标左键按下事件
- private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var startPoint = e.GetPosition(draw);
- DownHandle(startPoint);
- CheckIfMouseIsOutOfCanvas(startPoint, draw);
- GasMap.ModifyDrag();
- }
- // 处理鼠标滚轮事件
- private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)
- {
- if (e.Delta > 0)
- {
- ZoomInCmdClick(null, null);//放大
- }
- else
- {
- ZoomOutCmdClick(null, null);// 缩小
- }
- }
- #endregion
- #region 触摸操作:点击/拖拽
- private System.Windows.Point? touchStartPoint = null;
- private const double DragThreshold = 5.0;
- private void Canvas_TouchUp(object sender, TouchEventArgs e)
- {
- if (touchStartPoint.HasValue)
- {
- var endPoint = e.GetTouchPoint(draw).Position;
- double distance = Math.Sqrt(Math.Pow(endPoint.X - touchStartPoint.Value.X, 2) + Math.Pow(endPoint.Y - touchStartPoint.Value.Y, 2));
- if (distance < DragThreshold)
- {
- // 触发点击事件
- // ClickHandle(endPoint);
- }
- else
- {
- // 触发拖拽完成事件
- DraggedHandle(endPoint);
- }
- touchStartPoint = null;
- draw.ReleaseTouchCapture(e.TouchDevice);
- }
- }
- private void Canvas_TouchDown(object sender, TouchEventArgs e)
- {
- var startPoint = e.GetTouchPoint(draw).Position;
- DownHandle(startPoint);
- CheckIfMouseIsOutOfCanvas(startPoint, draw);
- draw.CaptureTouch(e.TouchDevice);
- GasMap.ModifyDrag();
- }
- #endregion
- #region 多指操作 :放大/缩小
- private void Canvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
- {
- ScriptVariables.IsFetchRT = false;
- e.ManipulationContainer = draw; // 设置操作容器为画布本身
- e.Mode = ManipulationModes.All; // 启用所有操作类型
- }
- private void Canvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
- {
- if (e.DeltaManipulation.Scale.X > 1.0 && e.DeltaManipulation.Scale.Y > 1.0)
- {
- ZoomInCmdClick(null, null);//放大
- }
- else if (e.DeltaManipulation.Scale.X < 1.0 && e.DeltaManipulation.Scale.Y < 1.0)
- {
- ZoomOutCmdClick(null, null);// 缩小
- }
- e.Handled = true;
- }
- private void Canvas_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
- {
- ScriptVariables.IsFetchRT = true;
- }
- #endregion
- private void ZoomInCmdClick(object sender, RoutedEventArgs e)
- {
- double rate = 1;
- if (GasMap.Scale < 10)
- {
- GasMap.Scale += 0.5;
- rate = GasMap.Scale / (GasMap.Scale - 0.5);
- }
- double backupDragX = GasMap.dragX;
- double backupDragY = GasMap.dragY;
- GasMap.dragX = 0;
- GasMap.dragY = 0;
- GasMap.Draw();
- GasMap.dragX = backupDragX * rate;
- GasMap.dragY = backupDragY * rate;
- GasMap.DrawMovedImage();
- }
- private void ZoomOutCmdClick(object sender, RoutedEventArgs e)
- {
- double rate = 1;
- if (GasMap.Scale > 1)
- {
- GasMap.Scale -= 0.5;
- rate = GasMap.Scale / (GasMap.Scale + 0.5);
- }
- else
- {
- GasMap.Scale = 1;
- GasMap.dragX = 0;
- GasMap.dragY = 0;
- }
- double backupDragX = GasMap.dragX;
- double backupDragY = GasMap.dragY;
- GasMap.dragX = 0;
- GasMap.dragY = 0;
- GasMap.Draw();
- GasMap.dragX = backupDragX * rate;
- GasMap.dragY = backupDragY * rate;
- GasMap.DrawMovedImage();
- }
- private void CheckIfMouseIsOutOfCanvas(System.Windows.Point mousePosition, Canvas canvas)
- {
- double canvasWidth = canvas.ActualWidth;
- double canvasHeight = canvas.ActualHeight;
- if (mousePosition.X < 0 || mousePosition.Y < 0 || mousePosition.X > canvasWidth || mousePosition.Y > canvasHeight)
- {
- this.CaptureMouse();
- }
- }
- private void DraggedHandle(System.Windows.Point point)
- {
- dragged = false;
- GasMap.dragX += point.X - mouseDownPoint.X;
- GasMap.dragY += point.Y - mouseDownPoint.Y;
- GasMap.DrawMovedImage();
- mouseDownPoint.X = -1;
- mouseDownPoint.Y = -1;
- }
- private void ClickHandle(System.Windows.Point point)
- {
- var x = GasMap.ScreenToDxfX(point.X);
- var y = GasMap.ScreenToDxfY(point.Y);
- GasBaseShape shape = GasMap.GetShapeByPosition(x, y);
- if (shape != null)
- {
- GasMap.DrawShape(shape, true);
- GasMapProvider.GasMap.SelectedShape = GasMap.SelectedShape = shape;
- if (shape.ClickCondition != null)
- {
- shape.ClickCondition.Execute();
- GasMap.Draw();
- }
- }
- }
- private void DownHandle(System.Windows.Point point)
- {
- mouseDownPoint.X = point.X;
- mouseDownPoint.Y = point.Y;
- touchStartPoint = point;
- }
- #endregion
- }
- }
|