diff --git a/StructureHelper/Windows/MainGraph/FormulaView.xaml b/StructureHelper/Windows/MainGraph/FormulaView.xaml index 70c763e..c3a165a 100644 --- a/StructureHelper/Windows/MainGraph/FormulaView.xaml +++ b/StructureHelper/Windows/MainGraph/FormulaView.xaml @@ -1,4 +1,5 @@  + Title="FormulaFunction" Height="320" Width="400"> @@ -31,25 +30,21 @@ - - - - + TextWrapping="Wrap"> @@ -75,7 +70,7 @@ diff --git a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs index 2207f75..dbfdc43 100644 --- a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs +++ b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs @@ -1,15 +1,52 @@ -using StructureHelperCommon.Infrastructures.Interfaces; + +using StructureHelper.Infrastructure; +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; +using System.Windows; +using System.Windows.Documents; +using System.Windows.Input; namespace StructureHelper.Windows.MainGraph { - public class FormulaViewModel + public class FormulaViewModel : ViewModelBase { + private const string DEFAULT_NAME = "Put function name here..."; + private const string DEFAULT_DESCRIPTION = "Put function description here..."; + private const string DEFAULT_FORMULA = "x^2"; + 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 + { + get => drawGraphCommand ??= new RelayCommand(o => Save(o)); + } + private string formula; + + public string Formula + { + get => formula; + set + { + formula = value; + } + } + private string formulaText = "y(x)="; + public string FormulaText + { + get => formulaText; + set + { + formulaText = $"y(x)={Formula}"; + OnPropertyChanged(nameof(Formula)); + } + } private IOneVariableFunction function; public IOneVariableFunction Function { @@ -19,13 +56,49 @@ namespace StructureHelper.Windows.MainGraph function = value; } } - public FormulaViewModel() + private string name; + public string Name { - + get => name; + set + { + name = value; + } } - public FormulaViewModel(FormulaFunction function) + private string description; + public string Description { - + get => description; + set + { + description = value; + } } + public FormulaViewModel() + { + Name = DEFAULT_NAME; + Description = DEFAULT_DESCRIPTION; + } + public FormulaViewModel(FormulaFunction formulaFunction) + { + Function = formulaFunction; + Name = Function.Name; + Description = Function.Description; + } + private void Save(object parameter) + { + if (Function is null) + { + Function = new FormulaFunction(); + } + Function.Name = Name; + Function.Description = Description; + Function.IsUser = true; + (Function as FormulaFunction).Formula = Formula; + var window = parameter as Window; + window.DialogResult = true; + window.Close(); + } + } } diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml b/StructureHelper/Windows/MainGraph/GraphView.xaml index 6a44b0b..6de161f 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml @@ -18,15 +18,44 @@ - - + + + + + + + + + + + + + - + - - + + diff --git a/StructureHelper/Windows/MainGraph/GraphViewModel.cs b/StructureHelper/Windows/MainGraph/GraphViewModel.cs index 9fa55ae..079311d 100644 --- a/StructureHelper/Windows/MainGraph/GraphViewModel.cs +++ b/StructureHelper/Windows/MainGraph/GraphViewModel.cs @@ -6,6 +6,7 @@ using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models.Functions; using StructureHelperLogics.Models.Graphs; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows.Input; @@ -47,6 +48,7 @@ namespace StructureHelper.Windows.MainGraph private RelayCommand deleteCommand; private RelayCommand copyCommand; private RelayCommand treeCommand; + private RelayCommand drawGraphCommand; public ICommand AddTableCommand { get => addTableCommand ??= new RelayCommand(o => AddTable()); @@ -71,47 +73,47 @@ namespace StructureHelper.Windows.MainGraph { get => treeCommand ??= new RelayCommand(o => Tree()); } + public ICommand DrawGraphCommand + { + get => drawGraphCommand ??= new RelayCommand(o => DrawGraph()); + } public GraphViewModel() { Functions = new ObservableCollection(); var f1 = new TableFunction(); - f1.Name = "Пробная табличная системная функция 1"; - f1.Table = new List(); + f1.Name = "Табличная системная функция"; + f1.Table = new List() + { + new GraphPoint(1, 0), + new GraphPoint(0, 1), + }; f1.IsUser = false; - f1.Description = "Описание 1"; - var f2 = new TableFunction(); + f1.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"; + f2.Description = "Описание 2";*/ var f3 = new FormulaFunction(); - f3.Name = "Пробная формульная системная функция 3"; + f3.Name = "Формульная системная функция"; f3.Formula = "x^2"; f3.IsUser = false; - f3.Description = "Описание 3"; + f3.Description = "Описание формульной системной функции"; Functions.Add(f1); - Functions.Add(f2); + //Functions.Add(f2); Functions.Add(f3); - - - Labels = new List(); - Labels.Add("1"); - Labels.Add("2"); - Labels.Add("2"); - Labels.Add("3"); - var chartValues = new ChartValues(); - chartValues.Add(1); - chartValues.Add(10); - chartValues.Add(100); - chartValues.Add(25); - chartValues.Add(150); - chartValues.Add(100); - chartValues.Add(200); - chartValues.Add(50); - var lineSeries = new LineSeries(); - lineSeries.Values = chartValues; - SeriesCollection = new SeriesCollection(); - SeriesCollection.Add(lineSeries); + Functions.Add(f4); } /*public GraphViewModel(IGraph graph) { @@ -148,8 +150,6 @@ namespace StructureHelper.Windows.MainGraph var tableView = new TableView(); tableView.DataContext = tableViewModel; tableView.ShowDialog(); - //SelectedFunction.Name = tableViewModel.Function.Name; //!!!!!!!!!! - //SelectedFunction.Description = tableViewModel.Function.Description; //!!!!!!!!!! } else if (SelectedFuntion.Type == FunctionType.FormulaFunction) { @@ -157,13 +157,23 @@ namespace StructureHelper.Windows.MainGraph var formulaView = new FormulaView(); formulaView.DataContext = formulaViewModel; formulaView.ShowDialog(); - //SelectedFunction.Name = formulaViewModel.Function.Name; //!!!!!!!!!! - //SelectedFunction.Description = formulaViewModel.Function.Description; //!!!!!!!!!! + } } private void Delete() { - Functions.Remove(SelectedFuntion); + if (SelectedFuntion is null) + { + var lastFunction = Functions[Functions.Count - 1]; + if (lastFunction.IsUser) + { + Functions.Remove(lastFunction); + } + } + else + { + Functions.Remove(SelectedFuntion); + } } private void Copy() { @@ -187,5 +197,20 @@ namespace StructureHelper.Windows.MainGraph treeGraph.DataContext = treeGraphVM; treeGraph.ShowDialog(); } + private void DrawGraph() + { + var labels = new List(); + var lineSeries = new LineSeries(); + var seriesCollection = new SeriesCollection(); + var chartValues = new ChartValues(); + 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 = seriesCollection; + } } } diff --git a/StructureHelper/Windows/MainGraph/TableViewModel.cs b/StructureHelper/Windows/MainGraph/TableViewModel.cs index 18b28b9..3dac3f0 100644 --- a/StructureHelper/Windows/MainGraph/TableViewModel.cs +++ b/StructureHelper/Windows/MainGraph/TableViewModel.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; @@ -22,7 +23,7 @@ namespace StructureHelper.Windows.MainGraph private RelayCommand deletePointCommand; public ICommand DrawGraphCommand { - get => drawGraphCommand ??= new RelayCommand(o => DrawGraph(o)); + get => drawGraphCommand ??= new RelayCommand(o => Save(o)); } public ICommand AddPointCommand { @@ -84,7 +85,8 @@ namespace StructureHelper.Windows.MainGraph { Table = new ObservableCollection() { - new GraphPoint(), + new GraphPoint(0, 0), + new GraphPoint(0, 0), }; Name = DEFAULT_NAME; Description = DEFAULT_DESCRIPTION; @@ -96,7 +98,7 @@ namespace StructureHelper.Windows.MainGraph Name = Function.Name; Description = Function.Description; } - private void DrawGraph(object parameter) + private void Save(object parameter) { if (Function is null) { @@ -112,12 +114,31 @@ namespace StructureHelper.Windows.MainGraph } private void AddPoint() { - var point = new GraphPoint(); - Table.Add(point); + var point = new GraphPoint(0, 0); + if (SelectedPoint is null) + { + Table.Add(point); + } + else + { + var selectedPointIndex = Table.IndexOf(SelectedPoint); + Table.Insert(selectedPointIndex + 1, point); + } } private void DeletePoint() { - Table.Remove(SelectedPoint); + if (Table.Count < 3) + { + return; + } + if (SelectedPoint is null) + { + Table.RemoveAt(Table.Count - 1); + } + else + { + Table.Remove(SelectedPoint); + } } } } diff --git a/StructureHelper/Windows/TreeGraph/GetValueView.xaml b/StructureHelper/Windows/TreeGraph/GetValueView.xaml index b6a5ba3..3401098 100644 --- a/StructureHelper/Windows/TreeGraph/GetValueView.xaml +++ b/StructureHelper/Windows/TreeGraph/GetValueView.xaml @@ -29,9 +29,7 @@ - + TextWrapping="Wrap"> @@ -65,9 +62,7 @@ - + TextWrapping="Wrap"> diff --git a/StructureHelper/Windows/TreeGraph/LimViewModel.cs b/StructureHelper/Windows/TreeGraph/LimViewModel.cs index 21831ec..ea18a01 100644 --- a/StructureHelper/Windows/TreeGraph/LimViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/LimViewModel.cs @@ -9,7 +9,7 @@ namespace StructureHelper.Windows.TreeGraph { public class LimViewModel : ViewModelBase { - public char GREATER { get; } = '\u2A7E'; + public char GREATER { get; } = '\u2265'; public char LESS { get; } = '\u2264'; public char IN { get; } = '\u2208'; public char LEFT_BOUND { get; } = '['; @@ -25,19 +25,33 @@ namespace StructureHelper.Windows.TreeGraph public string LimitText { get => limitText; - set => limitText = value; + set + { + limitText = value; + OnPropertyChanged(nameof(LimitText)); + } } private double leftBound; private double rightBound; public double LeftBound { get => leftBound; - set => leftBound = value; + set + { + leftBound = value; + LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{value}" + $"{SEMICOLON}" + $"{rightBound}" + $"{RIGHT_BOUND}"; + OnPropertyChanged(nameof(LeftBound)); + } } public double RightBound { get => rightBound; - set => rightBound = value; + set + { + rightBound = value; + LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{LeftBound}" + $"{SEMICOLON}" + $"{value}" + $"{RIGHT_BOUND}"; + OnPropertyChanged(nameof(RightBound)); + } } public LimViewModel() { diff --git a/StructureHelper/Windows/TreeGraph/Node.cs b/StructureHelper/Windows/TreeGraph/Node.cs new file mode 100644 index 0000000..dde2a6e --- /dev/null +++ b/StructureHelper/Windows/TreeGraph/Node.cs @@ -0,0 +1,15 @@ +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/ScaleView.xaml b/StructureHelper/Windows/TreeGraph/ScaleView.xaml index f40f830..39a8c46 100644 --- a/StructureHelper/Windows/TreeGraph/ScaleView.xaml +++ b/StructureHelper/Windows/TreeGraph/ScaleView.xaml @@ -28,23 +28,23 @@ - - + TextWrapping="Wrap"> diff --git a/StructureHelper/Windows/TreeGraph/ScaleViewModel.cs b/StructureHelper/Windows/TreeGraph/ScaleViewModel.cs index 8292057..fdfc0d3 100644 --- a/StructureHelper/Windows/TreeGraph/ScaleViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/ScaleViewModel.cs @@ -9,20 +9,48 @@ namespace StructureHelper.Windows.TreeGraph { public class ScaleViewModel : ViewModelBase { + private bool isArg = false; private double scaleFactor; private string scaleText; + private const string X_DEFAULT_SCALE_TEXT = "y=f(sx)"; + private const string Y_DEFAULT_SCALE_TEXT = "y=sf(x)"; public double ScaleFactor { get => scaleFactor; - set => scaleFactor = value; + set + { + scaleFactor = value; + if (isArg) + { + ScaleText = $"y=f({value}x)"; + } + else + { + ScaleText = $"y={value}f(x)"; + } + OnPropertyChanged(nameof(ScaleFactor)); + } } public string ScaleText { get => scaleText; - set => scaleText = value; + set + { + scaleText = value; + OnPropertyChanged(nameof(ScaleText)); + } } - public ScaleViewModel() - { + public ScaleViewModel(bool isArg) + { + this.isArg = isArg; + if (isArg) + { + ScaleText = $"{X_DEFAULT_SCALE_TEXT}"; + } + else + { + ScaleText= $"{Y_DEFAULT_SCALE_TEXT}"; + } } } } diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml index dbbf7f9..fb4af47 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml +++ b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml @@ -18,13 +18,15 @@ - - - - - - + + + + + + diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs index ae5599c..cc20e22 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs @@ -39,12 +39,21 @@ namespace StructureHelper.Windows.TreeGraph { get => _deleteCommand ??= new RelayCommand(o => Delete()); } - private ObservableCollection nodes; - public ObservableCollection Nodes { get; set; } + private ObservableCollection functions; + public ObservableCollection Functions { get; set; } + public ObservableCollection Nodes { get; set; } public TreeGraphViewModel(IOneVariableFunction function) { - Nodes = new ObservableCollection(); - Nodes.Add(function); + Functions = new ObservableCollection(); + Functions.Add(function); + Nodes = new ObservableCollection() + { + new Node(), + new Node(), + new Node(), + new Node(), + new Node(), + }; } private void GetY() { @@ -55,7 +64,20 @@ namespace StructureHelper.Windows.TreeGraph } private void Scale(object parameter) { - var vm = new ScaleViewModel(); + ScaleViewModel vm = null; + var type = parameter as string; + if (type.Equals("x")) + { + vm = new ScaleViewModel(true); + } + else if (type.Equals("y")) + { + vm = new ScaleViewModel(false); + } + else + { + return; + } var v = new ScaleView(); v.DataContext = vm; v.ShowDialog(); @@ -69,10 +91,15 @@ namespace StructureHelper.Windows.TreeGraph } private void Edit() { + } private void Delete() { + } + private void RefreshTree() + { + } } } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs index be94665..53a4d7b 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs @@ -1,6 +1,8 @@ using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Models.Functions; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; @@ -14,6 +16,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces public FunctionType Type { get; set; } public string Name { get; set; } public string Description { get; set; } + public List Table { 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 5baf4ba..7f6071f 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -2,6 +2,7 @@ using StructureHelperCommon.Infrastructures.Interfaces; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,14 +12,22 @@ namespace StructureHelperCommon.Models.Functions { public class FormulaFunction : IOneVariableFunction { + private const string COPY = "copy"; public bool IsUser { get; set; } public FunctionType Type { get; set; } public string Name { get; set; } public string Description { get ; set; } + public List Table { get; set; } public string Formula { get; set; } public Guid Id => throw new NotImplementedException(); + public ObservableCollection Functions { get; set; } + public FormulaFunction() + { + Type = FunctionType.FormulaFunction; + } + public bool Check() { throw new NotImplementedException(); @@ -30,11 +39,10 @@ namespace StructureHelperCommon.Models.Functions //Здесь будет стратегия formulaFunction.Type = Type; - formulaFunction.Name = Name; + formulaFunction.Name = $"{Name} {COPY}"; formulaFunction.Description = Description; formulaFunction.Formula = Formula; formulaFunction.IsUser = true; - return formulaFunction; } diff --git a/StructureHelperCommon/Models/Functions/GraphPoint.cs b/StructureHelperCommon/Models/Functions/GraphPoint.cs index a72348f..0a09608 100644 --- a/StructureHelperCommon/Models/Functions/GraphPoint.cs +++ b/StructureHelperCommon/Models/Functions/GraphPoint.cs @@ -6,9 +6,20 @@ using System.Threading.Tasks; namespace StructureHelperCommon.Models.Functions { - public class GraphPoint + public class GraphPoint : ICloneable { public double X { get; set; } public double Y { get; set; } + + public GraphPoint(double x, double y) + { + X = x; + Y = y; + } + public object Clone() + { + var clone = new GraphPoint(X,Y); + return clone; + } } } diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs index ca8faf4..43b8fa3 100644 --- a/StructureHelperCommon/Models/Functions/TableFunction.cs +++ b/StructureHelperCommon/Models/Functions/TableFunction.cs @@ -12,7 +12,9 @@ namespace StructureHelperCommon.Models.Functions { public class TableFunction : IOneVariableFunction { + private const string COPY = "copy"; private string name; + public bool IsUser { get; set; } public FunctionType Type { get; set; } public string Name @@ -27,8 +29,12 @@ namespace StructureHelperCommon.Models.Functions public List Table { get; set; } public Guid Id => throw new NotImplementedException(); + public ObservableCollection Functions { get; set; } - public event PropertyChangedEventHandler? PropertyChanged; + public TableFunction() + { + Type = FunctionType.TableFunction; + } public bool Check() { @@ -41,9 +47,11 @@ namespace StructureHelperCommon.Models.Functions //Здесь будет стратегия tableFunction.Type = Type; - tableFunction.Name = Name; + tableFunction.Name = $"{Name} {COPY}"; tableFunction.Description = Description; - tableFunction.Table = Table; + var newTable = new List(); + Table.ForEach(x => newTable.Add(x.Clone() as GraphPoint)); + tableFunction.Table = newTable; tableFunction.IsUser = true; return tableFunction;