Save function tree done

This commit is contained in:
Иван Ивашкин
2025-02-19 11:50:10 +05:00
parent 68a1e62c18
commit 27d4ca95c8
5 changed files with 68 additions and 32 deletions

View File

@@ -38,11 +38,13 @@ namespace StructureHelper.Windows.MainGraph
{ {
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(FunctionList.ItemsSource); CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(FunctionList.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription(GROUP_FACTOR); PropertyGroupDescription groupDescription = new PropertyGroupDescription(GROUP_FACTOR);
view.GroupDescriptions.Clear();
view.GroupDescriptions.Add(groupDescription); view.GroupDescriptions.Add(groupDescription);
} }
public void Refresh() public void Refresh()
{ {
FunctionList.Items.Refresh(); FunctionList.Items.Refresh();
} }
} }
} }

View File

@@ -5,6 +5,7 @@ using StructureHelper.Windows.Graphs;
using StructureHelper.Windows.TreeGraph; using StructureHelper.Windows.TreeGraph;
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
using StructureHelperLogics.Models.Graphs; using StructureHelperLogics.Models.Graphs;
using System; using System;
@@ -49,8 +50,8 @@ namespace StructureHelper.Windows.MainGraph
OnPropertyChanged(nameof(labels)); OnPropertyChanged(nameof(labels));
} }
} }
public GraphVisualProps VisualProps public GraphVisualProps VisualProps
{ {
get => visualProps; get => visualProps;
set set
{ {
@@ -82,8 +83,9 @@ namespace StructureHelper.Windows.MainGraph
private RelayCommand copyCommand; private RelayCommand copyCommand;
private RelayCommand treeCommand; private RelayCommand treeCommand;
private RelayCommand drawGraphCommand; private RelayCommand drawGraphCommand;
private RelayCommand _saveCommand;
public ICommand AddTableCommand public ICommand AddTableCommand
{ {
get => addTableCommand ??= new RelayCommand(o => AddTable()); get => addTableCommand ??= new RelayCommand(o => AddTable());
} }
public ICommand AddFormulaCommand public ICommand AddFormulaCommand
@@ -110,39 +112,48 @@ namespace StructureHelper.Windows.MainGraph
{ {
get => drawGraphCommand ??= new RelayCommand(o => DrawGraph()); get => drawGraphCommand ??= new RelayCommand(o => DrawGraph());
} }
public ICommand SaveCommand
{
get => _saveCommand ??= new RelayCommand(o => Save());
}
public GraphViewModel() public GraphViewModel()
{ {
//Пример 1 Functions = null;
Functions = new ObservableCollection<IOneVariableFunction>(); if (ProgramSetting.Functions is null)
var f1 = new TableFunction();
f1.Name = "Табличная системная функция";
f1.Table = new List<GraphPoint>()
{ {
new GraphPoint(1, 1), //Пример 1
new GraphPoint(2, 2), Functions = new ObservableCollection<IOneVariableFunction>();
new GraphPoint(3, 3), var f1 = new TableFunction();
new GraphPoint(4, 4), f1.Name = "Табличная системная функция";
new GraphPoint(5, 5), f1.Table = new List<GraphPoint>()
new GraphPoint(6, 6), {
}; new GraphPoint(1, 1),
f1.IsUser = false; new GraphPoint(2, 2),
f1.Description = "Описание табличной системной функции"; new GraphPoint(3, 3),
//Пример 2 new GraphPoint(4, 4),
var f2 = new FormulaFunction(); new GraphPoint(5, 5),
f2.Name = "Формульная системная функция"; new GraphPoint(6, 6),
f2.Formula = "x^2"; };
f2.Step = 100; f1.IsUser = false;
f2.MinArg = 1; f1.Description = "Описание табличной системной функции";
f2.MaxArg = 1000; //Пример 2
f2.IsUser = false; var f2 = new FormulaFunction();
f2.Description = "Описание формульной системной функции"; f2.Name = ормульная системная функция";
f2.Formula = "x^2";
f2.Step = 100;
f2.MinArg = 1;
f2.MaxArg = 1000;
f2.IsUser = false;
f2.Description = "Описание формульной системной функции";
Functions.Add(f1); Functions.Add(f1);
Functions.Add(f2); Functions.Add(f2);
}
else
{
Functions = ProgramSetting.Functions;
}
} }
/*public GraphViewModel(IGraph graph)
{
}*/
private void AddTable() private void AddTable()
{ {
var tableViewModel = new TableViewModel(); var tableViewModel = new TableViewModel();
@@ -153,6 +164,7 @@ namespace StructureHelper.Windows.MainGraph
Functions.Add(tableViewModel.Function); Functions.Add(tableViewModel.Function);
SelectedFuntion = tableViewModel.Function; SelectedFuntion = tableViewModel.Function;
} }
Save();
} }
private void AddFormula() private void AddFormula()
{ {
@@ -164,6 +176,7 @@ namespace StructureHelper.Windows.MainGraph
Functions.Add(formulaViewModel.Function); Functions.Add(formulaViewModel.Function);
SelectedFuntion = formulaViewModel.Function; SelectedFuntion = formulaViewModel.Function;
} }
Save();
} }
private void Edit(object parameter) private void Edit(object parameter)
{ {
@@ -189,6 +202,7 @@ namespace StructureHelper.Windows.MainGraph
} }
var graphView = parameter as GraphView; var graphView = parameter as GraphView;
graphView.Refresh(); graphView.Refresh();
Save();
} }
private void Delete() private void Delete()
{ {
@@ -204,6 +218,7 @@ namespace StructureHelper.Windows.MainGraph
{ {
Functions.Remove(SelectedFuntion); Functions.Remove(SelectedFuntion);
} }
Save();
} }
private void Copy() private void Copy()
{ {
@@ -219,6 +234,7 @@ namespace StructureHelper.Windows.MainGraph
{ {
Functions.Add(SelectedFuntion.Clone() as FormulaFunction); Functions.Add(SelectedFuntion.Clone() as FormulaFunction);
} }
Save();
} }
private void Tree() private void Tree()
{ {
@@ -244,6 +260,11 @@ namespace StructureHelper.Windows.MainGraph
GraphService.SetVisualProps(LineSeries, VisualProps); GraphService.SetVisualProps(LineSeries, VisualProps);
SeriesCollection = new SeriesCollection(); SeriesCollection = new SeriesCollection();
SeriesCollection.Add(LineSeries); SeriesCollection.Add(LineSeries);
Save();
}
public void Save()
{
ProgramSetting.Functions = Functions;
} }
} }
} }

View File

@@ -29,6 +29,7 @@ namespace StructureHelper.Windows.TreeGraph
private RelayCommand _scaleCommand; private RelayCommand _scaleCommand;
private RelayCommand _limCommand; private RelayCommand _limCommand;
private RelayCommand _deleteCommand; private RelayCommand _deleteCommand;
private RelayCommand _saveCommand;
private TreeGraphView _treeGraphView_win; private TreeGraphView _treeGraphView_win;
private IOneVariableFunction selectedFunction; private IOneVariableFunction selectedFunction;
public IOneVariableFunction SelectedFuntion public IOneVariableFunction SelectedFuntion
@@ -96,6 +97,10 @@ namespace StructureHelper.Windows.TreeGraph
{ {
get => _deleteCommand ??= new RelayCommand(o => Delete()); get => _deleteCommand ??= new RelayCommand(o => Delete());
} }
public ICommand SaveCommand
{
get => _saveCommand ??= new RelayCommand(o => Save());
}
public TreeGraphViewModel(IOneVariableFunction rootFunction) public TreeGraphViewModel(IOneVariableFunction rootFunction)
{ {
_rootFunction = new TreeViewItemViewModel(rootFunction, this); _rootFunction = new TreeViewItemViewModel(rootFunction, this);
@@ -232,5 +237,9 @@ namespace StructureHelper.Windows.TreeGraph
SeriesCollection = new SeriesCollection(); SeriesCollection = new SeriesCollection();
SeriesCollection.Add(LineSeries); SeriesCollection.Add(LineSeries);
} }
public void Save()
{
}
} }
} }

View File

@@ -1,10 +1,12 @@
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Codes; using StructureHelperCommon.Models.Codes;
using StructureHelperCommon.Models.Codes.Factories; using StructureHelperCommon.Models.Codes.Factories;
using StructureHelperCommon.Models.Materials; using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperCommon.Models.Projects; using StructureHelperCommon.Models.Projects;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Design.Serialization; using System.ComponentModel.Design.Serialization;
using System.Linq; using System.Linq;
using System.Windows.Documents; using System.Windows.Documents;
@@ -90,5 +92,6 @@ namespace StructureHelperCommon.Infrastructures.Settings
SubVersionNumber = 0 SubVersionNumber = 0
}; };
} }
public static ObservableCollection<IOneVariableFunction> Functions { get; set; }
} }
} }

View File

@@ -1,6 +1,7 @@
using LoaderCalculator.Data.Materials; using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperLogics.Models.Materials.Logics; using StructureHelperLogics.Models.Materials.Logics;
using System; using System;
@@ -28,7 +29,7 @@ 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)
{ {