From 45dc56a63e87f5d1f1f4760a75371ec7a28c04b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=98=D0=B2=D0=B0=D1=88=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Tue, 4 Mar 2025 14:11:41 +0500 Subject: [PATCH] Binding function by states and terms done --- .../Graphs/MaterialDiagramViewModel.cs | 2 +- .../Materials/MaterialsViewModel.cs | 16 +++++-- .../Infrastructures/Commands/RelayCommand.cs | 32 ++++++++++++++ .../Models/Functions/FunctionStorage.cs | 20 +++++++++ .../Windows/FunctionSelectionVM.cs | 40 ++++++++++++++++- .../Windows/FunctionSelectionView.xaml | 13 +++++- .../Windows/FunctionSelectionView.xaml.cs | 6 +-- .../Factories/HeadMaterialFactory.cs | 12 ++++- .../Models/Materials/FunctionMaterial.cs | 3 +- .../Models/Materials/HeadMaterial.cs | 2 +- .../Models/Materials/IFunctionMaterial.cs | 2 + .../Materials/Logics/FunctionMaterialLogic.cs | 44 +++++++++++++------ 12 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 StructureHelperCommon/Infrastructures/Commands/RelayCommand.cs create mode 100644 StructureHelperCommon/Models/Functions/FunctionStorage.cs diff --git a/StructureHelper/Windows/Graphs/MaterialDiagramViewModel.cs b/StructureHelper/Windows/Graphs/MaterialDiagramViewModel.cs index 47d295d..a91d0de 100644 --- a/StructureHelper/Windows/Graphs/MaterialDiagramViewModel.cs +++ b/StructureHelper/Windows/Graphs/MaterialDiagramViewModel.cs @@ -175,7 +175,7 @@ namespace StructureHelper.Windows.Graphs for (double s = minValue; s < maxValue; s += step) { double strain = s * factor; - double diagramValue = loaderMaterial.Diagram.Invoke(loaderMaterial.DiagramParameters, strain) * factor; //!!!!!!!!!!!!!!!!!!!! + double diagramValue = loaderMaterial.Diagram.Invoke(loaderMaterial.DiagramParameters, strain) * factor; StressEntity stressEntity = new() { LimitState = limitState, diff --git a/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs b/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs index 56a34f4..bf0d2a6 100644 --- a/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs +++ b/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs @@ -43,8 +43,11 @@ namespace StructureHelper.Windows.ViewModels.Materials else if (parameterType == MaterialType.GlassFiber) { AddGlassFiber(); } else if (parameterType == MaterialType.Function) { AddFunctionMaterial(); } else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $". Expected: {typeof(MaterialType)}, Actual type: {nameof(parameterType)}"); - GlobalRepository.Materials.Create(NewItem); - base.AddMethod(parameter); + if (!(NewItem is null)) + { + GlobalRepository.Materials.Create(NewItem); + base.AddMethod(parameter); + } } public override void DeleteMethod(object parameter) { @@ -123,7 +126,14 @@ namespace StructureHelper.Windows.ViewModels.Materials { var material = HeadMaterialFactory.GetHeadMaterial(HeadmaterialType.Function); material.Name = "New Function Material"; - NewItem = material; + if ((material as HeadMaterial).SuccessfullyCreated) + { + NewItem = material; + } + else + { + NewItem = null; + } } private void CheckParameters(object parameter) { diff --git a/StructureHelperCommon/Infrastructures/Commands/RelayCommand.cs b/StructureHelperCommon/Infrastructures/Commands/RelayCommand.cs new file mode 100644 index 0000000..f068435 --- /dev/null +++ b/StructureHelperCommon/Infrastructures/Commands/RelayCommand.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace StructureHelperCommon.Infrastructures.Commands +{ + public class RelayCommand : ICommand + { + private Action execute; + private Func canExecute; + + public event EventHandler CanExecuteChanged + { + add => CommandManager.RequerySuggested += value; + remove => CommandManager.RequerySuggested -= value; + } + + public RelayCommand(Action execute, Func canExecute = null) + { + this.execute = execute; + this.canExecute = canExecute; + } + + public bool CanExecute(object parameter) => canExecute == null || canExecute(parameter); + + public void Execute(object parameter) => execute(parameter); + } + +} diff --git a/StructureHelperCommon/Models/Functions/FunctionStorage.cs b/StructureHelperCommon/Models/Functions/FunctionStorage.cs new file mode 100644 index 0000000..798a57c --- /dev/null +++ b/StructureHelperCommon/Models/Functions/FunctionStorage.cs @@ -0,0 +1,20 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Functions +{ + public class FunctionStorage + { + public IOneVariableFunction Func_ST_ULS { get; set; } + public IOneVariableFunction Func_ST_SLS { get; set; } + public IOneVariableFunction Func_ST_Special { get; set; } + public IOneVariableFunction Func_LT_ULS { get; set; } + public IOneVariableFunction Func_LT_SLS { get; set; } + public IOneVariableFunction Func_LT_Special { get; set; } + + } +} diff --git a/StructureHelperCommon/Windows/FunctionSelectionVM.cs b/StructureHelperCommon/Windows/FunctionSelectionVM.cs index cb7c89d..52655da 100644 --- a/StructureHelperCommon/Windows/FunctionSelectionVM.cs +++ b/StructureHelperCommon/Windows/FunctionSelectionVM.cs @@ -1,4 +1,5 @@ -using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Infrastructures.Commands; +using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models.Functions; using System; @@ -7,17 +8,54 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; namespace StructureHelperCommon.Windows { public class FunctionSelectionVM { + private RelayCommand createFunctionMaterialCommand; + public ICommand CreateFunctionMaterialCommand + { + get => createFunctionMaterialCommand ??= new RelayCommand(o => CreateFunctionMaterial(o)); + } public string SHORT_TERM { get; } = "Short Term"; public string LONG_TERM { get; } = "Long Term"; public string ULS { get; } = "Ultimate Limit State (ULS)"; public string SLS { get; } = "Serviceability Limit State (SLS)"; public string SPECIAL { get; } = "Special Limit State"; public string CREATE_MATERIAL { get; } = "Create Function Material"; + private const string ERROR_TEXT_1 = "Not all material states have functions "; public ObservableCollection Functions { get; set; } = ProgramSetting.Functions; + public IOneVariableFunction Func_ST_ULS { get; set; } + public IOneVariableFunction Func_ST_SLS { get; set; } + public IOneVariableFunction Func_ST_Special { get; set; } + public IOneVariableFunction Func_LT_ULS { get; set; } + public IOneVariableFunction Func_LT_SLS { get; set; } + public IOneVariableFunction Func_LT_Special { get; set; } + public FunctionStorage FunctionStorage { get; set; } = new(); + private void CreateFunctionMaterial(object parameter) + { + var window = parameter as Window; + if (Func_ST_ULS == null || + Func_ST_SLS == null || + Func_ST_Special == null || + Func_LT_ULS == null || + Func_LT_SLS == null || + Func_LT_Special == null) + { + MessageBox.Show($"{ERROR_TEXT_1}"); + return; + } + FunctionStorage.Func_ST_ULS = Func_ST_ULS; + FunctionStorage.Func_ST_SLS = Func_ST_SLS; + FunctionStorage.Func_ST_Special = Func_ST_Special; + FunctionStorage.Func_LT_ULS = Func_LT_ULS; + FunctionStorage.Func_LT_SLS = Func_LT_SLS; + FunctionStorage.Func_LT_Special = Func_LT_Special; + window.DialogResult = true; + window.Close(); + } } } diff --git a/StructureHelperCommon/Windows/FunctionSelectionView.xaml b/StructureHelperCommon/Windows/FunctionSelectionView.xaml index d1a8aeb..4a95d35 100644 --- a/StructureHelperCommon/Windows/FunctionSelectionView.xaml +++ b/StructureHelperCommon/Windows/FunctionSelectionView.xaml @@ -1,4 +1,5 @@  + Grid.Column="1" Grid.Row="1" + SelectedItem="{Binding Func_ST_ULS}"/>