VisionStaticAccuracyAnalyzer.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Cognex.VisionPro;
  2. using Cognex.VisionPro.Dimensioning;
  3. using System;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Windows.Controls;
  7. using TeamAAS_VP.ViewModels.Calibration;
  8. using TeamAAS_VP.ViewModels.Product;
  9. namespace TeamAAS_VP.Views.Product
  10. {
  11. /// <summary>
  12. /// Interaction logic for VisionStaticAccuracyAnalyzer
  13. /// </summary>
  14. public partial class VisionStaticAccuracyAnalyzer : UserControl
  15. {
  16. VisionStaticAccuracyAnalyzerViewModel VM;
  17. public VisionStaticAccuracyAnalyzer()
  18. {
  19. InitializeComponent();
  20. VM = DataContext as VisionStaticAccuracyAnalyzerViewModel;
  21. VM.PropertyChanged += VM_PropertyChanged;
  22. this.display.VerticalScrollBar = false;
  23. this.display.HorizontalScrollBar = false;
  24. this.display.AutoFit = true;
  25. this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
  26. }
  27. private int _imageWidth;
  28. private int _imageHeight;
  29. private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  30. {
  31. try
  32. {
  33. if (e.PropertyName == "Image")
  34. {
  35. this.display.Image = VM.Image;
  36. //图像中心点坐标
  37. _imageWidth = this.display.Image.Width;
  38. _imageHeight = this.display.Image.Height;
  39. }
  40. else if (e.PropertyName == "Graphic")
  41. {
  42. this.display.StaticGraphics.Clear();
  43. CogGraphicCollection graphic = new CogGraphicCollection();
  44. CogCreateLineTool line1 = new CogCreateLineTool();
  45. CogCreateLineTool line2 = new CogCreateLineTool();
  46. line1.InputImage = this.display.Image;
  47. line2.InputImage = this.display.Image;
  48. line1.Line.X = _imageWidth / 2;
  49. line1.Line.Y = _imageHeight / 2;
  50. line1.Line.Rotation = 0;
  51. line2.Line.X = _imageWidth / 2;
  52. line2.Line.Y = _imageHeight / 2;
  53. line2.Line.Rotation = Math.PI / 180 * 90;
  54. line1.Run();
  55. line2.Run();
  56. graphic.Add(line1.GetOutputLine());
  57. graphic.Add(line2.GetOutputLine());
  58. this.display.StaticGraphics.Clear();
  59. this.display.StaticGraphics.AddList(graphic, "");
  60. if (VM.Graphic != null)
  61. {
  62. this.display.StaticGraphics.AddList(VM.Graphic, "");
  63. }
  64. }
  65. }
  66. catch (System.Exception)
  67. {
  68. }
  69. }
  70. private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
  71. {
  72. // If the source is a DataTable, we can read the DataColumn's Caption
  73. if (e.PropertyDescriptor is PropertyDescriptor pd)
  74. {
  75. var columnName = pd.Name;
  76. var dv = dgResults.ItemsSource as DataView;
  77. if (dv != null && dv.Table != null && dv.Table.Columns.Contains(columnName))
  78. {
  79. var dataCol = dv.Table.Columns[columnName];
  80. if (!string.IsNullOrEmpty(dataCol.Caption))
  81. {
  82. e.Column.Header = dataCol.Caption;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }