Browse Source

优化图像中心十字线绘制及命令刷新逻辑

- 在图像显示控件中,新增自动绘制中心十字线功能,支持图像尺寸变化时自动重绘,提升视觉定位体验。
- 将 _IsGrap 字段默认值由 true 改为未初始化(false)。
- StartGrabbingCommand 和 StopGrabbingCommand 增加对 SelectedCamera 属性的监听,确保命令可用性及时刷新。
- 新增相关命名空间引用,完善代码结构。
孝锋 徐 8 tháng trước cách đây
mục cha
commit
4d501ac5fb

+ 3 - 3
TeamAAS-VM/ViewModels/Product/PlcPointParamsViewModel.cs

@@ -274,7 +274,7 @@ namespace TeamAAS_VP.ViewModels.Product
             set { SetProperty(ref _LockScrewProgramNumber, value); }
         }
 
-        private bool _IsGrap = true;
+        private bool _IsGrap;
         public bool IsGrap
         {
             get { return _IsGrap; }
@@ -438,11 +438,11 @@ namespace TeamAAS_VP.ViewModels.Product
 
         private DelegateCommand _StartGrabbingCommand;
         public DelegateCommand StartGrabbingCommand =>
-            _StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand, CanExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap));
+            _StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand, CanExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(()=> SelectedCamera));
 
         private DelegateCommand _StopGrabbingCommand;
         public DelegateCommand StopGrabbingCommand =>
-            _StopGrabbingCommand ?? (_StopGrabbingCommand = new DelegateCommand(ExecuteStopGrabbingCommand, CanExecuteStopGrabbingCommand).ObservesProperty(() => IsGrap));
+            _StopGrabbingCommand ?? (_StopGrabbingCommand = new DelegateCommand(ExecuteStopGrabbingCommand, CanExecuteStopGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
         
         #endregion
 

+ 56 - 2
TeamAAS-VM/Views/Product/PlcPointParams.xaml.cs

@@ -1,4 +1,8 @@
-using System.Windows.Controls;
+using Cognex.VisionPro;
+using Cognex.VisionPro.Dimensioning;
+using OxyPlot;
+using System;
+using System.Windows.Controls;
 using TeamAAS_VP.ViewModels.Product;
 
 namespace TeamAAS_VP.Views.Product
@@ -21,11 +25,61 @@ namespace TeamAAS_VP.Views.Product
             this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
         }
 
+        private int _imageWidth;
+        private int _imageHeight;
         private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
         {
             if (e.PropertyName == "Image")
             {
-                this.display.Image = VM.Image;
+                if (this.display.Image==null)
+                {
+                    this.display.Image = VM.Image;
+                    //图像中心点坐标
+                    _imageWidth= this.display.Image.Width;
+                    _imageHeight= this.display.Image.Height;
+                    CogGraphicCollection graphic = new CogGraphicCollection();
+                    CogCreateLineTool line1 = new CogCreateLineTool();
+                    CogCreateLineTool line2 = new CogCreateLineTool();
+                    line1.InputImage = this.display.Image;
+                    line2.InputImage = this.display.Image;
+                    line1.Line.X = _imageWidth / 2;
+                    line1.Line.Y = _imageHeight / 2;
+                    line1.Line.Rotation = 0;
+                    line2.Line.X = _imageWidth / 2;
+                    line2.Line.Y = _imageHeight / 2;
+                    line2.Line.Rotation = Math.PI / 180 * 90;
+                    line1.Run();
+                    line2.Run();
+                    graphic.Add(line1.GetOutputLine());
+                    graphic.Add(line2.GetOutputLine());
+
+                }
+                else
+                {
+                    this.display.Image = VM.Image;
+                    //如果图像的长宽发生变化,则重新绘制十字线
+                    if (_imageWidth!= this.display.Image.Width|| _imageHeight!= this.display.Image.Height)
+                    {
+                        _imageWidth = this.display.Image.Width;
+                        _imageHeight = this.display.Image.Height;
+                        CogGraphicCollection graphic = new CogGraphicCollection();
+                        CogCreateLineTool line1 = new CogCreateLineTool();
+                        CogCreateLineTool line2 = new CogCreateLineTool();
+                        line1.InputImage = this.display.Image;
+                        line2.InputImage = this.display.Image;
+                        line1.Line.X = _imageWidth / 2;
+                        line1.Line.Y = _imageHeight / 2;
+                        line1.Line.Rotation = 0;
+                        line2.Line.X = _imageWidth / 2;
+                        line2.Line.Y = _imageHeight / 2;
+                        line2.Line.Rotation = Math.PI / 180 * 90;
+                        line1.Run();
+                        line2.Run();
+                        graphic.Add(line1.GetOutputLine());
+                        graphic.Add(line2.GetOutputLine());
+                    }
+
+                }
             }
         }
     }