// Method for elliptical arc extension private bool ExtendEllipticalArc(ICurve ellipticalArcCurve, ICurve boundary, bool start) { EllipticalArc selEllipseArc = ellipticalArcCurve as EllipticalArc; Ellipse tempEllipse = new Ellipse(selEllipseArc.Plane, selEllipseArc.Center, selEllipseArc.RadiusX, selEllipseArc.RadiusY); #if NURBS Point3D[] intersetionPoints = Curve.Intersection(boundary, tempEllipse); if (intersetionPoints.Length == 0) { intersetionPoints = Curve.Intersection(GetExtendedBoundary(boundary), tempEllipse); } EllipticalArc newArc = null; if (intersetionPoints.Length > 0) { Plane arcPlane = selEllipseArc.Plane; if (start) { Point3D intPoint = GetClosestPoint(selEllipseArc.StartPoint, intersetionPoints); newArc = new EllipticalArc(arcPlane, selEllipseArc.Center, selEllipseArc.RadiusX, selEllipseArc.RadiusY, selEllipseArc.EndPoint, intPoint, false); // If start point is not on the new arc, flip needed double t; newArc.ClosestPointTo(selEllipseArc.StartPoint, out t); Point3D projPt = newArc.PointAt(t); if (projPt.DistanceTo(selEllipseArc.StartPoint) > 0.1) { newArc = new EllipticalArc(arcPlane, selEllipseArc.Center, selEllipseArc.RadiusX, selEllipseArc.RadiusY, selEllipseArc.EndPoint, intPoint, true); } AddAndRefresh(newArc, ((Entity)ellipticalArcCurve).LayerName); } else { Point3D intPoint = GetClosestPoint(selEllipseArc.EndPoint, intersetionPoints); newArc = new EllipticalArc(arcPlane, selEllipseArc.Center, selEllipseArc.RadiusX, selEllipseArc.RadiusY, selEllipseArc.StartPoint, intPoint, false); // If end point is not on the new arc, flip needed double t; newArc.ClosestPointTo(selEllipseArc.EndPoint, out t); Point3D projPt = newArc.PointAt(t); if (projPt.DistanceTo(selEllipseArc.EndPoint) > 0.1) { newArc = new EllipticalArc(arcPlane, selEllipseArc.Center, selEllipseArc.RadiusX, selEllipseArc.RadiusY, selEllipseArc.StartPoint, intPoint, true); } } if (newArc != null) { AddAndRefresh(newArc, ((Entity)ellipticalArcCurve).LayerName); return(true); } } #endif return(false); }
// Draws interactive elliptical arc // Inputs - Ellipse center, End of first axis, End of second axis, Start and End point private void DrawInteractiveEllipticalArc() { Point3D center = points[0]; if (points.Count <= 3) { DrawInteractiveEllipse(); } ScreenToPlane(mouseLocation, plane, out current); if (points.Count == 3) // ellipse completed, ask user to select start point { //start position line renderContext.DrawLine(WorldToScreen(center), WorldToScreen(points[1])); //current position line renderContext.DrawLine(WorldToScreen(center), WorldToScreen(current)); //arc portion radius = center.DistanceTo(points[1]); radiusY = points[2].DistanceTo(new Segment2D(center, points[1])); if (radius > 1e-3 && radiusY > 1e-3) { DrawPositionMark(points[0]); drawingPlane = GetPlane(points[1]); Vector2D v1 = new Vector2D(center, points[1]); v1.Normalize(); Vector2D v2 = new Vector2D(center, current); v2.Normalize(); arcSpanAngle = Vector2D.SignedAngleBetween(v1, v2); if (Math.Abs(arcSpanAngle) > 1e-3) { EllipticalArc tempArc = new EllipticalArc(drawingPlane, drawingPlane.Origin, radius, radiusY, 0, arcSpanAngle, true); Draw(tempArc); } } } }
/// <summary> /// identify snapPoints of the entity under mouse cursor in that moment, using PickBoxSize as tolerance /// </summary> public SnapPoint[] GetSnapPoints(System.Drawing.Point mouseLocation) { //changed PickBoxSize to define a range for display snapPoints int oldSize = PickBoxSize; PickBoxSize = 10; //select the entity under mouse cursor Transformation accumulatedParentTransform = new Identity(); Entity ent = GetNestedEntity(mouseLocation, Entities, ref accumulatedParentTransform); PickBoxSize = oldSize; SnapPoint[] snapPoints = new SnapPoint[0]; if (ent != null) { //extract the entity selected with GetEntityUnderMouseCursor //check which type of entity is it and then,identify snap points if (ent is devDept.Eyeshot.Entities.Point) { devDept.Eyeshot.Entities.Point point = (devDept.Eyeshot.Entities.Point)ent; switch (activeObjectSnap) { case objectSnapType.Point: Point3D point3d = point.Vertices[0]; snapPoints = new SnapPoint[] { new SnapPoint(point3d, objectSnapType.Point) }; break; } } else if (ent is Line) //line { Line line = (Line)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[] { new SnapPoint(line.StartPoint, objectSnapType.End), new SnapPoint(line.EndPoint, objectSnapType.End) }; break; case objectSnapType.Mid: snapPoints = new SnapPoint[] { new SnapPoint(line.MidPoint, objectSnapType.Mid) }; break; } } else if (ent is LinearPath)//polyline { LinearPath polyline = (LinearPath)ent; List <SnapPoint> polyLineSnapPoints = new List <SnapPoint>(); switch (activeObjectSnap) { case objectSnapType.End: foreach (Point3D point in polyline.Vertices) { polyLineSnapPoints.Add(new SnapPoint(point, objectSnapType.End)); } snapPoints = polyLineSnapPoints.ToArray(); break; } } else if (ent is CompositeCurve)//composite { CompositeCurve composite = (CompositeCurve)ent; List <SnapPoint> polyLineSnapPoints = new List <SnapPoint>(); switch (activeObjectSnap) { case objectSnapType.End: foreach (ICurve curveSeg in composite.CurveList) { polyLineSnapPoints.Add(new SnapPoint(curveSeg.EndPoint, objectSnapType.End)); } polyLineSnapPoints.Add(new SnapPoint(composite.CurveList[0].StartPoint, objectSnapType.End)); snapPoints = polyLineSnapPoints.ToArray(); break; } } else if (ent is Arc) //Arc { Arc arc = (Arc)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[] { new SnapPoint(arc.StartPoint, objectSnapType.End), new SnapPoint(arc.EndPoint, objectSnapType.End) }; break; case objectSnapType.Mid: snapPoints = new SnapPoint[] { new SnapPoint(arc.MidPoint, objectSnapType.Mid) }; break; case objectSnapType.Center: snapPoints = new SnapPoint[] { new SnapPoint(arc.Center, objectSnapType.Center) }; break; } } else if (ent is Circle) //Circle { Circle circle = (Circle)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[] { new SnapPoint(circle.EndPoint, objectSnapType.End) }; break; case objectSnapType.Mid: snapPoints = new SnapPoint[] { new SnapPoint(circle.PointAt(circle.Domain.Mid), objectSnapType.Mid) }; break; case objectSnapType.Center: snapPoints = new SnapPoint[] { new SnapPoint(circle.Center, objectSnapType.Center) }; break; case objectSnapType.Quad: Point3D quad1 = new Point3D(circle.Center.X, circle.Center.Y + circle.Radius); Point3D quad2 = new Point3D(circle.Center.X + circle.Radius, circle.Center.Y); Point3D quad3 = new Point3D(circle.Center.X, circle.Center.Y - circle.Radius); Point3D quad4 = new Point3D(circle.Center.X - circle.Radius, circle.Center.Y); snapPoints = new SnapPoint[] { new SnapPoint(quad1, objectSnapType.Quad), new SnapPoint(quad2, objectSnapType.Quad), new SnapPoint(quad3, objectSnapType.Quad), new SnapPoint(quad4, objectSnapType.Quad) }; break; } } #if NURBS else if (ent is Curve) // Spline { Curve curve = (Curve)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[] { new SnapPoint(curve.StartPoint, objectSnapType.End), new SnapPoint(curve.EndPoint, objectSnapType.End) }; break; case objectSnapType.Mid: snapPoints = new SnapPoint[] { new SnapPoint(curve.PointAt(0.5), objectSnapType.Mid) }; break; } } #endif else if (ent is EllipticalArc) //Elliptical Arc { EllipticalArc elArc = (EllipticalArc)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[] { new SnapPoint(elArc.StartPoint, objectSnapType.End), new SnapPoint(elArc.EndPoint, objectSnapType.End) }; break; case objectSnapType.Center: snapPoints = new SnapPoint[] { new SnapPoint(elArc.Center, objectSnapType.Center) }; break; } } else if (ent is Ellipse) //Ellipse { Ellipse ellipse = (Ellipse)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[] { new SnapPoint(ellipse.EndPoint, objectSnapType.End) }; break; case objectSnapType.Mid: snapPoints = new SnapPoint[] { new SnapPoint(ellipse.PointAt(ellipse.Domain.Mid), objectSnapType.Mid) }; break; case objectSnapType.Center: snapPoints = new SnapPoint[] { new SnapPoint(ellipse.Center, objectSnapType.Center) }; break; } } else if (ent is Mesh) //Mesh { Mesh mesh = (Mesh)ent; switch (activeObjectSnap) { case objectSnapType.End: snapPoints = new SnapPoint[mesh.Vertices.Length]; for (int i = 0; i < mesh.Vertices.Length; i++) { Point3D pt = mesh.Vertices[i]; snapPoints[i] = new SnapPoint(pt, objectSnapType.End); } break; } } } if (accumulatedParentTransform != new Identity()) { Point3D p_tmp; foreach (SnapPoint sp in snapPoints) { p_tmp = accumulatedParentTransform * sp; sp.X = p_tmp.X; sp.Y = p_tmp.Y; sp.Z = p_tmp.Z; } } return(snapPoints); }
public void AcceptGraphicalPrimitiveEllipticalArc(EllipticalArc ellipticalArc, PrintContext parameter) { parameter.WriteLine("Elliptical Arc: {0} @ {1} - {2} ({3} to {4})", ellipticalArc.Center, ellipticalArc.FirstConjugateDiameter, ellipticalArc.SecondConjugateDiameter, ellipticalArc.Start, ellipticalArc.End); }
public SnapPoint[] GetSnapPoints() { //changed PickBoxSize to define a range for display snapPoints int oldSize = PickBoxSize; PickBoxSize = 10; PickBoxSize = oldSize; List <SnapPoint> snapPoints = new List <SnapPoint>(); if (CurrentIndex != -1) { devDept.Eyeshot.Entities.Entity ent = Entities[CurrentIndex]; if (ent is Entity.IFFEntity ffEntity) { snapPoints.AddRange(ffEntity.GetSnapPoints(StateSnap)); } else if (ent is Point point) { foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.POINT: Point3D point3d = point.Vertices[0]; snapPoints.Add(new SnapPoint(point3d, SnapState.SnapType.POINT)); break; } } } else if (ent is Line line) //line { foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: snapPoints.Add(new SnapPoint(line.StartPoint, SnapState.SnapType.END)); snapPoints.Add(new SnapPoint(line.EndPoint, SnapState.SnapType.END)); break; case SnapState.SnapType.MID: snapPoints.Add(new SnapPoint(line.MidPoint, SnapState.SnapType.MID)); break; } } } else if (ent is LinearPath polyline)//polyline { List <SnapPoint> polyLineSnapPoints = new List <SnapPoint>(); foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: foreach (var ver in polyline.Vertices) { polyLineSnapPoints.Add(new SnapPoint(ver, SnapState.SnapType.END)); } snapPoints.AddRange(polyLineSnapPoints); break; } } } else if (ent is CompositeCurve composite)//composite { List <SnapPoint> polyLineSnapPoints = new List <SnapPoint>(); foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: foreach (ICurve curveSeg in composite.CurveList) { polyLineSnapPoints.Add(new SnapPoint(curveSeg.EndPoint, SnapState.SnapType.END)); } polyLineSnapPoints.Add(new SnapPoint(composite.CurveList[0].StartPoint, SnapState.SnapType.END)); snapPoints.AddRange(polyLineSnapPoints); break; } } } else if (ent is Arc arc) //Arc { foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(arc.StartPoint, SnapState.SnapType.END), new SnapPoint(arc.EndPoint, SnapState.SnapType.END) }); break; case SnapState.SnapType.MID: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(arc.MidPoint, SnapState.SnapType.MID) }); break; case SnapState.SnapType.CENTER: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(arc.Center, SnapState.SnapType.CENTER) }); break; } } } else if (ent is Circle circle) //Circle { foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(circle.EndPoint, SnapState.SnapType.END) }); break; case SnapState.SnapType.MID: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(circle.PointAt(circle.Domain.Mid), SnapState.SnapType.MID) }); break; case SnapState.SnapType.CENTER: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(circle.Center, SnapState.SnapType.CENTER) }); break; case SnapState.SnapType.QUAD: Point3D quad1 = new Point3D(circle.Center.X, circle.Center.Y + circle.Radius); Point3D quad2 = new Point3D(circle.Center.X + circle.Radius, circle.Center.Y); Point3D quad3 = new Point3D(circle.Center.X, circle.Center.Y - circle.Radius); Point3D quad4 = new Point3D(circle.Center.X - circle.Radius, circle.Center.Y); snapPoints.AddRange(new SnapPoint[] { new SnapPoint(quad1, SnapState.SnapType.QUAD), new SnapPoint(quad2, SnapState.SnapType.QUAD), new SnapPoint(quad3, SnapState.SnapType.QUAD), new SnapPoint(quad4, SnapState.SnapType.QUAD) }); break; } } } else if (ent is Curve curve) // Spline { foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(curve.StartPoint, SnapState.SnapType.END), new SnapPoint(curve.EndPoint, SnapState.SnapType.END) }); break; case SnapState.SnapType.MID: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(curve.PointAt(0.5), SnapState.SnapType.MID) }); break; } } } else if (ent is EllipticalArc) //Elliptical Arc { EllipticalArc elArc = (EllipticalArc)ent; foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(elArc.StartPoint, SnapState.SnapType.END), new SnapPoint(elArc.EndPoint, SnapState.SnapType.END) }); break; case SnapState.SnapType.CENTER: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(elArc.Center, SnapState.SnapType.CENTER) }); break; } } } else if (ent is Ellipse) //Ellipse { Ellipse ellipse = (Ellipse)ent; foreach (var activeObjectSnap in StateSnap.EnabledSnapTypes) { switch (activeObjectSnap) { case SnapState.SnapType.END: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(ellipse.EndPoint, SnapState.SnapType.END) }); break; case SnapState.SnapType.MID: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(ellipse.PointAt(ellipse.Domain.Mid), SnapState.SnapType.MID) }); break; case SnapState.SnapType.CENTER: snapPoints.AddRange(new SnapPoint[] { new SnapPoint(ellipse.Center, SnapState.SnapType.CENTER) }); break; } } } //else if (ent is Entities.NSphere) //Mesh //{ // Entities.NSphere mesh = (Entities.NSphere)ent; // foreach (var activeObjectSnap in CurrentSnapTypes) // { // snapPoints.Add(new SnapPoint(mesh.center, SnapType.END)); // break; // } //} } return(snapPoints.ToArray()); }
public virtual void AcceptGraphicalPrimitiveEllipticalArc(EllipticalArc ellipticalArc, T parameter) { // intentionally left blank }
public bool AreEqual(Entity ent1, Entity ent2) { if (ent1 is CompositeCurve) { CompositeCurve cc1 = (CompositeCurve)ent1; CompositeCurve cc2 = (CompositeCurve)ent2; if (cc1.CurveList.Count == cc2.CurveList.Count) { int equalCurvesInListCount = 0; foreach (Entity entC in cc1.CurveList) { foreach (Entity entC2 in cc2.CurveList) { if (entC.GetType() == entC2.GetType()) { if (CompareIfEqual(entC, entC2)) { equalCurvesInListCount++; break; } } } } if (cc1.CurveList.Count == equalCurvesInListCount) { return(true); } } } else if (ent1 is LinearPath) { LinearPath lp1 = (LinearPath)ent1; LinearPath lp2 = (LinearPath)ent2; if (lp1.Vertices.Length == lp2.Vertices.Length) { for (int i = 0; i < lp1.Vertices.Length; i++) { if (!(lp1.Vertices[i] == lp2.Vertices[i])) { return(false); } } return(true); } } else if (ent1 is PlanarEntity) { PlanarEntity pe1 = (PlanarEntity)ent1; PlanarEntity pe2 = (PlanarEntity)ent2; if ( pe1.Plane.AxisZ == pe2.Plane.AxisZ && pe1.Plane.AxisX == pe2.Plane.AxisX ) { if (ent1 is Arc) { Arc arc1 = (Arc)ent1; Arc arc2 = (Arc)ent2; if ( arc1.Center == arc2.Center && arc1.Radius == arc2.Radius && arc1.Domain.Min == arc2.Domain.Min && arc1.Domain.Max == arc2.Domain.Max ) { return(true); } } else if (ent1 is Circle) { Circle c1 = (Circle)ent1; Circle c2 = (Circle)ent2; if ( c1.Center == c2.Center && c1.Radius == c2.Radius ) { return(true); } } else if (ent1 is EllipticalArc) { EllipticalArc e1 = (EllipticalArc)ent1; EllipticalArc e2 = (EllipticalArc)ent2; if ( e1.Center == e2.Center && e1.RadiusX == e2.RadiusX && e1.RadiusY == e2.RadiusY && e1.Domain.Low == e2.Domain.Low && e1.Domain.High == e2.Domain.High ) { return(true); } } else if (ent1 is Ellipse) { Ellipse e1 = (Ellipse)ent1; Ellipse e2 = (Ellipse)ent2; if ( e1.Center == e2.Center && e1.RadiusX == e2.RadiusX && e1.RadiusY == e2.RadiusY ) { return(true); } } else if (ent1 is Text) { if (ent1 is Dimension) { Dimension dim1 = (Dimension)ent1; Dimension dim2 = (Dimension)ent2; if ( dim1.InsertionPoint == dim2.InsertionPoint && dim1.DimLinePosition == dim2.DimLinePosition ) { if (ent1 is AngularDim) { AngularDim ad1 = (AngularDim)ent1; AngularDim ad2 = (AngularDim)ent2; if ( ad1.ExtLine1 == ad2.ExtLine1 && ad1.ExtLine2 == ad2.ExtLine2 && ad1.StartAngle == ad2.StartAngle && ad1.EndAngle == ad2.EndAngle && ad1.Radius == ad2.Radius ) { return(true); } } else if (ent1 is LinearDim) { LinearDim ld1 = (LinearDim)ent1; LinearDim ld2 = (LinearDim)ent2; if ( ld1.ExtLine1 == ld2.ExtLine1 && ld1.ExtLine2 == ld2.ExtLine2 ) { return(true); } } else if (ent1 is DiametricDim) { DiametricDim dd1 = (DiametricDim)ent1; DiametricDim dd2 = (DiametricDim)ent2; if ( dd1.Distance == dd2.Distance && dd1.Radius == dd2.Radius && dd1.CenterMarkSize == dd2.CenterMarkSize ) { return(true); } } else if (ent1 is RadialDim) { RadialDim rd1 = (RadialDim)ent1; RadialDim rd2 = (RadialDim)ent2; if ( rd1.Radius == rd2.Radius && rd1.CenterMarkSize == rd2.CenterMarkSize ) { return(true); } } else if (ent1 is OrdinateDim) { OrdinateDim od1 = (OrdinateDim)ent1; OrdinateDim od2 = (OrdinateDim)ent2; if ( od1.DefiningPoint == od2.DefiningPoint && od1.Origin == od2.Origin && od1.LeaderEndPoint == od2.LeaderEndPoint ) { return(true); } } else { Console.Write("Type " + ent1.GetType() + " not implemented."); return(true); } } } else if (ent1 is devDept.Eyeshot.Entities.Attribute) { devDept.Eyeshot.Entities.Attribute att1 = (devDept.Eyeshot.Entities.Attribute)ent1; devDept.Eyeshot.Entities.Attribute att2 = (devDept.Eyeshot.Entities.Attribute)ent2; if ( att1.Value == att2.Value && att1.InsertionPoint == att2.InsertionPoint ) { return(true); } } else { Text tx1 = (Text)ent1; Text tx2 = (Text)ent2; if ( tx1.InsertionPoint == tx2.InsertionPoint && tx1.TextString == tx2.TextString && tx1.StyleName == tx2.StyleName && tx1.WidthFactor == tx2.WidthFactor && tx1.Height == tx2.Height ) { return(true); } } } else { Console.Write("Type " + ent1.GetType() + " not implemented."); return(true); } } } else if (ent1 is Line) { Line line1 = (Line)ent1; Line line2 = (Line)ent2; if ( line1.StartPoint == line2.StartPoint && line1.EndPoint == line2.EndPoint ) { return(true); } } else if (ent1 is devDept.Eyeshot.Entities.Point) { devDept.Eyeshot.Entities.Point point1 = (devDept.Eyeshot.Entities.Point)ent1; devDept.Eyeshot.Entities.Point point2 = (devDept.Eyeshot.Entities.Point)ent2; if ( point1.Position == point2.Position ) { return(true); } } #if NURBS else if (ent1 is Curve) { Curve cu1 = (Curve)ent1; Curve cu2 = (Curve)ent2; if ( cu1.ControlPoints.Length == cu2.ControlPoints.Length && cu1.KnotVector.Length == cu2.KnotVector.Length && cu1.Degree == cu2.Degree ) { for (int k = 0; k < cu1.ControlPoints.Length; k++) { if (cu1.ControlPoints[k] != cu2.ControlPoints[k]) { return(false); } } for (int k = 0; k < cu1.KnotVector.Length; k++) { if (cu1.KnotVector[k] != cu2.KnotVector[k]) { return(false); } } return(true); } } #endif else { Console.Write("Type " + ent1.GetType() + " not implemented."); return(true); } return(false); }
/// <summary> /// ArcTo Helper for StreamGeometryContext /// </summary> /// <param name="path">Target path</param> /// <param name="p1">Start point</param> /// <param name="p2">End point</param> /// <param name="size">Ellipse radii</param> /// <param name="theta">Ellipse theta (angle measured from the abscissa)</param> /// <param name="isLargeArc">Large Arc Indicator</param> /// <param name="clockwise">Clockwise direction flag</param> public static void BuildArc(IStreamGeometryContextImpl path, Point p1, Point p2, Size size, double theta, bool isLargeArc, bool clockwise) { // var orthogonalizer = new RotateTransform(-theta); var orth = new SimpleMatrix(Math.Cos(theta), Math.Sin(theta), -Math.Sin(theta), Math.Cos(theta)); var rest = new SimpleMatrix(Math.Cos(theta), -Math.Sin(theta), Math.Sin(theta), Math.Cos(theta)); // var restorer = orthogonalizer.Inverse; // if(restorer == null) throw new InvalidOperationException("Can't get a restorer!"); Point p1S = orth * (new Point((p1.X - p2.X) / 2, (p1.Y - p2.Y) / 2)); double rx = size.Width; double ry = size.Height; double rx2 = rx * rx; double ry2 = ry * ry; double y1S2 = p1S.Y * p1S.Y; double x1S2 = p1S.X * p1S.X; double numerator = rx2*ry2 - rx2*y1S2 - ry2*x1S2; double denominator = rx2*y1S2 + ry2*x1S2; if (Math.Abs(denominator) < 1e-8) { path.LineTo(p2); return; } if ((numerator / denominator) < 0) { double lambda = x1S2/rx2 + y1S2/ry2; double lambdaSqrt = Math.Sqrt(lambda); if (lambda > 1) { rx *= lambdaSqrt; ry *= lambdaSqrt; rx2 = rx*rx; ry2 = ry*ry; numerator = rx2 * ry2 - rx2 * y1S2 - ry2 * x1S2; if (numerator < 0) numerator = 0; denominator = rx2 * y1S2 + ry2 * x1S2; } } double multiplier = Math.Sqrt(numerator / denominator); Point mulVec = new Point(rx * p1S.Y / ry, -ry * p1S.X / rx); int sign = (clockwise != isLargeArc) ? 1 : -1; Point cs = new Point(mulVec.X * multiplier * sign, mulVec.Y * multiplier * sign); Vector translation = new Vector((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); Point c = rest * (cs) + translation; // See "http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter" to understand // how the ellipse center is calculated // from here, W3C recommendations from the above link make less sense than Darth Vader pouring // some sea water in a water filter while standing in the water confused // Therefore, we are on our own with our task of finding out lambda1 and lambda2 // matching our points p1 and p2. // Fortunately it is not so difficult now, when we already know the ellipse centre. // We eliminate the offset, making our ellipse zero-centered, then we eliminate the theta, // making its Y and X axes the same as global axes. Then we can easily get our angles using // good old school formula for angles between vectors. // We should remember that this class expects true angles, and not the t-values for ellipse equation. // To understand how t-values are obtained, one should see Etas calculation in the constructor code. var p1NoOffset = orth * (p1-c); var p2NoOffset = orth * (p2-c); // if the arc is drawn clockwise, we swap start and end points var revisedP1 = clockwise ? p1NoOffset : p2NoOffset; var revisedP2 = clockwise ? p2NoOffset : p1NoOffset; var thetaStart = GetAngle(new Vector(1, 0), revisedP1); var thetaEnd = GetAngle(new Vector(1, 0), revisedP2); // Uncomment this to draw a pie // path.LineTo(c, true, true); // path.LineTo(clockwise ? p1 : p2, true,true); path.LineTo(clockwise ? p1 : p2); var arc = new EllipticalArc(c.X, c.Y, rx, ry, theta, thetaStart, thetaEnd, false); arc.BuildArc(path, arc._maxDegree, arc._defaultFlatness, false); //uncomment this to draw a pie //path.LineTo(c, true, true); }
public abstract void VisitEllipticalArc( EllipticalArc ellipticalArc );
protected override void OnMouseDown(MouseButtonEventArgs e) { var mousePos = RenderContextUtility.ConvertPoint(GetMousePosition(e)); this.selEntityIndex = GetEntityUnderMouseCursor(mousePos); if (waitingForSelection) { if (this.selEntityIndex != -1) { if (selEntity == null || drawingAngularDim) { this.selEntity = this.Entities[selEntityIndex]; if (activeOperationLabel != "") { this.selEntity.Selected = true; } } // drawingAngularDim from lines needs more than one selection if (!drawingAngularDim || this.Entities[selEntityIndex] is Arc) { waitingForSelection = false; } } } if (GetToolBar().Contains(mousePos)) { base.OnMouseDown(e); return; } #region Handle LMB Clicks if (ActionMode == actionType.None && e.ChangedButton == MouseButton.Left) { // we need to skip adding points for entity selection click editingMode = doingOffset || doingMirror || doingExtend || doingTrim || doingFillet || doingChamfer || doingTangents; ScreenToPlane(mousePos, plane, out current); if (objectSnapEnabled && snapPoint != null) { if (!(editingMode && firstClick)) { points.Add(snapPoint); } } else if (IsPolygonClosed())//control needed to close curve and polyline when cursor is near the starting point of polyline or curve { //if the distance from current point and first point stored is less than given threshold points.Add((Point3D)points[0].Clone()); //the point to add to points is the first point stored. current = (Point3D)points[0].Clone(); } else if (gridSnapEnabled) { if (!(editingMode && firstClick)) { SnapToGrid(ref current); points.Add(current); } } else { if (!(editingMode && firstClick)) { points.Add(current); } } firstClick = false; // If drawing points, create and add new point entity on each LMB click if (drawingPoints) { devDept.Eyeshot.Entities.Point point; if (objectSnapEnabled && snapPoint != null) { point = new devDept.Eyeshot.Entities.Point(snap); } else { point = new devDept.Eyeshot.Entities.Point(current); } AddAndRefresh(point, ActiveLayerName); } else if (drawingText) { devDept.Eyeshot.Entities.Text text = new Text(current, "Sample Text", 5); AddAndRefresh(text, ActiveLayerName); } else if (drawingLeader) { if (points.Count == 3) { Leader leader = new Leader(Plane.XY, points); leader.ArrowheadSize = 3; AddAndRefresh(leader, ActiveLayerName); devDept.Eyeshot.Entities.Text text = new Text((Point3D)current.Clone(), "Sample Text", leader.ArrowheadSize); AddAndRefresh(text, ActiveLayerName); drawingLeader = false; } } // If LINE drawing is finished, create and add line entity to model else if (drawingLine && points.Count == 2) { Line line = new Line(points[0], points[1]); AddAndRefresh(line, ActiveLayerName); drawingLine = false; } // If CIRCLE drawing is finished, create and add a circle entity to model else if (drawingCircle && points.Count == 2) { Circle circle = new Circle(drawingPlane, drawingPlane.Origin, radius); AddAndRefresh(circle, ActiveLayerName); drawingCircle = false; } // If ARC drawing is finished, create and add an arc entity to model // Input - Center and two end points else if (drawingArc && points.Count == 3) { Arc arc = new Arc(drawingPlane, drawingPlane.Origin, radius, 0, arcSpanAngle); AddAndRefresh(arc, ActiveLayerName); drawingArc = false; } // If drawing ellipse, create and add ellipse entity to model // Inputs - Ellipse center, End of first axis, End of second axis else if (drawingEllipse && points.Count == 3) { Ellipse ellipse = new Ellipse(drawingPlane, drawingPlane.Origin, radius, radiusY); AddAndRefresh(ellipse, ActiveLayerName); drawingEllipse = false; } // If EllipticalArc drawing is finished, create and add EllipticalArc entity to model // Input - Ellipse center, End of first axis, End of second axis, end point else if (drawingEllipticalArc && points.Count == 4) { EllipticalArc ellipticalArc = new EllipticalArc(drawingPlane, drawingPlane.Origin, radius, radiusY, 0, arcSpanAngle, true); AddAndRefresh(ellipticalArc, ActiveLayerName); drawingEllipticalArc = false; } else if (drawingLinearDim && points.Count == 3) { LinearDim linearDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight); AddAndRefresh(linearDim, ActiveLayerName); drawingLinearDim = false; } else if (drawingAlignedDim && points.Count == 3) { LinearDim alignedDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight); AddAndRefresh(alignedDim, ActiveLayerName); drawingAlignedDim = false; } else if (drawingOrdinateDim && points.Count == 2) { OrdinateDim ordinateDim = new OrdinateDim(Plane.XY, points[0], points[1], drawingOrdinateDimVertical, dimTextHeight); AddAndRefresh(ordinateDim, ActiveLayerName); drawingOrdinateDim = false; } else if ((drawingRadialDim || drawingDiametricDim) && points.Count == 2) { if (selEntity is Circle) { Circle circle = selEntity as Circle; // ensures that radialDim plane has always the correct normal Circle orientedCircle = new Circle(Plane.XY, circle.Center, circle.Radius); if (drawingRadialDim) { RadialDim radialDim = new RadialDim(orientedCircle, points[points.Count - 1], dimTextHeight); AddAndRefresh(radialDim, ActiveLayerName); drawingRadialDim = false; } else { DiametricDim diametricDim = new DiametricDim(orientedCircle, points[points.Count - 1], dimTextHeight); AddAndRefresh(diametricDim, ActiveLayerName); drawingDiametricDim = false; } } } else if (drawingAngularDim) { if (!drawingAngularDimFromLines) { if (selEntity is Arc && points.Count == 2 && !drawingQuadrantPoint) { Arc arc = selEntity as Arc; Plane myPlane = (Plane)arc.Plane.Clone(); Point3D startPoint = arc.StartPoint; Point3D endPoint = arc.EndPoint; // checks if the Arc is clockwise if (Utility.IsOrientedClockwise(arc.Vertices)) { myPlane.Flip(); startPoint = arc.EndPoint; endPoint = arc.StartPoint; } AngularDim angularDim = new AngularDim(myPlane, startPoint, endPoint, points[points.Count - 1], dimTextHeight); angularDim.TextSuffix = "°"; AddAndRefresh(angularDim, ActiveLayerName); drawingAngularDim = false; } } // If it's not time to set quadrantPoint, adds the lines for angular dim if (selEntity is Line && !drawingQuadrantPoint && quadrantPoint == null) { Line selectedLine = (Line)selEntity; if (firstLine == null) { firstLine = selectedLine; } else if (secondLine == null && !ReferenceEquals(firstLine, selectedLine)) { secondLine = selectedLine; drawingQuadrantPoint = true; // resets points to get only the quadrant point and text position point points.Clear(); } drawingAngularDimFromLines = true; } else if (drawingQuadrantPoint) { ScreenToPlane(mousePos, plane, out quadrantPoint); drawingQuadrantPoint = false; } //if all parameters are present, gets angular dim else if (points.Count == 2 && quadrantPoint != null) { AngularDim angularDim = new AngularDim(plane, (Line)firstLine.Clone(), (Line)secondLine.Clone(), quadrantPoint, points[points.Count - 1], dimTextHeight); angularDim.TextSuffix = "°"; AddAndRefresh(angularDim, ActiveLayerName); drawingAngularDim = false; drawingAngularDimFromLines = false; } } else if (doingOffset && points.Count == 1) { CreateOffsetEntity(); ClearAllPreviousCommandData(); } else if (doingMirror && points.Count == 2 && selEntity != null) { CreateMirrorEntity(); ClearAllPreviousCommandData(); } else if (doingExtend && firstSelectedEntity != null && secondSelectedEntity != null) { ExtendEntity(); ClearAllPreviousCommandData(); } else if (doingTrim && firstSelectedEntity != null && secondSelectedEntity != null) { TrimEntity(); ClearAllPreviousCommandData(); } else if (doingFillet && firstSelectedEntity != null && secondSelectedEntity != null) { CreateFilletEntity(); ClearAllPreviousCommandData(); } else if (doingChamfer && firstSelectedEntity != null && secondSelectedEntity != null) { CreateChamferEntity(); ClearAllPreviousCommandData(); } else if (doingTangents && firstSelectedEntity != null && secondSelectedEntity != null) { CreateTangentEntity(); ClearAllPreviousCommandData(); } else if (doingMove && points.Count == 2) { if (points.Count == 2) { foreach (Entity ent in this.selEntities) { Vector3D movement = new Vector3D(points[0], points[1]); ent.Translate(movement); } Entities.Regen(); ClearAllPreviousCommandData(); } } else if (doingRotate) { if (points.Count == 3) { foreach (Entity ent in this.selEntities) { ent.Rotate(arcSpanAngle, Vector3D.AxisZ, points[0]); } Entities.Regen(); ClearAllPreviousCommandData(); } } else if (doingScale) { if (points.Count == 3) { foreach (Entity ent in this.selEntities) { ent.Scale(points[0], scaleFactor); } Entities.Regen(); ClearAllPreviousCommandData(); } } } #endregion #region Handle RMB Clicks else if (e.ChangedButton == MouseButton.Right) { ScreenToPlane(mousePos, plane, out current); if (drawingPoints) { points.Clear(); drawingPoints = false; } else if (drawingText) { drawingText = false; } else if (drawingLeader) { drawingLeader = false; } // If drawing polyline, create and add LinearPath entity to model else if (drawingPolyLine) { LinearPath lp = new LinearPath(points); AddAndRefresh(lp, ActiveLayerName); drawingPolyLine = false; } // If drawing spline, create and add curve entity to model else if (drawingCurve) { #if NURBS Curve curve = Curve.CubicSplineInterpolation(points); AddAndRefresh(curve, ActiveLayerName); #endif drawingCurve = false; } else { ClearAllPreviousCommandData(); } } #endregion base.OnMouseDown(e); }