Exemplo n.º 1
0
        /// <summary>
        /// 获得一个单位占据的英寸数
        /// </summary>
        /// <param name="unit">单位类型</param>
        /// <returns>英寸数</returns>
        public static double GetUnit(LengthUnit unit)
        {
            switch (unit)
            {
            case LengthUnit.Document:
                return(1 / 300.0);

            case LengthUnit.Inch:
                return(1);

            case LengthUnit.Millimeter:
                return(1 / 25.4);

            case LengthUnit.Pixel:
                return(1 / fDpi);

            case LengthUnit.Point:
                return(1 / 72.0);

            case LengthUnit.Centimerter:
                return(1 / 2.54);

            case LengthUnit.Twips:
                return(1 / 1440.0);

            default:
                throw new System.NotSupportedException("Not support " + unit.ToString());
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取单位的多语言描述
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 public static string GetName(this LengthUnit unit)
 {
     if (UnitNameDict.ContainsKey(unit))
     {
         return(UnitNameDict[unit].GetValue());
     }
     return(unit.ToString());
 }
 protected void ToString(List <string> toStringOutput)
 {
     toStringOutput.Add($"CustomUnit = {(CustomUnit == null ? "null" : CustomUnit.ToString())}");
     toStringOutput.Add($"AreaUnit = {(AreaUnit == null ? "null" : AreaUnit.ToString())}");
     toStringOutput.Add($"LengthUnit = {(LengthUnit == null ? "null" : LengthUnit.ToString())}");
     toStringOutput.Add($"VolumeUnit = {(VolumeUnit == null ? "null" : VolumeUnit.ToString())}");
     toStringOutput.Add($"WeightUnit = {(WeightUnit == null ? "null" : WeightUnit.ToString())}");
     toStringOutput.Add($"GenericUnit = {(GenericUnit == null ? "null" : GenericUnit.ToString())}");
     toStringOutput.Add($"TimeUnit = {(TimeUnit == null ? "null" : TimeUnit.ToString())}");
     toStringOutput.Add($"Type = {(Type == null ? "null" : Type.ToString())}");
 }
Exemplo n.º 4
0
        public static GBXMLUnitSetUp GBXMLUnitSetUp(LengthUnit length, TemperatureUnit temperature = TemperatureUnit.Celcius)
        {
            string type = length.ToString();

            return(new GBXMLUnitSetUp
            {
                LengthUnit = length,
                AreaUnit = (AreaUnit)Enum.Parse(typeof(AreaUnit), "Square" + type),
                TemperatureUnit = temperature,
                VolumeUnit = (VolumeUnit)Enum.Parse(typeof(VolumeUnit), "Cubic" + type),
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// 返回相对于米的进阶,即换算基数。
        /// </summary>
        /// <param name="unit"></param>
        /// <returns></returns>
        static decimal Get_M_Base(LengthUnit unit)
        {
            int unitInt = (int)unit;

            if (unitInt >= 0 && unitInt <= 99)
            {
                return(M_Series_To_M_Base[unitInt]);
            }
            unitInt = unitInt - 100;
            if (unitInt >= 0 && unitInt <= 99)
            {
                return(Inch_Series_To_M_Base[unitInt]);
            }
            throw new NotImplementedException(string.Format("没有实现单位:{0}的换算", unit.ToString()));
        }
        static Label GetLengthLabel(LengthUnit unit)
        {
            Label lbl = new Label();

            switch (unit)
            {
            case LengthUnit.Pixel:
                lbl.text = "px";
                break;

            default:
                lbl.text = unit.ToString();
                break;
            }
            return(lbl);
        }
Exemplo n.º 7
0
        private void WriteCalibrationHelp(XmlTextWriter w)
        {
            bool       line       = random.NextBoolean();
            Array      values     = Enum.GetValues(typeof(LengthUnit));
            LengthUnit lengthUnit = (LengthUnit)values.GetValue(random.Next(values.Length));

            w.WriteStartElement("Calibration");

            if (line)
            {
                PointF origin = random.NextPointF(0, imageSize.Width, 0, imageSize.Height);
                float  scale  = (float)(random.NextDouble() * 50);

                w.WriteStartElement("CalibrationLine");
                w.WriteElementString("Origin", XmlHelper.WritePointF(origin));
                w.WriteElementString("Scale", string.Format(CultureInfo.InvariantCulture, "{0}", scale));
                w.WriteEndElement();
            }
            else
            {
                SizeF          calibrationSize = random.NextSizeF(1, 100, 1, 100);
                QuadrilateralF quad            = GetRandomQuadrilateral();
                PointF         origin          = new PointF(0, calibrationSize.Height);

                w.WriteStartElement("CalibrationPlane");

                w.WriteElementString("Size", XmlHelper.WriteSizeF(calibrationSize));

                w.WriteStartElement("Quadrilateral");
                w.WriteElementString("A", XmlHelper.WritePointF(quad.A));
                w.WriteElementString("B", XmlHelper.WritePointF(quad.B));
                w.WriteElementString("C", XmlHelper.WritePointF(quad.C));
                w.WriteElementString("D", XmlHelper.WritePointF(quad.D));
                w.WriteEndElement();

                w.WriteElementString("Origin", XmlHelper.WritePointF(origin));

                w.WriteEndElement();
            }

            w.WriteStartElement("Unit");
            w.WriteAttributeString("Abbreviation", UnitHelper.LengthAbbreviation(lengthUnit));
            w.WriteString(lengthUnit.ToString());
            w.WriteEndElement();

            w.WriteEndElement();
        }
Exemplo n.º 8
0
        public void WriteXml(XmlWriter w)
        {
            if (calibratorType == CalibratorType.Line)
            {
                w.WriteStartElement("CalibrationLine");
                calibrationLine.WriteXml(w);
                w.WriteEndElement();
            }
            else if (calibratorType == CalibratorType.Plane)
            {
                w.WriteStartElement("CalibrationPlane");
                calibrationPlane.WriteXml(w);
                w.WriteEndElement();
            }

            w.WriteStartElement("Unit");
            w.WriteAttributeString("Abbreviation", GetLengthAbbreviation());
            w.WriteString(lengthUnit.ToString());
            w.WriteEndElement();

            DistortionSerializer.Serialize(w, distortionHelper.Parameters, false, imageSize);
        }
Exemplo n.º 9
0
        public string ToString(CultureInfo ci)
        {
            string tz;

            if (UseLocalTime)
            {
                tz = WxDateUnit.TimeZoneName(true, 0);
            }
            else
            {
                tz = UtcOffset.ToString(ci);
            }
            string sep = ci.TextInfo.ListSeparator;

            return(string.Format(CultureInfo.InvariantCulture,
                                 "{0}{8}{1}{8}{2}{8}{3}{8}{4}{8}{5}{8}{6}{8}{7}",
                                 tz, Temperature.ToString(),
                                 TemperatureRate.ToString(),
                                 Pressure.ToString(), Wind.ToString(),
                                 Rain.ToString(), RainRate.ToString(),
                                 "", sep));
        }
        private double _convertValueTo(LengthUnit units)
        {
            switch (units)
            {
            case LengthUnit.Yoctometers:
                return(ToMeters() * Math.Pow(10, 24));

            case LengthUnit.Zeptometers:
                return(ToMeters() * Math.Pow(10, 21));

            case LengthUnit.Attometers:
                return(ToMeters() * Math.Pow(10, 18));

            case LengthUnit.Femtometers:
                return(ToMeters() * Math.Pow(10, 15));

            case LengthUnit.Picometers:
                return(ToMeters() * Math.Pow(10, 12));

            case LengthUnit.Nanometers:
                return(ToNanometers());

            case LengthUnit.Micrometers:
                return(ToMicrometers());

            case LengthUnit.Millimeters:
                return(ToMillimeters());

            case LengthUnit.Centimeters:
                return(ToCentimeters());

            case LengthUnit.Meters:
                return(ToMeters());

            case LengthUnit.Dekameters:
                return(ToMeters() / Math.Pow(10, 1));

            case LengthUnit.Hectometers:
                return(ToMeters() / Math.Pow(10, 2));

            case LengthUnit.Kilometers:
                return(ToMeters() / Math.Pow(10, 3));

            case LengthUnit.Megameters:
                return(ToMeters() / Math.Pow(10, 6));

            case LengthUnit.Gigameters:
                return(ToMeters() / Math.Pow(10, 9));

            case LengthUnit.Terameters:
                return(ToMeters() / Math.Pow(10, 12));

            case LengthUnit.Petameters:
                return(ToMeters() / Math.Pow(10, 15));

            case LengthUnit.Exameters:
                return(ToMeters() / Math.Pow(10, 18));

            case LengthUnit.Zettameters:
                return(ToMeters() / Math.Pow(10, 21));

            case LengthUnit.Yottameters:
                return(ToMeters() / Math.Pow(10, 24));

            case LengthUnit.Inches:
                return(ToInches());

            case LengthUnit.Hands:
                return(ToFeet() * 3.0);

            case LengthUnit.Feet:
                return(ToFeet());

            case LengthUnit.Yards:
                return(ToFeet() / 3.0);

            case LengthUnit.Fathoms:
                return(ToFeet() / 6.0);

            case LengthUnit.Perch:
                return(ToFeet() / 16.5);

            case LengthUnit.Poles:
                return(_convertValueTo(LengthUnit.Rods));

            case LengthUnit.Rods:
                return(ToFeet() / 5.5);

            case LengthUnit.Chains:
                return(ToFeet() / 66.0);

            case LengthUnit.Furlongs:
                return(_convertValueTo(LengthUnit.Rods) / 40.0);

            case LengthUnit.Miles:
                return(_convertValueTo(LengthUnit.Furlongs) / 8.0);

            case LengthUnit.Leagues:
                return(_convertValueTo(LengthUnit.Miles) / 3.0);

            case LengthUnit.Angstrom:
                return(ToInches() * 3.9 * Math.Pow(10, -5));

            case LengthUnit.NauticalMiles:
                return(_convertValueTo(LengthUnit.Kilometers) / 1.9);

            case LengthUnit.LightYears:
                return(_convertValueTo(LengthUnit.AstronomicalUnits) / 63000.0);

            case LengthUnit.AstronomicalUnits:
                return(_convertValueTo(LengthUnit.Kilometers) / 150000000.0);

            case LengthUnit.PlankLength:
                return(ToNanometers() * 6.25e+25);

            default:
                throw new ArgumentException("Invalid units: " + units.ToString());
            }
        }
Exemplo n.º 11
0
 public void SetLengthUnit(LengthUnit lengthUnit)
 {
     ConvToMicron = dictionary.ConversionToUM(lengthUnit);
     Name         = lengthUnit.ToString();
     LengthUnits  = lengthUnit;
 }
Exemplo n.º 12
0
 public void SetDistanceUnit(LengthUnit unit) => Preferences.Set(PreferenceKeys.DistanceUnit, unit.ToString());
Exemplo n.º 13
0
 public MeasurementUnit(LengthUnit lengthUnit)
 {
     ConversionFactor = MeasurementUnitDictionary.ConversionToMM(lengthUnit);
     Name             = lengthUnit.ToString();
     LengthUnits      = lengthUnit;
 }