From ef52fd6fd07508883dce4eb002acda59f0169e59 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 23 四月 2026 10:19:33 +0800
Subject: [PATCH] 优化;

---
 Plugin.TsExecution/SingleControl.xaml.cs |  145 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 134 insertions(+), 11 deletions(-)

diff --git a/Plugin.TsExecution/SingleControl.xaml.cs b/Plugin.TsExecution/SingleControl.xaml.cs
index 293f3f6..3e3c21a 100644
--- a/Plugin.TsExecution/SingleControl.xaml.cs
+++ b/Plugin.TsExecution/SingleControl.xaml.cs
@@ -1,4 +1,5 @@
-锘縰sing HMI.Core.Manager;
+锘縰sing HMI.Core.Entity;
+using HMI.Core.Manager;
 using HMI.Core.Util;
 using HMI.Util;
 using NationalInstruments.TestStand.Interop.API;
@@ -7,11 +8,11 @@
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.IO;
+using System.Linq;
 using System.Runtime.CompilerServices;
 using System.Timers;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Media;
 
 namespace Plugin.TsExecution
 {
@@ -25,7 +26,6 @@
 
         protected void Set([CallerMemberName] string name = null)
         {
-
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
         }
 
@@ -38,11 +38,13 @@
             }
         }
         #endregion
-        private bool isLoadOK = false;
         private int index;
         private string CountIniPath;
 
         private string status = "Ready";
+
+        private ScreenTouch[] screens;
+        private ScreenGrid screenGrid;
 
         public string Status
         {
@@ -101,6 +103,13 @@
             set { Set(ref barcode, value); }
         }
 
+        private string model = string.Empty;
+        public string Model
+        {
+            get { return model; }
+            set { Set(ref model, value); }
+        }
+
         private string elapseTime = "00:00:00";
         public string ElapseTime
         {
@@ -125,6 +134,16 @@
             }
         }
 
+        private string socketName = string.Empty;
+        public string SocketName
+        {
+            get { return socketName; }
+            set
+            {
+                Set(ref socketName, value);
+            }
+        }
+
         private ObservableCollection<TestStep> _datasource = new ObservableCollection<TestStep>();
         public ObservableCollection<TestStep> Datasource
         {
@@ -141,7 +160,7 @@
 
         private System.Timers.Timer refreshTimer;
 
-        private string currentStep = "绛夊緟鎵爜";
+        private string currentStep = "";
         public string CurrentStep
         {
             get => currentStep;
@@ -214,8 +233,8 @@
 
         public SingleControl(int Index, string CountIniPath, int probeWarn)
         {
-            this.CountIniPath = CountIniPath;
             DataContext = this;
+            this.CountIniPath = CountIniPath;
             this.index = Index;
             ProbeWarn = probeWarn;
 
@@ -302,7 +321,7 @@
                     var now = DateTime.Now;
                     var span = now - StepStartTime;
                     StepStartTime = now;
-                    data.ConsumeTime = $"{span.Seconds}s";
+                    data.ConsumeTime = $"{(span.TotalMilliseconds / 1000d).ToString("F2")}s";
                     Datasource.Add(data);
                     table.ScrollIntoView(data);
                 }));
@@ -546,11 +565,115 @@
             }
         }
 
-        private void TextBlock_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+        public void RefreshScreen(int[][] configs)
         {
-            DependencyObject parent = VisualTreeHelper.GetParent((DependencyObject)sender);
-            while (parent != null) {
-                parent = VisualTreeHelper.GetParent(parent);
+            //foreach (UIElement item in canvas.Children)
+            //{
+            //    if (item is ScreenTouch)
+            //    {
+            //        canvas.Children.Remove(item);
+            //    }
+            //}
+            screenContainer.Child = null;
+
+
+            screenGrid = new ScreenGrid(1, configs.Length);
+
+            screens = new ScreenTouch[configs.Length];
+
+            int space = 2 * (screens.Length + 1);
+            for (int i = 0; i < configs.Length; i++)
+            {
+                var screen = new ScreenTouch(configs[i][0], configs[i][1])
+                {
+                    Width = Math.Max((tableHeader.ActualHeight / 9 * 16 - space) / screens.Length, 0),
+                    Height = Math.Max((tableHeader.ActualHeight / 9 * 16 - space) / screens.Length / 16 * 9, 0)
+                };
+                screens[i] = screen;
+                screenGrid.AddScreen(screen, 0, i);
+            }
+            screenContainer.Child = screenGrid;
+
+            //canvas.Children.Add(screens[0]);
+            //Canvas.SetBottom(screens[0], 0);
+            //Canvas.SetRight(screens[0], 0);
+            //Panel.SetZIndex(screens[0], 999);
+        }
+
+        public void DrawScreenPoint(int index, int x, int y)
+        {
+            screens[index].DrawPoint(x, y);
+        }
+
+        public void DrawScreenPoints(int index, int[][] points)
+        {
+            screens[index].DrawPoints(points);
+        }
+
+        public void ClearScreenPoint(int index)
+        {
+            screens[index].Clear();
+        }
+
+        public void RefreshProduct(ProductData product)
+        {
+            if (product == null)
+            {
+                screenContainer.Child = null;
+                return;
+            }
+            try
+            {
+                string screenSize = ProductManager.GetParameterByProductAndName(product.Name, "ScreenTouch")?.Value;
+                if (string.IsNullOrEmpty(screenSize))
+                {
+                    screenContainer.Child = null;
+                    return;
+                }
+                string[] arr = screenSize.Split(';');
+                int[][] configs = new int[arr.Length][];
+
+                for (int i = 0; i < arr.Length; i++)
+                {
+                    string[] size = arr[i].Split(',');
+                    configs[i] = new int[2] { int.Parse(size[0]), int.Parse(size[1]) };
+                }
+                RefreshScreen(configs);
+            }
+            catch (Exception ex)
+            {
+                TsExecution.logger.Error("RefreshProduct Failed.", ex);
+                screenContainer.Child = null;
+            }
+        }
+
+        private void control_SizeChanged(object sender, SizeChangedEventArgs e)
+        {
+            if (screenGrid == null)
+            {
+                return;
+            }
+            //screenGrid.Height = tableHeader.ActualHeight - 2;
+            //screenGrid.Width = tableHeader.ActualHeight / 9 * 16 - 2;
+
+            int space = 2 * (screens.Length + 1);
+
+            for (int i = 0; i < screens.Length; i++)
+            {
+                var screen = screens[i];
+                screen.Width = Math.Max(Math.Floor((tableHeader.ActualHeight / 9 * 16 - space) / screens.Length), 0);
+                screen.Height = Math.Max(Math.Floor(screen.Width / 16 * 9), 0);
+            }
+        }
+
+        private void screenContainer_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+        {
+            if (e.ClickCount == 2)
+            {
+                new ScreenTouchWin(screens)
+                {
+                    Owner = Window.GetWindow(this)
+                }.ShowDialog();
             }
         }
     }

--
Gitblit v1.9.1