using PaintDotNet.Base.CommTool; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass { class GrainPointStyleClass { /// /// 需要根据当前操作图片备份和读取的截点数据 /// public GrainPointStyleModel styleModel = new GrainPointStyleModel(); /// /// 根据图片保存截点数据 /// public Dictionary styleDict = new Dictionary(); /// /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2) /// private int pointKb = 0; /// /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2) /// public int PointKb { get { return pointKb; } set { pointKb = value; } } int minDistance = 10; /// /// 鼠标按下 /// /// 换算后的点 /// 辅助线边框 /// 辅助线的点集合 /// /// public void OnMouseDownFirst(PointF point1, RectangleF rectangleF, List linePointList, object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && e.Clicks == 1) { // 0.5截点 if (this.pointKb == 1) { //if (add == 0) // rectangleF = guideClass.RectangleFLine; if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } // 1截点 else if (this.pointKb == 2) { //if (add == 0) // rectangleF = guideClass.RectangleFLine; if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } // 1.5/2截点(1.5) else if (this.pointKb == 3) { //if (add == 0) // rectangleF = guideClass.RectangleFLine; if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } // 1.5/2截点(2) else if (this.pointKb == 4) { //if (add == 0) // rectangleF = guideClass.RectangleFLine; if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } } } /// /// 鼠标按下 /// /// 换算后的点 /// 辅助线边框 /// 辅助线的点集合 /// public void OnMouseDownFirst(PointF point1, RectangleF rectangleF, List linePointList, MouseEventArgs e) { if (e.Button != MouseButtons.Left || e.Clicks != 1) return; // 0.5截点 if (this.pointKb == 1) { if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } // 1截点 else if (this.pointKb == 2) { if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } // 1.5/2截点(1.5) else if (this.pointKb == 3) { if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } // 1.5/2截点(2) else if (this.pointKb == 4) { if (rectangleF.Contains(point1)) { double distance = 0; int init = 0; PointF pointFAdd = new PointF(); foreach (var linePoint in linePointList) { double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10); if (init == 0) distance = distance1; else { if (distance1 < distance) { distance = distance1; pointFAdd = linePoint; } } init++; } if (distance > minDistance) { return; } styleModel.manualAddPoint(pointFAdd, this.pointKb); } } styleModel.ReloadLineValueList(); } /// /// 返回布尔类型空或者下一步是否可以添加截点 /// /// /// /// /// public bool OnMouseDownNext(PointF point1, object sender, MouseEventArgs e) { // 右键取消添加 if (e.Button == MouseButtons.Right) { this.pointKb = 0; return false; } bool toAddPoint = true; if (e.Button == MouseButtons.Left && e.Clicks == 1) styleModel.manualRemovePoint(point1, out toAddPoint); return toAddPoint; } /// /// 获取截点的中间数据 /// public List> getTableDataList(GrainPointStyleModel styleModel, double physical_length) { //拼接中间数据 List> dataList = new List>(); List columnName = new List(); columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text")); columnName.Add(PdnResources.GetString("Menu.Thestartingpointofthetransversal.Text")); columnName.Add(PdnResources.GetString("Menu.Theendingpointofthetransversal.Text")); columnName.Add(PdnResources.GetString("Menu.Thelengthofthethread.Text")+"(μm)"); dataList.Add(columnName); int index = 0; foreach (var lineKey in styleModel.lineValueList.Keys) { List strList = new List(); strList.Add((++index).ToString()); strList.Add("" + lineKey.startPoint.X + "," + lineKey.startPoint.Y + ""); strList.Add("" + lineKey.endPoint.X + "," + lineKey.endPoint.Y + ""); strList.Add("" + styleModel.lineValueList[lineKey] * physical_length); dataList.Add(strList); } return dataList; } } internal class Line { /// /// 直线的起点 /// public System.Drawing.Point startPoint; /// /// 直线的终点 /// public System.Drawing.Point endPoint; /// /// 构造方法 /// /// /// public Line(System.Drawing.Point s, System.Drawing.Point e) { this.startPoint = s; this.endPoint = e; } } }