Smart rounding was ajusted

This commit is contained in:
Evgeny Redikultsev
2024-06-02 16:56:44 +05:00
parent 99d5aa3608
commit 31d668b996
58 changed files with 716 additions and 274 deletions

View File

@@ -14,7 +14,7 @@ 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 IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "mm2"); }
public override string UnitName { get => "Area"; }
}
}

View File

@@ -0,0 +1,28 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
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 CrackWidth : UnitBase
{
public CrackWidth()
{
OperationLogic = new ConvertUnitLogic()
{
MathRoundLogic = new FixedRoundLogic()
{
DigitQuant = 3
}
};
}
public override UnitTypes UnitType { get => UnitTypes.Length; }
public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "mm"); }
public override string UnitName { get => "Length"; }
}
}

View File

@@ -11,7 +11,7 @@ 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 IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "1/mm"); }
public override string UnitName { get => "Curvature"; }
}
}

View File

@@ -13,7 +13,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
internal class Force : UnitBase
{
public override UnitTypes UnitType { get => UnitTypes.Force; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "kN"); }
public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "kN"); }
public override string UnitName { get => "Force"; }
}
}

View File

@@ -5,8 +5,9 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Length : UnitBase
{
public override UnitTypes UnitType { get => UnitTypes.Length; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "mm"); }
public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "mm"); }
public override string UnitName { get => "Length"; }
}
}

View File

@@ -11,7 +11,7 @@ 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 IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "kNm"); }
public override string UnitName { get => "Moment"; }
}
}

View File

@@ -12,6 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class PlainDouble : IValueConverter
{
IConvertUnitLogic operationLogic = new ConvertUnitLogic();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
@@ -28,7 +30,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
try
{
return CommonOperation.ConvertToDoubleChangeComma((string)value);
return ProcessString.ConvertCommaToCultureSettings((string)value);
}
catch (Exception)
{

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
@@ -12,8 +13,19 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Stress : UnitBase
{
public override UnitTypes UnitType { get => UnitTypes.Stress; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "MPa"); }
public override IUnit CurrentUnit { get => UnitLogic.GetUnit(UnitType, "MPa"); }
public override string UnitName { get => "Stress"; }
public Stress()
{
OperationLogic = new ConvertUnitLogic()
{
MathRoundLogic = new SmartRoundLogic()
{
DigitQuant = 3
}
};
}
}
}

View File

@@ -1,4 +1,7 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Services;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
@@ -14,19 +17,61 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal abstract class UnitBase : IValueConverter
{
IMathRoundLogic roundLogic = new DirectRoundLogic();
public IConvertUnitLogic OperationLogic { get; set; } = new ConvertUnitLogic();
public IGetUnitLogic UnitLogic { get; set; } = new GetUnitLogic();
public abstract UnitTypes UnitType { get; }
public abstract IUnit CurrentUnit { get; }
public abstract string UnitName { get;}
/// <summary>
/// From variable to user
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return CommonOperation.Convert(CurrentUnit, UnitName, value);
var pair = OperationLogic.Convert(CurrentUnit, UnitName, value);
var result = pair.Value;
if (parameter is not null)
{
if (parameter is string paramString)
{
var logic = new ProcessDoublePairLogic() { DigitPlace = DigitPlace.Any };
var paramPair = logic.GetValuePairByString(paramString);
string paramTextPart = paramPair.Text.ToLower();
int paramValuePart = (int)paramPair.Value;
if (paramTextPart == "smart")
{
roundLogic = new SmartRoundLogic() { DigitQuant = paramValuePart };
}
else if (paramTextPart == "fixed")
{
roundLogic = new FixedRoundLogic() { DigitQuant = paramValuePart };
}
result = roundLogic.RoundValue(result);
}
}
string strValue = $"{result} {pair.Text}";
return strValue;
}
/// <summary>
/// From user to variable
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
return CommonOperation.ConvertBack(UnitType, CurrentUnit, value);
double result = OperationLogic.ConvertBack(UnitType, CurrentUnit, value);
return result;
}
catch (Exception)
{

View File

@@ -12,5 +12,6 @@
<convertersUnits:Moment x:Key="MomentConverter"/>
<convertersUnits:Stress x:Key="StressConverter"/>
<convertersUnits:Curvature x:Key="Curvature"/>
<convertersUnits:CrackWidth x:Key="CrackWidth"/>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</ResourceDictionary>

View File

@@ -1,7 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="CrackTextBox">
<TextBlock Grid.Row="0" Text="{Binding CrackWidth, Converter={StaticResource LengthConverter}}">
<TextBlock Grid.Row="0" Text="{Binding CrackWidth, Converter={StaticResource LengthConverter}}" HorizontalAlignment="Right">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>