Ejemplo n.º 1
0
        private static string DecimalNumberFormat(UnitStyleFormat format)
        {
            char[] zeroes = new char[format.AngularDecimalPlaces + 2];
            if (format.SupressAngularLeadingZeros)
            {
                zeroes[0] = '#';
            }
            else
            {
                zeroes[0] = '0';
            }

            zeroes[1] = '.';

            for (int i = 2; i < zeroes.Length; i++)
            {
                if (format.SupressAngularTrailingZeros)
                {
                    zeroes[i] = '#';
                }
                else
                {
                    zeroes[i] = '0';
                }
            }
            return(new string(zeroes));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in degrees, minutes and seconds.</returns>
        public static string ToDegreesMinutesSeconds(double angle, UnitStyleFormat format)
        {
            double degrees = angle;
            double minutes = (degrees - (int)degrees) * 60;
            double seconds = (minutes - (int)minutes) * 60;

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            if (format.AngularDecimalPlaces == 0)
            {
                return(string.Format(numberFormat, (int)Math.Round(degrees, 0) + format.DegreesSymbol));
            }
            if (format.AngularDecimalPlaces == 1)
            {
                return(string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)Math.Round(minutes, 0) + format.MinutesSymbol));
            }
            if (format.AngularDecimalPlaces == 2)
            {
                return(string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)minutes + format.MinutesSymbol + (int)Math.Round(seconds, 0) + format.SecondsSymbol));
            }
            if (MathHelper.IsZero(seconds))
            {
                return(string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)minutes + format.MinutesSymbol + (int)Math.Round(seconds, 0) + format.SecondsSymbol));
            }

            string f = DecimalNumberFormat(format);

            f = f.Substring(0, f.Length - 2);
            return(string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)minutes + format.MinutesSymbol + seconds.ToString(f, numberFormat) + format.SecondsSymbol));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts a length value into its fractional string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in fractional units.</returns>
        public static string ToFractional(double length, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            int num = (int)length;
            int numerator;
            int denominator;

            GetFraction(length, (short)Math.Pow(2, format.LinearDecimalPlaces), out numerator, out denominator);
            if (numerator == 0)
            {
                return(string.Format("{0}", (int)length));
            }

            string text = string.Empty;

            switch (format.FractionType)
            {
            case FractionFormatType.Diagonal:
                text = "\\A1;" + num + "{\\H" + format.FractionHeightScale + "x;\\S" + numerator + "#" + denominator + ";}";
                break;

            case FractionFormatType.Horizontal:
                text = "\\A1;" + num + "{\\H" + format.FractionHeightScale + "x;\\S" + numerator + "/" + denominator + ";}";
                break;

            case FractionFormatType.NotStacked:
                text = num + " " + numerator + "/" + denominator;
                break;
            }
            return(text);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in degrees, minutes and seconds.</returns>
        public static string ToDegreesMinutesSeconds(double angle, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }

            double degrees = angle;
            double minutes = (degrees - (int)degrees) * 60;
            double seconds = (minutes - (int)minutes) * 60;

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            if (format.AngularDecimalPlaces == 0)
            {
                return(string.Format(numberFormat, "{0}" + format.DegreesSymbol, (int)Math.Round(degrees, 0)));
            }
            if (format.AngularDecimalPlaces == 1 || format.AngularDecimalPlaces == 2)
            {
                return(string.Format(numberFormat, "{0}" + format.DegreesSymbol + "{1}" + format.MinutesSymbol, (int)degrees, (int)Math.Round(minutes, 0)));
            }
            if (format.AngularDecimalPlaces == 3 || format.AngularDecimalPlaces == 4)
            {
                return(string.Format(numberFormat, "{0}" + format.DegreesSymbol + "{1}" + format.MinutesSymbol + "{2}" + format.SecondsSymbol, (int)degrees, (int)minutes, (int)Math.Round(seconds, 0)));
            }
            // the suppression of leading or trailing zeros is not applicable to DegreesMinutesSeconds angles format
            string f = "0." + new string('0', format.AngularDecimalPlaces - 4);

            return(string.Format(numberFormat, "{0}" + format.DegreesSymbol + "{1}" + format.MinutesSymbol + "{2}" + format.SecondsSymbol, (int)degrees, (int)minutes, seconds.ToString(f, numberFormat)));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts an angle value in degrees into its gradians string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in gradians.</returns>
        public static string ToGradians(double angle, UnitStyleFormat format)
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return((angle * MathHelper.DegToGrad).ToString(DecimalNumberFormat(format), numberFormat) + format.GradiansSymbol);
        }
 /// <summary>
 /// Converts an angle value in degrees into its gradians string representation.
 /// </summary>
 /// <param name="angle">The angle value in degrees.</param>
 /// <param name="format">The unit style format.</param>
 /// <returns>A string that represents the angle in gradians.</returns>
 public static string ToGradians(double angle, UnitStyleFormat format)
 {
     NumberFormatInfo numberFormat = new NumberFormatInfo
     {
         NumberDecimalSeparator = format.DecimalSeparator
     };
     
     return (angle * MathHelper.DegToGrad).ToString(DecimalNumberFormat(format), numberFormat) + format.GradiansSymbol;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Converts a length value into its decimal string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in decimal units.</returns>
        public static string ToDecimal(double length, UnitStyleFormat format)
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return length.ToString(DecimalNumberFormat(format), numberFormat);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts a length value into its decimal string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in decimal units.</returns>
        public static string ToDecimal(double length, UnitStyleFormat format)
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return(length.ToString(DecimalNumberFormat(format), numberFormat));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts an angle value in degrees into its decimal string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in decimal units.</returns>
        public static string ToDecimal(double angle, UnitStyleFormat format)
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return angle.ToString(DecimalNumberFormat(format), numberFormat) + format.DegreesSymbol;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Converts an angle value in degrees into its decimal string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in decimal units.</returns>
        public static string ToDecimal(double angle, UnitStyleFormat format)
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return(angle.ToString(DecimalNumberFormat(format), numberFormat) + format.DegreesSymbol);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Converts an angle value in degrees into its decimal string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in decimal units.</returns>
        public static string ToDecimal(double angle, UnitStyleFormat format)
        {
            if (format == null)
                throw new ArgumentNullException(nameof(format));

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return angle.ToString(DecimalNumberFormat(format), numberFormat) + format.DegreesSymbol;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Converts a length value into its decimal string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in decimal units.</returns>
        public static string ToDecimal(double length, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            NumberFormatInfo numberFormat = new NumberFormatInfo {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return(length.ToString(DecimalNumberFormat(format), numberFormat));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Converts an angle value in degrees into its gradians string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in gradians.</returns>
        public static string ToGradians(double angle, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            NumberFormatInfo numberFormat = new NumberFormatInfo {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return((angle * MathHelper.DegToGrad).ToString(DecimalNumberFormat(format), numberFormat) + format.GradiansSymbol);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Converts a length value into its feet and decimal inches string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in feet and decimal inches.</returns>
        /// <remarks>The Engineering format assumes that each drawing unit represents one inch.</remarks>
        public static string ToEngineering(double length, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };
            int    feet   = (int)(length / 12);
            double inches = length - 12 * feet;

            if (MathHelper.IsZero(inches))
            {
                if (feet == 0)
                {
                    if (format.SuppressZeroFeet)
                    {
                        return(string.Format("0{0}", format.InchesSymbol));
                    }

                    if (format.SuppressZeroInches)
                    {
                        return(string.Format("0{0}", format.FeetSymbol));
                    }
                    return(string.Format("0{0}{1}0{2}", format.FeetSymbol, format.FeetInchesSeparator, format.InchesSymbol));
                }

                if (format.SuppressZeroInches)
                {
                    return(string.Format("{0}{1}", feet, format.FeetSymbol));
                }

                return(string.Format("{0}{1}{2}0{3}", feet, format.FeetSymbol, format.FeetInchesSeparator, format.InchesSymbol));
            }

            string inchesDec = inches.ToString(DecimalNumberFormat(format), numberFormat);

            if (feet == 0)
            {
                if (format.SuppressZeroFeet)
                {
                    return(string.Format("{0}{1}", inches, format.InchesSymbol));
                }

                return(string.Format("0{0}{1}{2}{3}", format.FeetSymbol, format.FeetInchesSeparator, inchesDec, format.InchesSymbol));
            }
            return(string.Format("{0}{1}{2}{3}{4}", feet, format.FeetSymbol, format.FeetInchesSeparator, inchesDec, format.InchesSymbol));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Converts an angle value in degrees into its decimal string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in decimal units.</returns>
        public static string ToDecimal(double angle, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return(angle.ToString(DecimalNumberFormat(format), numberFormat) + format.DegreesSymbol);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Converts a length value into its feet and decimal inches string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in feet and decimal inches.</returns>
        /// <remarks>The Engineering format assumes that each drawing unit represents one inch.</remarks>
        public static string ToEngineering(double length, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };
            int    feet   = (int)(length / 12);
            double inches = length - 12 * feet;

            if (MathHelper.IsZero(inches))
            {
                if (feet == 0)
                {
                    if (format.SupressZeroFeet)
                    {
                        return("0" + format.InchesSymbol);
                    }
                    if (format.SupressZeroInches)
                    {
                        return("0" + format.FeetSymbol);
                    }
                    return("0" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol);
                }
                if (format.SupressZeroInches)
                {
                    return(string.Format("{0}" + format.FeetSymbol, feet));
                }

                return(string.Format("{0}" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol, feet));
            }

            string feetStr = feet + format.FeetSymbol + format.FeetInchesSeparator;

            if (format.SupressZeroFeet && feet == 0)
            {
                feetStr = string.Empty;
            }

            return(string.Format(numberFormat, feetStr + "{0}" + format.InchesSymbol, inches.ToString(DecimalNumberFormat(format), numberFormat)));
        }
        /// <summary>
        /// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in degrees, minutes and seconds.</returns>
        public static string ToDegreesMinutesSeconds(double angle, UnitStyleFormat format)
        {
            double degrees = angle;
            double minutes = (degrees - (int)degrees) * 60;
            double seconds = (minutes - (int)minutes) * 60;

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            if(format.AngularDecimalPlaces == 0)
                return string.Format(numberFormat, "{0}" + format.DegreesSymbol, (int)Math.Round(degrees, 0));
            if (format.AngularDecimalPlaces == 1 || format.AngularDecimalPlaces == 2)
                return string.Format(numberFormat, "{0}" + format.DegreesSymbol + "{1}" + format.MinutesSymbol, (int)degrees, (int)Math.Round(minutes, 0));
            if (format.AngularDecimalPlaces == 3 || format.AngularDecimalPlaces == 4)
                return string.Format(numberFormat, "{0}" + format.DegreesSymbol + "{1}" + format.MinutesSymbol + "{2}" + format.SecondsSymbol, (int)degrees, (int)minutes, (int)Math.Round(seconds, 0));
            // the suppression of leading or trailing zeros is not applicable to DegreesMinutesSeconds angles format
            string f = "0." + new string('0', format.AngularDecimalPlaces - 4);
            return string.Format(numberFormat, "{0}" + format.DegreesSymbol + "{1}" + format.MinutesSymbol + "{2}" + format.SecondsSymbol, (int)degrees, (int)minutes, seconds.ToString(f, numberFormat));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in degrees, minutes and seconds.</returns>
        public static string ToDegreesMinutesSeconds(double angle, UnitStyleFormat format)
        {
            double degrees = angle;
            double minutes = (degrees - (int)degrees) * 60;
            double seconds = (minutes - (int)minutes) * 60;

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            if(format.AngularDecimalPlaces == 0)
                return string.Format(numberFormat, (int)Math.Round(degrees, 0) + format.DegreesSymbol);
            if (format.AngularDecimalPlaces == 1)
                return string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)Math.Round(minutes, 0) + format.MinutesSymbol);
            if (format.AngularDecimalPlaces == 2)
                return string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)minutes + format.MinutesSymbol + (int)Math.Round(seconds, 0) + format.SecondsSymbol);
            if(MathHelper.IsZero(seconds))
                return string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)minutes + format.MinutesSymbol + (int)Math.Round(seconds, 0) + format.SecondsSymbol);

            string f = DecimalNumberFormat(format);
            f = f.Substring(0, f.Length - 2);
            return string.Format(numberFormat, (int)degrees + format.DegreesSymbol + (int)minutes + format.MinutesSymbol + seconds.ToString(f, numberFormat) + format.SecondsSymbol);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Converts a length value into its scientific string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in scientific units.</returns>
        public static string ToScientific(double length, UnitStyleFormat format)
        {
            if (format == null)
                throw new ArgumentNullException(nameof(format));

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return length.ToString(DecimalNumberFormat(format) + "E+00", numberFormat);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Converts a length value into its feet and decimal inches string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in feet and decimal inches.</returns>
        /// <remarks>The Engineering format assume that each drawing unit represents one inch.</remarks>
        public static string ToEngineering(double length, UnitStyleFormat format)
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };
            int feet = (int)(length / 12);
            double inches = length - 12 * feet;

            if (MathHelper.IsZero(inches))
            {
                if (feet == 0)
                {
                    if (format.SupressZeroFeet)
                        return "0" + format.InchesSymbol;
                    if (format.SupressZeroInches)
                        return "0" + format.FeetSymbol;
                    return "0" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol;
                }
                if (format.SupressZeroInches)
                    return string.Format("{0}" + format.FeetSymbol, feet);

                return string.Format("{0}" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol, feet);
            }

            string feetStr = feet + format.FeetSymbol + format.FeetInchesSeparator;
            if (format.SupressZeroFeet && feet == 0) feetStr = string.Empty;

            return string.Format(numberFormat, feetStr + inches.ToString(DecimalNumberFormat(format), numberFormat) + format.InchesSymbol);
        }
Ejemplo n.º 21
0
        private static string DecimalNumberFormat(UnitStyleFormat format)
        {
            char[] zeroes = new char[format.AngularDecimalPlaces + 2];
            if (format.SupressAngularLeadingZeros)
                zeroes[0] = '#';
            else
                zeroes[0] = '0';

            zeroes[1] = '.';

            for (int i = 2; i < zeroes.Length; i++)
            {
                if (format.SupressAngularTrailingZeros)
                    zeroes[i] = '#';
                else
                    zeroes[i] = '0';
            }
            return new string(zeroes);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Converts a length value into its fractional string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in fractional units.</returns>
        public static string ToFractional(double length, UnitStyleFormat format)
        {
            int num = (int)length;
            int numerator;
            int denominator;
            GetFraction(length, (short)Math.Pow(2, format.LinearDecimalPlaces), out numerator, out denominator);
            if (numerator == 0)
                return string.Format("{0}", (int)length);

            string text = string.Empty;
            switch (format.FractionType)
            {
                case FractionFormatType.Diagonal:
                    text = "\\A1;" + num + "{\\H1.0x;\\S" + numerator + "#" + denominator + ";}";
                    break;
                case FractionFormatType.Horizontal:
                    text = "\\A1;" + num + "{\\H1.0x;\\S" + numerator + "/" + denominator + ";}";
                    break;
                case FractionFormatType.NotStacked:
                    text = num + " " + numerator + "/" + denominator;
                    break;
            }
            return text;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Converts a length value into its feet and fractional inches string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in feet and fractional inches.</returns>
        /// <remarks>The Architectural format assume that each drawing unit represents one inch.</remarks>
        public static string ToArchitectural(double length, UnitStyleFormat format)
        {
            int feet = (int)(length / 12);
            double inchesDec = length - 12 * feet;
            int inches = (int)inchesDec;

            if (MathHelper.IsZero(inchesDec))
            {
                if (feet == 0)
                {
                    if(format.SupressZeroFeet)
                        return "0" + format.InchesSymbol;
                    if (format.SupressZeroInches)
                        return "0" + format.FeetSymbol;
                    return "0" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol;
                }
                if(format.SupressZeroInches)
                    return string.Format("{0}" + format.FeetSymbol, feet);
                
                return string.Format("{0}" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol, feet);
            }

            int numerator;
            int denominator;
            GetFraction(inchesDec, (short)Math.Pow(2, format.LinearDecimalPlaces), out numerator, out denominator);

            if (numerator == 0)
            {
                if (inches == 0)
                {
                    if (feet == 0)
                    {
                        if (format.SupressZeroFeet)
                            return "0" + format.InchesSymbol;
                        if (format.SupressZeroInches)
                            return "0" + format.FeetSymbol;
                        return "0" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol;
                    }
                    if (format.SupressZeroInches)
                        return string.Format("{0}" + format.FeetSymbol, feet);

                    return string.Format("{0}" + format.FeetSymbol + format.FeetInchesSeparator + "0" + format.InchesSymbol, feet);
                }
                if (feet == 0)
                {
                    if (format.SupressZeroFeet)
                        return string.Format("{0}" + format.InchesSymbol, inches);
                    return string.Format("0" + format.FeetSymbol + format.FeetInchesSeparator + "{0}" + format.InchesSymbol, inches);
                }
                return string.Format("{0}" + format.FeetSymbol + format.FeetInchesSeparator + "{0}" + format.InchesSymbol, feet, inches);
            }

            string text = string.Empty;
            string feetStr = feet + format.FeetSymbol + format.FeetInchesSeparator;
            if (format.SupressZeroFeet && feet == 0) feetStr = string.Empty;
            switch (format.FractionType)
            {
                case FractionFormatType.Diagonal:
                    text = "\\A1;" + feetStr + inches + "{\\H1.0x;\\S" + numerator + "#" + denominator + ";}" + format.InchesSymbol;
                    break;
                case FractionFormatType.Horizontal:
                    text = "\\A1;" + feetStr + inches + "{\\H1.0x;\\S" + numerator + "/" + denominator + ";}" + format.InchesSymbol;
                    break;
                case FractionFormatType.NotStacked:
                    text = feetStr + inches + " " + numerator + "/" + denominator + format.InchesSymbol;
                    break;
            }
            return text;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Converts an angle value in degrees into its gradians string representation.
        /// </summary>
        /// <param name="angle">The angle value in degrees.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the angle in gradians.</returns>
        public static string ToGradians(double angle, UnitStyleFormat format)
        {
            if (format == null)
                throw new ArgumentNullException(nameof(format));

            NumberFormatInfo numberFormat = new NumberFormatInfo
            {
                NumberDecimalSeparator = format.DecimalSeparator
            };

            return (angle*MathHelper.DegToGrad).ToString(DecimalNumberFormat(format), numberFormat) + format.GradiansSymbol;
        }
Ejemplo n.º 25
0
        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.LengthPrecision,
                AngularDecimalPlaces = style.AngularPrecision == -1 ? style.LengthPrecision : style.AngularPrecision,
                DecimalSeparator = style.DecimalSeparator.ToString(),
                FractionType = style.FractionalType,
                SupressLinearLeadingZeros = style.SuppressLinearLeadingZeros,
                SupressLinearTrailingZeros = style.SuppressLinearTrailingZeros,
                SupressAngularLeadingZeros = style.SuppressAngularLeadingZeros,
                SupressAngularTrailingZeros = style.SuppressAngularTrailingZeros,
                SupressZeroFeet = style.SuppressZeroFeet,
                SupressZeroInches = style.SuppressZeroInches
            };

            if (angular)
            {
                switch (style.DimAngularUnits)
                {
                    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.DimScaleLinear);
                if (layout != null)
                {
                    // if DIMLFAC is negative the scale value is only applied to dimensions in PaperSpace
                    if (style.DimScaleLinear < 0 && !layout.IsPaperSpace)
                        scale = 1.0;
                }

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

                switch (style.DimLengthUnits)
                {
                    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.DimScaleLinear, unitFormat);
                        break;
                }
            }
            text = string.Format("{0}{1}{2}", style.DimPrefix, text, style.DimSuffix);

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

            return text;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Converts a length value into its feet and fractional inches string representation.
        /// </summary>
        /// <param name="length">The length value.</param>
        /// <param name="format">The unit style format.</param>
        /// <returns>A string that represents the length in feet and fractional inches.</returns>
        /// <remarks>The Architectural format assumes that each drawing unit represents one inch.</remarks>
        public static string ToArchitectural(double length, UnitStyleFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            int    feet      = (int)(length / 12);
            double inchesDec = length - 12 * feet;
            int    inches    = (int)inchesDec;

            if (MathHelper.IsZero(inchesDec))
            {
                if (feet == 0)
                {
                    if (format.SupressZeroFeet)
                    {
                        return(string.Format("0{0}", format.InchesSymbol));
                    }
                    if (format.SupressZeroInches)
                    {
                        return(string.Format("0{0}", format.FeetSymbol));
                    }

                    return(string.Format("0{0}{1}0{2}", format.FeetSymbol, format.FeetInchesSeparator, format.InchesSymbol));
                }
                if (format.SupressZeroInches)
                {
                    return(string.Format("{0}{1}", feet, format.FeetSymbol));
                }

                return(string.Format("{0}{1}{2}0{3}", feet, format.FeetSymbol, format.FeetInchesSeparator, format.InchesSymbol));
            }

            int numerator;
            int denominator;

            GetFraction(inchesDec, (short)Math.Pow(2, format.LinearDecimalPlaces), out numerator, out denominator);

            if (numerator == 0)
            {
                if (inches == 0)
                {
                    if (feet == 0)
                    {
                        if (format.SupressZeroFeet)
                        {
                            return(string.Format("0{0}", format.InchesSymbol));
                        }
                        if (format.SupressZeroInches)
                        {
                            return(string.Format("0{0}", format.FeetSymbol));
                        }

                        return(string.Format("0{0}{1}0{2}", format.FeetSymbol, format.FeetInchesSeparator, format.InchesSymbol));
                    }
                    if (format.SupressZeroInches)
                    {
                        return(string.Format("{0}{1}", feet, format.FeetSymbol));
                    }

                    return(string.Format("{0}{1}{2}0{3}", feet, format.FeetSymbol, format.FeetInchesSeparator, format.InchesSymbol));
                }
                if (feet == 0)
                {
                    if (format.SupressZeroFeet)
                    {
                        return(string.Format("{0}{1}", inches, format.InchesSymbol));
                    }

                    return(string.Format("0{0}{1}{2}{3}", format.FeetSymbol, format.FeetInchesSeparator, inches, format.InchesSymbol));
                }

                return(string.Format("{0}{1}{2}{3}{4}", feet, format.FeetSymbol, format.FeetInchesSeparator, inches, format.InchesSymbol));
            }

            string text = string.Empty;
            string feetStr;

            if (format.SupressZeroFeet && feet == 0)
            {
                feetStr = string.Empty;
            }
            else
            {
                feetStr = feet + format.FeetSymbol + format.FeetInchesSeparator;
            }
            switch (format.FractionType)
            {
            case FractionFormatType.Diagonal:
                text = "\\A1;" + feetStr + inches + "{\\H" + format.FractionHeightScale + "x;\\S" + numerator + "#" + denominator + ";}" + format.InchesSymbol;
                break;

            case FractionFormatType.Horizontal:
                text = "\\A1;" + feetStr + inches + "{\\H" + format.FractionHeightScale + "x;\\S" + numerator + "/" + denominator + ";}" + format.InchesSymbol;
                break;

            case FractionFormatType.NotStacked:
                text = feetStr + inches + " " + numerator + "/" + denominator + format.InchesSymbol;
                break;
            }
            return(text);
        }