Unit constants was added

This commit is contained in:
Evgeny Redikultsev
2022-11-13 20:12:28 +05:00
parent 1e98e2cc57
commit e68ae14963
18 changed files with 152 additions and 40 deletions

View File

@@ -17,7 +17,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= UnitConstatnts.LengthConstant * UnitConstatnts.LengthConstant;
val *= UnitConstatnts.Length * UnitConstatnts.Length;
return val;
}
@@ -30,7 +30,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
double.TryParse(strVal, out val);
}
else { throw new Exception($"{unitName} value is null"); }
val /= (UnitConstatnts.LengthConstant * UnitConstatnts.LengthConstant);
val /= (UnitConstatnts.Length * UnitConstatnts.Length);
return val;
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Force : UnitBase
{
private double coeffficient = UnitConstatnts.Force;
public override string unitName { get => "Force"; }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= coeffficient;
return val;
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null)
{
var strVal = value as string;
double.TryParse(strVal, out val);
}
else { throw new Exception($"{unitName} value is null"); }
val /= coeffficient;
return val;
}
}
}

View File

@@ -17,7 +17,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= UnitConstatnts.LengthConstant;
val *= UnitConstatnts.Length;
return val;
}
@@ -30,7 +30,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
double.TryParse(strVal, out val);
}
else { throw new Exception($"{unitName} value is null"); }
val /= UnitConstatnts.LengthConstant;
val /= UnitConstatnts.Length;
return val;
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Stress : UnitBase
{
private double coeffficient = UnitConstatnts.Stress;
public override string unitName { get => "Stress"; }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= coeffficient;
return val;
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null)
{
var strVal = value as string;
double.TryParse(strVal, out val);
}
else { throw new Exception($"{unitName} value is null"); }
val /= coeffficient;
return val;
}
}
}

View File

@@ -8,6 +8,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal static class UnitConstatnts
{
public static double LengthConstant = 1000d;
public static double Length = 1e3d;
public static double Force = 1e-3d;
public static double Stress = 1e-6d;
}
}