public static Ellipse ToCadEllipse(EllipticArc arc, double defaultElevation) { EllipticArc ellipticArc = (EllipticArc)Utility.CloneObject(arc); PointN pointN = (PointN)ellipticArc.CenterPoint; if (double.IsNaN(pointN.Z)) { pointN.Z = 0.0; } if (!pointN.ZSpecified) { pointN.Z = defaultElevation; ((PointN)ellipticArc.FromPoint).Z = defaultElevation; ((PointN)ellipticArc.ToPoint).Z = defaultElevation; } Point3d point3d = GIS2CAD.ToCadPoint3d((PointN)ellipticArc.FromPoint); Point3d point3d2 = GIS2CAD.ToCadPoint3d((PointN)ellipticArc.ToPoint); if (!ellipticArc.EllipseStd) { AGSEllipticalArc.TransformToEllipseStd(ref ellipticArc); } PointN pointN2 = (PointN)ellipticArc.FromPoint; PointN pointN3 = (PointN)ellipticArc.ToPoint; double arg_B7_0 = pointN2.X; double arg_BF_0 = pointN2.Y; double num = ellipticArc.MinorMajorRatio * ellipticArc.MinorMajorRatio; double x = pointN2.X; double y = pointN2.Y; double x2 = pointN3.X; double y2 = pointN3.Y; double num2 = Math.Sqrt(num * x * x + y * y); double num3 = Math.Sqrt(num * x2 * x2 + y2 * y2); double num4 = 0.5 * (num2 + num3); double num5 = num4 / ellipticArc.MinorMajorRatio; Vector3d vector3d = new Vector3d(num5, 0.0, 0.0); Vector3d vector3d2 = new Vector3d(0.0, num4, 0.0); Vector3d vector3d3 = vector3d.RotateBy(ellipticArc.Rotation, Vector3d.ZAxis); Vector3d vector3d4 = vector3d2.RotateBy(ellipticArc.Rotation, Vector3d.ZAxis); Point3d point3d3 = GIS2CAD.ToCadPoint3d(pointN); EllipticalArc3d ellipticalArc3d = new EllipticalArc3d(point3d3, vector3d3, vector3d4, num5, num4); double num6 = ellipticalArc3d.GetParameterOf(point3d); double num7 = ellipticalArc3d.GetParameterOf(point3d2); if (!ellipticArc.IsCounterClockwise) { double num8 = num6; num6 = num7; num7 = num8; } return(new Ellipse(point3d3, Vector3d.ZAxis, vector3d3, ellipticArc.MinorMajorRatio, num6, num7)); }
public static Point3dCollection SamplePoints(EllipticArc inArc, double defaultElevation) { Ellipse ellipse = AGSEllipticalArc.ToCadEllipse(inArc, defaultElevation); Point3d center = ellipse.Center; Vector3d majorAxis = ellipse.MajorAxis; Vector3d minorAxis = ellipse.MinorAxis; double majorRadius = ellipse.MajorRadius; double minorRadius = ellipse.MinorRadius; double parameterAtAngle = ellipse.GetParameterAtAngle(ellipse.StartAngle); double parameterAtAngle2 = ellipse.GetParameterAtAngle(ellipse.EndAngle); EllipticalArc3d arc = new EllipticalArc3d(center, majorAxis, minorAxis, majorRadius, minorRadius, parameterAtAngle, parameterAtAngle2); return(AGSEllipticalArc.SamplePoints(arc, inArc.IsCounterClockwise)); }
private static void TransformToEllipseStd(ref EllipticArc arc) { PointN pointN = (PointN)arc.CenterPoint; if (double.IsNaN(pointN.Z)) { pointN.Z = 0.0; } PointN fromPoint = (PointN)arc.FromPoint; PointN toPoint = (PointN)arc.ToPoint; AGSEllipticalArc.TransformToEllipseStd(ref fromPoint, pointN, arc.Rotation); AGSEllipticalArc.TransformToEllipseStd(ref toPoint, pointN, arc.Rotation); arc.FromPoint = fromPoint; arc.ToPoint = toPoint; }
private static Entity DrawPart(Segment[] segs, Point[] points, Point[] densifiedPoints, bool closePart, bool hasZ, double defaultElevation) { double num = 0.0; if (segs != null) { if (segs.Length == 1) { CircularArc circularArc = segs[0] as CircularArc; EllipticArc ellipticArc = segs[0] as EllipticArc; BezierCurve bezierCurve = segs[0] as BezierCurve; ArcGIS10Types.Line line = segs[0] as ArcGIS10Types.Line; if (circularArc != null) { if (((PointN)circularArc.FromPoint).X == ((PointN)circularArc.ToPoint).X && ((PointN)circularArc.FromPoint).Y == ((PointN)circularArc.ToPoint).Y) { return(GIS2CAD.DrawCircle(circularArc, defaultElevation)); } return(GIS2CAD.DrawCircularArc(circularArc, defaultElevation, densifiedPoints)); } else if (ellipticArc != null) { if (!ellipticArc.IsCounterClockwise) { return(AGSEllipticalArc.ToCadSpline(ellipticArc, defaultElevation)); } return(AGSEllipticalArc.ToCadEllipse(ellipticArc, defaultElevation)); } else { if (line != null) { return(GIS2CAD.DrawPolyline(densifiedPoints, false)); } if (bezierCurve != null) { return(GIS2CAD.DrawPolyline(densifiedPoints, closePart)); } } } else if (segs.Length > 1) { PointN pointN = segs[0].FromPoint as PointN; num = pointN.Z; if (num == 0.0) { num = defaultElevation; } if (GIS2CAD.CanBeDrawnAsPolyline(segs)) { var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); polyline.ColorIndex = (256); int num2 = 0; PointN pointN2 = (PointN)segs[0].ToPoint; for (int i = 0; i < segs.Length; i++) { Segment segment = segs[i]; CircularArc circularArc2 = segment as CircularArc; var line2 = segment as ArcGIS10Types.Line; if (line2 != null) { PointN pointN3 = (PointN)line2.FromPoint; polyline.AddVertexAt(num2++, new Point2d(pointN3.X, pointN3.Y), 0.0, -1.0, -1.0); pointN2 = (PointN)line2.ToPoint; } else if (circularArc2 != null) { PointN pointN4 = (PointN)circularArc2.CenterPoint; PointN pointN5 = (PointN)circularArc2.FromPoint; PointN pointN6 = (PointN)circularArc2.ToPoint; new Point2d(pointN5.X - pointN4.X, pointN5.Y - pointN4.Y); new Point2d(pointN6.X - pointN4.X, pointN6.Y - pointN4.Y); Point2d point2d = new Point2d(pointN5.X, pointN5.Y); Point2d centerPoint = new Point2d(pointN4.X, pointN4.Y); Point2d point2d2 = new Point2d(pointN6.X, pointN6.Y); double num3 = Math.Abs(centerPoint.GetDistanceTo(point2d)); double num4 = Math.Abs(point2d.GetDistanceTo(point2d2)); double num5 = num3; double num6 = num3; double d = (num5 * num5 + num6 * num6 - num4 * num4) / (2.0 * num5 * num6); double num7 = Math.Acos(d); num7 = GIS2CAD.CalcThetaFromVectors(point2d, point2d2, centerPoint, circularArc2.IsCounterClockwise); double num8 = Math.Tan(num7 / 4.0); if (!circularArc2.IsCounterClockwise) { num8 *= -1.0; } polyline.AddVertexAt(num2++, point2d, num8, -1.0, -1.0); pointN2 = pointN6; } } polyline.AddVertexAt(num2, new Point2d(pointN2.X, pointN2.Y), 0.0, -1.0, -1.0); if (closePart) { polyline.Closed = (true); } return(polyline); } return(GIS2CAD.Draw3dPline(densifiedPoints, closePart)); } } else if (points != null) { if (points.Length == 2) { var line3 = new Autodesk.AutoCAD.DatabaseServices.Line(); line3.ColorIndex = (256); GIS2CAD.AdjustZ(ref points, defaultElevation); Point3d startPoint = GIS2CAD.ToCadPoint3d((PointN)points[0]); Point3d endPoint = GIS2CAD.ToCadPoint3d((PointN)points[1]); line3.StartPoint = (startPoint); line3.EndPoint = (endPoint); return(line3); } if (points.Length > 0) { if (!GIS2CAD.IsPlanar(points)) { try { Document document = AfaDocData.ActiveDocData.Document; var database = document.Database; var transactionManager = document.TransactionManager; using (document.LockDocument()) { using (Transaction transaction = transactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(database.BlockTableId, 0); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[(BlockTableRecord.ModelSpace)], (OpenMode)1); Polyline3d polyline3d = new Polyline3d(); polyline3d.ColorIndex = (256); blockTableRecord.AppendEntity(polyline3d); transaction.AddNewlyCreatedDBObject(polyline3d, true); Point[] array = points; for (int j = 0; j < array.Length; j++) { PointN srcPt = (PointN)array[j]; PolylineVertex3d polylineVertex3d = new PolylineVertex3d(GIS2CAD.ToCadPoint3d(srcPt)); polyline3d.AppendVertex(polylineVertex3d); transaction.AddNewlyCreatedDBObject(polylineVertex3d, true); } if (closePart) { polyline3d.Closed = (true); } document.TransactionManager.QueueForGraphicsFlush(); document.TransactionManager.FlushGraphics(); document.Editor.UpdateScreen(); transaction.Commit(); return(polyline3d); } } } catch (System.Exception ex) { string arg_526_0 = ex.Message; } } var polyline2 = new Autodesk.AutoCAD.DatabaseServices.Polyline(); polyline2.ColorIndex = (256); polyline2.Elevation = (num); num = ((PointN)points[0]).Z; if (num == 0.0) { num = defaultElevation; } int num9 = 0; Point[] array2 = points; for (int k = 0; k < array2.Length; k++) { PointN pointN7 = (PointN)array2[k]; polyline2.AddVertexAt(num9++, new Point2d(pointN7.X, pointN7.Y), 0.0, -1.0, -1.0); } if (closePart) { polyline2.Closed = (true); } return(polyline2); } } return(null); }
private static Spline BuildSpline(EllipticalArc3d arc, bool isCounterClockwise) { Point3dCollection point3dCollection = AGSEllipticalArc.SamplePoints(arc, isCounterClockwise); return(new Spline(point3dCollection, 2, 0.0)); }