private static bool ZeroElevation(FeatureLine fl)
        {
            try
            {
                using (var tr = Active.StartTransaction())
                {
                    Point3dCollection pointsOnFL =
                        fl.GetPoints(FeatureLinePointType.AllPoints);

                    for (int i = 0; i < pointsOnFL.Count; i++)
                    {
                        if (Math.Abs(pointsOnFL[i].Z) < 0.01)
                        {
                            return(true);
                        }
                    }

                    tr.Commit();
                }
            }
            catch (Exception ex)

            {
                MessengerManager.MessengerManager.LogException(ex);
            }

            return(false);
        }
        public static void SetNewPointElevation(FeatureLine fl,
                                                Point3d point, double elevationDelta)
        {
            // get all points on the Feature Line
            Point3dCollection pointsOnFL =
                fl.GetPoints(FeatureLinePointType.AllPoints);

            // find the closest point and index
            double  distance            = double.MaxValue;
            int     index               = 0;
            Point3d closestPointOnCurve = Point3d.Origin;

            for (int i = 0; i < pointsOnFL.Count; i++)
            {
                Point3d p = pointsOnFL[i];
                if (p.DistanceTo(point) < distance)
                {
                    distance            = p.DistanceTo(point);
                    closestPointOnCurve = p;
                    index = i;
                }
            }

            // apply the delta
            fl.SetPointElevation(index,
                                 closestPointOnCurve.Z + elevationDelta);
        }
Beispiel #3
0
        public void CreateFromPolyline()
        {
            using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                try
                {
                    PromptEntityOptions promptEntOp = new PromptEntityOptions("Select a Polyline : ");
                    PromptEntityResult  promptEntRs = default(PromptEntityResult);
                    promptEntRs = Active.Editor.GetEntity(promptEntOp);
                    if (promptEntRs.Status != PromptStatus.OK)
                    {
                        Active.Editor.WriteMessage("Exiting! Try Again !");
                        return;
                    }

                    ObjectId idEnt = default(ObjectId);
                    idEnt = promptEntRs.ObjectId;
                    ObjectId oFtrLn = FeatureLine.Create("Test", idEnt);
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    Active.Editor.WriteMessage("Error : ", ex.Message);
                }
            }
        }
Beispiel #4
0
        public static double GetElevationAtPoint(this FeatureLine featureLine, Point3d point)
        {
            Point3dCollection points = featureLine.GetPoints(FeatureLinePointType.AllPoints);

            //Se if point already exists
            foreach (Point3d point3d in points)
            {
                if (point3d.X == point.X && point3d.Y == point.Y)
                {
                    return(point3d.Z);
                }
            }

            double  targetParam = featureLine.GetParameterAtPoint(point);
            Point3d lastPoint   = Point3d.Origin;

            //if not find closest point and interpolate between
            for (int i = 0; i < points.Count; i++)
            {
                Point3d testPoint = points[i];
                double  param     = featureLine.GetParameterAtPoint(testPoint);
                if (targetParam < param)
                {
                    break;
                }

                lastPoint = testPoint;
            }

            double additionalDistance = Math.Sqrt(Math.Pow(point.X - lastPoint.X, 2) + Math.Pow(point.Y - lastPoint.Y, 2));
            double grade = featureLine.GetGradeOutAtPoint(lastPoint);

            return(lastPoint.Z + grade * additionalDistance);
        }
Beispiel #5
0
        public FeatureLine SelectFeatureline(string message)
        {
            PromptEntityOptions options = new PromptEntityOptions(message);

            options.SetRejectMessage("\nThe selected object is not a Featureline!");
            options.AddAllowedClass(typeof(FeatureLine), false);
            PromptEntityResult peo = Active.Editor.GetEntity(options);

            FeatureLine result = null;

            using (Transaction tr = Active.Database.TransactionManager.StartTransaction())
            {
                switch (peo.Status)
                {
                case PromptStatus.OK:
                    FeatureLine feat = tr.GetObject(peo.ObjectId, OpenMode.ForRead) as FeatureLine;
                    result = feat;
                    break;

                case PromptStatus.Cancel:
                    Active.Editor.WriteMessage("Select canceled");
                    return(null);
                }
                tr.Commit();
                return(result);
            }
        }
        public double GetDepthAtPoint(Point3d point, FeatureLine existingGround, FeatureLine proposedGround)
        {
            NHBC2020FoundationDepth depth = new NHBC2020FoundationDepth();

            depth.ExistingGroundLevel = existingGround.GetElevationAtPoint(point);
            depth.ProposedGroundLevel = proposedGround.GetElevationAtPoint(point);

            /*if (ProposedGround != null)
             * {
             *  FeatureLine proposedLine = GetFeatureLine(this.BaseObject, soilSurfaceContainer.ProposedGround);
             *  depth.ProposedGroundLevel = proposedLine.MinElevation;
             * }*/

            switch (SoilProperties.SoilShrinkability)
            {
            case Shrinkage.High:
                depth.SoilPlasticity = VolumeChangePotential.High;
                break;

            case Shrinkage.Medium:
                depth.SoilPlasticity = VolumeChangePotential.Medium;
                break;

            case Shrinkage.Low:
                depth.SoilPlasticity = VolumeChangePotential.Low;
                break;
            }

            depth.Run();

            return(depth.FoundationDepth.Value);
        }
        public static double[] GetZValues(FeatureLine fl)
        {
            try
            {
                Point3dCollection pointsOnFL =
                    fl.GetPoints(FeatureLinePointType.AllPoints);

                var mypoints = new List <double>();


                foreach (Point3d item in pointsOnFL)
                {
                    if (Math.Abs(item.Z) > 0.01)
                    {
                        mypoints.Add(item.Z);
                    }
                }


                return(mypoints.ToArray());
            }
            catch (Exception ex)

            {
                MessengerManager.MessengerManager.LogException(ex);
            }

            return(null);
        }
        public static void SendMessage(FeatureLine fl)
        {
            try
            {
                var _site    = fl.SiteId;
                var _lay     = fl.Layer;
                var _name    = fl.Name;
                var max      = fl.MaxElevation;
                var min      = fl.MinElevation;
                var maxg     = fl.MaxGrade;
                var sitename = "";

                var site = _site.GetObject(Acaddb.OpenMode.ForRead) as Site;
                if (site != null)
                {
                    sitename = site.Name;
                }
                else
                {
                    sitename = "No-Id";
                }

                WriteOutput(_lay, _name, max, min, maxg, sitename);
            }
            catch (Exception ex)

            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }
        private static void ApplyElevationCorrection(FeatureLine fl, double mean, double flMaxElevation)
        {
            try
            {
                if (mean <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(mean));
                }


                fl.UpgradeOpen();
                COMS.MessengerManager.AddLog("Start ApplyElevationCorrection");

                using (var tr = Active.StartTransaction())
                {
                    Point3dCollection pointsOnFL =
                        fl.GetPoints(FeatureLinePointType.AllPoints);

                    for (int i = 0; i < pointsOnFL.Count; i++)
                    {
                        Point3d p = pointsOnFL[i];


                        var diff = Math.Abs(flMaxElevation - p.Z);
                        if (diff > MaxDiff)
                        {
                            try
                            {
                                fl.SetPointElevation(i, mean);
                                COMS.MessengerManager.AddLog
                                    ("Changed Feature Line: " +
                                    fl.Name + " Old Elevation=" +
                                    p.Z + " New Elevation=" +
                                    mean);
                            }
                            catch (Exception ex)
                            {
                                COMS.MessengerManager.LogException(ex);
                            }
                        }
                    }

                    tr.Commit();
                }

                COMS.MessengerManager.AddLog("End ApplyElevationCorrection");
            }
            catch (Exception ex)

            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }
        public FeatureLine GetFeatureLine(ObjectId curve, CivSurface targetSurface)
        {
            Database    acCurDb = _hostDocument.Database;
            Transaction acTrans = acCurDb.TransactionManager.TopTransaction;

            ObjectId    perimId = FeatureLine.Create(Guid.NewGuid().ToString(), curve);
            FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;

            perim.AssignElevationsFromSurface(targetSurface.Id, true);

            return(perim);
        }
        // TODO: Revoew this method

        /*private SurfaceProperties? ExtractSurfaceInformation(CivSurface targetSurface)
         * {
         *  Document acDoc = Application.DocumentManager.MdiActiveDocument;
         *  Database acCurDb = acDoc.Database;
         *  Transaction acTrans = acCurDb.TransactionManager.TopTransaction;
         *  Polyline boundary = (Polyline) acTrans.GetObject(this.BaseObject, OpenMode.ForRead);
         *
         *  Point2dCollection points = new Point2dCollection();
         *  for (int i = 0, size = boundary.NumberOfVertices; i < size; i++)
         *      points.Add(boundary.GetPoint2dAt(i));
         *
         *  SurfaceProperties result = new SurfaceProperties();
         *
         *  using (Database destDb = new Database(true, true))
         *  {
         *      using (Transaction transDest = destDb.TransactionManager.StartTransaction())
         *      {
         *
         *          Database db = Application.DocumentManager.MdiActiveDocument.Database;
         *          HostApplicationServices.WorkingDatabase = destDb;
         *
         *          // TODO: Review if exception handling is the answer
         *          ObjectId newSurfaceId;
         *          try
         *          {
         *              // This errors out when surface has ben copied
         *              newSurfaceId = TinSurface.CreateByCropping(destDb, "Surface<[Next Counter(CP)]>",
         *                  targetSurface.ObjectId, points);
         *
         *              TinSurface newSurface = transDest.GetObject(newSurfaceId, OpenMode.ForRead) as TinSurface;
         *              GeneralSurfaceProperties genProps = newSurface.GetGeneralProperties();
         *              result.MaxElevation = genProps.MaximumElevation;
         *              result.MinElevation = genProps.MinimumElevation;
         *          }
         *          catch (SurfaceException e)
         *          {
         *              return null;
         *          }
         *          finally
         *          {
         *              HostApplicationServices.WorkingDatabase = db;
         *          }
         *      }
         *  }
         *
         *  return result;
         * }*/

        public FeatureLine GetPerim(CivSurface targetSurface)
        {
            Document    acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database    acCurDb = acDoc.Database;
            Transaction acTrans = acCurDb.TransactionManager.TopTransaction;
            //Polyline boundary = (Polyline) acTrans.GetObject(this.BaseObject, OpenMode.ForRead);

            ObjectId    perimId = FeatureLine.Create(Guid.NewGuid().ToString(), this.BaseObject);
            FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;

            perim.AssignElevationsFromSurface(targetSurface.Id, true);

            return(perim);
        }
        private bool SetFoundationInputs(CivSurface existing, CivSurface proposed, SoilProperties properties)
        {
            /*SurfaceProperties? existingProps = ExtractSurfaceInformation(existing);
             * if (existingProps.HasValue)
             * {
             *  _depth.ExistingGroundLevel = existingProps.Value.MinElevation;
             * }
             * else
             * {
             *  return false;
             * }*/
            FeatureLine existingLine = GetPerim(existing);

            _depth.ExistingGroundLevel = existingLine.MinElevation;

            if (proposed != null)
            {
                /*SurfaceProperties? proposedProps = ExtractSurfaceInformation(proposed);
                 * if (proposedProps.HasValue)
                 * {
                 *  _depth.ProposedGroundLevel = proposedProps.Value.MinElevation;
                 * }*/
                FeatureLine proposedLine = GetPerim(proposed);
                _depth.ProposedGroundLevel = proposedLine.MinElevation;
            }

            switch (properties.SoilShrinkability)
            {
            case Shrinkage.High:
                _depth.SoilPlasticity = VolumeChangePotential.High;
                break;

            case Shrinkage.Medium:
                _depth.SoilPlasticity = VolumeChangePotential.Medium;
                break;

            case Shrinkage.Low:
                _depth.SoilPlasticity = VolumeChangePotential.Low;
                break;
            }

            return(true);
        }
        public static Polyline3d AlignmentToPolyline3d2(Alignment alignment, Profile profile)
        {
            Point3d    point;
            Polyline3d p3d = null;

            var    elevations = new Point3dCollection();
            var    station    = 0d;
            double elevation;
            var    db = alignment.Database;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var polylineId = alignment.GetPolyline();
                using (var polyline = tr.GetObject(polylineId, OpenMode.ForRead) as Polyline)
                {
                    do
                    {
                        station += 0.001;
                        if (station > polyline.Length)
                        {
                            station = polyline.Length;
                        }

                        elevation = profile.ElevationAt(station);
                        point     = polyline.GetPointAtDist(station);
                        point     = new Point3d(point.X, point.Y, elevation);
                        elevations.Add(point);
                    } while (station < polyline.Length);

                    var fid         = FeatureLine.Create("george", polylineId);
                    var featureLine = tr.GetObject(fid, OpenMode.ForWrite) as FeatureLine;
                    foreach (Point3d p in elevations)
                    {
                        featureLine.InsertElevationPoint(p);
                    }
                    var objs = new DBObjectCollection();
                    featureLine.Explode(objs);
                    p3d = new Polyline3d(Poly3dType.SimplePoly, elevations, polyline.Closed);
                }
            }

            return(p3d);
        }
        public IReadOnlyList <DepthPoint> CalculateDepths(SoilSurfaceContainer soilSurfaceContainer)
        {
            // TODO: Add code for more than just the centre line
            // TODO: Add tree ring code

            FeatureLine existingLine = soilSurfaceContainer.GetFeatureLine(this.BaseObject, soilSurfaceContainer.ExistingGround);
            FeatureLine proposedLine = soilSurfaceContainer.GetFeatureLine(this.BaseObject, soilSurfaceContainer.ProposedGround);

            List <Point3d>    elevationPoints = GetPointsOfElevationChange(soilSurfaceContainer, existingLine, proposedLine);
            List <DepthPoint> depthPoints     = new List <DepthPoint>();

            foreach (Point3d elevationPoint in elevationPoints)
            {
                DepthPoint dp = new DepthPoint()
                {
                    DistanceParameter = existingLine.GetParameterAtPoint(elevationPoint),
                    RequiredDepth     = soilSurfaceContainer.GetDepthAtPoint(elevationPoint, existingLine, proposedLine)
                };

                depthPoints.Add(dp);
            }

            return(depthPoints.OrderBy(x => x.DistanceParameter).ToList());
        }
Beispiel #15
0
        //[CommandMethod("AddDataToSurfaces")]
        /// <summary>
        /// Adding data from PlanFeatures (character lines) to surfaces and also inser PointsCogoGrous to surfaces
        /// </summary>
        /// <param name="midOrdinate"></param>
        /// <param name="maxDist"></param>
        /// <param name="weedingDist"></param>
        /// <param name="weedingAngle"></param>
        public static void AddDataToSurfaces(double midOrdinate = 0.1, double maxDist = 10.0, double weedingDist = 0.1, double weedingAngle = 0.5)
        {
            //Document doc = doc_dyn.AcDocument;
            var      CivilApp = CivilApplication.ActiveDocument;
            Document doc      = Application.DocumentManager.MdiActiveDocument;
            Database db       = doc.Database;
            Editor   ed       = doc.Editor;

            //double midOrdinate = 0.1; double maxDist = 10.0; double weedingDist = 0.1; double weedingAngle = 0.5; -- if start as CommandMethod
            using (Transaction ts = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId OneSiteItem in CivilApp.GetSiteIds())
                    {
                        Site   OneSite   = ts.GetObject(OneSiteItem, OpenMode.ForRead) as Site;
                        string Site_Name = OneSite.Name;
                        //ed.WriteMessage("\n Site_Name =" + Site_Name);

                        foreach (ObjectId OneSurfaceId in CivilApp.GetSurfaceIds())
                        {
                            //ObjectId SurfaceId = new ObjectId();
                            TinSurface CurrentSurface = ts.GetObject(OneSurfaceId, OpenMode.ForWrite) as TinSurface;
                            //ed.WriteMessage("\n OneSurf.Name =" + CurrentSurface.Name);
                            if (CurrentSurface.Name == Site_Name)
                            {
                                ed.WriteMessage($"\n Site with surface's name {CurrentSurface.Name} is exist!");
                                //ed.WriteMessage("\n Start adding standard breaklines for " + CurrentSurface.Name);
                                AddBreakLines(null);
                                //ed.WriteMessage("\n Start adding point group for " + CurrentSurface.Name);
                                AddPointsGroup();
                                //ed.WriteMessage("\n Start adding out boundary for " + CurrentSurface.Name);
                                AddBreakLines("Out_Boundary");
                                //ed.WriteMessage("\n Start adding internal boundary for " + CurrentSurface.Name);
                                AddBreakLines("Internal_Boundary");
                                CurrentSurface.Rebuild();
                                ed.WriteMessage("\n Start rebuilding for " + CurrentSurface.Name);

                                void AddBreakLines(string TypeOfLines)
                                {
                                    ObjectIdCollection GroupOfBreaklines = new ObjectIdCollection();

                                    foreach (ObjectId OneFlineItem in OneSite.GetFeatureLineIds())
                                    {
                                        FeatureLine OneFline      = ts.GetObject(OneFlineItem, OpenMode.ForRead) as FeatureLine;
                                        string      OneFline_Name = OneFline.Name;

                                        if (OneFline_Name.Contains("outer_") && TypeOfLines == "Out_Boundary")
                                        {
                                            ed.WriteMessage("\n Start adding outer boundary for " + OneFline_Name);
                                            CurrentSurface.BoundariesDefinition.AddBoundaries(OneFline.GetPoints(Autodesk.Civil.FeatureLinePointType.AllPoints), midOrdinate, Autodesk.Civil.SurfaceBoundaryType.Outer, true);
                                        }
                                        else if (OneFline_Name.Contains("void_") && TypeOfLines == "Internal_Boundary")
                                        {
                                            ed.WriteMessage("\n Start adding internal boundary for " + OneFline_Name);
                                            CurrentSurface.BoundariesDefinition.AddBoundaries(OneFline.GetPoints(Autodesk.Civil.FeatureLinePointType.AllPoints), midOrdinate, Autodesk.Civil.SurfaceBoundaryType.Hide, true);
                                        }
                                        else
                                        {
                                            GroupOfBreaklines.Add(OneFlineItem);
                                        }
                                    }
                                    if (TypeOfLines == null)
                                    {
                                        ed.WriteMessage("\n Start adding standard breaklines");
                                        CurrentSurface.BreaklinesDefinition.AddStandardBreaklines(GroupOfBreaklines, midOrdinate, maxDist, weedingDist, weedingAngle);
                                    }
                                }

                                void AddPointsGroup()
                                {
                                    CogoPointCollection CG_AllPoints = CivilApp.CogoPoints;

                                    foreach (ObjectId OneCogoItem in CG_AllPoints)
                                    {
                                        CogoPoint  COGO_Single = ts.GetObject(OneCogoItem, OpenMode.ForRead) as CogoPoint;
                                        ObjectId   CG_GroupId  = COGO_Single.PrimaryPointGroupId;
                                        PointGroup CG_Group    = ts.GetObject(CG_GroupId, OpenMode.ForRead) as PointGroup;
                                        if (CG_Group.Name == Site_Name)
                                        {
                                            ed.WriteMessage("\n COGO points group for surface's name was find - it's name = " + CG_Group.Name);
                                            CurrentSurface.PointGroupsDefinition.AddPointGroup(CG_GroupId);
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
                catch (System.Exception e)
                {
                    ed.WriteMessage(e.Message);
                }

                ts.Commit();
            }
        }
        private List <Point3d> GetPointsOfElevationChange(SoilSurfaceContainer soilSurfaceContainer, FeatureLine existingLine, FeatureLine proposedLine)
        {
            List <Point3d> elevationPoints = new List <Point3d>();

            elevationPoints.Add(StartPoint);

            foreach (Point3d point3d in existingLine.GetPoints(FeatureLinePointType.AllPoints))
            {
                elevationPoints.Add(point3d);
            }

            foreach (Point3d point3d in proposedLine.GetPoints(FeatureLinePointType.AllPoints))
            {
                elevationPoints.Add(point3d);
            }

            elevationPoints.Add(EndPoint);

            return(elevationPoints);
        }
        public static void CheckElevFromFeatureLine(FeatureLine fl)
        {
            try
            {
                var mean = 0.0;

                if (fl == null)
                {
                    throw new ArgumentNullException(nameof(fl));
                }


                COMS.MessengerManager.AddLog("Start CheckElevFromFeatureLine");

                using (Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    using (var tr = Active.StartTransaction())

                    {
                        var feature = (FeatureLine)fl.ObjectId.GetObject(Acaddb.OpenMode.ForRead);

                        if (!feature.IsWriteEnabled)
                        {
                            feature.UpgradeOpen();
                        }


                        if (feature != null)
                        {
                            SendMessage(feature);

                            try
                            {
                                mean = GetAverageElev(feature);
                            }
                            catch
                            {
                            }

                            if (Math.Abs(mean) <= 0.01)
                            {
                                goto Skip;
                            }

                            if (ZeroElevation(feature))
                            {
                                ApplyElevationCorrection(feature, mean, feature.MaxElevation);
                            }

                            if (feature.Layer.Contains("S-WATER"))
                            {
                                // CorrectWaterFeaturelines(fl, mean);
                            }

                            SendMessage(feature);
                        }

Skip:

                        tr.Commit();
                    }

                    COMS.MessengerManager.AddLog("End CheckElevFromFeatureLine");
                }
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }
        // TODO: Port of existing code, requires refactoring immininently
        public void EstimateFFLFromSurface(CivSurface proposed)
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObject obj = acTrans.GetObject(this.BaseObject, OpenMode.ForWrite);

                //Need to add the temp line to create feature line from it
                BlockTable       acBlkTbl    = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec =
                    acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                ObjectId    perimId = FeatureLine.Create("plot" + PlotId, obj.ObjectId);
                FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;
                perim.AssignElevationsFromSurface(proposed.Id, false);
                var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint);

                // TODO: Move to settings
                double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15;

                // TODO: Move to generation code
                //Ad the FFL Label
                // Create a multiline text object
                using (MText acMText = new MText())
                {
                    Solid3d            Solid = new Solid3d();
                    DBObjectCollection coll  = new DBObjectCollection();
                    coll.Add(obj);
                    Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0);
                    Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0);
                    Solid.Dispose();

                    acMText.Location = centroid;
                    acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3");

                    //acMText.Rotation = Rotation;
                    acMText.Height     = 8;
                    acMText.Attachment = AttachmentPoint.MiddleCenter;

                    acBlkTblRec.AppendEntity(acMText);
                    acTrans.AddNewlyCreatedDBObject(acMText, true);
                }

                // TODO: Move to generation code
                foreach (Point3d p in points)
                {
                    using (MText acMText = new MText())
                    {
                        Point3d insert = new Point3d(p.X, p.Y, 0);
                        acMText.Location = insert;

                        //Number of course
                        int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f)));

                        if (courses > 0)
                        {
                            acMText.Contents   = courses + " Courses";
                            acMText.Height     = 4;
                            acMText.Attachment = AttachmentPoint.TopRight;

                            acBlkTblRec.AppendEntity(acMText);
                            acTrans.AddNewlyCreatedDBObject(acMText, true);
                        }
                    }
                }

                //perim.Erase();
                //obj.Erase();
                acTrans.Commit();
            }
        }
        public void PlineToPlots()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.SingleOnly = true;
            pso.RejectObjectsOnLockedLayers = true;
            PromptSelectionResult psr = acDoc.Editor.GetSelection(pso);

            if (psr.Status == PromptStatus.OK)
            {
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    CivSurface oSurface = null;

                    //Get the target surface
                    ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds();
                    foreach (ObjectId surfaceId in SurfaceIds)
                    {
                        CivSurface temp = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;
                        if (temp.Name == Civils.Constants.ProposedGroundName)
                        {
                            oSurface = temp;
                        }
                    }

                    int plotCount = 0;


                    foreach (SelectedObject so in psr.Value)
                    {
                        try
                        {
                            DBObject obj = acTrans.GetObject(so.ObjectId, OpenMode.ForWrite);

                            if (obj is Curve)
                            {
                                plotCount++;

                                //Polyline acPline = obj as Polyline;

                                //Need to add the temp line to create feature line from it
                                BlockTable       acBlkTbl    = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                                BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                                ObjectId perimId = FeatureLine.Create("plot" + plotCount, obj.ObjectId);

                                FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;
                                perim.AssignElevationsFromSurface(oSurface.Id, false);
                                var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint);

                                double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15;

                                //Ad the FFL Label
                                // Create a multiline text object
                                using (MText acMText = new MText())
                                {
                                    Solid3d            Solid = new Solid3d();
                                    DBObjectCollection coll  = new DBObjectCollection();
                                    coll.Add(obj);
                                    Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0);
                                    Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0);
                                    Solid.Dispose();

                                    acMText.Location = centroid;
                                    acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3");
                                    //acMText.Rotation = Rotation;
                                    acMText.Height     = 8;
                                    acMText.Attachment = AttachmentPoint.MiddleCenter;

                                    acBlkTblRec.AppendEntity(acMText);
                                    acTrans.AddNewlyCreatedDBObject(acMText, true);
                                }

                                foreach (Point3d p in points)
                                {
                                    using (MText acMText = new MText())
                                    {
                                        Point3d insert = new Point3d(p.X, p.Y, 0);
                                        acMText.Location = insert;
                                        //Number of course
                                        int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f)));

                                        if (courses > 0)
                                        {
                                            acMText.Contents   = courses + " Courses";
                                            acMText.Height     = 4;
                                            acMText.Attachment = AttachmentPoint.TopRight;

                                            acBlkTblRec.AppendEntity(acMText);
                                            acTrans.AddNewlyCreatedDBObject(acMText, true);
                                        }
                                    }
                                }

                                //perim.Erase();
                                obj.Erase();
                            }
                            else
                            {
                                acDoc.Editor.WriteMessage("Object is not a polyline\n");
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception e)
                        {
                            acDoc.Editor.WriteMessage(e.Message + "\n");
                        }
                        catch (System.Exception e)
                        {
                            acDoc.Editor.WriteMessage(e.Message + "\n");
                        }
                    }
                    acTrans.Commit();
                }
            }
        }
 private static double ElevationDifference(FeatureLine fl)
 {
     return(Math.Abs(fl.MaxElevation - fl.MinElevation));
 }
        /// <summary>
        /// Corrects the water featurelines.
        /// Has been omitted until further notice due to 25 swings in elevation for wier and structures
        /// </summary>
        /// <param name="fl">The fl.</param>
        /// <param name="mean">The mean.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        public static void CorrectWaterFeaturelines(FeatureLine fl, double mean)
        {
            try
            {
                if (mean <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(mean));
                }

                fl.UpgradeOpen();
                if (fl.Layer.Contains("S-WATER"))
                {
                    using (var tr = Active.StartTransaction())
                    {
                        Point3dCollection pointsOnFL =
                            fl.GetPoints(FeatureLinePointType.AllPoints);
                        COMS.MessengerManager.AddLog("Start CorrectWaterFeaturelines");

                        for (int i = 0; i < pointsOnFL.Count; i++)
                        {
                            Point3d p    = pointsOnFL[i];
                            var     last = pointsOnFL.Count - 1;
                            var     diff = Math.Abs(p.Z - mean);

                            if ((diff > MaxWater) && (Math.Abs(mean) > 0.01))
                            {
                                COMS.MessengerManager.AddLog("S-Changed to Mean = " + mean);
                                try
                                {
                                    if (i != last)
                                    {
                                        fl.SetPointElevation(i, mean);
                                    }
                                }
                                catch (System.ArgumentOutOfRangeException)
                                {
                                }

                                catch (Exception ex)
                                {
                                    MessengerManager.MessengerManager.LogException(ex);
                                    MessengerManager.MessengerManager.AddLog("Failure = " + i + "and Mean = " + mean);
                                }

                                COMS.MessengerManager.AddLog("E-Changed to Mean = " + mean);
                            }
                        }

                        tr.Commit();
                    }
                }

                COMS.MessengerManager.AddLog("End CorrectWaterFeaturelines");
            }

            catch (Exception ex)

            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }
        public static double GetAverageElev(FeatureLine fl)
        {
            var nodes = 0;
            var mean  = 0.0;
            //var total = 0.0;
            var median = 0.0;
            var max    = 0.0;
            var min    = 0.0;

            try
            {
                var vals = GetZValues(fl);

                if (vals == null)
                {
                    return(0.0);
                }

                nodes = GetCount(vals);

                if (nodes == 0)
                {
                    return(0.0);
                }
                try
                {
                    MessengerManager.MessengerManager.AddLog("Mean Before: " + mean);

                    mean = MathNet.Numerics.Statistics.Statistics.GeometricMean(vals);

                    MessengerManager.MessengerManager.AddLog("Mean After: " + mean);


                    if (Math.Abs(mean) < 0.01)
                    {
                        median = MathNet.Numerics.Statistics.Statistics.Median(vals);
                        min    = MathNet.Numerics.Statistics.Statistics.Minimum(vals);
                        max    = MathNet.Numerics.Statistics.Statistics.Maximum(vals);

                        if (Math.Abs(median) > 0.01)
                        {
                            return(median);
                        }
                    }
                    else
                    {
                        return(mean);
                    }
                }
                catch
                {
                }
            }
            catch (Exception ex)

            {
                MessengerManager.MessengerManager.LogException(ex);
            }

            return(0.0);
        }