diff --git a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs
index b2a3e64..a511732 100644
--- a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs
+++ b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs
@@ -82,6 +82,7 @@ namespace StructureHelper.Windows.MainGraph
public FormulaViewModel(FormulaFunction formulaFunction)
{
Function = formulaFunction;
+ Formula = formulaFunction.Formula;
Name = Function.Name;
Description = Function.Description;
}
diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml b/StructureHelper/Windows/MainGraph/GraphView.xaml
index cfb841b..1806f76 100644
--- a/StructureHelper/Windows/MainGraph/GraphView.xaml
+++ b/StructureHelper/Windows/MainGraph/GraphView.xaml
@@ -1,4 +1,5 @@
+ Series="{Binding SeriesCollection}" Margin="5"
+ Zoom="Xy">
@@ -114,7 +117,8 @@
diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml.cs b/StructureHelper/Windows/MainGraph/GraphView.xaml.cs
index 65e103e..aa3e669 100644
--- a/StructureHelper/Windows/MainGraph/GraphView.xaml.cs
+++ b/StructureHelper/Windows/MainGraph/GraphView.xaml.cs
@@ -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();
+ }
}
}
diff --git a/StructureHelper/Windows/MainGraph/GraphViewModel.cs b/StructureHelper/Windows/MainGraph/GraphViewModel.cs
index 079311d..28edd43 100644
--- a/StructureHelper/Windows/MainGraph/GraphViewModel.cs
+++ b/StructureHelper/Windows/MainGraph/GraphViewModel.cs
@@ -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 functions;
public ObservableCollection 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();
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()
- {
- new GraphPoint(1, 0),
- new GraphPoint(0, 1),
- };
- f4.IsUser = false;
- f4.Description = "Описание табличной системной функции";
-
- /*var f2 = new TableFunction();
- f2.Name = "Пробная табличная пользовательская функция 2";
- f2.Table = new List();
- 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();
}
diff --git a/StructureHelper/Windows/TreeGraph/Database.cs b/StructureHelper/Windows/TreeGraph/Database.cs
new file mode 100644
index 0000000..fe58200
--- /dev/null
+++ b/StructureHelper/Windows/TreeGraph/Database.cs
@@ -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()
+ {
+ new FormulaFunction()
+ {
+ Name = "func1.1"
+ },
+ new FormulaFunction()
+ {
+ Name = "func1.2"
+ },
+ new FormulaFunction()
+ {
+ Name = "func1.3",
+ Functions = new ObservableCollection()
+ {
+ new FormulaFunction()
+ {
+ Name = "func2.1"
+ },
+ new FormulaFunction()
+ {
+ Name = "func2.2"
+ },
+ }
+ },
+ new TableFunction()
+ {
+ Name = "func1.4"
+ }
+ }
+ };
+ }
+ }
+}
diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml
index fb4af47..b3c7136 100644
--- a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml
+++ b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml
@@ -21,12 +21,24 @@
-
-
-
+ ItemsSource="{Binding FirstGeneration}">
+
+
+
+
+
+
-
+
@@ -68,7 +80,8 @@
Command="{Binding DeleteCommand}"/>
+ Series="{Binding SeriesCollection}" Margin="5"
+ Zoom="Xy">
diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs
index cc20e22..92398b3 100644
--- a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs
+++ b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs
@@ -14,11 +14,18 @@ namespace StructureHelper.Windows.TreeGraph
{
public class TreeGraphViewModel : ViewModelBase
{
+ readonly ReadOnlyCollection _firstGeneration;
+ readonly TreeViewItemViewModel _rootFunction;
+ readonly ICommand _searchCommand;
private RelayCommand _getYCommand;
private RelayCommand _scaleCommand;
private RelayCommand _limCommand;
private RelayCommand _editCommand;
private RelayCommand _deleteCommand;
+ public ReadOnlyCollection FirstGeneration
+ {
+ get => _firstGeneration;
+ }
public ICommand GetYCommand
{
get => _getYCommand ??= new RelayCommand(o => GetY());
@@ -42,18 +49,15 @@ namespace StructureHelper.Windows.TreeGraph
private ObservableCollection functions;
public ObservableCollection Functions { get; set; }
public ObservableCollection Nodes { get; set; }
- public TreeGraphViewModel(IOneVariableFunction function)
+ public TreeGraphViewModel(IOneVariableFunction rootFunction)
{
- Functions = new ObservableCollection();
- Functions.Add(function);
- Nodes = new ObservableCollection()
- {
- new Node(),
- new Node(),
- new Node(),
- new Node(),
- new Node(),
- };
+ _rootFunction = new TreeViewItemViewModel(rootFunction);
+
+ _firstGeneration = new ReadOnlyCollection(
+ new TreeViewItemViewModel[]
+ {
+ _rootFunction
+ });
}
private void GetY()
{
diff --git a/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs
new file mode 100644
index 0000000..61bd957
--- /dev/null
+++ b/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs
@@ -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 _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
+ (
+ _functions.Functions
+ .Select(x => new TreeViewItemViewModel(x, this))
+ .ToList()
+ );
+ }
+ public ReadOnlyCollection 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; }
+ }
+
+ }
+}
diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs
index ce5e857..04146b2 100644
--- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs
+++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs
@@ -26,7 +26,7 @@ namespace StructureHelperCommon.Models.Functions
public Guid Id => throw new NotImplementedException();
- public ObservableCollection Functions { get; set; }
+ public ObservableCollection Functions { get; set; } = new ObservableCollection();
public FormulaFunction(bool isUser = false)
{
Type = FunctionType.FormulaFunction;
diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs
index 6041409..40d7927 100644
--- a/StructureHelperCommon/Models/Functions/TableFunction.cs
+++ b/StructureHelperCommon/Models/Functions/TableFunction.cs
@@ -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 Table { get; set; }
public Guid Id => throw new NotImplementedException();
- public ObservableCollection Functions { get; set; }
+ public ObservableCollection Functions { get; set; } = new ObservableCollection();
public TableFunction(bool isUser = false)
{