diff --git a/App.xaml.cs b/App.xaml.cs index da89033..eec8ad0 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,7 +1,9 @@ using System.Windows; using Autofac; using StructureHelper.Services; +using StructureHelper.UnitSystem; using StructureHelper.Windows.MainWindow; +using StructureHelperLogics.Services; namespace StructureHelper { @@ -18,7 +20,8 @@ namespace StructureHelper base.OnStartup(e); var builder = new ContainerBuilder(); builder.RegisterType().As().SingleInstance(); - builder.RegisterType().As().SingleInstance(); + builder.RegisterType().AsSelf().SingleInstance(); + builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); diff --git a/Infrastructure/UI/DataContexts/Point.cs b/Infrastructure/UI/DataContexts/Point.cs index d7632f7..ef1b857 100644 --- a/Infrastructure/UI/DataContexts/Point.cs +++ b/Infrastructure/UI/DataContexts/Point.cs @@ -1,5 +1,6 @@ using System; using StructureHelper.Infrastructure.Enums; +using StructureHelper.UnitSystem.Systems; using StructureHelper.Windows.MainWindow; using StructureHelperCommon.Models.Entities; using StructureHelperCommon.Models.Materials; @@ -9,36 +10,21 @@ namespace StructureHelper.Infrastructure.UI.DataContexts { public class Point : PrimitiveBase { - private double square; - public double Square + public Point(double d, double x, double y, MainViewModel mainViewModel) : base(PrimitiveType.Point, x, y, mainViewModel) { - get => square; - set - { - square = value; - PrimitiveWidth = Math.Round(Math.Sqrt(4 * value / Math.PI), 2); - OnPropertyChanged(nameof(PrimitiveWidth)); - OnPropertyChanged(); - } - } - - public Point(double square, double x, double y, MainViewModel mainViewModel) : base(PrimitiveType.Point, x, y, mainViewModel) - { - Square = square; + PrimitiveWidth = d; ShowedX = 0; ShowedY = 0; } - public override INdmPrimitive GetNdmPrimitive() + public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem) { - double strength = 0; - double centerX = 0; - double centerY = 0; - double area = 0; - string materialName = "s400"; - ICenter center = new Center { X = centerX, Y = centerY }; + var width = unitSystem.ConvertLength(PrimitiveWidth); + double area = Math.Round(width * width * Math.PI / 4, 2); + string materialName = MaterialName; + ICenter center = new Center { X = unitSystem.ConvertLength(ShowedX), Y = unitSystem.ConvertLength(ShowedY) }; IShape shape = new StructureHelperCommon.Models.Shapes.Point { Area = area }; - IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = strength }; ; + IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesingTensileStrength }; ; INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial }; return ndmPrimitive; } diff --git a/Infrastructure/UI/DataContexts/PrimitiveBase.cs b/Infrastructure/UI/DataContexts/PrimitiveBase.cs index cce3d18..1b6fad6 100644 --- a/Infrastructure/UI/DataContexts/PrimitiveBase.cs +++ b/Infrastructure/UI/DataContexts/PrimitiveBase.cs @@ -4,6 +4,7 @@ using System.Windows.Input; using System.Windows.Media; using StructureHelper.Infrastructure.Enums; using StructureHelper.Models.Materials; +using StructureHelper.UnitSystem.Systems; using StructureHelper.Windows.MainWindow; using StructureHelperCommon.Models.Entities; using StructureHelperCommon.Models.Materials; @@ -62,9 +63,12 @@ namespace StructureHelper.Infrastructure.UI.DataContexts get => material; set { - MaterialName = material.MaterialClass; - OnPropertyChanged(value, ref material); - OnPropertyChanged(nameof(MaterialName)); + if (value != null) + { + MaterialName = value.MaterialClass; + OnPropertyChanged(value, ref material); + OnPropertyChanged(nameof(MaterialName)); + } } } private string materialName = string.Empty; @@ -276,7 +280,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts if (Type == PrimitiveType.Point) Y = -showedY + Xy1 - PrimitiveWidth / 2; } - public abstract INdmPrimitive GetNdmPrimitive(); + public abstract INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem); public MaterialTypes GetMaterialTypes() { MaterialTypes materialTypes; diff --git a/Infrastructure/UI/DataContexts/Rectangle.cs b/Infrastructure/UI/DataContexts/Rectangle.cs index fa2727b..7a1dcda 100644 --- a/Infrastructure/UI/DataContexts/Rectangle.cs +++ b/Infrastructure/UI/DataContexts/Rectangle.cs @@ -1,4 +1,5 @@ using StructureHelper.Infrastructure.Enums; +using StructureHelper.UnitSystem.Systems; using StructureHelper.Windows.MainWindow; using StructureHelperCommon.Models.Entities; using StructureHelperCommon.Models.Materials; @@ -17,18 +18,17 @@ namespace StructureHelper.Infrastructure.UI.DataContexts ShowedY = 0; } - public override INdmPrimitive GetNdmPrimitive() + public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem) { - double strength = 0; - double centerX = 0; - double centerY = 0; - string materialName = "C20"; - ICenter center = new Center() { X = centerX, Y = centerY }; - double height = 0; - double width = 0; - IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle() { Height = height, Width = width, Angle = 0 }; - IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial() { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = strength }; ; - INdmPrimitive ndmPrimitive = new NdmPrimitive() { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial }; + var width = unitSystem.ConvertLength(PrimitiveWidth); + var height = unitSystem.ConvertLength(PrimitiveHeight); + double centerX = unitSystem.ConvertLength(ShowedX) + width / 2; + double centerY = unitSystem.ConvertLength(ShowedY) + height / 2; + string materialName = MaterialName; + ICenter center = new Center { X = centerX, Y = centerY }; + IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle { Height = height, Width = width, Angle = 0 }; + IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesingTensileStrength }; + INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial }; return ndmPrimitive; } } diff --git a/Infrastructure/UI/UserControls/PrimitivePopup.xaml b/Infrastructure/UI/UserControls/PrimitivePopup.xaml index 3d7826f..c320ff4 100644 --- a/Infrastructure/UI/UserControls/PrimitivePopup.xaml +++ b/Infrastructure/UI/UserControls/PrimitivePopup.xaml @@ -29,8 +29,6 @@ - - @@ -61,14 +59,12 @@ - +