private static string FormatDimensionText(double measure, bool angular, string userText, DimensionStyle style, Layout layout)
        {
            if (userText == " ")
            {
                return(null);
            }

            string text = string.Empty;

            UnitStyleFormat unitFormat = new UnitStyleFormat
            {
                LinearDecimalPlaces         = style.DIMDEC,
                AngularDecimalPlaces        = style.DIMADEC == -1 ? style.DIMDEC : style.DIMADEC,
                DecimalSeparator            = style.DIMDSEP.ToString(),
                FractionType                = style.DIMFRAC,
                SupressLinearLeadingZeros   = style.SuppressLinearLeadingZeros,
                SupressLinearTrailingZeros  = style.SuppressLinearTrailingZeros,
                SupressAngularLeadingZeros  = style.SuppressAngularLeadingZeros,
                SupressAngularTrailingZeros = style.SuppressAngularTrailingZeros,
                SupressZeroFeet             = style.SuppressZeroFeet,
                SupressZeroInches           = style.SuppressZeroInches
            };

            if (angular)
            {
                switch (style.DIMAUNIT)
                {
                case AngleUnitType.DecimalDegrees:
                    text = AngleUnitFormat.ToDecimal(measure, unitFormat);
                    break;

                case AngleUnitType.DegreesMinutesSeconds:
                    text = AngleUnitFormat.ToDegreesMinutesSeconds(measure, unitFormat);
                    break;

                case AngleUnitType.Gradians:
                    text = AngleUnitFormat.ToGradians(measure, unitFormat);
                    break;

                case AngleUnitType.Radians:
                    text = AngleUnitFormat.ToRadians(measure, unitFormat);
                    break;

                case AngleUnitType.SurveyorUnits:
                    text = AngleUnitFormat.ToDecimal(measure, unitFormat);
                    break;
                }
            }
            else
            {
                double scale = Math.Abs(style.DIMLFAC);
                if (layout != null)
                {
                    // if DIMLFAC is negative the scale value is only applied to dimensions in PaperSpace
                    if (style.DIMLFAC < 0 && !layout.IsPaperSpace)
                    {
                        scale = 1.0;
                    }
                }

                if (style.DIMRND > 0.0)
                {
                    measure = MathHelper.RoundToNearest(measure * scale, style.DIMRND);
                }
                else
                {
                    measure *= scale;
                }

                switch (style.DIMLUNIT)
                {
                case LinearUnitType.Architectural:
                    text = LinearUnitFormat.ToArchitectural(measure, unitFormat);
                    break;

                case LinearUnitType.Decimal:
                    text = LinearUnitFormat.ToDecimal(measure, unitFormat);
                    break;

                case LinearUnitType.Engineering:
                    text = LinearUnitFormat.ToEngineering(measure, unitFormat);
                    break;

                case LinearUnitType.Fractional:
                    text = LinearUnitFormat.ToFractional(measure, unitFormat);
                    break;

                case LinearUnitType.Scientific:
                    text = LinearUnitFormat.ToScientific(measure, unitFormat);
                    break;

                case LinearUnitType.WindowsDesktop:
                    unitFormat.LinearDecimalPlaces = (short)Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalDigits;
                    unitFormat.DecimalSeparator    = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                    text = LinearUnitFormat.ToDecimal(measure * style.DIMLFAC, unitFormat);
                    break;
                }
            }
            text = style.DIMPOST.Replace("<>", text);

            if (!string.IsNullOrEmpty(userText))
            {
                text = userText.Replace("<>", text);
            }

            return(text);
        }
Beispiel #2
0
        public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext)
        {
            base.CopyFrom(from, cloneContext);
            DxfDimensionStyle dxfDimensionStyle = (DxfDimensionStyle)from;

            this.standardFlags_0 = dxfDimensionStyle.standardFlags_0;
            this.string_1        = dxfDimensionStyle.string_1;
            this.string_2        = dxfDimensionStyle.string_2;
            this.string_3        = dxfDimensionStyle.string_3;
            this.double_0        = dxfDimensionStyle.double_0;
            this.double_1        = dxfDimensionStyle.double_1;
            this.double_2        = dxfDimensionStyle.double_2;
            this.double_3        = dxfDimensionStyle.double_3;
            this.double_4        = dxfDimensionStyle.double_4;
            this.double_5        = dxfDimensionStyle.double_5;
            this.double_6        = dxfDimensionStyle.double_6;
            this.double_7        = dxfDimensionStyle.double_7;
            this.double_8        = dxfDimensionStyle.double_8;
            this.double_9        = dxfDimensionStyle.double_9;
            this.double_10       = dxfDimensionStyle.double_10;
            this.double_11       = dxfDimensionStyle.double_11;
            this.double_12       = dxfDimensionStyle.double_12;
            this.double_13       = dxfDimensionStyle.double_13;
            this.double_14       = dxfDimensionStyle.double_14;
            this.double_15       = dxfDimensionStyle.double_15;
            this.double_16       = dxfDimensionStyle.double_16;
            this.double_17       = dxfDimensionStyle.double_17;
            this.bool_0          = dxfDimensionStyle.bool_0;
            this.bool_1          = dxfDimensionStyle.bool_1;
            this.bool_2          = dxfDimensionStyle.bool_2;
            this.bool_3          = dxfDimensionStyle.bool_3;
            this.bool_4          = dxfDimensionStyle.bool_4;
            this.bool_5          = dxfDimensionStyle.bool_5;
            this.dimensionTextVerticalAlignment_0 = dxfDimensionStyle.dimensionTextVerticalAlignment_0;
            this.zeroHandling_0        = dxfDimensionStyle.zeroHandling_0;
            this.zeroHandling_1        = dxfDimensionStyle.zeroHandling_1;
            this.bool_6                = dxfDimensionStyle.bool_6;
            this.short_0               = dxfDimensionStyle.short_0;
            this.bool_7                = dxfDimensionStyle.bool_7;
            this.bool_8                = dxfDimensionStyle.bool_8;
            this.bool_9                = dxfDimensionStyle.bool_9;
            this.bool_10               = dxfDimensionStyle.bool_10;
            this.color_0               = dxfDimensionStyle.color_0;
            this.color_1               = dxfDimensionStyle.color_1;
            this.color_2               = dxfDimensionStyle.color_2;
            this.short_1               = dxfDimensionStyle.short_1;
            this.short_2               = dxfDimensionStyle.short_2;
            this.alternateUnitFormat_0 = dxfDimensionStyle.alternateUnitFormat_0;
            this.short_3               = dxfDimensionStyle.short_3;
            this.angularUnit_0         = dxfDimensionStyle.angularUnit_0;
            this.linearUnitFormat_0    = dxfDimensionStyle.linearUnitFormat_0;
            this.fractionFormat_0      = dxfDimensionStyle.fractionFormat_0;
            this.char_0                = dxfDimensionStyle.char_0;
            this.textMovement_0        = dxfDimensionStyle.textMovement_0;
            this.dimensionTextHorizontalAlignment_0 = dxfDimensionStyle.dimensionTextHorizontalAlignment_0;
            this.bool_11 = dxfDimensionStyle.bool_11;
            this.bool_12 = dxfDimensionStyle.bool_12;
            this.toleranceAlignment_0 = dxfDimensionStyle.toleranceAlignment_0;
            this.zeroHandling_2       = dxfDimensionStyle.zeroHandling_2;
            this.short_4             = dxfDimensionStyle.short_4;
            this.zeroHandling_3      = dxfDimensionStyle.zeroHandling_3;
            this.zeroHandling_4      = dxfDimensionStyle.zeroHandling_4;
            this.cursorUpdate_0      = dxfDimensionStyle.cursorUpdate_0;
            this.short_5             = dxfDimensionStyle.short_5;
            this.short_6             = dxfDimensionStyle.short_6;
            this.arrowsTextFitType_0 = dxfDimensionStyle.arrowsTextFitType_0;
            this.double_18           = dxfDimensionStyle.double_18;
            this.bool_13             = dxfDimensionStyle.bool_13;
            this.double_19           = dxfDimensionStyle.double_19;
            this.dimensionTextBackgroundFillMode_0 = dxfDimensionStyle.dimensionTextBackgroundFillMode_0;
            this.color_3 = dxfDimensionStyle.color_3;
            this.arcLengthSymbolPosition_0 = dxfDimensionStyle.arcLengthSymbolPosition_0;
            this.textDirection_0           = dxfDimensionStyle.textDirection_0;
            this.double_20 = dxfDimensionStyle.double_20;
            this.string_4  = dxfDimensionStyle.string_4;
            this.double_21 = dxfDimensionStyle.double_21;
            this.string_5  = dxfDimensionStyle.string_5;
        }