Function tree in process

This commit is contained in:
Иван Ивашкин
2024-10-29 14:44:55 +05:00
parent 8510db1a85
commit 2a0704fc4f
10 changed files with 200 additions and 64 deletions

View File

@@ -82,6 +82,7 @@ namespace StructureHelper.Windows.MainGraph
public FormulaViewModel(FormulaFunction formulaFunction) public FormulaViewModel(FormulaFunction formulaFunction)
{ {
Function = formulaFunction; Function = formulaFunction;
Formula = formulaFunction.Formula;
Name = Function.Name; Name = Function.Name;
Description = Function.Description; Description = Function.Description;
} }

View File

@@ -1,4 +1,5 @@
<Window x:Class="StructureHelper.Windows.MainGraph.GraphView" <Window x:Class="StructureHelper.Windows.MainGraph.GraphView"
x:Name="GraphView_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"
@@ -84,6 +85,7 @@
Background="LightGreen"/> Background="LightGreen"/>
<Button Grid.Column="1" Grid.Row="0" Margin="5" Content="Edit" <Button Grid.Column="1" Grid.Row="0" Margin="5" Content="Edit"
Command="{Binding EditCommand}" Command="{Binding EditCommand}"
CommandParameter="{Binding ElementName=GraphView_win}"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"
Background="LightYellow"/> Background="LightYellow"/>
<Button Grid.Column="1" Grid.Row="1" Margin="5" Content="Delete" <Button Grid.Column="1" Grid.Row="1" Margin="5" Content="Delete"
@@ -99,7 +101,8 @@
Background="AntiqueWhite"/> Background="AntiqueWhite"/>
</Grid> </Grid>
<lvc:CartesianChart Grid.Row="0" Grid.Column="1" <lvc:CartesianChart Grid.Row="0" Grid.Column="1"
Series="{Binding SeriesCollection}" Margin="5"> Series="{Binding SeriesCollection}" Margin="5"
Zoom="Xy">
<lvc:CartesianChart.AxisY> <lvc:CartesianChart.AxisY>
<lvc:Axis Title="Y"></lvc:Axis> <lvc:Axis Title="Y"></lvc:Axis>
</lvc:CartesianChart.AxisY> </lvc:CartesianChart.AxisY>
@@ -114,7 +117,8 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Description:" Margin="5"/> <TextBlock Grid.Row="0" Text="Description:" Margin="5"/>
<TextBlock Grid.Row="1" <TextBlock Grid.Row="1"
Text="{Binding SelectedFuntion.Description, UpdateSourceTrigger=PropertyChanged}" Name="DescriptionTextBlock"
Text="{Binding SelectedFuntion.Description}"
Margin="5" TextWrapping="Wrap" Margin="5" TextWrapping="Wrap"
VerticalAlignment="Center" Height="60"/> VerticalAlignment="Center" Height="60"/>
</Grid> </Grid>

View File

@@ -40,5 +40,10 @@ namespace StructureHelper.Windows.MainGraph
PropertyGroupDescription groupDescription = new PropertyGroupDescription(GROUP_FACTOR); PropertyGroupDescription groupDescription = new PropertyGroupDescription(GROUP_FACTOR);
view.GroupDescriptions.Add(groupDescription); view.GroupDescriptions.Add(groupDescription);
} }
public void Refresh()
{
FunctionList.Items.Refresh();
DescriptionTextBlock.UpdateLayout();
}
} }
} }

View File

@@ -9,6 +9,7 @@ using StructureHelperLogics.Models.Graphs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input; using System.Windows.Input;
namespace StructureHelper.Windows.MainGraph namespace StructureHelper.Windows.MainGraph
@@ -36,12 +37,6 @@ namespace StructureHelper.Windows.MainGraph
private ObservableCollection<IOneVariableFunction> functions; private ObservableCollection<IOneVariableFunction> functions;
public ObservableCollection<IOneVariableFunction> Functions { get; set; } public ObservableCollection<IOneVariableFunction> Functions { get; set; }
private RelayCommand addTableCommand; private RelayCommand addTableCommand;
private RelayCommand addFormulaCommand; private RelayCommand addFormulaCommand;
private RelayCommand editCommand; private RelayCommand editCommand;
@@ -59,7 +54,7 @@ namespace StructureHelper.Windows.MainGraph
} }
public ICommand EditCommand public ICommand EditCommand
{ {
get => editCommand ??= new RelayCommand(o => Edit()); get => editCommand ??= new RelayCommand(o => Edit(o));
} }
public ICommand DeleteCommand public ICommand DeleteCommand
{ {
@@ -79,6 +74,7 @@ namespace StructureHelper.Windows.MainGraph
} }
public GraphViewModel() public GraphViewModel()
{ {
//Пример 1
Functions = new ObservableCollection<IOneVariableFunction>(); Functions = new ObservableCollection<IOneVariableFunction>();
var f1 = new TableFunction(); var f1 = new TableFunction();
f1.Name = "Табличная системная функция"; f1.Name = "Табличная системная функция";
@@ -89,31 +85,15 @@ namespace StructureHelper.Windows.MainGraph
}; };
f1.IsUser = false; f1.IsUser = false;
f1.Description = "Описание табличной системной функции"; f1.Description = "Описание табличной системной функции";
//Пример 2
var f2 = new FormulaFunction();
f2.Name = "Формульная системная функция";
f2.Formula = "x^2";
f2.IsUser = false;
f2.Description = "Описание формульной системной функции";
var f4 = new TableFunction();
f4.Name = "Табличная системная функция";
f4.Table = new List<GraphPoint>()
{
new GraphPoint(1, 0),
new GraphPoint(0, 1),
};
f4.IsUser = false;
f4.Description = "Описание табличной системной функции";
/*var f2 = new TableFunction();
f2.Name = "Пробная табличная пользовательская функция 2";
f2.Table = new List<GraphPoint>();
f2.IsUser = true;
f2.Description = "Описание 2";*/
var f3 = new FormulaFunction();
f3.Name = "Формульная системная функция";
f3.Formula = "x^2";
f3.IsUser = false;
f3.Description = "Описание формульной системной функции";
Functions.Add(f1); Functions.Add(f1);
//Functions.Add(f2); Functions.Add(f2);
Functions.Add(f3);
Functions.Add(f4);
} }
/*public GraphViewModel(IGraph graph) /*public GraphViewModel(IGraph graph)
{ {
@@ -138,7 +118,7 @@ namespace StructureHelper.Windows.MainGraph
Functions.Add(formulaViewModel.Function); Functions.Add(formulaViewModel.Function);
} }
} }
private void Edit() private void Edit(object parameter)
{ {
if (SelectedFuntion is null) if (SelectedFuntion is null)
{ {
@@ -150,6 +130,7 @@ namespace StructureHelper.Windows.MainGraph
var tableView = new TableView(); var tableView = new TableView();
tableView.DataContext = tableViewModel; tableView.DataContext = tableViewModel;
tableView.ShowDialog(); tableView.ShowDialog();
SelectedFuntion = tableViewModel.Function;
} }
else if (SelectedFuntion.Type == FunctionType.FormulaFunction) else if (SelectedFuntion.Type == FunctionType.FormulaFunction)
{ {
@@ -157,8 +138,10 @@ namespace StructureHelper.Windows.MainGraph
var formulaView = new FormulaView(); var formulaView = new FormulaView();
formulaView.DataContext = formulaViewModel; formulaView.DataContext = formulaViewModel;
formulaView.ShowDialog(); formulaView.ShowDialog();
SelectedFuntion = formulaViewModel.Function;
} }
var graphView = parameter as GraphView;
graphView.Refresh();
} }
private void Delete() private void Delete()
{ {
@@ -192,8 +175,11 @@ namespace StructureHelper.Windows.MainGraph
} }
private void Tree() private void Tree()
{ {
var treeGraphVM = new TreeGraphViewModel(SelectedFuntion); var func = Database.GetFunctionTree();
var treeGraph = new TreeGraph.TreeGraphView();
var treeGraphVM = new TreeGraphViewModel(func);
var treeGraph = new TreeGraphView();
treeGraph.DataContext = treeGraphVM; treeGraph.DataContext = treeGraphVM;
treeGraph.ShowDialog(); treeGraph.ShowDialog();
} }

View File

@@ -0,0 +1,52 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.TreeGraph
{
public static class Database
{
public static IOneVariableFunction GetFunctionTree()
{
return new TableFunction()
{
Name = "func0",
Functions = new ObservableCollection<IOneVariableFunction>()
{
new FormulaFunction()
{
Name = "func1.1"
},
new FormulaFunction()
{
Name = "func1.2"
},
new FormulaFunction()
{
Name = "func1.3",
Functions = new ObservableCollection<IOneVariableFunction>()
{
new FormulaFunction()
{
Name = "func2.1"
},
new FormulaFunction()
{
Name = "func2.2"
},
}
},
new TableFunction()
{
Name = "func1.4"
}
}
};
}
}
}

View File

@@ -21,12 +21,24 @@
<TreeView Grid.Row="0" <TreeView Grid.Row="0"
Grid.Column="0" Grid.Column="0"
Margin="5" Margin="5"
ItemsSource="{Binding ItemsSource}"> ItemsSource="{Binding FirstGeneration}">
<TreeView.Resources> <TreeView.ItemContainerStyle>
<HierarchicalDataTemplate DataType="{x:Type local:Node}" ItemsSource="{Binding Nodes}"> <Style TargetType="{x:Type TreeViewItem}">
<TextBlock Text="{Binding Path=Name}" /> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
</TreeView.Resources> </TreeView.ItemTemplate>
</TreeView> </TreeView>
<Grid Grid.Row="1" Grid.Column="0"> <Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -68,7 +80,8 @@
Command="{Binding DeleteCommand}"/> Command="{Binding DeleteCommand}"/>
</Grid> </Grid>
<lvc:CartesianChart Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" <lvc:CartesianChart Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"
Series="{Binding SeriesCollection}" Margin="5"> Series="{Binding SeriesCollection}" Margin="5"
Zoom="Xy">
<lvc:CartesianChart.AxisY> <lvc:CartesianChart.AxisY>
<lvc:Axis Title="Y"></lvc:Axis> <lvc:Axis Title="Y"></lvc:Axis>
</lvc:CartesianChart.AxisY> </lvc:CartesianChart.AxisY>

View File

@@ -14,11 +14,18 @@ namespace StructureHelper.Windows.TreeGraph
{ {
public class TreeGraphViewModel : ViewModelBase public class TreeGraphViewModel : ViewModelBase
{ {
readonly ReadOnlyCollection<TreeViewItemViewModel> _firstGeneration;
readonly TreeViewItemViewModel _rootFunction;
readonly ICommand _searchCommand;
private RelayCommand _getYCommand; private RelayCommand _getYCommand;
private RelayCommand _scaleCommand; private RelayCommand _scaleCommand;
private RelayCommand _limCommand; private RelayCommand _limCommand;
private RelayCommand _editCommand; private RelayCommand _editCommand;
private RelayCommand _deleteCommand; private RelayCommand _deleteCommand;
public ReadOnlyCollection<TreeViewItemViewModel> FirstGeneration
{
get => _firstGeneration;
}
public ICommand GetYCommand public ICommand GetYCommand
{ {
get => _getYCommand ??= new RelayCommand(o => GetY()); get => _getYCommand ??= new RelayCommand(o => GetY());
@@ -42,18 +49,15 @@ namespace StructureHelper.Windows.TreeGraph
private ObservableCollection<IOneVariableFunction> functions; private ObservableCollection<IOneVariableFunction> functions;
public ObservableCollection<IOneVariableFunction> Functions { get; set; } public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public ObservableCollection<Node> Nodes { get; set; } public ObservableCollection<Node> Nodes { get; set; }
public TreeGraphViewModel(IOneVariableFunction function) public TreeGraphViewModel(IOneVariableFunction rootFunction)
{ {
Functions = new ObservableCollection<IOneVariableFunction>(); _rootFunction = new TreeViewItemViewModel(rootFunction);
Functions.Add(function);
Nodes = new ObservableCollection<Node>() _firstGeneration = new ReadOnlyCollection<TreeViewItemViewModel>(
{ new TreeViewItemViewModel[]
new Node(), {
new Node(), _rootFunction
new Node(), });
new Node(),
new Node(),
};
} }
private void GetY() private void GetY()
{ {

View File

@@ -0,0 +1,78 @@
using FieldVisualizer.ViewModels;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.TreeGraph
{
public class TreeViewItemViewModel : ViewModelBase
{
readonly ReadOnlyCollection<TreeViewItemViewModel> _children;
readonly TreeViewItemViewModel _parent;
readonly IOneVariableFunction _functions;
bool _isExpanded;
bool _isSelected;
public TreeViewItemViewModel(IOneVariableFunction function) : this(function, null)
{
}
private TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent)
{
_functions = function;
_parent = parent;
_children = new ReadOnlyCollection<TreeViewItemViewModel>
(
_functions.Functions
.Select(x => new TreeViewItemViewModel(x, this))
.ToList<TreeViewItemViewModel>()
);
}
public ReadOnlyCollection<TreeViewItemViewModel> Children
{
get { return _children; }
}
public string Name
{
get { return _functions.Name; }
}
public bool IsExpanded
{
get { return _isExpanded; }
set
{
if (value != _isExpanded)
{
_isExpanded = value;
OnPropertyChanged(nameof(IsExpanded));
}
// Expand all the way up to the root.
if (_isExpanded && _parent != null)
_parent.IsExpanded = true;
}
}
public bool IsSelected
{
get { return _isSelected; }
set
{
if (value != _isSelected)
{
_isSelected = value;
OnPropertyChanged(nameof(IsSelected));
}
}
}
public TreeViewItemViewModel Parent
{
get { return _parent; }
}
}
}

View File

@@ -26,7 +26,7 @@ namespace StructureHelperCommon.Models.Functions
public Guid Id => throw new NotImplementedException(); public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; } public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public FormulaFunction(bool isUser = false) public FormulaFunction(bool isUser = false)
{ {
Type = FunctionType.FormulaFunction; Type = FunctionType.FormulaFunction;

View File

@@ -21,19 +21,12 @@ namespace StructureHelperCommon.Models.Functions
public bool IsUser { get; set; } public bool IsUser { get; set; }
public FunctionType Type { get; set; } public FunctionType Type { get; set; }
public string Group { get; set; } public string Group { get; set; }
public string Name public string Name { get; set; }
{
get => name;
set
{
name = value;
}
}
public string Description { get; set; } public string Description { get; set; }
public List<GraphPoint> Table { get; set; } public List<GraphPoint> Table { get; set; }
public Guid Id => throw new NotImplementedException(); public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; } public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public TableFunction(bool isUser = false) public TableFunction(bool isUser = false)
{ {