Unit constants was added
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
39
Infrastructure/UI/Converters/Units/Force.cs
Normal file
39
Infrastructure/UI/Converters/Units/Force.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
39
Infrastructure/UI/Converters/Units/Stress.cs
Normal file
39
Infrastructure/UI/Converters/Units/Stress.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,12 +337,12 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
if (this is Rectangle)
|
||||
{
|
||||
X = showedX + OwnerVm.YX1 / UnitConstatnts.LengthConstant;
|
||||
X = showedX + OwnerVm.YX1 / UnitConstatnts.Length;
|
||||
}
|
||||
else if (this is Point)
|
||||
{
|
||||
Point point = this as Point;
|
||||
X = showedX + OwnerVm.YX1 / UnitConstatnts.LengthConstant;
|
||||
X = showedX + OwnerVm.YX1 / UnitConstatnts.Length;
|
||||
}
|
||||
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
|
||||
}
|
||||
@@ -350,12 +350,12 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
if (this is Rectangle)
|
||||
{
|
||||
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.LengthConstant - PrimitiveHeight;
|
||||
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.Length - PrimitiveHeight;
|
||||
}
|
||||
else if (this is Point)
|
||||
{
|
||||
Point point = this as Point;
|
||||
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.LengthConstant - point.Diameter;
|
||||
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.Length - point.Diameter;
|
||||
}
|
||||
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
|
||||
}
|
||||
|
||||
12
Infrastructure/UI/Resources/Converters.xaml
Normal file
12
Infrastructure/UI/Resources/Converters.xaml
Normal file
@@ -0,0 +1,12 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:convertersCommon ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Common"
|
||||
xmlns:convertersUnits ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Units">
|
||||
|
||||
<convertersCommon:InvertBoolConverter x:Key="InvertBoolConverter"/>
|
||||
<convertersUnits:Length x:Key="LengthConverter"/>
|
||||
<convertersUnits:Area x:Key="AreaConverter"/>
|
||||
<convertersUnits:Force x:Key="ForceConverter"/>
|
||||
<convertersUnits:Stress x:Key="StressConverter"/>
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user