From 165a2846bb48b63cb6663a463a6c028dd77c0703 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Fri, 2 Feb 2024 22:27:18 +0500 Subject: [PATCH] CrossSection view model was improved --- StructureHelper/App.xaml.cs | 4 +- .../{MainView.xaml => CrossSectionView.xaml} | 12 +- ...nView.xaml.cs => CrossSectionView.xaml.cs} | 4 +- .../MainWindow/CrossSectionViewModel.cs | 134 ++++++++---------- .../CrossSectionVisualPropertyVM.cs | 83 +++++++++++ .../MainWindow/VisualPropertyView.xaml | 12 +- .../MainWindow/VisualPropertyView.xaml.cs | 5 +- .../Services/CopyByParameterViewModel.cs | 2 +- .../CrossSectionViewVisualProperty.cs | 26 ---- .../PrimitiveViewModelLogic.cs | 38 ++--- .../Loggers/Factories/TraceTablesFactory.cs | 12 +- .../Models/Loggers/ITraceLogger.cs | 1 + .../Models/Loggers/ShiftTraceLogger.cs | 5 +- .../Models/Loggers/TraceLogger.cs | 2 + .../Shapes/Logics/ConstOneDirectionLogic.cs | 38 ++++- .../Logics/IConvert2DPointTo3DPointLogic.cs | 5 +- .../LimitCurve/Factories/GetPredicateLogic.cs | 13 +- .../Factories/IGetPredicateLogic.cs | 6 +- .../LimitCurve/Factories/PredicateFactory.cs | 27 +++- .../ByForces/LimitCurve/LimitCurveLogic.cs | 33 +++-- .../LimitCurve/LimitCurvesCalculator.cs | 5 +- .../Cracking/ExpSofteningLogic.cs | 10 +- 22 files changed, 307 insertions(+), 170 deletions(-) rename StructureHelper/Windows/MainWindow/{MainView.xaml => CrossSectionView.xaml} (97%) rename StructureHelper/Windows/MainWindow/{MainView.xaml.cs => CrossSectionView.xaml.cs} (84%) create mode 100644 StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs delete mode 100644 StructureHelper/Windows/ViewModels/NdmCrossSections/CrossSectionViewVisualProperty.cs diff --git a/StructureHelper/App.xaml.cs b/StructureHelper/App.xaml.cs index f18a2b1..86d7f43 100644 --- a/StructureHelper/App.xaml.cs +++ b/StructureHelper/App.xaml.cs @@ -25,12 +25,12 @@ namespace StructureHelper builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); - builder.RegisterType().AsSelf(); + builder.RegisterType().AsSelf(); Container = builder.Build(); Scope = Container.Resolve(); - var window = Scope.Resolve(); + var window = Scope.Resolve(); window.Show(); } diff --git a/StructureHelper/Windows/MainWindow/MainView.xaml b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml similarity index 97% rename from StructureHelper/Windows/MainWindow/MainView.xaml rename to StructureHelper/Windows/MainWindow/CrossSectionView.xaml index 05a8e8e..79d5191 100644 --- a/StructureHelper/Windows/MainWindow/MainView.xaml +++ b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml @@ -1,4 +1,4 @@ - @@ -363,7 +363,7 @@ - + @@ -438,8 +438,10 @@ - - + + + + diff --git a/StructureHelper/Windows/MainWindow/MainView.xaml.cs b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml.cs similarity index 84% rename from StructureHelper/Windows/MainWindow/MainView.xaml.cs rename to StructureHelper/Windows/MainWindow/CrossSectionView.xaml.cs index 462baf1..e94de2f 100644 --- a/StructureHelper/Windows/MainWindow/MainView.xaml.cs +++ b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml.cs @@ -6,12 +6,12 @@ using StructureHelper.Services.Primitives; namespace StructureHelper.Windows.MainWindow { - public partial class MainView : Window + public partial class CrossSectionView : Window { private CrossSectionViewModel viewModel; public IPrimitiveRepository PrimitiveRepository { get; } - public MainView(IPrimitiveRepository primitiveRepository, CrossSectionViewModel viewModel) + public CrossSectionView(IPrimitiveRepository primitiveRepository, CrossSectionViewModel viewModel) { PrimitiveRepository = primitiveRepository; this.viewModel = viewModel; diff --git a/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs b/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs index 0d35b42..2629b08 100644 --- a/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs +++ b/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs @@ -27,21 +27,19 @@ namespace StructureHelper.Windows.MainWindow { public class CrossSectionViewModel : ViewModelBase { - ICrossSection section; - ICrossSectionRepository repository => section.SectionRepository; - - private CrossSectionViewVisualProperty visualProperty; - + private ICrossSection section; + private ICrossSectionRepository repository => section.SectionRepository; private readonly double scaleRate = 1.1d; - public PrimitiveBase SelectedPrimitive { get; set; } - //public IForceCombinationList SelectedForceCombinationList { get; set; } + public CrossSectionVisualPropertyVM VisualProperty { get; private set; } - private readonly AnalysisVewModelLogic calculatorsLogic; - public AnalysisVewModelLogic CalculatorsLogic { get => calculatorsLogic;} - public ActionsViewModel CombinationsLogic { get => combinationsLogic; } - public MaterialsViewModel MaterialsLogic { get => materialsLogic; } - public PrimitiveViewModelLogic PrimitiveLogic => primitiveLogic; + + public PrimitiveBase SelectedPrimitive { get; set; } + + public AnalysisVewModelLogic CalculatorsLogic { get; private set; } + public ActionsViewModel CombinationsLogic { get; } + public MaterialsViewModel MaterialsLogic { get; } + public PrimitiveViewModelLogic PrimitiveLogic { get; } public HelpLogic HelpLogic => new HelpLogic(); private CrossSectionModel Model { get; } @@ -84,37 +82,26 @@ namespace StructureHelper.Windows.MainWindow public double AxisLineThickness { - get => visualProperty.AxisLineThickness / scaleValue; + get => VisualProperty.AxisLineThickness / scaleValue; } public double GridLineThickness { - get => visualProperty.GridLineThickness / scaleValue; - } - - private double xX2, xY1, yX1, yY2; - public double CanvasWidth - { - get => visualProperty.WorkPlainWidth; - } - - public double CanvasHeight - { - get => visualProperty.WorkPlainHeight; - } + get => VisualProperty.GridLineThickness / scaleValue; + } public string CanvasViewportSize { get { - string s = visualProperty.GridSize.ToString(); + string s = VisualProperty.GridSize.ToString(); s = s.Replace(',', '.'); return $"0,0,{s},{s}"; } } - public double GridSize { get => visualProperty.GridSize; } + public double GridSize => VisualProperty.GridSize; public ObservableCollection HeadMaterials { @@ -129,26 +116,22 @@ namespace StructureHelper.Windows.MainWindow } } - public double XX2 - { - get => xX2; - set => OnPropertyChanged(value, ref xX2); - } - public double XY1 - { - get => xY1; - set => OnPropertyChanged(value, ref xY1); - } - public double YX1 - { - get => yX1; - set => OnPropertyChanged(value, ref yX1); - } - public double YY2 - { - get => yY2; - set => OnPropertyChanged(value, ref yY2); - } + /// + /// Right edge of work plane, coordinate X + /// + public double RightLimitX => VisualProperty.WorkPlainWidth; + /// + /// Bottom edge of work plane Y + /// + public double BottomLimitY => VisualProperty.WorkPlainHeight; + /// + /// Middle of coordinate X + /// + public double MiddleLimitX => VisualProperty.WorkPlainWidth / 2d; + /// + /// Middle of coordinate Y + /// + public double MiddleLimitY => VisualProperty.WorkPlainHeight / 2d; public ICommand Calculate { get; } public ICommand EditCalculationPropertyCommand { get; } @@ -160,7 +143,7 @@ namespace StructureHelper.Windows.MainWindow return new RelayCommand(o => { PrimitiveLogic.AddItems(GetRCCirclePrimitives()); - materialsLogic.Refresh(); + MaterialsLogic.Refresh(); }); } } @@ -189,11 +172,18 @@ namespace StructureHelper.Windows.MainWindow return showVisualProperty ?? (showVisualProperty = new RelayCommand(o=> { - var wnd = new VisualPropertyView(visualProperty); + var wnd = new VisualPropertyView(VisualProperty); wnd.ShowDialog(); OnPropertyChanged(nameof(AxisLineThickness)); OnPropertyChanged(nameof(CanvasViewportSize)); OnPropertyChanged(nameof(GridSize)); + OnPropertyChanged(nameof(RightLimitX)); + OnPropertyChanged(nameof(BottomLimitY)); + OnPropertyChanged(nameof(MiddleLimitX)); + OnPropertyChanged(nameof(MiddleLimitY)); + PrimitiveLogic.WorkPlaneWidth = VisualProperty.WorkPlainWidth; + PrimitiveLogic.WorkPlaneHeight = VisualProperty.WorkPlainHeight; + PrimitiveLogic.Refresh(); })); } } @@ -214,27 +204,24 @@ namespace StructureHelper.Windows.MainWindow } private double delta = 0.0005; - private ActionsViewModel combinationsLogic; - private PrimitiveViewModelLogic primitiveLogic; private RelayCommand showVisualProperty; private RelayCommand selectPrimitive; - private MaterialsViewModel materialsLogic; public CrossSectionViewModel(CrossSectionModel model) { - visualProperty = new CrossSectionViewVisualProperty(); + VisualProperty = new CrossSectionVisualPropertyVM(); Model = model; section = model.Section; - combinationsLogic = new ActionsViewModel(repository); - materialsLogic = new MaterialsViewModel(repository); - materialsLogic.AfterItemsEdit += afterMaterialEdit; - calculatorsLogic = new AnalysisVewModelLogic(repository); - primitiveLogic = new PrimitiveViewModelLogic(section) { CanvasWidth = CanvasWidth, CanvasHeight = CanvasHeight }; - XX2 = CanvasWidth; - XY1 = CanvasHeight / 2d; - YX1 = CanvasWidth / 2d; - YY2 = CanvasHeight; - scaleValue = 300d; + CombinationsLogic = new ActionsViewModel(repository); + MaterialsLogic = new MaterialsViewModel(repository); + MaterialsLogic.AfterItemsEdit += afterMaterialEdit; + CalculatorsLogic = new AnalysisVewModelLogic(repository); + PrimitiveLogic = new PrimitiveViewModelLogic(section) + { + WorkPlaneWidth = VisualProperty.WorkPlainWidth, + WorkPlaneHeight = VisualProperty.WorkPlainHeight + }; + scaleValue = 500d; LeftButtonUp = new RelayCommand(o => { @@ -260,13 +247,6 @@ namespace StructureHelper.Windows.MainWindow } }); - //SetColor = new RelayCommand(o => - //{ - // var primitive = o as PrimitiveBase; - // var colorPickerView = new ColorPickerView(primitive); - // colorPickerView.ShowDialog(); - //}); - ScaleCanvasDown = new RelayCommand(o => { ScrollPanelX = PanelX; @@ -284,19 +264,19 @@ namespace StructureHelper.Windows.MainWindow AddBeamCase = new RelayCommand(o => { PrimitiveLogic.AddItems(GetBeamCasePrimitives()); - materialsLogic.Refresh(); + MaterialsLogic.Refresh(); }); AddColumnCase = new RelayCommand(o => { PrimitiveLogic.AddItems(GetColumnCasePrimitives()); - materialsLogic.Refresh(); + MaterialsLogic.Refresh(); }); AddSlabCase = new RelayCommand(o => { PrimitiveLogic.AddItems(GetSlabCasePrimitives()); - materialsLogic.Refresh(); + MaterialsLogic.Refresh(); }); MovePrimitiveToGravityCenterCommand = new RelayCommand(o => @@ -328,7 +308,7 @@ namespace StructureHelper.Windows.MainWindow private void afterMaterialEdit(SelectItemVM sender, CRUDVMEventArgs e) { - foreach (var primitive in primitiveLogic.Items) + foreach (var primitive in PrimitiveLogic.Items) { primitive.RefreshColor(); } @@ -336,7 +316,7 @@ namespace StructureHelper.Windows.MainWindow private bool CheckMaterials() { - foreach (var item in primitiveLogic.Items) + foreach (var item in PrimitiveLogic.Items) { if (item.HeadMaterial == null) { @@ -400,7 +380,7 @@ namespace StructureHelper.Windows.MainWindow var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives); foreach (var item in primitives) { - item.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2); + item.RegisterDeltas(VisualProperty.WorkPlainWidth / 2, VisualProperty.WorkPlainHeight / 2); } PrimitiveLogic.Refresh(); foreach (var item in newRepository.HeadMaterials) diff --git a/StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs b/StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs new file mode 100644 index 0000000..b5d10d6 --- /dev/null +++ b/StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs @@ -0,0 +1,83 @@ +using StructureHelper.Infrastructure; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelper.Windows.MainWindow +{ + public class CrossSectionVisualPropertyVM : ViewModelBase + { + private double axisLineThickness; + private double gridLineThickness; + private double gridSize; + private double workPlainWidth; + private double workPlainHeight; + + /// + /// Thickness of x-, and y- axis line + /// + public double AxisLineThickness + { + get => axisLineThickness; set + { + axisLineThickness = value; + OnPropertyChanged(nameof(AxisLineThickness)); + } + } + /// + /// Thickness of lines of coordinate mesh + /// + public double GridLineThickness + { + get => gridLineThickness; set + { + gridLineThickness = value; + OnPropertyChanged(nameof(GridLineThickness)); + } + } + /// + /// Size of coordinate mesh + /// + public double GridSize + { + get => gridSize; set + { + gridSize = value; + OnPropertyChanged(nameof(GridSize)); + } + } + /// + /// Width of work plane + /// + public double WorkPlainWidth + { + get => workPlainWidth; set + { + workPlainWidth = value; + OnPropertyChanged(nameof(WorkPlainWidth)); + } + } + /// + /// Height of work plane + /// + public double WorkPlainHeight + { + get => workPlainHeight; set + { + workPlainHeight = value; + OnPropertyChanged(nameof(WorkPlainHeight)); + } + } + + public CrossSectionVisualPropertyVM() + { + AxisLineThickness = 2d; + GridLineThickness = 0.25d; + GridSize = 0.05d; + WorkPlainWidth = 1.2d; + WorkPlainHeight = 1.2d; + } + } +} diff --git a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml b/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml index e5cff22..f29ca80 100644 --- a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml +++ b/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml @@ -4,10 +4,14 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow" + d:DataContext="{d:DesignInstance local:CrossSectionVisualPropertyVM}" mc:Ignorable="d" Title="Grid properies" Height="200" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> + + + @@ -18,7 +22,13 @@ - + + + + + + + diff --git a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs b/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs index 4a15149..029214b 100644 --- a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs +++ b/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs @@ -1,5 +1,4 @@ -using StructureHelper.Windows.ViewModels.NdmCrossSections; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -20,7 +19,7 @@ namespace StructureHelper.Windows.MainWindow /// public partial class VisualPropertyView : Window { - public VisualPropertyView(CrossSectionViewVisualProperty vm) + public VisualPropertyView(CrossSectionVisualPropertyVM vm) { InitializeComponent(); DataContext = vm; diff --git a/StructureHelper/Windows/Services/CopyByParameterViewModel.cs b/StructureHelper/Windows/Services/CopyByParameterViewModel.cs index 6b6877f..f541cbf 100644 --- a/StructureHelper/Windows/Services/CopyByParameterViewModel.cs +++ b/StructureHelper/Windows/Services/CopyByParameterViewModel.cs @@ -81,7 +81,7 @@ namespace StructureHelper.Windows.Services } private void RefreshAngle() { - Angle = Math.Atan2(deltaX, deltaY) * 180d / Math.PI - 90d; + Angle = Math.Atan2(deltaX, deltaY * (-1)) * 180d / Math.PI - 90d; Angle = Math.Round(Angle, 1); Distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY); Distance = Math.Round(Distance, 3); diff --git a/StructureHelper/Windows/ViewModels/NdmCrossSections/CrossSectionViewVisualProperty.cs b/StructureHelper/Windows/ViewModels/NdmCrossSections/CrossSectionViewVisualProperty.cs deleted file mode 100644 index e41f9a4..0000000 --- a/StructureHelper/Windows/ViewModels/NdmCrossSections/CrossSectionViewVisualProperty.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StructureHelper.Windows.ViewModels.NdmCrossSections -{ - public class CrossSectionViewVisualProperty - { - public double AxisLineThickness { get; set; } - public double GridLineThickness { get; set; } - public double GridSize { get; set; } - public double WorkPlainWidth { get; set; } - public double WorkPlainHeight { get; set; } - - public CrossSectionViewVisualProperty() - { - AxisLineThickness = 2d; - GridLineThickness = 0.25d; - GridSize = 0.05d; - WorkPlainWidth = 2.4d; - WorkPlainHeight = 2.0d; - } - } -} diff --git a/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs b/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs index 353086d..1fe12a3 100644 --- a/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs +++ b/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs @@ -1,26 +1,21 @@ -using FieldVisualizer.ViewModels; +using StructureHelper.Infrastructure; +using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.UI.DataContexts; +using StructureHelper.Windows.PrimitiveProperiesWindow; +using StructureHelper.Windows.Services; +using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperLogics.Models.CrossSections; +using StructureHelperLogics.Models.Primitives; +using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Primitives; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using StructureHelper.Services.Primitives; -using StructureHelper.Infrastructure; -using StructureHelper.Infrastructure.Enums; -using StructureHelperCommon.Infrastructures.Exceptions; -using StructureHelperLogics.Models.Primitives; -using ViewModelBase = StructureHelper.Infrastructure.ViewModelBase; using System.Windows.Forms; -using System.Windows.Documents; -using StructureHelper.Windows.PrimitiveProperiesWindow; -using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using System.Windows.Input; -using StructureHelper.Windows.Services; -using StructureHelperCommon.Models.Shapes; + +//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia +//All rights reserved. namespace StructureHelper.Windows.ViewModels.NdmCrossSections { @@ -36,8 +31,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections private ICommand setToBack; private ICommand copyToCommand; - public double CanvasWidth { get; set; } - public double CanvasHeight { get; set; } + public double WorkPlaneWidth { get; set; } + public double WorkPlaneHeight { get; set; } public PrimitiveBase SelectedItem { get; set; } @@ -101,7 +96,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections viewPrimitive = new CircleViewPrimitive(primitive); } else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); } - viewPrimitive.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2); + viewPrimitive.RegisterDeltas(WorkPlaneWidth / 2, WorkPlaneHeight / 2); repository.Primitives.Add(ndmPrimitive); ndmPrimitive.CrossSection = section; Items.Add(viewPrimitive); @@ -244,7 +239,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections } else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); - primitiveBase.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2); + primitiveBase.RegisterDeltas(WorkPlaneWidth / 2, WorkPlaneHeight / 2); Items.Add(primitiveBase); OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(PrimitivesCount)); @@ -306,6 +301,11 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections public void Refresh() { + foreach (var item in Items) + { + item.RegisterDeltas(WorkPlaneWidth / 2, WorkPlaneHeight / 2); + item.Refresh(); + } OnPropertyChanged(nameof(PrimitivesCount)); } diff --git a/StructureHelperCommon/Models/Loggers/Factories/TraceTablesFactory.cs b/StructureHelperCommon/Models/Loggers/Factories/TraceTablesFactory.cs index 1fbda58..8df19df 100644 --- a/StructureHelperCommon/Models/Loggers/Factories/TraceTablesFactory.cs +++ b/StructureHelperCommon/Models/Loggers/Factories/TraceTablesFactory.cs @@ -24,8 +24,8 @@ namespace StructureHelperCommon.Models { var table = new TableLogEntry(2); table.Priority = Priority; - table.Table.AddRow(GetPointHeaderRow()); - table.Table.AddRow(GetPointRow(point2D)); + table.Table.AddRow(GetPoint2DHeaderRow()); + table.Table.AddRow(GetPoint2DRow(point2D)); return table; } /// @@ -50,10 +50,10 @@ namespace StructureHelperCommon.Models { var table = new TableLogEntry(2); table.Priority = Priority; - table.Table.AddRow(GetPointHeaderRow()); + table.Table.AddRow(GetPoint2DHeaderRow()); foreach (var item in points) { - table.Table.AddRow(GetPointRow(item)); + table.Table.AddRow(GetPoint2DRow(item)); } return table; } @@ -182,7 +182,7 @@ namespace StructureHelperCommon.Models return forceTupleRow; } - private ShTableRow GetPointHeaderRow() + private ShTableRow GetPoint2DHeaderRow() { const CellRole cellRole = CellRole.Header; @@ -213,7 +213,7 @@ namespace StructureHelperCommon.Models headerRow.Elements[1] = tableCell; return headerRow; } - private ShTableRow GetPointRow(IPoint2D point2D) + private ShTableRow GetPoint2DRow(IPoint2D point2D) { var pointRow = new ShTableRow(2); pointRow.Elements[0].Value = new StringLogEntry() diff --git a/StructureHelperCommon/Models/Loggers/ITraceLogger.cs b/StructureHelperCommon/Models/Loggers/ITraceLogger.cs index f4f8a4f..e22701e 100644 --- a/StructureHelperCommon/Models/Loggers/ITraceLogger.cs +++ b/StructureHelperCommon/Models/Loggers/ITraceLogger.cs @@ -11,5 +11,6 @@ namespace StructureHelperCommon.Models List TraceLoggerEntries { get; } void AddMessage(string message, TraceLogStatuses status = TraceLogStatuses.Info, int shiftPriority = 0); void AddMessage(string message, int priority); + bool KeepErrorStatus { get; set; } } } diff --git a/StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs b/StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs index a6ea08e..54c80ee 100644 --- a/StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs +++ b/StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs @@ -12,15 +12,18 @@ namespace StructureHelperCommon.Models public int ShiftPriority { get; set; } public List TraceLoggerEntries => Logger.TraceLoggerEntries; + public bool KeepErrorStatus { get => Logger.KeepErrorStatus; set => Logger.KeepErrorStatus = value; } + public ShiftTraceLogger(ITraceLogger logger) { Logger = logger; + KeepErrorStatus = true; } public ShiftTraceLogger() : this(new TraceLogger()) { } public void AddMessage(string message, TraceLogStatuses status = TraceLogStatuses.Info, int shiftPrioriry = 0) { // if status in (fatal, error, warning) they must be kept as they are - if (status <= TraceLogStatuses.Warning) + if (status <= TraceLogStatuses.Warning & KeepErrorStatus == true) { Logger.AddMessage(message, status); } diff --git a/StructureHelperCommon/Models/Loggers/TraceLogger.cs b/StructureHelperCommon/Models/Loggers/TraceLogger.cs index b2397d3..9477de3 100644 --- a/StructureHelperCommon/Models/Loggers/TraceLogger.cs +++ b/StructureHelperCommon/Models/Loggers/TraceLogger.cs @@ -11,10 +11,12 @@ namespace StructureHelperCommon.Models public class TraceLogger : ITraceLogger { public List TraceLoggerEntries { get; } + public bool KeepErrorStatus { get; set; } public TraceLogger() { TraceLoggerEntries = new(); + KeepErrorStatus = true; } public void AddMessage(string message, TraceLogStatuses status = TraceLogStatuses.Info, int shiftPrioriry = 0) diff --git a/StructureHelperCommon/Models/Shapes/Logics/ConstOneDirectionLogic.cs b/StructureHelperCommon/Models/Shapes/Logics/ConstOneDirectionLogic.cs index 9fd71f9..f849bdf 100644 --- a/StructureHelperCommon/Models/Shapes/Logics/ConstOneDirectionLogic.cs +++ b/StructureHelperCommon/Models/Shapes/Logics/ConstOneDirectionLogic.cs @@ -12,7 +12,7 @@ namespace StructureHelperCommon.Models.Shapes { private Directions constDirections; /// - /// Direction, for which canstant value is assigned + /// Direction, for which constant value is assigned /// public Directions ConstDirections { @@ -31,6 +31,8 @@ namespace StructureHelperCommon.Models.Shapes /// Constant value for assigned direction /// public double ConstDirectionValue { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } + public ConstOneDirectionLogic(Directions constDirection, double constValue) { ConstDirections = constDirection; @@ -39,18 +41,46 @@ namespace StructureHelperCommon.Models.Shapes /// public IPoint3D GetPoint3D(IPoint2D point2D) { + TraceLogger?.AddMessage($"Logic convert point from 2D-space to 3D-space"); IPoint3D point; if (ConstDirections == Directions.X) { - point = new Point3D() { X = ConstDirectionValue, Y = - point2D.X, Z = point2D.Y }; + point = new Point3D() + { + X = ConstDirectionValue, + Y = - point2D.X, + Z = point2D.Y + }; + TraceLogger?.AddMessage($"Constant direction is x-direction, so X = {point.X}"); + TraceLogger?.AddMessage($"X = ConstantValue = {point.X}"); + TraceLogger?.AddMessage($"Y = - point2D.X = {point.Y}"); + TraceLogger?.AddMessage($"Z = point2D.Y = {point.Z}"); } else if (ConstDirections == Directions.Y) { - point = new Point3D() { X = point2D.X, Y = ConstDirectionValue, Z = point2D.Y }; + point = new Point3D() + { + X = point2D.X, + Y = ConstDirectionValue, + Z = point2D.Y + }; + TraceLogger?.AddMessage($"Constant direction is Y-direction"); + TraceLogger?.AddMessage($"X = point2D.X = {point.X}"); + TraceLogger?.AddMessage($"Y = ConstantValue = {point.Y}"); + TraceLogger?.AddMessage($"Z = point2D.Y = {point.Z}"); } else if (ConstDirections == Directions.Z) { - point = new Point3D() { X = point2D.Y, Y = point2D.X, Z = ConstDirectionValue }; + point = new Point3D() + { + X = point2D.Y, + Y = point2D.X, + Z = ConstDirectionValue + }; + TraceLogger?.AddMessage($"Constant direction is Z-direction"); + TraceLogger?.AddMessage($"X = point2D.Y = {point.X}"); + TraceLogger?.AddMessage($"Y = point2D.X = {point.Y}"); + TraceLogger?.AddMessage($"Z = ConstantValue = {point.Z}"); } else { diff --git a/StructureHelperCommon/Models/Shapes/Logics/IConvert2DPointTo3DPointLogic.cs b/StructureHelperCommon/Models/Shapes/Logics/IConvert2DPointTo3DPointLogic.cs index fec870a..2f63d06 100644 --- a/StructureHelperCommon/Models/Shapes/Logics/IConvert2DPointTo3DPointLogic.cs +++ b/StructureHelperCommon/Models/Shapes/Logics/IConvert2DPointTo3DPointLogic.cs @@ -1,4 +1,5 @@ -using System; +using StructureHelperCommon.Infrastructures.Interfaces; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,7 +14,7 @@ namespace StructureHelperCommon.Models.Shapes /// /// Logic for convert 2DPoint of some plane to point of 3DSpace /// - public interface IConvert2DPointTo3DPointLogic + public interface IConvert2DPointTo3DPointLogic : ILogic { /// /// Returns point in 3D-space by 2D point in some workplane diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs index e3aa211..a4061b9 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs @@ -1,4 +1,5 @@ using LoaderCalculator.Data.Ndms; +using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Shapes; @@ -10,7 +11,12 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Fac public PredicateTypes PredicateType { get; set; } public IConvert2DPointTo3DPointLogic ConvertLogic { get; set; } public string Name { get; set; } - public ITraceLogger? TraceLogger { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } + + public object Clone() + { + throw new NotImplementedException(); + } public Predicate GetPredicate() { @@ -19,6 +25,11 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Fac Ndms = Ndms, ConvertLogic = ConvertLogic }; + if (TraceLogger is not null) + { + factory.TraceLogger = TraceLogger; + } + TraceLogger?.AddMessage($"Predicate factory was obtained succsefully", TraceLogStatuses.Debug); var predicateType = PredicateType; var predicate = factory.GetPredicate(predicateType); return predicate; diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs index acd1739..60681da 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs @@ -1,12 +1,12 @@ -using StructureHelperCommon.Models; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; using StructureHelperCommon.Models.Shapes; namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories { - public interface IGetPredicateLogic + public interface IGetPredicateLogic : ILogic, ICloneable { string Name { get; set; } Predicate GetPredicate(); - ITraceLogger? TraceLogger { get; set; } } } \ No newline at end of file diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/PredicateFactory.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/PredicateFactory.cs index 0fd688a..39717b8 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/PredicateFactory.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/PredicateFactory.cs @@ -1,5 +1,8 @@ -using LoaderCalculator.Data.Ndms; +using LoaderCalculator; +using LoaderCalculator.Data.Ndms; using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.NdmCalculations.Cracking; @@ -14,13 +17,17 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces Strength, Cracking } - public class PredicateFactory + public class PredicateFactory : ILogic { private ForceTupleCalculator calculator; private ForceTuple tuple; private ForceTupleInputData inputData; + private IShiftTraceLogger logger; + public IEnumerable Ndms { get; set; } public IConvert2DPointTo3DPointLogic ConvertLogic { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } + public PredicateFactory() { inputData = new(); @@ -28,6 +35,12 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces } public Predicate GetPredicate(PredicateTypes predicateType) { + if (TraceLogger is not null) + { + logger = new ShiftTraceLogger() { ShiftPriority = 500, KeepErrorStatus = false }; + //calculator.TraceLogger = logger; // too much results + //ConvertLogic.TraceLogger = logger; //wrong work in different threads + } if (predicateType == PredicateTypes.Strength) { return point2D => IsSectionFailure(point2D); @@ -44,6 +57,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces private bool IsSectionFailure(IPoint2D point2D) { + logger?.TraceLoggerEntries.Clear(); var point3D = ConvertLogic.GetPoint3D(point2D); tuple = new() { @@ -54,12 +68,17 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces inputData.Tuple = tuple; inputData.NdmCollection = Ndms; calculator.Run(); + if (logger is not null) + { + TraceLogger?.TraceLoggerEntries.AddRange(logger.TraceLoggerEntries); + } var result = calculator.Result; return !result.IsValid; } private bool IsSectionCracked(IPoint2D point2D) { + logger?.TraceLoggerEntries.Clear(); var logic = new HoleSectionCrackedLogic(); var point3D = ConvertLogic.GetPoint3D(point2D); tuple = new() @@ -72,6 +91,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces logic.NdmCollection = Ndms; try { + if (logger is not null) + { + TraceLogger?.TraceLoggerEntries.AddRange(logger.TraceLoggerEntries); + } var result = logic.IsSectionCracked(); return result; } diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs index 9c1f024..e160803 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs @@ -33,7 +33,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces /// public List GetPoints(IEnumerable points) { - if (TraceLogger is not null) { ParameterLogic.TraceLogger = TraceLogger; } + if (TraceLogger is not null) + { + ParameterLogic.TraceLogger = TraceLogger; + } result = new(); resultList = new(); TraceLogger?.AddMessage($"Predicate name is {GetPredicateLogic.Name}"); @@ -74,12 +77,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces private Point2D FindResultPoint(IPoint2D point) { - Predicate limitPredicate; - lock (lockObject) - { - limitPredicate = GetPredicateLogic.GetPredicate(); - } - var resultPoint = FindResultPointByPredicate(point, limitPredicate); + var resultPoint = FindResultPointByPredicate(point); lock (lockObject) { pointCount++; @@ -89,14 +87,23 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces return resultPoint; } - private Point2D FindResultPointByPredicate(IPoint2D point, Predicate limitPredicate) + private Point2D FindResultPointByPredicate(IPoint2D point) { + ShiftTraceLogger newLogger; + Predicate limitPredicate; + + lock (lockObject) + { + newLogger = new ShiftTraceLogger() + { + ShiftPriority = 100 + }; + GetPredicateLogic.TraceLogger = newLogger; + limitPredicate = GetPredicateLogic.GetPredicate(); + } var localCurrentPoint = point.Clone() as IPoint2D; var logic = ParameterLogic.Clone() as ILimitCurveParameterLogic; - logic.TraceLogger = new ShiftTraceLogger() - { - ShiftPriority=100 - }; + logic.TraceLogger = newLogger; logic.CurrentPoint = localCurrentPoint; logic.LimitPredicate = limitPredicate; double parameter; @@ -119,7 +126,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { TraceLogger?.AddMessage($"Source point"); TraceLogger?.AddEntry(new TraceTablesFactory(TraceLogStatuses.Info).GetByPoint2D(localCurrentPoint)); - TraceLogger?.TraceLoggerEntries.AddRange(logic.TraceLogger.TraceLoggerEntries); + TraceLogger?.TraceLoggerEntries.AddRange(newLogger.TraceLoggerEntries); TraceLogger?.AddMessage($"Parameter value {parameter} was obtained"); TraceLogger?.AddMessage($"Calculated point\n(X={localCurrentPoint.X} * {parameter} = {resultPoint.X},\nY={localCurrentPoint.Y} * {parameter} = {resultPoint.Y})"); TraceLogger?.AddEntry(new TraceTablesFactory(TraceLogStatuses.Info).GetByPoint2D(resultPoint)); diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs index cbb0425..f88eff2 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs @@ -106,7 +106,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces ConvertLogic = InputData.SurroundData.ConvertLogicEntity.ConvertLogic, PredicateType = predicateType }; - if (TraceLogger is not null) { getPredicateLogic.TraceLogger = TraceLogger; } + if (TraceLogger is not null) + { + //getPredicateLogic.TraceLogger = TraceLogger; + } var logic = new LimitCurveLogic(getPredicateLogic); var calculator = new LimitCurveCalculator(logic) { diff --git a/StructureHelperLogics/NdmCalculations/Cracking/ExpSofteningLogic.cs b/StructureHelperLogics/NdmCalculations/Cracking/ExpSofteningLogic.cs index 48773f7..65f2c63 100644 --- a/StructureHelperLogics/NdmCalculations/Cracking/ExpSofteningLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Cracking/ExpSofteningLogic.cs @@ -6,6 +6,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia +//All rights reserved. + namespace StructureHelperLogics.NdmCalculations.Cracking { public class ExpSofteningLogic : ICrackSofteningLogic @@ -25,6 +28,9 @@ namespace StructureHelperLogics.NdmCalculations.Cracking powerFactor = value; } } + /// + /// Factor betta in exponential softening model of reinforced concrete + /// public double BettaFactor { get; set; } public double ForceRatio { @@ -42,6 +48,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking forceRatio = value; } } + /// public double PsiSMin {get;set;} public IShiftTraceLogger? TraceLogger { get; set; } @@ -51,6 +58,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking PowerFactor = 2d; BettaFactor = 0.8d; } + /// public double GetSofteningFactor() { TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLogStatuses.Service); @@ -59,7 +67,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking TraceLogger?.AddMessage($"But not less than psi_s_min = {PsiSMin}"); TraceLogger?.AddMessage($"BettaFactor = {BettaFactor}"); TraceLogger?.AddMessage($"ForceRatio = {ForceRatio}"); - TraceLogger?.AddMessage($"PowerFactor = {BettaFactor}"); + TraceLogger?.AddMessage($"PowerFactor = {PowerFactor}"); double psi; psi = 1 - BettaFactor * Math.Pow(ForceRatio, PowerFactor); TraceLogger?.AddMessage($"psi_s = 1 - BettaFactor * ForceRatio ^ PowerFactor = 1 - {BettaFactor} * {ForceRatio} ^ {PowerFactor} = {psi}");