コード例 #1
0
        public static PointSet SubdividePolyline(DBObject obj, Transaction trans, double d)
        {
            Polyline polyline = obj as Polyline;

            if (polyline != null)
            {
                return(PointGeneration.SubdivideLWPolyline(polyline, d));
            }
            Polyline2d polyline2d = obj as Polyline2d;

            if (polyline2d != null)
            {
                return(PointGeneration.SubdividePolyline2d(polyline2d, trans, d));
            }
            Polyline3d polyline3d = obj as Polyline3d;

            if (!(polyline3d != null))
            {
                throw new ArgumentException("Invalid polyline object: " + obj.Handle.ToString() + "\nObject type: " + obj.GetType().ToString());
            }
            return(PointGeneration.SubdividePolyline3d(polyline3d, trans, d));
        }
コード例 #2
0
ファイル: IO2.cs プロジェクト: 1833183060/autocad-dev
        private void method_1(ObjectId[] objectId_0)
        {
            Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            EntityList    entityList      = new EntityList();
            int           num             = 0;
            int           num2            = 0;
            int           num3            = 0;
            int           num4            = 0;
            MessageFilter messageFilter   = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            ProgressMeter progressMeter = new ProgressMeter();

            progressMeter.SetLimit(objectId_0.Length);
            progressMeter.Start("Serializing XML entities");
            try
            {
                CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(CoordinateSystem.Global(), Conversions.GetUCS());
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    LayerTable arg_83_0 = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                    for (int i = 0; i < objectId_0.Length; i++)
                    {
                        messageFilter.CheckMessageFilter((long)i, 10000);
                        progressMeter.MeterProgress();
                        Entity entity = (Entity)transaction.GetObject(objectId_0[i], (OpenMode)0);
                        string name   = ((LayerTableRecord)transaction.GetObject(entity.LayerId, (OpenMode)0)).Name;
                        Autodesk.AutoCAD.DatabaseServices.Face face = entity as Autodesk.AutoCAD.DatabaseServices.Face;
                        if (face != null)
                        {
                            Point3d vertexAt  = face.GetVertexAt(0);
                            Point3d vertexAt2 = face.GetVertexAt(1);
                            Point3d vertexAt3 = face.GetVertexAt(2);
                            Point3d vertexAt4 = face.GetVertexAt(3);
                            global::TerrainComputeC.XML.Vertex v     = new global::TerrainComputeC.XML.Vertex(vertexAt.X, vertexAt.Y, vertexAt.Z);
                            global::TerrainComputeC.XML.Vertex v2    = new global::TerrainComputeC.XML.Vertex(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                            global::TerrainComputeC.XML.Vertex v3    = new global::TerrainComputeC.XML.Vertex(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                            global::TerrainComputeC.XML.Vertex v4    = new global::TerrainComputeC.XML.Vertex(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                            global::TerrainComputeC.XML.Face   face2 = new global::TerrainComputeC.XML.Face(v, v2, v3, v4);
                            face2.SetProperties(name, face.Color.ColorIndex);
                            entityList.Faces.Add(face2);
                            coordinateTransformator.Transform(face2);
                            num4++;
                        }
                        else
                        {
                            DBPoint dBPoint = entity as DBPoint;
                            if (dBPoint != null)
                            {
                                global::TerrainComputeC.XML.Point point = new global::TerrainComputeC.XML.Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z);
                                point.SetProperties(name, dBPoint.Color.ColorIndex);
                                entityList.Points.Add(point);
                                coordinateTransformator.Transform(point);
                                num++;
                            }
                            else
                            {
                                Autodesk.AutoCAD.DatabaseServices.Line line = entity as Autodesk.AutoCAD.DatabaseServices.Line;
                                if (line != null)
                                {
                                    Point3d startPoint = line.StartPoint;
                                    Point3d endPoint   = line.EndPoint;
                                    global::TerrainComputeC.XML.Vertex startVertex = new global::TerrainComputeC.XML.Vertex(startPoint.X, startPoint.Y, startPoint.Z);
                                    global::TerrainComputeC.XML.Vertex endVertex   = new global::TerrainComputeC.XML.Vertex(endPoint.X, endPoint.Y, endPoint.Z);
                                    global::TerrainComputeC.XML.Line   line2       = new global::TerrainComputeC.XML.Line(startVertex, endVertex);
                                    line2.SetProperties(name, line.Color.ColorIndex);
                                    entityList.Lines.Add(line2);
                                    coordinateTransformator.Transform(line2);
                                    num2++;
                                }
                                else
                                {
                                    Polyline   polyline   = entity as Polyline;
                                    Polyline2d polyline2d = entity as Polyline2d;
                                    Polyline3d polyline3d = entity as Polyline3d;
                                    if (polyline != null || polyline2d != null || polyline3d != null)
                                    {
                                        short colorIndex = 256;
                                        if (polyline != null)
                                        {
                                            colorIndex = polyline.Color.ColorIndex;
                                        }
                                        if (polyline2d != null)
                                        {
                                            colorIndex = polyline2d.Color.ColorIndex;
                                        }
                                        if (polyline3d != null)
                                        {
                                            colorIndex = polyline3d.Color.ColorIndex;
                                        }
                                        PointSet pointSet = PointGeneration.SubdividePolyline(entity, transaction, 0.0);
                                        List <global::TerrainComputeC.XML.Vertex> list = new List <global::TerrainComputeC.XML.Vertex>();
                                        for (int j = 0; j < pointSet.Count; j++)
                                        {
                                            list.Add(new global::TerrainComputeC.XML.Vertex(pointSet[j].X, pointSet[j].Y, pointSet[j].Z));
                                        }
                                        PolyLine polyLine = new PolyLine(list);
                                        polyLine.SetProperties(name, colorIndex);
                                        entityList.Polylines.Add(polyLine);
                                        coordinateTransformator.Transform(polyLine);
                                        num3++;
                                    }
                                }
                            }
                        }
                    }
                }
                progressMeter.Stop();
                editor.WriteMessage("\nXML entity list created:");
                editor.WriteMessage("\nNumber of points        : " + entityList.Points.Count);
                editor.WriteMessage("\nNumber of lines         : " + entityList.Lines.Count);
                editor.WriteMessage("\nNumber of polylines     : " + entityList.Polylines.Count);
                editor.WriteMessage("\nNumber of faces         : " + entityList.Faces.Count);
                editor.WriteMessage("\nTotal number of entities: " + entityList.Count);
                editor.WriteMessage("\nWriting xml file " + IO2.string_0 + "...");
                Serializer.Serialize(IO2.string_0, entityList);
                editor.WriteMessage("OK\n");
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
        }
コード例 #3
0
ファイル: PLine.cs プロジェクト: 1833183060/autocad-dev
        private void method_1(ObjectId[] objectId_0, double double_1, ref int int_1, ref int int_2, ref int int_3)
        {
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            Editor        arg_15_0        = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ProgressMeter progressMeter   = new ProgressMeter();
            MessageFilter messageFilter   = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            progressMeter.SetLimit(objectId_0.Length);
            progressMeter.Start("Simplifying polylines");
            try
            {
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1);
                    BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                    for (int i = 0; i < objectId_0.Length; i++)
                    {
                        try
                        {
                            progressMeter.MeterProgress();
                            messageFilter.CheckMessageFilter((long)i, 10);
                            DBObject @object  = transaction.GetObject(objectId_0[i], (OpenMode)1);
                            bool     flag     = false;
                            Polyline polyline = @object as Polyline;
                            if (polyline != null)
                            {
                                flag = polyline.Closed;
                            }
                            Polyline2d polyline2d = @object as Polyline2d;
                            if (polyline2d != null)
                            {
                                flag = polyline2d.Closed;
                            }
                            Polyline3d polyline3d = @object as Polyline3d;
                            if (polyline3d != null)
                            {
                                flag = polyline3d.Closed;
                            }
                            List <ngeometry.VectorGeometry.Point> p = PointGeneration.SubdividePolyline(@object, transaction, 0.0).ToList();
                            int_1 += Conversions.GetNumberOfPoyllineVertices(@object);
                            List <ngeometry.VectorGeometry.Point> list = this.method_2(p, double_1);
                            int_2 += list.Count;
                            Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(list);
                            Polyline3d        polyline3d2       = new Polyline3d(0, point3dCollection, flag);
                            polyline3d2.SetPropertiesFrom((Entity)@object);
                            if (PLine.string_2 == "N" & [email protected])
                            {
                                @object.Erase();
                            }
                            blockTableRecord.AppendEntity(polyline3d2);
                            transaction.AddNewlyCreatedDBObject(polyline3d2, true);
                        }
                        catch (System.Exception ex)
                        {
                            int_3++;
                        }
                    }
                    transaction.Commit();
                }
                progressMeter.Stop();
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw ex;
            }
        }
コード例 #4
0
        private PointSet method_1(ObjectId[] objectId_0, double double_1)
        {
            if (objectId_0 == null)
            {
                return(null);
            }
            Editor        arg_14_0        = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            PointSet      pointSet        = new PointSet();
            PointSet      pointSet2       = new PointSet();
            ProgressMeter progressMeter   = new ProgressMeter();

            progressMeter.SetLimit(objectId_0.Length);
            progressMeter.Start("Computing points on entities");
            try
            {
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    for (int i = 0; i < objectId_0.Length; i++)
                    {
                        progressMeter.MeterProgress();
                        if (i % 10000 == 0)
                        {
                            System.Windows.Forms.Application.DoEvents();
                        }
                        Entity entity = (Entity)objectId_0[i].GetObject((OpenMode)0);
                        string text   = entity.ToString();
                        if (text.ToUpper().Contains("POLYLINE"))
                        {
                            text = "PLINE";
                        }
                        string key;
                        switch (key = text)
                        {
                        case "Autodesk.AutoCAD.DatabaseServices.Line":
                        {
                            Autodesk.AutoCAD.DatabaseServices.Line dbl = (Autodesk.AutoCAD.DatabaseServices.Line)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = PointGeneration.SubdivideLine(dbl, double_1);
                            break;
                        }

                        case "Autodesk.AutoCAD.DatabaseServices.DBText":
                        {
                            DBText dbtext_ = (DBText)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = this.method_2(dbtext_);
                            break;
                        }

                        case "Autodesk.AutoCAD.DatabaseServices.Circle":
                        {
                            Autodesk.AutoCAD.DatabaseServices.Circle circle_ = (Autodesk.AutoCAD.DatabaseServices.Circle)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = this.method_3(circle_, double_1);
                            break;
                        }

                        case "Autodesk.AutoCAD.DatabaseServices.Ellipse":
                        {
                            Autodesk.AutoCAD.DatabaseServices.Ellipse ellipse_ = (Autodesk.AutoCAD.DatabaseServices.Ellipse)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = this.method_4(ellipse_, double_1);
                            break;
                        }

                        case "Autodesk.AutoCAD.DatabaseServices.Arc":
                        {
                            Autodesk.AutoCAD.DatabaseServices.Arc arc_ = (Autodesk.AutoCAD.DatabaseServices.Arc)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = this.method_5(arc_, double_1);
                            break;
                        }

                        case "Autodesk.AutoCAD.DatabaseServices.Spline":
                        {
                            Spline spline_ = (Spline)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = this.method_6(spline_, double_1);
                            break;
                        }

                        case "Autodesk.AutoCAD.DatabaseServices.Face":
                        {
                            Face face_ = (Face)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            pointSet2 = this.method_7(face_);
                            break;
                        }

                        case "PLINE":
                        {
                            DBObject @object = transaction.GetObject(objectId_0[i], (OpenMode)0);
                            pointSet2 = PointGeneration.SubdividePolyline(@object, transaction, double_1);
                            break;
                        }
                        }
                        if (pointSet2 != null)
                        {
                            pointSet.Add(pointSet2);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
            progressMeter.Stop();
            if (pointSet.Count == 0)
            {
                return(null);
            }
            pointSet.RemoveMultiplePoints3d();
            return(pointSet);
        }