123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- using PaintDotNet.Base.CommTool;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
- {
- class GrainPointStyleClass
- {
- /// <summary>
- /// 需要根据当前操作图片备份和读取的截点数据
- /// </summary>
- public GrainPointStyleModel styleModel = new GrainPointStyleModel();
- /// <summary>
- /// 根据图片保存截点数据
- /// </summary>
- public Dictionary<string, GrainPointStyleModel> styleDict = new Dictionary<string, GrainPointStyleModel>();
- /// <summary>
- /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2)
- /// </summary>
- private int pointKb = 0;
- /// <summary>
- /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2)
- /// </summary>
- public int PointKb
- {
- get
- {
- return pointKb;
- }
- set
- {
- pointKb = value;
- }
- }
- int minDistance = 10;
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="point1">换算后的点</param>
- /// <param name="rectangleF">辅助线边框</param>
- /// <param name="linePointList">辅助线的点集合</param>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void OnMouseDownFirst(PointF point1, RectangleF rectangleF, List<PointF> 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);
- }
- }
- }
- }
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="point1">换算后的点</param>
- /// <param name="rectangleF">辅助线边框</param>
- /// <param name="linePointList">辅助线的点集合</param>
- /// <param name="e"></param>
- public void OnMouseDownFirst(PointF point1, RectangleF rectangleF, List<PointF> 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();
- }
- /// <summary>
- /// 返回布尔类型空或者下一步是否可以添加截点
- /// </summary>
- /// <param name="point1"></param>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取截点的中间数据
- /// </summary>
- public List<List<string>> getTableDataList(GrainPointStyleModel styleModel, double physical_length)
- {
- //拼接中间数据
- List<List<string>> dataList = new List<List<string>>();
- List<string> columnName = new List<string>();
- 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<string> strList = new List<string>();
- 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
- {
- /// <summary>
- /// 直线的起点
- /// </summary>
- public System.Drawing.Point startPoint;
- /// <summary>
- /// 直线的终点
- /// </summary>
- public System.Drawing.Point endPoint;
- /// <summary>
- /// 构造方法
- /// </summary>
- /// <param name="s"></param>
- /// <param name="e"></param>
- public Line(System.Drawing.Point s, System.Drawing.Point e)
- {
- this.startPoint = s;
- this.endPoint = e;
- }
- }
- }
|