diff --git a/StructureHelper/Windows/MainGraph/FormulaView.xaml b/StructureHelper/Windows/MainGraph/FormulaView.xaml index c3a165a..97a1c42 100644 --- a/StructureHelper/Windows/MainGraph/FormulaView.xaml +++ b/StructureHelper/Windows/MainGraph/FormulaView.xaml @@ -7,11 +7,14 @@ xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph" mc:Ignorable="d" d:DataContext="{d:DesignInstance local:FormulaViewModel}" - Title="FormulaFunction" Height="320" Width="400"> + Title="FormulaFunction" Height="580" Width="400"> + + + @@ -47,6 +50,79 @@ TextWrapping="Wrap"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,7 +133,7 @@ VerticalAlignment="Center"/> - + @@ -68,8 +144,19 @@ VerticalAlignment="Center"/> - diff --git a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs index a511732..1e60e50 100644 --- a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs +++ b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs @@ -22,10 +22,10 @@ namespace StructureHelper.Windows.MainGraph private const double DEFAULT_LEFT_BOUND = 0; private const double DEFAULT_RIGHT_BOUND = 1000; private const int DEFAULT_STEP = 100; - private RelayCommand drawGraphCommand; - public ICommand DrawGraphCommand + private RelayCommand saveCommand; + public ICommand SaveCommand { - get => drawGraphCommand ??= new RelayCommand(o => Save(o)); + get => saveCommand ??= new RelayCommand(o => Save(o)); } private string formula; diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml b/StructureHelper/Windows/MainGraph/GraphView.xaml index 1806f76..9d351fb 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml @@ -101,13 +101,13 @@ Background="AntiqueWhite"/> + Series="{Binding SeriesCollection, UpdateSourceTrigger=PropertyChanged}" Margin="5" + Zoom="None"> - + diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml.cs b/StructureHelper/Windows/MainGraph/GraphView.xaml.cs index aa3e669..1bfc7bb 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml.cs +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml.cs @@ -43,7 +43,6 @@ namespace StructureHelper.Windows.MainGraph public void Refresh() { FunctionList.Items.Refresh(); - DescriptionTextBlock.UpdateLayout(); } } } diff --git a/StructureHelper/Windows/MainGraph/GraphViewModel.cs b/StructureHelper/Windows/MainGraph/GraphViewModel.cs index 28edd43..e410f36 100644 --- a/StructureHelper/Windows/MainGraph/GraphViewModel.cs +++ b/StructureHelper/Windows/MainGraph/GraphViewModel.cs @@ -16,11 +16,26 @@ namespace StructureHelper.Windows.MainGraph { public class GraphViewModel : ViewModelBase { - public SeriesCollection SeriesCollection { get; set; } - public List Labels { get; set; } - - - + private SeriesCollection seriesCollection; + private List labels; + public SeriesCollection SeriesCollection + { + get => seriesCollection; + set + { + seriesCollection = value; + OnPropertyChanged(nameof(seriesCollection)); + } + } + public List Labels + { + get => labels; + set + { + labels = value; + OnPropertyChanged(nameof(labels)); + } + } private IOneVariableFunction selectedFunction; public IOneVariableFunction SelectedFuntion { @@ -31,6 +46,7 @@ namespace StructureHelper.Windows.MainGraph set { selectedFunction = value; + DrawGraph(); OnPropertyChanged(nameof(SelectedFuntion)); } } @@ -89,6 +105,9 @@ namespace StructureHelper.Windows.MainGraph var f2 = new FormulaFunction(); f2.Name = "Формульная системная функция"; f2.Formula = "x^2"; + f2.Step = 100; + f2.MinArg = -1000; + f2.MaxArg = 1000; f2.IsUser = false; f2.Description = "Описание формульной системной функции"; @@ -106,6 +125,7 @@ namespace StructureHelper.Windows.MainGraph if (tableView.ShowDialog() == true) { Functions.Add(tableViewModel.Function); + SelectedFuntion = tableViewModel.Function; } } private void AddFormula() @@ -116,6 +136,7 @@ namespace StructureHelper.Windows.MainGraph if (formulaView.ShowDialog() == true) { Functions.Add(formulaViewModel.Function); + SelectedFuntion = formulaViewModel.Function; } } private void Edit(object parameter) @@ -139,9 +160,9 @@ namespace StructureHelper.Windows.MainGraph formulaView.DataContext = formulaViewModel; formulaView.ShowDialog(); SelectedFuntion = formulaViewModel.Function; - } - var graphView = parameter as GraphView; - graphView.Refresh(); + } + //var graphView = parameter as GraphView; + //graphView.Refresh(); } private void Delete() { @@ -175,12 +196,18 @@ namespace StructureHelper.Windows.MainGraph } private void Tree() { - var func = Database.GetFunctionTree(); + if (SelectedFuntion is null) + { + return; + } + //var testFunction = Database.GetFunctionTree(); + //var treeGraphVM = new TreeGraphViewModel(testFunction); - var treeGraphVM = new TreeGraphViewModel(func); + var treeGraphVM = new TreeGraphViewModel(SelectedFuntion); var treeGraph = new TreeGraphView(); treeGraph.DataContext = treeGraphVM; + treeGraphVM.TreeGraphView_win = treeGraph; treeGraph.ShowDialog(); } private void DrawGraph() @@ -196,6 +223,7 @@ namespace StructureHelper.Windows.MainGraph } lineSeries.Values = chartValues; Labels = labels; + seriesCollection.Add(lineSeries); SeriesCollection = seriesCollection; } } diff --git a/StructureHelper/Windows/MainGraph/TableView.xaml b/StructureHelper/Windows/MainGraph/TableView.xaml index f232943..8d227e1 100644 --- a/StructureHelper/Windows/MainGraph/TableView.xaml +++ b/StructureHelper/Windows/MainGraph/TableView.xaml @@ -8,7 +8,7 @@ mc:Ignorable="d" ResizeMode="CanResize" d:DataContext="{d:DesignInstance local:TableViewModel}" - Title="TableFunction" Height="500" Width="400" + Title="TableFunction" Height="560" Width="400" MaxWidth="400" MinWidth="400"> @@ -18,6 +18,7 @@ + @@ -105,8 +106,19 @@ VerticalAlignment="Center"/> - diff --git a/StructureHelper/Windows/MainGraph/TableViewModel.cs b/StructureHelper/Windows/MainGraph/TableViewModel.cs index 1834980..2ce0520 100644 --- a/StructureHelper/Windows/MainGraph/TableViewModel.cs +++ b/StructureHelper/Windows/MainGraph/TableViewModel.cs @@ -18,12 +18,12 @@ namespace StructureHelper.Windows.MainGraph { private const string DEFAULT_NAME = "Put function name here..."; private const string DEFAULT_DESCRIPTION = "Put function description here..."; - private RelayCommand drawGraphCommand; + private RelayCommand saveCommand; private RelayCommand addPointCommand; private RelayCommand deletePointCommand; - public ICommand DrawGraphCommand + public ICommand SaveCommand { - get => drawGraphCommand ??= new RelayCommand(o => Save(o)); + get => saveCommand ??= new RelayCommand(o => Save(o)); } public ICommand AddPointCommand { diff --git a/StructureHelper/Windows/TreeGraph/GetValueView.xaml b/StructureHelper/Windows/TreeGraph/GetValueView.xaml index 3401098..2bb0642 100644 --- a/StructureHelper/Windows/TreeGraph/GetValueView.xaml +++ b/StructureHelper/Windows/TreeGraph/GetValueView.xaml @@ -35,14 +35,14 @@ @@ -67,7 +67,7 @@ HorizontalAlignment="Right"/> diff --git a/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs b/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs index 917576d..659553e 100644 --- a/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs @@ -28,12 +28,20 @@ namespace StructureHelper.Windows.TreeGraph public double Value { get => value; - set => this.value = value; + set + { + this.value = value; + OnPropertyChanged(nameof(Value)); + } } public string Trace { get => trace; - set => trace = value; + set + { + trace = value; + OnPropertyChanged(nameof(Trace)); + } } private RelayCommand _getValueCommand; public ICommand GetValueCommand @@ -47,7 +55,7 @@ namespace StructureHelper.Windows.TreeGraph private void GetValue() { Value = Function.GetByX(Argument); - Trace = "скорее всего переменная внутри функции"; + Trace = "Calculation logic"; } } } diff --git a/StructureHelper/Windows/TreeGraph/LimViewModel.cs b/StructureHelper/Windows/TreeGraph/LimViewModel.cs index ea18a01..f94b6a7 100644 --- a/StructureHelper/Windows/TreeGraph/LimViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/LimViewModel.cs @@ -9,13 +9,16 @@ namespace StructureHelper.Windows.TreeGraph { public class LimViewModel : ViewModelBase { + private bool isArg = false; public char GREATER { get; } = '\u2265'; public char LESS { get; } = '\u2264'; public char IN { get; } = '\u2208'; public char LEFT_BOUND { get; } = '['; public char RIGHT_BOUND { get; } = ']'; public char SEMICOLON { get; } = ';'; - private string x_or_y_text = "x"; + private const string X = "x"; + private const string Y = "y"; + private string x_or_y_text; private string limitText; public string X_or_Y_text { @@ -53,8 +56,17 @@ namespace StructureHelper.Windows.TreeGraph OnPropertyChanged(nameof(RightBound)); } } - public LimViewModel() + public LimViewModel(bool isArg) { + this.isArg = isArg; + if (isArg) + { + X_or_Y_text = X; + } + else + { + X_or_Y_text = Y; + } LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{LeftBound}" + $"{SEMICOLON}" + $"{rightBound}" + $"{RIGHT_BOUND}"; } } diff --git a/StructureHelper/Windows/TreeGraph/Node.cs b/StructureHelper/Windows/TreeGraph/Node.cs deleted file mode 100644 index dde2a6e..0000000 --- a/StructureHelper/Windows/TreeGraph/Node.cs +++ /dev/null @@ -1,15 +0,0 @@ -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 class Node - { - public ObservableCollection Nodes { get; set; } - public string Name { get; set; } - } -} diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml index b3c7136..b72842f 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml +++ b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml @@ -18,7 +18,8 @@ - @@ -81,7 +82,7 @@ + Zoom="None"> diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs index 92398b3..7eceab4 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs @@ -1,4 +1,6 @@ -using NLog.Common; +using LiveCharts.Wpf; +using LiveCharts; +using NLog.Common; using StructureHelper.Infrastructure; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models.Functions; @@ -14,7 +16,9 @@ namespace StructureHelper.Windows.TreeGraph { public class TreeGraphViewModel : ViewModelBase { - readonly ReadOnlyCollection _firstGeneration; + private SeriesCollection seriesCollection; + private List labels; + readonly ObservableCollection _firstGeneration; readonly TreeViewItemViewModel _rootFunction; readonly ICommand _searchCommand; private RelayCommand _getYCommand; @@ -22,7 +26,44 @@ namespace StructureHelper.Windows.TreeGraph private RelayCommand _limCommand; private RelayCommand _editCommand; private RelayCommand _deleteCommand; - public ReadOnlyCollection FirstGeneration + private TreeGraphView _treeGraphView_win; + private IOneVariableFunction selectedFunction; + public IOneVariableFunction SelectedFuntion + { + get + { + return selectedFunction; + } + set + { + selectedFunction = value; + OnPropertyChanged(nameof(SelectedFuntion)); + } + } + public SeriesCollection SeriesCollection + { + get => seriesCollection; + set + { + seriesCollection = value; + OnPropertyChanged(nameof(seriesCollection)); + } + } + public List Labels + { + get => labels; + set + { + labels = value; + OnPropertyChanged(nameof(labels)); + } + } + public TreeGraphView TreeGraphView_win + { + get => _treeGraphView_win; + set => _treeGraphView_win = value; + } + public ObservableCollection FirstGeneration { get => _firstGeneration; } @@ -46,22 +87,27 @@ namespace StructureHelper.Windows.TreeGraph { get => _deleteCommand ??= new RelayCommand(o => Delete()); } - private ObservableCollection functions; - public ObservableCollection Functions { get; set; } - public ObservableCollection Nodes { get; set; } public TreeGraphViewModel(IOneVariableFunction rootFunction) { - _rootFunction = new TreeViewItemViewModel(rootFunction); + _rootFunction = new TreeViewItemViewModel(rootFunction, this); - _firstGeneration = new ReadOnlyCollection( - new TreeViewItemViewModel[] - { - _rootFunction - }); + _firstGeneration = new ObservableCollection + ( + new ObservableCollection() + { + _rootFunction, + } + ); } private void GetY() { - var vm = new GetValueViewModel(new TableFunction()); + var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel; + if (selectedTreeViewItem is null) + { + return; + } + SelectedFuntion = selectedTreeViewItem.Function; + var vm = new GetValueViewModel(SelectedFuntion); var v = new GetValueView(); v.DataContext = vm; v.ShowDialog(); @@ -88,7 +134,20 @@ namespace StructureHelper.Windows.TreeGraph } private void Limit(object parameter) { - var vm = new LimViewModel(); + LimViewModel vm = null; + var type = parameter as string; + if (type.Equals("x")) + { + vm = new LimViewModel(true); + } + else if (type.Equals("y")) + { + vm = new LimViewModel(false); + } + else + { + return; + } var v = new LimView(); v.DataContext = vm; v.ShowDialog(); @@ -99,11 +158,39 @@ namespace StructureHelper.Windows.TreeGraph } private void Delete() { - + var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel; + if (selectedTreeViewItem is null) + { + return; + } + var selectedTreeViewItemParent = selectedTreeViewItem.Parent; + if (selectedTreeViewItemParent is null) + { + return; + } + selectedTreeViewItemParent.Children.Remove(selectedTreeViewItem); } - private void RefreshTree() + public void DrawGraph() { - + var labels = new List(); + var lineSeries = new LineSeries(); + var seriesCollection = new SeriesCollection(); + var chartValues = new ChartValues(); + var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel; + if (selectedTreeViewItem is null) + { + return; + } + SelectedFuntion = selectedTreeViewItem.Function; + foreach (GraphPoint graphPoint in SelectedFuntion.Table) + { + labels.Add(Math.Round(graphPoint.X, 2).ToString()); + chartValues.Add(Math.Round(graphPoint.Y)); + } + lineSeries.Values = chartValues; + Labels = labels; + seriesCollection.Add(lineSeries); + SeriesCollection = seriesCollection; } } } diff --git a/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs index 61bd957..df1f4d6 100644 --- a/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/TreeViewItemViewModel.cs @@ -12,35 +12,40 @@ namespace StructureHelper.Windows.TreeGraph { public class TreeViewItemViewModel : ViewModelBase { - readonly ReadOnlyCollection _children; + readonly ObservableCollection _children; readonly TreeViewItemViewModel _parent; - readonly IOneVariableFunction _functions; + readonly IOneVariableFunction _function; + readonly TreeGraphViewModel _treeGraphViewModel; bool _isExpanded; bool _isSelected; - public TreeViewItemViewModel(IOneVariableFunction function) : this(function, null) + public TreeViewItemViewModel(IOneVariableFunction function, TreeGraphViewModel treeGraphViewModel) : this(function, null, treeGraphViewModel) { } - private TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent) + private TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent, TreeGraphViewModel treeGraphViewModel) { - _functions = function; + _function = function; _parent = parent; - _children = new ReadOnlyCollection + _treeGraphViewModel = treeGraphViewModel; + _children = new ObservableCollection ( - _functions.Functions - .Select(x => new TreeViewItemViewModel(x, this)) + _function.Functions + .Select(x => new TreeViewItemViewModel(x, this, treeGraphViewModel)) .ToList() ); } - public ReadOnlyCollection Children + public IOneVariableFunction Function + { + get { return _function; } + } + public ObservableCollection Children { get { return _children; } } - public string Name { - get { return _functions.Name; } + get { return _function.Name; } } public bool IsExpanded { @@ -65,6 +70,7 @@ namespace StructureHelper.Windows.TreeGraph if (value != _isSelected) { _isSelected = value; + _treeGraphViewModel.DrawGraph(); OnPropertyChanged(nameof(IsSelected)); } } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs index 95ad36e..63f580e 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs @@ -20,6 +20,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces public string Name { get; set; } public string Description { get; set; } public List Table { get; set; } + public double MinArg { get; set; } + public double MaxArg { get; set; } public ObservableCollection Functions { get; set; } public bool Check(); public double GetByX(double xValue); diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs index 04146b2..9555b77 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -21,12 +21,27 @@ namespace StructureHelperCommon.Models.Functions public string Group { get; set; } public string Name { get; set; } public string Description { get ; set; } - public List Table { get; set; } + public int Step { get; set; } + private List table; + public List Table + { + get + { + return CalculateTable(); + } + set + { + table = value; + } + } public string Formula { get; set; } public Guid Id => throw new NotImplementedException(); public ObservableCollection Functions { get; set; } = new ObservableCollection(); + public double MinArg { get; set; } + public double MaxArg { get; set; } + public FormulaFunction(bool isUser = false) { Type = FunctionType.FormulaFunction; @@ -58,12 +73,28 @@ namespace StructureHelperCommon.Models.Functions formulaFunction.Formula = Formula; formulaFunction.IsUser = true; formulaFunction.Group = GROUP_TYPE_2; + formulaFunction.Step = Step; + formulaFunction.MinArg = MinArg; + formulaFunction.MaxArg = MaxArg; return formulaFunction; } public double GetByX(double xValue) { - throw new NotImplementedException(); + double yValue = 0; + yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временное тестовой выражение квадратичной параболы, будет разбор выражения + return yValue; + } + public List CalculateTable() + { + var table = new List(); + var stepLenght = Math.Abs(MaxArg - MinArg) / Step; + for (double x = MinArg; x < MaxArg; x += stepLenght) + { + var graphPoint = new GraphPoint(x, GetByX(x)); + table.Add(graphPoint); + } + return table; } } } diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs index 40d7927..743cb57 100644 --- a/StructureHelperCommon/Models/Functions/TableFunction.cs +++ b/StructureHelperCommon/Models/Functions/TableFunction.cs @@ -27,6 +27,8 @@ namespace StructureHelperCommon.Models.Functions public Guid Id => throw new NotImplementedException(); public ObservableCollection Functions { get; set; } = new ObservableCollection(); + public double MinArg { get; set; } + public double MaxArg { get; set; } public TableFunction(bool isUser = false) {