コード例 #1
0
        public void AddPointToSurfaceWithoutDeform()
        {
            Document adoc = Application.DocumentManager.MdiActiveDocument;

            if (adoc == null)
            {
                return;
            }

            Database db = adoc.Database;

            Editor ed = adoc.Editor;

            CivilDocument cdok = CivilDocument.GetCivilDocument(adoc.Database);

            try
            {
                PromptEntityOptions peo1 = new PromptEntityOptions("\nУкажите поверхность для вставки дополнительной точки");
                peo1.SetRejectMessage("\nМожно выбрать только поверхность TIN");
                peo1.AddAllowedClass(typeof(TinSurface), true);
                PromptEntityResult per1 = ed.GetEntity(peo1);
                if (per1.Status == PromptStatus.OK)
                {
                    //Указание точки внутри треугольника для встваки точки
                    while (true)
                    {
                        PromptPointOptions ppo = new PromptPointOptions("Укажите точку внутри одного из треугольников поверхности");
                        PromptPointResult  ppr = ed.GetPoint(ppo);
                        if (ppr.Status == PromptStatus.OK)
                        {
                            Point3d pt = ppr.Value;

                            using (Transaction tr = db.TransactionManager.StartTransaction())
                            {
                                TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface;

                                TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y);
                                if (triangle != null)
                                {
                                    tinSurf.AddLine(triangle.Vertex1, triangle.Vertex2);
                                }

                                tr.Commit();
                            }
                            using (Transaction tr = db.TransactionManager.StartTransaction())
                            {
                                TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface;

                                TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y);
                                if (triangle != null)
                                {
                                    tinSurf.AddLine(triangle.Vertex2, triangle.Vertex3);
                                }

                                tr.Commit();
                            }
                            using (Transaction tr = db.TransactionManager.StartTransaction())
                            {
                                TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface;

                                TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y);
                                if (triangle != null)
                                {
                                    tinSurf.AddLine(triangle.Vertex3, triangle.Vertex1);
                                }

                                tr.Commit();
                            }
                            using (Transaction tr = db.TransactionManager.StartTransaction())
                            {
                                TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface;

                                TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y);
                                if (triangle != null)
                                {
                                    tinSurf.AddVertex(new Point2d(pt.X, pt.Y));
                                }
                                tr.Commit();
                            }
                            ed.Regen();
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            catch (Autodesk.Civil.SurfaceException)
            {
                WF.MessageBox.Show("Невозможно редактировать поверхность. Если это быстрая ссылка, то ее нужно освободить");
            }
            catch (System.Exception ex)
            {
                CommonException(ex, "Ошибка при вставке точки в поверхность");
            }
        }
コード例 #2
0
        public static void testCreatePlateau()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //select a surface
            PromptEntityOptions selSurface = new PromptEntityOptions("\nSelect a tin surface: ");

            selSurface.SetRejectMessage("\nOnly tin surface allowed");
            selSurface.AddAllowedClass(typeof(TinSurface), true);
            PromptEntityResult resSurface = ed.GetEntity(selSurface);

            if (resSurface.Status != PromptStatus.OK)
            {
                return;
            }
            ObjectId surfaceId = resSurface.ObjectId;

            //select a polyline
            PromptEntityOptions selPline = new PromptEntityOptions("\nSelect a polyline: ");

            selPline.SetRejectMessage("\nOnly polylines allowed");
            selPline.AddAllowedClass(typeof(Polyline), true);
            PromptEntityResult resPline = ed.GetEntity(selPline);

            if (resPline.Status != PromptStatus.OK)
            {
                return;
            }
            ObjectId plineId = resPline.ObjectId;

            //erase the pline?
            PromptKeywordOptions selYesNo = new PromptKeywordOptions("\nErase polyline?");

            selYesNo.Keywords.Add("Yes");
            selYesNo.Keywords.Add("No");
            PromptResult resYesNo = ed.GetKeywords(selYesNo);

            if (resYesNo.Status != PromptStatus.OK)
            {
                return;
            }
            bool erasePline = resYesNo.StringResult.Equals("Yes");

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;
                Polyline   pline   = trans.GetObject(plineId, OpenMode.ForWrite) as Polyline;
                var        test    = surface.ExtractGridded(SurfaceExtractionSettingsType.Model);
                //find all vertices inside a pline area
                ObjectIdCollection plinesBorder = new ObjectIdCollection();
                plinesBorder.Add(plineId);
                TinSurfaceVertex[] verticesInsidePline = surface.GetVerticesInsidePolylines(plinesBorder);

                //set the new elevation for all vertices founded
                surface.SetVerticesElevation(verticesInsidePline, pline.Elevation);

                //now create a surface vertex at each pline vertex
                for (int plineVertexIndex = 0; plineVertexIndex < pline.NumberOfVertices; plineVertexIndex++)
                {
                    //get the pline coordinate
                    Point3d plineVertex0 = pline.GetPoint3dAt(plineVertexIndex);
                    Point3d plineVertex1 = pline.GetPoint3dAt(plineVertexIndex < (pline.NumberOfVertices - 1) ? plineVertexIndex + 1 : 0);

                    //create a surface vertex at each pline vertex
                    //this will ensure that we have a vertex at each corner,
                    //which is required for the next step (AddLine)
                    SurfaceOperationAddTinVertex res0 = surface.AddVertex(plineVertex0);
                    SurfaceOperationAddTinVertex res1 = surface.AddVertex(plineVertex1);

                    //finally create a line connecting the newly creted vertices
                    TinSurfaceVertex vertex0 = surface.FindVertexAtXY(res0.Location.X, res0.Location.Y);
                    TinSurfaceVertex vertex1 = surface.FindVertexAtXY(res1.Location.X, res1.Location.Y);
                    surface.AddLine(vertex0, vertex1);
                }

                trans.Commit();
            }
        }