2 Commits

Author SHA1 Message Date
6696c4e106 修改config 2025-03-18 14:20:11 +08:00
25cd61c5cb 尺寸测量功能界面 2025-03-16 17:32:09 +08:00
103 changed files with 13759 additions and 482 deletions

View File

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\</BaseOutputPath>
<AppendTargetFrameworkToOutputPath>output</AppendTargetFrameworkToOutputPath>
<UseWindowsForms>true</UseWindowsForms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<!--<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.9" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.9" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.9" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.88.9" />
</ItemGroup>-->
</Project>

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Helper
{
public static class PointHelper
{
public static Point ToPoint(this PointF pf)
{
return new Point((int)pf.X, (int)pf.Y);
}
/// <summary>
/// 将相对于控件的坐标转换为相对于图像的坐标
/// </summary>
/// <param name="p">控件中指定点的点位坐标,坐标原点为控件左上角</param>
/// <returns>该点以图像坐标系为基准的坐标值,坐标原点为图像左上角</returns>
public static PointF ToImageCoordinate(this Point p, Matrix m)
{
PointF pf = new PointF(p.X, p.Y);
return ToImageCoordinate(pf, m);
}
/// <summary>
/// 将相对于控件的坐标转换为相对于图像的坐标
/// </summary>
/// <param name="p">控件中指定点的点位坐标,坐标原点为控件左上角</param>
/// <returns>该点以图像坐标系为基准的坐标值,坐标原点为图像左上角</returns>
public static PointF ToImageCoordinate(this PointF p, Matrix m)
{
PointF[] ps = new PointF[] { p };
Matrix invertMatrix = m.Clone();
//想要从旧空间到新空间的逆变换,所以我们需要对这个矩阵求逆
invertMatrix.Invert();
invertMatrix.TransformPoints(ps);
return ps[0];
}
/// <summary>
/// 将相对于图像的坐标转换为相对于控件坐标系
/// </summary>
/// <param name="p">图像中指定点的点位坐标,坐标原点为图像左上角</param>
/// <returns>该点以空间坐标系为基准的坐标值,坐标原点为空间坐左上角</returns>
public static PointF ToControlCoordinate(this PointF p, Matrix m)
{
PointF[] ps = new PointF[] { p };
m.TransformPoints(ps);
return ps[0];
}
public static float Distance(PointF p1, PointF p2)
{
return (float)Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2));
}
public static float DistanceToLine(PointF point, PointF start, PointF end)
{
float lineLengthSquared = DistanceSquared(start, end);
if (lineLengthSquared == 0)
{
return Distance(point, start); // 线段的两个端点重合
}
float t = ((point.X - start.X) * (end.X - start.X) + (point.Y - start.Y) * (end.Y - start.Y)) / lineLengthSquared;
t = Math.Clamp(t, 0, 1); // 限制 t 在 [0, 1] 范围内
PointF projection = new PointF(
start.X + t * (end.X - start.X),
start.Y + t * (end.Y - start.Y));
return Distance(point, projection);
}
public static float DistanceSquared(PointF p1, PointF p2)
{
return (float)(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2));
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Model
{
/// <summary>
/// 点击的区域
/// </summary>
internal enum ClickArea
{
/// <summary>
/// 未知区域
/// </summary>
AREA_UNKNOW,
/// <summary>
/// 图片区域
/// </summary>
AREA_IMG,
/// <summary>
/// 缺陷元素区域
/// </summary>
AREA_DEFECT,
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LabelSharp.Config
{
public static class CustomCursors
{
public static Cursor CURSOR_DEFAULT = Cursors.Arrow;
public static Cursor CURSOR_POINT = Cursors.Hand;
public static Cursor CURSOR_DRAW = Cursors.Cross;
public static Cursor CURSOR_MOVE = Cursors.Hand;
public static Cursor CURSOR_GRAB = Cursors.Hand;
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Model.Exception
{
internal class InvalidShapeException : System.Exception
{
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Shape
{
public abstract class BaseShape
{
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Shape
{
internal enum DoubleClickActionEnum
{
None,
Close,
}
}

View File

@ -0,0 +1,938 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using CanFly.Canvas.Helper;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Drawing;
namespace CanFly.Canvas.Shape
{
[Serializable]
public class FlyShape
{
private const float DFT_VTX_EPSILON = 4f;
private float _epsilon = DFT_VTX_EPSILON;
public float LineWidth { get; set; } = 2f;
#region Shape颜色
#region drawing
public Color line_color = Color.FromArgb(128, 0, 255, 0);
public Color fill_color = Color.FromArgb(64, 0, 0, 0);
public Color vertex_fill_color = Color.FromArgb(255, 0, 255, 0);
#endregion
#region selecting / hovering
public Color select_line_color = Color.FromArgb(255, 255, 255, 255);
public Color select_fill_color = Color.FromArgb(64, 0, 255, 0);
public Color hvertex_fill_color = Color.FromArgb(255, 255, 255, 255);
#endregion
#endregion
private PointTypeEnum point_type = PointTypeEnum.ROUND;
private float point_size = 8.0f;
private float _scale = 1.0f;
private float scale
{
get
{
return _scale;
}
set
{
_scale = value;
}
}
private ShapeTypeEnum _shape_type;
private Matrix _matrix = new Matrix();
public ShapeTypeEnum ShapeType
{
get => _shape_type;
set { _shape_type = value; }
}
public string label = "";
public int? group_id = null;
private List<PointF> _points
{
get;
set;
} = new List<PointF>();
public List<PointF> Points
{
get { return _points; }
set
{
this._points = value;
}
}
private List<PointF> _pointsRaw = new List<PointF>();
/// <summary>
/// 辅助节点
/// </summary>
public List<PointF> GuidePoints = new List<PointF>();
public float _currentRotateAngle;
private bool _isRotating = false;
public List<int> point_labels = new List<int>();
private ShapeTypeEnum _shape_type_raw;
/// <summary>
/// 是否填充多边形 使用select_fill_color 或 fill_color 填充
/// </summary>
public bool fill = false;
public bool Selected { get; set; } = false;
public object? flags;
public string description = "";
private List<object> other_data = new List<object>();
private int _highlightIndex = -1;
private HighlightModeEnum _highlightMode = HighlightModeEnum.NEAR_VERTEX;
private Dictionary<HighlightModeEnum, HighlightSetting> _highlightSettings = new Dictionary<HighlightModeEnum, HighlightSetting>()
{
{ HighlightModeEnum.NEAR_VERTEX,new HighlightSetting(4,PointTypeEnum.ROUND)},
{ HighlightModeEnum.MOVE_VERTEX,new HighlightSetting(1.5f,PointTypeEnum.SQUARE)},
};
private bool _closed = false;
private Color _vertex_fill_color;
/// <summary>
/// 当图形是Line时是否绘制辅助矩形框
/// </summary>
public bool IsDrawLineVirtualRect { get; set; } = false;
/// <summary>
/// 画Line时辅助矩形的宽度
/// </summary>
public float LineVirtualRectWidth = 40;
public PointF[] LineVirtualRectPoints = new PointF[4];
public FlyShape()
{
}
private PointF ScalePoint(PointF point)
{
return point;
//return new PointF(
// (float)(point.X * scale),
// (float)(point.Y * scale));
}
public void Close()
{
this._closed = true;
}
public void AddPoint(PointF point, int label = 1)
{
if (_points != null && _points.Count > 0 && point.Equals(_points.ElementAt(0)))
{
Close();
}
else
{
if (_points.Count > 0 && this[-1].Equals(point))
{
return;
}
_points.Add(point);
point_labels.Add(label);
}
}
public bool CanAddPoint()
{
return ShapeType == ShapeTypeEnum.Polygon
|| ShapeType == ShapeTypeEnum.LineStrip;
}
public PointF? PopPoint()
{
if (_points != null && _points.Count > 0)
{
if (point_labels != null && point_labels.Count > 0)
{
point_labels.RemoveAt(point_labels.Count - 1);
}
PointF lastPoint = _points[_points.Count - 1];
_points.RemoveAt(_points.Count - 1);
return lastPoint;
}
return null;
}
public void InsertPoint(int i, PointF point, int label = 1)
{
_points.Insert(i, point);
point_labels.Insert(i, label);
}
public void RemovePoint(int i)
{
if (!CanAddPoint())
{
return;
}
if (ShapeType == ShapeTypeEnum.Polygon && _points.Count <= 3)
{
return;
}
else if (ShapeType == ShapeTypeEnum.LineStrip && _points.Count <= 2)
{
return;
}
_points.RemoveAt(_points.Count - 1);
point_labels.RemoveAt(point_labels.Count - 1);
}
public bool IsClosed() => _closed;
public void SetOpen() { _closed = false; }
#region
/// <summary>
/// 矩形模式下,选中的点索引
/// </summary>
[JsonIgnore]
private int _rectSelectedVertex = -1;
[JsonIgnore]
private PointF _rectSelectedMoveVertex;
[JsonIgnore]
private PointF _rectCenterPoint;
[JsonIgnore]
private bool isVertexMoving;
/// <summary>
/// 正在移动节点
/// </summary>
[JsonIgnore]
public bool IsVertexMoving
{
get
{
return isVertexMoving;
}
internal set
{
//float centerX = (_points[0].X + _points[2].X) / 2f;
//float centerY = (_points[0].Y + _points[2].Y) / 2f;
//_rectCenterVertex = new PointF(centerX, centerY);
isVertexMoving = value;
}
}
//private PointF[] TransformPoints(List<PointF> points, PointF center, float angle)
//{
// PointF[] ptsArray = points.ToArray();
// using (Matrix matrix = new Matrix())
// {
// matrix.RotateAt(angle, center);
// matrix.TransformPoints(ptsArray);
// }
// return ptsArray;
//}
//GraphicsPath vrtx_path = new GraphicsPath();
#endregion
public void Paint(Graphics painter)
{
if (_points == null || _points.Count == 0)
{
return;
}
Color color = Selected ? select_line_color : line_color;
using Pen pen = new Pen(color, LineWidth);
// Create paths
GraphicsPath line_path = new GraphicsPath();
GraphicsPath vrtx_path = new GraphicsPath();
GraphicsPath guide_vrtx_path = new GraphicsPath();
switch (ShapeType)
{
//case ShapeTypeEnum.Rectangle:
// {
// if (_points.Count == 2)
// {
// float centerX = (_points[0].X + _points[1].X) / 2f;
// float centerY = (_points[0].Y + _points[1].Y) / 2f;
// _rectCenterPoint = new PointF(centerX, centerY);
// line_path.StartFigure();
// if (_points[1].X < _points[0].X)
// {
// _points[1] = new PointF(_points[0].X + LineWidth / 2f, _points[1].Y);
// }
// if (_points[1].Y < _points[0].Y)
// {
// _points[1] = new PointF(_points[1].X, _points[0].Y + LineWidth / 2f);
// }
// //float x = Math.Min(_points[0].X, _points[1].X);
// //float y = Math.Min(_points[0].Y, _points[1].Y);
// float w = Math.Abs(ScalePoint(_points[1]).X - ScalePoint(_points[0]).X);
// float h = Math.Abs(ScalePoint(_points[1]).Y - ScalePoint(_points[0]).Y);
// RectangleF drawRect = new(new PointF(_points[0].X, _points[0].Y), new SizeF(w, h));
// bool bRotated = false;
// NomalizeRotateAngle();
// Matrix oMatrix = null;
// if (_currentRotateAngle > 0)
// {
// // Create rotation matrix
// oMatrix = new Matrix();
// oMatrix.RotateAt(_currentRotateAngle, _rectCenterPoint, MatrixOrder.Append);
// painter.Transform = oMatrix;
// bRotated = true;
// }
// //Store rectangle region
// //Region _drawRectRegion = new Region(drawRect);
// if (oMatrix != null)
// line_path.Transform(oMatrix);
// line_path.AddRectangle(drawRect);
// // Reset transform
// if (bRotated)
// {
// bRotated = false;
// painter.ResetTransform();
// }
// //_matrix.Reset();
// //_matrix.RotateAt(_currentRotateAngle, new PointF(
// // (_points[0].X + _points[1].X) / 2,
// // (_points[0].Y + _points[1].Y) / 2));
// //line_path.Transform(_matrix);
// //line_path.AddPolygon(_pointsRaw.ToArray());
// }
// if (_regionVertex.Length != _points.Count)
// {
// _regionVertex = new Region[_points.Count];
// }
// for (int i = 0; i < _points.Count; i++)
// {
// DrawVertex(vrtx_path, i);
// }
// vrtx_path.Transform(_matrix);
// }
// break;
case ShapeTypeEnum.Rectangle:
{
if (_points.Count == 2)
{
float centerX = (_points[0].X + _points[1].X) / 2f;
float centerY = (_points[0].Y + _points[1].Y) / 2f;
_rectCenterPoint = new PointF(centerX, centerY);
line_path.StartFigure();
if (_points[1].X < _points[0].X)
{
_points[1] = new PointF(_points[0].X + LineWidth / 2f, _points[1].Y);
}
if (_points[1].Y < _points[0].Y)
{
_points[1] = new PointF(_points[1].X, _points[0].Y + LineWidth / 2f);
}
float w = Math.Abs(ScalePoint(_points[1]).X - ScalePoint(_points[0]).X);
float h = Math.Abs(ScalePoint(_points[1]).Y - ScalePoint(_points[0]).Y);
RectangleF drawRect = new(new PointF(_points[0].X, _points[0].Y), new SizeF(w, h));
line_path.AddRectangle(drawRect);
_matrix.Reset();
_matrix.RotateAt(_currentRotateAngle, _rectCenterPoint); // 使用更新后的旋转角度
line_path.Transform(_matrix);
}
if (_regionVertex.Length != _points.Count)
{
_regionVertex = new Region[_points.Count];
}
for (int i = 0; i < _points.Count; i++)
{
DrawVertex1(vrtx_path, i);
}
vrtx_path.Transform(_matrix);
}
break;
case ShapeTypeEnum.Circle:
{
if (_points.Count == 2)
{
float radius = PointHelper.Distance(ScalePoint(_points[0]), ScalePoint(_points[1]));
line_path.AddEllipse(
ScalePoint(_points[0]).X - radius,
ScalePoint(_points[0]).Y - radius,
radius * 2,
radius * 2);
}
for (int i = 0; i < _points.Count; i++)
{
DrawVertex(vrtx_path, i);
}
}
break;
case ShapeTypeEnum.LineStrip:
{
line_path.StartFigure();
line_path.AddLine(ScalePoint(_points[0]), ScalePoint(_points[0]));
for (int i = 0; i < _points.Count; i++)
{
PointF pt = _points[i];
line_path.AddLine(ScalePoint(pt), ScalePoint(pt));
DrawVertex(vrtx_path, i);
}
}
break;
case ShapeTypeEnum.Line:
{
// 添加框线到路径
var tmpPoints = _points.Select(p => ScalePoint(p)).ToList();
line_path.AddLines(tmpPoints.ToArray());
if (IsDrawLineVirtualRect && tmpPoints.Count == 2)
{
var center = new PointF((tmpPoints[0].X + tmpPoints[1].X) / 2,
(tmpPoints[0].Y + tmpPoints[1].Y) / 2);
// 计算两点之间的角度
float dx = tmpPoints[1].X - tmpPoints[0].X;
float dy = tmpPoints[1].Y - tmpPoints[0].Y;
float distance = PointHelper.Distance(tmpPoints[0], tmpPoints[1]);
double angle = Math.Atan2(dy, dx) * (180.0 / Math.PI); // 转换为度数
float l = center.X - distance / 2;
float t = center.Y - LineVirtualRectWidth / 2;
float r = center.X + distance / 2;
float b = center.Y + LineVirtualRectWidth / 2;
PointF ptLT = new PointF(l, t);
PointF ptRT = new PointF(r, t);
PointF ptRB = new PointF(r, b);
PointF ptLB = new PointF(l, b);
#if false
RectangleF rect = new RectangleF(ptLT, new SizeF(distance, LineVirtualRectWidth));
GraphicsPath rectPath = new GraphicsPath();
rectPath.AddRectangle(rect);
//// 设置矩阵以进行旋转和位移
Matrix matrix = new Matrix();
matrix.RotateAt((float)angle, center); // 旋转
// 应用变换
rectPath.Transform(matrix);
// 画框线
painter.DrawPath(pen, rectPath);
#else
RectangleF rect = new RectangleF(ptLT, new SizeF(distance, LineVirtualRectWidth));
LineVirtualRectPoints = new PointF[4] {
ptLT,ptRT,ptRB,ptLB
};
//// 设置矩阵以进行旋转和位移
Matrix matrix = new Matrix();
matrix.RotateAt((float)angle, center); // 旋转
matrix.TransformPoints(LineVirtualRectPoints);
GraphicsPath rectPath = new GraphicsPath();
rectPath.AddPolygon(LineVirtualRectPoints);
Pen rectpen = new Pen(Color.FromArgb(60, 0, 255, 0), 1);
// 画框线
painter.DrawPath(rectpen, rectPath);
#endif
}
// 添加节点到路径
for (int i = 0; i < _points.Count; i++)
{
DrawVertex(vrtx_path, i);
}
if (IsClosed())
{
line_path.AddLine(ScalePoint(_points[0]), ScalePoint(_points[0]));
}
}
break;
case ShapeTypeEnum.Polygon:
case ShapeTypeEnum.Point:
default:
{
// 添加多边形框线到路径
line_path.AddLines(_points.Select(p => ScalePoint(p)).ToArray());
// 添加节点到路径
for (int i = 0; i < _points.Count; i++)
{
DrawVertex(vrtx_path, i);
}
if (IsClosed())
{
line_path.AddLine(ScalePoint(_points[0]), ScalePoint(_points[0]));
}
}
break;
}
#region
// 画框线
painter.DrawPath(pen, line_path);
// 填充节点
if (vrtx_path.PointCount > 0)
{
painter.DrawPath(pen, vrtx_path);
painter.FillPath(new SolidBrush(vertex_fill_color), vrtx_path);
}
if (fill) // 是否填充多边形
{
Color fillColor = Selected ? select_fill_color : fill_color;
painter.FillPath(new SolidBrush(fillColor), line_path);
}
#endregion
}
private Region[] _regionVertex = new Region[] { };
private void DrawVertex1(GraphicsPath path, int i)
{
PointF pt = _points[i];
_regionVertex[i] = new Region(new RectangleF(
pt.X - _epsilon, pt.Y - _epsilon,
_epsilon * 2, _epsilon * 2));
// 将节点变换
PointF[] transformedPoint = new PointF[] { pt };
_matrix.TransformPoints(transformedPoint); // 变换节点位置
pt = transformedPoint[0]; // 获取变换后的节点位置
// 绘制节点
float d = point_size; // Point size
PointTypeEnum shape = point_type; // Point shape
PointF point = ScalePoint(pt);
if (i == _highlightIndex)
{
var setting = _highlightSettings[_highlightMode];
var size = setting.PointSize;
shape = setting.PointType;
d *= size; // Example for highlighting
}
if (_highlightIndex >= 0)
{
_vertex_fill_color = hvertex_fill_color;
}
else
{
_vertex_fill_color = vertex_fill_color;
}
switch (shape)
{
case PointTypeEnum.SQUARE:
path.AddRectangle(new RectangleF(point.X - d / 2, point.Y - d / 2, d, d));
break;
case PointTypeEnum.ROUND:
path.AddEllipse(point.X - d / 2, point.Y - d / 2, d, d);
break;
default:
throw new InvalidOperationException("Unsupported vertex shape");
}
}
private void DrawVertex(GraphicsPath path, int i)
{
PointF pt = _points[i];
float d = point_size; // Point size
PointTypeEnum shape = point_type; // Point shape
PointF point = ScalePoint(pt);
if (i == _highlightIndex)
{
var setting = _highlightSettings[_highlightMode];
var size = setting.PointSize;
shape = setting.PointType;
d *= size; // Example for highlighting
}
if (_highlightIndex >= 0)
{
_vertex_fill_color = hvertex_fill_color;
}
else
{
_vertex_fill_color = vertex_fill_color;
}
switch (shape)
{
case PointTypeEnum.SQUARE:
path.AddRectangle(new RectangleF(point.X - d / 2, point.Y - d / 2, d, d));
break;
case PointTypeEnum.ROUND:
path.AddEllipse(point.X - d / 2, point.Y - d / 2, d, d);
break;
default:
throw new InvalidOperationException("Unsupported vertex shape");
}
}
/// <summary>
/// 查找离鼠标最近且距离小于阈值的节点
/// </summary>
/// <param name="point">鼠标位置</param>
/// <param name="epsilon">阈值</param>
/// <returns>返回节点的索引</returns>
public int NearestVertex(PointF point, float epsilon = DFT_VTX_EPSILON)
{
switch (ShapeType)
{
case ShapeTypeEnum.Rectangle:
{
for (int i = 0; i < _regionVertex.Length; i++)
{
if (_regionVertex[i] == null)
{
break;
}
if (_regionVertex[i].IsVisible(point))
{
return i;
}
}
}
break;
default:
{
_epsilon = epsilon;
float min_distance = float.MaxValue;
int min_i = -1;
PointF scaledPoint = new PointF(point.X * scale, point.Y * scale);
for (int i = 0; i < _points.Count; i++)
{
// 缩放顶点
PointF scaledVertex = new PointF(_points[i].X * scale, _points[i].Y * scale);
float dist = PointHelper.Distance(scaledVertex, scaledPoint);
// 检查距离是否在 epsilon 范围内
if (dist <= epsilon && dist < min_distance)
{
min_distance = dist;
min_i = i;
}
}
return min_i;
}
}
return -1;
}
public int NearestEdge(PointF point, float epsilon)
{
float min_distance = float.MaxValue;
int post_i = -1;
PointF scaledPoint = new PointF(point.X * scale, point.Y * scale);
for (int i = 0; i < _points.Count; i++)
{
// 计算边的两个端点
PointF start = new PointF(this[i - 1].X * scale, this[i - 1].Y * scale);
PointF end = new PointF(this[i].X * scale, this[i].Y * scale);
// 计算到线段的距离
float dist = PointHelper.DistanceToLine(scaledPoint, start, end);
// 检查距离是否在 epsilon 范围内
if (dist <= epsilon && dist < min_distance)
{
min_distance = dist;
post_i = i;
}
}
return post_i;
}
public bool ContainsPoint(PointF point)
{
return MakePath().IsVisible(point);
}
private GraphicsPath MakePath()
{
GraphicsPath path = new GraphicsPath();
if (ShapeType == ShapeTypeEnum.Rectangle)
{
if (_points.Count == 2)
{
// 创建矩形路径
RectangleF rect = new RectangleF(
Math.Min(_points[0].X, _points[1].X),
Math.Min(_points[0].Y, _points[1].Y),
Math.Abs(_points[1].X - _points[0].X),
Math.Abs(_points[1].Y - _points[0].Y));
path.AddRectangle(rect);
}
}
else if (ShapeType == ShapeTypeEnum.Circle)
{
if (_points.Count == 2)
{
// 计算半径
float radius = PointHelper.Distance(_points[0], _points[1]);
path.AddEllipse(_points[0].X - radius, _points[0].Y - radius, radius * 2, radius * 2);
}
}
else
{
// 处理多边形
path.StartFigure();
path.AddLine(_points[0], _points[1]);
for (int i = 2; i < _points.Count; i++)
{
path.AddLine(_points[i - 1], _points[i]);
}
path.CloseFigure(); // 结束图形
}
return path;
}
public RectangleF BoundingRect()
{
return MakePath().GetBounds();
}
public void MoveBy(PointF offset)
{
for (int i = 0; i < _points.Count; i++)
{
_points[i] = new PointF(_points[i].X + offset.X, _points[i].Y + offset.Y);
}
}
/// <summary>
/// 移动特定顶点
/// </summary>
/// <param name="index"></param>
/// <param name="offset"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public void MoveVertexBy(int index, PointF offset)
{
if (index >= 0 && index < _points.Count)
{
_rectSelectedVertex = index;
_rectSelectedMoveVertex = new PointF(_points[index].X, _points[index].Y);
_points[index] = new PointF(_points[index].X + offset.X, _points[index].Y + offset.Y);
}
else
{
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
}
}
public void HighlightVertex(int i, HighlightModeEnum action)
{
this._highlightIndex = i;
this._highlightMode = action;
}
public void HighlightClear()
{
_highlightIndex = -1;
}
public FlyShape Copy()
{
var jsonStr = JsonConvert.SerializeObject(this);
FlyShape copyShp = JsonConvert.DeserializeObject<FlyShape>(jsonStr);
return copyShp;
}
public int Length => _points.Count();
public PointF this[int index]
{
get
{
if (index == -1)
{
return _points[_points.Count - 1];
}
return _points[index];
}
set
{
if (index == -1)
{
_points[_points.Count - 1] = value;
}
else
{
_points[index] = value;
}
}
}
private void NomalizeRotateAngle()
{
if (_currentRotateAngle >= 360)
{
_currentRotateAngle %= 360;
}
else if (_currentRotateAngle < 0)
{
_currentRotateAngle = 360 - (-_currentRotateAngle % 360);
}
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Shape
{
public enum PointTypeEnum
{
SQUARE = 0,
ROUND = 1,
}
public enum HighlightModeEnum
{
MOVE_VERTEX = 0,
NEAR_VERTEX = 1,
}
[Serializable]
public class HighlightSetting
{
public float PointSize { get; set; }
public PointTypeEnum PointType { get; set; }
public HighlightSetting(float pointSize, PointTypeEnum pointType)
{
this.PointSize = pointSize;
PointType = pointType;
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Canvas.Shape
{
public enum ShapeTypeEnum
{
Point,
Line,
Rectangle,
Circle,
Polygon,
LineStrip,
}
}

56
CanFly.Canvas/UI/FlyCanvas.Designer.cs generated Normal file
View File

@ -0,0 +1,56 @@
namespace CanFly.Canvas.UI
{
partial class FlyCanvas
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
///// <summary>
///// 清理所有正在使用的资源
///// </summary>
///// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
//protected override void Dispose(bool disposing)
//{
// if (disposing && (components != null))
// {
// components.Dispose();
// }
// base.Dispose(disposing);
//}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
SuspendLayout();
//
// Canvas
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Margin = new Padding(2);
Name = "Canvas";
Size = new Size(96, 106);
SizeChanged += Canvas_SizeChanged;
KeyDown += FlyCanvas_KeyDown;
MouseDoubleClick += FlyCanvas_MouseDoubleClick;
MouseDown += FlyCanvas_MouseDown;
MouseMove += FlyCanvas_OnMouseMove;
MouseUp += FlyCanvas_MouseUp;
MouseWheel += FlyCanvas_MouseWheel;
ResumeLayout(false);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
</root>

View File

@ -0,0 +1,676 @@
using HalconDotNet;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
namespace CanFly.Helper
{
public class HDevEngineTool : IDisposable
{
#region
// path of external procedures
readonly string ProcedurePath = Environment.CurrentDirectory + "\\Vision\\";
#endregion
#region
/// <summary>
/// 处理过程名
/// </summary>
public string ProcedureName;
/// <summary>
/// hdev程序启动引擎
/// </summary>
private readonly HDevEngine myEngine;
/// <summary>
/// 过程载入工具 .hdvp
/// </summary>
private HDevProcedureCall procedureCall;
/// <summary>
/// 程序运行是否成功
/// </summary>
public bool IsSuccessful { get; set; } = false;
/// <summary>
/// 控制参数字典
/// </summary>
public Dictionary<string, HTuple> InputTupleDic { get; set; }
/// <summary>
/// 图形参数字典
/// </summary>
public Dictionary<string, HObject> InputImageDic { get; set; }
#endregion
#region
/// <summary>
/// 实例化 默认搜索路径为: 启动路径//Vision//
/// </summary>
public HDevEngineTool()
{
ProcedureName = "";
myEngine = new HDevEngine();
myEngine.SetProcedurePath(ProcedurePath);
InputImageDic = new Dictionary<string, HObject>();
InputTupleDic = new Dictionary<string, HTuple>();
}
/// <summary>
/// 实例化
/// </summary>
/// <param name="path">外部函数搜索路径</param>
public HDevEngineTool(string path)
{
myEngine = new HDevEngine();
myEngine.SetProcedurePath(path);
InputImageDic = new Dictionary<string, HObject>();
InputTupleDic = new Dictionary<string, HTuple>();
}
#endregion
/// <summary>
/// 设置函数运行所需参数
/// </summary>
/// <param name="_tupleDictionary">控制参数</param>
/// <param name="_imageDictionary">图形参数</param>
public void SetDictionary(Dictionary<string, HTuple> _tupleDictionary, Dictionary<string, HObject> _imageDictionary)
{
InputTupleDic = _tupleDictionary;
InputImageDic = _imageDictionary;
}
/// <summary>
/// 载入过程 .hdvp
/// </summary>
/// <param name="procedureName">过程名</param>
public void LoadProcedure(string procedureName)
{
ProcedureName = procedureName;
try
{
HDevProcedure procedure = new HDevProcedure(procedureName);
procedureCall = new HDevProcedureCall(procedure);
}
catch (HDevEngineException Ex)
{
Trace.TraceInformation("HDevProgram {0} Load fail ,Error Line : {1}, Line number: {2}, Halcon error number : {3}", Ex.ProcedureName, Ex.LineText, Ex.LineNumber, Ex.HalconError);
return;
}
}
/// <summary>
/// 执行过程
/// </summary>
[HandleProcessCorruptedStateExceptions]
public bool RunProcedure(out string errorMsg, out int timeElasped)
{
//lock (_runLock)
{
errorMsg = "";
Stopwatch sw = new Stopwatch();
sw.Start();
try
{
foreach (KeyValuePair<string, HTuple> pair in InputTupleDic)
{
procedureCall.SetInputCtrlParamTuple(pair.Key, pair.Value);
}
foreach (KeyValuePair<string, HObject> pair in InputImageDic)
{
procedureCall.SetInputIconicParamObject(pair.Key, pair.Value);
}
procedureCall.Execute();
IsSuccessful = true;
}
catch (HDevEngineException ex)
{
IsSuccessful = false;
errorMsg = $"HDevProgram {ex.ProcedureName} Run fail , Line number: {ex.LineNumber}, Halcon error number : {ex.HalconError},ex:{ex.Message}";
}
finally
{
sw.Stop();
timeElasped = (int)sw.ElapsedMilliseconds;
}
return IsSuccessful;
}
}
object _runLock = new object();
/// <summary>
/// 执行过程
/// </summary>
public Tuple<bool, Dictionary<string, HTuple>, Dictionary<string, HObject>, string, int> RunProcedure(Dictionary<string, HTuple> inputHTupleDict, Dictionary<string, HObject> inputImgDict, List<string> outputHTuples = null, List<string> outputObjs = null)
{
lock (_runLock)
{
string errorMsg = "";
int timeElasped = 0;
bool result = false;
Dictionary<string, HTuple> outputHTupleDict = new Dictionary<string, HTuple>();
Dictionary<string, HObject> outputObjDict = new Dictionary<string, HObject>();
Stopwatch sw = new Stopwatch();
sw.Start();
try
{
if (inputHTupleDict != null && inputHTupleDict.Count > 0)
{
foreach (KeyValuePair<string, HTuple> pair in inputHTupleDict)
{
procedureCall.SetInputCtrlParamTuple(pair.Key, pair.Value);
}
}
if (InputImageDic != null && inputImgDict.Count > 0)
{
foreach (KeyValuePair<string, HObject> pair in inputImgDict)
{
procedureCall.SetInputIconicParamObject(pair.Key, pair.Value);
}
}
procedureCall.Execute();
result = true;
}
catch (HDevEngineException ex)
{
result = false;
errorMsg += $"HDevProgram {ex.ProcedureName} Run fail , Line number: {ex.LineNumber}, Halcon error number : {ex.HalconError},ex:{ex.Message}";
}
finally
{
sw.Stop();
timeElasped = (int)sw.ElapsedMilliseconds;
}
if (result)
{
if (outputHTuples != null && outputHTuples.Count > 0)
{
outputHTuples.ForEach(t =>
{
try
{
outputHTupleDict[t] = procedureCall.GetOutputCtrlParamTuple(t);
}
catch (Exception ex)
{
result = false;
errorMsg += $"\r\n获取{t}结果异常:{ex.Message}";
outputHTupleDict[t] = null;
}
});
}
if (outputObjs != null && outputObjs.Count > 0)
{
outputObjs.ForEach(t =>
{
try
{
outputObjDict[t] = procedureCall.GetOutputIconicParamObject(t);
}
catch (Exception ex)
{
result = false;
errorMsg += $"\r\n获取{t}结果异常:{ex.Message}";
outputObjDict[t] = null;
}
});
}
}
Tuple<bool, Dictionary<string, HTuple>, Dictionary<string, HObject>, string, int> ret = new Tuple<bool, Dictionary<string, HTuple>, Dictionary<string, HObject>, string, int>(result, outputHTupleDict, outputObjDict, errorMsg, timeElasped);
return ret;
}
}
public HTuple GetResultTuple(string key)
{
try
{
if (IsSuccessful)
{
return procedureCall.GetOutputCtrlParamTuple(key);
}
else
{
return new HTuple();
}
}
catch (Exception ex)
{
return new HTuple();
}
}
public HObject GetResultObject(string key, bool ignoreError = false)
{
try
{
if (ignoreError || IsSuccessful)
{
return procedureCall.GetOutputIconicParamObject(key);
}
else
{
return new HObject();
}
}
catch (Exception ex)
{
return new HObject();
}
}
public void Dispose()
{
procedureCall?.Dispose();
myEngine?.Dispose();
}
}
public static class HalconHelper
{
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
public static HImage Convert8GrayBitmapToHImage(this Bitmap bmp)
{
HImage himage = new HImage();
try
{
//判断输入图像不为null
if (bmp == null)
{
return null;
}
{
//重绘himage
//HImage curImage = new HImage();
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
himage.GenImage1("byte", bmp.Width, bmp.Height, bmpData.Scan0);
bmp.UnlockBits(bmpData);
//himage = curImage;
}
return himage;
}
catch (Exception e)
{
return null;
}
}
public static Bitmap ConvertHImageToBitmap(this HObject hImage)
{
HOperatorSet.CountChannels(hImage, out HTuple chanels);
if (chanels.I == 1)
{
return hImage.ConvertHImageTo8GrayBitmap();
}
else
{
return hImage.ConvertHImageToRGBBitmap();
//return hImage.HObject2BitmapRGB();
}
}
public static Bitmap HObject2BitmapRGB(this HObject hObject)
{
////获取图像尺寸
HTuple width0, height0, type, width, height;
//获取图像尺寸
HOperatorSet.GetImageSize(hObject, out width0, out height0);
// 创建交错格式图像
HOperatorSet.InterleaveChannels(hObject, out HObject InterImage, "argb", "match", 255); //"rgb", 4 * width0, 0 "argb", "match", 255
//获取交错格式图像指针
HOperatorSet.GetImagePointer1(InterImage, out HTuple Pointer, out type, out width, out height);
IntPtr ptr = Pointer;
//构建新Bitmap图像
Bitmap res32 = new Bitmap(width / 4, height, width, PixelFormat.Format32bppArgb, ptr); // Format32bppArgb Format24bppRgb
//32位Bitmap转24位
var res24 = new Bitmap(res32.Width, res32.Height, PixelFormat.Format24bppRgb);
Graphics graphics = Graphics.FromImage(res24);
graphics.DrawImage(res32, new Rectangle(0, 0, res32.Width, res32.Height));
return res24;
}
public static Bitmap ConvertHImageTo8GrayBitmap(this HObject hImage)
{
try
{
HTuple type, width, height, pointer;
HOperatorSet.GetImagePointer1(hImage, out pointer, out type, out width, out height);
Bitmap bmp = new Bitmap(width.I, height.I, PixelFormat.Format8bppIndexed);
ColorPalette pal = bmp.Palette;
for (int i = 0; i <= 255; i++)
{
pal.Entries[i] = Color.FromArgb(255, i, i, i);
}
bmp.Palette = pal;
BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
if (width % 4 == 0)
{
CopyMemory(bitmapData.Scan0, (IntPtr)pointer.D, (uint)(bitmapData.Stride * height.I));
}
else
{
Parallel.For(0, height.I, h =>
{
CopyMemory(bitmapData.Scan0 + h * bitmapData.Stride, (IntPtr)(pointer.D + h * width.I), (uint)width.I);
});
}
bmp.UnlockBits(bitmapData);
return bmp;
}
catch (Exception ex)
{
return null;
}
}
public static Bitmap ConvertHImageToRGBBitmap(this HObject hImage)
{
try
{
HOperatorSet.GetImagePointer3(hImage, out HTuple pointRed, out HTuple pointGreen, out HTuple pointBlue, out HTuple type, out HTuple width, out HTuple height);
Bitmap image = new Bitmap(width.I, height.I, PixelFormat.Format24bppRgb);
BitmapData imageData = image.LockBits(new Rectangle(0, 0, width.I, height.I), ImageLockMode.ReadWrite, image.PixelFormat);
IntPtr pR = (IntPtr)pointRed.D;
IntPtr pG = (IntPtr)pointGreen.D;
IntPtr pB = (IntPtr)pointBlue.D;
Parallel.For(0, imageData.Height, h =>
{
Parallel.For(0, imageData.Width, w =>
{
int dest = h * imageData.Stride + w * 3;
int source = h * imageData.Width + w;
Marshal.WriteByte(imageData.Scan0, dest, Marshal.ReadByte(pB, source));
Marshal.WriteByte(imageData.Scan0, dest + 1, Marshal.ReadByte(pG, source));
Marshal.WriteByte(imageData.Scan0, dest + 2, Marshal.ReadByte(pR, source));
});
});
image.UnlockBits(imageData);
return image;
}
catch (Exception exc)
{
return null;
}
}
public static Bitmap ConvertHImageTo16GrayBitmap(this HImage originHImage)
{
//IntPtr pointer = hImage.GetImagePointer1(out string type, out int width, out int height);
//int widthIn4 = (int)Math.Ceiling(width / 4.0) * 4;
////Bitmap bmp = new Bitmap(widthIn4, height, PixelFormat.Format48bppRgb);
//Bitmap showImage = new Bitmap(widthIn4, height, PixelFormat.Format48bppRgb);
//Rectangle rect = new Rectangle(0, 0, widthIn4, height);
////BitmapData bitmapData = bmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format48bppRgb);
//BitmapData showImageData = showImage.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format48bppRgb);
//unsafe
//{
// byte* data = (byte*)pointer;
// //byte* bitmapBuffer = (byte*)bitmapData.Scan0;
// byte* showBitmapBuffer = (byte*)showImageData.Scan0;
// Parallel.For(0, width * height, i =>
// {
// int index = (i + 1) % width + widthIn4 * ((int)Math.Floor((double)(i + 1) / width)) - 1;
// //showBitmapBuffer[index * 6] = bitmapBuffer[index * 6] = data[i * 2];
// //showBitmapBuffer[index * 6 + 1] = bitmapBuffer[index * 6 + 1] = data[i * 2 + 1];
// showBitmapBuffer[index * 6] = data[i * 2];
// showBitmapBuffer[index * 6 + 1] = data[i * 2 + 1];
// });
//}
////bmp.UnlockBits(bitmapData);
//showImage.UnlockBits(showImageData);
//return showImage;
// dev_set_draw('margin')
//read_image(Image, '0.tif')
HImage hImage = originHImage.Clone();
//* 如果16位图像非常暗的话建议在这一步进行提亮因为后面8位图像大幅度提亮易造成色阶断裂出现不连续的像素块
// * scale_image(Image, Image, 25, 0)
//hImage = hImage.ScaleImage(25.0, 0.0);
//get_domain(Image, rectangle)
//* 获取全图中像素灰度值的最大和最小值
//min_max_gray(rectangle, Image, 0, Min, Max, range)
hImage.MinMaxGray(hImage.GetDomain(), 0, out double min, out double max, out double range);
//* 将16位图的灰度值映射到0 - 255上
double mult = 255.0 / (max - min);
double add = -mult * min;
hImage = hImage.ScaleImage(mult, add);
//* 转换为'byte'类型
//convert_image_type(Image_scaled, ImageConverted, 'byte')
hImage = hImage.ConvertImageType("byte");
Bitmap showImage = hImage.ConvertHImageTo8GrayBitmap();
hImage.Dispose();
return showImage;
//* 如果转换以后图像整体对比度太低的话可以提高对比度这里是对8位图像处理
//Min:= 20
//Max:= 160
//Mult:= 255.0 / (Max - Min)
//Add:= -Mult * Min
//scale_image(ImageConverted, ImageConverted_scaled, Mult, Add)
}
public static List<double> HTupleToDouble(this HTuple tuple)
{
List<double> list = new List<double>();
for (int i = 0; i < tuple.Length; i++)
{
list.Add(tuple[i].D);
}
return list;
}
public static HImage ConvertHObjectToHImage(this HObject obj)
{
HOperatorSet.CountChannels(obj, out HTuple channels);
HImage img = new HImage();
if (channels.I == 1)
{
HTuple pointer, type, width, height;
HOperatorSet.GetImagePointer1(obj, out pointer, out type, out width, out height);
img.GenImage1(type, width, height, pointer);
}
else
{
HTuple pRed, pGreen, pBlue, type, width, height;
HOperatorSet.GetImagePointer3(obj, out pRed, out pGreen, out pBlue, out type, out width, out height);
img.GenImage3(type, width, height, pRed, pGreen, pBlue);
}
return img;
}
#region
public static Bitmap ConvertGrayImageToPesudoColorfulImage(this HImage hImage, double max = 0, double min = 0, double zoom = 1, bool isShowHeightTip = false, int zResolution = 100000)
{
hImage.GetImageSize(out int width, out int height);
hImage.MinMaxGray(new HRegion(0.0, 0.0, width, height), 3, out HTuple roiMin, out HTuple roiMax, out _);
if (max == 0)
{
max = roiMax;
}
if (min == 0)
{
min = roiMin;
}
double mult = 235 / (zoom * (max - min));
double add = (0 - mult) * min * zoom + 10;
HOperatorSet.ScaleImage(hImage, out HObject imageScaled, mult, add);
HOperatorSet.ConvertImageType(imageScaled, out imageScaled, "byte");
Stopwatch sw = new Stopwatch();
sw.Start();
HOperatorSet.GetImagePointer1(imageScaled, out HTuple pointer, out HTuple type, out _, out _);
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
unsafe
{
byte* data = (byte*)(IntPtr)pointer;
byte* bitmapDataBuff = (byte*)bitmapData.Scan0;
if (width % 4 != 0)
{
Parallel.For(0, height, h =>
{
Parallel.For(0, width, w =>
{
byte gray = data[h * width + w];
byte[] convertBytes = ConvertByteToColorfulArray(gray);
Marshal.Copy(convertBytes, 0, (IntPtr)(bitmapDataBuff + h * bitmapData.Stride + w * 3), 3);
});
});
}
else
{
Parallel.For(0, width * height, i =>
{
byte gray = data[i];
byte[] convertBytes = ConvertByteToColorfulArray(gray);
Marshal.Copy(convertBytes, 0, (IntPtr)(bitmapDataBuff + i * 3), 3);
});
}
}
bitmap.UnlockBits(bitmapData);
if (isShowHeightTip)
{
List<byte> lableList = new List<byte>() { 5, 30, 60, 90, 120, 150, 180, 210, 240, 255 };
Dictionary<double, Color> lableColorDict = lableList.ToDictionary(
u => (u - add) / (mult * zResolution),
u =>
{
byte[] colorBytes = ConvertByteToColorfulArray(u);
return Color.FromArgb(colorBytes[2], colorBytes[1], colorBytes[0]);
});
using (Graphics g = Graphics.FromImage(bitmap))
{
int rectHeight = (int)(bitmap.Height / (5.0 * lableColorDict.Count));
Font font = new Font("宋体", (int)(rectHeight * 0.75), GraphicsUnit.Pixel);
string lable = lableColorDict.ElementAt(0).Key.ToString("f3");
SizeF lableSize = g.MeasureString(lable, font);
int rectWidth = (int)(lableSize.Width * 1.5);
int startX = 0;
int startY = 0;
foreach (KeyValuePair<double, Color> pair in lableColorDict)
{
g.FillRectangle(new SolidBrush(pair.Value), startX, startY, rectWidth, rectHeight);
g.DrawString(pair.Key.ToString("f3"), font, new SolidBrush(Color.White), (float)(startX + (rectWidth - lableSize.Width) / 2.0), (float)(startY + (rectHeight - lableSize.Height) / 2.0));
startY += rectHeight;
}
}
}
sw.Stop();
//LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"转换耗时{sw.ElapsedMilliseconds}ms");
return bitmap;
}
private static byte[] ConvertByteToColorfulArray(byte gray)
{
byte[] bytes = new byte[3];
if (gray == 0)
{
bytes[2] = 255;
bytes[1] = 255;
bytes[0] = 255;
}
if (gray > 0 && gray <= 63)
{
bytes[2] = 0;
bytes[+1] = (byte)(254 - 4 * gray);
bytes[0] = 255;
}
if (gray >= 64 && gray <= 127)
{
bytes[2] = 0;
bytes[1] = (byte)(4 * gray - 254);
bytes[0] = (byte)(510 - 4 * gray);
}
if (gray >= 128 && gray <= 191)
{
bytes[2] = (byte)(4 * gray - 510);
bytes[1] = 255;
bytes[0] = 0;
}
if (gray >= 192 && gray <= 255)
{
bytes[2] = 255;
bytes[1] = (byte)(1022 - 4 * gray);
bytes[0] = 0;
}
return bytes;
}
#endregion
}
}

17
CanFly/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace CanFly
{
//internal static class Program
//{
// /// <summary>
// /// The main entry point for the application.
// /// </summary>
// [STAThread]
// static void Main()
// {
// // To customize application configuration such as set high DPI settings or default font,
// // see https://aka.ms/applicationconfiguration.
// ApplicationConfiguration.Initialize();
// Application.Run(new FrmMain2());
// }
//}
}

73
CanFly/Properties/Resources.Designer.cs generated Normal file
View File

@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失
// </auto-generated>
//------------------------------------------------------------------------------
namespace XKRS.CanFly.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XKRS.CanFly.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary>
internal static System.Drawing.Bitmap Close {
get {
object obj = ResourceManager.GetObject("Close", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Close" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

BIN
CanFly/Resources/Close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 836 B

BIN
CanFly/Resources/circle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

117
CanFly/UI/BaseFrmGuide.Designer.cs generated Normal file
View File

@ -0,0 +1,117 @@
namespace CanFly.UI
{
partial class BaseFrmGuide
{
/// <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()
{
flowLayoutPanel = new FlowLayoutPanel();
pbLogo = new PictureBox();
lblTitle = new Label();
flowPanelContent = new FlowLayoutPanel();
panelMain = new Panel();
flowLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pbLogo).BeginInit();
panelMain.SuspendLayout();
SuspendLayout();
//
// flowLayoutPanel
//
flowLayoutPanel.Controls.Add(pbLogo);
flowLayoutPanel.Controls.Add(lblTitle);
flowLayoutPanel.Dock = DockStyle.Top;
flowLayoutPanel.Location = new Point(0, 0);
flowLayoutPanel.Name = "flowLayoutPanel1";
flowLayoutPanel.Size = new Size(692, 36);
flowLayoutPanel.TabIndex = 0;
//
// pbLogo
//
pbLogo.Location = new Point(3, 3);
pbLogo.Name = "pbLogo";
pbLogo.Size = new Size(30, 30);
pbLogo.SizeMode = PictureBoxSizeMode.StretchImage;
pbLogo.TabIndex = 0;
pbLogo.TabStop = false;
pbLogo.Visible = false;
//
// lblTitle
//
lblTitle.AutoSize = true;
lblTitle.Dock = DockStyle.Fill;
lblTitle.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Bold, GraphicsUnit.Point);
lblTitle.Location = new Point(39, 0);
lblTitle.Name = "lblTitle";
lblTitle.Size = new Size(20, 36);
lblTitle.TabIndex = 1;
lblTitle.Text = " ";
lblTitle.TextAlign = ContentAlignment.MiddleLeft;
//
// flowPanelContent
//
flowPanelContent.Dock = DockStyle.Fill;
flowPanelContent.Location = new Point(0, 0);
flowPanelContent.Name = "flowPanelContent";
flowPanelContent.Size = new Size(692, 511);
flowPanelContent.TabIndex = 1;
//
// panelMain
//
panelMain.AutoScroll = true;
panelMain.Controls.Add(flowPanelContent);
panelMain.Dock = DockStyle.Fill;
panelMain.Location = new Point(0, 36);
panelMain.Name = "panelMain";
panelMain.Size = new Size(692, 511);
panelMain.TabIndex = 2;
//
// BaseFrmGuide
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(692, 547);
Controls.Add(panelMain);
Controls.Add(flowLayoutPanel);
FormBorderStyle = FormBorderStyle.None;
Name = "BaseFrmGuide";
Text = "BaseFrmGuide";
Load += BaseFrmGuide_Load;
flowLayoutPanel.ResumeLayout(false);
flowLayoutPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)pbLogo).EndInit();
panelMain.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private FlowLayoutPanel flowLayoutPanel;
private PictureBox pbLogo;
private Label lblTitle;
protected FlowLayoutPanel flowPanelContent;
private Panel panelMain;
}
}

53
CanFly/UI/BaseFrmGuide.cs Normal file
View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CanFly.UI
{
public partial class BaseFrmGuide : Form
{
public BaseFrmGuide()
{
InitializeComponent();
// 处理 Panel 的大小变化事件,以动态更新控件宽度
panelMain.SizeChanged += PanelMain_SizeChanged; ;
}
private void PanelMain_SizeChanged(object? sender, EventArgs e)
{
foreach (Control control in flowPanelContent.Controls)
{
control.Width = panelMain.Width - 6; // 根据 Panel 的宽度调整控件
}
}
public void SetTitle(string title)
{
this.lblTitle.Text = title;
}
public void SetLogo(Image logo)
{
this.pbLogo.BackgroundImage = logo;
this.pbLogo.SizeMode = PictureBoxSizeMode.StretchImage;
this.pbLogo.Refresh();
}
private void BaseFrmGuide_Load(object sender, EventArgs e)
{
}
}
}

120
CanFly/UI/BaseFrmGuide.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
</root>

279
CanFly/UI/FrmMain.Designer.cs generated Normal file
View File

@ -0,0 +1,279 @@

namespace CanFly
{
partial class FrmMain
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
panel1 = new Panel();
canvas = new Canvas.UI.FlyCanvas();
statusStrip1 = new StatusStrip();
lblStatus = new ToolStripStatusLabel();
flowLayoutPanel1 = new FlowLayoutPanel();
btnLoadImage = new Button();
btnCreateCircle = new Button();
btnCreateRect = new Button();
btnStopDraw = new Button();
btnTestOutsideDraw = new Button();
btnTestClearDraw = new Button();
btnTestCircleMeasure = new Button();
btnTest = new Button();
splitContainer = new SplitContainer();
panelGuide = new Panel();
btnRotateTest = new Button();
panel1.SuspendLayout();
statusStrip1.SuspendLayout();
flowLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
SuspendLayout();
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(canvas);
panel1.Controls.Add(statusStrip1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(947, 791);
panel1.TabIndex = 1;
//
// canvas
//
canvas.AllowMultiSelect = false;
canvas.CreateMode = Canvas.Shape.ShapeTypeEnum.Polygon;
canvas.Dock = DockStyle.Fill;
canvas.Enabled = false;
canvas.FillDrawing = false;
canvas.Location = new Point(0, 0);
canvas.Margin = new Padding(2);
canvas.Name = "canvas";
canvas.OutsideShapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.OutsideShapes");
canvas.Scale = 1F;
canvas.Shapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.Shapes");
canvas.Size = new Size(945, 767);
canvas.TabIndex = 2;
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { lblStatus });
statusStrip1.Location = new Point(0, 767);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(945, 22);
statusStrip1.TabIndex = 1;
statusStrip1.Text = "statusStrip1";
//
// lblStatus
//
lblStatus.Name = "lblStatus";
lblStatus.Size = new Size(44, 17);
lblStatus.Text = " ";
//
// flowLayoutPanel1
//
flowLayoutPanel1.BorderStyle = BorderStyle.FixedSingle;
flowLayoutPanel1.Controls.Add(btnLoadImage);
flowLayoutPanel1.Controls.Add(btnCreateCircle);
flowLayoutPanel1.Controls.Add(btnCreateRect);
flowLayoutPanel1.Controls.Add(btnStopDraw);
flowLayoutPanel1.Controls.Add(btnTestOutsideDraw);
flowLayoutPanel1.Controls.Add(btnTestClearDraw);
flowLayoutPanel1.Controls.Add(btnTestCircleMeasure);
flowLayoutPanel1.Controls.Add(btnTest);
flowLayoutPanel1.Controls.Add(btnRotateTest);
flowLayoutPanel1.Dock = DockStyle.Top;
flowLayoutPanel1.Location = new Point(0, 0);
flowLayoutPanel1.Name = "flowLayoutPanel1";
flowLayoutPanel1.Size = new Size(1185, 40);
flowLayoutPanel1.TabIndex = 2;
//
// btnLoadImage
//
btnLoadImage.Location = new Point(3, 3);
btnLoadImage.Name = "btnLoadImage";
btnLoadImage.Size = new Size(75, 30);
btnLoadImage.TabIndex = 0;
btnLoadImage.Text = "加载图像";
btnLoadImage.UseVisualStyleBackColor = true;
btnLoadImage.Click += btnLoadImage_Click;
//
// btnCreateCircle
//
btnCreateCircle.Enabled = false;
btnCreateCircle.Location = new Point(84, 3);
btnCreateCircle.Name = "btnCreateCircle";
btnCreateCircle.Size = new Size(75, 30);
btnCreateCircle.TabIndex = 1;
btnCreateCircle.Text = "绘制圆形";
btnCreateCircle.UseVisualStyleBackColor = true;
btnCreateCircle.Click += btnCreateCircle_Click;
//
// btnCreateRect
//
btnCreateRect.Location = new Point(165, 3);
btnCreateRect.Name = "btnCreateRect";
btnCreateRect.Size = new Size(75, 30);
btnCreateRect.TabIndex = 6;
btnCreateRect.Text = "绘制矩形";
btnCreateRect.UseVisualStyleBackColor = true;
btnCreateRect.Click += btnCreateRect_Click;
//
// btnStopDraw
//
btnStopDraw.Enabled = false;
btnStopDraw.Location = new Point(246, 3);
btnStopDraw.Name = "btnStopDraw";
btnStopDraw.Size = new Size(75, 30);
btnStopDraw.TabIndex = 2;
btnStopDraw.Text = "停止绘制";
btnStopDraw.UseVisualStyleBackColor = true;
btnStopDraw.Click += btnStopDraw_Click;
//
// btnTestOutsideDraw
//
btnTestOutsideDraw.Location = new Point(327, 3);
btnTestOutsideDraw.Name = "btnTestOutsideDraw";
btnTestOutsideDraw.Size = new Size(75, 30);
btnTestOutsideDraw.TabIndex = 3;
btnTestOutsideDraw.Text = "测试绘图";
btnTestOutsideDraw.UseVisualStyleBackColor = true;
btnTestOutsideDraw.Click += btnTestOutsideDraw_Click;
//
// btnTestClearDraw
//
btnTestClearDraw.Location = new Point(408, 3);
btnTestClearDraw.Name = "btnTestClearDraw";
btnTestClearDraw.Size = new Size(75, 30);
btnTestClearDraw.TabIndex = 4;
btnTestClearDraw.Text = "清除绘图";
btnTestClearDraw.UseVisualStyleBackColor = true;
btnTestClearDraw.Click += btnTestClearDraw_Click;
//
// btnTestCircleMeasure
//
btnTestCircleMeasure.Location = new Point(489, 3);
btnTestCircleMeasure.Name = "btnTestCircleMeasure";
btnTestCircleMeasure.Size = new Size(89, 30);
btnTestCircleMeasure.TabIndex = 5;
btnTestCircleMeasure.Text = "测试圆形算法";
btnTestCircleMeasure.UseVisualStyleBackColor = true;
btnTestCircleMeasure.Click += btnTestCircleMeasure_Click;
//
// btnTest
//
btnTest.Location = new Point(584, 3);
btnTest.Name = "btnTest";
btnTest.Size = new Size(89, 30);
btnTest.TabIndex = 7;
btnTest.Text = "测试";
btnTest.UseVisualStyleBackColor = true;
btnTest.Click += btnTest_Click;
//
// splitContainer
//
splitContainer.Dock = DockStyle.Fill;
splitContainer.Location = new Point(0, 40);
splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
splitContainer.Panel1.Controls.Add(panelGuide);
splitContainer.Panel1MinSize = 150;
//
// splitContainer.Panel2
//
splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = new Size(1185, 791);
splitContainer.SplitterDistance = 234;
splitContainer.TabIndex = 3;
//
// panelGuide
//
panelGuide.BorderStyle = BorderStyle.FixedSingle;
panelGuide.Dock = DockStyle.Fill;
panelGuide.Location = new Point(0, 0);
panelGuide.Name = "panelGuide";
panelGuide.Size = new Size(234, 791);
panelGuide.TabIndex = 0;
//
// btnRotateTest
//
btnRotateTest.Location = new Point(679, 3);
btnRotateTest.Name = "btnRotateTest";
btnRotateTest.Size = new Size(89, 30);
btnRotateTest.TabIndex = 8;
btnRotateTest.Text = "测试旋转";
btnRotateTest.UseVisualStyleBackColor = true;
btnRotateTest.Click += btnRotateTest_Click;
//
// FrmMain
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1185, 831);
Controls.Add(splitContainer);
Controls.Add(flowLayoutPanel1);
Name = "FrmMain";
Text = "Form1";
WindowState = FormWindowState.Maximized;
Load += FrmMain_Load;
panel1.ResumeLayout(false);
panel1.PerformLayout();
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
flowLayoutPanel1.ResumeLayout(false);
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer).EndInit();
splitContainer.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private Panel panel1;
private FlowLayoutPanel flowLayoutPanel1;
private SplitContainer splitContainer;
private Panel panelGuide;
private Button btnLoadImage;
private Button btnCreateCircle;
private Button btnStopDraw;
private StatusStrip statusStrip1;
private Canvas.UI.FlyCanvas canvas;
private ToolStripStatusLabel lblStatus;
private Button btnTestOutsideDraw;
private Button btnTestClearDraw;
private Button btnTestCircleMeasure;
private Button btnCreateRect;
private Button btnTest;
private Button btnRotateTest;
}
}

345
CanFly/UI/FrmMain.cs Normal file
View File

@ -0,0 +1,345 @@
using CanFly.Canvas.Shape;
using CanFly.Helper;
using CanFly.UI;
using CanFly.UI.GuidePanel;
using CanFly.Util;
using HalconDotNet;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace CanFly
{
public partial class FrmMain : Form
{
private string _currentImageFile = "";
private System.Windows.Forms.Timer _statusTimer = new System.Windows.Forms.Timer();
private BaseGuideControl? _currentGuideCtrl;
public FrmMain()
{
InitializeComponent();
this.canvas.mouseMoved += Canvas_mouseMoved;
this.canvas.OnShapeUpdateEvent += Canvas_OnShapeUpdateEvent;
this.canvas.selectionChanged += Canvas_selectionChanged;
this.canvas.OnShapeMoving += Canvas_OnShapeMoving;
}
private void FrmMain_Load(object sender, EventArgs e)
{
_currentImageFile = @"C:\Users\DEV\Desktop\<5C><>˿\Cam7_130252457.jpg";
Bitmap bitmap = (Bitmap)Image.FromFile(_currentImageFile);
this.canvas.LoadPixmap(bitmap);
this.btnCreateCircle.Enabled = true;
this.canvas.Enabled = true;
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = <><CDBC><EFBFBD>ļ<EFBFBD>|*.jpg;*.png";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
_currentImageFile = ofd.FileName;
//this.canvasMain.LoadImageFile(_currentImageFile);
Bitmap bitmap = (Bitmap)Image.FromFile(_currentImageFile);
this.canvas.LoadPixmap(bitmap);
this.btnCreateCircle.Enabled = true;
}
}
private void btnCreateCircle_Click(object sender, EventArgs e)
{
//FrmGuideCircle frmGuideCircle = new FrmGuideCircle();
//panelGuide.ShowForm(frmGuideCircle);
SwitchGuideForm(ShapeTypeEnum.Circle);
this.canvas.StartDraw(ShapeTypeEnum.Circle);
this.btnCreateCircle.Enabled = false;
this.btnStopDraw.Enabled = true;
this.canvas.Enabled = true;
}
private void btnCreateRect_Click(object sender, EventArgs e)
{
this.canvas.StartDraw(ShapeTypeEnum.Rectangle);
this.btnCreateCircle.Enabled = false;
this.btnStopDraw.Enabled = true;
this.canvas.Enabled = true;
}
private void btnStopDraw_Click(object sender, EventArgs e)
{
//panelGuide.Controls.Clear();
StopDrawMode();
}
private void StartDrawMode()
{
}
private void StopDrawMode()
{
this.canvas.StopDraw();
this.btnStopDraw.Enabled = false;
this.btnCreateCircle.Enabled = true;
}
private void Status(string message, int delay = 5000)
{
_statusTimer.Stop();
// <20><>ʾ<EFBFBD><CABE>Ϣ
lblStatus.Text = message;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
_statusTimer.Interval = delay; // <20><><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><CAB1>
_statusTimer.Tick += (sender, e) =>
{
_statusTimer.Stop(); // ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1>
lblStatus.Text = string.Empty; // <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>Ϣ
};
_statusTimer.Start(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
}
private void Canvas_mouseMoved(PointF pos)
{
if (InvokeRequired)
{
Invoke(Canvas_mouseMoved, pos);
return;
}
lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
// panelGuide.Controls.Clear();
return;
}
//SwitchGuideForm(shapes[0].ShapeType);
Canvas_OnShapeUpdateEvent(shapes[0]);
}
private void SwitchGuideForm(ShapeTypeEnum shapeType)
{
if (_currentGuideCtrl == null)
{
switch (shapeType)
{
case ShapeTypeEnum.Point:
break;
case ShapeTypeEnum.Line:
break;
case ShapeTypeEnum.Rectangle:
break;
case ShapeTypeEnum.Circle:
_currentGuideCtrl = new GuideCircleCtrl();
_currentGuideCtrl.CurrentImageFile = _currentImageFile;
_currentGuideCtrl.OnControlCloseEvent += () =>
{
panelGuide.Controls.Clear();
StopDrawMode();
};
break;
case ShapeTypeEnum.Polygon:
break;
case ShapeTypeEnum.LineStrip:
break;
default:
break;
}
}
//_currentGuideCtrl?.AddToPanel(panelGuide);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
panelGuide.Controls.Clear();
return;
}
// _currentGuideCtrl?.UpdateShape(shapes[0]);
}
private void Canvas_OnShapeUpdateEvent(FlyShape shape)
{
switch (shape.ShapeType)
{
case ShapeTypeEnum.Point:
break;
case ShapeTypeEnum.Line:
break;
case ShapeTypeEnum.Rectangle:
break;
case ShapeTypeEnum.Circle:
{
//_currentGuideCtrl?.UpdateShape(shape);
}
break;
case ShapeTypeEnum.Polygon:
break;
case ShapeTypeEnum.LineStrip:
break;
default:
break;
}
}
private void btnTestOutsideDraw_Click(object sender, EventArgs e)
{
Random random = new Random((int)DateTime.Now.Ticks);
for (int i = 0; i < 10; i++)
{
// this.canvas.DrawCircle(new PointF(500, 500), 100);
int x = random.Next() % 500;
int y = random.Next() % 500;
int r = random.Next() % 200;
Debug.WriteLine($"X:{x}\tY:{y}\tR:{r}");
this.canvas.DrawCircle(new PointF(x, y), r);
}
}
private void btnTestClearDraw_Click(object sender, EventArgs e)
{
this.canvas.ClearDraw();
}
private async void btnTestCircleMeasure_Click(object sender, EventArgs e)
{
//string dir = Path.Combine(Environment.CurrentDirectory, "hscripts");
//string file = "CircleMeasure.hdvp";
//string filePath = Path.Combine(dir, file);
//if (!File.Exists(filePath))
//{
// MessageBox.Show($"<22>ļ<EFBFBD> {filePath} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
// return;
//}
//HObject? hImage = null;
//try
//{
// HDevEngineTool tool = new HDevEngineTool(dir);
// tool.LoadProcedure(Path.GetFileNameWithoutExtension(file));
// // string imageFile = Path.Combine(Environment.CurrentDirectory, "hscripts", "image.png");
// HOperatorSet.ReadImage(out hImage, _currentImageFile);
// tool.InputImageDic["INPUT_Image"] = hImage;
// tool.InputTupleDic["XCenter"] = 981.625;
// tool.InputTupleDic["YCenter"] = 931.823;
// tool.InputTupleDic["Radius"] = 900.141;
// Stopwatch sw = new Stopwatch();
// sw.Start();
// if (!tool.RunProcedure(out string error, out _))
// {
// throw new Exception();
// }
// sw.Stop();
// var flag = tool.GetResultTuple("OUTPUT_Flag").HTupleToDouble();
// List<double> x = tool.GetResultTuple("RXCenter").HTupleToDouble();
// var y = tool.GetResultTuple("RYCenter").HTupleToDouble();
// var r = tool.GetResultTuple("RRadius").HTupleToDouble();
// if (flag.Count > 0 && x.Count > 0 && y.Count > 0 && r.Count > 0)
// {
// this.canvas.DrawCircle(new PointF((float)x[0], (float)y[0]), (float)r[0]);
// }
// //
// Debug.WriteLine("");
//}
//catch (Exception)
//{
// throw;
//}
//finally
//{
// hImage?.Dispose();
//}
}
private void btnTest_Click(object sender, EventArgs e)
{
this.canvas.DrawRectangle(new PointF(300, 300),
new PointF(800, 500), 33f);
}
private void btnRotateTest_Click(object sender, EventArgs e)
{
if (this.canvas.Shapes.Count == 0)
{
return;
}
this.canvas.Shapes[0]._currentRotateAngle += 10;
//var shp = this.canvas.Shapes[this.canvas.Shapes.Count - 1].Copy();
//shp.Rotate += 10;
//this.canvas.Shapes.Add(shp);
this.canvas.Invalidate();
}
}
}

148
CanFly/UI/FrmMain.resx Normal file
View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="canvas.OutsideShapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<data name="canvas.Shapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

75
CanFly/UI/FrmMain3.Designer.cs generated Normal file
View File

@ -0,0 +1,75 @@

namespace XKRS.CanFly
{
partial class FrmMain3
{
/// <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()
{
statusStrip1 = new StatusStrip();
panelContent = new Panel();
SuspendLayout();
//
// statusStrip1
//
statusStrip1.Location = new Point(0, 808);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(1185, 22);
statusStrip1.TabIndex = 4;
statusStrip1.Text = "statusStrip1";
//
// panelContent
//
panelContent.Dock = DockStyle.Fill;
panelContent.Location = new Point(0, 0);
panelContent.Margin = new Padding(4, 3, 4, 3);
panelContent.Name = "panelContent";
panelContent.Size = new Size(1185, 808);
panelContent.TabIndex = 5;
//
// FrmMain3
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1185, 830);
Controls.Add(panelContent);
Controls.Add(statusStrip1);
FormBorderStyle = FormBorderStyle.FixedSingle;
Margin = new Padding(2, 3, 2, 3);
Name = "FrmMain3";
StartPosition = FormStartPosition.CenterScreen;
Text = "尺寸测量";
Load += FrmMain_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private StatusStrip statusStrip1;
private Panel panelContent;
}
}

435
CanFly/UI/FrmMain3.cs Normal file
View File

@ -0,0 +1,435 @@
using CanFly.Canvas.Shape;
using CanFly.Helper;
using CanFly.UI;
using CanFly.UI.GuidePanel;
using CanFly.Util;
using HalconDotNet;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace XKRS.CanFly
{
public partial class FrmMain3 : Form
{
private string _currentImageFile = "";
private System.Windows.Forms.Timer _statusTimer = new System.Windows.Forms.Timer();
private BaseGuideControl? _currentGuideCtrl;
private GuideCircleCtrl guideCircleCtrl = new GuideCircleCtrl();
private GuideLineCircleCtrl guideLineCircleCtrl = new GuideLineCircleCtrl();
private GuideLineLineCtrl guideLineLineCtrl = new GuideLineLineCtrl();
private GuideLineCtrl guideLineCtrl = new GuideLineCtrl();
private GuideHeightCtrl guideHeightCtrl = new GuideHeightCtrl();
string Type=string.Empty;
public string inputtext=string.Empty;
public string outtext = string.Empty;
public FrmMain3(string type)
{
InitializeComponent();
Type=type;
guideCircleCtrl.Dock = DockStyle.Fill;
guideCircleCtrl.OnControlCloseEvent -= () => panelContent.Controls.Clear();
guideCircleCtrl.OnControlCloseEvent += () => panelContent.Controls.Clear();
guideLineCircleCtrl.Dock = DockStyle.Fill;
guideLineCircleCtrl.OnControlCloseEvent -= () => panelContent.Controls.Clear();
guideLineCircleCtrl.OnControlCloseEvent += () => panelContent.Controls.Clear();
guideLineLineCtrl.Dock = DockStyle.Fill;
guideLineLineCtrl.OnControlCloseEvent -= () => panelContent.Controls.Clear();
guideLineLineCtrl.OnControlCloseEvent += () => panelContent.Controls.Clear();
guideLineCtrl.Dock = DockStyle.Fill;
guideLineCtrl.OnControlCloseEvent -= () => panelContent.Controls.Clear();
guideLineCtrl.OnControlCloseEvent += () => panelContent.Controls.Clear();
guideHeightCtrl.Dock = DockStyle.Fill;
guideHeightCtrl.OnControlCloseEvent -= () => panelContent.Controls.Clear();
guideHeightCtrl.OnControlCloseEvent += () => panelContent.Controls.Clear();
}
private void FrmMain_Load(object sender, EventArgs e)
{
switch (Type)
{
case "1":
SwitchMeasureMode(guideCircleCtrl);
break;
case "2":
SwitchMeasureMode(guideLineCtrl);
break;
case "3":
SwitchMeasureMode(guideLineLineCtrl);
break;
case "4":
SwitchMeasureMode(guideLineCircleCtrl);
break;
case "5":
SwitchMeasureMode(guideHeightCtrl);
break;
default:
break;
}
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
//OpenFileDialog ofd = new OpenFileDialog();
//ofd.Filter = "ͼ<><CDBC><EFBFBD>ļ<EFBFBD>|*.jpg;*.png";
//ofd.Multiselect = false;
//if (ofd.ShowDialog() == DialogResult.OK)
//{
// _currentImageFile = ofd.FileName;
// Bitmap bitmap = (Bitmap)Image.FromFile(_currentImageFile);
// this.canvas.LoadPixmap(bitmap);
// this.btnCreateCircle.Enabled = true;
//}
}
private void btnMeasureCircle_Click(object sender, EventArgs e)
{
//var contentCtrls = panelContent.Controls;
//if (contentCtrls.Count > 0)
//{
// if (contentCtrls[0] == guideCircleCtrl)
// {
// return;
// }
//}
//panelContent.Controls.Clear();
//panelContent.Controls.Add(guideCircleCtrl);
SwitchMeasureMode(guideCircleCtrl);
}
private void btnMeasureLineCircle_Click(object sender, EventArgs e)
{
SwitchMeasureMode(guideLineCircleCtrl);
}
private void SwitchMeasureMode(BaseGuideControl control)
{
var contentCtrls = panelContent.Controls;
if (contentCtrls.Count > 0)
{
if (contentCtrls[0] == control)
{
return;
}
}
panelContent.Controls.Clear();
control.OnDataPassed -= Control_OnDataPassed;
control.OnDataPassed += Control_OnDataPassed;
//control.Dock = DockStyle.Fill;
//control.OnControlCloseEvent -= () => panelContent.Controls.Clear();
//control.OnControlCloseEvent += () => panelContent.Controls.Clear();
panelContent.Controls.Add(control);
}
private void Control_OnDataPassed(string obj,string obj1)
{
inputtext = obj;
outtext = obj1;
this.Close();
}
private void btnCreateRect_Click(object sender, EventArgs e)
{
//this.canvas.StartDraw(ShapeTypeEnum.Rectangle);
//this.btnCreateCircle.Enabled = false;
//this.btnStopDraw.Enabled = true;
//this.canvas.Enabled = true;
}
private void btnStopDraw_Click(object sender, EventArgs e)
{
//panelGuide.Controls.Clear();
StopDrawMode();
}
private void StartDrawMode()
{
}
private void StopDrawMode()
{
//this.canvas.StopDraw();
//this.btnStopDraw.Enabled = false;
//this.btnCreateCircle.Enabled = true;
}
private void Status(string message, int delay = 5000)
{
//_statusTimer.Stop();
//// <20><>ʾ<EFBFBD><CABE>Ϣ
//lblStatus.Text = message;
//// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//_statusTimer.Interval = delay; // <20><><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><CAB1>
//_statusTimer.Tick += (sender, e) =>
//{
// _statusTimer.Stop(); // ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1>
// lblStatus.Text = string.Empty; // <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>Ϣ
//};
//_statusTimer.Start(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
}
private void Canvas_mouseMoved(PointF pos)
{
//if (InvokeRequired)
//{
// Invoke(Canvas_mouseMoved, pos);
// return;
//}
//lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
// panelGuide.Controls.Clear();
return;
}
//SwitchGuideForm(shapes[0].ShapeType);
Canvas_OnShapeUpdateEvent(shapes[0]);
}
private void SwitchGuideForm(ShapeTypeEnum shapeType)
{
//if (_currentGuideCtrl == null)
//{
// switch (shapeType)
// {
// case ShapeTypeEnum.Point:
// break;
// case ShapeTypeEnum.Line:
// break;
// case ShapeTypeEnum.Rectangle:
// break;
// case ShapeTypeEnum.Circle:
// _currentGuideCtrl = new GuideCircleCtrl();
// _currentGuideCtrl.ImageFile = _currentImageFile;
// _currentGuideCtrl.OnDrawCircle += this.canvas.DrawCircle;
// _currentGuideCtrl.OnClose += () =>
// {
// panelGuide.Controls.Clear();
// StopDrawMode();
// };
// break;
// case ShapeTypeEnum.Polygon:
// break;
// case ShapeTypeEnum.LineStrip:
// break;
// default:
// break;
// }
//}
//_currentGuideCtrl?.AddToPanel(panelGuide);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
//if (shapes.Count != 1)
//{
// panelGuide.Controls.Clear();
// return;
//}
//_currentGuideCtrl?.UpdateShape(shapes[0]);
}
private void Canvas_OnShapeUpdateEvent(FlyShape shape)
{
switch (shape.ShapeType)
{
case ShapeTypeEnum.Point:
break;
case ShapeTypeEnum.Line:
break;
case ShapeTypeEnum.Rectangle:
break;
case ShapeTypeEnum.Circle:
{
//_currentGuideCtrl?.UpdateShape(shape);
}
break;
case ShapeTypeEnum.Polygon:
break;
case ShapeTypeEnum.LineStrip:
break;
default:
break;
}
}
private void btnTestOutsideDraw_Click(object sender, EventArgs e)
{
//Random random = new Random((int)DateTime.Now.Ticks);
//for (int i = 0; i < 10; i++)
//{
// // this.canvas.DrawCircle(new PointF(500, 500), 100);
// int x = random.Next() % 500;
// int y = random.Next() % 500;
// int r = random.Next() % 200;
// Debug.WriteLine($"X:{x}\tY:{y}\tR:{r}");
// this.canvas.DrawCircle(new PointF(x, y), r);
//}
}
private void btnTestClearDraw_Click(object sender, EventArgs e)
{
//this.canvas.ClearDraw();
}
private async void btnTestCircleMeasure_Click(object sender, EventArgs e)
{
//string dir = Path.Combine(Environment.CurrentDirectory, "hscripts");
//string file = "CircleMeasure.hdvp";
//string filePath = Path.Combine(dir, file);
//if (!File.Exists(filePath))
//{
// MessageBox.Show($"<22>ļ<EFBFBD> {filePath} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
// return;
//}
//HObject? hImage = null;
//try
//{
// HDevEngineTool tool = new HDevEngineTool(dir);
// tool.LoadProcedure(Path.GetFileNameWithoutExtension(file));
// // string imageFile = Path.Combine(Environment.CurrentDirectory, "hscripts", "image.png");
// HOperatorSet.ReadImage(out hImage, _currentImageFile);
// tool.InputImageDic["INPUT_Image"] = hImage;
// tool.InputTupleDic["XCenter"] = 981.625;
// tool.InputTupleDic["YCenter"] = 931.823;
// tool.InputTupleDic["Radius"] = 900.141;
// Stopwatch sw = new Stopwatch();
// sw.Start();
// if (!tool.RunProcedure(out string error, out _))
// {
// throw new Exception();
// }
// sw.Stop();
// var flag = tool.GetResultTuple("OUTPUT_Flag").HTupleToDouble();
// List<double> x = tool.GetResultTuple("RXCenter").HTupleToDouble();
// var y = tool.GetResultTuple("RYCenter").HTupleToDouble();
// var r = tool.GetResultTuple("RRadius").HTupleToDouble();
// if (flag.Count > 0 && x.Count > 0 && y.Count > 0 && r.Count > 0)
// {
// this.canvas.DrawCircle(new PointF((float)x[0], (float)y[0]), (float)r[0]);
// }
// //
// Debug.WriteLine("");
//}
//catch (Exception)
//{
// throw;
//}
//finally
//{
// hImage?.Dispose();
//}
}
private void btnTest_Click(object sender, EventArgs e)
{
//this.canvas.DrawRectangle(new PointF(300, 300),
// new PointF(800, 500), 33f);
}
private void btnRotateTest_Click(object sender, EventArgs e)
{
//if (this.canvas.Shapes.Count == 0)
//{
// return;
//}
//this.canvas.Shapes[0]._currentRotateAngle += 10;
//this.canvas.Invalidate();
}
private void btnMeasureLineline_Click(object sender, EventArgs e)
{
SwitchMeasureMode(guideLineLineCtrl);
}
private void btnMeasureLine_Click(object sender, EventArgs e)
{
SwitchMeasureMode(guideLineCtrl);
}
}
}

123
CanFly/UI/FrmMain3.resx Normal file
View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,158 @@
using CanFly.Canvas.Shape;
using CanFly.Canvas.UI;
using CanFly.Helper;
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.UI.GuidePanel
{
public class BaseGuideControl : UserControl
{
public Action? OnControlCloseEvent;
public event Action<string,string> OnDataPassed;
private string _currentImageFile;
public string CurrentImageFile;
protected string _hScriptsDir = Path.Combine(Environment.CurrentDirectory, "hscripts");
protected HObject? hImage = null;
protected FlyCanvas _canvas;
private HDevEngineTool? tool = null;
public void DataToTriggerEvent(string input,string output)
{
OnDataPassed?.Invoke(input, output);
}
protected virtual void UpdateShape(FlyShape shape)
{
throw new NotImplementedException();
}
protected virtual string GetScriptFileName()
{
throw new NotImplementedException();
}
/// <summary>
/// 执行Halcon脚本
/// </summary>
/// <param name="inputImg">输入图像</param>
/// <param name="inputDic">输入参数</param>
/// <param name="outputParamKeys">输出参数</param>
protected void ExecuteHScript(
Dictionary<string, HObject> inputImg,
Dictionary<string, HTuple> inputDic,
List<string> outputParamKeys,
Action<Exception>? exceptionHandler = null)
{
string filePath = Path.Combine(_hScriptsDir, GetScriptFileName());
if (!File.Exists(filePath))
{
MessageBox.Show($"文件 {filePath} 不存在");
return;
}
try
{
if (tool == null)
{
tool = new HDevEngineTool(_hScriptsDir);
tool.LoadProcedure(Path.GetFileNameWithoutExtension(GetScriptFileName()));
}
//tool.InputImageDic["INPUT_Image"] = hImage;
//tool.InputTupleDic["XCenter"] = _x;
//tool.InputTupleDic["YCenter"] = _y;
//tool.InputTupleDic["Radius"] = _r;
tool.InputImageDic = inputImg;
tool.InputTupleDic = inputDic;
Dictionary<string, HTuple> outputParams = new Dictionary<string, HTuple>();
if (!tool.RunProcedure(out string error, out int timeElasped))
{
OnExecuteHScriptResult(false, outputParams, timeElasped);
return;
}
for (int i = 0; i < outputParamKeys.Count; i++)
{
string k = outputParamKeys[i];
outputParams[k] = tool.GetResultTuple(k);
}
OnExecuteHScriptResult(true, outputParams, timeElasped);
}
catch (Exception ex)
{
exceptionHandler?.Invoke(ex);
}
finally
{
hImage?.Dispose();
hImage = null;
}
}
/// <summary>
/// Halcon脚本执行结果回调函数重写该方法以自行处理算法执行结果
/// </summary>
/// <param name="success">算法执行是否成功</param>
/// <param name="resultDic">算法输出结果</param>
/// <param name="timeElasped">算法耗时单位ms</param>
protected virtual void OnExecuteHScriptResult(bool success, Dictionary<string, HTuple> resultDic, int timeElasped)
{
throw new NotImplementedException();
}
protected void OpenImageFile(Action<Bitmap> callback)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "图像文件|*.jpg;*.jpeg;*.png";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
CurrentImageFile = ofd.FileName;
Bitmap bitmap = (Bitmap)Image.FromFile(CurrentImageFile);
callback?.Invoke(bitmap);
}
}
protected void OnControlClose()
{
OnControlCloseEvent?.Invoke();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
</root>

View File

@ -0,0 +1,77 @@
namespace CanFly.UI.GuidePanel
{
partial class CtrlTitleBar
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
btnClose = new PictureBox();
j = new Label();
((System.ComponentModel.ISupportInitialize)btnClose).BeginInit();
SuspendLayout();
//
// btnClose
//
btnClose.Dock = DockStyle.Right;
btnClose.Image = XKRS.CanFly.Properties.Resources.Close;
btnClose.Location = new Point(516, 3);
btnClose.Name = "btnClose";
btnClose.Size = new Size(30, 30);
btnClose.SizeMode = PictureBoxSizeMode.StretchImage;
btnClose.TabIndex = 1;
btnClose.TabStop = false;
btnClose.Click += btnClose_Click;
//
// j
//
j.Dock = DockStyle.Fill;
j.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Bold, GraphicsUnit.Point);
j.Location = new Point(3, 3);
j.Name = "j";
j.Size = new Size(513, 30);
j.TabIndex = 2;
j.Text = "标题";
j.TextAlign = ContentAlignment.MiddleLeft;
//
// CtrlTitleBar
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(j);
Controls.Add(btnClose);
MinimumSize = new Size(0, 36);
Name = "CtrlTitleBar";
Padding = new Padding(3);
Size = new Size(549, 36);
((System.ComponentModel.ISupportInitialize)btnClose).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox btnClose;
private Label j;
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CanFly.UI.GuidePanel
{
public partial class CtrlTitleBar : UserControl
{
public event Action? OnCloseClicked;
[DisplayName("Title")]
public string Title
{
get { return this.j.Text; }
set { this.j.Text = value; }
}
public CtrlTitleBar()
{
InitializeComponent();
this.Dock = DockStyle.Top;
}
private void btnClose_Click(object sender, EventArgs e)
{
OnCloseClicked?.Invoke();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
</root>

View File

@ -0,0 +1,364 @@
namespace CanFly.UI.GuidePanel
{
partial class GuideCircleCtrl
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GuideCircleCtrl));
splitContainer = new SplitContainer();
panel1 = new Panel();
canvas = new Canvas.UI.FlyCanvas();
statusStrip1 = new StatusStrip();
lblStatus = new ToolStripStatusLabel();
btnClose = new PictureBox();
label4 = new Label();
btnExecute = new Button();
lblElapsed = new Label();
ctrlTitleBar = new CtrlTitleBar();
groupBox1 = new GroupBox();
label1 = new Label();
label2 = new Label();
label3 = new Label();
tbR = new TextBox();
tbY = new TextBox();
tbX = new TextBox();
btnLoadImage = new Button();
btnCreateCircle = new Button();
btnSave = new Button();
label6 = new Label();
lblResult = new Label();
panelGuide = new Panel();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
panel1.SuspendLayout();
statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)btnClose).BeginInit();
groupBox1.SuspendLayout();
panelGuide.SuspendLayout();
SuspendLayout();
//
// splitContainer
//
splitContainer.Dock = DockStyle.Fill;
splitContainer.Location = new Point(0, 0);
splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
splitContainer.Panel1.Controls.Add(panelGuide);
splitContainer.Panel1MinSize = 150;
//
// splitContainer.Panel2
//
splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = new Size(1280, 640);
splitContainer.SplitterDistance = 200;
splitContainer.TabIndex = 12;
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(canvas);
panel1.Controls.Add(statusStrip1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(1076, 640);
panel1.TabIndex = 1;
//
// canvas
//
canvas.AllowMultiSelect = false;
canvas.CreateMode = Canvas.Shape.ShapeTypeEnum.Polygon;
canvas.Dock = DockStyle.Fill;
canvas.Enabled = false;
canvas.FillDrawing = false;
canvas.Location = new Point(0, 0);
canvas.Margin = new Padding(2);
canvas.Name = "canvas";
canvas.OutsideShapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.OutsideShapes");
canvas.Scale = 1F;
canvas.Shapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.Shapes");
canvas.Size = new Size(1074, 616);
canvas.TabIndex = 2;
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { lblStatus });
statusStrip1.Location = new Point(0, 616);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(1074, 22);
statusStrip1.TabIndex = 1;
statusStrip1.Text = "statusStrip1";
//
// lblStatus
//
lblStatus.Name = "lblStatus";
lblStatus.Size = new Size(44, 17);
lblStatus.Text = " ";
//
// btnClose
//
btnClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
btnClose.Image = XKRS.CanFly.Properties.Resources.Close;
btnClose.InitialImage = XKRS.CanFly.Properties.Resources.Close;
btnClose.Location = new Point(1102, 3);
btnClose.Name = "btnClose";
btnClose.Size = new Size(33, 33);
btnClose.SizeMode = PictureBoxSizeMode.StretchImage;
btnClose.TabIndex = 5;
btnClose.TabStop = false;
btnClose.Click += btnClose_Click;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(6, 307);
label4.Name = "label4";
label4.Size = new Size(44, 17);
label4.TabIndex = 3;
label4.Text = "耗时:";
//
// btnExecute
//
btnExecute.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnExecute.Location = new Point(6, 272);
btnExecute.Name = "btnExecute";
btnExecute.Size = new Size(186, 32);
btnExecute.TabIndex = 2;
btnExecute.Text = "执行";
btnExecute.UseVisualStyleBackColor = true;
btnExecute.Click += btnExecute_Click;
//
// lblElapsed
//
lblElapsed.AutoSize = true;
lblElapsed.Location = new Point(56, 307);
lblElapsed.Name = "lblElapsed";
lblElapsed.Size = new Size(32, 17);
lblElapsed.TabIndex = 4;
lblElapsed.Text = "0ms";
//
// ctrlTitleBar
//
ctrlTitleBar.Dock = DockStyle.Top;
ctrlTitleBar.Location = new Point(0, 0);
ctrlTitleBar.MinimumSize = new Size(0, 36);
ctrlTitleBar.Name = "ctrlTitleBar";
ctrlTitleBar.Padding = new Padding(3);
ctrlTitleBar.Size = new Size(198, 36);
ctrlTitleBar.TabIndex = 11;
ctrlTitleBar.Title = "圆形测量";
//
// groupBox1
//
groupBox1.Controls.Add(tbX);
groupBox1.Controls.Add(tbY);
groupBox1.Controls.Add(tbR);
groupBox1.Controls.Add(label3);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Dock = DockStyle.Top;
groupBox1.Location = new Point(0, 36);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(198, 116);
groupBox1.TabIndex = 12;
groupBox1.TabStop = false;
groupBox1.Text = "圆参数";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 25);
label1.Name = "label1";
label1.Size = new Size(19, 17);
label1.TabIndex = 0;
label1.Text = "X:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 54);
label2.Name = "label2";
label2.Size = new Size(18, 17);
label2.TabIndex = 1;
label2.Text = "Y:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(3, 83);
label3.Name = "label3";
label3.Size = new Size(44, 17);
label3.TabIndex = 2;
label3.Text = "半径:";
//
// tbR
//
tbR.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbR.Location = new Point(56, 80);
tbR.Name = "tbR";
tbR.Size = new Size(136, 23);
tbR.TabIndex = 3;
//
// tbY
//
tbY.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbY.Location = new Point(56, 51);
tbY.Name = "tbY";
tbY.Size = new Size(136, 23);
tbY.TabIndex = 4;
//
// tbX
//
tbX.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbX.Location = new Point(56, 22);
tbX.Name = "tbX";
tbX.Size = new Size(136, 23);
tbX.TabIndex = 5;
//
// btnLoadImage
//
btnLoadImage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnLoadImage.Location = new Point(6, 158);
btnLoadImage.Name = "btnLoadImage";
btnLoadImage.Size = new Size(186, 32);
btnLoadImage.TabIndex = 13;
btnLoadImage.Text = "打开图片";
btnLoadImage.UseVisualStyleBackColor = true;
btnLoadImage.Click += btnLoadImage_Click;
//
// btnCreateCircle
//
btnCreateCircle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnCreateCircle.Location = new Point(6, 196);
btnCreateCircle.Name = "btnCreateCircle";
btnCreateCircle.Size = new Size(186, 32);
btnCreateCircle.TabIndex = 14;
btnCreateCircle.Text = "创建圆形";
btnCreateCircle.UseVisualStyleBackColor = true;
btnCreateCircle.Click += btnCreateCircle_Click;
//
// btnSave
//
btnSave.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnSave.Location = new Point(9, 397);
btnSave.Name = "btnSave";
btnSave.Size = new Size(186, 32);
btnSave.TabIndex = 15;
btnSave.Text = "保存数据";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += btnSave_Click;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(6, 338);
label6.Name = "label6";
label6.Size = new Size(44, 17);
label6.TabIndex = 16;
label6.Text = "结果:";
//
// lblResult
//
lblResult.AutoSize = true;
lblResult.Location = new Point(56, 338);
lblResult.Name = "lblResult";
lblResult.Size = new Size(20, 17);
lblResult.TabIndex = 17;
lblResult.Text = "无";
//
// panelGuide
//
panelGuide.BorderStyle = BorderStyle.FixedSingle;
panelGuide.Controls.Add(lblResult);
panelGuide.Controls.Add(label6);
panelGuide.Controls.Add(btnSave);
panelGuide.Controls.Add(btnCreateCircle);
panelGuide.Controls.Add(btnLoadImage);
panelGuide.Controls.Add(groupBox1);
panelGuide.Controls.Add(ctrlTitleBar);
panelGuide.Controls.Add(lblElapsed);
panelGuide.Controls.Add(btnExecute);
panelGuide.Controls.Add(label4);
panelGuide.Dock = DockStyle.Fill;
panelGuide.Location = new Point(0, 0);
panelGuide.Name = "panelGuide";
panelGuide.Size = new Size(200, 640);
panelGuide.TabIndex = 0;
//
// GuideCircleCtrl
//
Controls.Add(splitContainer);
Controls.Add(btnClose);
Name = "GuideCircleCtrl";
Size = new Size(1280, 640);
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer).EndInit();
splitContainer.ResumeLayout(false);
panel1.ResumeLayout(false);
panel1.PerformLayout();
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)btnClose).EndInit();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
panelGuide.ResumeLayout(false);
panelGuide.PerformLayout();
ResumeLayout(false);
}
#endregion
private SplitContainer splitContainer;
private Panel panel1;
private Canvas.UI.FlyCanvas canvas;
private StatusStrip statusStrip1;
private ToolStripStatusLabel lblStatus;
private PictureBox btnClose;
private Panel panelGuide;
private Label lblResult;
private Label label6;
private Button btnSave;
private Button btnCreateCircle;
private Button btnLoadImage;
private GroupBox groupBox1;
private TextBox tbX;
private TextBox tbY;
private TextBox tbR;
private Label label3;
private Label label2;
private Label label1;
private CtrlTitleBar ctrlTitleBar;
private Label lblElapsed;
private Button btnExecute;
private Label label4;
}
}

View File

@ -0,0 +1,359 @@
using CanFly.Canvas.Shape;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CanFly.Canvas.Helper;
using CanFly.Helper;
using HalconDotNet;
using System.Diagnostics;
using CanFly.Canvas.UI;
namespace CanFly.UI.GuidePanel
{
public partial class GuideCircleCtrl : BaseGuideControl
{
private float _x;
private float _y;
private float _r;
private FlyShape? _circle;
protected override string GetScriptFileName() => "CircleMeasure.hdvp";
public GuideCircleCtrl()
{
InitializeComponent();
this.canvas.mouseMoved += Canvas_mouseMoved;
this.canvas.OnShapeUpdateEvent += UpdateShape;
this.canvas.selectionChanged += Canvas_selectionChanged;
this.canvas.OnShapeMoving += Canvas_OnShapeMoving;
this.canvas.newShape += Canvas_newShape;
this.ctrlTitleBar.OnCloseClicked += OnControlClose;
}
protected override void UpdateShape(FlyShape shape)
{
this._circle = shape;
_x = shape.Points[0].X;
_y = shape.Points[0].Y;
_r = PointHelper.Distance(shape.Points[0], shape.Points[1]);
this.tbX.Text = shape.Points[0].X.ToString("F3");
this.tbY.Text = shape.Points[0].Y.ToString("F3");
this.tbR.Text = _r.ToString("F3");
}
private void btnExecute_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
if(this.tbX.Text.Trim().Length == 0)
{
MessageBox.Show("请先创建圆形");
return;
}
this.canvas.OutsideShapes.Clear();
this.canvas.Invalidate();
flag = new List<double>();
x = new List<double>();
y = new List<double>();
r = new List<double>();
Dictionary<string, HObject> inputImg = new Dictionary<string, HObject>();
if (hImage == null)
{
HOperatorSet.ReadImage(out hImage, CurrentImageFile);
}
inputImg["INPUT_Image"] = hImage;
Dictionary<string, HTuple> inputPara = new Dictionary<string, HTuple>();
inputPara["XCenter"] = _x;
inputPara["YCenter"] = _y;
inputPara["Radius"] = _r;
List<string> outputKeys = new List<string>()
{
"OUTPUT_PreTreatedImage",
"OUTPUT_Flag",
"RXCenter",
"RYCenter",
"RRadius"
};
ExecuteHScript(
inputImg,
inputPara,
outputKeys);
}
List<double> flag = new List<double>(), x=new List<double>(),y=new List<double>(),r=new List<double>();
protected override void OnExecuteHScriptResult(
bool success,
Dictionary<string, HTuple> resultDic,
int timeElasped)
{
if (!success)
{
return;
}
/*
"OUTPUT_Flag",
"RXCenter",
"RYCenter",
"RRadius"
*/
//取图?????
flag = resultDic["OUTPUT_Flag"].HTupleToDouble();
x = resultDic["RXCenter"].HTupleToDouble();
y = resultDic["RYCenter"].HTupleToDouble();
r = resultDic["RRadius"].HTupleToDouble();
if (flag.Count > 0)
{
lblResult.Text = flag[0].ToString();
}
else
{
lblResult.Text = "无";
}
if (flag.Count > 0 && x.Count > 0 && y.Count > 0 && r.Count > 0)
{
//detectResult.VisionImageSet.MLImage = resultDic["RRadius"].GetResultObject("OUTPUT_PreTreatedImage");
this.canvas.DrawCircle(new PointF((float)x[0], (float)y[0]), (float)r[0]);
lblElapsed.Text = $"{timeElasped} ms";
}
}
private void Test()
{
string filePath = Path.Combine(_hScriptsDir, GetScriptFileName());
if (!File.Exists(filePath))
{
MessageBox.Show($"文件 {filePath} 不存在");
return;
}
try
{
HDevEngineTool tool = new HDevEngineTool(_hScriptsDir);
tool.LoadProcedure(Path.GetFileNameWithoutExtension(GetScriptFileName()));
if (hImage == null)
{
HOperatorSet.ReadImage(out hImage, CurrentImageFile);
}
tool.InputImageDic["INPUT_Image"] = hImage;
tool.InputTupleDic["XCenter"] = _x;
tool.InputTupleDic["YCenter"] = _y;
tool.InputTupleDic["Radius"] = _r;
if (!tool.RunProcedure(out string error, out int timeElasped))
{
throw new Exception();
}
HTuple hFlag = tool.GetResultTuple("OUTPUT_Flag");
var flag = tool.GetResultTuple("OUTPUT_Flag").HTupleToDouble();
List<double> x = tool.GetResultTuple("RXCenter").HTupleToDouble();
var y = tool.GetResultTuple("RYCenter").HTupleToDouble();
var r = tool.GetResultTuple("RRadius").HTupleToDouble();
if (flag.Count > 0)
{
lblResult.Text = flag[0].ToString();
}
else
{
lblResult.Text = "无";
}
if (flag.Count > 0 && x.Count > 0 && y.Count > 0 && r.Count > 0)
{
this.canvas.DrawCircle(new PointF((float)x[0], (float)y[0]), (float)r[0]);
lblElapsed.Text = $"{timeElasped} ms";
}
//
Debug.WriteLine("");
}
catch (Exception)
{
throw;
}
finally
{
hImage?.Dispose();
hImage = null;
}
}
private void btnClose_Click(object sender, EventArgs e)
{
OnControlCloseEvent?.Invoke();
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
OpenImageFile(bitmap =>
{
this.canvas.LoadPixmap(bitmap);
this.canvas.Enabled = true;
});
}
private void Canvas_mouseMoved(PointF pos)
{
if (InvokeRequired)
{
Invoke(Canvas_mouseMoved, pos);
return;
}
lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
//if (shapes.Count != 1)
//{
// // panelGuide.Controls.Clear();
// return;
//}
//SwitchGuideForm(shapes[0].ShapeType);
// Canvas_OnShapeUpdateEvent(shapes[0]);
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void btnCreateCircle_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
this.tbX.Text = string.Empty;
this.tbY.Text = string.Empty;
this.tbR.Text = string.Empty;
this.canvas.Shapes.Clear();
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Circle);
this.canvas.Enabled = true;
}
private void Canvas_newShape()
{
this.canvas.StopDraw();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (lblResult.Text.Equals("无"))
{
MessageBox.Show("请先进行绘制");
return;
}
if(lblResult.Text != "0")
{
MessageBox.Show("测量计算错误,无法保存");
return;
}
//List<double> x = tool.GetResultTuple("RXCenter").HTupleToDouble();
//var y = tool.GetResultTuple("RYCenter").HTupleToDouble();
//var r = tool.GetResultTuple("RRadius").HTupleToDouble();
//tool.InputTupleDic["XCenter"] = _x;
//tool.InputTupleDic["YCenter"] = _y;
//tool.InputTupleDic["Radius"] = _r;
string inputput = $"XCenter:{string.Join(";", _x)};YCenter:{string.Join(";", _y)};RRadius:{string.Join(";", _r)}";
string output = $"RXCenter:{string.Join(";", x[0])};RYCenter:{string.Join(";", y[0])};RRadius:{string.Join(";", r[0])}";
DataToTriggerEvent(inputput,output);
}
}
}

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
<data name="canvas.OutsideShapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<data name="canvas.Shapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,446 @@
namespace CanFly.UI.GuidePanel
{
partial class GuideHeightCtrl
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GuideHeightCtrl));
lblElapsed = new Label();
label4 = new Label();
splitContainer = new SplitContainer();
panelGuide = new Panel();
btnSave = new Button();
lblResult = new Label();
label1 = new Label();
btnCreateLine = new Button();
btnLoadImage = new Button();
label9 = new Label();
btnExecute = new Button();
label10 = new Label();
groupBox2 = new GroupBox();
tbheight = new TextBox();
lbheight = new Label();
tbwidth = new TextBox();
label2 = new Label();
tbLineX2 = new TextBox();
label8 = new Label();
tbLineY2 = new TextBox();
label5 = new Label();
tbLineX1 = new TextBox();
tbLineY1 = new TextBox();
label6 = new Label();
label7 = new Label();
ctrlTitleBar = new CtrlTitleBar();
panel1 = new Panel();
canvas = new Canvas.UI.FlyCanvas();
statusStrip1 = new StatusStrip();
lblStatus = new ToolStripStatusLabel();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
panelGuide.SuspendLayout();
groupBox2.SuspendLayout();
panel1.SuspendLayout();
statusStrip1.SuspendLayout();
SuspendLayout();
//
// lblElapsed
//
lblElapsed.AutoSize = true;
lblElapsed.Location = new Point(50, 328);
lblElapsed.Name = "lblElapsed";
lblElapsed.Size = new Size(32, 17);
lblElapsed.TabIndex = 9;
lblElapsed.Text = "0ms";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(0, 328);
label4.Name = "label4";
label4.Size = new Size(44, 17);
label4.TabIndex = 8;
label4.Text = "耗时:";
//
// splitContainer
//
splitContainer.Dock = DockStyle.Fill;
splitContainer.Location = new Point(0, 0);
splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
splitContainer.Panel1.Controls.Add(panelGuide);
splitContainer.Panel1MinSize = 150;
//
// splitContainer.Panel2
//
splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = new Size(1280, 640);
splitContainer.SplitterDistance = 200;
splitContainer.TabIndex = 11;
//
// panelGuide
//
panelGuide.BorderStyle = BorderStyle.FixedSingle;
panelGuide.Controls.Add(btnSave);
panelGuide.Controls.Add(lblResult);
panelGuide.Controls.Add(label1);
panelGuide.Controls.Add(btnCreateLine);
panelGuide.Controls.Add(btnLoadImage);
panelGuide.Controls.Add(label9);
panelGuide.Controls.Add(btnExecute);
panelGuide.Controls.Add(label10);
panelGuide.Controls.Add(groupBox2);
panelGuide.Controls.Add(ctrlTitleBar);
panelGuide.Dock = DockStyle.Fill;
panelGuide.Location = new Point(0, 0);
panelGuide.Name = "panelGuide";
panelGuide.Size = new Size(200, 640);
panelGuide.TabIndex = 0;
//
// btnSave
//
btnSave.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnSave.Location = new Point(2, 419);
btnSave.Name = "btnSave";
btnSave.Size = new Size(186, 32);
btnSave.TabIndex = 23;
btnSave.Text = "保存数据";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += btnSave_Click;
//
// lblResult
//
lblResult.AutoSize = true;
lblResult.Location = new Point(59, 354);
lblResult.Name = "lblResult";
lblResult.Size = new Size(20, 17);
lblResult.TabIndex = 22;
lblResult.Text = "无";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(9, 354);
label1.Name = "label1";
label1.Size = new Size(44, 17);
label1.TabIndex = 21;
label1.Text = "结果:";
//
// btnCreateLine
//
btnCreateLine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnCreateLine.Location = new Point(9, 252);
btnCreateLine.Name = "btnCreateLine";
btnCreateLine.Size = new Size(186, 32);
btnCreateLine.TabIndex = 20;
btnCreateLine.Text = "创建矩形";
btnCreateLine.UseVisualStyleBackColor = true;
btnCreateLine.Click += btnCreateLine_Click;
//
// btnLoadImage
//
btnLoadImage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnLoadImage.Location = new Point(6, 214);
btnLoadImage.Name = "btnLoadImage";
btnLoadImage.Size = new Size(186, 32);
btnLoadImage.TabIndex = 18;
btnLoadImage.Text = "打开图片";
btnLoadImage.UseVisualStyleBackColor = true;
btnLoadImage.Click += btnLoadImage_Click;
//
// label9
//
label9.AutoSize = true;
label9.Location = new Point(59, 325);
label9.Name = "label9";
label9.Size = new Size(32, 17);
label9.TabIndex = 17;
label9.Text = "0ms";
//
// btnExecute
//
btnExecute.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnExecute.Location = new Point(9, 290);
btnExecute.Name = "btnExecute";
btnExecute.Size = new Size(186, 32);
btnExecute.TabIndex = 15;
btnExecute.Text = "执行";
btnExecute.UseVisualStyleBackColor = true;
btnExecute.Click += btnExecute_Click;
//
// label10
//
label10.AutoSize = true;
label10.Location = new Point(9, 325);
label10.Name = "label10";
label10.Size = new Size(44, 17);
label10.TabIndex = 16;
label10.Text = "耗时:";
//
// groupBox2
//
groupBox2.Controls.Add(tbheight);
groupBox2.Controls.Add(lbheight);
groupBox2.Controls.Add(tbwidth);
groupBox2.Controls.Add(label2);
groupBox2.Controls.Add(tbLineX2);
groupBox2.Controls.Add(label8);
groupBox2.Controls.Add(tbLineY2);
groupBox2.Controls.Add(label5);
groupBox2.Controls.Add(tbLineX1);
groupBox2.Controls.Add(tbLineY1);
groupBox2.Controls.Add(label6);
groupBox2.Controls.Add(label7);
groupBox2.Dock = DockStyle.Top;
groupBox2.Location = new Point(0, 36);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(198, 172);
groupBox2.TabIndex = 13;
groupBox2.TabStop = false;
groupBox2.Text = "线参数";
//
// tbheight
//
tbheight.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbheight.Location = new Point(126, 140);
tbheight.Name = "tbheight";
tbheight.Size = new Size(66, 23);
tbheight.TabIndex = 13;
//
// lbheight
//
lbheight.AutoSize = true;
lbheight.Location = new Point(97, 143);
lbheight.Name = "lbheight";
lbheight.Size = new Size(23, 17);
lbheight.TabIndex = 12;
lbheight.Text = "高:";
//
// tbwidth
//
tbwidth.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbwidth.Location = new Point(27, 140);
tbwidth.Name = "tbwidth";
tbwidth.Size = new Size(64, 23);
tbwidth.TabIndex = 11;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 143);
label2.Name = "label2";
label2.Size = new Size(23, 17);
label2.TabIndex = 10;
label2.Text = "宽:";
//
// tbLineX2
//
tbLineX2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineX2.Location = new Point(56, 80);
tbLineX2.Name = "tbLineX2";
tbLineX2.Size = new Size(136, 23);
tbLineX2.TabIndex = 9;
//
// label8
//
label8.AutoSize = true;
label8.Location = new Point(6, 83);
label8.Name = "label8";
label8.Size = new Size(26, 17);
label8.TabIndex = 8;
label8.Text = "X2:";
//
// tbLineY2
//
tbLineY2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineY2.Location = new Point(56, 109);
tbLineY2.Name = "tbLineY2";
tbLineY2.Size = new Size(136, 23);
tbLineY2.TabIndex = 7;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(6, 112);
label5.Name = "label5";
label5.Size = new Size(25, 17);
label5.TabIndex = 6;
label5.Text = "Y2:";
//
// tbLineX1
//
tbLineX1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineX1.Location = new Point(56, 22);
tbLineX1.Name = "tbLineX1";
tbLineX1.Size = new Size(136, 23);
tbLineX1.TabIndex = 5;
tbLineX1.TextChanged += tbLineX1_TextChanged;
//
// tbLineY1
//
tbLineY1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineY1.Location = new Point(56, 51);
tbLineY1.Name = "tbLineY1";
tbLineY1.Size = new Size(136, 23);
tbLineY1.TabIndex = 4;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(6, 54);
label6.Name = "label6";
label6.Size = new Size(25, 17);
label6.TabIndex = 1;
label6.Text = "Y1:";
//
// label7
//
label7.AutoSize = true;
label7.Location = new Point(6, 25);
label7.Name = "label7";
label7.Size = new Size(26, 17);
label7.TabIndex = 0;
label7.Text = "X1:";
//
// ctrlTitleBar
//
ctrlTitleBar.Dock = DockStyle.Top;
ctrlTitleBar.Location = new Point(0, 0);
ctrlTitleBar.MinimumSize = new Size(0, 36);
ctrlTitleBar.Name = "ctrlTitleBar";
ctrlTitleBar.Padding = new Padding(3);
ctrlTitleBar.Size = new Size(198, 36);
ctrlTitleBar.TabIndex = 11;
ctrlTitleBar.Title = "高度测量";
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(canvas);
panel1.Controls.Add(statusStrip1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(1076, 640);
panel1.TabIndex = 1;
//
// canvas
//
canvas.AllowMultiSelect = false;
canvas.CreateMode = Canvas.Shape.ShapeTypeEnum.Polygon;
canvas.Dock = DockStyle.Fill;
canvas.Enabled = false;
canvas.FillDrawing = false;
canvas.Location = new Point(0, 0);
canvas.Margin = new Padding(2);
canvas.Name = "canvas";
canvas.OutsideShapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.OutsideShapes");
canvas.Scale = 1F;
canvas.Shapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.Shapes");
canvas.Size = new Size(1074, 616);
canvas.TabIndex = 2;
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { lblStatus });
statusStrip1.Location = new Point(0, 616);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(1074, 22);
statusStrip1.TabIndex = 1;
statusStrip1.Text = "statusStrip1";
//
// lblStatus
//
lblStatus.Name = "lblStatus";
lblStatus.Size = new Size(44, 17);
lblStatus.Text = " ";
//
// GuideHeightCtrl
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(splitContainer);
Controls.Add(lblElapsed);
Controls.Add(label4);
Name = "GuideHeightCtrl";
Size = new Size(1280, 640);
Load += GuideLineCircleCtrl_Load;
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer).EndInit();
splitContainer.ResumeLayout(false);
panelGuide.ResumeLayout(false);
panelGuide.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
panel1.ResumeLayout(false);
panel1.PerformLayout();
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label lblElapsed;
private Label label4;
private SplitContainer splitContainer;
private Panel panelGuide;
private Panel panel1;
private Canvas.UI.FlyCanvas canvas;
private StatusStrip statusStrip1;
private ToolStripStatusLabel lblStatus;
private GroupBox groupBox2;
private TextBox tbLineX2;
private Label label8;
private TextBox tbLineY2;
private Label label5;
private TextBox tbLineX1;
private TextBox tbLineY1;
private Label label6;
private Label label7;
private CtrlTitleBar ctrlTitleBar;
private Button btnLoadImage;
private Label label9;
private Button btnExecute;
private Label label10;
private Button btnCreateLine;
private TextBox tbRectWidth1;
private Label lblResult;
private Label label1;
private Button btnSave;
private TextBox tbheight;
private Label lbheight;
private TextBox tbwidth;
private Label label2;
}
}

View File

@ -0,0 +1,346 @@
using CanFly.Canvas.Helper;
using CanFly.Canvas.Shape;
using CanFly.Canvas.UI;
using CanFly.Helper;
using HalconDotNet;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CanFly.UI.GuidePanel
{
public partial class GuideHeightCtrl : BaseGuideControl
{
private FlyShape? _line;
private float _lineX1;
private float _lineY1;
private float _lineX2;
private float _lineY2;
float width, height;
private float _lineWidth;
private PointF[] _rectPoints = new PointF[4];
//private float _LineLX=new float();
//private float _LineLY =new float();
//private float _LineRX =new float();
//private float _LineRY =new float();
protected override string GetScriptFileName() => "HeightMeasure.hdvp";
public GuideHeightCtrl()
{
InitializeComponent();
this.canvas.mouseMoved += Canvas_mouseMoved;
this.canvas.OnShapeUpdateEvent += UpdateShape;
this.canvas.selectionChanged += Canvas_selectionChanged;
this.canvas.OnShapeMoving += Canvas_OnShapeMoving;
this.canvas.newShape += Canvas_newShape;
this.ctrlTitleBar.OnCloseClicked += OnControlClose;
}
protected override void UpdateShape(FlyShape shape)
{
switch (shape.ShapeType)
{
case ShapeTypeEnum.Rectangle:
this._line = shape;
var pts = this._line.Points;
_lineX1 = pts[0].X;
_lineY1 = pts[0].Y;
_lineX2 = pts[1].X;
_lineY2 = pts[1].Y;
_lineWidth = shape.LineVirtualRectWidth;
_rectPoints = shape.LineVirtualRectPoints;
//_LineLX = (shape.LineVirtualRectPoints[0].X + shape.LineVirtualRectPoints[3].X) / 2;
//_LineLY = (shape.LineVirtualRectPoints[0].Y + shape.LineVirtualRectPoints[3].Y) / 2;
//_LineRX = (shape.LineVirtualRectPoints[1].X + shape.LineVirtualRectPoints[2].X) / 2;
//_LineRY = (shape.LineVirtualRectPoints[1].Y + shape.LineVirtualRectPoints[2].Y) / 2;
width = Math.Abs(_lineX2 - _lineX1);
height = Math.Abs(_lineY2 - _lineY1);
tbLineX1.Text = _lineX1.ToString("F3");
tbLineY1.Text = _lineY1.ToString("F3");
tbLineX2.Text = _lineX2.ToString("F3");
tbLineY2.Text = _lineY2.ToString("F3");
tbwidth.Text = width.ToString();
tbheight.Text = height.ToString();
// NumRectWidth1.Value = (decimal)_lineWidth;
break;
default:
break;
}
}
private void GuideLineCircleCtrl_Load(object sender, EventArgs e)
{
}
private void Canvas_mouseMoved(PointF pos)
{
if (InvokeRequired)
{
Invoke(Canvas_mouseMoved, pos);
return;
}
lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
//if (shapes.Count != 1)
//{
// // panelGuide.Controls.Clear();
// return;
//}
//SwitchGuideForm(shapes[0].ShapeType);
// Canvas_OnShapeUpdateEvent(shapes[0]);
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void btnCreateLine_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
tbLineX1.Text = string.Empty;
tbLineY1.Text = string.Empty;
tbLineX2.Text = string.Empty;
tbLineY2.Text = string.Empty; ;
tbwidth.Text = string.Empty; ;
tbheight.Text = string.Empty; ;
this.canvas.Shapes.RemoveAll(shp => shp.ShapeType == ShapeTypeEnum.Rectangle);
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Rectangle);
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
OpenImageFile(bitmap =>
{
this.canvas.LoadPixmap(bitmap);
this.canvas.Enabled = true;
});
}
private void Canvas_newShape()
{
this.canvas.StopDraw();
}
private void btnExecute_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
if (this.tbLineX1.Text.Trim().Length == 0)
{
MessageBox.Show("请先创建矩形");
return;
}
this.canvas.OutsideShapes.Clear();
this.canvas.Invalidate();
flag = new List<double>();
Line1Para = new List<double>();
Line2Para = new List<double>();
iHeight = new List<double>();
Dictionary<string, HObject> inputImg = new Dictionary<string, HObject>();
if (hImage == null)
{
HOperatorSet.ReadImage(out hImage, CurrentImageFile);
}
inputImg["INPUT_Image"] = hImage;
Dictionary<string, HTuple> inputPara = new Dictionary<string, HTuple>();
inputPara["row"] = _lineY1;
inputPara["column"] = _lineX1;
inputPara["Width"] = width;
inputPara["Height"] = height;
List<string> outputKeys = new List<string>()
{
"OUTPUT_PreTreatedImage",
"OUTPUT_Flag",
"Line1Para",
"Line2Para",
"iHeight"
};
ExecuteHScript(
inputImg,
inputPara,
outputKeys);
}
List<double> flag = new List<double>();
List<double> Line1Para = new List<double>();
List<double> Line2Para = new List<double>();
List<double> iHeight = new List<double>();
protected override void OnExecuteHScriptResult(
bool success,
Dictionary<string, HTuple> resultDic,
int timeElasped)
{
if (!success)
{
return;
}
/*
"OUTPUT_Flag",
"RXCenter",
"RYCenter",
"RRadius"
*/
flag = resultDic["OUTPUT_Flag"].HTupleToDouble();
Line1Para = resultDic["Line1Para"].HTupleToDouble();
Line2Para = resultDic["Line2Para"].HTupleToDouble();
// EndRow = resultDic["EndRow"].HTupleToDouble();
//EndCloumn = resultDic["EndColumn"].HTupleToDouble();
iHeight = resultDic["iHeight"].HTupleToDouble();
if (flag.Count > 0)
{
lblResult.Text = flag[0].ToString();
}
else
{
lblResult.Text = "无";
}
if (flag.Count > 0 && Line1Para.Count == 4 && Line2Para.Count == 4 && iHeight.Count > 0)
{
float width = 0;
this.canvas.DrawLine(new PointF((float)Line1Para[1], (float)Line1Para[0]), new PointF((float)Line1Para[3], (float)Line1Para[2]), 0);
this.canvas.DrawLine(new PointF((float)Line2Para[1], (float)Line2Para[0]), new PointF((float)Line2Para[3], (float)Line2Para[2]), 0);
this.canvas.Invalidate();
lblElapsed.Text = $"{timeElasped} ms";
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (lblResult.Text.Equals("无"))
{
MessageBox.Show("请先进行绘制");
return;
}
if (lblResult.Text != "0")
{
MessageBox.Show("测量计算错误,无法保存");
return;
}
string input = $"row:{string.Join(";", _lineY1)};column:{string.Join(";", _lineX1)};" +
$"Width:{string.Join(";", width)};Height:{string.Join(";", height)}";
string output = $"iHeight:{string.Join(";", iHeight[0])}";
DataToTriggerEvent(input, output);
}
private void tbLineX1_TextChanged(object sender, EventArgs e)
{
}
}
}

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
<data name="canvas.OutsideShapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<data name="canvas.Shapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,550 @@
namespace CanFly.UI.GuidePanel
{
partial class GuideLineCircleCtrl
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GuideLineCircleCtrl));
lblElapsed = new Label();
label4 = new Label();
splitContainer = new SplitContainer();
panelGuide = new Panel();
lblDistance = new Label();
label17 = new Label();
lblResult = new Label();
label15 = new Label();
btnCreateLine = new Button();
btnCreateCircle = new Button();
btnLoadImage = new Button();
label9 = new Label();
btnExecute = new Button();
label10 = new Label();
groupBox2 = new GroupBox();
NumRectWidth1 = new NumericUpDown();
label11 = new Label();
tbLineX2 = new TextBox();
label8 = new Label();
tbLineY2 = new TextBox();
label5 = new Label();
tbLineX1 = new TextBox();
tbLineY1 = new TextBox();
label6 = new Label();
label7 = new Label();
groupBox1 = new GroupBox();
tbCircleX = new TextBox();
tbCircleY = new TextBox();
tbCircleR = new TextBox();
label3 = new Label();
label2 = new Label();
label1 = new Label();
ctrlTitleBar = new CtrlTitleBar();
panel1 = new Panel();
canvas = new Canvas.UI.FlyCanvas();
statusStrip1 = new StatusStrip();
lblStatus = new ToolStripStatusLabel();
btnSave = new Button();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
panelGuide.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth1).BeginInit();
groupBox1.SuspendLayout();
panel1.SuspendLayout();
statusStrip1.SuspendLayout();
SuspendLayout();
//
// lblElapsed
//
lblElapsed.AutoSize = true;
lblElapsed.Location = new Point(50, 328);
lblElapsed.Name = "lblElapsed";
lblElapsed.Size = new Size(32, 17);
lblElapsed.TabIndex = 9;
lblElapsed.Text = "0ms";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(0, 328);
label4.Name = "label4";
label4.Size = new Size(44, 17);
label4.TabIndex = 8;
label4.Text = "耗时:";
//
// splitContainer
//
splitContainer.Dock = DockStyle.Fill;
splitContainer.Location = new Point(0, 0);
splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
splitContainer.Panel1.Controls.Add(panelGuide);
splitContainer.Panel1MinSize = 150;
//
// splitContainer.Panel2
//
splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = new Size(1280, 640);
splitContainer.SplitterDistance = 200;
splitContainer.TabIndex = 11;
//
// panelGuide
//
panelGuide.BorderStyle = BorderStyle.FixedSingle;
panelGuide.Controls.Add(btnSave);
panelGuide.Controls.Add(lblDistance);
panelGuide.Controls.Add(label17);
panelGuide.Controls.Add(lblResult);
panelGuide.Controls.Add(label15);
panelGuide.Controls.Add(btnCreateLine);
panelGuide.Controls.Add(btnCreateCircle);
panelGuide.Controls.Add(btnLoadImage);
panelGuide.Controls.Add(label9);
panelGuide.Controls.Add(btnExecute);
panelGuide.Controls.Add(label10);
panelGuide.Controls.Add(groupBox2);
panelGuide.Controls.Add(groupBox1);
panelGuide.Controls.Add(ctrlTitleBar);
panelGuide.Dock = DockStyle.Fill;
panelGuide.Location = new Point(0, 0);
panelGuide.Name = "panelGuide";
panelGuide.Size = new Size(200, 640);
panelGuide.TabIndex = 0;
//
// lblDistance
//
lblDistance.AutoSize = true;
lblDistance.Location = new Point(54, 505);
lblDistance.Name = "lblDistance";
lblDistance.Size = new Size(15, 17);
lblDistance.TabIndex = 29;
lblDistance.Text = "0";
//
// label17
//
label17.AutoSize = true;
label17.Location = new Point(6, 505);
label17.Name = "label17";
label17.Size = new Size(44, 17);
label17.TabIndex = 28;
label17.Text = "距离:";
//
// lblResult
//
lblResult.AutoSize = true;
lblResult.Location = new Point(54, 479);
lblResult.Name = "lblResult";
lblResult.Size = new Size(20, 17);
lblResult.TabIndex = 27;
lblResult.Text = "无";
//
// label15
//
label15.AutoSize = true;
label15.Location = new Point(6, 479);
label15.Name = "label15";
label15.Size = new Size(44, 17);
label15.TabIndex = 26;
label15.Text = "结果:";
//
// btnCreateLine
//
btnCreateLine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnCreateLine.Location = new Point(6, 406);
btnCreateLine.Name = "btnCreateLine";
btnCreateLine.Size = new Size(186, 32);
btnCreateLine.TabIndex = 20;
btnCreateLine.Text = "创建直线";
btnCreateLine.UseVisualStyleBackColor = true;
btnCreateLine.Click += btnCreateLine_Click;
//
// btnCreateCircle
//
btnCreateCircle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnCreateCircle.Location = new Point(6, 368);
btnCreateCircle.Name = "btnCreateCircle";
btnCreateCircle.Size = new Size(186, 32);
btnCreateCircle.TabIndex = 19;
btnCreateCircle.Text = "创建圆形";
btnCreateCircle.UseVisualStyleBackColor = true;
btnCreateCircle.Click += btnCreateCircle_Click;
//
// btnLoadImage
//
btnLoadImage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnLoadImage.Location = new Point(6, 330);
btnLoadImage.Name = "btnLoadImage";
btnLoadImage.Size = new Size(186, 32);
btnLoadImage.TabIndex = 18;
btnLoadImage.Text = "打开图片";
btnLoadImage.UseVisualStyleBackColor = true;
btnLoadImage.Click += btnLoadImage_Click;
//
// label9
//
label9.AutoSize = true;
label9.Location = new Point(56, 525);
label9.Name = "label9";
label9.Size = new Size(32, 17);
label9.TabIndex = 17;
label9.Text = "0ms";
//
// btnExecute
//
btnExecute.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnExecute.Location = new Point(6, 444);
btnExecute.Name = "btnExecute";
btnExecute.Size = new Size(186, 32);
btnExecute.TabIndex = 15;
btnExecute.Text = "执行";
btnExecute.UseVisualStyleBackColor = true;
btnExecute.Click += btnExecute_Click;
//
// label10
//
label10.AutoSize = true;
label10.Location = new Point(6, 525);
label10.Name = "label10";
label10.Size = new Size(44, 17);
label10.TabIndex = 16;
label10.Text = "耗时:";
//
// groupBox2
//
groupBox2.Controls.Add(NumRectWidth1);
groupBox2.Controls.Add(label11);
groupBox2.Controls.Add(tbLineX2);
groupBox2.Controls.Add(label8);
groupBox2.Controls.Add(tbLineY2);
groupBox2.Controls.Add(label5);
groupBox2.Controls.Add(tbLineX1);
groupBox2.Controls.Add(tbLineY1);
groupBox2.Controls.Add(label6);
groupBox2.Controls.Add(label7);
groupBox2.Dock = DockStyle.Top;
groupBox2.Location = new Point(0, 152);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(198, 172);
groupBox2.TabIndex = 13;
groupBox2.TabStop = false;
groupBox2.Text = "线参数";
//
// NumRectWidth1
//
NumRectWidth1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
NumRectWidth1.Location = new Point(56, 138);
NumRectWidth1.Maximum = new decimal(new int[] { 9000, 0, 0, 0 });
NumRectWidth1.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
NumRectWidth1.Name = "NumRectWidth1";
NumRectWidth1.Size = new Size(136, 23);
NumRectWidth1.TabIndex = 13;
NumRectWidth1.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label11
//
label11.AutoSize = true;
label11.Location = new Point(6, 140);
label11.Name = "label11";
label11.Size = new Size(35, 17);
label11.TabIndex = 12;
label11.Text = "宽度:";
//
// tbLineX2
//
tbLineX2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineX2.Location = new Point(56, 80);
tbLineX2.Name = "tbLineX2";
tbLineX2.Size = new Size(136, 23);
tbLineX2.TabIndex = 9;
//
// label8
//
label8.AutoSize = true;
label8.Location = new Point(6, 83);
label8.Name = "label8";
label8.Size = new Size(26, 17);
label8.TabIndex = 8;
label8.Text = "X2:";
//
// tbLineY2
//
tbLineY2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineY2.Location = new Point(56, 109);
tbLineY2.Name = "tbLineY2";
tbLineY2.Size = new Size(136, 23);
tbLineY2.TabIndex = 7;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(6, 112);
label5.Name = "label5";
label5.Size = new Size(25, 17);
label5.TabIndex = 6;
label5.Text = "Y2:";
//
// tbLineX1
//
tbLineX1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineX1.Location = new Point(56, 22);
tbLineX1.Name = "tbLineX1";
tbLineX1.Size = new Size(136, 23);
tbLineX1.TabIndex = 5;
//
// tbLineY1
//
tbLineY1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineY1.Location = new Point(56, 51);
tbLineY1.Name = "tbLineY1";
tbLineY1.Size = new Size(136, 23);
tbLineY1.TabIndex = 4;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(6, 54);
label6.Name = "label6";
label6.Size = new Size(25, 17);
label6.TabIndex = 1;
label6.Text = "Y1:";
//
// label7
//
label7.AutoSize = true;
label7.Location = new Point(6, 25);
label7.Name = "label7";
label7.Size = new Size(26, 17);
label7.TabIndex = 0;
label7.Text = "X1:";
//
// groupBox1
//
groupBox1.Controls.Add(tbCircleX);
groupBox1.Controls.Add(tbCircleY);
groupBox1.Controls.Add(tbCircleR);
groupBox1.Controls.Add(label3);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Dock = DockStyle.Top;
groupBox1.Location = new Point(0, 36);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(198, 116);
groupBox1.TabIndex = 12;
groupBox1.TabStop = false;
groupBox1.Text = "圆参数";
//
// tbCircleX
//
tbCircleX.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbCircleX.Location = new Point(56, 22);
tbCircleX.Name = "tbCircleX";
tbCircleX.Size = new Size(136, 23);
tbCircleX.TabIndex = 5;
//
// tbCircleY
//
tbCircleY.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbCircleY.Location = new Point(56, 51);
tbCircleY.Name = "tbCircleY";
tbCircleY.Size = new Size(136, 23);
tbCircleY.TabIndex = 4;
//
// tbCircleR
//
tbCircleR.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbCircleR.Location = new Point(56, 80);
tbCircleR.Name = "tbCircleR";
tbCircleR.Size = new Size(136, 23);
tbCircleR.TabIndex = 3;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(3, 83);
label3.Name = "label3";
label3.Size = new Size(44, 17);
label3.TabIndex = 2;
label3.Text = "半径:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 54);
label2.Name = "label2";
label2.Size = new Size(18, 17);
label2.TabIndex = 1;
label2.Text = "Y:";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 25);
label1.Name = "label1";
label1.Size = new Size(19, 17);
label1.TabIndex = 0;
label1.Text = "X:";
//
// ctrlTitleBar
//
ctrlTitleBar.Dock = DockStyle.Top;
ctrlTitleBar.Location = new Point(0, 0);
ctrlTitleBar.MinimumSize = new Size(0, 36);
ctrlTitleBar.Name = "ctrlTitleBar";
ctrlTitleBar.Padding = new Padding(3);
ctrlTitleBar.Size = new Size(198, 36);
ctrlTitleBar.TabIndex = 11;
ctrlTitleBar.Title = "线圆测量";
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(canvas);
panel1.Controls.Add(statusStrip1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(1076, 640);
panel1.TabIndex = 1;
//
// canvas
//
canvas.AllowMultiSelect = false;
canvas.CreateMode = Canvas.Shape.ShapeTypeEnum.Polygon;
canvas.Dock = DockStyle.Fill;
canvas.Enabled = false;
canvas.FillDrawing = false;
canvas.Location = new Point(0, 0);
canvas.Margin = new Padding(2);
canvas.Name = "canvas";
canvas.OutsideShapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.OutsideShapes");
canvas.Scale = 1F;
canvas.Shapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.Shapes");
canvas.Size = new Size(1074, 616);
canvas.TabIndex = 2;
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { lblStatus });
statusStrip1.Location = new Point(0, 616);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(1074, 22);
statusStrip1.TabIndex = 1;
statusStrip1.Text = "statusStrip1";
//
// lblStatus
//
lblStatus.Name = "lblStatus";
lblStatus.Size = new Size(44, 17);
lblStatus.Text = " ";
//
// btnSave
//
btnSave.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnSave.Location = new Point(6, 545);
btnSave.Name = "btnSave";
btnSave.Size = new Size(186, 32);
btnSave.TabIndex = 30;
btnSave.Text = "保存数据";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += btnSave_Click;
//
// GuideLineCircleCtrl
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(splitContainer);
Controls.Add(lblElapsed);
Controls.Add(label4);
Name = "GuideLineCircleCtrl";
Size = new Size(1280, 640);
Load += GuideLineCircleCtrl_Load;
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer).EndInit();
splitContainer.ResumeLayout(false);
panelGuide.ResumeLayout(false);
panelGuide.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth1).EndInit();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
panel1.ResumeLayout(false);
panel1.PerformLayout();
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label lblElapsed;
private Label label4;
private SplitContainer splitContainer;
private Panel panelGuide;
private Panel panel1;
private Canvas.UI.FlyCanvas canvas;
private StatusStrip statusStrip1;
private ToolStripStatusLabel lblStatus;
private GroupBox groupBox2;
private TextBox tbLineX2;
private Label label8;
private TextBox tbLineY2;
private Label label5;
private TextBox tbLineX1;
private TextBox tbLineY1;
private Label label6;
private Label label7;
private GroupBox groupBox1;
private TextBox tbCircleX;
private TextBox tbCircleY;
private TextBox tbCircleR;
private Label label3;
private Label label2;
private Label label1;
private CtrlTitleBar ctrlTitleBar;
private Button btnCreateCircle;
private Button btnLoadImage;
private Label label9;
private Button btnExecute;
private Label label10;
private Button btnCreateLine;
private TextBox tbRectWidth1;
private Label label11;
private NumericUpDown NumRectWidth1;
private Label lblDistance;
private Label label17;
private Label lblResult;
private Label label15;
private Button btnSave;
}
}

View File

@ -0,0 +1,449 @@
using CanFly.Canvas.Helper;
using CanFly.Canvas.Shape;
using CanFly.Canvas.UI;
using CanFly.Helper;
using HalconDotNet;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CanFly.UI.GuidePanel
{
public partial class GuideLineCircleCtrl : BaseGuideControl
{
private FlyShape? _circle;
private FlyShape? _line;
private float _lineX1;
private float _lineY1;
private float _lineX2;
private float _lineY2;
private float _lineWidth;
private float _circleX;
private float _circleY;
private float _circleR;
protected override string GetScriptFileName() => "LineToCircle.hdvp";
public GuideLineCircleCtrl()
{
InitializeComponent();
this.canvas.mouseMoved += Canvas_mouseMoved;
this.canvas.OnShapeUpdateEvent += UpdateShape;
this.canvas.selectionChanged += Canvas_selectionChanged;
this.canvas.OnShapeMoving += Canvas_OnShapeMoving;
this.canvas.newShape += Canvas_newShape;
this.ctrlTitleBar.OnCloseClicked += OnControlClose;
NumRectWidth1.ValueChanged -= NumRectWidth1_ValueChanged;
NumRectWidth1.Value = 40;
NumRectWidth1.ValueChanged += NumRectWidth1_ValueChanged;
}
protected override void UpdateShape(FlyShape shape)
{
switch (shape.ShapeType)
{
case ShapeTypeEnum.Line:
this._line = shape;
_line.IsDrawLineVirtualRect = true;
var pts = this._line.Points;
_lineX1 = pts[0].X;
_lineY1 = pts[0].Y;
_lineX2 = pts[1].X;
_lineY2 = pts[1].Y;
_lineWidth = shape.LineVirtualRectWidth;
tbLineX1.Text = _lineX1.ToString("F3");
tbLineY1.Text = _lineY1.ToString("F3");
tbLineX2.Text = _lineX2.ToString("F3");
tbLineY2.Text = _lineY2.ToString("F3");
// NumRectWidth1.Value = (decimal)_lineWidth;
break;
case ShapeTypeEnum.Circle:
this._circle = shape;
_circleX = shape.Points[0].X;
_circleY = shape.Points[0].Y;
_circleR = PointHelper.Distance(shape.Points[0], shape.Points[1]);
this.tbCircleX.Text = _circleX.ToString("F3");
this.tbCircleY.Text = _circleY.ToString("F3");
this.tbCircleR.Text = _circleR.ToString("F3");
break;
default:
break;
}
}
private void GuideLineCircleCtrl_Load(object sender, EventArgs e)
{
}
private void Canvas_mouseMoved(PointF pos)
{
if (InvokeRequired)
{
Invoke(Canvas_mouseMoved, pos);
return;
}
lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
//if (shapes.Count != 1)
//{
// // panelGuide.Controls.Clear();
// return;
//}
//SwitchGuideForm(shapes[0].ShapeType);
// Canvas_OnShapeUpdateEvent(shapes[0]);
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void btnCreateCircle_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
this.tbCircleX.Text = string.Empty;
this.tbCircleY.Text = string.Empty;
this.tbCircleR.Text = string.Empty;
this.canvas.Shapes.RemoveAll(shp => shp.ShapeType == ShapeTypeEnum.Circle);
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Circle);
}
private void btnCreateLine_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
tbLineX1.Text = string.Empty;
tbLineY1.Text = string.Empty;
tbLineX2.Text = string.Empty;
tbLineY2.Text = string.Empty;
this.canvas.Shapes.RemoveAll(shp => shp.ShapeType == ShapeTypeEnum.Line);
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Line);
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
OpenImageFile(bitmap =>
{
this.canvas.LoadPixmap(bitmap);
this.canvas.Enabled = true;
});
}
private void Canvas_newShape()
{
this.canvas.StopDraw();
}
string strarrayX=string.Empty;
string strarrayY=string.Empty;
private void btnExecute_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
if (this.tbLineX1.Text.Trim().Length == 0)
{
MessageBox.Show("请先创建直线");
return;
}
if (this.tbLineX1.Text.Trim().Length == 0)
{
MessageBox.Show("请先创建圆形");
return;
}
this.canvas.OutsideShapes.Clear();
this.canvas.Invalidate();
flag = new List<double>();
Distance = new List<double>();
fRowCenter = new List<double>();
fColCenter = new List<double>();
fRadius = new List<double>();
RowBegin = new List<double>();
ColBegin = new List<double>();
RowEnd = new List<double>();
ColEnd = new List<double>();
Dictionary<string, HObject> inputImg = new Dictionary<string, HObject>();
if (hImage == null)
{
HOperatorSet.ReadImage(out hImage, CurrentImageFile);
}
inputImg["INPUT_Image"] = hImage;
Dictionary<string, HTuple> inputPara = new Dictionary<string, HTuple>();
PointF[] Points = this._line.LineVirtualRectPoints;
PointF Point1 = Points[0];
PointF Point2 = Points[1];
PointF Point3 = Points[2];
PointF Point4 = Points[3];
PointF Point5 = Points[0];
float x1 = Point1.X;
float y1 = Point1.Y;
float x2 = Point2.X;
float y2 = Point2.Y;
float x3 = Point3.X;
float y3 = Point3.Y;
float x4 = Point4.X;
float y4 = Point4.Y;
float x5 = Point5.X;
float y5 = Point5.Y;
float[] arrayX = new float[] { x1, x2, x3, x4, x5 };
HTuple hTupleArrayX = new HTuple(arrayX);
float[] arrayY = new float[] { y1, y2, y3, y4, y5 };
HTuple hTupleArrayY = new HTuple(arrayY);
strarrayX=string.Join(",", arrayX);
strarrayY=string.Join(",", arrayY);
inputPara["LX"] = _lineX1;
inputPara["LY"] = _lineY1;
inputPara["RX"] = _lineX2;
inputPara["RY"] = _lineY2;
inputPara["XCenter"] = _circleX;
inputPara["YCenter"] = _circleY;
inputPara["Radius"] = _circleR;
inputPara["Line_XRect"] = hTupleArrayX;
inputPara["Line_YRect"] = hTupleArrayY;
List<string> outputKeys = new List<string>()
{
"OUTPUT_Flag",
"distance",
"fRowCenter",
"fColCenter",
"fRadius",
"RowBegin",
"ColBegin",
"RowEnd",
"ColEnd"
};
ExecuteHScript(
inputImg,
inputPara,
outputKeys);
}
List<double> flag = new List<double>();
List<double> Distance = new List<double>();
List<double> fRowCenter = new List<double>();
List<double> fColCenter = new List<double>();
List<double> fRadius = new List<double>();
List<double> RowBegin = new List<double>();
List<double> ColBegin = new List<double>();
List<double> RowEnd = new List<double>();
List<double> ColEnd = new List<double>();
protected override void OnExecuteHScriptResult(
bool success,
Dictionary<string, HTuple> resultDic,
int timeElasped)
{
if (!success)
{
return;
}
//"OUTPUT_Flag",
// "distance",
// "fRowCenter",
// "fColCenter",
// "fRadius",
// "RowBegin",
// "ColBegin",
// "RowEnd",
// "ColEnd"
flag = resultDic["OUTPUT_Flag"].HTupleToDouble();
Distance = resultDic["distance"].HTupleToDouble();
fRowCenter = resultDic["fRowCenter"].HTupleToDouble();
fColCenter = resultDic["fColCenter"].HTupleToDouble();
fRadius = resultDic["fRadius"].HTupleToDouble();
RowBegin = resultDic["RowBegin"].HTupleToDouble();
ColBegin = resultDic["ColBegin"].HTupleToDouble();
RowEnd = resultDic["RowEnd"].HTupleToDouble();
ColEnd = resultDic["ColEnd"].HTupleToDouble();
if (flag.Count > 0)
{
lblResult.Text = flag[0].ToString();
}
else
{
lblResult.Text = "无";
}
if (Distance.Count > 0)
{
lblDistance.Text = Distance[0].ToString();
}
else
{
lblDistance.Text = "0";
}
if (flag.Count > 0 && Distance.Count > 0 && fRowCenter.Count > 0 && fColCenter.Count > 0 && fRadius.Count > 0 && RowBegin.Count > 0 && ColBegin.Count > 0 && RowEnd.Count > 0 && ColEnd.Count > 0)
{
float width = 0;
this.canvas.DrawLine(new PointF((float)ColBegin[0], (float)RowBegin[0]), new PointF((float)ColEnd[0], (float)RowEnd[0]), width);
this.canvas.DrawCircle(new PointF((float)fColCenter[0], (float)fRowCenter[0]), (float)fRadius[0]);
this.canvas.Invalidate();
lblElapsed.Text = $"{timeElasped} ms";
}
}
private void NumRectWidth1_ValueChanged(object sender, EventArgs e)
{
if (_line != null)
{
//_line1.IsDrawLineVirtualRect = true;
_line.LineVirtualRectWidth = (float)NumRectWidth1.Value;
UpdateShape(_line);
this.canvas.Invalidate();
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (lblResult.Text.Equals("无"))
{
MessageBox.Show("请先进行绘制");
return;
}
if (lblResult.Text != "0")
{
MessageBox.Show("测量计算错误,无法保存");
return;
}
string input = $"LX:{_lineX1};" +
$"LY:{_lineY1};" +
$"RX:{_lineX2};" +
$"RY:{_lineY2};" +
$"XCenter:{_circleX};" +
$"YCenter:{_circleY};" +
$"Radius:{_circleR};" +
$"Line_XRect:{strarrayX};"+
$"Line_YRect:{strarrayY}";
string result = $"distance:{Distance[0]};";
DataToTriggerEvent(input, result);
}
}
}

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
<data name="canvas.OutsideShapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<data name="canvas.Shapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,427 @@
namespace CanFly.UI.GuidePanel
{
partial class GuideLineCtrl
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GuideLineCtrl));
lblElapsed = new Label();
label4 = new Label();
splitContainer = new SplitContainer();
panelGuide = new Panel();
btnSave = new Button();
lblResult = new Label();
label1 = new Label();
btnCreateLine = new Button();
btnLoadImage = new Button();
label9 = new Label();
btnExecute = new Button();
label10 = new Label();
groupBox2 = new GroupBox();
NumRectWidth1 = new NumericUpDown();
label11 = new Label();
tbLineX2 = new TextBox();
label8 = new Label();
tbLineY2 = new TextBox();
label5 = new Label();
tbLineX1 = new TextBox();
tbLineY1 = new TextBox();
label6 = new Label();
label7 = new Label();
ctrlTitleBar = new CtrlTitleBar();
panel1 = new Panel();
canvas = new Canvas.UI.FlyCanvas();
statusStrip1 = new StatusStrip();
lblStatus = new ToolStripStatusLabel();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
panelGuide.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth1).BeginInit();
panel1.SuspendLayout();
statusStrip1.SuspendLayout();
SuspendLayout();
//
// lblElapsed
//
lblElapsed.AutoSize = true;
lblElapsed.Location = new Point(50, 328);
lblElapsed.Name = "lblElapsed";
lblElapsed.Size = new Size(32, 17);
lblElapsed.TabIndex = 9;
lblElapsed.Text = "0ms";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(0, 328);
label4.Name = "label4";
label4.Size = new Size(44, 17);
label4.TabIndex = 8;
label4.Text = "耗时:";
//
// splitContainer
//
splitContainer.Dock = DockStyle.Fill;
splitContainer.Location = new Point(0, 0);
splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
splitContainer.Panel1.Controls.Add(panelGuide);
splitContainer.Panel1MinSize = 150;
//
// splitContainer.Panel2
//
splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = new Size(1280, 640);
splitContainer.SplitterDistance = 200;
splitContainer.TabIndex = 11;
//
// panelGuide
//
panelGuide.BorderStyle = BorderStyle.FixedSingle;
panelGuide.Controls.Add(btnSave);
panelGuide.Controls.Add(lblResult);
panelGuide.Controls.Add(label1);
panelGuide.Controls.Add(btnCreateLine);
panelGuide.Controls.Add(btnLoadImage);
panelGuide.Controls.Add(label9);
panelGuide.Controls.Add(btnExecute);
panelGuide.Controls.Add(label10);
panelGuide.Controls.Add(groupBox2);
panelGuide.Controls.Add(ctrlTitleBar);
panelGuide.Dock = DockStyle.Fill;
panelGuide.Location = new Point(0, 0);
panelGuide.Name = "panelGuide";
panelGuide.Size = new Size(200, 640);
panelGuide.TabIndex = 0;
//
// btnSave
//
btnSave.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnSave.Location = new Point(6, 390);
btnSave.Name = "btnSave";
btnSave.Size = new Size(186, 32);
btnSave.TabIndex = 23;
btnSave.Text = "保存数据";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += btnSave_Click;
//
// lblResult
//
lblResult.AutoSize = true;
lblResult.Location = new Point(59, 354);
lblResult.Name = "lblResult";
lblResult.Size = new Size(20, 17);
lblResult.TabIndex = 22;
lblResult.Text = "无";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(9, 354);
label1.Name = "label1";
label1.Size = new Size(44, 17);
label1.TabIndex = 21;
label1.Text = "结果:";
//
// btnCreateLine
//
btnCreateLine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnCreateLine.Location = new Point(9, 252);
btnCreateLine.Name = "btnCreateLine";
btnCreateLine.Size = new Size(186, 32);
btnCreateLine.TabIndex = 20;
btnCreateLine.Text = "创建直线";
btnCreateLine.UseVisualStyleBackColor = true;
btnCreateLine.Click += btnCreateLine_Click;
//
// btnLoadImage
//
btnLoadImage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnLoadImage.Location = new Point(6, 214);
btnLoadImage.Name = "btnLoadImage";
btnLoadImage.Size = new Size(186, 32);
btnLoadImage.TabIndex = 18;
btnLoadImage.Text = "打开图片";
btnLoadImage.UseVisualStyleBackColor = true;
btnLoadImage.Click += btnLoadImage_Click;
//
// label9
//
label9.AutoSize = true;
label9.Location = new Point(59, 325);
label9.Name = "label9";
label9.Size = new Size(32, 17);
label9.TabIndex = 17;
label9.Text = "0ms";
//
// btnExecute
//
btnExecute.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnExecute.Location = new Point(9, 290);
btnExecute.Name = "btnExecute";
btnExecute.Size = new Size(186, 32);
btnExecute.TabIndex = 15;
btnExecute.Text = "执行";
btnExecute.UseVisualStyleBackColor = true;
btnExecute.Click += btnExecute_Click;
//
// label10
//
label10.AutoSize = true;
label10.Location = new Point(9, 325);
label10.Name = "label10";
label10.Size = new Size(44, 17);
label10.TabIndex = 16;
label10.Text = "耗时:";
//
// groupBox2
//
groupBox2.Controls.Add(NumRectWidth1);
groupBox2.Controls.Add(label11);
groupBox2.Controls.Add(tbLineX2);
groupBox2.Controls.Add(label8);
groupBox2.Controls.Add(tbLineY2);
groupBox2.Controls.Add(label5);
groupBox2.Controls.Add(tbLineX1);
groupBox2.Controls.Add(tbLineY1);
groupBox2.Controls.Add(label6);
groupBox2.Controls.Add(label7);
groupBox2.Dock = DockStyle.Top;
groupBox2.Location = new Point(0, 36);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(198, 172);
groupBox2.TabIndex = 13;
groupBox2.TabStop = false;
groupBox2.Text = "线参数";
//
// NumRectWidth1
//
NumRectWidth1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
NumRectWidth1.Location = new Point(56, 138);
NumRectWidth1.Maximum = new decimal(new int[] { 9000, 0, 0, 0 });
NumRectWidth1.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
NumRectWidth1.Name = "NumRectWidth1";
NumRectWidth1.Size = new Size(136, 23);
NumRectWidth1.TabIndex = 13;
NumRectWidth1.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label11
//
label11.AutoSize = true;
label11.Location = new Point(6, 140);
label11.Name = "label11";
label11.Size = new Size(35, 17);
label11.TabIndex = 12;
label11.Text = "宽度:";
//
// tbLineX2
//
tbLineX2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineX2.Location = new Point(56, 80);
tbLineX2.Name = "tbLineX2";
tbLineX2.Size = new Size(136, 23);
tbLineX2.TabIndex = 9;
//
// label8
//
label8.AutoSize = true;
label8.Location = new Point(6, 83);
label8.Name = "label8";
label8.Size = new Size(26, 17);
label8.TabIndex = 8;
label8.Text = "X2:";
//
// tbLineY2
//
tbLineY2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineY2.Location = new Point(56, 109);
tbLineY2.Name = "tbLineY2";
tbLineY2.Size = new Size(136, 23);
tbLineY2.TabIndex = 7;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(6, 112);
label5.Name = "label5";
label5.Size = new Size(25, 17);
label5.TabIndex = 6;
label5.Text = "Y2:";
//
// tbLineX1
//
tbLineX1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineX1.Location = new Point(56, 22);
tbLineX1.Name = "tbLineX1";
tbLineX1.Size = new Size(136, 23);
tbLineX1.TabIndex = 5;
//
// tbLineY1
//
tbLineY1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLineY1.Location = new Point(56, 51);
tbLineY1.Name = "tbLineY1";
tbLineY1.Size = new Size(136, 23);
tbLineY1.TabIndex = 4;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(6, 54);
label6.Name = "label6";
label6.Size = new Size(25, 17);
label6.TabIndex = 1;
label6.Text = "Y1:";
//
// label7
//
label7.AutoSize = true;
label7.Location = new Point(6, 25);
label7.Name = "label7";
label7.Size = new Size(26, 17);
label7.TabIndex = 0;
label7.Text = "X1:";
//
// ctrlTitleBar
//
ctrlTitleBar.Dock = DockStyle.Top;
ctrlTitleBar.Location = new Point(0, 0);
ctrlTitleBar.MinimumSize = new Size(0, 36);
ctrlTitleBar.Name = "ctrlTitleBar";
ctrlTitleBar.Padding = new Padding(3);
ctrlTitleBar.Size = new Size(198, 36);
ctrlTitleBar.TabIndex = 11;
ctrlTitleBar.Title = "直线测量";
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(canvas);
panel1.Controls.Add(statusStrip1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(1076, 640);
panel1.TabIndex = 1;
//
// canvas
//
canvas.AllowMultiSelect = false;
canvas.CreateMode = Canvas.Shape.ShapeTypeEnum.Polygon;
canvas.Dock = DockStyle.Fill;
canvas.Enabled = false;
canvas.FillDrawing = false;
canvas.Location = new Point(0, 0);
canvas.Margin = new Padding(2);
canvas.Name = "canvas";
canvas.OutsideShapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.OutsideShapes");
canvas.Scale = 1F;
canvas.Shapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.Shapes");
canvas.Size = new Size(1074, 616);
canvas.TabIndex = 2;
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { lblStatus });
statusStrip1.Location = new Point(0, 616);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(1074, 22);
statusStrip1.TabIndex = 1;
statusStrip1.Text = "statusStrip1";
//
// lblStatus
//
lblStatus.Name = "lblStatus";
lblStatus.Size = new Size(44, 17);
lblStatus.Text = " ";
//
// GuideLineCtrl
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(splitContainer);
Controls.Add(lblElapsed);
Controls.Add(label4);
Name = "GuideLineCtrl";
Size = new Size(1280, 640);
Load += GuideLineCircleCtrl_Load;
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer).EndInit();
splitContainer.ResumeLayout(false);
panelGuide.ResumeLayout(false);
panelGuide.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth1).EndInit();
panel1.ResumeLayout(false);
panel1.PerformLayout();
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label lblElapsed;
private Label label4;
private SplitContainer splitContainer;
private Panel panelGuide;
private Panel panel1;
private Canvas.UI.FlyCanvas canvas;
private StatusStrip statusStrip1;
private ToolStripStatusLabel lblStatus;
private GroupBox groupBox2;
private TextBox tbLineX2;
private Label label8;
private TextBox tbLineY2;
private Label label5;
private TextBox tbLineX1;
private TextBox tbLineY1;
private Label label6;
private Label label7;
private CtrlTitleBar ctrlTitleBar;
private Button btnLoadImage;
private Label label9;
private Button btnExecute;
private Label label10;
private Button btnCreateLine;
private TextBox tbRectWidth1;
private Label label11;
private NumericUpDown NumRectWidth1;
private Label lblResult;
private Label label1;
private Button btnSave;
}
}

View File

@ -0,0 +1,387 @@
using CanFly.Canvas.Helper;
using CanFly.Canvas.Shape;
using CanFly.Canvas.UI;
using CanFly.Helper;
using HalconDotNet;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CanFly.UI.GuidePanel
{
public partial class GuideLineCtrl : BaseGuideControl
{
private FlyShape? _line;
private float _lineX1;
private float _lineY1;
private float _lineX2;
private float _lineY2;
private float _lineWidth;
private PointF[] _rectPoints = new PointF[4];
//private float _LineLX=new float();
//private float _LineLY =new float();
//private float _LineRX =new float();
//private float _LineRY =new float();
protected override string GetScriptFileName() => "Line_detect.hdvp";
public GuideLineCtrl()
{
InitializeComponent();
this.canvas.mouseMoved += Canvas_mouseMoved;
this.canvas.OnShapeUpdateEvent += UpdateShape;
this.canvas.selectionChanged += Canvas_selectionChanged;
this.canvas.OnShapeMoving += Canvas_OnShapeMoving;
this.canvas.newShape += Canvas_newShape;
this.ctrlTitleBar.OnCloseClicked += OnControlClose;
NumRectWidth1.ValueChanged -= NumRectWidth1_ValueChanged;
NumRectWidth1.Value = 40;
NumRectWidth1.ValueChanged += NumRectWidth1_ValueChanged;
}
protected override void UpdateShape(FlyShape shape)
{
switch (shape.ShapeType)
{
case ShapeTypeEnum.Line:
this._line = shape;
_line.IsDrawLineVirtualRect = true;
var pts = this._line.Points;
_lineX1 = pts[0].X;
_lineY1 = pts[0].Y;
_lineX2 = pts[1].X;
_lineY2 = pts[1].Y;
_lineWidth = shape.LineVirtualRectWidth;
_rectPoints = shape.LineVirtualRectPoints;
//_LineLX = (shape.LineVirtualRectPoints[0].X + shape.LineVirtualRectPoints[3].X) / 2;
//_LineLY = (shape.LineVirtualRectPoints[0].Y + shape.LineVirtualRectPoints[3].Y) / 2;
//_LineRX = (shape.LineVirtualRectPoints[1].X + shape.LineVirtualRectPoints[2].X) / 2;
//_LineRY = (shape.LineVirtualRectPoints[1].Y + shape.LineVirtualRectPoints[2].Y) / 2;
tbLineX1.Text = _lineX1.ToString("F3");
tbLineY1.Text = _lineY1.ToString("F3");
tbLineX2.Text = _lineX2.ToString("F3");
tbLineY2.Text = _lineY2.ToString("F3");
// NumRectWidth1.Value = (decimal)_lineWidth;
break;
default:
break;
}
}
private void GuideLineCircleCtrl_Load(object sender, EventArgs e)
{
}
private void Canvas_mouseMoved(PointF pos)
{
if (InvokeRequired)
{
Invoke(Canvas_mouseMoved, pos);
return;
}
lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
//if (shapes.Count != 1)
//{
// // panelGuide.Controls.Clear();
// return;
//}
//SwitchGuideForm(shapes[0].ShapeType);
// Canvas_OnShapeUpdateEvent(shapes[0]);
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void btnCreateLine_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
tbLineX1.Text = string.Empty;
tbLineY1.Text = string.Empty;
tbLineX2.Text = string.Empty;
tbLineY2.Text = string.Empty;
this.canvas.Shapes.RemoveAll(shp => shp.ShapeType == ShapeTypeEnum.Line);
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Line);
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
OpenImageFile(bitmap =>
{
this.canvas.LoadPixmap(bitmap);
this.canvas.Enabled = true;
});
}
private void Canvas_newShape()
{
this.canvas.StopDraw();
}
string strarrayX = string.Empty;
string strarrayY = string.Empty;
private void btnExecute_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
if (this.tbLineX1.Text.Trim().Length == 0)
{
MessageBox.Show("请先创建直线");
return;
}
this.canvas.OutsideShapes.Clear();
this.canvas.Invalidate();
flag = new List<double>();
RowBegin = new List<double>();
ColBegin = new List<double>();
RowEnd = new List<double>();
ColEnd = new List<double>();
Dictionary<string, HObject> inputImg = new Dictionary<string, HObject>();
if (hImage == null)
{
HOperatorSet.ReadImage(out hImage, CurrentImageFile);
}
inputImg["INPUT_Image"] = hImage;
// 创建一维数组
Dictionary<string, HTuple> inputPara = new Dictionary<string, HTuple>();
// 获取矩形的 4 个点
PointF[] Points = this._line.LineVirtualRectPoints;
PointF Point1 = Points[0];
PointF Point2 = Points[1];
PointF Point3 = Points[2];
PointF Point4 = Points[3];
PointF Point5 = Points[0];
float x1 = Point1.X;
float y1 = Point1.Y;
float x2 = Point2.X;
float y2 = Point2.Y;
float x3 = Point3.X;
float y3 = Point3.Y;
float x4 = Point4.X;
float y4 = Point4.Y;
float x5 = Point5.X;
float y5 = Point5.Y;
float[] arrayX = new float[] { x1, x2, x3, x4, x5 };
HTuple hTupleArrayX = new HTuple(arrayX);
float[] arrayY = new float[] { y1, y2, y3, y4, y5 };
HTuple hTupleArrayY = new HTuple(arrayY);
strarrayX = string.Join(",", arrayX);
strarrayY = string.Join(",", arrayY);
inputPara["LX"] = _lineX1;
inputPara["LY"] = _lineY1;
inputPara["RX"] = _lineX2;
inputPara["RY"] = _lineY2;
inputPara["XRect"] = hTupleArrayX;
inputPara["YRect"] = hTupleArrayY;
List<string> outputKeys = new List<string>()
{
"OUTPUT_Flag",
"RowBegin",
"ColBegin",
"RowEnd",
"ColEnd"
};
ExecuteHScript(
inputImg,
inputPara,
outputKeys);
}
List<double> flag = new List<double>();
List<double> RowBegin = new List<double>();
List<double> ColBegin = new List<double>();
List<double> RowEnd = new List<double>();
List<double> ColEnd = new List<double>();
protected override void OnExecuteHScriptResult(
bool success,
Dictionary<string, HTuple> resultDic,
int timeElasped)
{
if (!success)
{
return;
}
/*
"OUTPUT_Flag",
"RXCenter",
"RYCenter",
"RRadius"
*/
flag = resultDic["OUTPUT_Flag"].HTupleToDouble();
RowBegin = resultDic["RowBegin"].HTupleToDouble();
ColBegin = resultDic["ColBegin"].HTupleToDouble();
RowEnd = resultDic["RowEnd"].HTupleToDouble();
ColEnd = resultDic["ColEnd"].HTupleToDouble();
if (flag.Count > 0)
{
lblResult.Text = flag[0].ToString();
}
else
{
lblResult.Text = "无";
}
if (flag.Count > 0 && RowBegin.Count > 0 && ColBegin.Count > 0 && RowEnd.Count > 0 && ColEnd.Count > 0)
{
float width = 0;
this.canvas.DrawLine(new PointF((float)ColBegin[0], (float)RowBegin[0]), new PointF((float)ColEnd[0], (float)RowEnd[0]), width);
this.canvas.Invalidate();
lblElapsed.Text = $"{timeElasped} ms";
}
}
private void NumRectWidth1_ValueChanged(object sender, EventArgs e)
{
if (_line != null)
{
//_line1.IsDrawLineVirtualRect = true;
_line.LineVirtualRectWidth = (float)NumRectWidth1.Value;
UpdateShape(_line);
this.canvas.Invalidate();
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (lblResult.Text.Equals("无"))
{
MessageBox.Show("请先进行绘制");
return;
}
if (lblResult.Text != "0")
{
MessageBox.Show("测量计算错误,无法保存");
return;
}
//flag = resultDic["OUTPUT_Flag"].HTupleToDouble();
//RowBegin = resultDic["RowBegin"].HTupleToDouble();
//ColBegin = resultDic["ColBegin"].HTupleToDouble();
//RowEnd = resultDic["RowEnd"].HTupleToDouble();
//ColEnd = resultDic["ColEnd"].HTupleToDouble();
string input = $"LX:{_lineX1};" +
$"LY:{_lineY1};" +
$"RX:{_lineX2};" +
$"RY:{_lineY2};" +
$"Line_XRect:{strarrayX};" +
$"Line_YRect:{strarrayY}";
string result = $"RowBegin:{string.Join(";", RowBegin[0])};ColBegin:{string.Join(";", ColBegin[0])};RowEnd:{string.Join(";", RowEnd[0])};ColEnd:{string.Join(";", ColEnd[0])}";
DataToTriggerEvent(input, result);
}
}
}

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
<data name="canvas.OutsideShapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<data name="canvas.Shapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,570 @@
namespace CanFly.UI.GuidePanel
{
partial class GuideLineLineCtrl
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GuideLineLineCtrl));
lblStatus = new ToolStripStatusLabel();
panel1 = new Panel();
canvas = new Canvas.UI.FlyCanvas();
statusStrip1 = new StatusStrip();
ctrlTitleBar = new CtrlTitleBar();
tbLine1X2 = new TextBox();
label8 = new Label();
tbLine1Y2 = new TextBox();
label5 = new Label();
label10 = new Label();
tbLine1X1 = new TextBox();
tbLine1Y1 = new TextBox();
label6 = new Label();
label7 = new Label();
btnLoadImage = new Button();
label9 = new Label();
btnExecute = new Button();
panelGuide = new Panel();
lblDistance = new Label();
label17 = new Label();
lblResult = new Label();
label15 = new Label();
groupBox3 = new GroupBox();
NumRectWidth2 = new NumericUpDown();
label2 = new Label();
tbLine2X2 = new TextBox();
label11 = new Label();
tbLine2Y2 = new TextBox();
label12 = new Label();
tbLine2X1 = new TextBox();
tbLine2Y1 = new TextBox();
label13 = new Label();
label14 = new Label();
groupBox2 = new GroupBox();
NumRectWidth1 = new NumericUpDown();
label1 = new Label();
splitContainer = new SplitContainer();
lblElapsed = new Label();
label4 = new Label();
btnSave = new Button();
panel1.SuspendLayout();
statusStrip1.SuspendLayout();
panelGuide.SuspendLayout();
groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth2).BeginInit();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth1).BeginInit();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
SuspendLayout();
//
// lblStatus
//
lblStatus.Name = "lblStatus";
lblStatus.Size = new Size(44, 17);
lblStatus.Text = " ";
//
// panel1
//
panel1.BorderStyle = BorderStyle.FixedSingle;
panel1.Controls.Add(canvas);
panel1.Controls.Add(statusStrip1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(1076, 640);
panel1.TabIndex = 1;
//
// canvas
//
canvas.AllowMultiSelect = false;
canvas.CreateMode = Canvas.Shape.ShapeTypeEnum.Polygon;
canvas.Dock = DockStyle.Fill;
canvas.Enabled = false;
canvas.FillDrawing = false;
canvas.Location = new Point(0, 0);
canvas.Margin = new Padding(2);
canvas.Name = "canvas";
canvas.OutsideShapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.OutsideShapes");
canvas.Scale = 1F;
canvas.Shapes = (List<Canvas.Shape.FlyShape>)resources.GetObject("canvas.Shapes");
canvas.Size = new Size(1074, 616);
canvas.TabIndex = 2;
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { lblStatus });
statusStrip1.Location = new Point(0, 616);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(1074, 22);
statusStrip1.TabIndex = 1;
statusStrip1.Text = "statusStrip1";
//
// ctrlTitleBar
//
ctrlTitleBar.Dock = DockStyle.Top;
ctrlTitleBar.Location = new Point(0, 0);
ctrlTitleBar.MinimumSize = new Size(0, 36);
ctrlTitleBar.Name = "ctrlTitleBar";
ctrlTitleBar.Padding = new Padding(3);
ctrlTitleBar.Size = new Size(198, 36);
ctrlTitleBar.TabIndex = 11;
ctrlTitleBar.Title = "线线测量";
//
// tbLine1X2
//
tbLine1X2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine1X2.Location = new Point(56, 80);
tbLine1X2.Name = "tbLine1X2";
tbLine1X2.Size = new Size(134, 23);
tbLine1X2.TabIndex = 9;
//
// label8
//
label8.AutoSize = true;
label8.Location = new Point(6, 83);
label8.Name = "label8";
label8.Size = new Size(26, 17);
label8.TabIndex = 8;
label8.Text = "X2:";
//
// tbLine1Y2
//
tbLine1Y2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine1Y2.Location = new Point(56, 109);
tbLine1Y2.Name = "tbLine1Y2";
tbLine1Y2.Size = new Size(134, 23);
tbLine1Y2.TabIndex = 7;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(6, 112);
label5.Name = "label5";
label5.Size = new Size(25, 17);
label5.TabIndex = 6;
label5.Text = "Y2:";
//
// label10
//
label10.AutoSize = true;
label10.Location = new Point(6, 521);
label10.Name = "label10";
label10.Size = new Size(44, 17);
label10.TabIndex = 16;
label10.Text = "耗时:";
//
// tbLine1X1
//
tbLine1X1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine1X1.Location = new Point(56, 22);
tbLine1X1.Name = "tbLine1X1";
tbLine1X1.Size = new Size(134, 23);
tbLine1X1.TabIndex = 5;
//
// tbLine1Y1
//
tbLine1Y1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine1Y1.Location = new Point(56, 51);
tbLine1Y1.Name = "tbLine1Y1";
tbLine1Y1.Size = new Size(134, 23);
tbLine1Y1.TabIndex = 4;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(6, 54);
label6.Name = "label6";
label6.Size = new Size(25, 17);
label6.TabIndex = 1;
label6.Text = "Y1:";
//
// label7
//
label7.AutoSize = true;
label7.Location = new Point(6, 25);
label7.Name = "label7";
label7.Size = new Size(26, 17);
label7.TabIndex = 0;
label7.Text = "X1:";
//
// btnLoadImage
//
btnLoadImage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnLoadImage.Location = new Point(6, 394);
btnLoadImage.Name = "btnLoadImage";
btnLoadImage.Size = new Size(184, 32);
btnLoadImage.TabIndex = 18;
btnLoadImage.Text = "打开图片";
btnLoadImage.UseVisualStyleBackColor = true;
btnLoadImage.Click += btnLoadImage_Click;
//
// label9
//
label9.AutoSize = true;
label9.Location = new Point(54, 521);
label9.Name = "label9";
label9.Size = new Size(32, 17);
label9.TabIndex = 17;
label9.Text = "0ms";
//
// btnExecute
//
btnExecute.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnExecute.Location = new Point(5, 432);
btnExecute.Name = "btnExecute";
btnExecute.Size = new Size(184, 32);
btnExecute.TabIndex = 15;
btnExecute.Text = "执行";
btnExecute.UseVisualStyleBackColor = true;
btnExecute.Click += btnExecute_Click;
//
// panelGuide
//
panelGuide.BorderStyle = BorderStyle.FixedSingle;
panelGuide.Controls.Add(btnSave);
panelGuide.Controls.Add(lblDistance);
panelGuide.Controls.Add(label17);
panelGuide.Controls.Add(lblResult);
panelGuide.Controls.Add(label15);
panelGuide.Controls.Add(groupBox3);
panelGuide.Controls.Add(btnLoadImage);
panelGuide.Controls.Add(label9);
panelGuide.Controls.Add(btnExecute);
panelGuide.Controls.Add(label10);
panelGuide.Controls.Add(groupBox2);
panelGuide.Controls.Add(ctrlTitleBar);
panelGuide.Dock = DockStyle.Fill;
panelGuide.Location = new Point(0, 0);
panelGuide.Name = "panelGuide";
panelGuide.Size = new Size(200, 640);
panelGuide.TabIndex = 0;
//
// lblDistance
//
lblDistance.AutoSize = true;
lblDistance.Location = new Point(54, 493);
lblDistance.Name = "lblDistance";
lblDistance.Size = new Size(15, 17);
lblDistance.TabIndex = 25;
lblDistance.Text = "0";
//
// label17
//
label17.AutoSize = true;
label17.Location = new Point(6, 493);
label17.Name = "label17";
label17.Size = new Size(44, 17);
label17.TabIndex = 24;
label17.Text = "距离:";
//
// lblResult
//
lblResult.AutoSize = true;
lblResult.Location = new Point(54, 467);
lblResult.Name = "lblResult";
lblResult.Size = new Size(20, 17);
lblResult.TabIndex = 23;
lblResult.Text = "无";
//
// label15
//
label15.AutoSize = true;
label15.Location = new Point(6, 467);
label15.Name = "label15";
label15.Size = new Size(44, 17);
label15.TabIndex = 22;
label15.Text = "结果:";
//
// groupBox3
//
groupBox3.Controls.Add(NumRectWidth2);
groupBox3.Controls.Add(label2);
groupBox3.Controls.Add(tbLine2X2);
groupBox3.Controls.Add(label11);
groupBox3.Controls.Add(tbLine2Y2);
groupBox3.Controls.Add(label12);
groupBox3.Controls.Add(tbLine2X1);
groupBox3.Controls.Add(tbLine2Y1);
groupBox3.Controls.Add(label13);
groupBox3.Controls.Add(label14);
groupBox3.Dock = DockStyle.Top;
groupBox3.Location = new Point(0, 216);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(198, 172);
groupBox3.TabIndex = 21;
groupBox3.TabStop = false;
groupBox3.Text = "线2参数";
//
// NumRectWidth2
//
NumRectWidth2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
NumRectWidth2.Location = new Point(53, 138);
NumRectWidth2.Maximum = new decimal(new int[] { 9000, 0, 0, 0 });
NumRectWidth2.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
NumRectWidth2.Name = "NumRectWidth2";
NumRectWidth2.Size = new Size(136, 23);
NumRectWidth2.TabIndex = 13;
NumRectWidth2.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 140);
label2.Name = "label2";
label2.Size = new Size(35, 17);
label2.TabIndex = 12;
label2.Text = "宽度:";
//
// tbLine2X2
//
tbLine2X2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine2X2.Location = new Point(56, 80);
tbLine2X2.Name = "tbLine2X2";
tbLine2X2.Size = new Size(134, 23);
tbLine2X2.TabIndex = 9;
//
// label11
//
label11.AutoSize = true;
label11.Location = new Point(6, 83);
label11.Name = "label11";
label11.Size = new Size(26, 17);
label11.TabIndex = 8;
label11.Text = "X2:";
//
// tbLine2Y2
//
tbLine2Y2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine2Y2.Location = new Point(56, 109);
tbLine2Y2.Name = "tbLine2Y2";
tbLine2Y2.Size = new Size(136, 23);
tbLine2Y2.TabIndex = 7;
//
// label12
//
label12.AutoSize = true;
label12.Location = new Point(6, 112);
label12.Name = "label12";
label12.Size = new Size(25, 17);
label12.TabIndex = 6;
label12.Text = "Y2:";
//
// tbLine2X1
//
tbLine2X1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine2X1.Location = new Point(56, 22);
tbLine2X1.Name = "tbLine2X1";
tbLine2X1.Size = new Size(134, 23);
tbLine2X1.TabIndex = 5;
//
// tbLine2Y1
//
tbLine2Y1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tbLine2Y1.Location = new Point(56, 51);
tbLine2Y1.Name = "tbLine2Y1";
tbLine2Y1.Size = new Size(134, 23);
tbLine2Y1.TabIndex = 4;
//
// label13
//
label13.AutoSize = true;
label13.Location = new Point(6, 54);
label13.Name = "label13";
label13.Size = new Size(25, 17);
label13.TabIndex = 1;
label13.Text = "Y1:";
//
// label14
//
label14.AutoSize = true;
label14.Location = new Point(6, 25);
label14.Name = "label14";
label14.Size = new Size(26, 17);
label14.TabIndex = 0;
label14.Text = "X1:";
//
// groupBox2
//
groupBox2.Controls.Add(NumRectWidth1);
groupBox2.Controls.Add(label1);
groupBox2.Controls.Add(tbLine1X2);
groupBox2.Controls.Add(label8);
groupBox2.Controls.Add(tbLine1Y2);
groupBox2.Controls.Add(label5);
groupBox2.Controls.Add(tbLine1X1);
groupBox2.Controls.Add(tbLine1Y1);
groupBox2.Controls.Add(label6);
groupBox2.Controls.Add(label7);
groupBox2.Dock = DockStyle.Top;
groupBox2.Location = new Point(0, 36);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(198, 180);
groupBox2.TabIndex = 13;
groupBox2.TabStop = false;
groupBox2.Text = "线1参数";
//
// NumRectWidth1
//
NumRectWidth1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
NumRectWidth1.Location = new Point(54, 138);
NumRectWidth1.Maximum = new decimal(new int[] { 9000, 0, 0, 0 });
NumRectWidth1.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
NumRectWidth1.Name = "NumRectWidth1";
NumRectWidth1.Size = new Size(135, 23);
NumRectWidth1.TabIndex = 11;
NumRectWidth1.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 140);
label1.Name = "label1";
label1.Size = new Size(35, 17);
label1.TabIndex = 10;
label1.Text = "宽度:";
//
// splitContainer
//
splitContainer.Dock = DockStyle.Fill;
splitContainer.Location = new Point(0, 0);
splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
splitContainer.Panel1.Controls.Add(panelGuide);
splitContainer.Panel1MinSize = 150;
//
// splitContainer.Panel2
//
splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = new Size(1280, 640);
splitContainer.SplitterDistance = 200;
splitContainer.TabIndex = 11;
//
// lblElapsed
//
lblElapsed.AutoSize = true;
lblElapsed.Location = new Point(50, 328);
lblElapsed.Name = "lblElapsed";
lblElapsed.Size = new Size(32, 17);
lblElapsed.TabIndex = 13;
lblElapsed.Text = "0ms";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(0, 328);
label4.Name = "label4";
label4.Size = new Size(44, 17);
label4.TabIndex = 12;
label4.Text = "耗时:";
//
// btnSave
//
btnSave.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
btnSave.Location = new Point(3, 541);
btnSave.Name = "btnSave";
btnSave.Size = new Size(186, 32);
btnSave.TabIndex = 26;
btnSave.Text = "保存数据";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += btnSave_Click;
//
// GuideLineLineCtrl
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(splitContainer);
Controls.Add(lblElapsed);
Controls.Add(label4);
Name = "GuideLineLineCtrl";
Size = new Size(1280, 640);
panel1.ResumeLayout(false);
panel1.PerformLayout();
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
panelGuide.ResumeLayout(false);
panelGuide.PerformLayout();
groupBox3.ResumeLayout(false);
groupBox3.PerformLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth2).EndInit();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)NumRectWidth1).EndInit();
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer).EndInit();
splitContainer.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
}
#endregion
private ToolStripStatusLabel lblStatus;
private Panel panel1;
private Canvas.UI.FlyCanvas canvas;
private StatusStrip statusStrip1;
private CtrlTitleBar ctrlTitleBar;
private TextBox tbLine1X2;
private Label label8;
private TextBox tbLine1Y2;
private Label label5;
private Label label10;
private TextBox tbLine1X1;
private TextBox tbLine1Y1;
private Label label6;
private Label label7;
private Button btnLoadImage;
private Label label9;
private Button btnExecute;
private Panel panelGuide;
private GroupBox groupBox2;
private SplitContainer splitContainer;
private Label lblElapsed;
private Label label4;
private GroupBox groupBox3;
private TextBox tbLine2X2;
private Label label11;
private TextBox tbLine2Y2;
private Label label12;
private TextBox tbLine2X1;
private TextBox tbLine2Y1;
private Label label13;
private Label label14;
private Label label1;
private Label label2;
private NumericUpDown NumRectWidth2;
private NumericUpDown NumRectWidth1;
private Label lblDistance;
private Label label17;
private Label lblResult;
private Label label15;
private Button btnSave;
}
}

View File

@ -0,0 +1,526 @@
using CanFly.Canvas.Helper;
using CanFly.Canvas.Shape;
using CanFly.Helper;
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CanFly.UI.GuidePanel
{
public partial class GuideLineLineCtrl : BaseGuideControl
{
private FlyShape? _line1;
private FlyShape? _line2;
private float _line1X1;
private float _line1Y1;
private float _line1X2;
private float _line1Y2;
private float _lineWidth;
private float _line2X1;
private float _line2Y1;
private float _line2X2;
private float _line2Y2;
private float _line2Width;
protected override string GetScriptFileName() => "LineToLine.hdvp";
public GuideLineLineCtrl()
{
InitializeComponent();
this.canvas.mouseMoved += Canvas_mouseMoved;
this.canvas.OnShapeUpdateEvent += UpdateShape;
this.canvas.selectionChanged += Canvas_selectionChanged;
this.canvas.OnShapeMoving += Canvas_OnShapeMoving;
this.canvas.newShape += Canvas_newShape;
this.ctrlTitleBar.OnCloseClicked += OnControlClose;
NumRectWidth1.ValueChanged -= NumRectWidth1_ValueChanged;
NumRectWidth1.Value = 40;
NumRectWidth1.ValueChanged += NumRectWidth1_ValueChanged;
NumRectWidth2.ValueChanged -= NumericUpDown2_ValueChanged;
NumRectWidth2.Value = 40;
NumRectWidth2.ValueChanged += NumericUpDown2_ValueChanged;
}
protected override void UpdateShape(FlyShape shape)
{
switch (shape.ShapeType)
{
case ShapeTypeEnum.Line:
// 判断是否为第一条直线或第二条直线
if (_line1 == shape)
{
//_line1 = shape;
var pts1 = _line1.Points;
_line1X1 = pts1[0].X;
_line1Y1 = pts1[0].Y;
_line1X2 = pts1[1].X;
_line1Y2 = pts1[1].Y;
_lineWidth = _line1.LineVirtualRectWidth;
tbLine1X1.Text = _line1X1.ToString("F3");
tbLine1Y1.Text = _line1Y1.ToString("F3");
tbLine1X2.Text = _line1X2.ToString("F3");
tbLine1Y2.Text = _line1Y2.ToString("F3");
//NumRectWidth1.Value = (decimal)_lineWidth;
}
else
{
//_line2 = shape;
var pts2 = _line2.Points;
_line2X1 = pts2[0].X;
_line2Y1 = pts2[0].Y;
_line2X2 = pts2[1].X;
_line2Y2 = pts2[1].Y;
_line2Width = _line2.LineVirtualRectWidth;
tbLine2X1.Text = _line2X1.ToString("F3");
tbLine2Y1.Text = _line2Y1.ToString("F3");
tbLine2X2.Text = _line2X2.ToString("F3");
tbLine2Y2.Text = _line2Y2.ToString("F3");
// NumRectWidth2.Value = (decimal)_line2Width;
}
break;
default:
break;
}
}
private void GuideLineCircleCtrl_Load(object sender, EventArgs e)
{
}
private void Canvas_mouseMoved(PointF pos)
{
if (InvokeRequired)
{
Invoke(Canvas_mouseMoved, pos);
return;
}
lblStatus.Text = $"X:{pos.X}, Y:{pos.Y}";
}
private void Canvas_selectionChanged(List<FlyShape> shapes)
{
//if (shapes.Count != 1)
//{
// // panelGuide.Controls.Clear();
// return;
//}
//SwitchGuideForm(shapes[0].ShapeType);
// Canvas_OnShapeUpdateEvent(shapes[0]);
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void Canvas_OnShapeMoving(List<FlyShape> shapes)
{
if (shapes.Count != 1)
{
return;
}
UpdateShape(shapes[0]);
}
private void Canvas_newShape()
{
// 自动切换到下一条直线绘制
if (_line1 == null)
{
_line1 = this.canvas.Shapes.LastOrDefault(shp => shp.ShapeType == ShapeTypeEnum.Line);
}
else if (_line2 == null)
{
_line2 = this.canvas.Shapes.LastOrDefault(shp => shp.ShapeType == ShapeTypeEnum.Line);
}
// 停止绘制模式,用户可以根据需要重新启用
this.canvas.StopDraw();
//this.canvas.StopDraw();
}
private void btnCreateLineOne_Click(object sender, EventArgs e)
{
// this.canvas.Shapes.RemoveAll(shp => shp == _line1); // 移除第一条直线
this._line1 = null;
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Line); // 启动绘制模式
this.canvas.Enabled = true;
}
private void btnCreateLineTwo_Click(object sender, EventArgs e)
{
// this.canvas.Shapes.RemoveAll(shp => shp == _line2); // 移除第二条直线
this._line2 = null;
this.canvas.Invalidate();
this.canvas.StartDraw(ShapeTypeEnum.Line); // 启动绘制模式
this.canvas.Enabled = true;
}
private void btnExecute_Click(object sender, EventArgs e)
{
if (this.canvas.pixmap == null)
{
MessageBox.Show("请先打开图片");
return;
}
this.canvas.OutsideShapes.Clear();
this.canvas.Invalidate();
flag = new List<double>();
Distance = new List<double>();
Line1_RowBegin = new List<double>();
Line1_ColBegin = new List<double>();
Line1_RowEnd = new List<double>();
Line1_ColEnd = new List<double>();
Line2_RowBegin = new List<double>();
Line2_ColBegin = new List<double>();
Line2_RowEnd = new List<double>();
Line2_ColEnd = new List<double>();
Dictionary<string, HObject> inputImg = new Dictionary<string, HObject>();
if (hImage == null)
{
HOperatorSet.ReadImage(out hImage, CurrentImageFile);
}
inputImg["INPUT_Image"] = hImage;
Dictionary<string, HTuple> inputPara = new Dictionary<string, HTuple>();
// 获取矩形的 4 个点
PointF[] Points = this._line1.LineVirtualRectPoints;
if (Points.Count() < 4)
{
return;
}
PointF Point1 = Points[0];
PointF Point2 = Points[1];
PointF Point3 = Points[2];
PointF Point4 = Points[3];
PointF Point5 = Points[0];
float x1 = Point1.X;
float y1 = Point1.Y;
float x2 = Point2.X;
float y2 = Point2.Y;
float x3 = Point3.X;
float y3 = Point3.Y;
float x4 = Point4.X;
float y4 = Point4.Y;
float x5 = Point5.X;
float y5 = Point5.Y;
float[] array1X = new float[] { x1, x2, x3, x4, x5 };
HTuple hTupleArray1X = new HTuple(array1X);
float[] array1Y = new float[] { y1, y2, y3, y4, y5 };
HTuple hTupleArray1Y = new HTuple(array1Y);
strarray1X = string.Join(",", array1X);
strarray1Y = string.Join(",", array1Y);
// 获取矩形的 4 个点
PointF[] Points2 = this._line2.LineVirtualRectPoints;
if (Points2.Count() < 4)
{
return;
}
PointF Point21 = Points2[0];
PointF Point22 = Points2[1];
PointF Point23 = Points2[2];
PointF Point24 = Points2[3];
PointF Point25 = Points2[0];
float x21 = Point21.X;
float y21 = Point21.Y;
float x22 = Point22.X;
float y22 = Point22.Y;
float x23 = Point23.X;
float y23 = Point23.Y;
float x24 = Point24.X;
float y24 = Point24.Y;
float x25 = Point25.X;
float y25 = Point25.Y;
float[] array2X = new float[] { x21, x22, x23, x24, x25 };
HTuple hTupleArray2X = new HTuple(array2X);
float[] array2Y = new float[] { y21, y22, y23, y24, y25 };
HTuple hTupleArray2Y = new HTuple(array2Y);
strarray2X = string.Join(",", array2X);
strarray2Y = string.Join(",", array2Y);
inputPara["Line1_LX"] = _line1X1;
inputPara["Line1_LY"] = _line1Y1;
inputPara["Line1_RX"] = _line1X2;
inputPara["Line1_RY"] = _line1Y2;
inputPara["Line2_LX"] = _line2X1;
inputPara["Line2_LY"] = _line2Y1;
inputPara["Line2_RX"] = _line2X2;
inputPara["Line2_RY"] = _line2Y2;
inputPara["Line1_XRect"] = hTupleArray1X;
inputPara["Line1_YRect"] = hTupleArray1Y;
inputPara["Line2_XRect"] = hTupleArray2X;
inputPara["Line2_YRect"] = hTupleArray2Y;
List<string> outputKeys = new List<string>()
{
"OUTPUT_Flag",
"Distance",
"Line1_RowBegin",
"Line1_ColBegin",
"Line1_RowEnd",
"Line1_ColEnd",
"Line2_RowBegin",
"Line2_ColBegin",
"Line2_RowEnd",
"Line2_ColEnd"
};
ExecuteHScript(
inputImg,
inputPara,
outputKeys);
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
OpenImageFile(bitmap =>
{
this.canvas.LoadPixmap(bitmap);
this.canvas.Enabled = true;
_line1 = new FlyShape();
_line2 = new FlyShape();
_line1.AddPoint(new Point(10, 10));
_line1.AddPoint(new Point(50, 10));
_line2.AddPoint(new Point(10, 20));
_line2.AddPoint(new Point(60, 20));
_line1.ShapeType = ShapeTypeEnum.Line;
_line2.ShapeType = ShapeTypeEnum.Line;
_line1.IsDrawLineVirtualRect = true;
_line1.LineVirtualRectWidth = 40;
_line2.IsDrawLineVirtualRect = true;
_line2.LineVirtualRectWidth = 40;
canvas.Shapes.Add(_line1);
canvas.Shapes.Add(_line2);
canvas.Invalidate();
UpdateShape(_line1);
UpdateShape(_line2);
});
}
string strarray1X = string.Empty;
string strarray1Y = string.Empty;
string strarray2X = string.Empty;
string strarray2Y = string.Empty;
List<double> flag =new List<double>();
List<double> Distance = new List<double>();
List<double> Line1_RowBegin = new List<double>();
List<double> Line1_ColBegin = new List<double>();
List<double> Line1_RowEnd = new List<double>();
List<double> Line1_ColEnd = new List<double>();
List<double> Line2_RowBegin = new List<double>();
List<double> Line2_ColBegin = new List<double>();
List<double> Line2_RowEnd = new List<double>();
List<double> Line2_ColEnd = new List<double>();
protected override void OnExecuteHScriptResult(
bool success,
Dictionary<string, HTuple> resultDic,
int timeElasped)
{
if (!success)
{
return;
}
//"OUTPUT_Flag",
// "Distance",
// "Line1_RowBegin",
// "Line1_ColBegin",
// "Line1_RowEnd",
// "Line1_ColEnd",
// "Line2_RowBegin",
// "Line2_ColBegin",
// "Line2_RowEnd",
// "Line2_ColEnd"
flag = resultDic["OUTPUT_Flag"].HTupleToDouble();
Distance = resultDic["Distance"].HTupleToDouble();
Line1_RowBegin = resultDic["Line1_RowBegin"].HTupleToDouble();
Line1_ColBegin = resultDic["Line1_ColBegin"].HTupleToDouble();
Line1_RowEnd = resultDic["Line1_RowEnd"].HTupleToDouble();
Line1_ColEnd = resultDic["Line1_ColEnd"].HTupleToDouble();
Line2_RowBegin = resultDic["Line2_RowBegin"].HTupleToDouble();
Line2_ColBegin = resultDic["Line2_ColBegin"].HTupleToDouble();
Line2_RowEnd = resultDic["Line2_RowEnd"].HTupleToDouble();
Line2_ColEnd = resultDic["Line2_ColEnd"].HTupleToDouble();
if (flag.Count > 0)
{
lblResult.Text = flag[0].ToString();
}
else
{
lblResult.Text = "无";
}
if (Distance.Count > 0)
{
lblDistance.Text = Distance[0].ToString();
}
else
{
lblDistance.Text = "0";
}
if (flag.Count > 0 && Distance.Count > 0 && Line1_RowBegin.Count > 0 && Line1_ColBegin.Count > 0 && Line1_RowEnd.Count > 0 && Line1_ColEnd.Count > 0 && Line2_RowBegin.Count > 0 && Line2_ColBegin.Count > 0 && Line2_RowEnd.Count > 0 && Line2_ColEnd.Count > 0)
{
float width = 0;
this.canvas.DrawLine(new PointF((float)Line1_ColBegin[0], (float)Line1_RowBegin[0]), new PointF((float)Line1_ColEnd[0], (float)Line1_RowEnd[0]), width);
this.canvas.DrawLine(new PointF((float)Line2_ColBegin[0], (float)Line2_RowBegin[0]), new PointF((float)Line2_ColEnd[0], (float)Line2_RowEnd[0]), width);
this.canvas.Invalidate();
lblElapsed.Text = $"{timeElasped} ms";
}
}
private void NumRectWidth1_ValueChanged(object sender, EventArgs e)
{
if (_line1 != null)
{
//_line1.IsDrawLineVirtualRect = true;
_line1.LineVirtualRectWidth = (float)NumRectWidth1.Value;
UpdateShape(_line1);
this.canvas.Invalidate();
}
}
private void NumericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (_line2 != null)
{
// _line2.IsDrawLineVirtualRect = true;
_line2.LineVirtualRectWidth = (float)NumRectWidth2.Value;
UpdateShape(_line2);
this.canvas.Invalidate();
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (lblResult.Text.Equals("无"))
{
MessageBox.Show("请先进行绘制");
return;
}
if (lblResult.Text != "0")
{
MessageBox.Show("测量计算错误,无法保存");
return;
}
//inputPara["Line1_LX"] = _line1X1;
//inputPara["Line1_LY"] = _line1Y1;
//inputPara["Line1_RX"] = _line1X2;
//inputPara["Line1_RY"] = _line1Y2;
//inputPara["Line2_LX"] = _line2X1;
//inputPara["Line2_LY"] = _line2Y1;
//inputPara["Line2_RX"] = _line2X2;
//inputPara["Line2_RY"] = _line2Y2;
//inputPara["Line1_XRect"] = hTupleArray1X;
//inputPara["Line1_YRect"] = hTupleArray1Y;
//inputPara["Line2_XRect"] = hTupleArray2X;
//inputPara["Line2_YRect"] = hTupleArray2Y;
string input = $"Line1_LX:{_line1X1};" +
$"Line1_LY:{_line1Y1};" +
$"Line1_RX:{_line1X2};" +
$"Line1_RY:{_line1Y2};" +
$"Line2_LX:{_line2X1};" +
$"Line2_LY:{_line2Y1};" +
$"Line2_RX:{_line2X2};" +
$"Line2_RY:{_line2Y2};" +
$"Line1_XRect:{strarray1X};" +
$"Line1_YRect:{strarray1Y};" +
$"Line2_XRect:{strarray2X};" +
$"Line2_YRect:{strarray2Y}"
;
string result = $"Distance:{Distance[0]}";
DataToTriggerEvent(input, result);
}
}
}

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
<data name="canvas.OutsideShapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<data name="canvas.Shapes" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERDYW5GbHkuQ2FudmFzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAQBAAAAdlN5c3RlbS5Db2xsZWN0aW9ucy5HZW5l
cmljLkxpc3RgMVtbQ2FuRmx5LkNhbnZhcy5TaGFwZS5GbHlTaGFwZSwgQ2FuRmx5LkNhbnZhcywgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsXV0DAAAABl9pdGVtcwVfc2l6ZQhfdmVyc2lv
bgQAAB5DYW5GbHkuQ2FudmFzLlNoYXBlLkZseVNoYXBlW10CAAAACAgJAwAAAAAAAAAAAAAADAQAAAAz
Q2FuRmx5LkNhbnZhcywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBwMAAAAAAQAA
AAAAAAAEHENhbkZseS5DYW52YXMuU2hhcGUuRmx5U2hhcGUEAAAACw==
</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

41
CanFly/Util/FormUtils.cs Normal file
View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanFly.Util
{
public static class FormUtils
{
/// <summary>
/// 显示窗体
/// </summary>
/// <param name="panel"></param>
/// <param name="frm"></param>
public static void ShowForm(this Panel panel, Form frm)
{
try
{
frm.TopLevel = false;
panel.Controls.Clear();
panel.Controls.Add(frm);
frm.Show();
frm.Dock = DockStyle.Fill;
panel.Refresh();
foreach (Control item in frm.Controls)
{
item.Focus();
break;
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}

63
CanFly/XKRS.CanFly.csproj Normal file
View File

@ -0,0 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\</BaseOutputPath>
<AppendTargetFrameworkToOutputPath>output</AppendTargetFrameworkToOutputPath>
<UseWindowsForms>true</UseWindowsForms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Halcon\**" />
<EmbeddedResource Remove="Halcon\**" />
<None Remove="Halcon\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CanFly.Canvas\CanFly.Canvas.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="OpenCvSharp4" Version="4.10.0.20241108" />
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.10.0.20241108" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.10.0.20241108" />
</ItemGroup>
<ItemGroup>
<Reference Include="halcondotnet">
<HintPath>..\x64\Debug\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="hdevenginedotnet">
<HintPath>..\x64\Debug\hdevenginedotnet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -11,7 +11,7 @@ namespace DH.Devices.Devices
public virtual bool isEnabled { get; set; } = false; public virtual bool isEnabled { get; set; } = false;
[Category("采图模式")] [Category("采图模式")]
[Description("是否连续模式true连续模式采图false触发模式采图")] [Description("是否连续模式 true连续模式采图false触发模式采图")]
[DisplayName("连续模式")] [DisplayName("连续模式")]
public bool IsContinueMode { get; set; } = false; public bool IsContinueMode { get; set; } = false;
@ -31,7 +31,7 @@ namespace DH.Devices.Devices
public ImageFormat ImageFormat { get; set; } = ImageFormat.Jpeg; public ImageFormat ImageFormat { get; set; } = ImageFormat.Jpeg;
[Category("采图模式")] [Category("采图模式")]
[Description("是否硬触发模式true硬触发false软触发")] [Description("是否硬触发模式 true硬触发false软触发")]
[DisplayName("硬触发")] [DisplayName("硬触发")]
public bool IsHardwareTrigger { get; set; } = false; public bool IsHardwareTrigger { get; set; } = false;
@ -45,7 +45,7 @@ namespace DH.Devices.Devices
// public StreamFormat dvpStreamFormat = dvpStreamFormat.; // public StreamFormat dvpStreamFormat = dvpStreamFormat.;
[Category("采图模式")] [Category("采图模式")]
[Description("是否传感器直接硬触发true传感器硬触发不通过软件触发false通过软件触发IO 的硬触发模式")] [Description("是否传感器直接硬触发 true传感器硬触发不通过软件触发false通过软件触发IO 的硬触发模式")]
[DisplayName("是否传感器直接硬触发")] [DisplayName("是否传感器直接硬触发")]
public bool IsDirectHardwareTrigger { get; set; } = false; public bool IsDirectHardwareTrigger { get; set; } = false;

View File

@ -7,6 +7,10 @@ using System.Text;
using System.Drawing.Design; using System.Drawing.Design;
using AntdUI; using AntdUI;
using System.Text.Json.Serialization;
using static DH.Commons.Enums.EnumHelper;
using System.Collections.ObjectModel;
namespace DH.Commons.Enums namespace DH.Commons.Enums
{ {
@ -116,20 +120,20 @@ namespace DH.Commons.Enums
/// </summary> /// </summary>
public class DetectionResultDetail public class DetectionResultDetail
{ {
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelBGR { get; set; }//识别到对象的标签BGR public string LabelBGR { get; set; }//识别到对象的标签BGR
public int LabelNo { get; set; } // 识别到对象的标签索引 public int LabelNo { get; set; } // 识别到对象的标签索引
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelName { get; set; }//识别到对象的标签名称 public string LabelName { get; set; }//识别到对象的标签名称
public double Score { get; set; }//识别目标结果的可能性、得分 public double Score { get; set; }//识别目标结果的可能性、得分
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelDisplay { get; set; }//识别到对象的 显示信息 public string LabelDisplay { get; set; }//识别到对象的 显示信息
@ -150,10 +154,10 @@ namespace DH.Commons.Enums
public class MLResult public class MLResult
{ {
public bool IsSuccess = false; public bool IsSuccess = false;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string ResultMessage; public string ResultMessage;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public Bitmap ResultMap; public Bitmap ResultMap;
public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>(); public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>();
@ -177,8 +181,8 @@ namespace DH.Commons.Enums
public bool IsGPU; public bool IsGPU;
public int GPUId; public int GPUId;
public float Score_thre; public float Score_thre;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public MLInit(string modelFile, bool isGPU, int gpuId, float score_thre) public MLInit(string modelFile, bool isGPU, int gpuId, float score_thre)
@ -203,18 +207,18 @@ namespace DH.Commons.Enums
} }
public class DetectStationResult public class DetectStationResult
{ {
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string Pid { get; set; } public string Pid { get; set; }
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string TempPid { get; set; } public string TempPid { get; set; }
/// <summary> /// <summary>
/// 检测工位名称 /// 检测工位名称
/// </summary> /// </summary>
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string DetectName { get; set; } public string DetectName { get; set; }
@ -261,9 +265,9 @@ namespace DH.Commons.Enums
public int StationDetectElapsed { get; set; } public int StationDetectElapsed { get; set; }
public static string NormalizeAndClean(string input) public static string NormalizeAndClean(string input)
{ {
#pragma warning disable CS8603 // 可能返回 null 引用 #pragma warning disable CS8603 // 可能返回 null 引用
if (input == null) return null; if (input == null) return null;
#pragma warning restore CS8603 // 可能返回 null 引用 #pragma warning restore CS8603 // 可能返回 null 引用
// Step 1: 标准化字符编码为 Form C (规范组合) // Step 1: 标准化字符编码为 Form C (规范组合)
string normalizedString = input.Normalize(NormalizationForm.FormC); string normalizedString = input.Normalize(NormalizationForm.FormC);
@ -288,6 +292,7 @@ namespace DH.Commons.Enums
[Category("关联相机")] [Category("关联相机")]
[DisplayName("相机源ID")] [DisplayName("相机源ID")]
[Description("关联相机的唯一标识符")] [Description("关联相机的唯一标识符")]
[JsonPropertyName("camera_sourceId")]
//[TypeConverter(typeof(CollectionCountConvert))] //[TypeConverter(typeof(CollectionCountConvert))]
public string CameraSourceId public string CameraSourceId
{ {
@ -461,193 +466,217 @@ namespace DH.Commons.Enums
return new CustomizedPoint(p1.X + p2.X, p1.Y + p2.Y); return new CustomizedPoint(p1.X + p2.X, p1.Y + p2.Y);
} }
} }
// public class PreTreatParam // public class PreTreatParam
// { // {
// /// <summary> // /// <summary>
// /// 参数名称 // /// 参数名称
// /// </summary> // /// </summary>
// /// // ///
// [Category("预处理参数")] // [Category("预处理参数")]
// [DisplayName("参数名称")] // [DisplayName("参数名称")]
// [Description("参数名称")] // [Description("参数名称")]
//#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 //
// public string Name { get; set; } // public string Name { get; set; }
// /// <summary> // /// <summary>
// /// 参数值 // /// 参数值
// /// </summary> // /// </summary>
// /// // ///
// [Category("预处理参数")] // [Category("预处理参数")]
// [DisplayName("参数值")] // [DisplayName("参数值")]
// [Description("参数值")] // [Description("参数值")]
//#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 //
// public string Value { get; set; } // public string Value { get; set; }
// } // }
public class DetectionConfig public class DetectionConfig : NotifyProperty
{ {
#region
[JsonPropertyName("id")]
[ReadOnly(true)] [ReadOnly(true)]
public string Id { get; set; } = Guid.NewGuid().ToString(); public string Id { get; private set; } = Guid.NewGuid().ToString();
[Category("检测配置")] [Category("检测配置")]
[DisplayName("检测配置名称")] [DisplayName("检测配置名称")]
[Description("检测配置名称")] [Description("检测配置名称")]
[JsonPropertyName("name")]
public string Name { get; set; } public string Name { get; set; }
#endregion
#region
[Category("关联相机")] [Category("关联相机")]
[DisplayName("关联相机")] [DisplayName("关联相机")]
[Description("关联相机描述")] [Description("关联相机描述")]
[JsonPropertyName("camera_source_id")]
public string CameraSourceId { get; set; } = ""; public string CameraSourceId { get; set; } = "";
[Category("关联相机集合")] [Category("关联相机集合")]
[DisplayName("关联相机集合")] [DisplayName("关联相机集合")]
[Description("关联相机描述")] [Description("关联相机描述")]
//[TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))] [JsonPropertyName("camera_Collects")]
public List<RelatedCamera> CameraCollects { get; set; } = new();
#endregion
public List<RelatedCamera> CameraCollects { get; set; } = new List<RelatedCamera>();
#region
[Category("启用配置")] [Category("启用配置")]
[DisplayName("是否启用GPU检测")] [DisplayName("是否启用GPU检测")]
[Description("是否启用GPU检测")] [JsonPropertyName("is_enable_gpu")]
public bool IsEnableGPU { get; set; } = false; public bool IsEnableGPU { get; set; }
[Category("启用配置")] [Category("启用配置")]
[DisplayName("是否混料模型")] [DisplayName("是否混料模型")]
[Description("是否混料模型")] [JsonPropertyName("is_mixModel")]
public bool IsMixModel { get; set; } = false; public bool IsMixModel { get; set; }
[Category("启用配置")] [Category("启用配置")]
[DisplayName("是否启用该检测")] [DisplayName("是否启用该检测")]
[Description("是否启用该检测")] [JsonPropertyName("is_enabled")]
public bool IsEnabled { get; set; } public bool IsEnabled { get; set; }
[Category("启用配置")] [Category("启用配置")]
[DisplayName("是否加入检测工位")] [DisplayName("是否启用预处理")]
[Description("是否加入检测工位")] [JsonPropertyName("is_PreEnabled")]
public bool IsAddStation { get; set; } = true; public bool IsPreEnabled { get; set; }
// public bool IsAddStation { get; set; } = true;
private bool _isAddStation;
[Category("启用配置")]
[DisplayName("是否加入检测工位")]
[JsonPropertyName("is_addstation")]
public bool IsAddStation
{
get => _isAddStation;
set
{
if (_isAddStation != value)
{
_isAddStation = value;
OnPropertyChanged(nameof(IsAddStation));
}
}
}
#endregion
#region
[Category("1.预处理(视觉算子)")] [Category("1.预处理(视觉算子)")]
[DisplayName("预处理-算法文件路径")] [DisplayName("预处理-算法文件路径")]
// [Description("预处理算法文件路径配置")][Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] [JsonPropertyName("halcon_algorithemPath_pre")]
public string HalconAlgorithemPath_Pre { get; set; } public string HalconAlgorithemPath_Pre { get; set; }
// [Category("1.预处理(视觉算子)")]
//[DisplayName("预处理-输出结果的SPEC标准")]
//[Description("预处理输出结果的SPEC标准配置")]
// public List<IndexedSpec> OutputSpec_Pre { get; set; } = new List<IndexedSpec>();
[Category("1.预处理(视觉算子)")] [Category("1.预处理(视觉算子)")]
[DisplayName("预处理-参数列表")] [DisplayName("预处理-参数列表")]
[Description("预处理-参数列表")] [JsonPropertyName("pre_treatParams")]
public List<PreTreatParam> PreTreatParams { get; set; } = new();
public List<PreTreatParam> PreTreatParams { get; set; } = new List<PreTreatParam>();
[Category("1.预处理(视觉算子)")] [Category("1.预处理(视觉算子)")]
[DisplayName("预处理-输出参数列表")] [DisplayName("预处理-输出参数列表")]
[Description("预处理-输出参数列表")] [JsonPropertyName("out_preTreatParams")]
public List<PreTreatParam> OUTPreTreatParams { get; set; } = new();
public List<PreTreatParam> OUTPreTreatParams { get; set; } = new List<PreTreatParam>(); #endregion
#region
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型类型")] [DisplayName("模型类型")]
[Description("模型类型ImageClassification-图片分类ObjectDetection目标检测Segmentation-图像分割")] [JsonPropertyName("model_Type")]
//[TypeConverter(typeof(EnumDescriptionConverter<MLModelType>))]
public MLModelType ModelType { get; set; } = MLModelType.ObjectDetection; public MLModelType ModelType { get; set; } = MLModelType.ObjectDetection;
//[Category("2.中检测(深度学习)")]
//[DisplayName("中检测-GPU索引")]
//[Description("GPU索引")]
//public int GPUIndex { get; set; } = 0;
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型文件路径")] [DisplayName("模型文件路径")]
[Description("中处理 深度学习模型文件路径,路径中不可含有中文字符,一般情况可以只配置中检测模型,当需要先用预检测过滤一次时,请先配置好与预检测相关配置")] [JsonPropertyName("model_Path")]
public string ModelPath { get; set; } public string ModelPath { get; set; }
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型宽度")] [DisplayName("模型宽度")]
[Description("中处理-模型宽度")] [JsonPropertyName("model_Width")]
public int ModelWidth { get; set; } = 640; public int ModelWidth { get; set; } = 640;
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型高度")] [DisplayName("模型高度")]
[Description("中处理-模型高度")] [JsonPropertyName("model_Height")]
public int ModelHeight { get; set; } = 640; public int ModelHeight { get; set; } = 640;
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型节点名称")] [DisplayName("模型节点名称")]
[Description("中处理-模型节点名称")] [JsonPropertyName("model_outNodeName")]
public string ModeloutNodeName { get; set; } = "output0"; public string ModeloutNodeName { get; set; } = "output0";
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型置信度")] [DisplayName("模型置信度")]
[Description("中处理-模型置信度")] [JsonPropertyName("model_confThreshold")]
public float ModelconfThreshold { get; set; } = 0.5f; public float ModelconfThreshold { get; set; } = 0.5f;
[Category("2.中检测(深度学习)")] [Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型标签路径")] [DisplayName("模型标签路径")]
[Description("中处理-模型标签路径")] [JsonPropertyName("in_lablepath")]
public string in_lable_path { get; set; } public string in_lable_path { get; set; }
#endregion
#region
// public List<SizeTreatParam> PreTreatCollects { get; set; } = new();
private List<SizeTreatParam> _preTreatParams = new();
[Category("1.尺寸测量集合")]
[DisplayName("尺寸测量集合")]
[JsonPropertyName("Pre_TreatCollects")]
public List<SizeTreatParam> PreTreatCollects
{
get => _preTreatParams;
set
{
if (_preTreatParams != value)
{
_preTreatParams = value;
OnPropertyChanged(nameof(PreTreatCollects));
}
}
}
#endregion
#region
[Category("4.最终过滤(逻辑过滤)")] [Category("4.最终过滤(逻辑过滤)")]
[DisplayName("过滤器集合")] [DisplayName("过滤器集合")]
[Description("最后的逻辑过滤:可根据 识别出对象的 宽度、高度、面积、得分来设置最终检测结果,同一识别目标同一判定,多项过滤器之间为“或”关系")] [JsonPropertyName("detection_filterList")]
public List<DetectionFilter> DetectionFilterList { get; set; } = new();
public List<DetectionFilter> DetectionFilterList { get; set; } = new List<DetectionFilter>(); #endregion
#region
[JsonPropertyName("Detection_LableList")]
public List<DetectionLable> DetectionLableList { get; set; } = new();
/// <summary>
/// 标签集合
/// </summary>
public List<DetectionLable> DetectionLableList { get; set; } = new List<DetectionLable>();
//[Category("深度学习配置")]
//[DisplayName("检测配置标签")]
//[Description("检测配置标签关联")]
//public List<DetectConfigLabel> DetectConfigLabelList { get; set; } = new List<DetectConfigLabel>();
[Category("显示配置")] [Category("显示配置")]
[DisplayName("显示位置")] [DisplayName("显示位置")]
[Description("检测信息显示位置。左上角为11向右向下为正方向")] [JsonPropertyName("Show_Location")]
// [TypeConverter(typeof(ComplexObjectConvert))] public CustomizedPoint ShowLocation { get; set; } = new();
// [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] #endregion
public CustomizedPoint ShowLocation { get; set; } = new CustomizedPoint(); //public event PropertyChangedEventHandler PropertyChanged;
public DetectionConfig() //protected virtual void OnPropertyChanged(string propertyName)
//{
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
//}
#region
public DetectionConfig() { }
public DetectionConfig(string name, MLModelType modelType, string modelPath, bool isEnableGPU, string sCameraSourceId)
{ {
}
public DetectionConfig(string name, MLModelType modelType, string modelPath, bool isEnableGPU,string sCameraSourceId)
{
ModelPath = modelPath ?? string.Empty;
Name = name; Name = name;
ModelType = modelType; ModelType = modelType;
ModelPath = modelPath ?? string.Empty;
IsEnableGPU = isEnableGPU; IsEnableGPU = isEnableGPU;
Id = Guid.NewGuid().ToString();
CameraSourceId = sCameraSourceId; CameraSourceId = sCameraSourceId;
Id = Guid.NewGuid().ToString();
} }
#endregion
} }
//大改预处理类 //大改预处理类
@ -659,6 +688,7 @@ namespace DH.Commons.Enums
private bool _selected = false; private bool _selected = false;
public bool Selected public bool Selected
{ {
get { return _selected; } get { return _selected; }
@ -669,6 +699,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(Selected)); OnPropertyChanged(nameof(Selected));
} }
} }
[JsonPropertyName("name")]
private string _name; private string _name;
public string Name public string Name
{ {
@ -683,6 +714,7 @@ namespace DH.Commons.Enums
private string _value; private string _value;
[JsonPropertyName("value")]
public string Value public string Value
{ {
get { return _value; } get { return _value; }
@ -697,7 +729,9 @@ namespace DH.Commons.Enums
private CellLink[] cellLinks; private CellLink[] cellLinks;
public CellLink[] CellLinks public CellLink[] CellLinks
{ {
get { return cellLinks; } get {
return cellLinks; }
set set
{ {
if (cellLinks == value) return; if (cellLinks == value) return;
@ -736,6 +770,7 @@ namespace DH.Commons.Enums
} }
[JsonPropertyName("labelId")]
public string LabelId public string LabelId
{ {
get { return _labelId; } get { return _labelId; }
@ -746,7 +781,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(LabelId)); OnPropertyChanged(nameof(LabelId));
} }
} }
[JsonPropertyName("labelName")]
public string LabelName public string LabelName
{ {
get { return _labelName; } get { return _labelName; }
@ -757,7 +792,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(LabelName)); OnPropertyChanged(nameof(LabelName));
} }
} }
[JsonPropertyName("maxSource")]
public double MaxSource public double MaxSource
{ {
get { return _maxSource; } get { return _maxSource; }
@ -769,6 +804,7 @@ namespace DH.Commons.Enums
} }
} }
[JsonPropertyName("minSource")]
public double MinSource public double MinSource
{ {
get { return _minSource; } get { return _minSource; }
@ -779,7 +815,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(MinSource)); OnPropertyChanged(nameof(MinSource));
} }
} }
[JsonPropertyName("maxArea")]
public double MaxArea public double MaxArea
{ {
get { return _maxArea; } get { return _maxArea; }
@ -790,7 +826,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(MaxArea)); OnPropertyChanged(nameof(MaxArea));
} }
} }
[JsonPropertyName("minArea")]
public double MinArea public double MinArea
{ {
get { return _minArea; } get { return _minArea; }
@ -801,7 +837,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(MinArea)); OnPropertyChanged(nameof(MinArea));
} }
} }
[JsonPropertyName("_resultState")]
public ResultState ResultState public ResultState ResultState
{ {
get { return _resultState; } get { return _resultState; }
@ -812,6 +848,182 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(ResultState)); OnPropertyChanged(nameof(ResultState));
} }
} }
private CellLink[] cellLinks;
public CellLink[] CellLinks
{
get {
return cellLinks; }
set
{
if (cellLinks == value) return;
cellLinks = value;
OnPropertyChanged(nameof(CellLinks));
}
}
}
public class PreTreatCollect
{
[Category("尺寸测量集合")]
[DisplayName("预处理-算法文件路径")]
[Description("预处理算法文件路径配置")]
[JsonPropertyName("halconPath_Pre")]
// [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
public string HalconPath_Pre { get; set; }
[Category("尺寸测量集合")]
[DisplayName("输入参数列表")]
[Description("输入参数列表")]
[JsonPropertyName("preParams")]
// [TypeConverter(typeof(CollectionCountConvert))]
// [Editor(typeof(ComplexCollectionEditor<PreTreatParam>), typeof(UITypeEditor))]
public List<PreTreatParam> PreParams { get; set; } = new List<PreTreatParam>();
[Category("尺寸测量集合")]
[DisplayName("输出参数列表")]
[Description("输出参数列表")]
[JsonPropertyName("outPreParams")]
// [TypeConverter(typeof(CollectionCountConvert))]
// [Editor(typeof(ComplexCollectionEditor<PreTreatParam>), typeof(UITypeEditor))]
public List<PreTreatParam> outPreParams { get; set; } = new List<PreTreatParam>();
[Category("尺寸测量集合")]
[DisplayName("预处理-名称")]
[Description("预处理名称")]
[JsonPropertyName("preName")]
public string PreName { get; set; }
[Category("尺寸测量集合")]
[DisplayName("预处理-启用")]
[Description("预处理启用")]
[JsonPropertyName("preIsEnable")]
public bool PreIsEnable { get; set; } = false;
[Category("尺寸测量集合")]
[DisplayName("类型")]
[Description("类型")]
[JsonPropertyName("preType")]
// [TypeConverter(typeof(EnumDescriptionConverter<SizeEnum>))]
public SizeEnum PreType { get; set; }
[Category("尺寸测量集合")]
[DisplayName("阈值")]
[Description("阈值")]
[JsonPropertyName("prePix")]
public int PrePix { get; set; }
}
public class SizeTreatParam : NotifyProperty
{
private bool _selected = false;
private bool _isEnable;
private string _preName;
private int _prePix;
private SizeEnum _preType;
private string _resultShow;
private string _outResultShow;
private string _prePath;
public bool Selected
{
get { return _selected; }
set
{
if (_selected == value) return;
_selected = value;
OnPropertyChanged(nameof(Selected));
}
}
public bool IsEnable
{
get { return _isEnable; }
set
{
if (_isEnable == value) return;
_isEnable = value;
OnPropertyChanged(nameof(IsEnable));
}
}
public string PreName
{
get { return _preName; }
set
{
if (_preName == value) return;
_preName = value;
OnPropertyChanged(nameof(PreName));
}
}
public SizeEnum PreType
{
get { return _preType; }
set
{
if (_preType == value) return;
_preType = value;
OnPropertyChanged(nameof(PreType));
}
}
public int PrePix
{
get { return _prePix; }
set
{
if (_prePix.Equals(value)) return;
_prePix = value;
OnPropertyChanged(nameof(PrePix));
}
}
public string ResultShow
{
get { return _resultShow; }
set
{
if (_resultShow == value) return;
_resultShow = value;
OnPropertyChanged(nameof(ResultShow));
}
}
public string OutResultShow
{
get { return _outResultShow; }
set
{
if (_outResultShow == value) return;
_outResultShow = value;
OnPropertyChanged(nameof(OutResultShow));
}
}
//public string PrePath
//{
// get { return _prePath; }
// set
// {
// if (_prePath.Equals(value)) return;
// _prePath = value;
// OnPropertyChanged(nameof(PrePath));
// }
//}
private CellLink[] cellLinks; private CellLink[] cellLinks;
public CellLink[] CellLinks public CellLink[] CellLinks
@ -825,8 +1037,6 @@ namespace DH.Commons.Enums
} }
} }
} }
/// <summary> /// <summary>
/// 识别目标定义 class分类信息 Detection Segmentation要识别的对象 /// 识别目标定义 class分类信息 Detection Segmentation要识别的对象
/// </summary> /// </summary>
@ -867,7 +1077,7 @@ namespace DH.Commons.Enums
[DisplayName("检测项标签")] [DisplayName("检测项标签")]
[Description("检测标签Id")] [Description("检测标签Id")]
//[TypeConverter(typeof(DetectionLabelConverter))] //[TypeConverter(typeof(DetectionLabelConverter))]
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelId { get; set; } public string LabelId { get; set; }

View File

@ -650,15 +650,15 @@ namespace DH.Commons.Enums
public enum SizeEnum public enum SizeEnum
{ {
[Description("圆形测量")] [Description("圆形测量")]
Circle = 1, = 1,
[Description("直线测量")] [Description("直线测量")]
Line = 2, 线 = 2,
[Description("线线测量")] [Description("线线测量")]
LineLine = 3, 线线 = 3,
[Description("线圆测量")] [Description("线圆测量")]
LineCircle = 4, 线 = 4,
[Description("高度测量")] [Description("高度测量")]
Height = 5, = 5,
} }
public enum MachineState public enum MachineState
@ -674,31 +674,31 @@ namespace DH.Commons.Enums
Warning = 8, Warning = 8,
} }
public enum ResultState //public enum ResultState
{ //{
[Description("NA")] // [Description("NA")]
NA = -5, // NA = -5,
[Description("尺寸NG")] // [Description("尺寸NG")]
SizeNG = -4, // SizeNG = -4,
[Description("检测NG")] // [Description("检测NG")]
DetectNG = -3, // DetectNG = -3,
//[Description("检测不足TBD")] // //[Description("检测不足TBD")]
// ShortageTBD = -2, // // ShortageTBD = -2,
[Description("检测结果TBD")] // [Description("检测结果TBD")]
ResultTBD = -1, // ResultTBD = -1,
[Description("OK")] // [Description("OK")]
OK = 1, // OK = 1,
// [Description("NG")] // // [Description("NG")]
// NG = 2, // // NG = 2,
//统计结果 // //统计结果
[Description("A类NG")] // [Description("A类NG")]
A_NG = 25, // A_NG = 25,
[Description("B类NG")] // [Description("B类NG")]
B_NG = 26, // B_NG = 26,
[Description("C类NG")] // [Description("C类NG")]
C_NG = 27, // C_NG = 27,
} //}
public enum HikCameraType public enum HikCameraType
{ {
[Description("HikCamera-Gige")] [Description("HikCamera-Gige")]

View File

@ -571,8 +571,8 @@ namespace DH.Commons.Enums
} }
//分别基于像素GetPixel和SetPixel、基于内存、基于指针这三种方法增强图片对比度 //分别基于像素GetPixel和SetPixel、基于内存、基于指针这三种方法增强图片对比度
// 第一种方法:像素提取法速度慢 基于像素400-600ms // 第一种方法:像素提取法 速度慢 基于像素400-600ms
public static Bitmap MethodBaseOnPixel(Bitmap bitmap, int degree) public static Bitmap MethodBaseOnPixel(Bitmap bitmap, int degree)
{ {
Color curColor; Color curColor;

View File

@ -108,7 +108,7 @@ namespace DH.Commons.Enums
                DataGridViewCheckboxHeaderEventArgs ex = new DataGridViewCheckboxHeaderEventArgs();                 DataGridViewCheckboxHeaderEventArgs ex = new DataGridViewCheckboxHeaderEventArgs();
ex.CheckedState = _checked; ex.CheckedState = _checked;
object sender = new object();//此处不代表选择的列头checkbox只是作为参数传递因为列头checkbox是绘制出来的无法获得它的实例 object sender = new object();//此处不代表选择的列头checkbox只是作为参数传递 因为列头checkbox是绘制出来的无法获得它的实例
                if (OnCheckBoxClicked != null)                 if (OnCheckBoxClicked != null)
{ {

View File

@ -409,7 +409,7 @@ namespace MCDLL_NET
/******************************************************************************************************************************************************************** /********************************************************************************************************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD>ж<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ݡ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD>ж<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
********************************************************************************************************************************************************************/ ********************************************************************************************************************************************************************/
@ -1005,8 +1005,8 @@ namespace MCDLL_NET
/// </summary> /// </summary>
/// <param name="Axis"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param> /// <param name="Axis"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <param name="Stop_Time"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣʱ<CDA3><20><>Χ 0 -1000ms<6D><73><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD>ͣ<EFBFBD><CDA3> /// <param name="Stop_Time"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣʱ<CDA3><20><>Χ 0 -1000ms<6D><73><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD>ͣ<EFBFBD><CDA3>
/// ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײԭ<D7B2>㻺ͣʱ<CDA3><EFBFBD><E4A3AC>Ҫ<EFBFBD><D2AA><EFBFBD>ϻ<EFBFBD><CFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĸ<C3B5><C4B8>ٶ<EFBFBD><D9B6>ٶȣ<D9B6><C8A3>͵<EFBFBD><CDB5>ٶ<EFBFBD><D9B6>ٶȵĴ<C8B5><C4B4> /// ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײԭ<D7B2>㻺ͣʱ<CDA3><EFBFBD><E4A3AC>Ҫ<EFBFBD><D2AA><EFBFBD>ϻ<EFBFBD><CFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĸ<C3B5><C4B8>ٶ<EFBFBD><D9B6>ٶȣ<D9B6><C8A3>͵<EFBFBD><CDB5>ٶ<EFBFBD><D9B6>ٶȵĴ<C8B5><C4B4><EFBFBD>
/// <20><><EFBFBD>ô<EFBFBD><C3B4>˻<EFBFBD><CBBB><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ԭ<EFBFBD><D4AD>ʱ<EFBFBD><CAB1><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD>м</param> /// <20><><EFBFBD>ô<EFBFBD><C3B4>˻<EFBFBD><CBBB><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ԭ<EFBFBD><D4AD>ʱ<EFBFBD><CAB1><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD>м<EFBFBD> </param>
/// <param name="StationNumber">վ<><D5BE><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>Ϊ 0</param> /// <param name="StationNumber">վ<><D5BE><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>Ϊ 0</param>
/// <returns></returns> /// <returns></returns>
[DllImport("MCDLL_NET.DLL", EntryPoint = "MCF_Search_Home_Stop_Time_Net")] [DllImport("MCDLL_NET.DLL", EntryPoint = "MCF_Search_Home_Stop_Time_Net")]

View File

@ -444,17 +444,17 @@ namespace DH.Devices.Motion
//[Category("回原点设置")] //[Category("回原点设置")]
//[DisplayName("回原点模式")] //[DisplayName("回原点模式")]
//[Description("HomeMode回原点模式0一般模式 1极限限位模式 2外部触发模式")] //[Description("HomeMode回原点模式 0一般模式 1极限限位模式 2外部触发模式")]
//public int HomeMode { get; set; } = 0; //public int HomeMode { get; set; } = 0;
//[Category("回原点设置")] //[Category("回原点设置")]
//[DisplayName("回原点方向")] //[DisplayName("回原点方向")]
//[Description("IsHomePositive回原点方向 true正方向开始 false负方向开始")] //[Description("IsHomePositive回原点方向 true正方向开始 false负方向开始")]
//public bool IsHomePositive { get; set; } = true; //public bool IsHomePositive { get; set; } = true;
//[Category("回原点设置")] //[Category("回原点设置")]
//[DisplayName("是否自动回原点")] //[DisplayName("是否自动回原点")]
//[Description("IsAutoGoHome是否自动回原点 true是 false否")] //[Description("IsAutoGoHome是否自动回原点 true是 false否")]
//public bool IsAutoGoHome { get; set; } = false; //public bool IsAutoGoHome { get; set; } = false;
//[Category("超时设置")] //[Category("超时设置")]
@ -601,7 +601,7 @@ namespace DH.Devices.Motion
[Category("回原点参数")] [Category("回原点参数")]
[DisplayName("碰撞原点缓停时间")] [DisplayName("碰撞原点缓停时间")]
[Description("SearchHomeStopTime触发缓停时间范围 0-1000ms默认急停注意:设置碰撞原点缓停时间,需要配合回零设置的高速段速度,和低速度速度的搭配设置大了会出现过冲的现象,设置小了停止的时候会有抖动,需要调节时间,尽量设置找到原点时候在开关中间")] [Description("SearchHomeStopTime触发缓停时间范围 0-1000ms默认急停 注意:设置碰撞原点缓停时间,需要配合回零设置的高速段速度,和低速度速度的搭配 设置大了会出现过冲的现象,设置小了停止的时候会有抖动,需要调节时间,尽量设置找到原点时候在开关中间 ")]
public ushort SearchHomeStopTime { get; set; } = 0; public ushort SearchHomeStopTime { get; set; } = 0;

View File

@ -314,9 +314,9 @@ namespace DH.Devices.Motion
// //设置物件检测有效电平 0是低电平 1是高电平 // //设置物件检测有效电平 0是低电平 1是高电平
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Logic_Net((ushort)SortingInputSetting.BitInputNumber, 0); // rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Logic_Net((ushort)SortingInputSetting.BitInputNumber, 0);
// //设置来料检测编码器 双转盘要设置两个轴 // //设置来料检测编码器 双转盘要设置两个轴
// /*Bit_Input_Number设置位号 // /*Bit_Input_Number设置位号
// 取值: Bit_Input_0, Bit_Input_1 // 取值: Bit_Input_0, Bit_Input_1
// Axis: 轴号 // Axis: 轴号
// Source跟随方式 // Source跟随方式
// 取值0命令 // 取值0命令
// 1编码器(默认) // 1编码器(默认)
@ -1655,7 +1655,7 @@ namespace DH.Devices.Motion
#region IMonitor #region IMonitor
/// <summary> /// <summary>
/// 位置捕获监听,入料检测 /// 位置捕获监听,入料检测
/// 入料检测对射开关接到了HOME口每当有新料到达入料检测传感器时程序把当前位置当作原点并调用<see cref="SolidMotionCardBase.CapturePositionChanged(int, int)"/>函数 /// 入料检测对射开关接到了HOME口每当有新料到达入料检测传感器时程序把当前位置当作原点并调用<see cref="SolidMotionCardBase.CapturePositionChanged(int, int)"/>函数
/// </summary> /// </summary>
private void MonitorPieces() private void MonitorPieces()
@ -1796,7 +1796,7 @@ namespace DH.Devices.Motion
// Picese_sizeStr += i.ToString()+":"+Piece_Size[i]+"\t"; // Picese_sizeStr += i.ToString()+":"+Piece_Size[i]+"\t";
// Picese_DistanceizeStr += i.ToString()+":"+ Piece_Distance_To_next[i]+"\t"; // Picese_DistanceizeStr += i.ToString()+":"+ Piece_Distance_To_next[i]+"\t";
//} //}
// LogAsync(DateTime.Now, LogLevel.Information, $"转盘{station}产品入列 , {piecesCountDic[station]} size:{Piece_Size[Piece_Size.Length - 1]}"); // LogAsync(DateTime.Now, LogLevel.Information, $"转盘{station}产品入列 , {piecesCountDic[station]} size:{Piece_Size[Piece_Size.Length - 1]} ");
// LogAsync(DateTime.Now, LogLevel.Information, $"转盘{station}产品入列 ,监听piece_find{tmpPieceNumber} 监听物件大小" + Picese_sizeStr+",物件间距"+ Picese_DistanceizeStr+"相机经过个数"+Piece_Cross_Camera); // LogAsync(DateTime.Now, LogLevel.Information, $"转盘{station}产品入列 ,监听piece_find{tmpPieceNumber} 监听物件大小" + Picese_sizeStr+",物件间距"+ Picese_DistanceizeStr+"相机经过个数"+Piece_Cross_Camera);
if (tmpPieceNumber != piecesCountDic[station] + 1) if (tmpPieceNumber != piecesCountDic[station] + 1)
{ {

View File

@ -104,9 +104,9 @@ namespace DH.Devices.Vision
// json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}"; // json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}";
// //
Console.WriteLine("检测结果JSON" + json); Console.WriteLine("检测结果JSON" + json);
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
HYoloResult detResult = JsonConvert.DeserializeObject<HYoloResult>(json); HYoloResult detResult = JsonConvert.DeserializeObject<HYoloResult>(json);
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
if (detResult == null) if (detResult == null)
{ {
return; return;
@ -234,15 +234,15 @@ namespace DH.Devices.Vision
{ {
originMat?.Dispose(); originMat?.Dispose();
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
originMat = null; originMat = null;
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
//maskMat?.Dispose(); //maskMat?.Dispose();
// maskMat = null; // maskMat = null;
detectMat?.Dispose(); detectMat?.Dispose();
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
detectMat = null; detectMat = null;
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
// maskWeighted?.Dispose(); // maskWeighted?.Dispose();
// maskWeighted = null; // maskWeighted = null;
// GC.Collect(); // GC.Collect();

View File

@ -127,9 +127,9 @@ namespace DH.Devices.Vision
// json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}"; // json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}";
// //
Console.WriteLine("检测结果JSON" + json); Console.WriteLine("检测结果JSON" + json);
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
SegResult detResult = JsonConvert.DeserializeObject<SegResult>(json); SegResult detResult = JsonConvert.DeserializeObject<SegResult>(json);
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
if (detResult == null) if (detResult == null)
{ {
return; return;
@ -259,9 +259,9 @@ namespace DH.Devices.Vision
{ {
originMat?.Dispose(); originMat?.Dispose();
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
originMat = null; originMat = null;
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
// GC.Collect(); // GC.Collect();

View File

@ -136,9 +136,9 @@ namespace DH.Devices.Vision
// json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}"; // json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}";
// //
Console.WriteLine("检测结果JSON" + json); Console.WriteLine("检测结果JSON" + json);
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
SegResult detResult = JsonConvert.DeserializeObject<SegResult>(json); SegResult detResult = JsonConvert.DeserializeObject<SegResult>(json);
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
if (detResult == null) if (detResult == null)
{ {
return; return;
@ -267,17 +267,17 @@ namespace DH.Devices.Vision
if (detectMat != null) if (detectMat != null)
{ {
detectMat.Dispose(); detectMat.Dispose();
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
detectMat = null; detectMat = null;
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
} }
if (originMat != null) if (originMat != null)
{ {
originMat.Dispose(); originMat.Dispose();
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
originMat = null; originMat = null;
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型 #pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型
} }

View File

@ -59,7 +59,7 @@ namespace DH.Devices.Vision
// "rect": [421, 823, 6, 8] // "rect": [421, 823, 6, 8]
// }] // }]
//} //}
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public List<Result> HYolo; public List<Result> HYolo;
public class Result public class Result
@ -67,12 +67,12 @@ namespace DH.Devices.Vision
public double fScore; public double fScore;
public int classId; public int classId;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string classname; public string classname;
//public double area; //public double area;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public List<int> rect; public List<int> rect;
@ -82,7 +82,7 @@ namespace DH.Devices.Vision
} }
public class SegResult public class SegResult
{ {
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public List<Result> SegmentResult; public List<Result> SegmentResult;
public class Result public class Result
@ -90,12 +90,12 @@ namespace DH.Devices.Vision
public double fScore; public double fScore;
public int classId; public int classId;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string classname; public string classname;
public double area; public double area;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public List<int> rect; public List<int> rect;

View File

@ -22,18 +22,18 @@ namespace DH.Devices.Vision
/// <summary> /// <summary>
/// 检测配置ID /// 检测配置ID
/// </summary> /// </summary>
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string DetectionId { get; set; } public string DetectionId { get; set; }
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string DetectionName { get; set; } public string DetectionName { get; set; }
/// <summary> /// <summary>
/// 深度学习模型 /// 深度学习模型
/// </summary> /// </summary>
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public SimboVisionMLBase StationMLEngine { get; set; } public SimboVisionMLBase StationMLEngine { get; set; }

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\</BaseOutputPath>
<AppendTargetFrameworkToOutputPath>output</AppendTargetFrameworkToOutputPath>
<UseWindowsForms>true</UseWindowsForms>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DH.Commons.Devies\DH.Commons.Devies.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,49 @@
using DH.Commons.Enums;
using DH.Devices.Devices;
using System.ComponentModel;
using System.Drawing.Design;
using System.Text.Json.Serialization;
namespace DH.Process
{
public class ProcessConfigBase
{
[JsonPropertyName("station_code")]
public string StationCode { get; set; }
#region
[Category("设备配置")]
[Description("相机配置")]
[DisplayName("相机配置")]
[JsonPropertyName("camera_config_collection")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(InitialConfigCollectionEditor<CameraInitialConfigBase>), typeof(UITypeEditor))]
public List<CameraBase> CameraConfigCollection { get; set; } = new List<CameraBase>();
[Category("设备配置")]
[Description("模型配置")]
[DisplayName("模型配置")]
[JsonPropertyName("detection_config_collection")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(InitialConfigCollectionEditor<CameraInitialConfigBase>), typeof(UITypeEditor))]
public List<DetectionConfig> DetectionConfigCollection { get; set; } = new List<DetectionConfig>();
// [Category("设备配置")]
// [Description("PLC配置")]
// [DisplayName("PLC配置")]
// [TypeConverter(typeof(CollectionCountConvert))]
// [Editor(typeof(InitialConfigCollectionEditor<PLCInitialConfigBase>), typeof(UITypeEditor))]
// public List<IInitialConfig> PLCConfigCollection { get; set; } = new List<IInitialConfig>();
// [Category("设备配置")]
// [Description("其他设备配置")]
// [DisplayName("其他设备配置")]
// [TypeConverter(typeof(CollectionCountConvert))]
// [Editor(typeof(InitialConfigCollectionEditor<InitialConfigBase>), typeof(UITypeEditor))]
// public List<IInitialConfig> DeviceConfigs { get; set; } = new List<IInitialConfig>();
#endregion
}
}

View File

@ -3,14 +3,14 @@
partial class Canvas partial class Canvas
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,7 +3,7 @@
partial class CanvasImage partial class CanvasImage
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
@ -11,7 +11,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -923,9 +923,9 @@ namespace DH.UI.Model.Winform
#region Dispose #region Dispose
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
MAP?.Dispose(); MAP?.Dispose();

View File

@ -3,14 +3,14 @@
partial class GridCtrl partial class GridCtrl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class IOIndicatorCtrl partial class IOIndicatorCtrl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -864,30 +864,30 @@ namespace DH.UI.Model.Winform
{ {
if (disposing) if (disposing)
{ {
// 释放托管状态(托管对象) // 释放托管状态(托管对象)
Pen?.Dispose(); Pen?.Dispose();
} }
// TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器 // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器
// TODO: 将大型字段设置为 null // TODO: 将大型字段设置为 null
disposedValue = true; disposedValue = true;
} }
} }
// TODO: 仅当以上 Dispose(bool disposing) 拥有用于释放未托管资源的代码时才替代终结器 // TODO: 仅当以上 Dispose(bool disposing) 拥有用于释放未托管资源的代码时才替代终结器
// ~ElementBase() // ~ElementBase()
// { // {
// // 请勿更改此代码将清理代码放入以上 Dispose(bool disposing) 中 // // 请勿更改此代码 将清理代码放入以上 Dispose(bool disposing) 中
// Dispose(false); // Dispose(false);
// } // }
// 添加此代码以正确实现可处置模式 // 添加此代码以正确实现可处置模式
public void Dispose() public void Dispose()
{ {
// 请勿更改此代码将清理代码放入以上 Dispose(bool disposing) 中 // 请勿更改此代码 将清理代码放入以上 Dispose(bool disposing) 中
Dispose(true); Dispose(true);
// TODO: 如果在以上内容中替代了终结器,则取消注释以下行 // TODO: 如果在以上内容中替代了终结器,则取消注释以下行
// GC.SuppressFinalize(this); // GC.SuppressFinalize(this);
} }
#endregion #endregion

View File

@ -3,14 +3,14 @@
partial class GridCtrl partial class GridCtrl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class IOIndicatorCtrl partial class IOIndicatorCtrl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -33,6 +33,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DH.UI.Model.Winform", "DH.U
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DH.Devices.Vision", "DH.Devices.Vision\DH.Devices.Vision.csproj", "{5AD3A29E-149A-4C37-9548-7638A36C8175}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DH.Devices.Vision", "DH.Devices.Vision\DH.Devices.Vision.csproj", "{5AD3A29E-149A-4C37-9548-7638A36C8175}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Size", "Size", "{048B30B5-D075-4CE0-BF9F-CB6152E6D376}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XKRS.CanFly", "CanFly\XKRS.CanFly.csproj", "{1FB768DB-843E-4C67-96B9-7684CF890D89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanFly.Canvas", "CanFly.Canvas\CanFly.Canvas.csproj", "{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Process", "Process", "{FE1AEA36-9909-4E4F-8A88-37338ECCCE62}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DH.Process", "DH.Process\DH.Process.csproj", "{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -105,6 +115,30 @@ Global
{5AD3A29E-149A-4C37-9548-7638A36C8175}.Release|Any CPU.Build.0 = Release|Any CPU {5AD3A29E-149A-4C37-9548-7638A36C8175}.Release|Any CPU.Build.0 = Release|Any CPU
{5AD3A29E-149A-4C37-9548-7638A36C8175}.Release|x64.ActiveCfg = Release|x64 {5AD3A29E-149A-4C37-9548-7638A36C8175}.Release|x64.ActiveCfg = Release|x64
{5AD3A29E-149A-4C37-9548-7638A36C8175}.Release|x64.Build.0 = Release|x64 {5AD3A29E-149A-4C37-9548-7638A36C8175}.Release|x64.Build.0 = Release|x64
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Debug|x64.ActiveCfg = Debug|x64
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Debug|x64.Build.0 = Debug|x64
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Release|Any CPU.Build.0 = Release|Any CPU
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Release|x64.ActiveCfg = Release|x64
{1FB768DB-843E-4C67-96B9-7684CF890D89}.Release|x64.Build.0 = Release|x64
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Debug|x64.ActiveCfg = Debug|x64
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Debug|x64.Build.0 = Debug|x64
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Release|Any CPU.Build.0 = Release|Any CPU
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Release|x64.ActiveCfg = Release|x64
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35}.Release|x64.Build.0 = Release|x64
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Debug|x64.ActiveCfg = Debug|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Debug|x64.Build.0 = Debug|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Release|Any CPU.Build.0 = Release|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Release|x64.ActiveCfg = Release|Any CPU
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -121,6 +155,9 @@ Global
{A33108B6-2740-4D28-AD22-B280372980BE} = {0AB4BB9A-A861-4F80-B549-CD331490942B} {A33108B6-2740-4D28-AD22-B280372980BE} = {0AB4BB9A-A861-4F80-B549-CD331490942B}
{12CB9041-B1B1-41AE-B308-AABDACAA580E} = {3EAF3D9C-D3F9-4B6E-89DE-58F129CD1F4C} {12CB9041-B1B1-41AE-B308-AABDACAA580E} = {3EAF3D9C-D3F9-4B6E-89DE-58F129CD1F4C}
{5AD3A29E-149A-4C37-9548-7638A36C8175} = {F77AF94C-280D-44C5-B7C0-FC86AA9EC504} {5AD3A29E-149A-4C37-9548-7638A36C8175} = {F77AF94C-280D-44C5-B7C0-FC86AA9EC504}
{1FB768DB-843E-4C67-96B9-7684CF890D89} = {048B30B5-D075-4CE0-BF9F-CB6152E6D376}
{EA7E228B-DB5C-4BF1-832B-D51B7F7D5F35} = {048B30B5-D075-4CE0-BF9F-CB6152E6D376}
{9C6D1290-26D9-4C5B-8BF5-A1F1E35368C5} = {FE1AEA36-9909-4E4F-8A88-37338ECCCE62}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6FC1A8DF-636E-434C-981E-10F20FAD723B} SolutionGuid = {6FC1A8DF-636E-434C-981E-10F20FAD723B}

View File

@ -11,6 +11,8 @@
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
</PropertyGroup> </PropertyGroup>
@ -38,10 +40,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CanFly\XKRS.CanFly.csproj" />
<ProjectReference Include="..\DH.Devices.Camera\DH.Devices.Camera.csproj" /> <ProjectReference Include="..\DH.Devices.Camera\DH.Devices.Camera.csproj" />
<ProjectReference Include="..\DH.Devices.Motion\DH.Devices.Motion.csproj" /> <ProjectReference Include="..\DH.Devices.Motion\DH.Devices.Motion.csproj" />
<ProjectReference Include="..\DH.Devices.PLC\DH.Devices.PLC.csproj" /> <ProjectReference Include="..\DH.Devices.PLC\DH.Devices.PLC.csproj" />
<ProjectReference Include="..\DH.Devices.Vision\DH.Devices.Vision.csproj" /> <ProjectReference Include="..\DH.Devices.Vision\DH.Devices.Vision.csproj" />
<ProjectReference Include="..\DH.Process\DH.Process.csproj" />
<ProjectReference Include="..\DH.UI.Model.Winform\DH.UI.Model.Winform.csproj" /> <ProjectReference Include="..\DH.UI.Model.Winform\DH.UI.Model.Winform.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -6,6 +6,7 @@ using DH.Devices.Devices;
using DH.Devices.Motion; using DH.Devices.Motion;
using DH.Devices.PLC; using DH.Devices.PLC;
using DH.Devices.Vision; using DH.Devices.Vision;
using DH.Process;
using DHSoftware.Languages; using DHSoftware.Languages;
using DHSoftware.Models; using DHSoftware.Models;
using DHSoftware.Utils; using DHSoftware.Utils;
@ -18,17 +19,22 @@ using System;
using System.CodeDom; using System.CodeDom;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using XKRS.UI.Device.Winform; using XKRS.UI.Device.Winform;
using static AntdUI.Math3D; using static AntdUI.Math3D;
using static DH.Commons.Enums.EnumHelper;
using Camera = DHSoftware.Models.Camera; using Camera = DHSoftware.Models.Camera;
using IOType = DH.Commons.Enums.IOType;
namespace DHSoftware namespace DHSoftware
{ {
@ -229,7 +235,7 @@ namespace DHSoftware
SLDMotion sLDMotion = new SLDMotion(); SLDMotion sLDMotion = new SLDMotion();
private void MainWindow_Load(object sender, EventArgs e) private void MainWindow_Load(object sender, EventArgs e)
{ {
Json();
} }
private void MainWindow_FormClosed(object sender, FormClosedEventArgs e) private void MainWindow_FormClosed(object sender, FormClosedEventArgs e)
@ -278,21 +284,15 @@ namespace DHSoftware
public volatile int ProductNum_OK = 0; public volatile int ProductNum_OK = 0;
private readonly object _cameraSummaryLock = new object(); private readonly object _cameraSummaryLock = new object();
public SimboVisionDriver? _visionEngine = null; public SimboVisionDriver? _visionEngine = null;
List<DetectionConfig> DetectionConfigs = new List<DetectionConfig>(); ProcessConfigBase DHconfig;
List<SimboStationMLEngineSet> SimboStationMLEngineList = new List<SimboStationMLEngineSet>(); //
// List<SimboStationMLEngineSet> SimboStationMLEngineList = new List<SimboStationMLEngineSet>();
Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>(); Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>();
public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>(); public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>();
public DateTime startTime; public DateTime startTime;
private void HandleStartButton() private void Json()
{ {
CurrentMachine = true; List<DetectionConfig> DetectionConfigs = new List<DetectionConfig>();
//_visionEngine.Start();
//[Category("深度学习检测配置")]
//[DisplayName("检测标签定义集合")]
//[Description("定义检测标签的集合例如Seg/Detection模式断裂、油污、划伤...Class模式ok、ng、上面、下面、套环、正常...")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(ComplexCollectionEditor<RecongnitionLabel>), typeof(UITypeEditor))]
RecongnitionLabel recongnition = new RecongnitionLabel RecongnitionLabel recongnition = new RecongnitionLabel
{ {
LabelName = "youwu", LabelName = "youwu",
@ -315,7 +315,7 @@ namespace DHSoftware
RecongnitionLabelList.Add(recongnition2); RecongnitionLabelList.Add(recongnition2);
RecongnitionLabelList.Add(recongnition3); RecongnitionLabelList.Add(recongnition3);
var det1 = new DetectionConfig("相机1", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam1.onnx", false, "Cam1"); var det1 = new DetectionConfig("相机1", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam1.onnx", false, "Cam1");
var det2 = new DetectionConfig("相机2", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam2.onnx", false, "Cam2"); var det2 = new DetectionConfig("相机2", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam2.onnx", false, "Cam2");
@ -353,6 +353,13 @@ namespace DHSoftware
det1.IsEnabled = true; det1.IsEnabled = true;
det1.ShowLocation.X = 1; det1.ShowLocation.X = 1;
det1.ShowLocation.Y = 1; det1.ShowLocation.Y = 1;
det1.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1} ,
};
det2.CameraCollects = CameraCollects2; det2.CameraCollects = CameraCollects2;
det2.ModelconfThreshold = Conf; det2.ModelconfThreshold = Conf;
@ -362,7 +369,13 @@ namespace DHSoftware
det2.IsEnabled = true; det2.IsEnabled = true;
det2.ShowLocation.X = 2; det2.ShowLocation.X = 2;
det2.ShowLocation.Y = 1; det2.ShowLocation.Y = 1;
det2.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
det3.CameraCollects = CameraCollects3; det3.CameraCollects = CameraCollects3;
det3.ModelconfThreshold = Conf; det3.ModelconfThreshold = Conf;
det3.ModelWidth = 640; det3.ModelWidth = 640;
@ -371,6 +384,13 @@ namespace DHSoftware
det3.IsEnabled = true; det3.IsEnabled = true;
det3.ShowLocation.X = 3; det3.ShowLocation.X = 3;
det3.ShowLocation.Y = 1; det3.ShowLocation.Y = 1;
det3.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
det4.CameraCollects = CameraCollects4; det4.CameraCollects = CameraCollects4;
det4.ModelconfThreshold = Conf; det4.ModelconfThreshold = Conf;
@ -380,6 +400,13 @@ namespace DHSoftware
det4.IsEnabled = true; det4.IsEnabled = true;
det4.ShowLocation.X = 4; det4.ShowLocation.X = 4;
det4.ShowLocation.Y = 1; det4.ShowLocation.Y = 1;
det4.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
@ -391,6 +418,23 @@ namespace DHSoftware
det5.IsEnabled = true; det5.IsEnabled = true;
det5.ShowLocation.X = 1; det5.ShowLocation.X = 1;
det5.ShowLocation.Y = 2; det5.ShowLocation.Y = 2;
det5.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
det5.PreTreatCollects = new List<SizeTreatParam>()
{
new SizeTreatParam()
{
PreName="高度测量",
IsEnable=true,
PreType=SizeEnum.,
ResultShow="sssssss",
OutResultShow="sssssss",
},
};
det6.CameraCollects = CameraCollects6; det6.CameraCollects = CameraCollects6;
det6.ModelconfThreshold = Conf; det6.ModelconfThreshold = Conf;
@ -400,6 +444,13 @@ namespace DHSoftware
det6.IsEnabled = true; det6.IsEnabled = true;
det6.ShowLocation.X = 2; det6.ShowLocation.X = 2;
det6.ShowLocation.Y = 2; det6.ShowLocation.Y = 2;
det6.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
det7.CameraCollects = CameraCollects7; det7.CameraCollects = CameraCollects7;
det7.ModelconfThreshold = Conf; det7.ModelconfThreshold = Conf;
@ -409,6 +460,13 @@ namespace DHSoftware
det7.IsEnabled = true; det7.IsEnabled = true;
det7.ShowLocation.X = 3; det7.ShowLocation.X = 3;
det7.ShowLocation.Y = 2; det7.ShowLocation.Y = 2;
det7.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
det8.CameraCollects = CameraCollects8; det8.CameraCollects = CameraCollects8;
det8.ModelconfThreshold = Conf; det8.ModelconfThreshold = Conf;
@ -416,8 +474,27 @@ namespace DHSoftware
det8.ModelHeight = 640; det8.ModelHeight = 640;
det8.in_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam8.txt"; det8.in_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam8.txt";
det8.IsEnabled = true; det8.IsEnabled = true;
det8.IsAddStation = true;
det8.ShowLocation.X = 4; det8.ShowLocation.X = 4;
det8.ShowLocation.Y = 2; det8.ShowLocation.Y = 2;
det8.DetectionLableList = new List<DetectionLable>()
{ new DetectionLable{ LabelName="xinquexian1",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian2",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian3",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
new DetectionLable{ LabelName="xinquexian4",MaxArea=99999999,MinArea=1,MinSource=0.6,MaxSource=1 } ,
};
det8.PreTreatCollects = new List<SizeTreatParam>()
{
new SizeTreatParam()
{
PreName="高度测量",
IsEnable=true,
PreType=SizeEnum.,
ResultShow="sssssss",
OutResultShow="sssssss",
},
};
DetectionConfigs.Add(det1); DetectionConfigs.Add(det1);
DetectionConfigs.Add(det2); DetectionConfigs.Add(det2);
@ -428,6 +505,32 @@ namespace DHSoftware
DetectionConfigs.Add(det7); DetectionConfigs.Add(det7);
DetectionConfigs.Add(det8); DetectionConfigs.Add(det8);
DHconfig = new ProcessConfigBase();
DHconfig.StationCode = "小齿轮";
DHconfig.DetectionConfigCollection = DetectionConfigs;
// DHconfig.ca = "小齿轮";
// **序列化**
string json = JsonSerializer.Serialize(DHconfig, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine("序列化后的 JSON:\n" + json);
var deserializedConfig = JsonSerializer.Deserialize<ProcessConfigBase>(json);
Console.WriteLine("Station Code: " + deserializedConfig?.StationCode);
}
private void HandleStartButton()
{
CurrentMachine = true;
//_visionEngine.Start();
//[Category("深度学习检测配置")]
//[DisplayName("检测标签定义集合")]
//[Description("定义检测标签的集合例如Seg/Detection模式断裂、油污、划伤...Class模式ok、ng、上面、下面、套环、正常...")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(ComplexCollectionEditor<RecongnitionLabel>), typeof(UITypeEditor))]
Cameras.Clear(); Cameras.Clear();
HKCameras.Clear(); HKCameras.Clear();
Dectection.Clear(); Dectection.Clear();
@ -477,7 +580,7 @@ namespace DHSoftware
#endif #endif
DetectionConfigs.ForEach(detection => DHconfig?.DetectionConfigCollection.ForEach(detection =>
{ {
detection.CameraCollects.ForEach(cam => detection.CameraCollects.ForEach(cam =>
@ -504,7 +607,7 @@ namespace DHSoftware
_visionEngine = new SimboVisionDriver(); _visionEngine = new SimboVisionDriver();
_visionEngine.DetectionConfigs = DetectionConfigs; _visionEngine.DetectionConfigs =DHconfig?.DetectionConfigCollection;
_visionEngine.Init(); _visionEngine.Init();
CtrlVisionRunBase ctrlVisionRun = new CtrlVisionRunBase(_visionEngine); CtrlVisionRunBase ctrlVisionRun = new CtrlVisionRunBase(_visionEngine);
@ -1020,9 +1123,10 @@ namespace DHSoftware
listCamBase.Add(cam1); listCamBase.Add(cam1);
listCamBase.Add(cam2); listCamBase.Add(cam2);
SettingWindow s = new SettingWindow(); SettingWindow1 settingWindow = new SettingWindow1(DHconfig);
s.cameras = listCamBase; settingWindow.Show();
s.Show(); //s.cameras = listCamBase;
//s.Show();
} }

View File

@ -9,7 +9,7 @@ namespace DHSoftware
{ {
private static MainWindow mainWindow; private static MainWindow mainWindow;
/// <summary> /// <summary>
/// 应用程序的主入口点 /// 应用程序的主入口点
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main()

View File

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// 此代码由工具生成 // 此代码由工具生成
// 运行时版本:4.0.30319.42000 // 运行时版本:4.0.30319.42000
// //
// 对此文件的更改可能会导致不正确的行为,并且如果 // 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失 // 重新生成代码,这些更改将会丢失
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -13,12 +13,12 @@ namespace DHSoftware.Properties {
/// <summary> /// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等 /// 一个强类型的资源类,用于查找本地化的字符串等
/// </summary> /// </summary>
// 此类是由 StronglyTypedResourceBuilder // 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目 // (以 /str 作为命令选项),或重新生成 VS 项目
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
@ -33,7 +33,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例 /// 返回此类使用的缓存的 ResourceManager 实例
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
@ -48,7 +48,7 @@ namespace DHSoftware.Properties {
/// <summary> /// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对 /// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写 /// 使用此强类型资源类的所有资源查找执行重写
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture { internal static global::System.Globalization.CultureInfo Culture {
@ -61,7 +61,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap bg1 { internal static System.Drawing.Bitmap bg1 {
get { get {
@ -71,7 +71,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap bg2 { internal static System.Drawing.Bitmap bg2 {
get { get {
@ -81,7 +81,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap bg3 { internal static System.Drawing.Bitmap bg3 {
get { get {
@ -91,7 +91,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap head { internal static System.Drawing.Bitmap head {
get { get {
@ -101,7 +101,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap head2 { internal static System.Drawing.Bitmap head2 {
get { get {
@ -111,7 +111,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap logo { internal static System.Drawing.Bitmap logo {
get { get {
@ -121,7 +121,7 @@ namespace DHSoftware.Properties {
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源 /// 查找 System.Drawing.Bitmap 类型的本地化资源
/// </summary> /// </summary>
internal static System.Drawing.Bitmap { internal static System.Drawing.Bitmap {
get { get {

View File

@ -4,14 +4,14 @@
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -25,7 +25,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class CameraConfigControl partial class CameraConfigControl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class CorrelatedCameraEdit partial class CorrelatedCameraEdit
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class CtrlVisionDisplay partial class CtrlVisionDisplay
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -4,14 +4,14 @@ namespace XKRS.UI.Device.Winform
partial class CtrlVisionRunBase partial class CtrlVisionRunBase
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -25,7 +25,7 @@ namespace XKRS.UI.Device.Winform
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class DefectRowEdit partial class DefectRowEdit
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class DetectConfigControl partial class DetectConfigControl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class DetectControl partial class DetectControl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
@ -41,9 +41,9 @@
preTable = new AntdUI.Table(); preTable = new AntdUI.Table();
label3 = new AntdUI.Label(); label3 = new AntdUI.Label();
btnPath = new AntdUI.Button(); btnPath = new AntdUI.Button();
switch1 = new AntdUI.Switch(); swtPre = new AntdUI.Switch();
label2 = new AntdUI.Label(); label2 = new AntdUI.Label();
iptPath = new AntdUI.Input(); iptPrePath = new AntdUI.Input();
label1 = new AntdUI.Label(); label1 = new AntdUI.Label();
tabPage2 = new AntdUI.TabPage(); tabPage2 = new AntdUI.TabPage();
btnLableDelete = new AntdUI.Button(); btnLableDelete = new AntdUI.Button();
@ -59,24 +59,31 @@
label6 = new AntdUI.Label(); label6 = new AntdUI.Label();
switch5 = new AntdUI.Switch(); switch5 = new AntdUI.Switch();
label12 = new AntdUI.Label(); label12 = new AntdUI.Label();
input1 = new AntdUI.Input(); iptScore = new AntdUI.Input();
label5 = new AntdUI.Label(); label5 = new AntdUI.Label();
flowPanel1 = new AntdUI.FlowPanel(); flowPanel1 = new AntdUI.FlowPanel();
label11 = new AntdUI.Label(); label11 = new AntdUI.Label();
switch3 = new AntdUI.Switch(); swIsAddStation = new AntdUI.Switch();
label10 = new AntdUI.Label(); label10 = new AntdUI.Label();
stDetectType = new AntdUI.Select(); stDetectType = new AntdUI.Select();
label9 = new AntdUI.Label(); label9 = new AntdUI.Label();
btnCorrelatedCamera = new AntdUI.Button(); btnCorrelatedCamera = new AntdUI.Button();
btnPath2 = new AntdUI.Button(); btnPath2 = new AntdUI.Button();
switch2 = new AntdUI.Switch(); swIsEnabled = new AntdUI.Switch();
label7 = new AntdUI.Label(); label7 = new AntdUI.Label();
iptPath2 = new AntdUI.Input(); iptModelPath = new AntdUI.Input();
label8 = new AntdUI.Label(); label8 = new AntdUI.Label();
tabPage3 = new AntdUI.TabPage(); tabPage3 = new AntdUI.TabPage();
tabPage4 = new AntdUI.TabPage();
btnSizeDel = new AntdUI.Button();
btnSizeAdd = new AntdUI.Button();
SizeTable = new AntdUI.Table();
label17 = new AntdUI.Label();
tabs1.SuspendLayout(); tabs1.SuspendLayout();
tabPage1.SuspendLayout(); tabPage1.SuspendLayout();
tabPage2.SuspendLayout(); tabPage2.SuspendLayout();
tabPage3.SuspendLayout();
tabPage4.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// tabs1 // tabs1
@ -89,10 +96,9 @@
tabs1.Pages.Add(tabPage1); tabs1.Pages.Add(tabPage1);
tabs1.Pages.Add(tabPage2); tabs1.Pages.Add(tabPage2);
tabs1.Pages.Add(tabPage3); tabs1.Pages.Add(tabPage3);
tabs1.SelectedIndex = 1;
tabs1.Size = new Size(915, 609); tabs1.Size = new Size(915, 609);
tabs1.Style = styleLine1; tabs1.Style = styleLine1;
tabs1.TabIndex = 2; tabs1.TabIndex = 1;
tabs1.Text = "tabs1"; tabs1.Text = "tabs1";
// //
// tabPage1 // tabPage1
@ -106,13 +112,13 @@
tabPage1.Controls.Add(preTable); tabPage1.Controls.Add(preTable);
tabPage1.Controls.Add(label3); tabPage1.Controls.Add(label3);
tabPage1.Controls.Add(btnPath); tabPage1.Controls.Add(btnPath);
tabPage1.Controls.Add(switch1); tabPage1.Controls.Add(swtPre);
tabPage1.Controls.Add(label2); tabPage1.Controls.Add(label2);
tabPage1.Controls.Add(iptPath); tabPage1.Controls.Add(iptPrePath);
tabPage1.Controls.Add(label1); tabPage1.Controls.Add(label1);
tabPage1.Location = new Point(-822, -575); tabPage1.Location = new Point(3, 31);
tabPage1.Name = "tabPage1"; tabPage1.Name = "tabPage1";
tabPage1.Size = new Size(822, 575); tabPage1.Size = new Size(909, 575);
tabPage1.TabIndex = 0; tabPage1.TabIndex = 0;
tabPage1.Text = "预处理"; tabPage1.Text = "预处理";
// //
@ -213,14 +219,14 @@
btnPath.TabIndex = 7; btnPath.TabIndex = 7;
btnPath.Text = "打开"; btnPath.Text = "打开";
// //
// switch1 // swtPre
// //
switch1.CheckedText = "启用"; swtPre.CheckedText = "启用";
switch1.Location = new Point(207, 33); swtPre.Location = new Point(207, 33);
switch1.Name = "switch1"; swtPre.Name = "swtPre";
switch1.Size = new Size(82, 33); swtPre.Size = new Size(82, 33);
switch1.TabIndex = 4; swtPre.TabIndex = 4;
switch1.UnCheckedText = "关闭"; swtPre.UnCheckedText = "关闭";
// //
// label2 // label2
// //
@ -230,22 +236,22 @@
label2.TabIndex = 3; label2.TabIndex = 3;
label2.Text = "状 态"; label2.Text = "状 态";
// //
// iptPath // iptPrePath
// //
iptPath.Location = new Point(191, 79); iptPrePath.Location = new Point(191, 79);
iptPath.Name = "iptPath"; iptPrePath.Name = "iptPrePath";
iptPath.PlaceholderText = "请点击打开按钮选择模型路径"; iptPrePath.PlaceholderText = "请点击打开按钮选择预处理路径";
iptPath.ReadOnly = true; iptPrePath.ReadOnly = true;
iptPath.Size = new Size(423, 42); iptPrePath.Size = new Size(423, 42);
iptPath.TabIndex = 1; iptPrePath.TabIndex = 1;
// //
// label1 // label1
// //
label1.Location = new Point(110, 89); label1.Location = new Point(110, 89);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(75, 23); label1.Size = new Size(86, 23);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "模型路径"; label1.Text = "预处理路径";
// //
// tabPage2 // tabPage2
// //
@ -262,25 +268,26 @@
tabPage2.Controls.Add(label6); tabPage2.Controls.Add(label6);
tabPage2.Controls.Add(switch5); tabPage2.Controls.Add(switch5);
tabPage2.Controls.Add(label12); tabPage2.Controls.Add(label12);
tabPage2.Controls.Add(input1); tabPage2.Controls.Add(iptScore);
tabPage2.Controls.Add(label5); tabPage2.Controls.Add(label5);
tabPage2.Controls.Add(flowPanel1); tabPage2.Controls.Add(flowPanel1);
tabPage2.Controls.Add(label11); tabPage2.Controls.Add(label11);
tabPage2.Controls.Add(switch3); tabPage2.Controls.Add(swIsAddStation);
tabPage2.Controls.Add(label10); tabPage2.Controls.Add(label10);
tabPage2.Controls.Add(stDetectType); tabPage2.Controls.Add(stDetectType);
tabPage2.Controls.Add(label9); tabPage2.Controls.Add(label9);
tabPage2.Controls.Add(btnCorrelatedCamera); tabPage2.Controls.Add(btnCorrelatedCamera);
tabPage2.Controls.Add(btnPath2); tabPage2.Controls.Add(btnPath2);
tabPage2.Controls.Add(switch2); tabPage2.Controls.Add(swIsEnabled);
tabPage2.Controls.Add(label7); tabPage2.Controls.Add(label7);
tabPage2.Controls.Add(iptPath2); tabPage2.Controls.Add(iptModelPath);
tabPage2.Controls.Add(label8); tabPage2.Controls.Add(label8);
tabPage2.Location = new Point(3, 31); tabPage2.Location = new Point(-909, -575);
tabPage2.Name = "tabPage2"; tabPage2.Name = "tabPage2";
tabPage2.Size = new Size(909, 575); tabPage2.Size = new Size(909, 575);
tabPage2.TabIndex = 1; tabPage2.TabIndex = 1;
tabPage2.Text = "模型检测"; tabPage2.Text = "模型检测";
tabPage2.Click += tabPage2_Click;
// //
// btnLableDelete // btnLableDelete
// //
@ -406,14 +413,13 @@
label12.TabIndex = 36; label12.TabIndex = 36;
label12.Text = "OK原图"; label12.Text = "OK原图";
// //
// input1 // iptScore
// //
input1.Location = new Point(649, 24); iptScore.Location = new Point(649, 24);
input1.Name = "input1"; iptScore.Name = "iptScore";
input1.PlaceholderText = ""; iptScore.PlaceholderText = "";
input1.ReadOnly = true; iptScore.Size = new Size(117, 42);
input1.Size = new Size(117, 42); iptScore.TabIndex = 35;
input1.TabIndex = 35;
// //
// label5 // label5
// //
@ -441,14 +447,14 @@
label11.TabIndex = 32; label11.TabIndex = 32;
label11.Text = "关联相机"; label11.Text = "关联相机";
// //
// switch3 // swIsAddStation
// //
switch3.CheckedText = "启用"; swIsAddStation.CheckedText = "启用";
switch3.Location = new Point(270, 26); swIsAddStation.Location = new Point(270, 26);
switch3.Name = "switch3"; swIsAddStation.Name = "swIsAddStation";
switch3.Size = new Size(82, 33); swIsAddStation.Size = new Size(82, 33);
switch3.TabIndex = 31; swIsAddStation.TabIndex = 31;
switch3.UnCheckedText = "关闭"; swIsAddStation.UnCheckedText = "关闭";
// //
// label10 // label10
// //
@ -502,14 +508,14 @@
btnPath2.TabIndex = 20; btnPath2.TabIndex = 20;
btnPath2.Text = "打开"; btnPath2.Text = "打开";
// //
// switch2 // swIsEnabled
// //
switch2.CheckedText = "启用"; swIsEnabled.CheckedText = "启用";
switch2.Location = new Point(110, 26); swIsEnabled.Location = new Point(110, 26);
switch2.Name = "switch2"; swIsEnabled.Name = "swIsEnabled";
switch2.Size = new Size(82, 33); swIsEnabled.Size = new Size(82, 33);
switch2.TabIndex = 19; swIsEnabled.TabIndex = 19;
switch2.UnCheckedText = "关闭"; swIsEnabled.UnCheckedText = "关闭";
// //
// label7 // label7
// //
@ -519,14 +525,14 @@
label7.TabIndex = 18; label7.TabIndex = 18;
label7.Text = "状 态"; label7.Text = "状 态";
// //
// iptPath2 // iptModelPath
// //
iptPath2.Location = new Point(110, 75); iptModelPath.Location = new Point(110, 75);
iptPath2.Name = "iptPath2"; iptModelPath.Name = "iptModelPath";
iptPath2.PlaceholderText = "请点击打开按钮选择模型路径"; iptModelPath.PlaceholderText = "请点击打开按钮选择模型路径";
iptPath2.ReadOnly = true; iptModelPath.ReadOnly = true;
iptPath2.Size = new Size(656, 42); iptModelPath.Size = new Size(656, 42);
iptPath2.TabIndex = 17; iptModelPath.TabIndex = 17;
// //
// label8 // label8
// //
@ -538,12 +544,68 @@
// //
// tabPage3 // tabPage3
// //
tabPage3.Location = new Point(0, 0); tabPage3.Controls.Add(tabPage4);
tabPage3.Location = new Point(-909, -575);
tabPage3.Name = "tabPage3"; tabPage3.Name = "tabPage3";
tabPage3.Size = new Size(0, 0); tabPage3.Size = new Size(909, 575);
tabPage3.TabIndex = 2; tabPage3.TabIndex = 3;
tabPage3.Text = "尺寸测量"; tabPage3.Text = "尺寸测量";
// //
// tabPage4
//
tabPage4.Controls.Add(btnSizeDel);
tabPage4.Controls.Add(btnSizeAdd);
tabPage4.Controls.Add(SizeTable);
tabPage4.Controls.Add(label17);
tabPage4.Location = new Point(8, 8);
tabPage4.Name = "tabPage4";
tabPage4.Size = new Size(909, 575);
tabPage4.TabIndex = 1;
tabPage4.Text = "预处理";
//
// btnSizeDel
//
btnSizeDel.BorderWidth = 2F;
btnSizeDel.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
btnSizeDel.Ghost = true;
btnSizeDel.IconRatio = 0.8F;
btnSizeDel.IconSvg = resources.GetString("btnSizeDel.IconSvg");
btnSizeDel.Location = new Point(775, 192);
btnSizeDel.Name = "btnSizeDel";
btnSizeDel.Size = new Size(80, 38);
btnSizeDel.TabIndex = 10;
btnSizeDel.Text = "删除";
//
// btnSizeAdd
//
btnSizeAdd.BorderWidth = 2F;
btnSizeAdd.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
btnSizeAdd.Ghost = true;
btnSizeAdd.IconRatio = 0.8F;
btnSizeAdd.IconSvg = resources.GetString("btnSizeAdd.IconSvg");
btnSizeAdd.Location = new Point(775, 148);
btnSizeAdd.Name = "btnSizeAdd";
btnSizeAdd.Size = new Size(80, 38);
btnSizeAdd.TabIndex = 9;
btnSizeAdd.Text = "新增";
//
// SizeTable
//
SizeTable.AutoSizeColumnsMode = AntdUI.ColumnsMode.Fill;
SizeTable.Location = new Point(38, 65);
SizeTable.Name = "SizeTable";
SizeTable.Size = new Size(705, 455);
SizeTable.TabIndex = 8;
SizeTable.Text = "table1";
//
// label17
//
label17.Location = new Point(38, 24);
label17.Name = "label17";
label17.Size = new Size(91, 23);
label17.TabIndex = 1;
label17.Text = "配 置";
//
// DetectControl // DetectControl
// //
AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleDimensions = new SizeF(7F, 17F);
@ -551,9 +613,12 @@
Controls.Add(tabs1); Controls.Add(tabs1);
Name = "DetectControl"; Name = "DetectControl";
Size = new Size(915, 609); Size = new Size(915, 609);
Load += DetectControl_Load;
tabs1.ResumeLayout(false); tabs1.ResumeLayout(false);
tabPage1.ResumeLayout(false); tabPage1.ResumeLayout(false);
tabPage2.ResumeLayout(false); tabPage2.ResumeLayout(false);
tabPage3.ResumeLayout(false);
tabPage4.ResumeLayout(false);
ResumeLayout(false); ResumeLayout(false);
} }
@ -564,9 +629,9 @@
private AntdUI.TabPage tabPage2; private AntdUI.TabPage tabPage2;
private AntdUI.TabPage tabPage3; private AntdUI.TabPage tabPage3;
private AntdUI.Label label1; private AntdUI.Label label1;
private AntdUI.Input iptPath; private AntdUI.Input iptPrePath;
private AntdUI.Label label2; private AntdUI.Label label2;
private AntdUI.Switch switch1; private AntdUI.Switch swtPre;
private AntdUI.Button btnPath; private AntdUI.Button btnPath;
private AntdUI.Label label3; private AntdUI.Label label3;
private AntdUI.Button btnPreDelete; private AntdUI.Button btnPreDelete;
@ -578,18 +643,18 @@
private AntdUI.Table PreOutTable; private AntdUI.Table PreOutTable;
private AntdUI.Button btnCorrelatedCamera; private AntdUI.Button btnCorrelatedCamera;
private AntdUI.Button btnPath2; private AntdUI.Button btnPath2;
private AntdUI.Switch switch2; private AntdUI.Switch swIsEnabled;
private AntdUI.Label label7; private AntdUI.Label label7;
private AntdUI.Input iptPath2; private AntdUI.Input iptModelPath;
private AntdUI.Label label8; private AntdUI.Label label8;
private AntdUI.Select stDetectType; private AntdUI.Select stDetectType;
private AntdUI.Label label9; private AntdUI.Label label9;
private AntdUI.Switch switch3; private AntdUI.Switch swIsAddStation;
private AntdUI.Label label10; private AntdUI.Label label10;
private AntdUI.Label label11; private AntdUI.Label label11;
private AntdUI.FlowPanel flowPanel1; private AntdUI.FlowPanel flowPanel1;
private AntdUI.Label label5; private AntdUI.Label label5;
private AntdUI.Input input1; private AntdUI.Input iptScore;
private AntdUI.Switch switch4; private AntdUI.Switch switch4;
private AntdUI.Label label6; private AntdUI.Label label6;
private AntdUI.Switch switch5; private AntdUI.Switch switch5;
@ -603,5 +668,10 @@
private AntdUI.Table lableTable; private AntdUI.Table lableTable;
private AntdUI.Button btnLableAdd; private AntdUI.Button btnLableAdd;
private AntdUI.Button btnLableDelete; private AntdUI.Button btnLableDelete;
private AntdUI.TabPage tabPage4;
private AntdUI.Button btnSizeDel;
private AntdUI.Button btnSizeAdd;
private AntdUI.Table SizeTable;
private AntdUI.Label label17;
} }
} }

View File

@ -12,22 +12,207 @@ using System.Xml.Linq;
using AntdUI; using AntdUI;
using DH.Commons.Enums; using DH.Commons.Enums;
using DH.Devices.Vision; using DH.Devices.Vision;
using XKRS.CanFly;
using static AntdUI.Table;
using static DH.Commons.Enums.EnumHelper;
namespace DHSoftware.Views namespace DHSoftware.Views
{ {
public partial class DetectControl : UserControl public partial class DetectControl : UserControl
{ {
Window window; Window window;
// DetectionConfig detectionConfig;
private DetectionConfig _config;
List<RelatedCamera> relatedCameras = new List<RelatedCamera>();
AntList<PreTreatParam> PreTreatList;
AntList<PreTreatParam> PreOutTreatList;
AntList<DetectionLable> DetectionLableList;
AntList<SizeTreatParam> SizeLableList;
PreTreatParam curPreTreat;
PreTreatParam curPreOutTreat;
DetectionLable curDetectionLable;
SizeTreatParam SizeParamLable;
public DetectionConfig detectionConfig
{
get => _config;
set
{
if (_config != null)
{
_config.PropertyChanged -= Config_PropertyChanged; // 解绑旧的
}
_config = value;
if (_config != null)
{
_config.PropertyChanged += Config_PropertyChanged; // 绑定新的
UpdateUI(); // 初始化 UI
}
}
}
private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// 监听所有属性变化
switch (e.PropertyName)
{
case nameof(DetectionConfig.IsAddStation):
swIsAddStation.Checked = _config.IsAddStation;
break;
case nameof(DetectionConfig.IsEnabled):
swIsEnabled.Checked = _config.IsEnabled;
break;
case nameof(DetectionConfig.ModelType):
stDetectType.SelectedIndex = (int)_config.ModelType-1;
break;
case nameof(DetectionConfig.ModelconfThreshold):
if (iptScore.InvokeRequired)
{
iptScore.Invoke(() => iptScore.Text = _config.ModelconfThreshold.ToString());
}
else
{
iptScore.Text = _config.ModelconfThreshold.ToString();
}
break;
case nameof(DetectionConfig.PreTreatCollects):
break;
}
}
private void UpdateUI()
{
if (_config == null) return;
swIsAddStation.Checked = _config.IsAddStation;
swIsEnabled.Checked = _config.IsEnabled;
stDetectType.SelectedIndex = (int)_config.ModelType - 1;
iptScore.Text = _config.ModelconfThreshold.ToString();
iptModelPath.Text = _config.ModelPath;
swtPre.Checked = _config.IsPreEnabled;
iptPrePath.Text = _config.HalconAlgorithemPath_Pre;
// textBoxName.Text = _config.Name;
// checkBoxEnableGPU.Checked = _config.IsEnableGPU;
}
public DetectControl(Window _window) public DetectControl(Window _window)
{ {
window= _window; window = _window;
InitializeComponent(); InitializeComponent();
//this.detectionConfig = detectionConfig;
//初始化表格列头 //初始化表格列头
InitTableColumns(); InitTableColumns();
InitData(); foreach (var item in MLModelTypes)
BindEventHandler(); {
} stDetectType.Items.Add(item.Key);
}
BindEventHandler();
// 如果你的控件是通过设计器生成的,确保事件已经在设计器文件中绑定。
swtPre.CheckedChanged += swtPre_CheckedChanged; // 确保控件的事件处理器被注册
swIsAddStation.CheckedChanged += swIsAddStation_CheckedChanged; // 确保控件的事件处理器被注册
swIsEnabled.CheckedChanged += swIsEnabled_CheckedChanged; // 确保控件的事件处理器被注册
stDetectType.SelectedIndexChanged += stDetectType_SelectedIndexChanged; // 确保控件的事件处理器被注册
iptScore.TextChanged += IptScore_TextChanged;
iptModelPath.TextChanged += IptModelPath_TextChanged;
}
private void IptScore_TextChanged(object sender, EventArgs e)
{
if (_config != null && !string.IsNullOrEmpty(iptScore.Text))
{
if (float.TryParse(iptScore.Text, out float score) && _config.ModelconfThreshold != score)
{
_config.ModelconfThreshold = score;
}
else
{
iptScore.Text = _config.ModelconfThreshold.ToString();
}
}
}
private void IptModelPath_TextChanged(object sender, EventArgs e)
{
if (_config != null && !string.IsNullOrEmpty(iptModelPath.Text))
{
if ( _config.ModelPath != iptModelPath.Text)
{
_config.ModelPath = iptModelPath.Text;
}
else
{
iptModelPath.Text = _config.ModelPath;
}
}
}
private void stDetectType_SelectedIndexChanged(object sender, EventArgs e)
{
// 下拉选项变更事件处理
if (_config != null && stDetectType.SelectedIndex != -1)
{
// 防止循环更新
if ((int)_config.ModelType != stDetectType.SelectedIndex + 1)
{
_config.ModelType = (MLModelType)(stDetectType.SelectedIndex + 1);
}
}
}
private void swtPre_CheckedChanged(object sender, EventArgs e)
{
// 当用户改变控件的值时,更新数据模型的属性
if (_config != null)
{
_config.IsPreEnabled = swtPre.Checked;
}
}
private void swIsAddStation_CheckedChanged(object sender, EventArgs e)
{
// 当用户改变控件的值时,更新数据模型的属性
if (_config != null)
{
_config.IsAddStation = swIsAddStation.Checked;
}
}
private void swIsEnabled_CheckedChanged(object sender, EventArgs e)
{
// 当用户改变控件的值时,更新数据模型的属性
if (_config != null)
{
_config.IsEnabled = swIsEnabled.Checked;
}
}
/// <summary>
/// 更新尺寸测量表格
/// </summary>
private void UpdatePreTreatCollectsFromSizeTable()
{
// 假设 SizeLableList 是 SizeTable 的数据源
List<SizeTreatParam> updatedPreTreatCollects = new List<SizeTreatParam>();
foreach (var sizeTreat in SizeLableList)
{
var preTreatCollect = new SizeTreatParam
{
IsEnable = sizeTreat.IsEnable,
PreName = sizeTreat.PreName,
PrePix = sizeTreat.PrePix,
PreType = sizeTreat.PreType,
ResultShow = sizeTreat.ResultShow,
OutResultShow = sizeTreat.OutResultShow
};
updatedPreTreatCollects.Add(preTreatCollect);
}
// 将更新后的数据设置到 PreTreatCollects
detectionConfig.PreTreatCollects = updatedPreTreatCollects;
}
private void BindEventHandler() private void BindEventHandler()
{ {
//预处理 //预处理
@ -43,11 +228,18 @@ namespace DHSoftware.Views
//中处理 //中处理
btnPath2.Click += BtnPath2_Click; btnPath2.Click += BtnPath2_Click;
btnCorrelatedCamera.Click += BtnCorrelatedCamera_Click; btnCorrelatedCamera.Click += BtnCorrelatedCamera_Click;
btnPic.Click += BtnPic_Click; btnPic.Click += BtnPic_Click;
btnLableAdd.Click += BtnLableAdd_Click; btnLableAdd.Click += BtnLableAdd_Click;
btnLableDelete.Click += BtnLableDelete_Click; btnLableDelete.Click += BtnLableDelete_Click;
lableTable.CellButtonClick += LableTable_CellButtonClick; lableTable.CellButtonClick += LableTable_CellButtonClick;
btnSizeAdd.Click += BtnSizeAdd_Click;
btnSizeDel.Click += BtnSizeDelete_Click;
SizeTable.CellButtonClick += SizeTable_CellButtonClick;
} }
private void LableTable_CellButtonClick(object sender, TableButtonEventArgs e) private void LableTable_CellButtonClick(object sender, TableButtonEventArgs e)
@ -84,6 +276,78 @@ namespace DHSoftware.Views
} }
} }
private void SizeTable_CellButtonClick(object sender, TableButtonEventArgs e)
{
var buttontext = e.Btn.Text;
if (e.Record is SizeTreatParam sizeTreat)
{
SizeParamLable = sizeTreat;
switch (buttontext)
{
//暂不支持进入整行编辑,只支持指定单元格编辑,推荐使用弹窗或抽屉编辑整行数据
case "编辑":
var form = new SizeLabelEdit(window, SizeParamLable) { Size = new Size(500, 300) };
AntdUI.Drawer.open(new AntdUI.Drawer.Config(window, form)
{
OnLoad = () =>
{
AntdUI.Message.info(window, "进入编辑", autoClose: 1);
},
OnClose = () =>
{
AntdUI.Message.info(window, "结束编辑", autoClose: 1);
UpdatePreTreatCollectsFromSizeTable();
}
});
break;
case "删除":
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
if (result == DialogResult.OK)
SizeLableList.Remove(sizeTreat);
UpdatePreTreatCollectsFromSizeTable();
break;
case "进行测量":
var sizeType = ((int)SizeParamLable.PreType).ToString();
// 根据测量类型打开不同的窗口
switch (sizeType)
{
case "1":
case "2":
case "3":
case "4":
case "5":
FrmMain3 frmMain3 = new FrmMain3(sizeType);
frmMain3.ShowDialog();
if (!string.IsNullOrEmpty(frmMain3.inputtext))
{
sizeTreat.ResultShow = frmMain3.inputtext;
}
if (!string.IsNullOrEmpty(frmMain3.outtext))
{
sizeTreat.OutResultShow = frmMain3.outtext;
}
break;
default:
MessageBox.Show("未定义的测量类型!");
break;
}
UpdatePreTreatCollectsFromSizeTable();
//使用clone可以防止table中的image被修改
//Preview.open(new Preview.Config(window, (Image)SizeParamLable.CellImages[0].Image.Clone()));
break;
}
}
}
private void BtnLableDelete_Click(object? sender, EventArgs e) private void BtnLableDelete_Click(object? sender, EventArgs e)
{ {
if (DetectionLableList.Count == 0 || !DetectionLableList.Any(x => x.Selected)) if (DetectionLableList.Count == 0 || !DetectionLableList.Any(x => x.Selected))
@ -111,7 +375,7 @@ namespace DHSoftware.Views
private void BtnLableAdd_Click(object? sender, EventArgs e) private void BtnLableAdd_Click(object? sender, EventArgs e)
{ {
DetectionLable detectionLable = new DetectionLable() DetectionLable detectionLable = new DetectionLable()
{ {
CellLinks = new CellLink[] { CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary), new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
@ -129,15 +393,65 @@ namespace DHSoftware.Views
} }
} }
private void BtnPic_Click(object? sender, EventArgs e) private void BtnSizeDelete_Click(object? sender, EventArgs e)
{ {
if (SizeLableList.Count == 0 || !SizeLableList.Any(x => x.Selected))
{
AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3);
return;
}
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
if (result == DialogResult.OK)
{
// 使用反转for循环删除主列表中选中的项
for (int i = SizeLableList.Count - 1; i >= 0; i--)
{
// 删除选中的主列表项
if (SizeLableList[i].Selected)
{
SizeLableList.RemoveAt(i);
}
}
// 提示删除完成
AntdUI.Message.success(window, "删除成功!", autoClose: 3);
}
} }
List<RelatedCamera> relatedCameras = new List<RelatedCamera>(); private void BtnSizeAdd_Click(object? sender, EventArgs e)
{
SizeTreatParam SizeParamLable = new SizeTreatParam()
{
//CellBadge = new CellBadge(SizeEnum.Circle.GetEnumDescription()),
CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error),
new CellButton(Guid.NewGuid().ToString(),"进行测量",TTypeMini.Primary)
}
};
var form = new SizeLabelEdit(window, SizeParamLable) { Size = new Size(450, 500) };
AntdUI.Modal.open(new AntdUI.Modal.Config(window, "", form, TType.None)
{
BtnHeight = 0,
});
if (form.submit)
{
SizeLableList.Add(SizeParamLable);
}
}
private void BtnPic_Click(object? sender, EventArgs e)
{
}
private void BtnCorrelatedCamera_Click(object? sender, EventArgs e) private void BtnCorrelatedCamera_Click(object? sender, EventArgs e)
{ {
var form = new CorrelatedCameraEdit(window, relatedCameras) { Size = new Size(500, 400) }; var form = new CorrelatedCameraEdit(window, relatedCameras) { Size = new Size(500, 400) };
@ -148,39 +462,10 @@ namespace DHSoftware.Views
if (form.submit) if (form.submit)
{ {
flowPanel1.Controls.Clear(); flowPanel1.Controls.Clear();
if (relatedCameras.Count > 0) InitRelatedCamera();
{ detectionConfig.CameraCollects=relatedCameras;
foreach (var item in relatedCameras) }
{ }
var control = new AntdUI.Tag()
{
Font = new System.Drawing.Font("Microsoft YaHei UI", 9F),
Size = new Size(90, 42),
Text = item.CameraSourceId,
CloseIcon = true
};
control.CloseChanged += (sender, e) =>
{
var tag = sender as Tag;
foreach (var item in relatedCameras)
{
if (item.CameraSourceId.Equals(tag.Text))
{
relatedCameras.Remove(item);
break;
}
}
return true;
};
// 通过主窗口设置DPI控制添加控件保持缩放比例
window.AutoDpi(control);
flowPanel1.Controls.Add(control);
control.BringToFront();
}
}
}
}
private bool Control_CloseChanged(object sender, EventArgs e) private bool Control_CloseChanged(object sender, EventArgs e)
{ {
@ -203,8 +488,8 @@ namespace DHSoftware.Views
{ {
string filePath = openFileDialog.FileName; string filePath = openFileDialog.FileName;
iptPath2.Text = filePath; iptModelPath.Text = filePath;
_config.ModelPath = filePath;
} }
} }
} }
@ -272,6 +557,7 @@ namespace DHSoftware.Views
{ {
PreTreatParam preParam = new PreTreatParam() PreTreatParam preParam = new PreTreatParam()
{ {
CellLinks = new CellLink[] { CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary), new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error), new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error),
@ -317,7 +603,7 @@ namespace DHSoftware.Views
if (result == DialogResult.OK) if (result == DialogResult.OK)
PreTreatList.Remove(PreTreat); PreTreatList.Remove(PreTreat);
break; break;
} }
} }
} }
@ -325,15 +611,15 @@ namespace DHSoftware.Views
private void PreTable_CellClick(object sender, TableClickEventArgs e) private void PreTable_CellClick(object sender, TableClickEventArgs e)
{ {
} }
private void BtnPreDelete_Click(object? sender, EventArgs e) private void BtnPreDelete_Click(object? sender, EventArgs e)
{ {
if (PreTreatList.Count == 0 || !PreTreatList.Any(x => x.Selected)) if (PreTreatList.Count == 0 || !PreTreatList.Any(x => x.Selected))
{ {
AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3); AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3);
return; return;
} }
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn); var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
@ -373,33 +659,113 @@ namespace DHSoftware.Views
} }
} }
AntList<PreTreatParam> PreTreatList;
AntList<PreTreatParam> PreOutTreatList; //加载相机
AntList<DetectionLable> DetectionLableList; private void InitRelatedCamera()
PreTreatParam curPreTreat; {
PreTreatParam curPreOutTreat; if (relatedCameras.Count > 0)
DetectionLable curDetectionLable; {
foreach (var item in relatedCameras)
{
var control = new AntdUI.Tag()
{
Font = new System.Drawing.Font("Microsoft YaHei UI", 9F),
Size = new Size(90, 42),
Text = item.CameraSourceId,
CloseIcon = true
};
control.CloseChanged += (sender, e) =>
{
var tag = sender as Tag;
foreach (var item in relatedCameras)
{
if (item.CameraSourceId.Equals(tag.Text))
{
relatedCameras.Remove(item);
break;
}
}
detectionConfig.CameraCollects = relatedCameras;
return true;
};
// 通过主窗口设置DPI控制添加控件保持缩放比例
window.AutoDpi(control);
flowPanel1.Controls.Add(control);
control.BringToFront();
}
}
}
private void InitData() private void InitData()
{ {
PreTreatList = new AntList<PreTreatParam>(); relatedCameras = detectionConfig.CameraCollects;
InitRelatedCamera();
// swIsAddStation. = detectionConfig.IsAddStation;
PreTreatList = new AntList<PreTreatParam>();
foreach (var item in detectionConfig.PreTreatParams)
{
PreTreatParam lable = item;
lable.CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error),
};
PreTreatList.Add(lable);
}
preTable.Binding(PreTreatList); preTable.Binding(PreTreatList);
PreOutTreatList = new AntList<PreTreatParam>(); PreOutTreatList = new AntList<PreTreatParam>();
foreach (var item in detectionConfig.OUTPreTreatParams)
{
PreTreatParam lable = item;
lable.CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error),
};
PreOutTreatList.Add(lable);
}
PreOutTable.Binding(PreOutTreatList); PreOutTable.Binding(PreOutTreatList);
foreach (var item in MLModelTypes)
DetectionLableList = new AntList<DetectionLable>();
foreach (var item in detectionConfig.DetectionLableList)
{ {
stDetectType.Items.Add(item.Key); DetectionLable lable = item;
lable.CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error),
};
DetectionLableList.Add(lable);
} }
DetectionLableList =new AntList<DetectionLable>();
lableTable.Binding(DetectionLableList); lableTable.Binding(DetectionLableList);
// SizeLableList = new AntList<SizeTreatParam>(_config.PreTreatCollects);
foreach (var item in _config.PreTreatCollects)
{
item.CellLinks = new CellLink[] {
new CellButton(Guid.NewGuid().ToString(),"编辑",TTypeMini.Primary),
new CellButton(Guid.NewGuid().ToString(),"删除",TTypeMini.Error),
new CellButton(Guid.NewGuid().ToString(),"进行测量",TTypeMini.Primary)
};
// SizeLableList.Add(item);
}
// 将 List<PreTreatCollect> 转换为 AntList<PreTreatCollect>
SizeLableList = new AntList<SizeTreatParam>(_config.PreTreatCollects);
// 绑定转换后的数据到 SizeTable
SizeTable.Binding(SizeLableList);
//SizeTable.Binding(_config.PreTreatCollects);
} }
private void InitTableColumns() private void InitTableColumns()
@ -429,6 +795,19 @@ namespace DHSoftware.Views
new Column("ResultState", "结果", ColumnAlign.Center), new Column("ResultState", "结果", ColumnAlign.Center),
new Column("CellLinks", "操作", ColumnAlign.Center) new Column("CellLinks", "操作", ColumnAlign.Center)
}; };
SizeTable.Columns = new ColumnCollection() {
new ColumnCheck("Selected"){Fixed = true},
new ColumnSwitch("IsEnable", "是否启用") {Width = "10%" },
new Column("PreName", "测量名称") { Width = "15%" },
new Column("PreType", "测量类型") { Width = "10%" },
new Column("PrePix", "阈值") { Width = "5%" },
new Column("ResultShow", "输入参数") { Width = "15%" },
new Column("OutResultShow", "输出参数") { Width = "15%" },
new Column("CellLinks", "操作") { Width = "30%" }
};
} }
private void btnPath_Click(object? sender, EventArgs e) private void btnPath_Click(object? sender, EventArgs e)
@ -446,18 +825,30 @@ namespace DHSoftware.Views
if (openFileDialog.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
string filePath = openFileDialog.FileName; string filePath = openFileDialog.FileName;
iptPath.Text = filePath; iptPrePath.Text = filePath;
} }
} }
} }
List<KeyValuePair<string, int>> MLModelTypes = GetFilteredEnumDescriptionsAndValues<MLModelType>(); List<KeyValuePair<string, int>> MLModelTypes = GetFilteredEnumDescriptionsAndValues<MLModelType>();
List<KeyValuePair<string, int>> SizeEnum = GetFilteredEnumDescriptionsAndValues<SizeEnum>();
private void tabPage2_Click(object sender, EventArgs e)
{
}
private void DetectControl_Load(object sender, EventArgs e)
{
InitData();
}
public static List<KeyValuePair<string, int>> GetFilteredEnumDescriptionsAndValues<T>() where T : Enum public static List<KeyValuePair<string, int>> GetFilteredEnumDescriptionsAndValues<T>() where T : Enum
{ {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
@ -147,4 +147,10 @@
<data name="btnPath2.IconSvg" xml:space="preserve"> <data name="btnPath2.IconSvg" xml:space="preserve">
<value>&lt;svg t="1741939836774" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21349" width="200" height="200"&gt;&lt;path d="M1003.153333 404.96a52.933333 52.933333 0 0 0-42.38-20.96H896V266.666667a53.393333 53.393333 0 0 0-53.333333-53.333334H461.253333a10.573333 10.573333 0 0 1-7.54-3.126666L344.46 100.953333A52.986667 52.986667 0 0 0 306.746667 85.333333H53.333333a53.393333 53.393333 0 0 0-53.333333 53.333334v704a53.393333 53.393333 0 0 0 53.333333 53.333333h796.893334a53.453333 53.453333 0 0 0 51.453333-39.333333l110.546667-405.333334a52.953333 52.953333 0 0 0-9.073334-46.373333zM53.333333 128h253.413334a10.573333 10.573333 0 0 1 7.54 3.126667l109.253333 109.253333A52.986667 52.986667 0 0 0 461.253333 256H842.666667a10.666667 10.666667 0 0 1 10.666666 10.666667v117.333333H173.773333a53.453333 53.453333 0 0 0-51.453333 39.333333L42.666667 715.366667V138.666667a10.666667 10.666667 0 0 1 10.666666-10.666667zm917.726667 312.14l-110.546667 405.333333a10.666667 10.666667 0 0 1-10.286666 7.86H63.226667a10.666667 10.666667 0 0 1-10.286667-13.473333l110.546667-405.333333A10.666667 10.666667 0 0 1 173.773333 426.666667h787a10.666667 10.666667 0 0 1 10.286667 13.473333z" fill="#5C5C66" p-id="21350"/&gt;&lt;/svg&gt;</value> <value>&lt;svg t="1741939836774" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21349" width="200" height="200"&gt;&lt;path d="M1003.153333 404.96a52.933333 52.933333 0 0 0-42.38-20.96H896V266.666667a53.393333 53.393333 0 0 0-53.333333-53.333334H461.253333a10.573333 10.573333 0 0 1-7.54-3.126666L344.46 100.953333A52.986667 52.986667 0 0 0 306.746667 85.333333H53.333333a53.393333 53.393333 0 0 0-53.333333 53.333334v704a53.393333 53.393333 0 0 0 53.333333 53.333333h796.893334a53.453333 53.453333 0 0 0 51.453333-39.333333l110.546667-405.333334a52.953333 52.953333 0 0 0-9.073334-46.373333zM53.333333 128h253.413334a10.573333 10.573333 0 0 1 7.54 3.126667l109.253333 109.253333A52.986667 52.986667 0 0 0 461.253333 256H842.666667a10.666667 10.666667 0 0 1 10.666666 10.666667v117.333333H173.773333a53.453333 53.453333 0 0 0-51.453333 39.333333L42.666667 715.366667V138.666667a10.666667 10.666667 0 0 1 10.666666-10.666667zm917.726667 312.14l-110.546667 405.333333a10.666667 10.666667 0 0 1-10.286666 7.86H63.226667a10.666667 10.666667 0 0 1-10.286667-13.473333l110.546667-405.333333A10.666667 10.666667 0 0 1 173.773333 426.666667h787a10.666667 10.666667 0 0 1 10.286667 13.473333z" fill="#5C5C66" p-id="21350"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="btnSizeDel.IconSvg" xml:space="preserve">
<value>&lt;svg t="1741939836774" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21349" width="200" height="200"&gt;&lt;path d="M1003.153333 404.96a52.933333 52.933333 0 0 0-42.38-20.96H896V266.666667a53.393333 53.393333 0 0 0-53.333333-53.333334H461.253333a10.573333 10.573333 0 0 1-7.54-3.126666L344.46 100.953333A52.986667 52.986667 0 0 0 306.746667 85.333333H53.333333a53.393333 53.393333 0 0 0-53.333333 53.333334v704a53.393333 53.393333 0 0 0 53.333333 53.333333h796.893334a53.453333 53.453333 0 0 0 51.453333-39.333333l110.546667-405.333334a52.953333 52.953333 0 0 0-9.073334-46.373333zM53.333333 128h253.413334a10.573333 10.573333 0 0 1 7.54 3.126667l109.253333 109.253333A52.986667 52.986667 0 0 0 461.253333 256H842.666667a10.666667 10.666667 0 0 1 10.666666 10.666667v117.333333H173.773333a53.453333 53.453333 0 0 0-51.453333 39.333333L42.666667 715.366667V138.666667a10.666667 10.666667 0 0 1 10.666666-10.666667zm917.726667 312.14l-110.546667 405.333333a10.666667 10.666667 0 0 1-10.286666 7.86H63.226667a10.666667 10.666667 0 0 1-10.286667-13.473333l110.546667-405.333333A10.666667 10.666667 0 0 1 173.773333 426.666667h787a10.666667 10.666667 0 0 1 10.286667 13.473333z" fill="#5C5C66" p-id="21350"/&gt;&lt;/svg&gt;</value>
</data>
<data name="btnSizeAdd.IconSvg" xml:space="preserve">
<value>&lt;svg t="1741939836774" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21349" width="200" height="200"&gt;&lt;path d="M1003.153333 404.96a52.933333 52.933333 0 0 0-42.38-20.96H896V266.666667a53.393333 53.393333 0 0 0-53.333333-53.333334H461.253333a10.573333 10.573333 0 0 1-7.54-3.126666L344.46 100.953333A52.986667 52.986667 0 0 0 306.746667 85.333333H53.333333a53.393333 53.393333 0 0 0-53.333333 53.333334v704a53.393333 53.393333 0 0 0 53.333333 53.333333h796.893334a53.453333 53.453333 0 0 0 51.453333-39.333333l110.546667-405.333334a52.953333 52.953333 0 0 0-9.073334-46.373333zM53.333333 128h253.413334a10.573333 10.573333 0 0 1 7.54 3.126667l109.253333 109.253333A52.986667 52.986667 0 0 0 461.253333 256H842.666667a10.666667 10.666667 0 0 1 10.666666 10.666667v117.333333H173.773333a53.453333 53.453333 0 0 0-51.453333 39.333333L42.666667 715.366667V138.666667a10.666667 10.666667 0 0 1 10.666666-10.666667zm917.726667 312.14l-110.546667 405.333333a10.666667 10.666667 0 0 1-10.286666 7.86H63.226667a10.666667 10.666667 0 0 1-10.286667-13.473333l110.546667-405.333333A10.666667 10.666667 0 0 1 173.773333 426.666667h787a10.666667 10.666667 0 0 1 10.286667 13.473333z" fill="#5C5C66" p-id="21350"/&gt;&lt;/svg&gt;</value>
</data>
</root> </root>

View File

@ -3,14 +3,14 @@
partial class DetectionLableEdit partial class DetectionLableEdit
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
@ -81,6 +81,7 @@
// sltResultState // sltResultState
// //
sltResultState.Dock = DockStyle.Top; sltResultState.Dock = DockStyle.Top;
sltResultState.List = true;
sltResultState.Location = new Point(18, 444); sltResultState.Location = new Point(18, 444);
sltResultState.Name = "sltResultState"; sltResultState.Name = "sltResultState";
sltResultState.Size = new Size(464, 45); sltResultState.Size = new Size(464, 45);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -3,14 +3,14 @@
partial class PreTreatEdit partial class PreTreatEdit
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -3,14 +3,14 @@
partial class PreTreatUserControl partial class PreTreatUserControl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

View File

@ -102,6 +102,7 @@
menuItem1.IconSvg = "VideoCameraOutlined"; menuItem1.IconSvg = "VideoCameraOutlined";
menuItem1.Text = "相机设置"; menuItem1.Text = "相机设置";
menuItem2.IconSvg = "AppstoreOutlined"; menuItem2.IconSvg = "AppstoreOutlined";
menuItem2.ID = "Station";
menuItem2.Text = "工位设置"; menuItem2.Text = "工位设置";
menuItem3.IconSvg = "ControlOutlined"; menuItem3.IconSvg = "ControlOutlined";
menuItem3.Text = "运控设置"; menuItem3.Text = "运控设置";
@ -161,6 +162,7 @@
Name = "SettingWindow1"; Name = "SettingWindow1";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "SettingWinform"; Text = "SettingWinform";
Load += SettingWindow1_Load;
panel1.ResumeLayout(false); panel1.ResumeLayout(false);
panel2.ResumeLayout(false); panel2.ResumeLayout(false);
panel3.ResumeLayout(false); panel3.ResumeLayout(false);

View File

@ -8,15 +8,20 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using AntdUI; using AntdUI;
using AntdUIDemo.Models;
using DH.Process;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Window = AntdUI.Window;
namespace DHSoftware.Views namespace DHSoftware.Views
{ {
public partial class SettingWindow1 : Window public partial class SettingWindow1 : Window
{ {
private UserControl currControl; private UserControl currControl;
public SettingWindow1() ProcessConfigBase DHconfig;
public SettingWindow1(ProcessConfigBase _DHconfig)
{ {
InitializeComponent(); InitializeComponent();
DHconfig = _DHconfig;
AntdUI.TooltipComponent tooltip = new AntdUI.TooltipComponent() AntdUI.TooltipComponent tooltip = new AntdUI.TooltipComponent()
{ {
Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))), Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))),
@ -98,7 +103,115 @@ namespace DHSoftware.Views
} }
bool isUpdatingTabs = false; bool isUpdatingTabs = false;
private void InitDecetion()
{
MenuItem clickedItem = menu1.Items[1];
switch (clickedItem.Text)
{
case "相机设置":
break;
case "工位设置":
// 检查是否已存在同名 TabPage
//foreach (var tab in tabs1.Pages)
//{
// if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
// {
// isUpdatingTabs = true;
// tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
// isUpdatingTabs = false;
// currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
// return;
// }
//}
foreach (var item in DHconfig.DetectionConfigCollection)
{
AddSubItem(clickedItem, item.Name);
DetectControl control = new DetectControl(this);
control.detectionConfig = item;
if (control != null)
{
//容器添加控件需要调整dpi
control.Dock = DockStyle.Fill;
AutoDpi(control);
AntdUI.TabPage tabPage = new AntdUI.TabPage()
{
Text = $"{clickedItem.Text}-{item.Name}",
};
tabPage.Controls.Add(control);
tabs1.Pages.Add(tabPage);
isUpdatingTabs = true;
tabs1.SelectedTab = tabPage;
isUpdatingTabs = false;
currControl = control;
}
//tabs1.Pages[1].
}
break;
case "运控设置":
break;
}
}
private void LoadMenu(string filter = "")
{
menu1.Items.Clear();
Dictionary<string, List<MenuItems>> Menu_decetion = new Dictionary<string, List<MenuItems>>();
string lang = AntdUI.Localization.CurrentLanguage;
var menuItems = DataUtil.Menu_decetion;
//var menuIcons = DataUtil.MenuIcons_zhcn;
//if (lang.StartsWith("en"))
//{
// menuItems = DataUtil.MenuItems_enus;
// menuIcons = DataUtil.MenuIcons_enus;
//}
foreach (var rootItem in Menu_decetion)
{
var rootKey = rootItem.Key.ToLower();
var rootMenu = new AntdUI.MenuItem
{
Text = rootItem.Key,
//IconSvg = menuIcons.TryGetValue(rootItem.Key, out var icon) ? icon : "UnorderedListOutlined",
};
bool rootVisible = false; // 用于标记是否显示根节点
foreach (var item in rootItem.Value)
{
var childText = item.Text.ToLower();
// 如果子节点包含搜索文本
if (childText.Contains(filter))
{
var menuItem = new AntdUI.MenuItem
{
Text = item.Text,
IconSvg = item.IconSvg,
Tag = item.Tag,
};
rootMenu.Sub.Add(menuItem);
rootVisible = true; // 如果有子节点包含,则显示根节点
}
}
// 如果根节点包含搜索文本,或有可见的子节点,则显示根节点
if (rootKey.Contains(filter) || rootVisible)
{
menu1.Items.Add(rootMenu);
}
}
}
private void menu1_MouseDown(object sender, MouseEventArgs e) private void menu1_MouseDown(object sender, MouseEventArgs e)
{ {
@ -115,7 +228,7 @@ namespace DHSoftware.Views
return; return;
} }
switch (clickedItem.PARENTITEM.Text) switch (clickedItem.PARENTITEM.Text)
{ {
case "相机设置": case "相机设置":
@ -157,11 +270,11 @@ namespace DHSoftware.Views
case "运控设置": case "运控设置":
break; break;
} }
} }
} }
private MenuItem FindClickedItem(MenuItemCollection items, Point clickPoint) private MenuItem FindClickedItem(MenuItemCollection items, Point clickPoint)
@ -183,6 +296,11 @@ namespace DHSoftware.Views
} }
return null; return null;
} }
private void SettingWindow1_Load(object sender, EventArgs e)
{
InitDecetion();
}
} }
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -3,14 +3,14 @@
partial class SizeConfigControl partial class SizeConfigControl
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

263
DHSoftware/Views/SizeLabelEdit.Designer.cs generated Normal file
View File

@ -0,0 +1,263 @@
namespace DHSoftware.Views
{
partial class SizeLabelEdit
{
/// <summary>
/// 必需的设计器变量
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容
/// </summary>
private void InitializeComponent()
{
button_cancel = new AntdUI.Button();
iptName = new AntdUI.Input();
label2 = new AntdUI.Label();
divider2 = new AntdUI.Divider();
stackPanel1 = new AntdUI.StackPanel();
button_ok = new AntdUI.Button();
divider1 = new AntdUI.Divider();
label1 = new AntdUI.Label();
panel1 = new AntdUI.Panel();
iptOutParam = new AntdUI.Input();
label6 = new AntdUI.Label();
iptIntParam = new AntdUI.Input();
label5 = new AntdUI.Label();
ipthreshold = new AntdUI.InputNumber();
label4 = new AntdUI.Label();
sltSizeEnum = new AntdUI.Select();
label3 = new AntdUI.Label();
stackPanel1.SuspendLayout();
panel1.SuspendLayout();
SuspendLayout();
//
// button_cancel
//
button_cancel.BorderWidth = 1F;
button_cancel.Font = new Font("Microsoft YaHei UI", 9F);
button_cancel.Ghost = true;
button_cancel.Location = new Point(84, 3);
button_cancel.Name = "button_cancel";
button_cancel.Size = new Size(75, 38);
button_cancel.TabIndex = 1;
button_cancel.Text = "取消";
//
// iptName
//
iptName.Dock = DockStyle.Top;
iptName.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
iptName.Location = new Point(18, 134);
iptName.Name = "iptName";
iptName.Radius = 3;
iptName.Size = new Size(409, 38);
iptName.TabIndex = 23;
//
// label2
//
label2.Dock = DockStyle.Top;
label2.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label2.Location = new Point(18, 110);
label2.Name = "label2";
label2.Size = new Size(409, 24);
label2.TabIndex = 22;
label2.Text = "测量名称";
//
// divider2
//
divider2.Dock = DockStyle.Top;
divider2.Location = new Point(18, 98);
divider2.Name = "divider2";
divider2.Size = new Size(409, 12);
divider2.TabIndex = 21;
//
// stackPanel1
//
stackPanel1.Controls.Add(button_cancel);
stackPanel1.Controls.Add(button_ok);
stackPanel1.Dock = DockStyle.Top;
stackPanel1.Location = new Point(18, 54);
stackPanel1.Name = "stackPanel1";
stackPanel1.RightToLeft = RightToLeft.No;
stackPanel1.Size = new Size(409, 44);
stackPanel1.TabIndex = 20;
stackPanel1.Text = "stackPanel1";
//
// button_ok
//
button_ok.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
button_ok.Location = new Point(3, 3);
button_ok.Name = "button_ok";
button_ok.Size = new Size(75, 38);
button_ok.TabIndex = 0;
button_ok.Text = "确定";
button_ok.Type = AntdUI.TTypeMini.Primary;
//
// divider1
//
divider1.Dock = DockStyle.Top;
divider1.Location = new Point(18, 42);
divider1.Name = "divider1";
divider1.Size = new Size(409, 12);
divider1.TabIndex = 19;
//
// label1
//
label1.Dock = DockStyle.Top;
label1.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label1.Location = new Point(18, 18);
label1.Name = "label1";
label1.Size = new Size(409, 24);
label1.TabIndex = 17;
label1.Text = "尺寸测量操作";
//
// panel1
//
panel1.Controls.Add(iptOutParam);
panel1.Controls.Add(label6);
panel1.Controls.Add(iptIntParam);
panel1.Controls.Add(label5);
panel1.Controls.Add(ipthreshold);
panel1.Controls.Add(label4);
panel1.Controls.Add(sltSizeEnum);
panel1.Controls.Add(label3);
panel1.Controls.Add(iptName);
panel1.Controls.Add(label2);
panel1.Controls.Add(divider2);
panel1.Controls.Add(stackPanel1);
panel1.Controls.Add(divider1);
panel1.Controls.Add(label1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Padding = new Padding(12);
panel1.Shadow = 6;
panel1.Size = new Size(445, 459);
panel1.TabIndex = 1;
panel1.Text = "panel1";
//
// iptOutParam
//
iptOutParam.Dock = DockStyle.Top;
iptOutParam.Location = new Point(18, 381);
iptOutParam.Name = "iptOutParam";
iptOutParam.ReadOnly = true;
iptOutParam.Size = new Size(409, 37);
iptOutParam.TabIndex = 43;
//
// label6
//
label6.Dock = DockStyle.Top;
label6.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label6.Location = new Point(18, 357);
label6.Name = "label6";
label6.Size = new Size(409, 24);
label6.TabIndex = 42;
label6.Text = "输入参数";
//
// iptIntParam
//
iptIntParam.Dock = DockStyle.Top;
iptIntParam.Location = new Point(18, 320);
iptIntParam.Name = "iptIntParam";
iptIntParam.ReadOnly = true;
iptIntParam.Size = new Size(409, 37);
iptIntParam.TabIndex = 41;
//
// label5
//
label5.Dock = DockStyle.Top;
label5.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label5.Location = new Point(18, 296);
label5.Name = "label5";
label5.Size = new Size(409, 24);
label5.TabIndex = 37;
label5.Text = "输入参数";
//
// ipthreshold
//
ipthreshold.Dock = DockStyle.Top;
ipthreshold.Location = new Point(18, 258);
ipthreshold.Name = "ipthreshold";
ipthreshold.Size = new Size(409, 38);
ipthreshold.TabIndex = 36;
ipthreshold.Text = "0";
//
// label4
//
label4.Dock = DockStyle.Top;
label4.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label4.Location = new Point(18, 234);
label4.Name = "label4";
label4.Size = new Size(409, 24);
label4.TabIndex = 35;
label4.Text = "阈值";
//
// sltSizeEnum
//
sltSizeEnum.Dock = DockStyle.Top;
sltSizeEnum.List = true;
sltSizeEnum.Location = new Point(18, 196);
sltSizeEnum.Name = "sltSizeEnum";
sltSizeEnum.Size = new Size(409, 38);
sltSizeEnum.TabIndex = 34;
//
// label3
//
label3.Dock = DockStyle.Top;
label3.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label3.Location = new Point(18, 172);
label3.Name = "label3";
label3.Size = new Size(409, 24);
label3.TabIndex = 24;
label3.Text = "测量类型";
//
// SizeLabelEdit
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(panel1);
Name = "SizeLabelEdit";
Size = new Size(445, 459);
stackPanel1.ResumeLayout(false);
panel1.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private AntdUI.Button button_cancel;
private AntdUI.Input iptName;
private AntdUI.Label label2;
private AntdUI.Divider divider2;
private AntdUI.StackPanel stackPanel1;
private AntdUI.Button button_ok;
private AntdUI.Divider divider1;
private AntdUI.Label label1;
private AntdUI.Panel panel1;
private AntdUI.Label label3;
private AntdUI.Select sltSizeEnum;
private AntdUI.InputNumber ipthreshold;
private AntdUI.Label label4;
private AntdUI.Label label5;
private AntdUI.Input iptOutParam;
private AntdUI.Label label6;
private AntdUI.Input iptIntParam;
}
}

View File

@ -0,0 +1,94 @@
using DH.Commons.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static DH.Commons.Enums.EnumHelper;
namespace DHSoftware.Views
{
public partial class SizeLabelEdit : UserControl
{
private AntdUI.Window window;
private SizeTreatParam sizeLabel;
public bool submit;
public SizeLabelEdit(AntdUI.Window _window, SizeTreatParam SizeLabel)
{
InitializeComponent();
sizeLabel = SizeLabel;
//设置默认值
InitData();
// 绑定事件
BindEventHandler();
}
private void BindEventHandler()
{
button_ok.Click += Button_ok_Click;
button_cancel.Click += Button_cancel_Click;
}
private void Button_cancel_Click(object sender, EventArgs e)
{
submit = false;
this.Dispose();
}
private void Button_ok_Click(object sender, EventArgs e)
{
iptName.Status = AntdUI.TType.None;
//检查输入内容
if (String.IsNullOrEmpty(iptName.Text))
{
iptName.Status = AntdUI.TType.Error;
AntdUI.Message.warn(window, "参数名称不能为空!", autoClose: 3);
return;
}
sizeLabel.PreName = iptName.Text;
sizeLabel.PrePix = Convert.ToInt32(ipthreshold.Text);
sizeLabel.ResultShow = iptIntParam.Text;
sizeLabel.OutResultShow =iptOutParam.Text;
SizeEnum state = EnumHelper.GetEnumFromDescription<SizeEnum>(sltSizeEnum.Text);
sizeLabel.PreType = state;
submit = true;
this.Dispose();
}
private void InitData()
{
// 清空原有项
sltSizeEnum.Items.Clear();
foreach (SizeEnum state in Enum.GetValues(typeof(SizeEnum)))
{
string description = EnumHelper.GetEnumDescription(state);
sltSizeEnum.Items.Add(description);
}
if (string.IsNullOrEmpty(sizeLabel.PreName))
{
iptName.Text = string.Empty;
ipthreshold.Text = "1";
iptIntParam.Text = string.Empty;
iptOutParam.Text = string.Empty;
sltSizeEnum.SelectedIndex = 0;
}
else
{
iptName.Text = sizeLabel.PreName;
ipthreshold.Text = sizeLabel.PrePix.ToString();
iptIntParam.Text = sizeLabel.ResultShow;
iptOutParam.Text = sizeLabel.OutResultShow;
sltSizeEnum.Text = EnumHelper.GetEnumDescription(sizeLabel.PreType);
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
</root>

View File

@ -3,14 +3,14 @@
partial class UserConfigFrm partial class UserConfigFrm
{ {
/// <summary> /// <summary>
/// 必需的设计器变量 /// 必需的设计器变量
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源 /// 清理所有正在使用的资源
/// </summary> /// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false</param> /// <param name="disposing">如果应释放托管资源,为 true否则为 false </param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -24,7 +24,7 @@
/// <summary> /// <summary>
/// 设计器支持所需的方法 - 不要修改 /// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容 /// 使用代码编辑器修改此方法的内容
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {

Some files were not shown because too many files have changed in this diff Show More