public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Center point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("Semi major axis: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } float rot = (p2.Value - p1.Value).Angle; EllipticArc consArc = new EllipticArc( p1.Value, (p2.Value - p1.Value).Length, (p2.Value - p1.Value).Length / 10, 0, 2 * MathF.PI, rot); doc.Jigged.Add(consArc); var p3 = await ed.GetPoint("Semi minor axis: ", p1.Value, (p) => consArc.SemiMinorAxis = (p - p1.Value).Length); if (p3.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } var a1 = await ed.GetAngle("Start angle: ", p1.Value); if (a1.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } consArc.StartAngle = a1.Value - rot; var a2 = await ed.GetAngle("End angle: ", p1.Value, (p) => consArc.EndAngle = p - rot); if (a2.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } doc.Jigged.Remove(consArc); Drawable newItem = new EllipticArc( p1.Value, (p2.Value - p1.Value).Length, (p3.Value - p1.Value).Length, a1.Value - rot, a2.Value - rot, (p2.Value - p1.Value).Angle); doc.Model.Add(newItem); }
public AGSEllipticalArcSegment(EllipticArc srcSeg) { base.StartPoint = new AGSPoint(srcSeg.FromPoint as PointN); base.EndPoint = new AGSPoint(srcSeg.ToPoint as PointN); this.Center = new AGSPoint(srcSeg.CenterPoint as PointN); this.IsMinor = srcSeg.IsMinor; this.IsCounterClockwise = srcSeg.IsCounterClockwise; this.MinorMajorRatio = srcSeg.MinorMajorRatio; this.Rotation = srcSeg.Rotation; this.IsStandard = srcSeg.EllipseStd; }
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 AGSPath(Path srcP) { this.Segments = new List <AGSSegment>(); if (srcP.SegmentArray != null) { Segment[] segmentArray = srcP.SegmentArray; for (int i = 0; i < segmentArray.Length; i++) { Segment segment = segmentArray[i]; Line line = segment as Line; CircularArc circularArc = segment as CircularArc; EllipticArc ellipticArc = segment as EllipticArc; BezierCurve bezierCurve = segment as BezierCurve; if (line != null) { this.Segments.Add(new AGSLineSegment(line)); } else if (circularArc != null) { if (circularArc.IsLine) { this.Segments.Add(new AGSLineSegment(circularArc.FromPoint as PointN, circularArc.ToPoint as PointN)); } else { this.Segments.Add(new AGSCircularArcSegment(circularArc)); } } else if (ellipticArc != null) { this.Segments.Add(new AGSEllipticalArcSegment(ellipticArc)); } else if (bezierCurve != null) { this.Segments.Add(new AGSBezierSegment(bezierCurve)); } } return; } if (srcP.PointArray != null) { int num = srcP.PointArray.Length; AGSPoint f = new AGSPoint(srcP.PointArray[0] as PointN); for (int j = 1; j < num; j++) { AGSPoint aGSPoint = new AGSPoint(srcP.PointArray[j] as PointN); this.Segments.Add(new AGSLineSegment(f, aGSPoint)); f = aGSPoint; } } }
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 bool CanBeDrawnAsPolyline(Segment[] segs) { Segment segment = segs[0]; PointN pointN = (PointN)segment.FromPoint; PointN pointN2 = (PointN)segment.ToPoint; if (pointN.Z != pointN2.Z) { return(false); } double z = pointN2.Z; int i = 0; while (i < segs.Length) { Segment segment2 = segs[i]; EllipticArc ellipticArc = segment2 as EllipticArc; BezierCurve bezierCurve = segment2 as BezierCurve; bool result; if (bezierCurve != null) { result = false; } else if (ellipticArc != null) { result = false; } else { pointN = (PointN)segment2.FromPoint; pointN2 = (PointN)segment2.ToPoint; if (pointN.Z != z) { result = false; } else { if (pointN2.Z == z) { i++; continue; } result = false; } } return(result); } return(true); }
/// <summary> /// 转换包络为椭圆线 /// </summary> /// <param name="geometry">ESRI几何形状接口</param> /// <returns>ESRI几何形状接口的椭圆线</returns> public static IGeometry ConvertEnvelopeToEllipticArc(IGeometry geometry) { if ((IsValidGeometry(geometry)) && (geometry is IEnvelope)) { IEnvelope envelope = (IEnvelope)geometry; IPoint point = CreatePointByCoord((envelope.XMin + envelope.XMax) / 2, envelope.YMin); IEllipticArc ellipticArc = new EllipticArc(); (ellipticArc as IConstructEllipticArc).ConstructTwoPointsEnvelope(point, point, envelope, esriArcOrientation.esriArcClockwise); return(ellipticArc); } else { return(null); } }
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; }
public override void OnMouseUp(int button, int shift, int x, int y) { if (this.inewEnvelopeFeedback_0 != null) { IEnvelope boundingEnvelope = this.inewEnvelopeFeedback_0.Stop(); IEllipticArc ellipticArc = new EllipticArc(); (ellipticArc as IConstructEllipticArc).ConstructEnvelope(boundingEnvelope); this.inewEnvelopeFeedback_0 = null; IPolygon polygon = new Polygon() as IPolygon; object value = Missing.Value; (polygon as ISegmentCollection).AddSegment(ellipticArc as ISegment, ref value, ref value); IElement element = new EllipseElement { Geometry = polygon }; INewElementOperation operation = new NewElementOperation { ActiveView = this._context.ActiveView, Element = element, ContainHook = this.GetActiveView() }; this._context.OperationStack.Do(operation); //if (this._context.Hook is IApplication) //{ // if ((this._context.Hook as IApplication).ContainerHook != null) // { // DocumentManager.DocumentChanged((this._context.Hook as IApplication).ContainerHook); // } // else // { // DocumentManager.DocumentChanged((this._context.Hook as IApplication).Hook); // } //} //else //{ // DocumentManager.DocumentChanged(this._context.Hook); //} } }
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 ISegment method_3(ISegment isegment_0, IPoint ipoint_0) { ISegment lineClass; IPoint pointClass; IPoint point; ISegment segment; double num; double y; double num1; double y1; IPoint fromPoint = isegment_0.FromPoint; IPoint toPoint = isegment_0.ToPoint; if (isegment_0.GeometryType == esriGeometryType.esriGeometryLine) { lineClass = new Line() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y); lineClass.FromPoint = pointClass; lineClass.ToPoint = point; segment = lineClass; } else if (isegment_0.GeometryType == esriGeometryType.esriGeometryCircularArc) { lineClass = new CircularArc() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y); IPoint pointClass1 = new ESRI.ArcGIS.Geometry.Point(); (isegment_0 as ICircularArc).QueryCenterPoint(pointClass1); pointClass1.Y = 2 * ipoint_0.Y - pointClass1.Y; (lineClass as IConstructCircularArc).ConstructThreePoints(pointClass, pointClass1, point, false); segment = lineClass; } else if (isegment_0.GeometryType == esriGeometryType.esriGeometryEllipticArc) { lineClass = new EllipticArc() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y); isegment_0.Envelope.QueryCoords(out num, out y, out num1, out y1); y = 2 * ipoint_0.Y - y; y1 = 2 * ipoint_0.Y - y1; IEnvelope envelopeClass = new Envelope() as IEnvelope; envelopeClass.PutCoords(num, y, num1, y1); (lineClass as IConstructEllipticArc).ConstructTwoPointsEnvelope(pointClass, point, envelopeClass, ((isegment_0 as IEllipticArc).IsCounterClockwise ? esriArcOrientation.esriArcCounterClockwise : esriArcOrientation.esriArcClockwise)); segment = lineClass; } else if (isegment_0.GeometryType != esriGeometryType.esriGeometryBezier3Curve) { segment = null; } else { lineClass = new Line() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y); lineClass.FromPoint = pointClass; lineClass.ToPoint = point; segment = lineClass; } return(segment); }
private ISegment method_2(ISegment isegment_0, IPoint ipoint_0) { ISegment lineClass; IPoint pointClass; IPoint point; ISegment segment; IPoint x; double num; double num1; double x1; double num2; IPoint fromPoint = isegment_0.FromPoint; IPoint toPoint = isegment_0.ToPoint; if (isegment_0.GeometryType == esriGeometryType.esriGeometryLine) { lineClass = new Line() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y); lineClass.FromPoint = pointClass; lineClass.ToPoint = point; segment = lineClass; } else if (isegment_0.GeometryType == esriGeometryType.esriGeometryCircularArc) { lineClass = new CircularArc() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y); x = new ESRI.ArcGIS.Geometry.Point(); (isegment_0 as ICircularArc).QueryCenterPoint(x); x.X = 2 * ipoint_0.X - x.X; (lineClass as IConstructCircularArc).ConstructThreePoints(pointClass, x, point, false); segment = lineClass; } else if (isegment_0.GeometryType == esriGeometryType.esriGeometryEllipticArc) { lineClass = new EllipticArc() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y); x = new ESRI.ArcGIS.Geometry.Point(); (isegment_0 as IEllipticArc).QueryCenterPoint(x); x.X = 2 * ipoint_0.X - x.X; isegment_0.Envelope.QueryCoords(out num, out num1, out x1, out num2); num = 2 * ipoint_0.X - num; x1 = 2 * ipoint_0.X - x1; IEnvelope envelopeClass = new Envelope() as IEnvelope; envelopeClass.PutCoords(num, num1, x1, num2); (lineClass as IConstructEllipticArc).ConstructTwoPointsEnvelope(pointClass, point, envelopeClass, ((isegment_0 as IEllipticArc).IsCounterClockwise ? esriArcOrientation.esriArcCounterClockwise : esriArcOrientation.esriArcClockwise)); segment = lineClass; } else if (isegment_0.GeometryType != esriGeometryType.esriGeometryBezier3Curve) { segment = null; } else { lineClass = new Line() as ISegment; pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y); point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y); lineClass.FromPoint = pointClass; lineClass.ToPoint = point; segment = lineClass; } return(segment); }