123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- using OpenCvSharp;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using Point = System.Drawing.Point;
- namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
- {
- class GrainPointStyleModel
- {
- /// <summary>
- /// 直线图形上所有的点
- /// </summary>
- public List<List<PointF>> straightLinePointList = new List<List<PointF>>();
- /// <summary>
- /// 圆圈图形上所有的点,其中第一个点为圆心坐标
- /// </summary>
- public List<List<PointF>> roundLinePointList = new List<List<PointF>>();
- /// <summary>
- /// 图形上所有的两个截点和计算的截距值(像素)
- /// </summary>
- public Dictionary<Line, int> lineValueList = new Dictionary<Line, int>();
- /// <summary>
- /// 0.5截点矩形集合
- /// </summary>
- private List<RectangleF> rectangleFCaps1 = new List<RectangleF>();
- private List<Point> rectangleCaps1 = new List<Point>();
- /// <summary>
- /// 1截点矩形集合
- /// </summary>
- private List<RectangleF> rectangleFCaps2 = new List<RectangleF>();
- private List<Point> rectangleCaps2 = new List<Point>();
- /// <summary>
- /// 1.5/2截点矩形集合(1.5)
- /// </summary>
- private List<RectangleF> rectangleFCaps3_1 = new List<RectangleF>();
- private List<Point> rectangleCaps3_1 = new List<Point>();
- /// <summary>
- /// 1.5/2截点矩形集合(2)
- /// </summary>
- private List<RectangleF> rectangleFCaps3_2 = new List<RectangleF>();
- private List<Point> rectangleCaps3_2 = new List<Point>();
- #region 截点样式
- /// <summary>
- /// 颜色(0.5)
- /// </summary>
- private int pointColor1;
- /// <summary>
- /// 线宽(0.5)
- /// </summary>
- private int pointWidth1;
- /// <summary>
- /// 点样式 0:空心 1:实心(0.5)
- /// </summary>
- private int pointStyle1;
- /// <summary>
- /// 大小(0.5)
- /// </summary>
- private int pointDiameter1;
- /// <summary>
- /// 截点误差(0.5)
- /// </summary>
- private int pointError1;
- /// <summary>
- /// 形状 0:圆形 1:方形(0.5)
- /// </summary>
- private int pointshape1;
- /// <summary>
- /// 颜色(1)
- /// </summary>
- private int pointColor2;
- /// <summary>
- /// 线宽(1)
- /// </summary>
- private int pointWidth2;
- /// <summary>
- /// 点样式 0:空心 1:实心(1)
- /// </summary>
- private int pointStyle2;
- /// <summary>
- /// 大小(1)
- /// </summary>
- private int pointDiameter2;
- /// <summary>
- /// 截点误差(1)
- /// </summary>
- private int pointError2;
- /// <summary>
- /// 形状 0:圆形 1:方形(1)
- /// </summary>
- private int pointshape2;
- /// <summary>
- /// 颜色(1.5/2)
- /// </summary>
- private int pointColor3;
- /// <summary>
- /// 线宽(1.5/2)
- /// </summary>
- private int pointWidth3;
- /// <summary>
- /// 点样式 0:空心 1:实心(1.5/2)
- /// </summary>
- private int pointStyle3;
- /// <summary>
- /// 大小(1.5/2)
- /// </summary>
- private int pointDiameter3;
- /// <summary>
- /// 截点误差(1.5/2)
- /// </summary>
- private int pointError3;
- /// <summary>
- /// 形状 0:圆形 1:方形(1.5/2)
- /// </summary>
- private int pointshape3;
- #endregion
- /// <summary>
- /// 找到当前的参数数据
- /// </summary>
- /// <param name="menuId"></param>
- /// <returns></returns>
- public GrainPointStyleModel cloneListParamModel()
- {
- GrainPointStyleModel newMod = new GrainPointStyleModel();
- newMod.pointColor1 = this.pointColor1;
- newMod.pointWidth1 = this.pointWidth1;
- newMod.pointStyle1 = this.pointStyle1;
- newMod.pointDiameter1 = this.pointDiameter1;
- newMod.pointError1 = this.pointError1;
- newMod.pointshape1 = this.pointshape1;
- newMod.pointColor2 = this.pointColor2;
- newMod.pointWidth2 = this.pointWidth2;
- newMod.pointStyle2 = this.pointStyle2;
- newMod.pointDiameter2 = this.pointDiameter2;
- newMod.pointError2 = this.pointError2;
- newMod.pointshape2 = this.pointshape2;
- newMod.pointColor3 = this.pointColor3;
- newMod.pointWidth3 = this.pointWidth3;
- newMod.pointStyle3 = this.pointStyle3;
- newMod.pointDiameter3 = this.pointDiameter3;
- newMod.pointError3 = this.pointError3;
- newMod.pointshape3 = this.pointshape3;
- return newMod;
- }
- public GrainPointStyleModel cloneModel()
- {
- GrainPointStyleModel newMod = new GrainPointStyleModel();
- //newMod.straightLinePointList = new List<List<PointF>>();
- //newMod.straightLinePointList.AddRange(this.straightLinePointList);//#####
- //newMod.roundLinePointList = new List<List<PointF>>();
- //newMod.roundLinePointList.AddRange(this.roundLinePointList);//
- ////newMod.lineValueList = new Dictionary<Line, int>();
- newMod.pointColor1 = this.pointColor1;
- newMod.pointWidth1 = this.pointWidth1;
- newMod.pointStyle1 = this.pointStyle1;
- newMod.pointDiameter1 = this.pointDiameter1;
- newMod.pointError1 = this.pointError1;
- newMod.pointshape1 = this.pointshape1;
- newMod.pointColor2 = this.pointColor2;
- newMod.pointWidth2 = this.pointWidth2;
- newMod.pointStyle2 = this.pointStyle2;
- newMod.pointDiameter2 = this.pointDiameter2;
- newMod.pointError2 = this.pointError2;
- newMod.pointshape2 = this.pointshape2;
- newMod.pointColor3 = this.pointColor3;
- newMod.pointWidth3 = this.pointWidth3;
- newMod.pointStyle3 = this.pointStyle3;
- newMod.pointDiameter3 = this.pointDiameter3;
- newMod.pointError3 = this.pointError3;
- newMod.pointshape3 = this.pointshape3;
- return newMod;
- }
- /// <summary>
- /// 更新图形上所有的两个截点和计算的截距值
- /// </summary>
- public void ReloadLineValueList()
- {
- this.lineValueList.Clear();
- for (int i = 0; i < straightLinePointList.Count; i++)
- {
- Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
- List<PointF> linePointList = straightLinePointList[i];
- AddLineValueList(false, linePointList, out lineValueList1);
- foreach (var itemKey in lineValueList1.Keys)
- this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
- }
- for (int i = 0; i < roundLinePointList.Count; i++)
- {
- Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
- List<PointF> linePointList = roundLinePointList[i];
- AddLineValueList(true, linePointList, out lineValueList1);
- foreach (var itemKey in lineValueList1.Keys)
- this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
- }
- }
- private void AddLineValueList(bool isRound, List<PointF> linePointList, out Dictionary<Line, int> lineValueList1)
- {
- List<Point> rectangleCapsTotal = new List<Point>();
- rectangleCapsTotal.AddRange(this.rectangleCaps1);
- rectangleCapsTotal.AddRange(this.rectangleCaps2);
- rectangleCapsTotal.AddRange(this.rectangleCaps3_1);
- rectangleCapsTotal.AddRange(this.rectangleCaps3_2);
- lineValueList1 = new Dictionary<Line, int>();
- Point lastCap_Point = new Point(-1, -1);
- foreach (var point in linePointList)
- {
- if (rectangleCapsTotal.Contains(new Point((int)point.X, (int)point.Y)))
- {
- if (lastCap_Point.X >= 0)
- lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
- (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
- lastCap_Point = new Point((int)point.X, (int)point.Y);
- }
- }
- if (isRound && lineValueList1.Count > 0)
- {
- PointF point = new PointF(0, 0);
- foreach (var itemkey in lineValueList1.Keys)
- {
- point = new PointF(itemkey.startPoint.X, itemkey.startPoint.Y);
- break;
- }
- lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
- (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
- }
- }
- /// <summary>
- /// 刷新截点集合,并赋值截距列表
- /// </summary>
- /// <param name="linePointList">图形上所有的点</param>
- public void AddRectangleToRectangleFCapsAndLine(Mat mat, int matLevel, bool vGuideStylesOrHGuideStyles, int surfaceWidth, int surfaceHeight)
- {
- this.lineValueList.Clear();
- this.rectangleFCaps1.Clear();
- this.rectangleFCaps2.Clear();
- this.rectangleFCaps3_1.Clear();
- this.rectangleFCaps3_2.Clear();
- this.rectangleCaps1.Clear();
- this.rectangleCaps2.Clear();
- this.rectangleCaps3_1.Clear();
- this.rectangleCaps3_2.Clear();
- for (int i = 0; i < straightLinePointList.Count; i++)
- {
- Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
- List<PointF> linePointList = straightLinePointList[i];
- AddRectangleCapsAndLine(false, mat, matLevel, linePointList, vGuideStylesOrHGuideStyles, surfaceWidth, surfaceHeight, out lineValueList1);
- foreach (var itemKey in lineValueList1.Keys)
- this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
- }
- for (int i = 0; i < roundLinePointList.Count; i++)
- {
- Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
- List<PointF> linePointList = roundLinePointList[i];
- AddRectangleCapsAndLine(true, mat, matLevel, linePointList, vGuideStylesOrHGuideStyles, surfaceWidth, surfaceHeight, out lineValueList1);
- foreach (var itemKey in lineValueList1.Keys)
- this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
- }
- }
- private void AddRectangleCapsAndLine(bool isRound, Mat mat, int matLevel, List<PointF> linePointList, bool vGuideStylesOrHGuideStyles, int surfaceWidth, int surfaceHeight, out Dictionary<Line, int> lineValueList1)
- {
- lineValueList1 = new Dictionary<Line, int>();
- Point lastCap_s1 = new Point(0, 0);//###
- Point lastCap_s2 = new Point(0, 0);
- Point lastCap_s3 = new Point(0, 0);
- Point lastCap_Point = new Point(-1, -1);
- RectangleF rectangleFCap = new RectangleF();
- for (int iguidePoint = isRound ? 1 : 0; iguidePoint < linePointList.Count; iguidePoint++)
- {
- PointF point = linePointList[iguidePoint];
- if (point.X > 0 && point.X < surfaceWidth - 1
- && point.Y > 0 && point.Y < surfaceHeight - 1)
- {
- Vec4b vec4B = mat.At<Vec4b>((int)point.Y, (int)point.X);
- if (matLevel == 2 && vec4B.Item3 != 0 || matLevel == 1 && vec4B.Item3 != 0 || matLevel == 0 && false/*vec4B.Item0 == 0*/)
- {
- rectangleFCap = new RectangleF();
- int count = GetBoundryCountD(mat, matLevel, new Point((int)point.X, (int)point.Y));
- if (count > 2)
- {
- if (pointStyle3 == 0)
- {
- rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter3 / 2 - this.pointWidth3 / 2, (int)point.Y - this.pointDiameter3 / 2 - this.pointWidth3 / 2);
- rectangleFCap.Width = this.pointDiameter3 + this.pointWidth3 * 2;
- rectangleFCap.Height = this.pointDiameter3 + this.pointWidth3 * 2;
- }
- else
- {
- rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter3 / 2, (int)point.Y - this.pointDiameter3 / 2);
- rectangleFCap.Width = this.pointDiameter3;
- rectangleFCap.Height = this.pointDiameter3;
- }
- // 垂直辅助线/ 水平辅助线
- if (BasicCalculationHelper.GetDistance(lastCap_s3, point, 0) > this.pointError3)
- {
- if (vGuideStylesOrHGuideStyles)
- {
- this.rectangleFCaps3_1.Add(rectangleFCap);
- this.rectangleCaps3_1.Add(new Point((int)point.X, (int)point.Y));
- }
- else
- {
- this.rectangleFCaps3_2.Add(rectangleFCap);
- this.rectangleCaps3_2.Add(new Point((int)point.X, (int)point.Y));
- }
- lastCap_s3 = new Point((int)point.X, (int)point.Y);
- if (lastCap_Point.X >= 0)
- lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
- (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
- lastCap_Point = new Point((int)point.X, (int)point.Y);
- }
- }
- else
- {
- if (pointStyle2 == 0)
- {
- rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter2 / 2 - this.pointWidth2 / 2, (int)point.Y - this.pointDiameter2 / 2 - this.pointWidth2 / 2);
- rectangleFCap.Width = this.pointDiameter2 + this.pointWidth2 * 2;
- rectangleFCap.Height = this.pointDiameter2 + this.pointWidth2 * 2;
- }
- else
- {
- rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter2 / 2, (int)point.Y - this.pointDiameter2 / 2);
- rectangleFCap.Width = this.pointDiameter2;
- rectangleFCap.Height = this.pointDiameter2;
- }
- if (BasicCalculationHelper.GetDistance(lastCap_s2, point, 0) > this.pointError2)
- {
- this.rectangleFCaps2.Add(rectangleFCap);
- this.rectangleCaps2.Add(new Point((int)point.X, (int)point.Y));
- lastCap_s2 = new Point((int)point.X, (int)point.Y);
- if (lastCap_Point.X >= 0)
- lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
- (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
- lastCap_Point = new Point((int)point.X, (int)point.Y);
- }
- }
- }
- }
- }
- if (isRound && lineValueList1.Count > 0)
- {
- PointF point = new PointF(0, 0);
- foreach (var itemkey in lineValueList1.Keys)
- {
- point = new PointF(itemkey.startPoint.X, itemkey.startPoint.Y);
- break;
- }
- lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
- (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
- }
- }
- //################################################
- private int GetBoundryCountD(Mat mat, int matLevel, Point point)
- {
- if (matLevel == 1)
- {
- return this.GetBoundryCountDOfBinary(point, mat);
- }
- int count = 0;
- bool firstValueOnBoundry = false;
- bool lastValueOnBoundry = false;
- Vec4b vec4B = mat.At<Vec4b>(point.Y - 1, point.X - 1);
- if (vec4B.Item0 == 0)
- {
- count++;
- firstValueOnBoundry = true;
- lastValueOnBoundry = true;
- }
- vec4B = mat.At<Vec4b>(point.Y - 1, point.X);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y - 1, point.X + 1);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y, point.X + 1);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y + 1, point.X + 1);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y + 1, point.X);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y + 1, point.X - 1);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y, point.X - 1);
- if (vec4B.Item0 == 0)
- {
- if (!lastValueOnBoundry && !firstValueOnBoundry)
- count++;
- }
- return count;
- }
- private int GetBoundryCountDOfBinary(Point point, Mat mat)
- {
- int count = 0;
- bool firstValueOnBoundry = false;
- bool lastValueOnBoundry = false;
- Vec4b vec4B = mat.At<Vec4b>(point.Y - 1, point.X - 1);
- if (vec4B.Item3 != 0)
- {
- count++;
- firstValueOnBoundry = true;
- lastValueOnBoundry = true;
- }
- vec4B = mat.At<Vec4b>(point.Y - 1, point.X);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y - 1, point.X + 1);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y, point.X + 1);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y + 1, point.X + 1);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y + 1, point.X);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y + 1, point.X - 1);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry)
- count++;
- lastValueOnBoundry = true;
- }
- else lastValueOnBoundry = false;
- vec4B = mat.At<Vec4b>(point.Y, point.X - 1);
- if (vec4B.Item3 != 0)
- {
- if (!lastValueOnBoundry && !firstValueOnBoundry)
- count++;
- }
- return count;
- }
- /// <summary>
- /// 更新截点样式
- /// </summary>
- public void UpdateCupOffPointStyle()
- {
- GrainCutOffPointStyleModel grainCutOffPointStyleModel = XmlSerializeHelper.DESerializer<GrainCutOffPointStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainCutOffPointStyleModel.xml", FileMode.Open));
- // 0.5截点
- this.pointColor1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointColor;
- this.pointWidth1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointWidth;
- this.pointStyle1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointStyle;
- this.pointDiameter1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointDiameter;
- this.pointError1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointError;
- this.pointshape1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointshape;
- // 1截点
- this.pointColor2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointColor;
- this.pointWidth2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointWidth;
- this.pointStyle2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointStyle;
- this.pointDiameter2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointDiameter;
- this.pointError2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointError;
- this.pointshape2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointshape;
- // 1.5/2截点
- this.pointColor3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointColor;
- this.pointWidth3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointWidth;
- this.pointStyle3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointStyle;
- this.pointDiameter3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointDiameter;
- this.pointError3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointError;
- this.pointshape3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointshape;
- }
- /// <summary>
- /// 实现手动添加在原图情况下的截点位置跟随辅助线的移动而移动
- /// </summary>
- /// <param name="offsetX"></param>
- /// <param name="offsetY"></param>
- public void MoveOriginCutOffPoints(int offsetX, int offsetY, float offsetXF, float offsetYF)
- {
- //##21247
- foreach (var item in this.lineValueList)
- {
- item.Key.startPoint.X = item.Key.startPoint.X + offsetX;
- item.Key.startPoint.Y = item.Key.startPoint.Y + offsetY;
- item.Key.endPoint.X = item.Key.endPoint.X + offsetX;
- item.Key.endPoint.Y = item.Key.endPoint.Y + offsetY;
- }
- for (int i = 0; i < this.rectangleFCaps1.Count; i++)
- {
- var item = this.rectangleFCaps1[i];
- this.rectangleFCaps1[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
- }
- for (int i = 0; i < this.rectangleFCaps2.Count; i++)
- {
- var item = this.rectangleFCaps2[i];
- this.rectangleFCaps2[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
- //item.Location = new PointF(item.Location.X + offsetXF, item.Location.Y + offsetYF);
- }
- for (int i = 0; i < this.rectangleFCaps3_1.Count; i++)
- {
- var item = this.rectangleFCaps3_1[i];
- this.rectangleFCaps3_1[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
- //item.Location = new PointF(item.Location.X + offsetXF, item.Location.Y + offsetYF);
- }
- for (int i = 0; i < this.rectangleFCaps3_2.Count; i++)
- {
- var item = this.rectangleFCaps3_2[i];
- this.rectangleFCaps3_2[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
- }
- for (int i = 0; i < this.rectangleCaps1.Count; i++)
- {
- var item = this.rectangleCaps1[i];
- item.X = item.X + offsetX;
- item.Y = item.Y + offsetY;
- }
- for (int i = 0; i < this.rectangleCaps2.Count; i++)
- {
- var item = this.rectangleCaps2[i];
- item.X = item.X + offsetX;
- item.Y = item.Y + offsetY;
- }
- for (int i = 0; i < this.rectangleCaps3_1.Count; i++)
- {
- var item = this.rectangleCaps3_1[i];
- item.X = item.X + offsetX;
- item.Y = item.Y + offsetY;
- }
- for (int i = 0; i < this.rectangleCaps3_2.Count; i++)
- {
- var item = this.rectangleCaps3_2[i];
- item.X = item.X + offsetX;
- item.Y = item.Y + offsetY;
- }
- this.ReloadLineValueList();
- }
- /// <summary>
- /// 绘制截点
- /// </summary>
- public void DrawGuidePoints(Graphics graphics)
- {
- // 以下为绘制样式
- Pen pointPen1 = new Pen(Color.FromArgb(this.pointColor1), this.pointWidth1);
- Pen pointPen2 = new Pen(Color.FromArgb(this.pointColor2), this.pointWidth2);
- Pen pointPen3 = new Pen(Color.FromArgb(this.pointColor3), this.pointWidth3);
- SolidBrush brush1 = new SolidBrush(Color.FromArgb(this.pointColor1));
- SolidBrush brush2 = new SolidBrush(Color.FromArgb(this.pointColor2));
- SolidBrush brush3 = new SolidBrush(Color.FromArgb(this.pointColor3));
- if (this.rectangleFCaps1 != null && this.rectangleFCaps1.Count > 0)
- {
- foreach (var rectangleF in this.rectangleFCaps1)
- {
- if (pointStyle1 == 0)
- {
- if (this.pointshape1 == 0)
- graphics.DrawEllipse(pointPen1, rectangleF.X + (float)this.pointWidth1 / 2, rectangleF.Y + (float)this.pointWidth1 / 2, rectangleF.Width - (float)this.pointWidth1 * 2, rectangleF.Height - this.pointWidth1 * 2);
- else
- graphics.DrawRectangle(pointPen1, rectangleF.X + (float)this.pointWidth1 / 2, rectangleF.Y + (float)this.pointWidth1 / 2, rectangleF.Width - this.pointWidth1 * 2, rectangleF.Height - this.pointWidth1 * 2);
- }
- else
- {
- if (this.pointshape1 == 0)
- graphics.FillEllipse(brush1, rectangleF);
- else
- graphics.FillRectangle(brush1, rectangleF);
- }
- }
- }
- if (this.rectangleFCaps2 != null && this.rectangleFCaps2.Count > 0)
- {
- foreach (var rectangleF in this.rectangleFCaps2)
- {
- if (pointStyle2 == 0)
- {
- if (this.pointshape2 == 0)
- graphics.DrawEllipse(pointPen2, rectangleF.X + this.pointWidth2 / 2, rectangleF.Y + this.pointWidth2 / 2, rectangleF.Width - this.pointWidth2 * 2, rectangleF.Height - this.pointWidth2 * 2);
- else
- graphics.DrawRectangle(pointPen2, rectangleF.X + this.pointWidth2 / 2, rectangleF.Y + this.pointWidth2 / 2, rectangleF.Width - this.pointWidth2 * 2, rectangleF.Height - this.pointWidth2 * 2);
- }
- else
- {
- if (this.pointshape2 == 0)
- graphics.FillEllipse(brush2, rectangleF);
- else
- graphics.FillRectangle(brush2, rectangleF);
- }
- }
- }
- if (this.rectangleFCaps3_1 != null && this.rectangleFCaps3_1.Count > 0)
- {
- foreach (var rectangleF in this.rectangleFCaps3_1)
- {
- if (pointStyle3 == 0)
- {
- if (this.pointshape3 == 0)
- graphics.DrawEllipse(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
- else
- graphics.DrawRectangle(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
- }
- else
- {
- if (this.pointshape3 == 0)
- graphics.FillEllipse(brush3, rectangleF);
- else
- graphics.FillRectangle(brush3, rectangleF);
- }
- }
- }
- if (this.rectangleFCaps3_2 != null && this.rectangleFCaps3_2.Count > 0)
- {
- foreach (var rectangleF in this.rectangleFCaps3_2)
- {
- if (pointStyle3 == 0)
- {
- if (this.pointshape3 == 0)
- graphics.DrawEllipse(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
- else
- graphics.DrawRectangle(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
- }
- else
- {
- if (this.pointshape3 == 0)
- graphics.FillEllipse(brush3, rectangleF);
- else
- graphics.FillRectangle(brush3, rectangleF);
- }
- }
- }
- }
- /// <summary>
- /// 获取截点数量
- /// </summary>
- /// <returns></returns>
- public double getCountPoints()
- {
- return this.rectangleFCaps1.Count * 0.5 + this.rectangleFCaps2.Count * 1.0 + this.rectangleFCaps3_1.Count * 1.5 + this.rectangleFCaps3_2.Count * 2.0;
- }
- /// <summary>
- /// 手动添加截点
- /// </summary>
- /// <param name="pointFAdd">要添加的截点坐标</param>
- /// <param name="pointKb">节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2)</param>
- public void manualAddPoint(PointF pointFAdd, int pointKb)
- {
- if (pointKb == 1)
- {
- if (pointStyle1 == 0)
- {
- this.rectangleFCaps1.Add(new RectangleF(pointFAdd.X - this.pointDiameter1 / 2 - this.pointWidth1 / 2,
- pointFAdd.Y - this.pointDiameter1 / 2 - this.pointWidth1 / 2, this.pointDiameter1 + this.pointWidth1 * 2,
- this.pointDiameter1 + this.pointWidth1 * 2));
- this.rectangleCaps1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- else
- {
- this.rectangleFCaps1.Add(new RectangleF(pointFAdd.X - this.pointDiameter1 / 2, pointFAdd.Y - this.pointDiameter1 / 2,
- this.pointDiameter1, this.pointDiameter1));
- this.rectangleCaps1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- }
- else if (pointKb == 2)
- {
- if (pointStyle2 == 0)
- {
- this.rectangleFCaps2.Add(new RectangleF(pointFAdd.X - this.pointDiameter2 / 2 - this.pointWidth2 / 2,
- pointFAdd.Y - this.pointDiameter2 / 2 - this.pointWidth2 / 2, this.pointDiameter2 + this.pointWidth2 * 2,
- this.pointDiameter2 + this.pointWidth2 * 2));
- this.rectangleCaps2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- else
- {
- this.rectangleFCaps2.Add(new RectangleF(pointFAdd.X - this.pointDiameter2 / 2, pointFAdd.Y - this.pointDiameter2 / 2,
- this.pointDiameter2, this.pointDiameter2));
- this.rectangleCaps2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- }
- else if (pointKb == 3)
- {
- if (pointStyle3 == 0)
- {
- this.rectangleFCaps3_1.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2 - this.pointWidth3 / 2,
- pointFAdd.Y - this.pointDiameter3 / 2 - this.pointWidth3 / 2, this.pointDiameter3 + this.pointWidth3 * 2,
- this.pointDiameter3 + this.pointWidth3 * 2));
- this.rectangleCaps3_1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- else
- {
- this.rectangleFCaps3_1.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2, pointFAdd.Y - this.pointDiameter3 / 2,
- this.pointDiameter3, this.pointDiameter3));
- this.rectangleCaps3_1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- }
- else if (pointKb == 4)
- {
- if (pointStyle3 == 0)
- {
- this.rectangleFCaps3_2.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2 - this.pointWidth3 / 2,
- pointFAdd.Y - this.pointDiameter3 / 2 - this.pointWidth3 / 2, this.pointDiameter3 + this.pointWidth3 * 2,
- this.pointDiameter3 + this.pointWidth3 * 2));
- this.rectangleCaps3_2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- else
- {
- this.rectangleFCaps3_2.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2, pointFAdd.Y - this.pointDiameter3 / 2,
- this.pointDiameter3, this.pointDiameter3));
- this.rectangleCaps3_2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
- }
- }
- }
- /// <summary>
- /// 手动删除截点
- /// </summary>
- /// <param name="point1"></param>
- /// <param name="toAddPoint"></param>
- public void manualRemovePoint(PointF point1, out bool toAddPoint)
- {
- toAddPoint = true;
- for (int removeI = this.rectangleFCaps1.Count - 1; removeI >= 0; removeI--)
- {
- if (this.rectangleFCaps1[removeI].Contains(point1))
- {
- this.rectangleFCaps1.RemoveAt(removeI);
- this.rectangleCaps1.RemoveAt(removeI);
- toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
- break;
- }
- }
- for (int removeI = this.rectangleFCaps2.Count - 1; removeI >= 0; removeI--)
- {
- if (this.rectangleFCaps2[removeI].Contains(point1))
- {
- this.rectangleFCaps2.RemoveAt(removeI);
- this.rectangleCaps2.RemoveAt(removeI);
- toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
- break;
- }
- }
- for (int removeI = this.rectangleFCaps3_1.Count - 1; removeI >= 0; removeI--)
- {
- if (this.rectangleFCaps3_1[removeI].Contains(point1))
- {
- this.rectangleFCaps3_1.RemoveAt(removeI);
- this.rectangleCaps3_1.RemoveAt(removeI);
- toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
- break;
- }
- }
- for (int removeI = this.rectangleFCaps3_2.Count - 1; removeI >= 0; removeI--)
- {
- if (this.rectangleFCaps3_2[removeI].Contains(point1))
- {
- this.rectangleFCaps3_2.RemoveAt(removeI);
- this.rectangleCaps3_2.RemoveAt(removeI);
- toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
- break;
- }
- }
- }
- }
- }
|