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 { /// /// 直线图形上所有的点 /// public List> straightLinePointList = new List>(); /// /// 圆圈图形上所有的点,其中第一个点为圆心坐标 /// public List> roundLinePointList = new List>(); /// /// 图形上所有的两个截点和计算的截距值(像素) /// public Dictionary lineValueList = new Dictionary(); /// /// 0.5截点矩形集合 /// private List rectangleFCaps1 = new List(); private List rectangleCaps1 = new List(); /// /// 1截点矩形集合 /// private List rectangleFCaps2 = new List(); private List rectangleCaps2 = new List(); /// /// 1.5/2截点矩形集合(1.5) /// private List rectangleFCaps3_1 = new List(); private List rectangleCaps3_1 = new List(); /// /// 1.5/2截点矩形集合(2) /// private List rectangleFCaps3_2 = new List(); private List rectangleCaps3_2 = new List(); #region 截点样式 /// /// 颜色(0.5) /// private int pointColor1; /// /// 线宽(0.5) /// private int pointWidth1; /// /// 点样式 0:空心 1:实心(0.5) /// private int pointStyle1; /// /// 大小(0.5) /// private int pointDiameter1; /// /// 截点误差(0.5) /// private int pointError1; /// /// 形状 0:圆形 1:方形(0.5) /// private int pointshape1; /// /// 颜色(1) /// private int pointColor2; /// /// 线宽(1) /// private int pointWidth2; /// /// 点样式 0:空心 1:实心(1) /// private int pointStyle2; /// /// 大小(1) /// private int pointDiameter2; /// /// 截点误差(1) /// private int pointError2; /// /// 形状 0:圆形 1:方形(1) /// private int pointshape2; /// /// 颜色(1.5/2) /// private int pointColor3; /// /// 线宽(1.5/2) /// private int pointWidth3; /// /// 点样式 0:空心 1:实心(1.5/2) /// private int pointStyle3; /// /// 大小(1.5/2) /// private int pointDiameter3; /// /// 截点误差(1.5/2) /// private int pointError3; /// /// 形状 0:圆形 1:方形(1.5/2) /// private int pointshape3; #endregion /// /// 找到当前的参数数据 /// /// /// 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>(); //newMod.straightLinePointList.AddRange(this.straightLinePointList);//##### //newMod.roundLinePointList = new List>(); //newMod.roundLinePointList.AddRange(this.roundLinePointList);// ////newMod.lineValueList = new Dictionary(); 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 void ReloadLineValueList() { this.lineValueList.Clear(); for (int i = 0; i < straightLinePointList.Count; i++) { Dictionary lineValueList1 = new Dictionary(); List 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 lineValueList1 = new Dictionary(); List 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 linePointList, out Dictionary lineValueList1) { List rectangleCapsTotal = new List(); rectangleCapsTotal.AddRange(this.rectangleCaps1); rectangleCapsTotal.AddRange(this.rectangleCaps2); rectangleCapsTotal.AddRange(this.rectangleCaps3_1); rectangleCapsTotal.AddRange(this.rectangleCaps3_2); lineValueList1 = new Dictionary(); 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)); } } /// /// 刷新截点集合,并赋值截距列表 /// /// 图形上所有的点 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 lineValueList1 = new Dictionary(); List 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 lineValueList1 = new Dictionary(); List 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 linePointList, bool vGuideStylesOrHGuideStyles, int surfaceWidth, int surfaceHeight, out Dictionary lineValueList1) { lineValueList1 = new Dictionary(); 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((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(point.Y - 1, point.X - 1); if (vec4B.Item0 == 0) { count++; firstValueOnBoundry = true; lastValueOnBoundry = true; } vec4B = mat.At(point.Y - 1, point.X); if (vec4B.Item0 == 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y - 1, point.X + 1); if (vec4B.Item0 == 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y, point.X + 1); if (vec4B.Item0 == 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X + 1); if (vec4B.Item0 == 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X); if (vec4B.Item0 == 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X - 1); if (vec4B.Item0 == 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(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(point.Y - 1, point.X - 1); if (vec4B.Item3 != 0) { count++; firstValueOnBoundry = true; lastValueOnBoundry = true; } vec4B = mat.At(point.Y - 1, point.X); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y - 1, point.X + 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y, point.X + 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X + 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X - 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y, point.X - 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry && !firstValueOnBoundry) count++; } return count; } /// /// 更新截点样式 /// public void UpdateCupOffPointStyle() { GrainCutOffPointStyleModel grainCutOffPointStyleModel = XmlSerializeHelper.DESerializer(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; } /// /// 实现手动添加在原图情况下的截点位置跟随辅助线的移动而移动 /// /// /// 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(); } /// /// 绘制截点 /// 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); } } } } /// /// 获取截点数量 /// /// 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; } /// /// 手动添加截点 /// /// 要添加的截点坐标 /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2) 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)); } } } /// /// 手动删除截点 /// /// /// 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; } } } } }