Exemplo n.º 1
0
        public static DBObject Create(this Grevit.Types.Line l, Transaction tr)
        {
            LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);

            try
            {
                Line line = new Line(l.from.ToPoint3d(), l.to.ToPoint3d());


                line.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(l.TypeOrLayer))
                {
                    line.LayerId = lt[l.TypeOrLayer];
                }
                ms.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                return(line);
            }

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

            return(null);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static DBObject Create(this Grevit.Types.Wall w, Transaction tr, Grevit.Types.Point from = null, Grevit.Types.Point to = null)
        {
            DictionaryWallStyle ws = new DictionaryWallStyle(Command.Database);

            try
            {
                if (from == null && to == null && w.curve.GetType() == typeof(Grevit.Types.PLine))
                {
                    Grevit.Types.PLine pline = (Grevit.Types.PLine)w.curve;
                    for (int i = 0; i < pline.points.Count; i++)
                    {
                        if (i == pline.points.Count - 1)
                        {
                            if (pline.closed)
                            {
                                w.Create(tr, pline.points[i], pline.points[0]);
                            }
                        }
                        else
                        {
                            w.Create(tr, pline.points[i], pline.points[i + 1]);
                        }
                    }
                }
                else
                {
                    Wall       wall = new Wall();
                    LayerTable lt   = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);

                    bool newEnt = false;

                    if (Command.existing_objects.ContainsKey(w.GID))
                    {
                        wall = (Wall)tr.GetObject(Command.existing_objects[w.GID], OpenMode.ForWrite);
                    }
                    else
                    {
                        wall.SetDatabaseDefaults(Command.Database);
                        wall.SetToStandard(Command.Database);
                        newEnt = true;
                        wall.JustificationType = WallJustificationType.Center;
                    }

                    if (w.TypeOrLayer != "")
                    {
                        if (lt.Has(w.TypeOrLayer))
                        {
                            wall.LayerId = lt[w.TypeOrLayer];
                        }
                    }
                    if (ws.Has(w.FamilyOrStyle, tr))
                    {
                        wall.StyleId = ws.GetAt(w.FamilyOrStyle);
                    }



                    if (from != null && to != null)
                    {
                        wall.Set(from.ToPoint3d(), to.ToPoint3d(), Vector3d.ZAxis);
                    }
                    else
                    {
                        if (w.curve.GetType() == typeof(Grevit.Types.Line))
                        {
                            Grevit.Types.Line baseline = (Grevit.Types.Line)w.curve;
                            wall.Set(baseline.from.ToPoint3d(), baseline.to.ToPoint3d(), Vector3d.ZAxis);
                        }
                        else if (w.curve.GetType() == typeof(Grevit.Types.Arc))
                        {
                            Grevit.Types.Arc baseline = (Grevit.Types.Arc)w.curve;
                            CircularArc3d    arc      = new CircularArc3d(baseline.center.ToPoint3d(), Vector3d.ZAxis, Vector3d.ZAxis, baseline.radius, baseline.start, baseline.end);
                            wall.Set(arc, Vector3d.ZAxis);
                        }
                        else if (w.curve.GetType() == typeof(Grevit.Types.Curve3Points))
                        {
                            Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)w.curve;
                            wall.Set(baseline.a.ToPoint3d(), baseline.b.ToPoint3d(), baseline.c.ToPoint3d(), Vector3d.ZAxis);
                        }
                    }


                    wall.BaseHeight = w.height;

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

                        ms.AppendEntity(wall);
                        tr.AddNewlyCreatedDBObject(wall, true);
                    }

                    return(wall);
                }
            }

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

            return(null);
        }
Exemplo n.º 5
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);
        }