Binding function by states and terms done

This commit is contained in:
Иван Ивашкин
2025-03-04 14:11:41 +05:00
parent 0a7a696b5f
commit 45dc56a63e
12 changed files with 165 additions and 27 deletions

View File

@@ -175,7 +175,7 @@ namespace StructureHelper.Windows.Graphs
for (double s = minValue; s < maxValue; s += step) for (double s = minValue; s < maxValue; s += step)
{ {
double strain = s * factor; 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() StressEntity stressEntity = new()
{ {
LimitState = limitState, LimitState = limitState,

View File

@@ -43,8 +43,11 @@ namespace StructureHelper.Windows.ViewModels.Materials
else if (parameterType == MaterialType.GlassFiber) { AddGlassFiber(); } else if (parameterType == MaterialType.GlassFiber) { AddGlassFiber(); }
else if (parameterType == MaterialType.Function) { AddFunctionMaterial(); } else if (parameterType == MaterialType.Function) { AddFunctionMaterial(); }
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $". Expected: {typeof(MaterialType)}, Actual type: {nameof(parameterType)}"); else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $". Expected: {typeof(MaterialType)}, Actual type: {nameof(parameterType)}");
GlobalRepository.Materials.Create(NewItem); if (!(NewItem is null))
base.AddMethod(parameter); {
GlobalRepository.Materials.Create(NewItem);
base.AddMethod(parameter);
}
} }
public override void DeleteMethod(object parameter) public override void DeleteMethod(object parameter)
{ {
@@ -123,7 +126,14 @@ namespace StructureHelper.Windows.ViewModels.Materials
{ {
var material = HeadMaterialFactory.GetHeadMaterial(HeadmaterialType.Function); var material = HeadMaterialFactory.GetHeadMaterial(HeadmaterialType.Function);
material.Name = "New Function Material"; material.Name = "New Function Material";
NewItem = material; if ((material as HeadMaterial).SuccessfullyCreated)
{
NewItem = material;
}
else
{
NewItem = null;
}
} }
private void CheckParameters(object parameter) private void CheckParameters(object parameter)
{ {

View File

@@ -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<object> execute;
private Func<object, bool> canExecute;
public event EventHandler CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter) => canExecute == null || canExecute(parameter);
public void Execute(object parameter) => execute(parameter);
}
}

View File

@@ -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; }
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Commands;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
using System; using System;
@@ -7,17 +8,54 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace StructureHelperCommon.Windows namespace StructureHelperCommon.Windows
{ {
public class FunctionSelectionVM 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 SHORT_TERM { get; } = "Short Term";
public string LONG_TERM { get; } = "Long Term"; public string LONG_TERM { get; } = "Long Term";
public string ULS { get; } = "Ultimate Limit State (ULS)"; public string ULS { get; } = "Ultimate Limit State (ULS)";
public string SLS { get; } = "Serviceability Limit State (SLS)"; public string SLS { get; } = "Serviceability Limit State (SLS)";
public string SPECIAL { get; } = "Special Limit State"; public string SPECIAL { get; } = "Special Limit State";
public string CREATE_MATERIAL { get; } = "Create Function Material"; public string CREATE_MATERIAL { get; } = "Create Function Material";
private const string ERROR_TEXT_1 = "Not all material states have functions ";
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = ProgramSetting.Functions; public ObservableCollection<IOneVariableFunction> 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();
}
} }
} }

View File

@@ -1,4 +1,5 @@
<Window x:Class="StructureHelperCommon.Windows.FunctionSelectionView" <Window x:Class="StructureHelperCommon.Windows.FunctionSelectionView"
x:Name="FunctionSelectionView_win"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -67,20 +68,28 @@
<TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding SLS}" Style="{StaticResource TextBlockStyle}"/> <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding SLS}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Grid.Column="3" Grid.Row="0" Text="{Binding SPECIAL}" Style="{StaticResource TextBlockStyle}"/> <TextBlock Grid.Column="3" Grid.Row="0" Text="{Binding SPECIAL}" Style="{StaticResource TextBlockStyle}"/>
<ComboBox Style="{StaticResource FuncComboBox}" <ComboBox Style="{StaticResource FuncComboBox}"
Grid.Column="1" Grid.Row="1"/> Grid.Column="1" Grid.Row="1"
SelectedItem="{Binding Func_ST_ULS}"/>
<ComboBox Style="{StaticResource FuncComboBox}" <ComboBox Style="{StaticResource FuncComboBox}"
SelectedItem="{Binding Func_LT_ULS}"
Grid.Column="1" Grid.Row="2"/> Grid.Column="1" Grid.Row="2"/>
<ComboBox Style="{StaticResource FuncComboBox}" <ComboBox Style="{StaticResource FuncComboBox}"
SelectedItem="{Binding Func_ST_SLS}"
Grid.Column="2" Grid.Row="1"/> Grid.Column="2" Grid.Row="1"/>
<ComboBox Style="{StaticResource FuncComboBox}" <ComboBox Style="{StaticResource FuncComboBox}"
SelectedItem="{Binding Func_LT_SLS}"
Grid.Column="2" Grid.Row="2"/> Grid.Column="2" Grid.Row="2"/>
<ComboBox Style="{StaticResource FuncComboBox}" <ComboBox Style="{StaticResource FuncComboBox}"
SelectedItem="{Binding Func_ST_Special}"
Grid.Column="3" Grid.Row="1"/> Grid.Column="3" Grid.Row="1"/>
<ComboBox Style="{StaticResource FuncComboBox}" <ComboBox Style="{StaticResource FuncComboBox}"
SelectedItem="{Binding Func_LT_Special}"
Grid.Column="3" Grid.Row="2"/> Grid.Column="3" Grid.Row="2"/>
<Button Grid.Column="3" <Button Grid.Column="3"
Grid.Row="3" Grid.Row="3"
Margin="10" Margin="10"
Content="{Binding CREATE_MATERIAL}"/> Content="{Binding CREATE_MATERIAL}"
Command="{Binding CreateFunctionMaterialCommand}"
CommandParameter="{Binding ElementName=FunctionSelectionView_win}"/>
</Grid> </Grid>
</Window> </Window>

View File

@@ -19,11 +19,11 @@ namespace StructureHelperCommon.Windows
/// </summary> /// </summary>
public partial class FunctionSelectionView : Window public partial class FunctionSelectionView : Window
{ {
private FunctionSelectionVM viewModel; public FunctionSelectionVM ViewModel { get; set; }
public FunctionSelectionView(FunctionSelectionVM viewModel) public FunctionSelectionView(FunctionSelectionVM viewModel)
{ {
this.viewModel = viewModel; this.ViewModel = viewModel;
DataContext = this.viewModel; DataContext = this.ViewModel;
InitializeComponent(); InitializeComponent();
} }
public FunctionSelectionView() : this(new FunctionSelectionVM()) public FunctionSelectionView() : this(new FunctionSelectionVM())

View File

@@ -111,7 +111,17 @@ namespace StructureHelperLogics.Models.Materials
var functionSelectionView = new FunctionSelectionView(); var functionSelectionView = new FunctionSelectionView();
functionSelectionView.ShowDialog(); functionSelectionView.ShowDialog();
var material = new HeadMaterial(); var material = new HeadMaterial();
material.HelperMaterial = new FunctionMaterial() { Modulus = 2e11d, CompressiveStrength = 4e8d, TensileStrength = 4e8d }; material.HelperMaterial = new FunctionMaterial()
{
Modulus = 2e11d,
CompressiveStrength = 4e8d,
TensileStrength = 4e8d,
FunctionStorage = functionSelectionView.ViewModel.FunctionStorage,
};
if (functionSelectionView.DialogResult == true)
{
material.SuccessfullyCreated = true;
}
return material; return material;
} }
} }

View File

@@ -2,6 +2,7 @@
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Functions;
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperLogics.Models.Materials.Logics; using StructureHelperLogics.Models.Materials.Logics;
using System; using System;
@@ -20,6 +21,7 @@ namespace StructureHelperLogics.Models.Materials
public double TensileStrength { get; set; } public double TensileStrength { get; set; }
public List<IMaterialSafetyFactor> SafetyFactors { get; } = new(); public List<IMaterialSafetyFactor> SafetyFactors { get; } = new();
public IOneVariableFunction Function { get; set; } public IOneVariableFunction Function { get; set; }
public FunctionStorage FunctionStorage { get; set; }
public Guid Id { get; } public Guid Id { get; }
@@ -29,7 +31,6 @@ namespace StructureHelperLogics.Models.Materials
} }
public FunctionMaterial() : this(Guid.NewGuid()) public FunctionMaterial() : this(Guid.NewGuid())
{ {
Function = ProgramSetting.Functions.First();
} }
public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm)
{ {

View File

@@ -31,7 +31,7 @@ namespace StructureHelper.Models.Materials
} }
} }
public IHelperMaterial HelperMaterial {get; set;} public IHelperMaterial HelperMaterial {get; set;}
public bool SuccessfullyCreated { get; set; } = false;
public HeadMaterial(Guid id) public HeadMaterial(Guid id)
{ {

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions;
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Models.Materials.Libraries;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -14,6 +15,7 @@ namespace StructureHelperLogics.Models.Materials
double CompressiveStrength { get; set; } double CompressiveStrength { get; set; }
double TensileStrength { get; set; } double TensileStrength { get; set; }
List<IMaterialSafetyFactor> SafetyFactors { get; } List<IMaterialSafetyFactor> SafetyFactors { get; }
public FunctionStorage FunctionStorage { get; set; }
public IOneVariableFunction Function { get; set; } public IOneVariableFunction Function { get; set; }
} }
} }

View File

@@ -1,11 +1,6 @@
using LoaderCalculator.Data.Materials; using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Models.Materials.Libraries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperLogics.Models.Materials.Logics namespace StructureHelperLogics.Models.Materials.Logics
{ {
@@ -17,16 +12,37 @@ namespace StructureHelperLogics.Models.Materials.Logics
{ {
IMaterial material = new Material(); IMaterial material = new Material();
material.InitModulus = functionMaterial.Modulus; material.InitModulus = functionMaterial.Modulus;
IFactorLogic factorLogic = new FactorLogic(functionMaterial.SafetyFactors); if (calcTerm == CalcTerms.ShortTerm)
var factors = factorLogic.GetTotalFactor(limitState, calcTerm);
this.functionMaterial = functionMaterial;
parameters = new List<double>()
{ {
functionMaterial.Modulus, if (limitState == LimitStates.ULS)
functionMaterial.CompressiveStrength * factors.Compressive * factor, {
functionMaterial.TensileStrength * factors.Tensile * factor functionMaterial.Function = functionMaterial.FunctionStorage.Func_ST_ULS;
}; }
material.DiagramParameters = parameters; else if (limitState == LimitStates.SLS)
{
functionMaterial.Function = functionMaterial.FunctionStorage.Func_ST_SLS;
}
else if (limitState == LimitStates.Special)
{
functionMaterial.Function = functionMaterial.FunctionStorage.Func_ST_Special;
}
}
else if (calcTerm == CalcTerms.LongTerm)
{
if (limitState == LimitStates.ULS)
{
functionMaterial.Function = functionMaterial.FunctionStorage.Func_LT_ULS;
}
else if (limitState == LimitStates.SLS)
{
functionMaterial.Function = functionMaterial.FunctionStorage.Func_LT_SLS;
}
else if (limitState == LimitStates.Special)
{
functionMaterial.Function = functionMaterial.FunctionStorage.Func_LT_Special;
}
}
this.functionMaterial = functionMaterial;
material.Diagram = GetStressByStrain; material.Diagram = GetStressByStrain;
return material; return material;
} }