diff --git a/Infrastructure/UI/Converters/CommonOperation.cs b/Infrastructure/UI/Converters/CommonOperation.cs new file mode 100644 index 0000000..4b7582e --- /dev/null +++ b/Infrastructure/UI/Converters/CommonOperation.cs @@ -0,0 +1,47 @@ +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.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace StructureHelper.Infrastructure.UI.Converters +{ + internal static class CommonOperation + { + public static double ConvertToDoubleChangeComma(string s) + { + double result; + if (!double.TryParse(s, NumberStyles.Any, CultureInfo.CurrentCulture, out result) && + !double.TryParse(s, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out result) && + !double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out result)) + { + throw new StructureHelperException($"{ErrorStrings.IncorrectValue}: {s}"); + } + return result; + } + + public static IStringDoublePair DivideIntoStringDoublePair(string s) + { + string digitPattern = @"\d+(\.?|\,?)\d+"; + string textPattern = @"[0-9]|\.|\,"; + string caracterPattern = "[a-z]+$"; + string target = ""; + Regex regexText = new Regex(textPattern); + string textString = regexText.Replace(s, target); + var textMatch = Regex.Match(textString, caracterPattern, RegexOptions.IgnoreCase); + if (textMatch.Success) {textString = textMatch.Value.ToLower();} + var match = Regex.Match(s, digitPattern); + if (match.Success) + { + string digitString = match.Value; + double digit = ConvertToDoubleChangeComma(digitString); + return new StringDoublePair() { Digit = digit, Text = textString }; + } + throw new StructureHelperException(ErrorStrings.DataIsInCorrect); + } + } +} diff --git a/Infrastructure/UI/Converters/IStringDoublePair.cs b/Infrastructure/UI/Converters/IStringDoublePair.cs new file mode 100644 index 0000000..83de3b6 --- /dev/null +++ b/Infrastructure/UI/Converters/IStringDoublePair.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelper.Infrastructure.UI.Converters +{ + internal interface IStringDoublePair + { + double Digit { get; } + string Text { get; } + } +} diff --git a/Infrastructure/UI/Converters/StringDoublePair.cs b/Infrastructure/UI/Converters/StringDoublePair.cs new file mode 100644 index 0000000..37ed79e --- /dev/null +++ b/Infrastructure/UI/Converters/StringDoublePair.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelper.Infrastructure.UI.Converters +{ + internal class StringDoublePair : IStringDoublePair + { + public double Digit { get; set; } + public string Text { get; set; } + } +} diff --git a/Infrastructure/UI/Converters/Units/Area.cs b/Infrastructure/UI/Converters/Units/Area.cs index bf813df..f6b6e0e 100644 --- a/Infrastructure/UI/Converters/Units/Area.cs +++ b/Infrastructure/UI/Converters/Units/Area.cs @@ -12,6 +12,9 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units internal class Area : UnitBase { 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; @@ -24,12 +27,15 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { double val; - if (value != null) + try { var strVal = value as string; - double.TryParse(strVal, out val); + val = CommonOperation.ConvertToDoubleChangeComma(strVal); + } + catch + { + return null; } - else { throw new Exception($"{unitName} value is null"); } val /= (UnitConstatnts.Length * UnitConstatnts.Length); return val; } diff --git a/Infrastructure/UI/Converters/Units/Force.cs b/Infrastructure/UI/Converters/Units/Force.cs index 43d250a..2715863 100644 --- a/Infrastructure/UI/Converters/Units/Force.cs +++ b/Infrastructure/UI/Converters/Units/Force.cs @@ -14,6 +14,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units 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; @@ -26,12 +28,15 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { double val; - if (value != null) + try { var strVal = value as string; - double.TryParse(strVal, out val); + val = CommonOperation.ConvertToDoubleChangeComma(strVal); + } + catch + { + return null; } - else { throw new Exception($"{unitName} value is null"); } val /= coeffficient; return val; } diff --git a/Infrastructure/UI/Converters/Units/Length.cs b/Infrastructure/UI/Converters/Units/Length.cs index 12006b0..886704f 100644 --- a/Infrastructure/UI/Converters/Units/Length.cs +++ b/Infrastructure/UI/Converters/Units/Length.cs @@ -1,4 +1,8 @@ -using System; +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; using System.Linq; @@ -10,28 +14,60 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units { internal class Length : UnitBase { - public override string unitName { get => "Length"; } + 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 *= UnitConstatnts.Length; - return val; + val *= coeffficient; + string strValue = $"{val} {MeasureUnit}"; + return strValue; } public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { double val; - if (value != null) + try { var strVal = value as string; - double.TryParse(strVal, out val); + IStringDoublePair pair = CommonOperation.DivideIntoStringDoublePair(strVal); + double multy; + try + { + multy = coeffficient / GetMultiplyer(units, type, pair.Text); + } + catch (Exception ex) + { + multy = 1d; + } + val = pair.Digit * multy; } - else { throw new Exception($"{unitName} value is null"); } - val /= UnitConstatnts.Length; + 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); + } + } } } diff --git a/Infrastructure/UI/Converters/Units/Stress.cs b/Infrastructure/UI/Converters/Units/Stress.cs index 6291955..e19f9cd 100644 --- a/Infrastructure/UI/Converters/Units/Stress.cs +++ b/Infrastructure/UI/Converters/Units/Stress.cs @@ -14,6 +14,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units 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; @@ -26,12 +28,15 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { double val; - if (value != null) + try { var strVal = value as string; - double.TryParse(strVal, out val); + val = CommonOperation.ConvertToDoubleChangeComma(strVal); + } + catch + { + return null; } - else { throw new Exception($"{unitName} value is null"); } val /= coeffficient; return val; } diff --git a/Infrastructure/UI/Converters/Units/UnitBase.cs b/Infrastructure/UI/Converters/Units/UnitBase.cs index 75b5fd3..a234531 100644 --- a/Infrastructure/UI/Converters/Units/UnitBase.cs +++ b/Infrastructure/UI/Converters/Units/UnitBase.cs @@ -11,6 +11,7 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units internal abstract class UnitBase : IValueConverter { 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); } diff --git a/Infrastructure/UI/DataContexts/PointViewPrimitive.cs b/Infrastructure/UI/DataContexts/PointViewPrimitive.cs index 7e8537e..06f0b2d 100644 --- a/Infrastructure/UI/DataContexts/PointViewPrimitive.cs +++ b/Infrastructure/UI/DataContexts/PointViewPrimitive.cs @@ -11,8 +11,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts { public class PointViewPrimitive : PrimitiveBase, IHasCenter { - const double lengthUnit = 1000d; - IPointPrimitive primitive; public double Area @@ -27,11 +25,11 @@ namespace StructureHelper.Infrastructure.UI.DataContexts public double PrimitiveLeft { - get => DeltaX - Diameter / 2d * lengthUnit; + get => DeltaX - Diameter / 2d; } public double PrimitiveTop { - get => DeltaY - Diameter / 2d * lengthUnit; + get => DeltaY - Diameter / 2d; } public PointViewPrimitive(IPointPrimitive _primitive) : base(_primitive) diff --git a/Infrastructure/UI/DataContexts/RectangleViewPrimitive.cs b/Infrastructure/UI/DataContexts/RectangleViewPrimitive.cs index 9182354..58697f1 100644 --- a/Infrastructure/UI/DataContexts/RectangleViewPrimitive.cs +++ b/Infrastructure/UI/DataContexts/RectangleViewPrimitive.cs @@ -11,8 +11,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts { public class RectangleViewPrimitive : PrimitiveBase, IHasDivision, IHasCenter { - const double lengthUnit = 1000d; - private IRectanglePrimitive primitive; public override double PrimitiveWidth @@ -38,11 +36,11 @@ namespace StructureHelper.Infrastructure.UI.DataContexts public double PrimitiveLeft { - get => DeltaX - primitive.Width / 2 * lengthUnit; + get => DeltaX - primitive.Width / 2d; } public double PrimitiveTop { - get => DeltaY - primitive.Height / 2 * lengthUnit; + get => DeltaY - primitive.Height / 2d; } public int NdmMinDivision { diff --git a/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml b/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml index 5ce0f74..02c7b23 100644 --- a/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml +++ b/Infrastructure/UI/DataTemplates/EllipseTemplate.xaml @@ -32,13 +32,13 @@ - - + + - + diff --git a/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml b/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml index 3dc1852..9c9445b 100644 --- a/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml +++ b/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml @@ -46,7 +46,7 @@ - + diff --git a/Infrastructure/UI/Styles.xaml b/Infrastructure/UI/Styles.xaml index c2c1530..a163e5a 100644 --- a/Infrastructure/UI/Styles.xaml +++ b/Infrastructure/UI/Styles.xaml @@ -30,20 +30,20 @@ \ No newline at end of file diff --git a/StructureHelper.csproj b/StructureHelper.csproj index 4359cf2..e3600df 100644 --- a/StructureHelper.csproj +++ b/StructureHelper.csproj @@ -133,7 +133,10 @@ Designer + + + diff --git a/StructureHelperCommon/Infrastructures/Enums/UnitTypes.cs b/StructureHelperCommon/Infrastructures/Enums/UnitTypes.cs new file mode 100644 index 0000000..4c05928 --- /dev/null +++ b/StructureHelperCommon/Infrastructures/Enums/UnitTypes.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Infrastructures.Enums +{ + public enum UnitTypes + { + Length, + Area, + Stress, + Force, + Moment + } +} diff --git a/StructureHelperCommon/Infrastructures/Strings/ErrorString.cs b/StructureHelperCommon/Infrastructures/Strings/ErrorString.cs index 9684acd..db8746f 100644 --- a/StructureHelperCommon/Infrastructures/Strings/ErrorString.cs +++ b/StructureHelperCommon/Infrastructures/Strings/ErrorString.cs @@ -15,5 +15,6 @@ namespace StructureHelperCommon.Infrastructures.Strings public static string ShapeIsNotCorrect => "#0004: Shape is not valid"; public static string LimitStatesIsNotValid => "#0005: Type of limite state is not valid"; public static string LoadTermIsNotValid => "#0006: Load term is not valid"; + public static string IncorrectValue => "#0007: value is not valid"; } } diff --git a/StructureHelperCommon/Services/Units/IUnit.cs b/StructureHelperCommon/Services/Units/IUnit.cs new file mode 100644 index 0000000..7a81584 --- /dev/null +++ b/StructureHelperCommon/Services/Units/IUnit.cs @@ -0,0 +1,20 @@ +using StructureHelperCommon.Infrastructures.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Services.Units +{ + /// + /// Interface for measurements Unit + /// + public interface IUnit + { + + UnitTypes UnitType { get; } + string Name { get; } + double Multiplyer { get; } + } +} diff --git a/StructureHelperCommon/Services/Units/Unit.cs b/StructureHelperCommon/Services/Units/Unit.cs new file mode 100644 index 0000000..d3e2cf2 --- /dev/null +++ b/StructureHelperCommon/Services/Units/Unit.cs @@ -0,0 +1,16 @@ +using StructureHelperCommon.Infrastructures.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Services.Units +{ + public class Unit : IUnit + { + public UnitTypes UnitType { get; set; } + public string Name { get; set; } + public double Multiplyer { get; set; } + } +} diff --git a/StructureHelperCommon/Services/Units/UnitsFactory.cs b/StructureHelperCommon/Services/Units/UnitsFactory.cs new file mode 100644 index 0000000..430a961 --- /dev/null +++ b/StructureHelperCommon/Services/Units/UnitsFactory.cs @@ -0,0 +1,27 @@ +using StructureHelperCommon.Infrastructures.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Services.Units +{ + public static class UnitsFactory + { + public static List GetUnitCollection() + { + List units = new List(); + UnitTypes type = UnitTypes.Length; + units.Add(new Unit() { UnitType = type, Name = "m", Multiplyer = 1d }); + units.Add(new Unit() { UnitType = type, Name = "mm", Multiplyer = 1e3d }); + units.Add(new Unit() { UnitType = type, Name = "cm", Multiplyer = 1e2d }); + units.Add(new Unit() { UnitType = type, Name = "km", Multiplyer = 1e-3d }); + type = UnitTypes.Stress; + units.Add(new Unit() { UnitType = type, Name = "Pa", Multiplyer = 1d }); + units.Add(new Unit() { UnitType = type, Name = "kPa", Multiplyer = 1e-3d }); + units.Add(new Unit() { UnitType = type, Name = "MPa", Multiplyer = 1e-6d }); + return units; + } + } +} diff --git a/StructureHelperCommon/StructureHelperCommon.csproj b/StructureHelperCommon/StructureHelperCommon.csproj index 3204093..f8ab6cd 100644 --- a/StructureHelperCommon/StructureHelperCommon.csproj +++ b/StructureHelperCommon/StructureHelperCommon.csproj @@ -49,6 +49,7 @@ + @@ -68,6 +69,9 @@ + + + \ No newline at end of file diff --git a/Windows/MainWindow/MainModel.cs b/Windows/MainWindow/MainModel.cs index 8790f3d..92f8c72 100644 --- a/Windows/MainWindow/MainModel.cs +++ b/Windows/MainWindow/MainModel.cs @@ -9,6 +9,7 @@ using StructureHelper.Services.Primitives; using StructureHelper.UnitSystem; using StructureHelper.UnitSystem.Systems; using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Services.Units; using StructureHelperLogics.Models.Calculations.CalculationProperties; using StructureHelperLogics.Models.Materials; using StructureHelperLogics.Models.Materials.Factories; diff --git a/Windows/MainWindow/MainView.xaml b/Windows/MainWindow/MainView.xaml index e44a63e..7eaa9ba 100644 --- a/Windows/MainWindow/MainView.xaml +++ b/Windows/MainWindow/MainView.xaml @@ -157,25 +157,32 @@ - + - + - + + + + + + diff --git a/Windows/MainWindow/MainViewModel.cs b/Windows/MainWindow/MainViewModel.cs index fff786e..47bf048 100644 --- a/Windows/MainWindow/MainViewModel.cs +++ b/Windows/MainWindow/MainViewModel.cs @@ -37,10 +37,12 @@ namespace StructureHelper.Windows.MainWindow { public class MainViewModel : ViewModelBase { - const double ConstAxisLineThickness = 2d; - + const double scale = 1d; + private double ConstAxisLineThickness = 2d * scale; + private double ConstGridLineThickness = 0.25d * scale; + private List headMaterials; - private readonly double scaleRate = 1.1; + private readonly double scaleRate = 1.1d; private IPrimitiveRepository PrimitiveRepository { get; } public PrimitiveBase SelectedPrimitive { get; set; } @@ -73,7 +75,7 @@ namespace StructureHelper.Windows.MainWindow } public int PrimitivesCount => Primitives.Count; - private double scaleValue = 1.0; + private double scaleValue; public double ScaleValue { @@ -83,13 +85,19 @@ namespace StructureHelper.Windows.MainWindow OnPropertyChanged(value, ref scaleValue); axisLineThickness = ConstAxisLineThickness / scaleValue; OnPropertyChanged(nameof(AxisLineThickness)); + gridLineThickness = ConstGridLineThickness / scaleValue; + OnPropertyChanged(nameof(GridLineThickness)); } } public double AxisLineThickness { - get =>axisLineThickness == 0d? ConstAxisLineThickness: axisLineThickness; - set { axisLineThickness = value; } + get => axisLineThickness; + } + + public double GridLineThickness + { + get => gridLineThickness; } private double canvasWidth, canvasHeight, xX2, xY1, yX1, yY2; @@ -165,18 +173,22 @@ namespace StructureHelper.Windows.MainWindow private double delta = 0.0005; private double axisLineThickness; + private double gridLineThickness; public MainViewModel(MainModel model, IPrimitiveRepository primitiveRepository, UnitSystemService unitSystemService) { PrimitiveRepository = primitiveRepository; Model = model; headMaterials = Model.HeadMaterialRepository.HeadMaterials; - CanvasWidth = 1500; - CanvasHeight = 1000; + CanvasWidth = 2d * scale; + CanvasHeight = 1.5d * scale; XX2 = CanvasWidth; XY1 = CanvasHeight / 2d; YX1 = CanvasWidth / 2d; YY2 = CanvasHeight; + scaleValue = 1000d / scale; + axisLineThickness = ConstAxisLineThickness / scaleValue; + gridLineThickness = ConstGridLineThickness / scaleValue; calculationProperty = new CalculationProperty(); LeftButtonUp = new RelayCommand(o => diff --git a/Windows/MainWindow/Materials/HeadMaterialsView.xaml b/Windows/MainWindow/Materials/HeadMaterialsView.xaml index b815541..338e4d5 100644 --- a/Windows/MainWindow/Materials/HeadMaterialsView.xaml +++ b/Windows/MainWindow/Materials/HeadMaterialsView.xaml @@ -35,11 +35,11 @@ - + - + - + diff --git a/Windows/PrimitivePropertiesWindow/PrimitivePropertiesView.xaml b/Windows/PrimitivePropertiesWindow/PrimitivePropertiesView.xaml index 7745310..dcfe5c2 100644 --- a/Windows/PrimitivePropertiesWindow/PrimitivePropertiesView.xaml +++ b/Windows/PrimitivePropertiesWindow/PrimitivePropertiesView.xaml @@ -22,8 +22,8 @@ - - + + @@ -38,7 +38,7 @@ - + @@ -55,8 +55,8 @@ - - + + @@ -106,8 +106,8 @@ - - + +