Ejemplo n.º 1
0
        public C3DLandDb.TinSurface SetSmoothing(C3DLandDb.TinSurface surface)
        {
            try
            {
                var points   = new Point3dCollection();
                var polyline = PGA.SurfaceManager.SurfaceManager.GetOuterBoundary(surface);

                if (polyline != null)
                {
                    using (Transaction tr = CivilApplicationManager.StartTransaction())
                    {
                        foreach (PolylineVertex3d v3d in polyline)
                        {
                            points.Add(v3d.Position);
                        }
                        tr.Commit();
                    }
                    SetSmoothing(surface, points);
                }
                else
                {
                    PGA.MessengerManager.MessengerManager.AddLog(String.Format("Smoothing Region Failed to get Points!"));
                }
            }
            catch (Exception ex)
            {
                PGA.MessengerManager.MessengerManager.AddLog(String.Format("Smoothing Region Failed {0}", ex));
            }


            return(null);
        }
Ejemplo n.º 2
0
        public void AddStandardInnerBoundary(ObjectId polyId, string layername)
        {
            try
            {
                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    //1. Create new surface if no existing surface passed in
                    C3DLandDb.TinSurface surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                    if (surface == null)
                    {
                        surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                    }
                    //2. Store boundary
                    ObjectIdCollection boundaryEntities = new ObjectIdCollection();
                    boundaryEntities = GetObjectIdCollectionFromEntity(polyId);

                    //3. Access the BoundariesDefinition object from the surface object
                    C3DLandDb.SurfaceDefinitionBoundaries surfaceBoundaries = surface.BoundariesDefinition;

                    //4. now add the boundary to the surface
                    var sbo = surfaceBoundaries.AddBoundaries(boundaryEntities, 1.0, SurfaceBoundaryType.Hide, true);
                    sbo.Name = layername + "-" + DateTime.Now.Millisecond;

                    tr.Commit();
                }
            }
            catch (System.Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
        }
Ejemplo n.º 3
0
        public void AddStandardBoundary(ObjectId polyId, string surfacename,
                                        Autodesk.Civil.DatabaseServices.TinSurface surface)
        {
            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                //1. Create new surface if no existing surface passed in
                // if (surface == null)
                //   surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.TinSurface;
                //2. Store boundary
                ObjectIdCollection boundaryEntities = new ObjectIdCollection();
                boundaryEntities = GetObjectIdCollectionFromEntity(polyId);

                //3. Access the BoundariesDefinition object from the surface object
                Autodesk.Civil.DatabaseServices.SurfaceDefinitionBoundaries surfaceBoundaries =
                    surface.BoundariesDefinition;

                //4. now add the boundary to the surface
                surfaceBoundaries.AddBoundaries(boundaryEntities, 1.0, SurfaceBoundaryType.Hide, true);


                tr.Commit();


                //surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as C3DLandDb.TinSurface;

                //// Add the selected polyline's ObjectId to a collection
                //ObjectIdCollection boundaryEntities = new ObjectIdCollection();
                //boundaryEntities.Add(plineId);
            }
        }
Ejemplo n.º 4
0
        public void AddCivil2016Breakline(ObjectId SurfaceId, ObjectId polyId, ObjectId siteId, string name)
        {
            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                ObjectId featureId            = ObjectId.Null;
                C3DLandDb.FeatureLine feature = null;

                //ObjectId featureId = C3DLandDb.FeatureLine.Create(GetFeatureLineName(), polyId, GetSiteId(ObjectId.Null));
                var checkPoly = polyId.GetObject(OpenMode.ForRead, false, true) as Polyline;

                if (checkPoly != null)
                {
                    featureId = C3DLandDb.FeatureLine.Create(GetFeatureLineName(), polyId, siteId);
                }

                feature = (C3DLandDb.FeatureLine)featureId.GetObject(OpenMode.ForRead);
                feature.AssignElevationsFromSurface(SurfaceId, true);
                var p3Dcollection = feature.GetPoints(FeatureLinePointType.AllPoints);

                //Polyline3d poly = new Polyline3d(Poly3dType.SimplePoly, p3Dcollection, true);
                //tr.AddNewlyCreatedDBObject(poly,true);

                C3DLandDb.TinSurface surface = SurfaceId.GetObject(OpenMode.ForWrite) as C3DLandDb.TinSurface;

                //ObjectIdCollection entities = new ObjectIdCollection();
                //entities.Add(poly.ObjectId);
                surface.BreaklinesDefinition.AddStandardBreaklines(p3Dcollection, 1.0, 2.0, 1.0, 0.0);
                tr.Commit();
            }
        }
Ejemplo n.º 5
0
        getTinSurface(string nameSurf)
        {
            TinSurface objSurface = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDoc())
                {
                    ObjectIdCollection surfaceIDs = BaseObjs._civDoc.GetSurfaceIds();

                    foreach (ObjectId surfaceID in surfaceIDs)
                    {
                        Autodesk.Civil.DatabaseServices.TinSurface objTinSurface = (TinSurface)surfaceID.GetObject(OpenMode.ForRead);
                        if (objTinSurface.Name == nameSurf)
                        {
                            objSurface = objTinSurface;
                            break;
                        }
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 143", ex.Message));
            }
            return(objSurface);
        }
Ejemplo n.º 6
0
 public void AddPoints(Point3dCollection points)
 {
     using (Transaction tr = CivilApplicationManager.StartTransaction())
     {
         C3DLandDb.TinSurface surface = m_TheSurfaceId.GetObject(OpenMode.ForWrite) as C3DLandDb.TinSurface;
         surface.AddVertices(points);
         tr.Commit();
     }
 }
Ejemplo n.º 7
0
 public void AddStandardBreakline(ObjectId SurfaceId, ObjectId polyId, string name)
 {
     using (Transaction tr = CivilApplicationManager.StartTransaction())
     {
         C3DLandDb.TinSurface surface  = SurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
         ObjectIdCollection   entities = new ObjectIdCollection();
         entities.Add(polyId);
         surface.BreaklinesDefinition.AddStandardBreaklines(entities, 1.0, 1.0, 1.0, 0.0);
         tr.Commit();
     }
 }
Ejemplo n.º 8
0
        public static C3DLandDb.TinSurface FindSurfaceBySurfaceId(ObjectId surfaceId)
        {
            CivilDocument doc = CivilApplicationManager.ActiveCivilDocument;

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                C3DLandDb.TinSurface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;

                return(surface);
            }
        }
Ejemplo n.º 9
0
            private static void SetElevBySurf(double defaultDepth, CivilDB.TinSurface tinSurf, XYZ xyz)
            {
                double surfElev = 0;

                try
                {
                    surfElev = tinSurf.FindElevationAtXY(xyz.Position2d.X, xyz.Position2d.Y);
                }
                catch { }
                xyz.Z = surfElev - defaultDepth;
            }
Ejemplo n.º 10
0
        // surfaces
        public Mesh SurfaceToSpeckle(CivilDB.TinSurface surface)
        {
            Mesh mesh = null;

            // output vars
            var _vertices = new List <Acad.Point3d>();
            var faces     = new List <int>();

            foreach (var triangle in surface.GetTriangles(false))
            {
                // get vertices
                var faceIndices = new List <int>();
                foreach (var vertex in new List <CivilDB.TinSurfaceVertex>()
                {
                    triangle.Vertex1, triangle.Vertex2, triangle.Vertex3
                })
                {
                    if (!_vertices.Contains(vertex.Location))
                    {
                        faceIndices.Add(_vertices.Count);
                        _vertices.Add(vertex.Location);
                    }
                    else
                    {
                        faceIndices.Add(_vertices.IndexOf(vertex.Location));
                    }
                    vertex.Dispose();
                }

                // get face
                faces.AddRange(new List <int> {
                    0, faceIndices[0], faceIndices[1], faceIndices[2]
                });

                triangle.Dispose();
            }

            var vertices = PointsToFlatList(_vertices);

            mesh       = new Mesh(vertices, faces);
            mesh.units = ModelUnits;
            mesh.bbox  = BoxToSpeckle(surface.GeometricExtents);

            // add tin surface props
            try{
                mesh["name"]        = surface.DisplayName;
                mesh["description"] = surface.Description;
            }
            catch {}

            return(mesh);
        }
Ejemplo n.º 11
0
        getTinSurface(string nameSurf, out bool exists)
        {
            TinSurface objSurface = null;
            ObjectId   idStyle    = ObjectId.Null;

            exists = false;
            try
            {
                using (Transaction tr = BaseObjs.startTransactionDoc())
                {
                    ObjectIdCollection surfaceIDs = BaseObjs._civDoc.GetSurfaceIds();

                    foreach (ObjectId surfaceID in surfaceIDs)
                    {
                        Autodesk.Civil.DatabaseServices.TinSurface objTinSurface = (TinSurface)surfaceID.GetObject(OpenMode.ForRead);
                        if (objTinSurface.Name == nameSurf)
                        {
                            objSurface = objTinSurface;
                            exists     = true;
                            tr.Commit();
                            return(objSurface);
                        }
                    }
                    foreach (ObjectId idSty in BaseObjs._civDoc.Styles.SurfaceStyles)
                    {
                        SurfaceStyle style = (SurfaceStyle)tr.GetObject(idSty, OpenMode.ForRead);
                        if (style.Name == nameSurf)
                        {
                            idStyle = idSty;
                            break;
                        }
                    }
                    if (idStyle == ObjectId.Null)
                    {
                        idStyle = BaseObjs._civDoc.Styles.SurfaceStyles[0];
                    }
                    ObjectId idSurf = TinSurface.Create(nameSurf, idStyle);
                    objSurface = (TinSurface)tr.GetObject(idSurf, OpenMode.ForWrite);
                    Layer.manageLayers(string.Format("{0}_SURFACE", nameSurf));
                    objSurface.Layer = string.Format("{0}_SURFACE", nameSurf);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 143", ex.Message));
            }
            return(objSurface);
        }
Ejemplo n.º 12
0
 public CivilTinSurface(string surfaceName, string surfaceStyleName)
 {
     using (Transaction tr = CivilApplicationManager.StartTransaction())
     {
         m_TheSurfaceId = C3DLandDb.TinSurface.Create(CivilApplicationManager.WorkingDatabase, surfaceName);
         C3DLandDb.TinSurface surface = m_TheSurfaceId.GetObject(OpenMode.ForWrite) as C3DLandDb.TinSurface;
         surface.Layer = surfaceStyleName;
         ObjectId styleId = SurfaceStyleManager.GetStyleId(surfaceStyleName);
         if (styleId == ObjectId.Null)
         {
             throw new CreateSurfaceException("Unable to create Surface object.");
         }
         surface.StyleId = styleId;
         tr.Commit();
     }
 }
Ejemplo n.º 13
0
 public void AddPointCloudObjects()
 {
     using (Transaction tr = CivilApplicationManager.StartTransaction())
     {
         string surfaceName           = "";
         var    m_TheSurfaceId        = C3DLandDb.TinSurface.Create(CivilApplicationManager.WorkingDatabase, surfaceName);
         C3DLandDb.TinSurface surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
         string   surfaceStyleName    = "";
         ObjectId styleId             = SurfaceStyleManager.GetStyleId(surfaceStyleName);
         if (styleId == ObjectId.Null)
         {
             throw new CreateSurfaceException("Unable to create Surface object.");
         }
         surface.StyleId = styleId;
         tr.Commit();
     }
 }
Ejemplo n.º 14
0
        public void AddFeatureLinesToAllSurface(ObjectIdCollection featureIds, ObjectId surfaceId)
        {
            Debug.WriteLine("Starting AddFeatureLinesToAllSurface");
            using (Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    C3DLandDb.TinSurface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                    surface.UpgradeOpen();
                    surface.BreaklinesDefinition.AddStandardBreaklines(featureIds, 1.0, 2.0, 2.0, 0.0);
                    surface.DowngradeOpen();

                    tr.Commit();
                    Debug.WriteLine("Ending AddFeatureLinesToAllSurface");
                }
            }
        }
Ejemplo n.º 15
0
        public void AddStandardInnerBoundary(ObjectId polyId, string surfacename)
        {
            try
            {
                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    try
                    {
                        //1. Create new surface if no existing surface passed in
                        C3DLandDb.TinSurface surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                        if (surface == null)
                        {
                            surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                        }
                        //2. Store boundary
                        ObjectIdCollection boundaryEntities = new ObjectIdCollection();
                        boundaryEntities = GetObjectIdCollectionFromEntity(polyId);

                        //3. Access the BoundariesDefinition object from the surface object
                        C3DLandDb.SurfaceDefinitionBoundaries surfaceBoundaries = surface.BoundariesDefinition;

                        //4. now add the boundary to the surface
                        try
                        {
                            surfaceBoundaries.AddBoundaries(boundaryEntities, 1.0, SurfaceBoundaryType.Hide, true);
                        }
                        catch (Exception ex)
                        {
                            PGA.Civil.Logging.ACADLogging.LogMyExceptions(string.Format
                                                                              ("AddStandardInnerBoundary: {0}:{1}", polyId, ex.Message));
                        }
                    }
                    catch (Exception ex)
                    {
                        PGA.Civil.Logging.ACADLogging.LogMyExceptions(string.Format("AddStandardInnerBoundary: {0}:{1}", surfacename, ex.Message));
                    }

                    tr.Commit();
                }
            }
            catch (System.Exception e)
            {
                PGA.Civil.Logging.ACADLogging.LogMyExceptions("AddStandardInnerBoundary: " + e.Message);
            }
        }
Ejemplo n.º 16
0
        public void RemovePastecommandByCmd()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect Surface:");

            entOpts.SetRejectMessage("...not a Surface, try again.");
            entOpts.AddAllowedClass(typeof(C3DLandDb.TinSurface), true);
            PromptEntityResult entRes = ed.GetEntity(entOpts);

            if (entRes.Status != PromptStatus.OK)
            {
                return;
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                C3DLandDb.TinSurface surf = (C3DLandDb.TinSurface)entRes.ObjectId.GetObject(OpenMode.ForRead);
                C3DLandDb.SurfaceOperationCollection ops = surf.Operations;
                entOpts.Message = "Select pasted surface to remove: ";
                entRes          = ed.GetEntity(entOpts);
                if (entRes.Status != PromptStatus.OK)
                {
                    return;
                }
                for (int i = 0; i < ops.Count; i++)
                {
                    C3DLandDb.SurfaceOperationPasteSurface op = ops[i] as C3DLandDb.SurfaceOperationPasteSurface;
                    if (op == null)
                    {
                        continue;
                    }
                    if (op.SurfaceId == entRes.ObjectId)
                    {
                        ops.Remove(op);
                        break;
                    }
                }
                surf.Rebuild();
                tr.Commit();
            }
        }
Ejemplo n.º 17
0
        public void AddCivil2016ElevationsToFeature(ObjectId surfaceId, ObjectId featureId, ObjectId siteId,
                                                    object o)
        {
            try
            {
                Debug.WriteLine("Starting AddCivil2016ElevationsToFeature");
                using (Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    using (Transaction tr = CivilApplicationManager.StartTransaction())
                    {
                        var feature = (C3DLandDb.FeatureLine)featureId.GetObject(OpenMode.ForRead);
                        feature.UpgradeOpen();
                        feature.AssignElevationsFromSurface(surfaceId, false);
                        feature.DowngradeOpen();

                        //Check and Refine Breakline
                        //FeatureLineManager.RecurseElevFromSurface();

                        var p3Dcollection = feature.GetPoints(FeatureLinePointType.AllPoints);
                        //var poly3d = new Polyline3d(Poly3dType.SimplePoly, p3Dcollection, true);

                        C3DLandDb.TinSurface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                        surface.UpgradeOpen();
                        ///Todo:Handle Breaklines for Water and Bulkhead
                        surface.BuildOptions.ExecludeMinimumElevation          = true;
                        surface.BuildOptions.MinimumElevation                  = 0.1;
                        surface.BuildOptions.CrossingBreaklinesElevationOption =
                            CrossingBreaklinesElevationType.UseNone;
                        surface.BreaklinesDefinition.AddStandardBreaklines(p3Dcollection, 1.0, 2.0, 2.0, 0.0);
                        surface.DowngradeOpen();

                        tr.Commit();
                        Debug.WriteLine("Ending AddCivil2016ElevationsToFeature");
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
            }
            catch (System.AccessViolationException ex)
            {
            }
        }
Ejemplo n.º 18
0
 /// <exclude />
 public bool AddStandardBoundary(ObjectId polyId, string name, ObjectId surfaceId)
 {
     try
     {
         var db  = CivilApplicationManager.WorkingDatabase;
         var doc = CivilDocument.GetCivilDocument(db);
         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
             C3DLandDb.TinSurface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
             //surface.UpgradeOpen();
             FeatureLineIssues.AddStandardBoundary(polyId, name, surface);
             tr.Commit();
         }
         return(true);
     }
     catch (Exception ex)
     {
     }
     return(false);
 }
Ejemplo n.º 19
0
        public void AddStandardBoundary(ObjectId polyId, string surfacename)
        {
            try
            {
                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    //1. Create new surface if no existing surface passed in
                    C3DLandDb.TinSurface surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                    if (surface == null)
                    {
                        surface = m_TheSurfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;
                    }
                    //2. Store boundary
                    ObjectIdCollection boundaryEntities = new ObjectIdCollection();
                    boundaryEntities = GetObjectIdCollectionFromEntity(polyId);

                    //3. Access the BoundariesDefinition object from the surface object
                    C3DLandDb.SurfaceDefinitionBoundaries surfaceBoundaries = surface.BoundariesDefinition;

                    //4. now add the boundary to the surface
                    surfaceBoundaries.AddBoundaries(boundaryEntities, 1.0, SurfaceBoundaryType.Outer, true);


                    tr.Commit();



                    //surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as C3DLandDb.TinSurface;

                    //// Add the selected polyline's ObjectId to a collection
                    //ObjectIdCollection boundaryEntities = new ObjectIdCollection();
                    //boundaryEntities.Add(plineId);
                }
            }
            catch (System.Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Sets the smoothing to 0.5 ft for select surfaces
        /// </summary>
        /// <param name="surface">The surface.</param>
        /// <param name="points">The points.</param>
        /// <returns>TinSurface.</returns>
        public C3DLandDb.TinSurface SetSmoothing(C3DLandDb.TinSurface surface, Point3dCollection points)
        {
            try
            {
                MessengerManager.AddLog("Start Surface Smoothing: " + surface.Name);

                //Smooth Critical Surfaces//

                if (surface.Name.Contains("GREEN") ||
                    surface.Name.Contains("COLLAR") ||
                    surface.Name.Contains("BUNKER") ||
                    surface.Name.Contains("BRIDGE"))
                {
                    using (Transaction ts = CivilApplicationManager.StartTransaction())
                    {
                        C3DLandDb.SurfacePointOutputOptions pointOutputOptions =
                            new C3DLandDb.SurfacePointOutputOptions();
                        pointOutputOptions.GridSpacingX    = 0.5;
                        pointOutputOptions.GridSpacingY    = 0.5;
                        pointOutputOptions.OutputLocations =
                            SurfacePointOutputLocationsType.GridBased;
                        pointOutputOptions.OutputRegions = new Point3dCollection[]
                        { points };

                        C3DLandDb.SurfaceOperationSmooth op =
                            surface.SmoothSurfaceByNNI(pointOutputOptions);

                        ts.Commit();
                    }
                    MessengerManager.AddLog("End Surface Smoothing: " + surface.Name);
                }
                return(surface);
            }
            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
            return(null);
        }
Ejemplo n.º 21
0
        [CommandMethod("expsurfpts")] //Comanda pentru exportarea intr-un fisier PENZD.csv a punctelor unei suprafete
        public void ExpSurfPts()
        {
            CivilDocument      civDoc  = CivilApplication.ActiveDocument;
            Document           acadDoc = Application.DocumentManager.MdiActiveDocument;
            Database           db      = HostApplicationServices.WorkingDatabase;
            Editor             ed      = acadDoc.Editor;
            ObjectIdCollection surfIds = civDoc.GetSurfaceIds();

            //Verificarea existentei a cel putin unei suprafete
            if (surfIds.Count == 0)
            {
                ed.WriteMessage("\nNo Surfaces found!");
                return;
            }

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //Selectarea suprafetei
                Autodesk.Civil.DatabaseServices.Surface suprafata;
                if (surfIds.Count == 1)
                {
                    suprafata = (Autodesk.Civil.DatabaseServices.Surface)trans.GetObject(surfIds[0], OpenMode.ForRead);
                }
                else
                {
                    PromptEntityOptions PrEntOpt = new PromptEntityOptions("\nSelect Surface: ");
                    PrEntOpt.AllowNone = false;
                    PrEntOpt.SetRejectMessage("\nSelected object is not a Civil3D surface!");
                    PrEntOpt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Surface), false);
                    PromptEntityResult PrEntRes = ed.GetEntity(PrEntOpt);
                    if (PrEntRes.Status != PromptStatus.OK)
                    {
                        ed.WriteMessage("\nAborting!");
                        return;
                    }
                    suprafata = (Autodesk.Civil.DatabaseServices.Surface)trans.GetObject(PrEntRes.ObjectId, OpenMode.ForRead);
                }

                //Obtinerea punctelor suprafetei
                List <string> puncte = new List <string>();
                int           nr     = 0;
                if (suprafata is Autodesk.Civil.DatabaseServices.TinSurface)
                {
                    Autodesk.Civil.DatabaseServices.TinSurface suprafTIN = (Autodesk.Civil.DatabaseServices.TinSurface)suprafata;
                    //Autodesk.Civil.DatabaseServices.TinSurfaceVertexCollection vertecsiTIN = suprafTIN.Vertices;
                    foreach (Autodesk.Civil.DatabaseServices.TinSurfaceVertex V in suprafTIN.Vertices)
                    {
                        nr = nr + 1;
                        puncte.Add(nr.ToString() + "," + V.Location.ToString().Replace("(", "").Replace(")", "") + "," + suprafata.Name);
                    }
                }
                else if (suprafata is Autodesk.Civil.DatabaseServices.GridSurface)
                {
                    Autodesk.Civil.DatabaseServices.GridSurface suprafGRID = (Autodesk.Civil.DatabaseServices.GridSurface)suprafata;
                    foreach (Autodesk.Civil.DatabaseServices.GridSurfaceVertex V in suprafGRID.Vertices)
                    {
                        nr = nr + 1;
                        puncte.Add(nr.ToString() + "," + V.Location.ToString().Replace("(", "").Replace(")", "") + "," + suprafata.Name);
                    }
                }
                else
                {
                    ed.WriteMessage("\nSurface type not supported! Aborting.");
                    return;
                }

                ////TEST: se listeaza punctele
                //foreach(string p in puncte) ed.WriteMessage(p);

                //Selectia fisierului .csv si scrierea punctelor
                PromptSaveFileOptions PrFileOpt = new PromptSaveFileOptions("\nSelect file for point export: ");
                PrFileOpt.Filter = ("CSV file (*.csv)|*.csv");
                string caleDocAcad = HostApplicationServices.Current.FindFile(acadDoc.Name, acadDoc.Database, FindFileHint.Default);
                //PrFileOpt.InitialDirectory = caleDocAcad.Remove(caleDocAcad.LastIndexOf("\\");
                PrFileOpt.InitialFileName = caleDocAcad.Replace(caleDocAcad.Substring(caleDocAcad.LastIndexOf('.')), ".csv");
                ed.WriteMessage(PrFileOpt.InitialDirectory);

                PromptFileNameResult PrFileRes = ed.GetFileNameForSave(PrFileOpt);
                if (PrFileRes.Status != PromptStatus.OK)
                {
                    ed.WriteMessage("\nPoint export unsuccessful!");
                    return;
                }
                StreamWriter scriitor = new StreamWriter(PrFileRes.StringResult);
                foreach (string p in puncte)
                {
                    scriitor.WriteLine(p);
                }
                scriitor.Dispose();
            }
        }
Ejemplo n.º 22
0
        public void TestPasteSurface(Autodesk.Civil.DatabaseServices.Surface srcSurface, Autodesk.Civil.DatabaseServices.TinSurface destSurface)
        {
            if (srcSurface == null)
            {
                throw new ArgumentNullException("srcSurface");
            }
            if (destSurface == null)
            {
                throw new ArgumentNullException("destSurface");
            }

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                destSurface.PasteSurface(srcSurface.Id);
                tr.Commit();
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Removes the pasted objects.
        /// </summary>
        /// <param name="entRes">The surface id resource.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void RemoveBoundaryOperations(ObjectId entRes)
        {
            #region SDI Non-Session

            // Document doc = Application.DocumentManager.MdiActiveDocument;
            //Editor ed = doc.Editor;

            #endregion

            CivilDocument doc = CivilDocument.GetCivilDocument(CivilApplicationManager.WorkingDatabase);

            Autodesk.AutoCAD.DatabaseServices.Database db = CivilApplicationManager.WorkingDatabase;

            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    C3DLandDb.TinSurface surf = (C3DLandDb.TinSurface)entRes.GetObject(OpenMode.ForRead);
                    if (surf == null)
                    {
                        throw new ArgumentNullException(nameof(surf));
                    }

                    C3DLandDb.SurfaceOperationCollection  ops  = surf.Operations;
                    C3DLandDb.SurfaceDefinitionBoundaries ops1 = surf.BoundariesDefinition;

                    #region Surface Add Boundary Operation

                    for (int i = 0; i < ops.Count; i++)

                    {
                        C3DLandDb.SurfaceOperationAddBoundary op = ops[i] as C3DLandDb.SurfaceOperationAddBoundary;

                        if (op == null)
                        {
                            continue;
                        }
                        if (op.Count > 0)
                        {
                            ops.Remove(op);
                            break;
                        }
                    }

                    #endregion

                    #region Surface Existing Boundary Definitions

                    for (int i = 0; i < ops1.Count; i++)

                    {
                        if (ops1.Count == 0)
                        {
                            continue;
                        }
                        if (ops1.Count > 0)
                        {
                            ops1.RemoveAt(i);
                            break;
                        }
                    }

                    #endregion

                    surf.Rebuild();
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 24
0
 public Point3dEnumerator(C3DLandDb.TinSurface surface)
 {
     m_VertexEnumerator = surface.Vertices.GetEnumerator();
 }
Ejemplo n.º 25
0
 public TriangleEnumerator(C3DLandDb.TinSurface surface)
 {
     m_TriangleEnumerator = surface.Triangles.GetEnumerator();
 }
Ejemplo n.º 26
0
        public void AddCivil2016ElevationsToFeature(ObjectId surfaceId, ObjectId featureId, ObjectId siteId,
                                                    object o)
        {
            try
            {
                PGA.MessengerManager.MessengerManager.AddLog("Starting AddCivil2016ElevationsToFeature");
                using (Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    using (Transaction tr = CivilApplicationManager.StartTransaction())
                    {
                        var feature = (C3DLandDb.FeatureLine)featureId.GetObject(OpenMode.ForRead);

                        if (feature == null)
                        {
                            return;
                        }

                        feature.UpgradeOpen();
                        feature.AssignElevationsFromSurface(surfaceId, false);
                        feature.DowngradeOpen();

                        //Check and Refine Zeros from Breakline
                        FeatureLineManager.SendMessage(feature);
                        FeatureLineManager.CheckElevFromFeatureLine(feature.ObjectId);

                        var p3Dcollection = feature.GetPoints(FeatureLinePointType.AllPoints);

                        C3DLandDb.TinSurface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.TinSurface;

                        if (surface == null)
                        {
                            return;
                        }

                        surface.UpgradeOpen();
                        ///Todo:Handle Breaklines for Water and Bulkhead
                        ///
                        surface.BuildOptions.NeedConvertBreaklines             = true;
                        surface.BuildOptions.ExecludeMinimumElevation          = true;
                        surface.BuildOptions.MinimumElevation                  = 0.1;
                        surface.BuildOptions.CrossingBreaklinesElevationOption =
                            CrossingBreaklinesElevationType.UseLast; ///Todo: Changed 2/19/17 from None.
                        surface.BreaklinesDefinition.AddStandardBreaklines(p3Dcollection, 1.0, 2.0, 2.0, 0.0);
                        surface.DowngradeOpen();

                        tr.Commit();
                        PGA.MessengerManager.MessengerManager.AddLog("Ending AddCivil2016ElevationsToFeature");
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
            catch (System.AccessViolationException ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
        }
Ejemplo n.º 27
0
            //private bool joinedEdge = false;//test

            public void CalcPipePosition(Transaction tr, ObjectId tinSurfId, double defaultDepth, bool sameDepthEveryPt, BlockTableRecord ms)
            {
                //Нужно учитывать размеры колодцев при расчете положения ребра!
                //Колодцы бывают просто цилиндрические и просто коробчатые
                //Учитывать Rotation, BoundingShape, InnerDiameterOrWidth, InnerLength
                //Уточнить кривую в плане по которой идет труба с учетом размеров колодца

                //TODO: Как учесть, что блок прямоугольного колодца может не соответствовать колодцу по направлениям длины и ширины????

                PointOnCurve2d startSplitPt = null;
                PointOnCurve2d endSplitPt   = null;

                CivilDB.Structure strStart = null;
                CivilDB.Structure strEnd   = null;
                if (!StartNode.StructId.IsNull)
                {
                    strStart = (CivilDB.Structure)tr.GetObject(StartNode.StructId, OpenMode.ForRead);
                    //уточнить положение начала кривой в начале с учетом размеров колодца!
                    startSplitPt = GetSplitPt(strStart, true);
                }
                if (!EndNode.StructId.IsNull)
                {
                    strEnd = (CivilDB.Structure)tr.GetObject(EndNode.StructId, OpenMode.ForRead);
                    //уточнить положение конца кривой в начале с учетом размеров колодца!
                    endSplitPt = GetSplitPt(strEnd, false);
                }

                if (startSplitPt != null && endSplitPt != null && startSplitPt.Parameter >= endSplitPt.Parameter)
                {
                    //колодцы стоят вплотную друг к другу или залезают друг на друга. Места для трубы на остается
                    return;
                }

                //проход по составляющим кривой с отбрасыванием частей, отсекаемых колодцами
                //Curve2d.GetSplitCurves работает неправильно
                //Curve2d.Explode тоже не помогает
                if (startSplitPt == null)
                {
                    AddPtToPipePositionList(new XYZ(PositionCurve.StartPoint));
                }
                Curve2d[] segments  = PositionCurve.GetCurves();
                double    currParam = 0;

                foreach (Curve2d seg in segments)
                {
                    Interval interval = seg.GetInterval();
                    double   len      = seg.GetLength(interval.LowerBound, interval.UpperBound);

                    currParam += len;

                    //Если есть точка разбиения в начале и она еще не достигнута
                    if (startSplitPt != null)
                    {
                        if (startSplitPt.Parameter < currParam)
                        {
                            //точка разбиения находится на этой кривой. Ее нужно добавить в список
                            AddPtToPipePositionList(new XYZ(startSplitPt.Point));
                            startSplitPt = null;
                        }
                        else
                        {
                            //точка отсечения начала еще не достигнута, переход к следующей кривой
                            continue;
                        }
                    }


                    if (endSplitPt != null && endSplitPt.Parameter < currParam)
                    {
                        //точка разбиения находится на этой кривой. Ее нужно добавить в список
                        AddPtToPipePositionList(new XYZ(endSplitPt.Point));
                        endSplitPt = null;
                        break;//обход точек заканчивается
                    }

                    AddPtToPipePositionList(new XYZ(seg.EndPoint));
                }


                //Задание глубин заложения ребер по концам
                //- если не задана глубина заложения на одном из концов, сделать их равными
                //- если не задана глубина на обоих концах задать обоим концам глубину по умолчанию согласно вводу в окне
                CivilDB.TinSurface tinSurf         = (CivilDB.TinSurface)tr.GetObject(tinSurfId, OpenMode.ForRead);
                double             startElevByData = double.NegativeInfinity;
                double             endElevByData   = double.NegativeInfinity;

                if (StartPipeJunctionData != null && StartPipeJunctionData.JunctionLevel != double.NegativeInfinity)
                {
                    startElevByData = StartPipeJunctionData.JunctionLevel;
                    XYZ xyz = PipePositionList.First();
                    xyz.Z = startElevByData;
                }
                if (EndPipeJunctionData != null && EndPipeJunctionData.JunctionLevel != double.NegativeInfinity)
                {
                    endElevByData = EndPipeJunctionData.JunctionLevel;
                    XYZ xyz = PipePositionList.Last();
                    xyz.Z = endElevByData;
                }



                if (startElevByData != double.NegativeInfinity && endElevByData == double.NegativeInfinity)
                {
                    XYZ xyz = PipePositionList.Last();
                    xyz.Z = startElevByData;
                }
                else if (startElevByData == double.NegativeInfinity && endElevByData != double.NegativeInfinity)
                {
                    XYZ xyz = PipePositionList.First();
                    xyz.Z = endElevByData;
                }
                else if (startElevByData == double.NegativeInfinity && endElevByData == double.NegativeInfinity)
                {
                    XYZ xyz1 = PipePositionList.First();
                    SetElevBySurf(defaultDepth, tinSurf, xyz1);

                    XYZ xyz2 = PipePositionList.Last();
                    SetElevBySurf(defaultDepth, tinSurf, xyz2);
                }


                //- но не допускать, чтобы труба опускалась ниже дна колодца
                double sartElevByStr = double.NegativeInfinity;
                double endElevByStr  = double.NegativeInfinity;

                if (strStart != null && strStart.SumpElevation > PipePositionList.First().Z)
                {
                    sartElevByStr = strStart.SumpElevation;
                    PipePositionList.First().Z = sartElevByStr;
                }

                if (strEnd != null && strEnd.SumpElevation > PipePositionList.Last().Z)
                {
                    endElevByStr = strEnd.SumpElevation;
                    PipePositionList.Last().Z = endElevByStr;
                }
                //после корректировки уточнить отметку соседней точки если по ней нет данных
                if (sartElevByStr != double.NegativeInfinity &&
                    endElevByData == double.NegativeInfinity)
                {
                    XYZ xyz = PipePositionList.Last();
                    xyz.Z = sartElevByStr;
                }
                else if (startElevByData == double.NegativeInfinity &&
                         endElevByStr != double.NegativeInfinity)
                {
                    XYZ xyz = PipePositionList.First();
                    xyz.Z = endElevByStr;
                }


                //Убедиться, что если в одном узле без колодца стыкуются несколько ребер,
                //то в месте стыковки обязательно у всех ребер должна быть одинаковая отметка
                double neighborJunctElev = GetNeigborJuncElev(StartNode);
                XYZ    startPos          = PipePositionList.First();

                if (neighborJunctElev != double.NegativeInfinity && startPos.Z != neighborJunctElev)
                {
                    startPos.Z = neighborJunctElev;
                }

                neighborJunctElev = GetNeigborJuncElev(EndNode);
                XYZ endPos = PipePositionList.Last();

                if (neighborJunctElev != double.NegativeInfinity && endPos.Z != neighborJunctElev)
                {
                    endPos.Z = neighborJunctElev;
                }


                //Задание отметок промежуточных точек на ребрах сети (интерполяция либо относительно поверхности)
                if (PipePositionList.Count > 2)
                {
                    if (sameDepthEveryPt)
                    {
                        //одинаковая глубина относительно поверхности земли
                        //метод TinSurface.SampleElevations работает не так как надо! Он не дает подробного учета рельефа!
                        //точки полилинии
                        for (int i = 1; i < PipePositionList.Count - 1; i++)
                        {
                            XYZ xyz = PipePositionList[i];
                            SetElevBySurf(defaultDepth, tinSurf, xyz);
                        }


                        //Помимо углов поворотов нужно добавить промежуточные точки через 1 м для учета рельефа!


                        List <XYZ> positionListExtended = new List <XYZ>();
                        positionListExtended.Add(PipePositionList.First());
                        for (int i = 1; i < PipePositionList.Count; i++)
                        {
                            XYZ      xyz0    = PipePositionList[i - 1];
                            XYZ      xyz1    = PipePositionList[i];
                            double   len     = xyz1.Position2d.GetDistanceTo(xyz0.Position2d);
                            Vector2d vector  = (xyz1.Position2d - xyz0.Position2d).GetNormal();
                            double   currLen = 1;
                            while (currLen < len)
                            {
                                //добавление промежуточных точек
                                Point2d pt = xyz0.Position2d + vector * currLen;
                                XYZ     intermediateXYZ = new XYZ(pt);
                                SetElevBySurf(defaultDepth, tinSurf, intermediateXYZ);
                                positionListExtended.Add(intermediateXYZ);

                                currLen += 1;
                            }
                            positionListExtended.Add(xyz1);
                        }
                        PipePositionList = positionListExtended;
                    }
                    else
                    {
                        //интерполяция между началом и концом
                        double startElev  = startPos.Z;
                        double endElev    = endPos.Z;
                        double elevDiff   = endElev - startElev;
                        double currLength = 0;
                        for (int i = 1; i < PipePositionList.Count - 1; i++)
                        {
                            XYZ xyz = PipePositionList[i];

                            Point2d prevPt = PipePositionList[i - 1].Position2d;
                            currLength += prevPt.GetDistanceTo(xyz.Position2d);


                            xyz.Z = startElev + (elevDiff * currLength / pipeHorizontalLength);
                        }
                    }
                }
            }