예제 #1
0
        public static Curve2dCollection To2dCurve(this Grevit.Types.Component curve)
        {
            Curve2dCollection curveArray = new Curve2dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                curveArray.Add(new Line2d(baseline.from.ToPoint2d(), baseline.to.ToPoint2d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc baseline = (Grevit.Types.Arc)curve;
                curveArray.Add(new CircularArc2d(baseline.center.ToPoint2d(), baseline.radius, baseline.start, baseline.end, Vector2d.XAxis, true));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                curveArray.Add(new CircularArc2d(baseline.a.ToPoint2d(), baseline.c.ToPoint2d(), baseline.b.ToPoint2d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count - 1; i++)
                {
                    curveArray.Add(new Line2d(baseline.points[i].ToPoint2d(), baseline.points[i + 1].ToPoint2d()));
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s      = (Grevit.Types.Spline)curve;
                Point2dCollection   points = new Point2dCollection();
                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    points.Add(p.ToPoint2d());
                }
                DoubleCollection dc = new DoubleCollection();
                foreach (double dbl in s.weights)
                {
                    dc.Add(dbl);
                }
                NurbCurve2d sp = new NurbCurve2d(s.degree, new KnotCollection(), points, dc, s.isPeriodic);
                curveArray.Add(sp);
            }

            return(curveArray);
        }
예제 #2
0
        public static Curve3dCollection To3dCurve(this Grevit.Types.Component curve)
        {
            Curve3dCollection curveArray = new Curve3dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                curveArray.Add(new Line3d(baseline.from.ToPoint3d(), baseline.to.ToPoint3d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc baseline = (Grevit.Types.Arc)curve;
                curveArray.Add(new Arc(baseline.center.ToPoint3d(), baseline.radius, baseline.start, baseline.end).GetGeCurve());
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                curveArray.Add(new CircularArc3d(baseline.a.ToPoint3d(), baseline.c.ToPoint3d(), baseline.b.ToPoint3d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count - 1; i++)
                {
                    curveArray.Add(new Line3d(baseline.points[i].ToPoint3d(), baseline.points[i + 1].ToPoint3d()));
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s      = (Grevit.Types.Spline)curve;
                Point3dCollection   points = new Point3dCollection();
                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    points.Add(p.ToPoint3d());
                }
                DoubleCollection dc = new DoubleCollection();
                foreach (double dbl in s.weights)
                {
                    dc.Add(dbl);
                }
                Spline sp = new Spline(s.degree, s.isRational, s.isClosed, s.isPeriodic, points, new DoubleCollection(), dc, 0, 0);
                curveArray.Add(sp.GetGeCurve());
            }

            return(curveArray);
        }
예제 #3
0
        public static DBObject Create(this Grevit.Types.Spline s, Transaction tr)
        {
            LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);

            try
            {
                Point3dCollection points = new Point3dCollection();
                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    points.Add(p.ToPoint3d());
                }
                DoubleCollection dc = new DoubleCollection();
                foreach (double dbl in s.weights)
                {
                    dc.Add(dbl);
                }
                DoubleCollection dcc = new DoubleCollection();
                foreach (double dbl in s.knots)
                {
                    dcc.Add(dbl);
                }
                Spline sp = new Spline(s.degree, s.isRational, s.isClosed, s.isPeriodic, points, dcc, dc, 0, 0);
                sp.SetDatabaseDefaults(Command.Database);

                BlockTable       bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                if (lt.Has(s.TypeOrLayer))
                {
                    sp.LayerId = lt[s.TypeOrLayer];
                }
                ms.AppendEntity(sp);
                tr.AddNewlyCreatedDBObject(sp, true);
                ms.Dispose();
                return(sp);
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
            }

            return(null);
        }
예제 #4
0
        public static Point3dCollection To3dPointCollection(this Grevit.Types.Component curve)
        {
            Point3dCollection points = new Point3dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                Point3d           p1       = baseline.from.ToPoint3d();
                Point3d           p2       = baseline.to.ToPoint3d();

                if (!points.Contains(p1))
                {
                    points.Add(p1);
                }
                if (!points.Contains(p2))
                {
                    points.Add(p2);
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                Point3d p1 = baseline.a.ToPoint3d();
                Point3d p2 = baseline.b.ToPoint3d();
                Point3d p3 = baseline.c.ToPoint3d();

                if (!points.Contains(p1))
                {
                    points.Add(p1);
                }
                if (!points.Contains(p2))
                {
                    points.Add(p2);
                }
                if (!points.Contains(p3))
                {
                    points.Add(p3);
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count; i++)
                {
                    Point3d p1 = baseline.points[i].ToPoint3d();
                    if (!points.Contains(p1))
                    {
                        points.Add(p1);
                    }
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s = (Grevit.Types.Spline)curve;

                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    Point3d p1 = p.ToPoint3d();
                    if (!points.Contains(p1))
                    {
                        points.Add(p1);
                    }
                }
            }

            return(points);
        }