From decbc10f51f041aef7872a5031ba37b41cb0663a 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: Sat, 26 Apr 2025 23:07:18 +0500 Subject: [PATCH] Change ObsCollection to List in Common, write FunctionMaterialCreationVM, remove old UI, binding enums and functions to new UI. --- .../Windows/MainGraph/GraphViewModel.cs | 4 +- StructureHelper/Windows/TreeGraph/Database.cs | 4 +- .../Interfaces/FunctionDecorator.cs | 2 +- .../Interfaces/IOneVariableFunction.cs | 2 +- .../Settings/ProgramSetting.cs | 2 +- .../Models/Functions/FormulaFunction.cs | 2 +- .../Models/Functions/TableFunction.cs | 2 +- .../Models/Materials/MaterialSettings.cs | 1 + .../StructureHelperCommon.csproj.user | 6 - .../Windows/FunctionMaterialCreationVM.cs | 177 +++++++++++++++--- .../Windows/FunctionMaterialCreationView.xaml | 112 ++++++----- .../FunctionMaterialCreationView.xaml.cs | 2 + .../Windows/FunctionSelectionVM.cs | 84 --------- .../Windows/FunctionSelectionView.xaml | 95 ---------- .../Windows/FunctionSelectionView.xaml.cs | 33 ---- .../Factories/HeadMaterialFactory.cs | 1 - .../Models/Materials/FunctionMaterial.cs | 1 - .../Models/Materials/IFunctionMaterial.cs | 3 +- .../Materials/Logics/FunctionMaterialLogic.cs | 38 +--- 19 files changed, 237 insertions(+), 334 deletions(-) delete mode 100644 StructureHelperCommon/Windows/FunctionSelectionVM.cs delete mode 100644 StructureHelperCommon/Windows/FunctionSelectionView.xaml delete mode 100644 StructureHelperCommon/Windows/FunctionSelectionView.xaml.cs diff --git a/StructureHelper/Windows/MainGraph/GraphViewModel.cs b/StructureHelper/Windows/MainGraph/GraphViewModel.cs index b391a1e..101b098 100644 --- a/StructureHelper/Windows/MainGraph/GraphViewModel.cs +++ b/StructureHelper/Windows/MainGraph/GraphViewModel.cs @@ -118,7 +118,7 @@ namespace StructureHelper.Windows.MainGraph } public GraphViewModel() { - Functions = ProgramSetting.Functions; + Functions = new ObservableCollection(ProgramSetting.Functions); } private void AddTable() { @@ -226,7 +226,7 @@ namespace StructureHelper.Windows.MainGraph } public void Save() { - ProgramSetting.Functions = Functions; + ProgramSetting.Functions = new List(Functions); } } } diff --git a/StructureHelper/Windows/TreeGraph/Database.cs b/StructureHelper/Windows/TreeGraph/Database.cs index fe58200..37ae46d 100644 --- a/StructureHelper/Windows/TreeGraph/Database.cs +++ b/StructureHelper/Windows/TreeGraph/Database.cs @@ -16,7 +16,7 @@ namespace StructureHelper.Windows.TreeGraph return new TableFunction() { Name = "func0", - Functions = new ObservableCollection() + Functions = new List() { new FormulaFunction() { @@ -29,7 +29,7 @@ namespace StructureHelper.Windows.TreeGraph new FormulaFunction() { Name = "func1.3", - Functions = new ObservableCollection() + Functions = new List() { new FormulaFunction() { diff --git a/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs b/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs index 9657210..73afce8 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs @@ -26,7 +26,7 @@ namespace StructureHelperCommon.Infrastructures.Interfaces public List Table { get; set; } public double MinArg { get; set; } public double MaxArg { get; set; } - public ObservableCollection Functions { get; set; } = new ObservableCollection(); + public List Functions { get; set; } = new List(); public Guid Id => throw new NotImplementedException(); diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs index ef7c3ee..fd45d92 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs @@ -28,7 +28,7 @@ namespace StructureHelperCommon.Infrastructures.Interfaces public double MaxArg { get; set; } public Color Color { get; set; } public string Trace { get; set; } - public ObservableCollection Functions { get; set; } + public List Functions { get; set; } public bool Check(); public double GetByX(double xValue); diff --git a/StructureHelperCommon/Infrastructures/Settings/ProgramSetting.cs b/StructureHelperCommon/Infrastructures/Settings/ProgramSetting.cs index 3998b8b..7c4133a 100644 --- a/StructureHelperCommon/Infrastructures/Settings/ProgramSetting.cs +++ b/StructureHelperCommon/Infrastructures/Settings/ProgramSetting.cs @@ -94,7 +94,7 @@ namespace StructureHelperCommon.Infrastructures.Settings SubVersionNumber = 0 }; } - public static ObservableCollection Functions { get; set; } = new ObservableCollection + public static List Functions { get; set; } = new List { new TableFunction() { diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs index 1e48cdd..53472ba 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -57,7 +57,7 @@ namespace StructureHelperCommon.Models.Functions } } public Guid Id => throw new NotImplementedException(); - public ObservableCollection Functions { get; set; } = new ObservableCollection(); + public List Functions { get; set; } = new List(); public double MinArg { get; set; } public double MaxArg { get; set; } public IShiftTraceLogger? TraceLogger { get; set; } diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs index 2e6dab2..4e99e08 100644 --- a/StructureHelperCommon/Models/Functions/TableFunction.cs +++ b/StructureHelperCommon/Models/Functions/TableFunction.cs @@ -31,7 +31,7 @@ namespace StructureHelperCommon.Models.Functions public string Description { get; set; } public List Table { get; set; } public Guid Id => throw new NotImplementedException(); - public ObservableCollection Functions { get; set; } = new ObservableCollection(); + public List Functions { get; set; } = new List(); public double MinArg { get; set; } public double MaxArg { get; set; } public IShiftTraceLogger? TraceLogger { get; set; } diff --git a/StructureHelperCommon/Models/Materials/MaterialSettings.cs b/StructureHelperCommon/Models/Materials/MaterialSettings.cs index e41ada2..08cab2e 100644 --- a/StructureHelperCommon/Models/Materials/MaterialSettings.cs +++ b/StructureHelperCommon/Models/Materials/MaterialSettings.cs @@ -10,6 +10,7 @@ namespace StructureHelperCommon.Models.Materials { public class MaterialSettings { + public int Number { get; set; } public bool IsActive { get; set; } public LimitStates LimitState { get; set; } public CalcTerms CalcTerm { get; set; } diff --git a/StructureHelperCommon/StructureHelperCommon.csproj.user b/StructureHelperCommon/StructureHelperCommon.csproj.user index 5ab7385..c71f080 100644 --- a/StructureHelperCommon/StructureHelperCommon.csproj.user +++ b/StructureHelperCommon/StructureHelperCommon.csproj.user @@ -5,16 +5,10 @@ Code - - Code - Designer - - Designer - \ No newline at end of file diff --git a/StructureHelperCommon/Windows/FunctionMaterialCreationVM.cs b/StructureHelperCommon/Windows/FunctionMaterialCreationVM.cs index fdca4a9..f8ce5a4 100644 --- a/StructureHelperCommon/Windows/FunctionMaterialCreationVM.cs +++ b/StructureHelperCommon/Windows/FunctionMaterialCreationVM.cs @@ -4,6 +4,7 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Materials; +using StructureHelperCommon.Models.Sections.Logics; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -11,34 +12,93 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; using System.Windows.Input; namespace StructureHelperCommon.Windows { public class FunctionMaterialCreationVM { + private ObservableCollection materialSettingsList = new() + { + new MaterialSettings() + { + Number = 1, + IsActive = true, + LimitState = Infrastructures.Enums.LimitStates.ULS, + CalcTerm = Infrastructures.Enums.CalcTerms.ShortTerm, + }, + new MaterialSettings() + { + Number = 2, + IsActive = true, + LimitState = Infrastructures.Enums.LimitStates.ULS, + CalcTerm = Infrastructures.Enums.CalcTerms.LongTerm, + }, + new MaterialSettings() + { + Number = 3, + IsActive = true, + LimitState = Infrastructures.Enums.LimitStates.SLS, + CalcTerm = Infrastructures.Enums.CalcTerms.ShortTerm, + }, + new MaterialSettings() + { + Number = 4, + IsActive = true, + LimitState = Infrastructures.Enums.LimitStates.SLS, + CalcTerm = Infrastructures.Enums.CalcTerms.LongTerm, + }, + + }; public string CREATE_MATERIAL { get; } = "Create Function Material"; - public string MODULUS_OF_ELASTICITY { get; } = "Modulus of elasticity = "; - - private const string ERROR_TEXT_1 = "Not all material states have functions "; + public string MODULUS_OF_ELASTYCITY { get; } = "Modulus ="; + public string ADD { get; } = "Add"; + public string DELETE { get; } = "Delete"; + private const string ERROR_TEXT_1 = "There are no active calculation states. Please activate at least one table row."; + private const string ERROR_TEXT_2_1 = "Not all active material states have functions:"; + private const string ERROR_TEXT_2_2 = "please fill in functions in these rows."; + private const string ERROR_TEXT_3_1 = "The material cannot be created because some calculation states are duplicated:"; + private const string ERROR_TEXT_3_2 = "please remove or disable some duplicated rows, each state must be unique."; private RelayCommand createFunctionMaterialCommand; + private RelayCommand addCommand; + private RelayCommand deleteCommand; public ICommand CreateFunctionMaterialCommand { get => createFunctionMaterialCommand ??= new RelayCommand(o => CreateFunctionMaterial(o)); } + public ICommand AddCommand + { + get => addCommand ??= new RelayCommand(o => Add()); + } + public ICommand DeleteCommand + { + get => deleteCommand ??= new RelayCommand(o => Delete(o)); + } public double Modulus { get; set; } = 2e11d; public ObservableCollection Functions { get; set; } = new ObservableCollection(); - public ObservableCollection MaterialSettingsList { get; set; } = new() { new MaterialSettings() }; + public ObservableCollection MaterialSettingsList + { + get + { + return materialSettingsList; + } + set + { + materialSettingsList = value; + } + } public FunctionMaterialCreationVM() { - var stressStrainFunctions = new ObservableCollection + var stressStrainFunctions = new List ( ProgramSetting.Functions .Where(x => x.FunctionPurpose == Infrastructures.Enums.FunctionPurpose.StressStrain) ); GetFunctionsFromTree(stressStrainFunctions); } - private void GetFunctionsFromTree(ObservableCollection stressStrainFunctions) + private void GetFunctionsFromTree(List stressStrainFunctions) { foreach (IOneVariableFunction func in stressStrainFunctions) { @@ -49,27 +109,94 @@ namespace StructureHelperCommon.Windows } } } + private void Add() + { + var ms = new MaterialSettings() + { + Number = MaterialSettingsList.Count + 1, + IsActive = true, + LimitState = Infrastructures.Enums.LimitStates.ULS, + CalcTerm = Infrastructures.Enums.CalcTerms.ShortTerm, + }; + MaterialSettingsList.Add(ms); + } + private void Delete(object parameter) + { + var dataGrid = parameter as DataGrid; + var items = dataGrid.SelectedItems; + var removeList = new List(); + if (items.Count > 0) + { + if (items.Count == MaterialSettingsList.Count) + { + var firstElement = MaterialSettingsList.First(); + MaterialSettingsList.Clear(); + MaterialSettingsList.Add(firstElement); + } + foreach (MaterialSettings item in items) + { + removeList.Add(item); + } + foreach (MaterialSettings item in removeList) + { + MaterialSettingsList.Remove(item); + } + } + else + { + if (MaterialSettingsList.Count > 1) + { + MaterialSettingsList.RemoveAt(MaterialSettingsList.Count - 1); + } + } + for (int i = 0; i < MaterialSettingsList.Count; i++) + { + MaterialSettingsList[i].Number = i + 1; + } + dataGrid.Items.Refresh(); + } 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(); + var window = parameter as Window; + var activeMaterialSettingsList = MaterialSettingsList.Where(x => x.IsActive == true).ToList(); + if (activeMaterialSettingsList.Count() < 1) + { + MessageBox.Show($"{ERROR_TEXT_1}"); + return; + } + var emptyFunctions = activeMaterialSettingsList.Where(x => x.Function == null).ToList(); + if (emptyFunctions.Count > 0) + { + var errorMessage = String.Empty; + foreach (MaterialSettings ms in emptyFunctions) + { + errorMessage += $"{ms.Number}, "; + } + MessageBox.Show($"{ERROR_TEXT_2_1}\n{errorMessage}\n{ERROR_TEXT_2_2}"); + return; + } + var duplicates = activeMaterialSettingsList + .GroupBy(x => new { x.LimitState, x.CalcTerm }) + .Where(g => g.Count() > 1) + .ToList(); + if (duplicates.Count > 0) + { + var errorMessage = String.Empty; + for (int i = 0; i < duplicates.Count; i++) + { + var group = duplicates[i]; + var errorNumbers = String.Empty; + foreach (MaterialSettings ms in group) + { + errorNumbers += $"{ms.Number}, "; + } + errorMessage += $"{errorNumbers}\n"; + } + MessageBox.Show($"{ERROR_TEXT_3_1}\n{errorMessage}\n{ERROR_TEXT_3_2}"); + return; + } + window.DialogResult = true; + window.Close(); } } diff --git a/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml b/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml index df89fd9..9890b35 100644 --- a/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml +++ b/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml @@ -6,14 +6,29 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:StructureHelperCommon.Windows" xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:ens="clr-namespace:StructureHelperCommon.Infrastructures.Enums" mc:Ignorable="d" Title="FunctionMaterial" Height="250" Width="860" d:DataContext="{d:DesignInstance local:FunctionMaterialCreationVM}" Background="LightYellow"> + + + + + + + + + + + + @@ -25,73 +40,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - + diff --git a/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml.cs b/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml.cs index e7000ef..dd58a47 100644 --- a/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml.cs +++ b/StructureHelperCommon/Windows/FunctionMaterialCreationView.xaml.cs @@ -25,6 +25,8 @@ namespace StructureHelperCommon.Windows this.ViewModel = viewModel; DataContext = this.ViewModel; InitializeComponent(); + FunctionCB.ItemsSource = viewModel.Functions; + FunctionCB.DisplayMemberPath = "FullName"; } public FunctionMaterialCreationView() : this(new FunctionMaterialCreationVM()) { diff --git a/StructureHelperCommon/Windows/FunctionSelectionVM.cs b/StructureHelperCommon/Windows/FunctionSelectionVM.cs deleted file mode 100644 index be4410d..0000000 --- a/StructureHelperCommon/Windows/FunctionSelectionVM.cs +++ /dev/null @@ -1,84 +0,0 @@ -using LiveCharts.Wpf; -using StructureHelperCommon.Infrastructures.Commands; -using StructureHelperCommon.Infrastructures.Interfaces; -using StructureHelperCommon.Infrastructures.Settings; -using StructureHelperCommon.Models.Functions; -using StructureHelperCommon.Models.Materials; -using System; -using System.Collections.Generic; -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; } = new ObservableCollection(); - 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(); - public ObservableCollection MaterialSettings { get; set; } = new(); - public FunctionSelectionVM() - { - var stressStrainFunctions = new ObservableCollection - ( - ProgramSetting.Functions - .Where(x => x.FunctionPurpose == Infrastructures.Enums.FunctionPurpose.StressStrain) - ); - GetFunctionsFromTree(stressStrainFunctions); - } - private void GetFunctionsFromTree(ObservableCollection stressStrainFunctions) - { - foreach (IOneVariableFunction func in stressStrainFunctions) - { - Functions.Add(func); - if (func.Functions.Count > 0) - { - GetFunctionsFromTree(func.Functions); - } - } - } - 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 deleted file mode 100644 index 207f670..0000000 --- a/StructureHelperCommon/Windows/FunctionSelectionView.xaml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -