check point

This commit is contained in:
meelstorm
2025-07-14 12:03:59 +02:00
commit d3cb790bd9
431 changed files with 44078 additions and 0 deletions

View File

@@ -0,0 +1,191 @@
namespace Hawkeye.VisionBuilder.Features.VisionSteps
{
partial class VisionStepsPanel
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView1 = new DataGridView();
panel1 = new Panel();
lblProcessingTime = new Label();
label1 = new Label();
btnTest = new Button();
button1 = new Button();
Indicator = new DataGridViewTextBoxColumn();
Link = new DataGridViewTextBoxColumn();
UserName = new DataGridViewTextBoxColumn();
Result = new DataGridViewTextBoxColumn();
TypeName = new DataGridViewTextBoxColumn();
Time = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
panel1.SuspendLayout();
SuspendLayout();
//
// dataGridView1
//
dataGridView1.AllowDrop = true;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Indicator, Link, UserName, Result, TypeName, Time });
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Location = new Point(0, 40);
dataGridView1.MultiSelect = false;
dataGridView1.Name = "dataGridView1";
dataGridView1.ReadOnly = true;
dataGridView1.RowHeadersVisible = false;
dataGridView1.RowTemplate.Height = 25;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.Size = new Size(540, 562);
dataGridView1.TabIndex = 0;
dataGridView1.DragDrop += dataGridView1_DragDrop;
dataGridView1.DragOver += dataGridView1_DragOver;
dataGridView1.KeyDown += dataGridView1_KeyDown;
dataGridView1.MouseDown += dataGridView1_MouseDown;
dataGridView1.MouseMove += dataGridView1_MouseMove;
dataGridView1.MouseUp += dataGridView1_MouseUp;
//
// panel1
//
panel1.Controls.Add(lblProcessingTime);
panel1.Controls.Add(label1);
panel1.Controls.Add(btnTest);
panel1.Controls.Add(button1);
panel1.Dock = DockStyle.Top;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(540, 40);
panel1.TabIndex = 1;
//
// lblProcessingTime
//
lblProcessingTime.AutoSize = true;
lblProcessingTime.Location = new Point(312, 16);
lblProcessingTime.Name = "lblProcessingTime";
lblProcessingTime.Size = new Size(32, 15);
lblProcessingTime.TabIndex = 3;
lblProcessingTime.Text = "0 ms";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(216, 16);
label1.Name = "label1";
label1.Size = new Size(94, 15);
label1.TabIndex = 2;
label1.Text = "Processing time:";
//
// btnTest
//
btnTest.Location = new Point(112, 8);
btnTest.Name = "btnTest";
btnTest.Size = new Size(96, 23);
btnTest.TabIndex = 1;
btnTest.Text = "Test run";
btnTest.UseVisualStyleBackColor = true;
btnTest.Click += btnTest_Click;
//
// button1
//
button1.Location = new Point(8, 8);
button1.Name = "button1";
button1.Size = new Size(96, 23);
button1.TabIndex = 0;
button1.Text = "&Add tool";
button1.UseVisualStyleBackColor = true;
button1.Click += button1_Click;
//
// Indicator
//
Indicator.HeaderText = "";
Indicator.MinimumWidth = 20;
Indicator.Name = "Indicator";
Indicator.ReadOnly = true;
Indicator.Width = 32;
//
// Link
//
Link.HeaderText = "";
Link.Name = "Link";
Link.ReadOnly = true;
Link.Width = 32;
//
// UserName
//
UserName.HeaderText = "Label";
UserName.Name = "UserName";
UserName.ReadOnly = true;
//
// Result
//
Result.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
Result.HeaderText = "Result";
Result.Name = "Result";
Result.ReadOnly = true;
//
// TypeName
//
TypeName.HeaderText = "Type";
TypeName.Name = "TypeName";
TypeName.ReadOnly = true;
//
// Time
//
Time.HeaderText = "Time";
Time.Name = "Time";
Time.ReadOnly = true;
//
// VisionStepsPanel
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(540, 602);
Controls.Add(dataGridView1);
Controls.Add(panel1);
Name = "VisionStepsPanel";
Text = "Vision Steps";
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
panel1.ResumeLayout(false);
panel1.PerformLayout();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView1;
private Panel panel1;
private Button button1;
private Button btnTest;
private Label lblProcessingTime;
private Label label1;
private DataGridViewTextBoxColumn Indicator;
private DataGridViewTextBoxColumn Link;
private DataGridViewTextBoxColumn UserName;
private DataGridViewTextBoxColumn Result;
private DataGridViewTextBoxColumn TypeName;
private DataGridViewTextBoxColumn Time;
}
}

View File

@@ -0,0 +1,355 @@
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Hawkeye.VisionBuilder.Features.ImagePreview;
using Hawkeye.VisionBuilder.Panels;
using Hawkeye.VisionBuilder.Workflow;
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements;
using Hawkeye.VisionBuilder.Workflow.Links;
using Rectangle = System.Drawing.Rectangle;
namespace Hawkeye.VisionBuilder.Features.VisionSteps
{
public partial class VisionStepsPanel : BasePannel
{
private readonly WorkflowList _workflowList;
private readonly OperationDiscoveryService _discoveryService;
private readonly ImagePreviewPanel _imagePreviewPanel;
private BindingSource _bindingSource = new BindingSource();
public VisionStepsPanel(Workflow.WorkflowList workflowList, OperationDiscoveryService discoveryService,
ImagePreview.ImagePreviewPanel imagePreviewPanel)
{
_workflowList = workflowList;
_discoveryService = discoveryService;
_imagePreviewPanel = imagePreviewPanel;
InitializeComponent();
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = _bindingSource;
dataGridView1.Columns[0].DataPropertyName = nameof(BaseOperationDecorator.Result);
dataGridView1.Columns[2].DataPropertyName = nameof(BaseOperationDecorator.Label);
dataGridView1.Columns[2].ReadOnly = false;
dataGridView1.ReadOnly = false;
dataGridView1.Columns[3].DataPropertyName = nameof(BaseOperationDecorator.ResultString);
dataGridView1.Columns[4].DataPropertyName = nameof(BaseOperationDecorator.TypeName);
dataGridView1.Columns[5].DataPropertyName = nameof(BaseOperationDecorator.ExecutionTimeString);
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Bisque;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;
dataGridView1.CellPainting += DataGridView1_CellPainting;
dataGridView1.SelectionChanged += DataGridView1_SelectionChanged;
RefreshWorkflow();
//dataGridView1.Paint += DataGridView1_Paint;
}
public void RefreshWorkflow()
{
_bindingSource.Clear();
foreach (BaseOperation operation in _workflowList.Operations)
{
_bindingSource.Add(new BaseOperationDecorator(operation));
}
}
public event Action<BaseOperation> OperationSelected = delegate { };
private void DataGridView1_SelectionChanged(object? sender, EventArgs e)
{
}
public void UpdateView()
{
_imagePreviewPanel.ClearGraphics();
_imagePreviewPanel.SetImage(_workflowList.Context.ActiveImage);
_workflowList.Context.GraphicsElements.ForEach(_imagePreviewPanel.AddGraphics);
_imagePreviewPanel.Refresh();
Refresh();
}
private void DataGridView1_Paint(object? sender, PaintEventArgs e)
{
var g = e.Graphics;
var c1 = dataGridView1.GetCellDisplayRectangle(1, 0, true);
var c2 = dataGridView1.GetCellDisplayRectangle(1, 1, true);
Pen start = new Pen(Color.Blue, 2);
Pen body = new Pen(Color.Blue, 2);
Pen end = new Pen(Color.Blue, 2);
end.EndCap = LineCap.Custom;
AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5);
end.CustomEndCap = bigArrow;
g.DrawLine(start, c1.Right, (c1.Bottom - c1.Top) / 2 + c1.Top, (c1.Right - c1.Left) / 2 + c1.Left,
(c1.Bottom - c1.Top) / 2 + c1.Top);
g.DrawLine(body, (c1.Right - c1.Left) / 2 + c1.Left, (c1.Bottom - c1.Top) / 2 + c1.Top,
(c2.Right - c2.Left) / 2 + c1.Left, (c2.Bottom - c2.Top) / 2 + c2.Top);
g.DrawLine(end, (c2.Right - c2.Left) / 2 + c2.Left, (c2.Bottom - c2.Top) / 2 + c2.Top, c2.Right,
(c2.Bottom - c2.Top) / 2 + c2.Top);
}
private void DataGridView1_CellPainting(object? sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex > -1 && e.Value != null)
{
var cx = e.CellBounds.Width / 2 + e.CellBounds.Left;
var cy = e.CellBounds.Height / 2 + e.CellBounds.Top;
var radius = e.CellBounds.Height / 2 - 3;
var c1 = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
e.PaintBackground(c1, true);
if ((bool)e.Value)
{
e.Graphics.FillEllipse(Brushes.Green, cx - radius, cy - radius, radius * 2, radius * 2);
}
else
{
e.Graphics.FillEllipse(Brushes.Red, cx - radius, cy - radius, radius * 2, radius * 2);
}
e.Handled = true;
}
}
private static ToolStripMenuItem EnsureCategory(ToolStripItemCollection collection, string category)
{
var name = category.Split("/", StringSplitOptions.RemoveEmptyEntries);
ToolStripMenuItem currentCategory = null;
foreach (var s in name)
{
if (currentCategory == null)
{
if (!collection.ContainsKey(s))
{
currentCategory = new ToolStripMenuItem()
{
Name = s,
Text = s
};
collection.Add(currentCategory);
}
else
{
currentCategory = collection[s] as ToolStripMenuItem;
}
}
else
{
if (!currentCategory.DropDownItems.ContainsKey(s))
{
var newCategory = new ToolStripMenuItem()
{
Name = s,
Text = s
};
currentCategory.DropDownItems.Add(newCategory);
currentCategory = newCategory;
}
else
{
currentCategory = currentCategory.DropDownItems[s] as ToolStripMenuItem;
}
}
}
return currentCategory!;
}
private void button1_Click(object sender, EventArgs e)
{
var factories = _discoveryService.DiscoverOperations();
var context = new ContextMenuStrip();
foreach (OperationDescription desc in factories)
{
var descCategory = desc.Category;
ToolStripMenuItem currentCategory = EnsureCategory(context.Items, descCategory);
currentCategory.DropDownItems.Add(desc.Name).Click += (o, args) =>
{
var operation = _discoveryService.CreateInstance(desc.Type);
_workflowList.Operations.Add(operation);
int num = 1;
while (_workflowList.Operations.Any(x => x.Label == operation.Label + num)) num++;//generate unique name
operation.Label += "" + num;
_bindingSource.Add(new BaseOperationDecorator(operation));
dataGridView1.ClearSelection();
dataGridView1.Rows[^1].Selected = true;
ProcessRowSelection();
};
}
context.Show(button1, button1.Location);
}
private void btnTest_Click(object sender, EventArgs e)
{
ExecuteWorkflow();
}
public WorkflowList WorkflowList => _workflowList;
public void ExecuteWorkflow()
{
_workflowList.Context = new Context();
var sw = Stopwatch.StartNew();
_workflowList.Operations.ForEach(x => x.NeedsUpdate = true);
_workflowList.Execute();
sw.Stop();
lblProcessingTime.Text = sw.ElapsedMilliseconds.ToString() + " ms";
_imagePreviewPanel.SetImage(_workflowList.Context.ActiveImage);
_imagePreviewPanel.ClearGraphics();
_workflowList.Context.GraphicsElements.ForEach(_imagePreviewPanel.AddGraphics);
Refresh();
}
private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
ProcessRowSelection();
}
public BaseOperation? GetSelectedOperation()
{
if (dataGridView1.SelectedRows.Count == 0) return null;
var rowIndex = dataGridView1.SelectedRows[0].Index;
return (_bindingSource[rowIndex] as BaseOperationDecorator)?.Operation;
}
public void ProcessRowSelection()
{
if (dataGridView1.SelectedRows.Count == 0) return;
var rowIndex = dataGridView1.SelectedRows[0].Index;
var x = (_bindingSource[rowIndex] as BaseOperationDecorator);
OperationSelected.Invoke(x.Operation);
_imagePreviewPanel.ClearGraphics();
foreach (BaseOperation operation in _workflowList.Operations)
{
if (operation.NeedsUpdate) _workflowList.ExecuteOne(operation);
if (operation == x.Operation) break;
}
UpdateView();
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (dataGridView1.SelectedRows.Count == 0) return;
var rowIndex = dataGridView1.SelectedRows[0].Index;
_bindingSource.RemoveAt(rowIndex);
_workflowList.Operations.RemoveAt(rowIndex);
if (rowIndex > 0)
{
dataGridView1.ClearSelection();
dataGridView1.Rows[rowIndex - 1].Selected = true;
ProcessRowSelection();
}
}
}
private Rectangle dragBoxFromMouseDown;
private int rowIndexFromMouseDown;
private int rowIndexOfItemUnderMouseToDrop;
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Proceed with the drag and drop, passing in the list item.
DragDropEffects dropEffect = dataGridView1.DoDragDrop(
dataGridView1.Rows[rowIndexFromMouseDown],
DragDropEffects.Move);
}
}
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
// Get the index of the item the mouse is below.
rowIndexFromMouseDown = dataGridView1.HitTest(e.X, e.Y).RowIndex;
if (rowIndexFromMouseDown != -1)
{
// Remember the point where the mouse down occurred.
// The DragSize indicates the size that the mouse can move
// before a drag event should be started.
Size dragSize = SystemInformation.DragSize;
// Create a rectangle using the DragSize, with the mouse position being
// at the center of the rectangle.
dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2),
e.Y - (dragSize.Height / 2)),
dragSize);
}
else
// Reset the rectangle if the mouse is not over an item in the ListBox.
dragBoxFromMouseDown = Rectangle.Empty;
}
private void dataGridView1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
// The mouse locations are relative to the screen, so they must be
// converted to client coordinates.
Point clientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
// Get the row index of the item the mouse is below.
rowIndexOfItemUnderMouseToDrop =
dataGridView1.HitTest(clientPoint.X, clientPoint.Y).RowIndex;
var movable = _workflowList.Operations[rowIndexFromMouseDown];
_workflowList.Operations.RemoveAt(rowIndexFromMouseDown);
if (rowIndexOfItemUnderMouseToDrop == -1) rowIndexOfItemUnderMouseToDrop = _workflowList.Operations.Count;
_workflowList.Operations.Insert(rowIndexOfItemUnderMouseToDrop, movable);
dataGridView1.ClearSelection();
RefreshWorkflow();
dataGridView1.Rows[rowIndexOfItemUnderMouseToDrop].Selected = true;
ProcessRowSelection();
}
}
}

View File

@@ -0,0 +1,78 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Indicator.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Link.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="UserName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Result.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="TypeName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Time.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>