| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using Cognex.VisionPro;
- using Cognex.VisionPro.Dimensioning;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- 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 TeamAAS_VP.ViewModels.Product;
- namespace TeamAAS_VP.Views.Product
- {
- /// <summary>
- /// Interaction logic for VisionStaticAccuracyAnalyzer
- /// </summary>
- public partial class VisionStaticAccuracyAnalyzer : UserControl
- {
- VisionStaticAccuracyAnalyzerViewModel VM;
- public VisionStaticAccuracyAnalyzer()
- {
- InitializeComponent();
- VM = DataContext as VisionStaticAccuracyAnalyzerViewModel;
- VM.PropertyChanged += VM_PropertyChanged;
- this.display.VerticalScrollBar = false;
- this.display.HorizontalScrollBar = false;
- this.display.AutoFit = true;
- this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
- }
- private int _imageWidth;
- private int _imageHeight;
- private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- try
- {
- if (e.PropertyName == "Image")
- {
- this.display.Image = VM.Image;
- //图像中心点坐标
- _imageWidth = this.display.Image.Width;
- _imageHeight = this.display.Image.Height;
- }
- else if (e.PropertyName == "Graphic")
- {
- this.display.StaticGraphics.Clear();
- 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());
- this.display.StaticGraphics.Clear();
- this.display.StaticGraphics.AddList(graphic, "");
- if (VM.Graphic != null)
- {
- this.display.StaticGraphics.AddList(VM.Graphic, "");
- }
- }
- }
- catch (System.Exception)
- {
- }
- }
- private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
- {
- // If the source is a DataTable, we can read the DataColumn's Caption
- if (e.PropertyDescriptor is PropertyDescriptor pd)
- {
- var columnName = pd.Name;
- var dv = dgResults.ItemsSource as DataView;
- if (dv != null && dv.Table != null && dv.Table.Columns.Contains(columnName))
- {
- var dataCol = dv.Table.Columns[columnName];
- if (!string.IsNullOrEmpty(dataCol.Caption))
- {
- e.Column.Header = dataCol.Caption;
- }
- }
- }
- }
- }
- }
|