From 96b331f14cdad3c3d0508218c34d185d88ca6114 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Sun, 27 Nov 2022 17:04:34 +0500 Subject: [PATCH] Force combination was added --- .../UI/Converters/CommonOperation.cs | 55 ++++++++++++++++- Infrastructure/UI/Converters/Units/Area.cs | 33 ++--------- .../UI/Converters/Units/Curvature.cs | 17 ++++++ Infrastructure/UI/Converters/Units/Force.cs | 35 ++--------- Infrastructure/UI/Converters/Units/Length.cs | 59 ++----------------- Infrastructure/UI/Converters/Units/Moment.cs | 17 ++++++ .../UI/Converters/Units/PlainDouble.cs | 39 ++++++++++++ Infrastructure/UI/Converters/Units/Stress.cs | 35 ++--------- .../UI/Converters/Units/UnitBase.cs | 18 ++++-- .../UI/DataContexts/PointViewPrimitive.cs | 4 ++ .../UI/DataContexts/PrimitiveBase.cs | 5 ++ .../UI/DataTemplates/EllipseTemplate.xaml | 8 +-- .../UI/DataTemplates/RectangleTemplate.xaml | 8 +-- Infrastructure/UI/Resources/Converters.xaml | 3 + Infrastructure/UI/Styles.xaml | 8 +++ StructureHelper.csproj | 3 + .../Infrastructures/Enums/LimitStates.cs | 4 +- .../Infrastructures/Enums/UnitTypes.cs | 3 +- .../Models/Calculators/IHelperCalculator.cs | 14 +++++ .../Models/Forces/DesignForceTuple.cs | 23 ++++++++ .../Models/Forces/ForceCombinationList.cs | 27 +++++++++ .../Models/Forces/ForceTuple.cs | 18 ++++++ .../Models/Forces/IDesignForceTuple.cs | 16 +++++ .../Models/Forces/IForceCombinationList.cs | 16 +++++ .../Models/Forces/IForceTuple.cs | 19 ++++++ .../Models/Shapes/ICenterShape.cs | 2 +- .../Models/Shapes/ILineShape.cs | 4 +- .../Models/Shapes/{ICenter.cs => IPoint2D.cs} | 2 +- .../Models/Shapes/LineShape.cs | 8 +-- .../Models/Shapes/{Center.cs => Point2D.cs} | 2 +- .../Services/Units/UnitsFactory.cs | 17 ++++++ .../StructureHelperCommon.csproj | 12 +++- .../CalculationProperty.cs | 2 +- .../Models/Materials/LibMaterial.cs | 4 +- .../Models/Primitives/IPrimitive.cs | 2 +- .../Models/Primitives/LinePrimitive.cs | 2 +- .../Primitives/LinePrimitive.cs | 8 +-- .../IPointTriangulationLogicOptions.cs | 2 +- .../IRectangleTriangulationLogicOptions.cs | 2 +- .../Triangulations/PointTriangulationLogic.cs | 2 +- .../PointTriangulationLogicOptions.cs | 6 +- .../RectangleTriangulationLogicOptions.cs | 6 +- .../RCSectionFromNdmPrimitiveTest.cs | 10 ++-- .../Ndms/RCSections/RCSectionTest.cs | 10 ++-- .../Ndms/SteelSections/ReinforcementTest.cs | 2 +- .../RectangleTriangulationTest.cs | 2 +- .../CalculationPropertyView.xaml | 4 +- .../CalculationPropertyView.xaml.cs | 6 +- .../CalculationResultView.xaml | 4 +- Windows/MainWindow/MainView.xaml | 13 +++- Windows/MainWindow/MainViewModel.cs | 14 ++++- .../PrimitivePropertiesView.xaml | 6 +- 52 files changed, 427 insertions(+), 214 deletions(-) create mode 100644 Infrastructure/UI/Converters/Units/Curvature.cs create mode 100644 Infrastructure/UI/Converters/Units/Moment.cs create mode 100644 Infrastructure/UI/Converters/Units/PlainDouble.cs create mode 100644 StructureHelperCommon/Models/Calculators/IHelperCalculator.cs create mode 100644 StructureHelperCommon/Models/Forces/DesignForceTuple.cs create mode 100644 StructureHelperCommon/Models/Forces/ForceCombinationList.cs create mode 100644 StructureHelperCommon/Models/Forces/ForceTuple.cs create mode 100644 StructureHelperCommon/Models/Forces/IDesignForceTuple.cs create mode 100644 StructureHelperCommon/Models/Forces/IForceCombinationList.cs create mode 100644 StructureHelperCommon/Models/Forces/IForceTuple.cs rename StructureHelperCommon/Models/Shapes/{ICenter.cs => IPoint2D.cs} (95%) rename StructureHelperCommon/Models/Shapes/{Center.cs => Point2D.cs} (85%) diff --git a/Infrastructure/UI/Converters/CommonOperation.cs b/Infrastructure/UI/Converters/CommonOperation.cs index 4b7582e..332d745 100644 --- a/Infrastructure/UI/Converters/CommonOperation.cs +++ b/Infrastructure/UI/Converters/CommonOperation.cs @@ -1,5 +1,9 @@ -using StructureHelperCommon.Infrastructures.Exceptions; +using Newtonsoft.Json.Linq; +using StructureHelper.Infrastructure.UI.Converters.Units; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Strings; +using StructureHelperCommon.Services.Units; using System; using System.Collections.Generic; using System.Globalization; @@ -12,6 +16,8 @@ namespace StructureHelper.Infrastructure.UI.Converters { internal static class CommonOperation { + private static IEnumerable units = UnitsFactory.GetUnitCollection(); + public static double ConvertToDoubleChangeComma(string s) { double result; @@ -26,6 +32,7 @@ namespace StructureHelper.Infrastructure.UI.Converters public static IStringDoublePair DivideIntoStringDoublePair(string s) { + s = s.Replace(" ", ""); string digitPattern = @"\d+(\.?|\,?)\d+"; string textPattern = @"[0-9]|\.|\,"; string caracterPattern = "[a-z]+$"; @@ -43,5 +50,51 @@ namespace StructureHelper.Infrastructure.UI.Converters } throw new StructureHelperException(ErrorStrings.DataIsInCorrect); } + + public static IUnit GetUnit(UnitTypes unitType, string unitName) + { + return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single(); + } + + public static string Convert(IUnit unit, string unitName, object value) + { + double val; + if (value != null) { val = (double)value; } + else { throw new Exception($"{unitName} value is null"); } + val *= unit.Multiplyer; + string strValue = $"{val} {unit.Name}"; + return strValue; + } + + public static double ConvertBack(UnitTypes unitType, IUnit unit, object value) + { + double val; + double multy; + double coefficient = unit.Multiplyer; + var strVal = value as string; + IStringDoublePair pair = DivideIntoStringDoublePair(strVal); + try + { + multy = GetMultiplyer(unitType, pair.Text); + } + catch (Exception ex) + { + multy = coefficient; + } + val = pair.Digit / multy; + return val; + } + + private static double GetMultiplyer(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); + } + } } } diff --git a/Infrastructure/UI/Converters/Units/Area.cs b/Infrastructure/UI/Converters/Units/Area.cs index f6b6e0e..35b5d02 100644 --- a/Infrastructure/UI/Converters/Units/Area.cs +++ b/Infrastructure/UI/Converters/Units/Area.cs @@ -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; - } } } diff --git a/Infrastructure/UI/Converters/Units/Curvature.cs b/Infrastructure/UI/Converters/Units/Curvature.cs new file mode 100644 index 0000000..45176dd --- /dev/null +++ b/Infrastructure/UI/Converters/Units/Curvature.cs @@ -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"; } + } +} diff --git a/Infrastructure/UI/Converters/Units/Force.cs b/Infrastructure/UI/Converters/Units/Force.cs index 2715863..0cd5645 100644 --- a/Infrastructure/UI/Converters/Units/Force.cs +++ b/Infrastructure/UI/Converters/Units/Force.cs @@ -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; - } } } diff --git a/Infrastructure/UI/Converters/Units/Length.cs b/Infrastructure/UI/Converters/Units/Length.cs index 886704f..a9d56bf 100644 --- a/Infrastructure/UI/Converters/Units/Length.cs +++ b/Infrastructure/UI/Converters/Units/Length.cs @@ -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 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 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"; } } } diff --git a/Infrastructure/UI/Converters/Units/Moment.cs b/Infrastructure/UI/Converters/Units/Moment.cs new file mode 100644 index 0000000..360d1ba --- /dev/null +++ b/Infrastructure/UI/Converters/Units/Moment.cs @@ -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"; } + } +} diff --git a/Infrastructure/UI/Converters/Units/PlainDouble.cs b/Infrastructure/UI/Converters/Units/PlainDouble.cs new file mode 100644 index 0000000..6ab470e --- /dev/null +++ b/Infrastructure/UI/Converters/Units/PlainDouble.cs @@ -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); + } + } + } +} diff --git a/Infrastructure/UI/Converters/Units/Stress.cs b/Infrastructure/UI/Converters/Units/Stress.cs index e19f9cd..254c936 100644 --- a/Infrastructure/UI/Converters/Units/Stress.cs +++ b/Infrastructure/UI/Converters/Units/Stress.cs @@ -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; - } } } diff --git a/Infrastructure/UI/Converters/Units/UnitBase.cs b/Infrastructure/UI/Converters/Units/UnitBase.cs index a234531..f63219d 100644 --- a/Infrastructure/UI/Converters/Units/UnitBase.cs +++ b/Infrastructure/UI/Converters/Units/UnitBase.cs @@ -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); + } } } diff --git a/Infrastructure/UI/DataContexts/PointViewPrimitive.cs b/Infrastructure/UI/DataContexts/PointViewPrimitive.cs index 06f0b2d..5231aec 100644 --- a/Infrastructure/UI/DataContexts/PointViewPrimitive.cs +++ b/Infrastructure/UI/DataContexts/PointViewPrimitive.cs @@ -20,6 +20,10 @@ namespace StructureHelper.Infrastructure.UI.DataContexts primitive.Area = value; OnPropertyChanged(nameof(Area)); OnPropertyChanged(nameof(Diameter)); + OnPropertyChanged(nameof(CenterX)); + OnPropertyChanged(nameof(CenterY)); + OnPropertyChanged(nameof(PrimitiveLeft)); + OnPropertyChanged(nameof(PrimitiveTop)); } } diff --git a/Infrastructure/UI/DataContexts/PrimitiveBase.cs b/Infrastructure/UI/DataContexts/PrimitiveBase.cs index 16419e3..b4cbf2d 100644 --- a/Infrastructure/UI/DataContexts/PrimitiveBase.cs +++ b/Infrastructure/UI/DataContexts/PrimitiveBase.cs @@ -243,5 +243,10 @@ namespace StructureHelper.Infrastructure.UI.DataContexts { } + + public void RefreshColor() + { + OnPropertyChanged(nameof(Color)); + } } } diff --git a/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml b/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml index 02c7b23..d974201 100644 --- a/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml +++ b/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml @@ -24,10 +24,10 @@ - - - - + + + + diff --git a/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml b/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml index 9c9445b..dc410d2 100644 --- a/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml +++ b/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml @@ -30,10 +30,10 @@ - - - - + + + + diff --git a/Infrastructure/UI/Resources/Converters.xaml b/Infrastructure/UI/Resources/Converters.xaml index fa0fe35..d46f2f9 100644 --- a/Infrastructure/UI/Resources/Converters.xaml +++ b/Infrastructure/UI/Resources/Converters.xaml @@ -5,8 +5,11 @@ xmlns:convertersUnits ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Units"> + + + \ No newline at end of file diff --git a/Infrastructure/UI/Styles.xaml b/Infrastructure/UI/Styles.xaml index a163e5a..2a43656 100644 --- a/Infrastructure/UI/Styles.xaml +++ b/Infrastructure/UI/Styles.xaml @@ -26,6 +26,14 @@ + + + + + + + +