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)
{
Function = formulaFunction;
Formula = formulaFunction.Formula;
Name = Function.Name;
Description = Function.Description;
}

View File

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

View File

@@ -40,5 +40,10 @@ namespace StructureHelper.Windows.MainGraph
PropertyGroupDescription groupDescription = new PropertyGroupDescription(GROUP_FACTOR);
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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
namespace StructureHelper.Windows.MainGraph
@@ -36,12 +37,6 @@ namespace StructureHelper.Windows.MainGraph
private ObservableCollection<IOneVariableFunction> functions;
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
private RelayCommand addTableCommand;
private RelayCommand addFormulaCommand;
private RelayCommand editCommand;
@@ -59,7 +54,7 @@ namespace StructureHelper.Windows.MainGraph
}
public ICommand EditCommand
{
get => editCommand ??= new RelayCommand(o => Edit());
get => editCommand ??= new RelayCommand(o => Edit(o));
}
public ICommand DeleteCommand
{
@@ -79,6 +74,7 @@ namespace StructureHelper.Windows.MainGraph
}
public GraphViewModel()
{
//Пример 1
Functions = new ObservableCollection<IOneVariableFunction>();
var f1 = new TableFunction();
f1.Name = "Табличная системная функция";
@@ -89,31 +85,15 @@ namespace StructureHelper.Windows.MainGraph
};
f1.IsUser = false;
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(f2);
Functions.Add(f3);
Functions.Add(f4);
Functions.Add(f2);
}
/*public GraphViewModel(IGraph graph)
{
@@ -138,7 +118,7 @@ namespace StructureHelper.Windows.MainGraph
Functions.Add(formulaViewModel.Function);
}
}
private void Edit()
private void Edit(object parameter)
{
if (SelectedFuntion is null)
{
@@ -150,6 +130,7 @@ namespace StructureHelper.Windows.MainGraph
var tableView = new TableView();
tableView.DataContext = tableViewModel;
tableView.ShowDialog();
SelectedFuntion = tableViewModel.Function;
}
else if (SelectedFuntion.Type == FunctionType.FormulaFunction)
{
@@ -157,8 +138,10 @@ namespace StructureHelper.Windows.MainGraph
var formulaView = new FormulaView();
formulaView.DataContext = formulaViewModel;
formulaView.ShowDialog();
SelectedFuntion = formulaViewModel.Function;
}
var graphView = parameter as GraphView;
graphView.Refresh();
}
private void Delete()
{
@@ -192,8 +175,11 @@ namespace StructureHelper.Windows.MainGraph
}
private void Tree()
{
var treeGraphVM = new TreeGraphViewModel(SelectedFuntion);
var treeGraph = new TreeGraph.TreeGraphView();
var func = Database.GetFunctionTree();
var treeGraphVM = new TreeGraphViewModel(func);
var treeGraph = new TreeGraphView();
treeGraph.DataContext = treeGraphVM;
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"
Grid.Column="0"
Margin="5"
ItemsSource="{Binding ItemsSource}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:Node}" ItemsSource="{Binding Nodes}">
<TextBlock Text="{Binding Path=Name}" />
ItemsSource="{Binding FirstGeneration}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<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>
</TreeView.Resources>
</TreeView.ItemTemplate>
</TreeView>
<Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions>
@@ -68,7 +80,8 @@
Command="{Binding DeleteCommand}"/>
</Grid>
<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:Axis Title="Y"></lvc:Axis>
</lvc:CartesianChart.AxisY>

View File

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

View File

@@ -21,19 +21,12 @@ namespace StructureHelperCommon.Models.Functions
public bool IsUser { get; set; }
public FunctionType Type { get; set; }
public string Group { get; set; }
public string Name
{
get => name;
set
{
name = value;
}
}
public string Name { get; set; }
public string Description { get; set; }
public List<GraphPoint> Table { get; set; }
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)
{