Force combination was added
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -11,33 +13,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Area : UnitBase
|
||||
{
|
||||
public override UnitTypes unitType { get => UnitTypes.Area; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "mm2"); }
|
||||
public override string unitName { get => "Area"; }
|
||||
|
||||
public override string MeasureUnit => throw new NotImplementedException();
|
||||
|
||||
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 *= UnitConstatnts.Length * UnitConstatnts.Length;
|
||||
return val;
|
||||
}
|
||||
|
||||
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
val = CommonOperation.ConvertToDoubleChangeComma(strVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= (UnitConstatnts.Length * UnitConstatnts.Length);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
Infrastructure/UI/Converters/Units/Curvature.cs
Normal file
17
Infrastructure/UI/Converters/Units/Curvature.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Curvature : UnitBase
|
||||
{
|
||||
public override UnitTypes unitType { get => UnitTypes.Curvature; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "1/mm"); }
|
||||
public override string unitName { get => "Curvature"; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -10,35 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Force : UnitBase
|
||||
{
|
||||
private double coeffficient = UnitConstatnts.Force;
|
||||
|
||||
public override UnitTypes unitType { get => UnitTypes.Force; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "kN"); }
|
||||
public override string unitName { get => "Force"; }
|
||||
|
||||
public override string MeasureUnit => throw new NotImplementedException();
|
||||
|
||||
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;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
val = CommonOperation.ConvertToDoubleChangeComma(strVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= coeffficient;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -14,60 +15,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Length : UnitBase
|
||||
{
|
||||
private IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
||||
private UnitTypes type = UnitTypes.Length;
|
||||
private IUnit currentUnit => units.Where(u => u.UnitType == type & u.Name == "mm").Single();
|
||||
public override string MeasureUnit => currentUnit.Name;
|
||||
private double coeffficient => currentUnit.Multiplyer;
|
||||
|
||||
public override string unitName { get => "Length"; }
|
||||
|
||||
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;
|
||||
string strValue = $"{val} {MeasureUnit}";
|
||||
return strValue;
|
||||
}
|
||||
|
||||
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double val;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
IStringDoublePair pair = CommonOperation.DivideIntoStringDoublePair(strVal);
|
||||
double multy;
|
||||
try
|
||||
{
|
||||
multy = coeffficient / GetMultiplyer(units, type, pair.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
multy = 1d;
|
||||
}
|
||||
val = pair.Digit * multy;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= coeffficient;
|
||||
return val;
|
||||
}
|
||||
|
||||
private double GetMultiplyer(IEnumerable<IUnit> units, UnitTypes unitType, string unitName)
|
||||
{
|
||||
try
|
||||
{
|
||||
return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single().Multiplyer;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ex);
|
||||
}
|
||||
}
|
||||
public override UnitTypes unitType { get => UnitTypes.Length; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "mm"); }
|
||||
public override string unitName { get => "Length"; }
|
||||
}
|
||||
}
|
||||
|
||||
17
Infrastructure/UI/Converters/Units/Moment.cs
Normal file
17
Infrastructure/UI/Converters/Units/Moment.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Moment : UnitBase
|
||||
{
|
||||
public override UnitTypes unitType { get => UnitTypes.Moment; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "kNm"); }
|
||||
public override string unitName { get => "Moment"; }
|
||||
}
|
||||
}
|
||||
39
Infrastructure/UI/Converters/Units/PlainDouble.cs
Normal file
39
Infrastructure/UI/Converters/Units/PlainDouble.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
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 PlainDouble : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (double)value;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CommonOperation.ConvertToDoubleChangeComma((string)value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -10,35 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal class Stress : UnitBase
|
||||
{
|
||||
private double coeffficient = UnitConstatnts.Stress;
|
||||
|
||||
public override UnitTypes unitType { get => UnitTypes.Stress; }
|
||||
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "MPa"); }
|
||||
public override string unitName { get => "Stress"; }
|
||||
|
||||
public override string MeasureUnit => throw new NotImplementedException();
|
||||
|
||||
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;
|
||||
try
|
||||
{
|
||||
var strVal = value as string;
|
||||
val = CommonOperation.ConvertToDoubleChangeComma(strVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
val /= coeffficient;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -10,9 +12,17 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
|
||||
{
|
||||
internal abstract class UnitBase : IValueConverter
|
||||
{
|
||||
public abstract UnitTypes unitType { get; }
|
||||
public abstract IUnit currentUnit { get; }
|
||||
public abstract string unitName { get;}
|
||||
public abstract string MeasureUnit { get; }
|
||||
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
|
||||
public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return CommonOperation.Convert(currentUnit, unitName, value);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return CommonOperation.ConvertBack(unitType, currentUnit, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user