namespace IStation.Unit
|
{
|
/// <summary>
|
/// 扬程单位辅助类
|
/// </summary>
|
public class UnitHHelper : IUnitHelper
|
{
|
|
#region 静态
|
|
public static double fromM(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return value;
|
case eUnitH.MPa:
|
return M2MPa_calc.Calc(value);
|
case eUnitH.KPa:
|
return M2KPa_calc.Calc(value);
|
case eUnitH.Pa:
|
return M2Pa_calc.Calc(value);
|
case eUnitH.Ft:
|
return M2Ft_calc.Calc(value);
|
case eUnitH.Psi:
|
return M2Psi_calc.Calc(value);
|
case eUnitH.Bar:
|
return M2Bar_calc.Calc(value);
|
case eUnitH.kgf_cm2:
|
return M2kgf_cm2_calc.Calc(value);
|
case eUnitH.kgf_m2:
|
return M2kgf_m2_calc.Calc(value);
|
default:
|
return value;
|
}
|
}
|
public static double fromM2(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return value;
|
|
case eUnitH.MPa:
|
return M2MPa_calc2.Calc(value);
|
case eUnitH.KPa:
|
return M2KPa_calc2.Calc(value);
|
case eUnitH.Pa:
|
return M2Pa_calc2.Calc(value);
|
case eUnitH.Bar:
|
return M2Bar_calc2.Calc(value);
|
|
default:
|
return fromM(unit, value);
|
}
|
}
|
|
public static double fromMPa(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return M2MPa_calc.Calc(value);
|
|
case eUnitH.MPa:
|
return value;
|
|
default:
|
{
|
var m = toM(eUnitH.MPa, value);
|
return fromM(unit, m);
|
}
|
|
}
|
}
|
|
public static decimal toMPa(eUnitH unit, decimal value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return System.Convert.ToDecimal(M2MPa_calc.Calc(System.Convert.ToDouble(value)));
|
|
case eUnitH.MPa:
|
return value;
|
|
default:
|
{
|
var m = toM(unit, System.Convert.ToDouble(value));
|
return System.Convert.ToDecimal(M2MPa_calc.Calc(m));
|
}
|
}
|
}
|
public static double toMPa(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return M2MPa_calc.Calc(value);
|
|
case eUnitH.MPa:
|
return value;
|
|
default:
|
{
|
var m = toM(unit, value);
|
return M2MPa_calc.Calc(m);
|
}
|
}
|
}
|
|
public static decimal toMPa2(eUnitH unit, decimal value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return System.Convert.ToDecimal(M2MPa_calc2.Calc(System.Convert.ToDouble(value)));
|
|
case eUnitH.MPa:
|
return value;
|
|
default:
|
{
|
var m = toM(unit, value);
|
return System.Convert.ToDecimal(M2MPa_calc2.Calc(System.Convert.ToDouble(value)));
|
}
|
}
|
}
|
public static double toMPa2(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return M2MPa_calc2.Calc(value);
|
|
case eUnitH.MPa:
|
return value;
|
|
default:
|
{
|
var m = toM(unit, value);
|
return M2MPa_calc2.Calc(value);
|
}
|
}
|
}
|
|
|
|
public static decimal toM(eUnitH unit, decimal value)
|
{
|
return System.Convert.ToDecimal(toM(unit, System.Convert.ToDouble(value)));
|
}
|
|
public static double toM(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return value;
|
case eUnitH.MPa:
|
return MPa2M_calc.Calc(value);
|
case eUnitH.Bar:
|
return Bar2M_calc.Calc(value);
|
case eUnitH.KPa:
|
return KPa2M_calc.Calc(value);
|
case eUnitH.Pa:
|
return KPa2M_calc.Calc(value) * 0.001;
|
case eUnitH.Ft:
|
return Ft2M_calc.Calc(value);
|
case eUnitH.Psi:
|
return Psi2M_calc.Calc(value);
|
case eUnitH.kgf_cm2:
|
return Kgf_cm2M_calc.Calc(value);
|
case eUnitH.kgf_m2:
|
return Kgf_m2M_calc.Calc(value);
|
default:
|
return 0;
|
}
|
}
|
|
public static double toM2(eUnitH unit, double value)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return value;
|
case eUnitH.MPa:
|
return MPa2M_calc2.Calc(value);
|
case eUnitH.Bar:
|
return Bar2M_calc2.Calc(value);
|
case eUnitH.KPa:
|
return KPa2M_calc2.Calc(value);
|
case eUnitH.Pa:
|
return Pa2M_calc2.Calc(value);
|
|
default:
|
return toM(unit, value);
|
}
|
}
|
|
public static double Tran(eUnitH from, eUnitH to, double value)
|
{
|
if (from == to)
|
return value;
|
var mm = toM2(from, value);
|
return fromM2(to, mm);
|
}
|
|
public static CoefficientAxis toM(eUnitH unit)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return constantAxis;
|
case eUnitH.MPa:
|
return MPa2M_calc;
|
case eUnitH.Bar:
|
return Bar2M_calc;
|
case eUnitH.KPa:
|
return KPa2M_calc;
|
case eUnitH.Ft:
|
return Ft2M_calc;
|
case eUnitH.Pa:
|
return Pa2M_calc;
|
case eUnitH.Psi:
|
return Psi2M_calc;
|
case eUnitH.kgf_cm2:
|
return Kgf_cm2M_calc;
|
case eUnitH.kgf_m2:
|
return Kgf_m2M_calc;
|
default:
|
return constantAxis;
|
}
|
}
|
|
public static CoefficientAxis fromM(eUnitH unit)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return constantAxis;
|
case eUnitH.MPa:
|
return M2MPa_calc;
|
case eUnitH.Bar:
|
return Bar2M_calc;
|
case eUnitH.KPa:
|
return M2KPa_calc;
|
case eUnitH.Pa:
|
return M2Pa_calc;
|
case eUnitH.Ft:
|
return M2Ft_calc;
|
case eUnitH.Psi:
|
return M2Psi_calc;
|
case eUnitH.kgf_cm2:
|
return M2kgf_cm2_calc;
|
case eUnitH.kgf_m2:
|
return M2kgf_m2_calc;
|
default:
|
return constantAxis;
|
}
|
}
|
|
public static CoefficientAxis toM2(eUnitH unit)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return constantAxis;
|
case eUnitH.MPa:
|
return MPa2M_calc2;
|
case eUnitH.Bar:
|
return Bar2M_calc2;
|
case eUnitH.KPa:
|
return KPa2M_calc2;
|
case eUnitH.Pa:
|
return Pa2M_calc2;
|
default:
|
return toM(unit);
|
}
|
}
|
|
public static CoefficientAxis fromM2(eUnitH unit)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return constantAxis;
|
case eUnitH.MPa:
|
return M2MPa_calc2;
|
case eUnitH.Bar:
|
return Bar2M_calc2;
|
case eUnitH.KPa:
|
return M2KPa_calc2;
|
case eUnitH.Pa:
|
return M2Pa_calc2;
|
|
default:
|
return fromM(unit);
|
}
|
}
|
public static double Convert(eUnitH fromUnit, eUnitH toUnit, double fromValue)
|
{
|
if (fromUnit == toUnit)
|
return fromValue;
|
double m = toM(fromUnit, fromValue);
|
return fromM(toUnit, m);
|
}
|
|
public static string GetCnUnitName(eUnitH unit)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return "米";
|
case eUnitH.MPa:
|
return "兆帕";
|
case eUnitH.KPa:
|
return "千帕";
|
case eUnitH.Bar:
|
return "bar";
|
case eUnitH.Ft:
|
return "ft";
|
case eUnitH.Psi:
|
return "psi";
|
case eUnitH.Pa:
|
return "Pa";
|
case eUnitH.kgf_cm2:
|
return "kgf/cm²";
|
case eUnitH.kgf_m2:
|
return "kgf/m²";
|
default:
|
return "";
|
}
|
|
}
|
|
public static List<string> GetCnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
|
{
|
list.Add(GetCnUnitName(item));
|
}
|
return list;
|
}
|
|
public static Dictionary<eUnitH, string> GetCnUnitDict()
|
{
|
var dic = new Dictionary<eUnitH, string>();
|
foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
|
{
|
dic.Add(item, GetCnUnitName(item));
|
}
|
return dic;
|
}
|
|
public static string GetEnUnitName(eUnitH unit)
|
{
|
switch (unit)
|
{
|
case eUnitH.M:
|
return "m";
|
case eUnitH.MPa:
|
return "MPa";
|
case eUnitH.KPa:
|
return "KPa";
|
case eUnitH.Pa:
|
return "Pa";
|
case eUnitH.Ft:
|
return "Ft";
|
case eUnitH.Bar:
|
return "bar";
|
case eUnitH.Psi:
|
return "psi";
|
|
case eUnitH.kgf_cm2:
|
return "kgf/cm²";
|
case eUnitH.kgf_m2:
|
return "kgf/m²";
|
default:
|
return "";
|
}
|
}
|
|
public static List<string> GetEnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
|
{
|
list.Add(GetEnUnitName(item));
|
}
|
return list;
|
}
|
|
public static Dictionary<eUnitH, string> GetEnUnitDict()
|
{
|
var dic = new Dictionary<eUnitH, string>();
|
foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
|
{
|
dic.Add(item, GetEnUnitName(item));
|
}
|
return dic;
|
}
|
|
const double g = 9.81;
|
|
//
|
static CoefficientAxis constantAxis = new IStation.Unit.CoefficientAxis(1.0);
|
//米M ---> *
|
static CoefficientAxis M2MPa_calc = new IStation.Unit.CoefficientAxis(g / 1000);
|
static CoefficientAxis M2KPa_calc = new IStation.Unit.CoefficientAxis(g);
|
static CoefficientAxis M2Pa_calc = new IStation.Unit.CoefficientAxis(g * 1000);
|
static CoefficientAxis M2Bar_calc = new IStation.Unit.CoefficientAxis(g / 100);
|
static CoefficientAxis M2Ft_calc = new IStation.Unit.CoefficientAxis(3.2808399);
|
static CoefficientAxis M2Psi_calc = new IStation.Unit.CoefficientAxis(145 / 102.0);
|
static CoefficientAxis M2kgf_cm2_calc = new IStation.Unit.CoefficientAxis(1);
|
static CoefficientAxis M2kgf_m2_calc = new IStation.Unit.CoefficientAxis(10000);
|
|
//* ---> M
|
static CoefficientAxis MPa2M_calc = new IStation.Unit.CoefficientAxis(1000 / g);
|
static CoefficientAxis KPa2M_calc = new IStation.Unit.CoefficientAxis(1.0 / g);
|
static CoefficientAxis Pa2M_calc = new IStation.Unit.CoefficientAxis(0.001 / g);
|
static CoefficientAxis Ft2M_calc = new IStation.Unit.CoefficientAxis(1.0 / 3.2808399);
|
static CoefficientAxis Bar2M_calc = new IStation.Unit.CoefficientAxis(10);
|
static CoefficientAxis Psi2M_calc = new IStation.Unit.CoefficientAxis(102.0 / 145.0);
|
static CoefficientAxis Kgf_cm2M_calc = new IStation.Unit.CoefficientAxis(1);
|
static CoefficientAxis Kgf_m2M_calc = new IStation.Unit.CoefficientAxis(1.0 / 10000);
|
|
|
//米M ---> * (g = 10)
|
static CoefficientAxis M2MPa_calc2 = new IStation.Unit.CoefficientAxis(0.01);
|
static CoefficientAxis M2KPa_calc2 = new IStation.Unit.CoefficientAxis(10);
|
static CoefficientAxis M2Bar_calc2 = new IStation.Unit.CoefficientAxis(0.1);
|
static CoefficientAxis M2Pa_calc2 = new IStation.Unit.CoefficientAxis(0.01 * 0.001);
|
|
|
//* ---> M (g = 10)
|
static CoefficientAxis MPa2M_calc2 = new IStation.Unit.CoefficientAxis(100);
|
static CoefficientAxis KPa2M_calc2 = new IStation.Unit.CoefficientAxis(0.1);
|
static CoefficientAxis Pa2M_calc2 = new IStation.Unit.CoefficientAxis(0.001 / 10);
|
static CoefficientAxis Bar2M_calc2 = new IStation.Unit.CoefficientAxis(10.0);
|
#endregion
|
|
#region 显示接口
|
|
|
double IUnitHelper.Convert(int fromUnit, int toUnit, double fromValue)
|
{
|
return Convert((eUnitH)fromUnit, (eUnitH)toUnit, fromValue);
|
}
|
|
string IUnitHelper.GetCnUnitName(int unit)
|
{
|
return GetCnUnitName((eUnitH)unit);
|
}
|
|
List<string> IUnitHelper.GetCnUnitNameList()
|
{
|
return GetCnUnitNameList();
|
}
|
|
Dictionary<int, string> IUnitHelper.GetCnUnitDict()
|
{
|
var dic = new Dictionary<int, string>();
|
foreach (var item in GetCnUnitDict())
|
{
|
dic.Add((int)item.Key, item.Value);
|
}
|
return dic;
|
}
|
|
string IUnitHelper.GetEnUnitName(int unit)
|
{
|
return GetEnUnitName((eUnitH)unit);
|
}
|
|
List<string> IUnitHelper.GetEnUnitNameList()
|
{
|
return GetEnUnitNameList();
|
}
|
|
Dictionary<int, string> IUnitHelper.GetEnUnitDict()
|
{
|
var dic = new Dictionary<int, string>();
|
foreach (var item in GetEnUnitDict())
|
{
|
dic.Add((int)item.Key, item.Value);
|
}
|
return dic;
|
}
|
|
|
|
|
#endregion
|
}
|
}
|