Add GraphViewModel functions realization

This commit is contained in:
Иван Ивашкин
2024-10-16 14:41:10 +05:00
parent 883dbb189f
commit d8f0d9dd88
16 changed files with 444 additions and 90 deletions

View File

@@ -57,7 +57,10 @@
<Compile Update="Windows\Graphs\GraphView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\MainGraph\AddTable.xaml.cs">
<Compile Update="Windows\MainGraph\FormulaView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\MainGraph\TableView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\MainGraph\GraphView.xaml.cs">
@@ -164,7 +167,10 @@
<Page Update="Windows\Graphs\GraphView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\MainGraph\AddTable.xaml">
<Page Update="Windows\MainGraph\FormulaView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\MainGraph\TableView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\MainGraph\GraphView.xaml">

View File

@@ -1,25 +0,0 @@
<Window x:Class="StructureHelper.Windows.MainGraph.AddTable"
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
mc:Ignorable="d"
ResizeMode="CanResize"
Title="AddTable" Height="450" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Margin="5">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="X"/>
<DataGridTextColumn Width="*" Header="Y"/>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Row="1" Margin="5" Content="Build Graph">
</Button>
</Grid>
</Window>

View File

@@ -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
{
}
}

View File

@@ -0,0 +1,12 @@
<Window x:Class="StructureHelper.Windows.MainGraph.FormulaView"
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
mc:Ignorable="d"
Title="FormulaView" Height="450" Width="800">
<Grid>
</Grid>
</Window>

View File

@@ -15,11 +15,11 @@ using System.Windows.Shapes;
namespace StructureHelper.Windows.MainGraph
{
/// <summary>
/// Interaction logic for AddTable.xaml
/// Interaction logic for FormulaView.xaml
/// </summary>
public partial class AddTable : Window
public partial class FormulaView : Window
{
public AddTable()
public FormulaView()
{
InitializeComponent();
}

View File

@@ -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)
{
}
}
}

View File

@@ -38,16 +38,21 @@
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Margin="5" Content="Add table"
Command="{Binding AddTableCommand}"
Background="LightGreen"/>
<Button Grid.Column="0" Grid.Row="1" Margin="5" Content="Add formula"
Command="{Binding AddFormulaCommand}"
Background="LightGreen"/>
<Button Grid.Column="1" Grid.Row="0" Margin="5" Content="Edit"
Command="{Binding EditCommand}"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"
Background="LightYellow"/>
<Button Grid.Column="1" Grid.Row="1" Margin="5" Content="Delete"
Command="{Binding DeleteCommand}"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"
Background="LightPink"/>
<Button Grid.Column="2" Grid.Row="0" Margin="5" Content="Copy"
Command="{Binding CopyCommand}"
Background="LightBlue"/>
<Button Grid.Column="2" Grid.Row="1" Margin="5" Content="Tree"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"

View File

@@ -2,10 +2,12 @@
using LiveCharts.Wpf;
using StructureHelper.Infrastructure;
using StructureHelper.Windows.TreeGraph;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions;
using StructureHelperLogics.Models.Graphs;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace StructureHelper.Windows.MainGraph
@@ -30,8 +32,8 @@ namespace StructureHelper.Windows.MainGraph
OnPropertyChanged(nameof(SelectedFuntion));
}
}
private List<IOneVariableFunction> functions;
public List<IOneVariableFunction> Functions { get; set; }
private ObservableCollection<IOneVariableFunction> functions;
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
@@ -51,19 +53,19 @@ namespace StructureHelper.Windows.MainGraph
}
public ICommand AddFormulaCommand
{
get => addFormulaCommand ??= new RelayCommand(o => AddTable());
get => addFormulaCommand ??= new RelayCommand(o => AddFormula());
}
public ICommand EditCommand
{
get => editCommand ??= new RelayCommand(o => AddTable());
get => editCommand ??= new RelayCommand(o => Edit());
}
public ICommand DeleteCommand
{
get => deleteCommand ??= new RelayCommand(o => AddTable());
get => deleteCommand ??= new RelayCommand(o => Delete());
}
public ICommand CopyCommand
{
get => copyCommand ??= new RelayCommand(o => AddTable());
get => copyCommand ??= new RelayCommand(o => Copy());
}
public ICommand TreeCommand
{
@@ -71,17 +73,20 @@ namespace StructureHelper.Windows.MainGraph
}
public GraphViewModel()
{
Functions = new List<IOneVariableFunction>();
Functions = new ObservableCollection<IOneVariableFunction>();
var f1 = new TableFunction();
f1.Name = "Пробная табличная системная функция 1";
f1.Table = new List<GraphPoint>();
f1.IsUser = false;
f1.Description = "Описание 1";
var f2 = new TableFunction();
f2.Name = "Пробная табличная пользовательская функция 2";
f2.Table = new List<GraphPoint>();
f2.IsUser = true;
f2.Description = "Описание 2";
var f3 = new FormulaFunction();
f3.Name = "Пробная формульная системная функция 3";
f3.Formula = "x^2";
f3.IsUser = false;
f3.Description = "Описание 3";
Functions.Add(f1);
@@ -113,23 +118,63 @@ namespace StructureHelper.Windows.MainGraph
}*/
private void AddTable()
{
var tableViewModel = new TableViewModel();
var tableView = new TableView();
tableView.DataContext = tableViewModel;
if (tableView.ShowDialog() == true)
{
Functions.Add(tableViewModel.Function);
}
}
private void AddFormula()
{
var formulaViewModel = new FormulaViewModel();
var formulaView = new FormulaView();
formulaView.DataContext = formulaViewModel;
if (formulaView.ShowDialog() == true)
{
Functions.Add(formulaViewModel.Function);
}
}
private void Edit()
{
if (SelectedFuntion is null)
{
return;
}
if (SelectedFuntion.Type == FunctionType.TableFunction)
{
var tableViewModel = new TableViewModel(SelectedFuntion as TableFunction);
var tableView = new TableView();
tableView.DataContext = tableViewModel;
tableView.ShowDialog();
}
else if (SelectedFuntion.Type == FunctionType.FormulaFunction)
{
var formulaViewModel = new FormulaViewModel(SelectedFuntion as FormulaFunction);
var formulaView = new FormulaView();
formulaView.DataContext = formulaViewModel;
formulaView.ShowDialog();
}
}
private void Delete()
{
Functions.Remove(SelectedFuntion);
}
private void Cppy()
private void Copy()
{
if (SelectedFuntion is null)
{
return;
}
else if (SelectedFuntion.Type == FunctionType.TableFunction)
{
Functions.Add(SelectedFuntion.Clone() as TableFunction);
}
else if (SelectedFuntion.Type == FunctionType.FormulaFunction)
{
Functions.Add(SelectedFuntion.Clone() as FormulaFunction);
}
}
private void Tree()
{

View File

@@ -0,0 +1,113 @@
<Window x:Class="StructureHelper.Windows.MainGraph.TableView"
x:Name="TableFunction_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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
mc:Ignorable="d"
ResizeMode="CanResize"
d:DataContext="{d:DesignInstance local:TableViewModel}"
Title="TableFunction" Height="500" Width="400"
MaxWidth="400"
MinWidth="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid Grid.Column="0" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="37"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="1"
Grid.Row="0"
Stroke="Gray"/>
<Rectangle Grid.Column="2"
Grid.Row="0"
Stroke="Gray"/>
<TextBlock Grid.Column="0">
</TextBlock>
<TextBlock Grid.Column="1"
HorizontalAlignment="Center"
Text="X">
</TextBlock>
<TextBlock Grid.Column="2"
HorizontalAlignment="Center"
Text="Y">
</TextBlock>
<TextBlock Grid.Column="3">
</TextBlock>
</Grid>
<ListBox Grid.Row="1" Margin="5"
ItemsSource="{Binding Table,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay}"
SelectedItem="{Binding SelectedPoint}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="30"
MaxWidth="30">
</TextBlock>
<TextBox Text="{Binding X}"
Width="150"
MaxWidth="150">
</TextBox>
<TextBox Text="{Binding Y}"
Width="150"
MaxWidth="150">
</TextBox>
<TextBlock Width="25"
MaxWidth="25">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" Margin="5" Content="Add"
Background="LightGreen" Command="{Binding AddPointCommand}"/>
<Button Grid.Column="2" Margin="5" Content="Delete"
Background="LightPink" Command="{Binding DeletePointCommand}"/>
</Grid>
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="5"
Text="Name:"
VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Text="{Binding Name}" Margin="5"/>
</Grid>
<Grid Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="5"
Text="Description:"
VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Text="{Binding Name}" Margin="5"/>
</Grid>
<Button Grid.Row="5" Margin="5" Content="Save"
Command="{Binding DrawGraphCommand}"
CommandParameter="{Binding ElementName=TableFunction_win}">
</Button>
</Grid>
</Window>

View File

@@ -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
{
/// <summary>
/// Interaction logic for AddTable.xaml
/// </summary>
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();
}
}
}

View File

@@ -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<GraphPoint> table;
public ObservableCollection<GraphPoint> 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<GraphPoint>()
{
new GraphPoint(),
};
Name = DEFAULT_NAME;
Description = DEFAULT_DESCRIPTION;
}
public TableViewModel(TableFunction tableFunction)
{
Function = tableFunction;
Table = new ObservableCollection<GraphPoint>(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);
}
}
}

View File

@@ -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<IOneVariableFunction> nodes;
public List<IOneVariableFunction> Nodes { get; set; }
private ObservableCollection<IOneVariableFunction> nodes;
public ObservableCollection<IOneVariableFunction> Nodes { get; set; }
public TreeGraphViewModel(IOneVariableFunction function)
{
Nodes = new List<IOneVariableFunction>();
Nodes = new ObservableCollection<IOneVariableFunction>();
Nodes.Add(function);
}
}
}

View File

@@ -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; }

View File

@@ -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();

View File

@@ -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; }
}
}

View File

@@ -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<GraphPoint> 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();