private float GetPercentInArcByPoint(IDrawObject drawObject, UnitPoint unitPoint) { ArcBase arcBase = (ArcBase)drawObject; double angle = HitUtil.LineAngleR(arcBase.Center, unitPoint, 0); return((float)(angle / (Math.PI * 2))); }
private void SetPoint(Hexagon hexagon, UnitPoint unitPoint) { #region 变化单个节点 //hexagon.HexagonPoints[nodeIndex] = unitPoint; //double radius0 = hexagon.GetRadius(hexagon.HexagonPoints[0]); //double radius = hexagon.GetRadius(unitPoint); //double k = radius / radius0; //for (int i = 0; i < hexagon.HexagonPoints.Length; i++) //{ // hexagon.HexagonPoints[i].X = hexagon.HexagonPoints[i].X + (k - 1) * (hexagon.HexagonPoints[i].X - hexagon.CenterPoint.X); // hexagon.HexagonPoints[i].Y = hexagon.HexagonPoints[i].Y + (k - 1) * (hexagon.HexagonPoints[i].Y - hexagon.CenterPoint.Y); //} #endregion double startAngle = HitUtil.LineAngleR(hexagon.CenterPoint, unitPoint, 0); double radius = hexagon.GetRadius(unitPoint); hexagon.HexagonPoints[0] = unitPoint; for (int i = 1; i < hexagon.SideCount; i++) { UnitPoint vertexPoint = HitUtil.PointOnCircle(hexagon.CenterPoint, radius, startAngle + hexagon.stepAngle * Math.PI / 180 * i); hexagon.HexagonPoints[i] = vertexPoint; } //double currentNodeAngle = HitUtil.LineAngleR(hexagon.CenterPoint, unitPoint, 0); //double startAngle = currentNodeAngle - (nodeIndex * hexagon.stepAngle); //double radius = hexagon.GetRadius(unitPoint); //for (int i = 0; i < hexagon.SideCount; i++) //{ // UnitPoint vertexPoint = HitUtil.PointOnCircle(hexagon.CenterPoint, radius, startAngle + hexagon.stepAngle * Math.PI / 180 * i); // hexagon.HexagonPoints[i] = vertexPoint; //} }
private float GetPercentInCircleByPoint(IDrawObject drawObject, UnitPoint unitPoint) { Circle circle = (Circle)drawObject; double angle = HitUtil.LineAngleR(circle.Center, unitPoint, 0); return((float)(angle / (Math.PI * 2))); }
public override void OnMouseMove(ICanvas canvas, UnitPoint unitPoint) { if (this.arcCurrentPointType == ArcCurrentPointType.Center) { this.Center = unitPoint; return; } if (this.arcCurrentPointType == ArcCurrentPointType.StartPoint) { this.StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(this.Center, unitPoint, 0)); this.AngleSweep = 360; if (float.IsNaN(this.InRadiusValue)) { this.Radius = (float)HitUtil.Distance(this.Center, unitPoint); this.startPoint = unitPoint; } else { this.Radius = InRadiusValue; this.startPoint = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(StartAngle)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(StartAngle)) + this.Center.Y); } return; } if (this.arcCurrentPointType == ArcCurrentPointType.EndPoint) { float endAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(this.Center, unitPoint, 0)); this.AngleSweep = endAngle - this.StartAngle; this.AngleSweep = this.AngleSweep > 0 ? this.AngleSweep : this.AngleSweep + 360; this.endPoint = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(endAngle)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(endAngle)) + this.Center.Y); return; } }
public string GetInfoAsString() { return(string.Format("Line@{0},{1} - L={2:f4}<{3:f4}", P1.PosAsString(), P2.PosAsString(), HitUtil.Distance(P1, P2), HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P2, 0)))); }
/// <summary> /// 获取图形信息用于显示在面板下方 /// </summary> /// <returns></returns> string IDrawObject.GetInfoAsString() { return(string.Format("bezierCurve@{0},{1} - L={2:f4}<{3:f4}", P1.PosAsString(), P4.PosAsString(), HitUtil.Distance(P1, P4), HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P4, 0)))); }
public static UnitPoint GetBulgeCenter(UnitPoint vertex, UnitPoint cutoffPoint, UnitPoint cutoffPoint2, double radius) { UnitPoint midPoint = HitUtil.LineMidpoint(cutoffPoint, cutoffPoint2); double midAngle = HitUtil.LineAngleR(vertex, midPoint, 0); double sideLen = GetDistanceBetweenVertexAndCutoffPoint(radius, midAngle * 2); double vertexToCenter = radius * radius + sideLen * sideLen; UnitPoint center = HitUtil.LineEndPoint(vertex, midAngle, vertexToCenter); return(center); }
public NodePointCircleRadius(Circle3Point owner) { m_owner = owner; m_clone = m_owner.Clone() as Circle3Point; m_clone.CurrentPoint = m_owner.CurrentPoint; m_originalValue = m_owner.Radius; Angle1 = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_owner.Center, m_owner.P1, 0)); Angle2 = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_owner.Center, m_owner.P2, 0)); Angle3 = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_owner.Center, m_owner.P3, 0)); }
private void CalculateKeyPoints() { double startAngle = HitUtil.LineAngleR(this.centerPoint, this.hexagonPoints[0], 0); double radius = this.GetRadius(this.hexagonPoints[0]); for (int i = 1; i < this.SideCount; i++) { UnitPoint vertexPoint = HitUtil.PointOnCircle(this.centerPoint, radius, startAngle + this.stepAngle * Math.PI / 180 * i); this.hexagonPoints[i] = vertexPoint; } }
/// <summary> /// 根据圆心,圆上起始点,结束点及圆的时针方向计算圆弧凸度 /// </summary> /// <param name="center">圆心</param> /// <param name="startPoint">起始点</param> /// <param name="endPoint">结束点</param> /// <param name="clockwise">时针方向</param> /// <returns></returns> public static double GetBulgeFromTwoPointsAndCenter(UnitPoint center, UnitPoint startPoint, UnitPoint endPoint, bool clockwise) { double startAngle = HitUtil.LineAngleR(center, startPoint, 0); double endAngle = HitUtil.LineAngleR(center, endPoint, 0); double sweepAngle = HitUtil.CalAngleSweep(HitUtil.RadiansToDegrees(startAngle), HitUtil.RadiansToDegrees(endAngle), clockwise); sweepAngle = Math.Abs(HitUtil.DegreesToRadians(sweepAngle) / 4); double bulge = Math.Tan(sweepAngle); bulge = clockwise ? -bulge : bulge; return(bulge); }
/// <summary> /// 获取离交点距离一定的点 /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="p3"></param> /// <param name="radius"></param> /// <returns></returns> public static List <UnitPoint> GetCufPoint(UnitPoint p1, UnitPoint p2, UnitPoint p3, double radius) { List <UnitPoint> cutPoints = new List <UnitPoint>(); double angle = HitUtil.LineAngleR(p2, p1, 0); UnitPoint cutPoint = HitUtil.LineEndPoint(p2, angle, radius); cutPoints.Add(cutPoint); angle = HitUtil.LineAngleR(p2, p3, 0); cutPoint = HitUtil.LineEndPoint(p2, angle, radius); cutPoints.Add(cutPoint); return(cutPoints); }
private static double IsCorrectCenter(UnitPoint center, double radius, double bulge, UnitPoint p1, UnitPoint p2) { double startAngle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p1, 0)); double endAngle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p2, 0)); bool clockwise = bulge >= 0 ? false : true; double sweepAngle = HitUtil.CalAngleSweep(startAngle, endAngle, clockwise); double midAngle = startAngle + sweepAngle / 2; UnitPoint midPoint = new UnitPoint(radius * Math.Cos(HitUtil.DegreesToRadians(midAngle)) + center.X, radius * Math.Sin(HitUtil.DegreesToRadians(midAngle)) + center.Y); double temp = BulgeToDegree(bulge); return(Math.Abs(temp - Math.Abs(sweepAngle))); }
private void CalculateVertexPoints(UnitPoint centerPoint, UnitPoint vertexPoint) { double startAngle = HitUtil.LineAngleR(centerPoint, vertexPoint, 0); double radius = HitUtil.Distance(centerPoint, vertexPoint, true); double stepAngle = 360 / this.SideCount; for (int i = 0; i < this.SideCount; i++) { UnitPoint point = HitUtil.PointOnCircle(centerPoint, radius, startAngle + stepAngle * Math.PI / 180 * i); this.Points.Add(new UnitPointBulge(point)); } }
private void GetCircleLeadLineParams(IDrawObject drawObject, LineInOutParamsModel leadInOutParamsModel) { Circle circle = (Circle)drawObject; double angle = HitUtil.LineAngleR(circle.Center, this.p2, 0); leadInOutParamsModel.FigureTotalLength = (float)(angle / (Math.PI * 2)); this.p2 = HitUtil.PointOnCircle(circle.Center, circle.Radius, angle); bool isInner; leadInOutParamsModel.LineInAngle = DrawingOperationHelper.GetLeadLineAngleArc(this.p1, this.p2, circle.Center, circle.IsClockwise, out isInner); leadInOutParamsModel.LineInLength = (float)HitUtil.Distance(this.p1, this.p2); circle.IsInnerCut = isInner; }
public static UnitPoint GetBulgeMidPoint(UnitPoint p1, UnitPoint p2, double bulge) { bool clockwise = bulge >= 0 ? false : true; UnitPoint center = GetCenterByBulgeAndTwoPoints(p1, p2, bulge); float radius = (float)HitUtil.Distance(center, p1); float startAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p1, 0)); float EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p2, 0)); float sweepAngle = (float)HitUtil.CalAngleSweep(startAngle, EndAngle, clockwise); float midAngle = startAngle + sweepAngle / 2; UnitPoint midPoint = new UnitPoint(radius * Math.Cos(HitUtil.DegreesToRadians(midAngle)) + center.X, radius * Math.Sin(HitUtil.DegreesToRadians(midAngle)) + center.Y); return(midPoint); }
private void CalculateVertexPoints2(UnitPoint centerPoint, UnitPoint vertexPoint) { double startAngle = HitUtil.LineAngleR(centerPoint, this.Points[1].Point, 0); double r = HitUtil.Distance(centerPoint, vertexPoint, true); double stepAngle = 360 / this.SideCount; for (int i = 0; i < this.Points.Count; i++) { if (i % 2 != 0) { UnitPoint point = HitUtil.PointOnCircle(centerPoint, r, startAngle + stepAngle * Math.PI / 180 * (i / 2)); this.Points[i] = new UnitPointBulge(point); } } }
public static List <UnitPoint> GetCufoffPoint(UnitPoint p1, UnitPoint p2, UnitPoint p3, double radius) { List <UnitPoint> cutoffPoints = new List <UnitPoint>(); double lineAngle = CalTwoLinesAngleFromThreePoints(p1, p2, p3); double length = radius / Math.Tan(lineAngle / 2); double preAngle = HitUtil.LineAngleR(p2, p1, 0); UnitPoint prePoint = HitUtil.LineEndPoint(p2, preAngle, length); //UnitPoint prePoint = HitUtil.PointOnCircle(p2, length, preAngle); cutoffPoints.Add(prePoint); double nextAngle = HitUtil.LineAngleR(p2, p3, 0); UnitPoint nextPoint = HitUtil.LineEndPoint(p2, nextAngle, length); //UnitPoint nextPoint = HitUtil.PointOnCircle(p2, length, nextAngle); cutoffPoints.Add(nextPoint); return(cutoffPoints); }
/* * UnitPoint GetPoint() * { * if (m_curPoint == Arc3Point.eCurrentPoint.p1) * return m_clone.P1; * if (m_curPoint == Arc3Point.eCurrentPoint.p2) * return m_clone.P2; * if (m_curPoint == Arc3Point.eCurrentPoint.p3) * return m_clone.P3; * if (m_curPoint == Arc3Point.eCurrentPoint.startangle) * return m_clone.P1; * if (m_curPoint == Arc3Point.eCurrentPoint.endangle) * return m_clone.P3; * if (m_curPoint == Arc3Point.eCurrentPoint.radius) * return m_clone.P2; * return UnitPoint.Empty; * } * */ void SetPoint(Arc3Point arc, UnitPoint pos) { if (m_curPoint == Arc3Point.eCurrentPoint.p1) { arc.P1 = pos; } if (m_curPoint == Arc3Point.eCurrentPoint.p2) { arc.P2 = pos; } if (m_curPoint == Arc3Point.eCurrentPoint.p3) { arc.P3 = pos; } double angleToRound = 0; if (Control.ModifierKeys == Keys.Control) { angleToRound = HitUtil.DegressToRadians(45); } double angleR = HitUtil.LineAngleR(arc.Center, pos, angleToRound); if (m_curPoint == Arc3Point.eCurrentPoint.startangle) { arc.P1 = HitUtil.PointOncircle(arc.Center, arc.Radius, angleR); } if (m_curPoint == Arc3Point.eCurrentPoint.endangle) { arc.P3 = HitUtil.PointOncircle(arc.Center, arc.Radius, angleR); } if (m_curPoint == Arc3Point.eCurrentPoint.radius) { double radius = HitUtil.Distance(arc.Center, pos); arc.P1 = HitUtil.PointOncircle(arc.Center, radius, HitUtil.DegressToRadians(arc.StartAngle)); arc.P2 = pos; arc.P3 = HitUtil.PointOncircle(arc.Center, radius, HitUtil.DegressToRadians(arc.EndAngle)); } arc.UpdateArcFrom3Points(); if ((m_curPoint == Arc3Point.eCurrentPoint.startangle) || (m_curPoint == Arc3Point.eCurrentPoint.endangle)) { arc.UpdateCenterNodeFromAngles(); } }
public void CalOverCuttingPoints(UnitPoint startPoint, UnitPoint p2, double length, int index) { double distance = HitUtil.Distance(startPoint, p2); if (length > distance) { this.OverCuttingPoints.Add(p2); length -= distance; index += 1; this.CalOverCuttingPoints(p2, this.MachinePoints[index], length, index); } else { double angle = HitUtil.LineAngleR(startPoint, p2, 0); UnitPoint unitPoint = HitUtil.PointOnCircle(startPoint, length, angle); this.OverCuttingPoints.Add(unitPoint); } }
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point) { m_lastPoint = point; if (m_curPoint == eCurrentPoint.p1) { m_p1 = point; Center = point; return; } if (m_curPoint == eCurrentPoint.p2) { StartAngle = 0; EndAngle = 360; Center = HitUtil.LineMidpoint(m_p1, point); m_radius = (float)HitUtil.Distance(m_center, point); return; } if (m_curPoint == eCurrentPoint.center) { Center = point; } if (m_curPoint == eCurrentPoint.radius) { //StartAngle = 0; //EndAngle = 360; m_radius = (float)HitUtil.Distance(m_center, point); } double angleToRound = 0; if (Control.ModifierKeys == Keys.Control) { angleToRound = HitUtil.DegressToRadians(45); } if (m_curPoint == eCurrentPoint.startAngle) { StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, point, angleToRound)); } if (m_curPoint == eCurrentPoint.endAngle) { EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, point, angleToRound)); } }
/// <summary> /// 根据三个点来更新圆弧 /// </summary> public void UpdateArcFrom3Points() { //Console.WriteLine("UpdateArcFrom3Points()"); m_center = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3); m_radius = (float)HitUtil.Distance(m_center, m_p1); StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0)); EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0)); // find angle from P1 on line P1|P3 to P2. If this angle is 0-180 the direction is CCW else it is CW double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0)); double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0)); double diff = p1p3angle - p1p2angle; //我知道这个逻辑存在问题,在某些情况下,圆弧的绘制不跟随鼠标, //但是现在也会奏效。 Direction = eDirection.kCCW; if (diff < 0 || diff > 180) { Direction = eDirection.kCW; } if (p1p3angle == 0) { if (diff < -180) { Direction = eDirection.kCCW; } else { Direction = eDirection.kCW; } } if (p1p3angle == 90) { if (diff < -180) { Direction = eDirection.kCCW; } } }
public void UpdateArcFrom3Points() { m_center = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3); m_radius = (float)HitUtil.Distance(m_center, m_p1); StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0)); EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0)); // find angle from P1 on line P1|P3 to P2. If this angle is 0-180 the direction is CCW else it is CW double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0)); double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0)); double diff = p1p3angle - p1p2angle; // I know there is a problem with this logic, in some cases the arc does not follow the mouse, // but it will work for now. Direction = eDirection.kCCW; if (diff < 0 || diff > 180) { Direction = eDirection.kCW; } if (p1p3angle == 0) { if (diff < -180) { Direction = eDirection.kCCW; } else { Direction = eDirection.kCW; } } if (p1p3angle == 90) { if (diff < -180) { Direction = eDirection.kCCW; } } }
public void UpdateArcFrom3Points() { try { m_center = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3); m_radius = (float)HitUtil.Distance(m_center, m_p1); StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0)); EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0)); double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0)); double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0)); double diff = p1p3angle - p1p2angle; Direction = eDirection.kCCW; if (diff < 0 || diff > 180) { Direction = eDirection.kCW; } if (p1p3angle == 0) { if (diff < -180) { Direction = eDirection.kCCW; } else { Direction = eDirection.kCW; } } if (p1p3angle == 90) { if (diff < -180) { Direction = eDirection.kCCW; } } } catch (Exception ex) { throw ex; } }
private void SetNewStartMovePoint() { double cloneStartAngle = HitUtil.LineAngleR(this.clone.CenterPoint, this.clone.HexagonPoints[0], 0); double offsetAngle = cloneStartAngle - HitUtil.LineAngleR(this.owner.CenterPoint, this.owner.HexagonPoints[0], 0); double cloneStartMoveAngle = HitUtil.LineAngleR(this.owner.CenterPoint, this.owner.StartMovePoint, 0) + offsetAngle; if (cloneStartMoveAngle > 2 * Math.PI) { cloneStartMoveAngle -= 2 * Math.PI; } else if (cloneStartMoveAngle < 0) { cloneStartMoveAngle += 2 * Math.PI; } this.clone.StartMovePoint = HitUtil.PointOnCircle(this.clone.CenterPoint, this.clone.GetRadius(this.clone.HexagonPoints[0]), cloneStartMoveAngle); if (this.owner.StartMovePointIndex != this.owner.HexagonPoints.Length - 1) { this.clone.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.clone.CenterPoint, this.clone.StartMovePoint, this.clone.HexagonPoints[this.owner.StartMovePointIndex], this.clone.HexagonPoints[this.owner.StartMovePointIndex + 1]); } else { this.clone.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.clone.CenterPoint, this.clone.StartMovePoint, this.clone.HexagonPoints[this.owner.StartMovePointIndex], this.clone.HexagonPoints[0]); } }
private void GetMultiLineLeadLineParams(IDrawObject drawObject, LineInOutParamsModel leadInOutParamsModel) { MultiSegmentLineBase multiSegmentLine = drawObject as MultiSegmentLineBase; int segment = 0; if (multiSegmentLine != null) { //所在段数必须合法 segment = DrawingOperationHelper.GetPointInLineIndex(multiSegmentLine, this.p2); int nextIndex = (segment + 1 >= multiSegmentLine.PointCount && multiSegmentLine.IsCloseFigure) ? 0 : segment + 1; if (double.IsNaN(multiSegmentLine.Points[segment].Bulge)) { double partLen = HitUtil.Distance(multiSegmentLine.Points[segment].Point, this.p2); double allLen = HitUtil.Distance(multiSegmentLine.Points[segment].Point, multiSegmentLine.Points[nextIndex].Point); float percent = (float)(segment + partLen / allLen); leadInOutParamsModel.FigureTotalLength = (float)(DrawingOperationHelper.GetLengthByPositionInPolyLine(multiSegmentLine.Points, multiSegmentLine.IsCloseFigure, percent) / multiSegmentLine.SizeLength); //角度(p1p2与当前线段所成夹角或与圆弧在当前鼠标点位置的切点出的切线所成夹角) this.p2 = HitUtil.FindApparentIntersectPoint(this.p1, this.p2, multiSegmentLine.Points[segment].Point, multiSegmentLine.Points[nextIndex].Point); double lineAngle = HitUtil.LineAngleR(multiSegmentLine.Points[nextIndex].Point, multiSegmentLine.Points[segment].Point, 0); UnitPoint extensionCordPoint = HitUtil.LineEndPoint(multiSegmentLine.Points[segment].Point, lineAngle, 5); leadInOutParamsModel.LineInAngle = (float)BulgeHelper.CalTwoLinesAngleFromThreePoints(extensionCordPoint, this.p2, this.p1); multiSegmentLine.IsInnerCut = HitUtil.IsClockwiseByCross(this.p1, this.p2, extensionCordPoint) == multiSegmentLine.Clockwise ? false : true; } else { ArcModelMini arcModelMini = DrawingOperationHelper.GetArcParametersFromBulge(multiSegmentLine.Points[segment].Point, multiSegmentLine.Points[nextIndex].Point, (float)multiSegmentLine.Points[segment].Bulge); float percent = segment + DrawingOperationHelper.GetPercentInArcByPoint(arcModelMini, this.p2); leadInOutParamsModel.FigureTotalLength = (float)(DrawingOperationHelper.GetLengthByPositionInPolyLine(multiSegmentLine.Points, multiSegmentLine.IsCloseFigure, percent) / multiSegmentLine.SizeLength); bool isInner; leadInOutParamsModel.LineInAngle = DrawingOperationHelper.GetLeadLineAngleArc(this.p1, this.p2, arcModelMini.Center, arcModelMini.Clockwise, out isInner); multiSegmentLine.IsInnerCut = isInner; } } //长度(p1p2的长度) leadInOutParamsModel.LineInLength = (float)HitUtil.Distance(p1, p2); }
public void DoArcFlyingCut(List <IDrawObject> drawObjects, List <IDrawObject> flyArcGroups = null, List <IDrawObject> drawObjectsnew = null, List <IDrawObject> drawObjectsold = null) { List <IDrawObject> NewDrawobjects = new List <IDrawObject>(); if (flyArcGroups != null) { Circle circle = null; Circle newCircle = null; foreach (var idraw in flyArcGroups) { //按零件飞起,可能有图形不是圆 if (!(idraw is Circle)) { NewDrawobjects.Add(idraw.Clone()); continue; } circle = idraw as Circle; //因超过设定距离,该group只有一个圆 if (circle.GroupParam.GroupSN[1] == 0) { NewDrawobjects.Add(circle.Clone()); ((Circle)NewDrawobjects[NewDrawobjects.Count - 1]).IsFlyingCut = false; continue; } // 起点修改 StartAngle float StartAngle = (float)HitUtil.RadiansToDegrees( HitUtil.LineAngleR(circle.Center, circle.StartMovePoint, 0)); newCircle = new Circle() { Center = circle.Center, Radius = circle.Radius, StartAngle = StartAngle, StartMovePoint = circle.StartMovePoint, EndMovePoint = circle.StartMovePoint, IsFlyingCut = true, FlyingCutLeadOut = circle.FlyingCutLeadOut, GroupParam = circle.GroupParam }; newCircle.LeadIn.Position = StartAngle / 360.0f; newCircle.LeadOut.Position = StartAngle / 360.0f; NewDrawobjects.Add(newCircle); } if (NewDrawobjects.Count == 0) { return; } } if (drawObjectsnew == null) { if (NewDrawobjects == null || NewDrawobjects.Count <= 0)//重做 { NewDrawobjects = drawObjects.ToList(); this.DrawingLayer.DeleteObjects(drawObjectsold); } else { int newCount = NewDrawobjects.Count; int groupCount = NewDrawobjects.Max(o => o.GroupParam.GroupSN.Count > 1 ? o.GroupParam.GroupSN[1]: 0); int minSelectedSn = drawObjects.Min(idraw => idraw.GroupParam.FigureSN); //未被选中或者圆以外的图形,大于飞切的最小FigureSN的 加入到变化图形集合(方便做撤销和恢复) int noChange = 0; this.DrawingLayer.Objects.ForEach(idraw => { if (!drawObjects.Contains(idraw) && idraw.GroupParam.FigureSN > minSelectedSn && !flyArcGroups.Contains(idraw)) { drawObjects.Insert(noChange, idraw); NewDrawobjects.Insert(noChange, idraw.Clone()); noChange++; } }); this.DrawingLayer.DeleteObjects(drawObjects); int sn = this.DrawingLayer.Objects.Count; int idx = 0; NewDrawobjects.ForEach(r => { r.GroupParam.FigureSN = ++sn; }); idx = 0; int baseGroupSN = GlobalModel.TotalGroupCount; int previousGroupSN = -1; int currentGroupSN = 0; NewDrawobjects.ForEach(r => { if (++idx > noChange && r.GroupParam.GroupSN.Count > 1) { if (r.GroupParam.GroupSN[1] == 0) { r.GroupParam.GroupSN.RemoveAt(1); } else { currentGroupSN = baseGroupSN + r.GroupParam.GroupSN[1]; r.GroupParam.GroupSN.RemoveAt(1); r.GroupParam.GroupSN.Insert(1, currentGroupSN); if (previousGroupSN != currentGroupSN) { r.GroupParam.GroupSN[0] = r.GroupParam.FigureSN; } previousGroupSN = currentGroupSN; } } }); GlobalModel.TotalGroupCount = GlobalModel.TotalGroupCount + groupCount; } GlobalModel.TotalDrawObjectCount = GlobalModel.TotalDrawObjectCount + NewDrawobjects.Count; this.DrawingLayer.AddObjectOnDrawing(NewDrawobjects); if (this.undoRedoBuffer.CanCapture) { Circle circle = null; foreach (var item in drawObjects) { circle = item as Circle; if (circle != null) { circle.FlyingCutLeadOut = null; } } drawObjects = drawObjects.OrderBy(c => c.GroupParam.FigureSN).ToList(); this.undoRedoBuffer.AddCommand(new EditCommandArcFlyingCut(drawObjects, NewDrawobjects)); } this.UpdateSN(); } else { ((DrawingLayer)this.DrawingLayer).DeleteObjects(drawObjectsnew); foreach (var item in drawObjects) { this.DrawingLayer.AddObjectOnRedoUndo(item); } } }