public void AddCivil2016Breakline(ObjectId SurfaceId, ObjectId polyId, ObjectId siteId, string name)
        {
            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                ObjectId featureId            = ObjectId.Null;
                C3DLandDb.FeatureLine feature = 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();
            }
        }
 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();
     }
 }
        public ObjectId GetFeatureLineSiteId(ObjectId featureId)
        {
            Debug.WriteLine("Starting GetFeatureLineSiteId");

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                var feature = (C3DLandDb.FeatureLine)featureId.GetObject(OpenMode.ForRead, false, true);
                var siteid  = feature.SiteId;

                Debug.WriteLine("Ending GetFeatureLineSiteId");
                return(siteid);
            }
        }
        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");
                }
            }
        }
        public ObjectId AddCivil2016BreaklineByTrans(ObjectId SurfaceId, ObjectId polyId, ObjectId siteId, string name)
        {
            ObjectId featureId = ObjectId.Null;

            C3DLandDb.FeatureLine feature = null;
            var layername = "";

            Debug.WriteLine("Starting AddCivil2016BreaklineByTrans");

            using (Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    var checkPoly = polyId.GetObject
                                        (OpenMode.ForRead, false, true) as Polyline;

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

                        layername = checkPoly.Layer;
                        var color = checkPoly.Color;

                        feature = featureId.GetObject(OpenMode.ForWrite) as C3DLandDb.FeatureLine;

                        feature.Layer = layername;
                        feature.Color = color;
                        feature.Name += layername + "-" + String.Format("A{0:0#}A", feature.Area) + "-" + DateTime.Now.Millisecond;
                    }
                    else
                    {
                        tr.Abort();
                        Debug.WriteLine("Aborted AddCivil2016BreaklineByTrans " +
                                        layername + " Count: " + checkPoly.NumberOfVertices);
                    }

                    tr.Commit();

                    Debug.WriteLine("Ending AddCivil2016BreaklineByTrans" +
                                    layername + " Count: " + checkPoly.NumberOfVertices);

                    return(featureId);
                }
            }
        }
        public object OpenFeatureLineForSave(ObjectId featureId)
        {
            Debug.WriteLine("Starting OpenFeatureLineForSave");

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                var feature       = (C3DLandDb.FeatureLine)featureId.GetObject(OpenMode.ForWrite, false, true);
                var p3Dcollection = feature.GetPoints(FeatureLinePointType.AllPoints);

                var poly3d = new Polyline3d(Poly3dType.SimplePoly, p3Dcollection, true);
                poly3d.Layer = feature.Layer;
                poly3d.Color = feature.Color;
                _polylines.Add(poly3d);

                //C3DLandDb.TinSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as C3DLandDb.TinSurface;
                //surface.BreaklinesDefinition.AddStandardBreaklines(p3Dcollection, 1.0, 2.0, 5.0, 0.0);

                tr.Commit();
                Debug.WriteLine("Ending OpenFeatureLineForSave");
                return(poly3d);
            }
        }
 public bool AddStandardBoundary(ObjectId polyId, string name, ObjectId surfaceId)
 {
     try
     {
         PasteSurfaces pasteSurfaces = new PasteSurfaces();
         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();
             pasteSurfaces.AddStandardBoundary(polyId, name, surface);
             //surface.DowngradeOpen();
             tr.Commit();
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessengerManager.MessengerManager.LogException(ex);
     }
     return(false);
 }
        /// <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)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
        }
        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);
            }
        }