From d8f0d9dd88e09c09f1fe1370a074225dbad693e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=98=D0=B2=D0=B0=D1=88=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Wed, 16 Oct 2024 14:41:10 +0500 Subject: [PATCH] Add GraphViewModel functions realization --- StructureHelper/StructureHelper.csproj.user | 10 +- .../Windows/MainGraph/AddTable.xaml | 25 ---- .../Windows/MainGraph/AddTableViewModel.cs | 14 -- .../Windows/MainGraph/FormulaView.xaml | 12 ++ .../{AddTable.xaml.cs => FormulaView.xaml.cs} | 6 +- .../Windows/MainGraph/FormulaViewModel.cs | 31 +++++ .../Windows/MainGraph/GraphView.xaml | 5 + .../Windows/MainGraph/GraphViewModel.cs | 71 ++++++++-- .../Windows/MainGraph/TableView.xaml | 113 ++++++++++++++++ .../Windows/MainGraph/TableView.xaml.cs | 39 ++++++ .../Windows/MainGraph/TableViewModel.cs | 123 ++++++++++++++++++ .../Windows/TreeGraph/TreeGraphViewModel.cs | 8 +- .../Interfaces/IOneVariableFunction.cs | 3 +- .../Models/Functions/FormulaFunction.cs | 30 +++-- .../Models/Functions/GraphPoint.cs | 14 ++ .../Models/Functions/TableFunction.cs | 30 +++-- 16 files changed, 444 insertions(+), 90 deletions(-) delete mode 100644 StructureHelper/Windows/MainGraph/AddTable.xaml delete mode 100644 StructureHelper/Windows/MainGraph/AddTableViewModel.cs create mode 100644 StructureHelper/Windows/MainGraph/FormulaView.xaml rename StructureHelper/Windows/MainGraph/{AddTable.xaml.cs => FormulaView.xaml.cs} (80%) create mode 100644 StructureHelper/Windows/MainGraph/FormulaViewModel.cs create mode 100644 StructureHelper/Windows/MainGraph/TableView.xaml create mode 100644 StructureHelper/Windows/MainGraph/TableView.xaml.cs create mode 100644 StructureHelper/Windows/MainGraph/TableViewModel.cs create mode 100644 StructureHelperCommon/Models/Functions/GraphPoint.cs diff --git a/StructureHelper/StructureHelper.csproj.user b/StructureHelper/StructureHelper.csproj.user index 261919a..ea96ed2 100644 --- a/StructureHelper/StructureHelper.csproj.user +++ b/StructureHelper/StructureHelper.csproj.user @@ -57,7 +57,10 @@ Code - + + Code + + Code @@ -164,7 +167,10 @@ Designer - + + Designer + + Designer diff --git a/StructureHelper/Windows/MainGraph/AddTable.xaml b/StructureHelper/Windows/MainGraph/AddTable.xaml deleted file mode 100644 index b10c9fc..0000000 --- a/StructureHelper/Windows/MainGraph/AddTable.xaml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/StructureHelper/Windows/MainGraph/AddTableViewModel.cs b/StructureHelper/Windows/MainGraph/AddTableViewModel.cs deleted file mode 100644 index 7719aea..0000000 --- a/StructureHelper/Windows/MainGraph/AddTableViewModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using StructureHelper.Infrastructure; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StructureHelper.Windows.MainGraph -{ - class AddTableViewModel : ViewModelBase - { - - } -} diff --git a/StructureHelper/Windows/MainGraph/FormulaView.xaml b/StructureHelper/Windows/MainGraph/FormulaView.xaml new file mode 100644 index 0000000..2f5929a --- /dev/null +++ b/StructureHelper/Windows/MainGraph/FormulaView.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/StructureHelper/Windows/MainGraph/AddTable.xaml.cs b/StructureHelper/Windows/MainGraph/FormulaView.xaml.cs similarity index 80% rename from StructureHelper/Windows/MainGraph/AddTable.xaml.cs rename to StructureHelper/Windows/MainGraph/FormulaView.xaml.cs index 870629f..13a3693 100644 --- a/StructureHelper/Windows/MainGraph/AddTable.xaml.cs +++ b/StructureHelper/Windows/MainGraph/FormulaView.xaml.cs @@ -15,11 +15,11 @@ using System.Windows.Shapes; namespace StructureHelper.Windows.MainGraph { /// - /// Interaction logic for AddTable.xaml + /// Interaction logic for FormulaView.xaml /// - public partial class AddTable : Window + public partial class FormulaView : Window { - public AddTable() + public FormulaView() { InitializeComponent(); } diff --git a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs new file mode 100644 index 0000000..2207f75 --- /dev/null +++ b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs @@ -0,0 +1,31 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Functions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelper.Windows.MainGraph +{ + public class FormulaViewModel + { + private IOneVariableFunction function; + public IOneVariableFunction Function + { + get => function; + set + { + function = value; + } + } + public FormulaViewModel() + { + + } + public FormulaViewModel(FormulaFunction function) + { + + } + } +} diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml b/StructureHelper/Windows/MainGraph/GraphView.xaml index d2c363f..aee2c20 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml @@ -38,16 +38,21 @@ + + diff --git a/StructureHelper/Windows/MainGraph/TableView.xaml.cs b/StructureHelper/Windows/MainGraph/TableView.xaml.cs new file mode 100644 index 0000000..0ede25f --- /dev/null +++ b/StructureHelper/Windows/MainGraph/TableView.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace StructureHelper.Windows.MainGraph +{ + /// + /// Interaction logic for AddTable.xaml + /// + public partial class TableView : Window + { + private TableViewModel viewModel; + + public TableView(TableViewModel viewModel) + { + this.viewModel = viewModel; + DataContext = this.viewModel; + InitializeComponent(); + } + /*public AddTable() : this(new AddTableViewModel()) + { + }*/ + public TableView() + { + InitializeComponent(); + } + + } +} diff --git a/StructureHelper/Windows/MainGraph/TableViewModel.cs b/StructureHelper/Windows/MainGraph/TableViewModel.cs new file mode 100644 index 0000000..6c60001 --- /dev/null +++ b/StructureHelper/Windows/MainGraph/TableViewModel.cs @@ -0,0 +1,123 @@ +using StructureHelper.Infrastructure; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Functions; +using StructureHelperCommon.Models.Shapes; +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.Input; + +namespace StructureHelper.Windows.MainGraph +{ + public class TableViewModel : ViewModelBase + { + private const string DEFAULT_NAME = "Put function name here..."; + private const string DEFAULT_DESCRIPTION = "Put function description here..."; + private RelayCommand drawGraphCommand; + private RelayCommand addPointCommand; + private RelayCommand deletePointCommand; + public ICommand DrawGraphCommand + { + get => drawGraphCommand ??= new RelayCommand(o => DrawGraph(o)); + } + public ICommand AddPointCommand + { + get => addPointCommand ??= new RelayCommand(o => AddPoint()); + } + public ICommand DeletePointCommand + { + get => deletePointCommand ??= new RelayCommand(o => DeletePoint()); + } + + private ObservableCollection table; + + public ObservableCollection Table + { + get => table; + set + { + table = value; + } + } + private GraphPoint selectedPoint; + public GraphPoint SelectedPoint + { + get => selectedPoint; + set + { + selectedPoint = value; + OnPropertyChanged(nameof(SelectedPoint)); + } + } + private IOneVariableFunction function; + public IOneVariableFunction Function + { + get => function; + set + { + function = value; + } + } + private string name; + public string Name + { + get => name; + set + { + name = value; + } + } + private string description; + public string Description + { + get => description; + set + { + description = value; + } + } + public TableViewModel() + { + Table = new ObservableCollection() + { + new GraphPoint(), + }; + Name = DEFAULT_NAME; + Description = DEFAULT_DESCRIPTION; + } + public TableViewModel(TableFunction tableFunction) + { + Function = tableFunction; + Table = new ObservableCollection(tableFunction.Table); + Name = tableFunction.Name; + Description = tableFunction.Description; + } + private void DrawGraph(object parameter) + { + if (Function is null) + { + Function = new TableFunction(); + } + Function.Name = Name; + Function.Description = Description; + Function.IsUser = true; + (Function as TableFunction).Table = Table.ToList(); + var window = parameter as Window; + window.DialogResult = true; + window.Close(); + } + private void AddPoint() + { + var point = new GraphPoint(); + Table.Add(point); + } + private void DeletePoint() + { + Table.Remove(SelectedPoint); + } + } +} diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs index 09030e3..87f9ef6 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs @@ -3,6 +3,7 @@ using StructureHelper.Infrastructure; 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,12 +12,13 @@ namespace StructureHelper.Windows.TreeGraph { public class TreeGraphViewModel : ViewModelBase { - private List nodes; - public List Nodes { get; set; } + private ObservableCollection nodes; + public ObservableCollection Nodes { get; set; } public TreeGraphViewModel(IOneVariableFunction function) { - Nodes = new List(); + Nodes = new ObservableCollection(); Nodes.Add(function); } + } } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs index 77d97ef..df1aeca 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs @@ -7,9 +7,8 @@ using System.Threading.Tasks; namespace StructureHelperCommon.Infrastructures.Interfaces { - public interface IOneVariableFunction + public interface IOneVariableFunction : ICloneable, ISaveable { - public bool IsUser { get; set; } public FunctionType Type { get; set; } public string Name { get; set; } diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs index 0965eb5..5baf4ba 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Documents; namespace StructureHelperCommon.Models.Functions { @@ -14,28 +15,29 @@ namespace StructureHelperCommon.Models.Functions public FunctionType Type { get; set; } public string Name { get; set; } public string Description { get ; set; } + public string Formula { get; set; } + + public Guid Id => throw new NotImplementedException(); public bool Check() { throw new NotImplementedException(); } - public double GetByX(double xValue) - { - throw new NotImplementedException(); - } - } - public class CopyOfFormulaFunction : IOneVariableFunction - { - public bool IsUser { get; set; } - public FunctionType Type { get; set; } - public string Name { get; set; } - public string Description { get; set; } - - public bool Check() + public object Clone() { - throw new NotImplementedException(); + var formulaFunction = new FormulaFunction(); + + //Здесь будет стратегия + formulaFunction.Type = Type; + formulaFunction.Name = Name; + formulaFunction.Description = Description; + formulaFunction.Formula = Formula; + formulaFunction.IsUser = true; + + return formulaFunction; } + public double GetByX(double xValue) { throw new NotImplementedException(); diff --git a/StructureHelperCommon/Models/Functions/GraphPoint.cs b/StructureHelperCommon/Models/Functions/GraphPoint.cs new file mode 100644 index 0000000..a72348f --- /dev/null +++ b/StructureHelperCommon/Models/Functions/GraphPoint.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Functions +{ + public class GraphPoint + { + public double X { get; set; } + public double Y { get; set; } + } +} diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs index 4b9de96..db6850e 100644 --- a/StructureHelperCommon/Models/Functions/TableFunction.cs +++ b/StructureHelperCommon/Models/Functions/TableFunction.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; @@ -14,28 +15,29 @@ namespace StructureHelperCommon.Models.Functions public FunctionType Type { get; set; } public string Name { get; set; } public string Description { get; set; } + public List Table { get; set; } + + public Guid Id => throw new NotImplementedException(); public bool Check() { throw new NotImplementedException(); } - public double GetByX(double xValue) - { - throw new NotImplementedException(); - } - } - public class CopyOfTableFunction : IOneVariableFunction - { - public bool IsUser { get; set; } - public FunctionType Type { get; set; } - public string Name { get; set; } - public string Description { get; set; } - - public bool Check() + public object Clone() { - throw new NotImplementedException(); + var tableFunction = new TableFunction(); + + //Здесь будет стратегия + tableFunction.Type = Type; + tableFunction.Name = Name; + tableFunction.Description = Description; + tableFunction.Table = Table; + tableFunction.IsUser = true; + + return tableFunction; } + public double GetByX(double xValue) { throw new NotImplementedException();