Fix: return graph from player to independent button, develop: add MainGraphView, TreeView, TreeCommand.

This commit is contained in:
Иван Ивашкин
2024-10-14 20:36:25 +05:00
parent b5ed00341c
commit 883dbb189f
17 changed files with 440 additions and 21 deletions

View File

@@ -0,0 +1,25 @@
<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

@@ -0,0 +1,27 @@
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 AddTable : Window
{
public AddTable()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,14 @@
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

@@ -3,15 +3,76 @@
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:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
mc:Ignorable="d"
Title="GraphView" Height="450" Width="800">
d:DataContext="{d:DesignInstance local:GraphViewModel}"
Title="StructureHelper" Height="700"
Width="1000" MinHeight="400" MinWidth="600">
<Grid>
<TextBlock
Text = "Здесь будет приложение с графиком"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<ListBox Grid.Row="0" Grid.Column="0" Margin="5"
ItemsSource="{Binding Functions}"
SelectedItem="{Binding SelectedFuntion}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Margin="5" Content="Add table"
Background="LightGreen"/>
<Button Grid.Column="0" Grid.Row="1" Margin="5" Content="Add formula"
Background="LightGreen"/>
<Button Grid.Column="1" Grid.Row="0" Margin="5" Content="Edit"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"
Background="LightYellow"/>
<Button Grid.Column="1" Grid.Row="1" Margin="5" Content="Delete"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"
Background="LightPink"/>
<Button Grid.Column="2" Grid.Row="0" Margin="5" Content="Copy"
Background="LightBlue"/>
<Button Grid.Column="2" Grid.Row="1" Margin="5" Content="Tree"
IsEnabled="{Binding SelectedFuntion.IsUser, UpdateSourceTrigger=PropertyChanged}"
Command="{Binding TreeCommand}"
Background="AntiqueWhite"/>
</Grid>
<lvc:CartesianChart Grid.Row="0" Grid.Column="1"
Series="{Binding SeriesCollection}" Margin="5">
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Y"></lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="X" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<Grid Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Description:" Margin="5"/>
<TextBlock Grid.Row="1"
Text="{Binding SelectedFuntion.Description, UpdateSourceTrigger=PropertyChanged}"
Margin="5" TextWrapping="Wrap"
VerticalAlignment="Center" Height="60"/>
</Grid>
</Grid>
</Window>

View File

@@ -1,4 +1,8 @@
using System;
using StructureHelper.Windows.MainWindow;
using StructureHelper.Windows.ViewModels.Materials;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Graphs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -19,9 +23,15 @@ namespace StructureHelper.Windows.MainGraph
/// </summary>
public partial class GraphView : Window
{
public GraphView()
private GraphViewModel viewModel;
public GraphView(GraphViewModel viewModel)
{
this.viewModel = viewModel;
DataContext = this.viewModel;
InitializeComponent();
}
public GraphView() : this(new GraphViewModel())
{
}
}
}

View File

@@ -0,0 +1,142 @@
using LiveCharts;
using LiveCharts.Wpf;
using StructureHelper.Infrastructure;
using StructureHelper.Windows.TreeGraph;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions;
using StructureHelperLogics.Models.Graphs;
using System.Collections.Generic;
using System.Windows.Input;
namespace StructureHelper.Windows.MainGraph
{
public class GraphViewModel : ViewModelBase
{
public SeriesCollection SeriesCollection { get; set; }
public List<string> Labels { get; set; }
private IOneVariableFunction selectedFunction;
public IOneVariableFunction SelectedFuntion
{
get
{
return selectedFunction;
}
set
{
selectedFunction = value;
OnPropertyChanged(nameof(SelectedFuntion));
}
}
private List<IOneVariableFunction> functions;
public List<IOneVariableFunction> Functions { get; set; }
private RelayCommand addTableCommand;
private RelayCommand addFormulaCommand;
private RelayCommand editCommand;
private RelayCommand deleteCommand;
private RelayCommand copyCommand;
private RelayCommand treeCommand;
public ICommand AddTableCommand
{
get => addTableCommand ??= new RelayCommand(o => AddTable());
}
public ICommand AddFormulaCommand
{
get => addFormulaCommand ??= new RelayCommand(o => AddTable());
}
public ICommand EditCommand
{
get => editCommand ??= new RelayCommand(o => AddTable());
}
public ICommand DeleteCommand
{
get => deleteCommand ??= new RelayCommand(o => AddTable());
}
public ICommand CopyCommand
{
get => copyCommand ??= new RelayCommand(o => AddTable());
}
public ICommand TreeCommand
{
get => treeCommand ??= new RelayCommand(o => Tree());
}
public GraphViewModel()
{
Functions = new List<IOneVariableFunction>();
var f1 = new TableFunction();
f1.Name = "Пробная табличная системная функция 1";
f1.IsUser = false;
f1.Description = "Описание 1";
var f2 = new TableFunction();
f2.Name = "Пробная табличная пользовательская функция 2";
f2.IsUser = true;
f2.Description = "Описание 2";
var f3 = new FormulaFunction();
f3.Name = "Пробная формульная системная функция 3";
f3.IsUser = false;
f3.Description = "Описание 3";
Functions.Add(f1);
Functions.Add(f2);
Functions.Add(f3);
Labels = new List<string>();
Labels.Add("1");
Labels.Add("2");
Labels.Add("2");
Labels.Add("3");
var chartValues = new ChartValues<double>();
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);
}
/*public GraphViewModel(IGraph graph)
{
}*/
private void AddTable()
{
}
private void AddFormula()
{
}
private void Edit()
{
}
private void Delete()
{
}
private void Cppy()
{
}
private void Tree()
{
var treeGraphVM = new TreeGraphViewModel(SelectedFuntion);
var treeGraph = new TreeGraph.TreeGraph();
treeGraph.DataContext = treeGraphVM;
treeGraph.ShowDialog();
}
}
}