Beispiel #1
0
        public IEnumerable <DBText> CreateGridLabels(IEnumerable <Polyline> rectgs, Autodesk.Civil.DatabaseServices.TinVolumeSurface surface)
        {
            List <DBText> res = new List <DBText>();

            surface = surface.Id.GetObjectForRead <Autodesk.Civil.DatabaseServices.TinVolumeSurface>();
            var polygon = surface.ExtractBorders().ConvertToPolyline();

            var points = _getGridElevationPoints(rectgs.Cast <Polyline>());

            foreach (var p in points)
            {
                if (!polygon.IsInsidePolygon(p))
                {
                    continue;
                }

                var baseSurface       = surface.GetVolumeProperties().BaseSurface.GetObjectForRead <CivilSurface>();
                var comparisonSurface = surface.GetVolumeProperties().ComparisonSurface.GetObjectForRead <CivilSurface>();

                double baseElevation       = baseSurface.FindElevationAtXY(p.X, p.Y);
                double comparisonElevation = comparisonSurface.FindElevationAtXY(p.X, p.Y);
                //double topLeftElevation = surface.FindElevationAtXY(p.X, p.Y);

                var gridLabels = CreateElevationLabels(p, baseElevation, comparisonElevation);
                res.AddRange(gridLabels);
            }

            Dictionary <int, List <double[]> > ammounts = new Dictionary <int, List <double[]> >();

            foreach (var rectg in rectgs)
            {
                var volumeLable = CreateVolumeLabels(rectg.ConvertToRectangle().Value, surface);
                if (volumeLable != null)
                {
                    res.AddRange(volumeLable.Where(x => x != null));
                    int      columnNumber = _gride.GetColumnNumber(rectg.ConvertToRectangle().Value.LowerLeft);
                    double[] buffer       = new double[volumeLable.Count()];
                    DBText   textBuffer   = null;
                    if ((textBuffer = volumeLable.FirstOrDefault()) != null)
                    {
                        buffer[0] = double.Parse(textBuffer.TextString, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.AllowLeadingSign, _culture);
                    }
                    if (volumeLable.Count() > 1)
                    {
                        if ((textBuffer = volumeLable.LastOrDefault()) != null)
                        {
                            buffer[1] = double.Parse(textBuffer.TextString, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.AllowLeadingSign, _culture);
                        }
                    }
                    if (!ammounts.ContainsKey(columnNumber))
                    {
                        ammounts[columnNumber] = new List <double[]>();
                    }
                    ammounts[columnNumber].Add(buffer);
                }
            }

            foreach (var column in ammounts.Keys)
            {
                double fillSum = ammounts[column].Sum(x => x.Length > 0 ? x[0] : 0d);
                double cutSum  = ammounts[column].Sum(x => x.Length > 1 ? x[1] : 0d);
                SetValueToField(column, fillSum, TopRow);
                SetValueToField(column, cutSum, BottomRow);
            }
            CalculateSum();

            return(res);
        }
Beispiel #2
0
        public IEnumerable <DBText> CreateVolumeLabels(Rectangle3d rectg, Autodesk.Civil.DatabaseServices.TinVolumeSurface surface)
        {
            List <DBText> res           = new List <DBText>();
            Point3d       topPosition   = Point3d.Origin;
            Vector3d      centralVector = rectg.UpperRight - rectg.LowerLeft;

            topPosition = rectg.LowerLeft.Add(centralVector.MultiplyBy(0.5d));
            Point3d bottomPosition = topPosition;

            Autodesk.Civil.DatabaseServices.SurfaceVolumeInfo volumeInfo = new civil.DatabaseServices.SurfaceVolumeInfo();
            try
            {
                volumeInfo = surface.GetBoundedVolumes(rectg.GetPoints(true));
            }
            catch (ArgumentException)
            {
                return(null);
            }
            if (Math.Round(volumeInfo.Fill, 1) > 0d &&
                Math.Round(volumeInfo.Cut, 1) > 0d)
            {
                Vector3d yaxis = rectg.GetLeftVerticalVector().Normalize();
                Matrix3d mat   = Matrix3d.Displacement(yaxis.MultiplyBy(_volumeTextHeight * 0.7));
                topPosition    = topPosition.TransformBy(mat);
                bottomPosition = bottomPosition.TransformBy(mat.Inverse());
            }

            if (Math.Round(volumeInfo.Fill, 1) > 0d)
            {
                DBText topText = new DBText();
                topText.SetDatabaseDefaults();
                topText.Height         = _volumeTextHeight;
                topText.Rotation       = 0d;
                topText.Position       = Point3d.Origin;
                topText.HorizontalMode = TextHorizontalMode.TextCenter;
                topText.VerticalMode   = TextVerticalMode.TextVerticalMid;
                topText.Annotative     = AnnotativeStates.False;
                //topText.AddContext(_scale);
                topText.AlignmentPoint = topPosition;
                topText.AdjustAlignment(HostApplicationServices.WorkingDatabase);

                topText.TextString = '+' + Math.Round(volumeInfo.Fill).ToString("#0.0", _culture);
                res.Add(topText);
            }
            else
            {
                res.Add(null);
            }

            if (Math.Round(volumeInfo.Cut, 1) > 0d)
            {
                DBText bottomText = new DBText();
                bottomText.SetDatabaseDefaults();
                bottomText.Height         = _volumeTextHeight;
                bottomText.Rotation       = 0d;
                bottomText.Position       = Point3d.Origin;
                bottomText.HorizontalMode = TextHorizontalMode.TextCenter;
                bottomText.VerticalMode   = TextVerticalMode.TextVerticalMid;
                bottomText.Annotative     = AnnotativeStates.False;
                //bottomText.AddContext(_scale);
                bottomText.AlignmentPoint = bottomPosition;;
                bottomText.AdjustAlignment(HostApplicationServices.WorkingDatabase);

                bottomText.TextString = Math.Round(-volumeInfo.Cut, 1).ToString("#0.0", _culture);
                res.Add(bottomText);
            }
            else
            {
                res.Add(null);
            }

            if (Math.Round(volumeInfo.Fill, 1) == 0d &&
                Math.Round(volumeInfo.Cut, 1) == 0d)
            {
                DBText centralText = new DBText();
                centralText.SetDatabaseDefaults();
                centralText.Height         = _volumeTextHeight;
                centralText.Rotation       = 0d;
                centralText.Position       = Point3d.Origin;
                centralText.HorizontalMode = TextHorizontalMode.TextCenter;
                centralText.VerticalMode   = TextVerticalMode.TextVerticalMid;
                centralText.Annotative     = AnnotativeStates.False;
                //topText.AddContext(_scale);
                centralText.AlignmentPoint = topPosition;
                centralText.AdjustAlignment(HostApplicationServices.WorkingDatabase);

                centralText.TextString = Math.Round(volumeInfo.Fill).ToString("#0.0", _culture);
                res.Add(centralText);
            }

            return(res);
        }