Add tree graph commands

This commit is contained in:
Иван Ивашкин
2024-10-19 21:08:13 +05:00
parent 88ac95af2f
commit 11ac7c7c48
17 changed files with 366 additions and 112 deletions

View File

@@ -1,4 +1,5 @@
<Window x:Class="StructureHelper.Windows.MainGraph.FormulaView" <Window x:Class="StructureHelper.Windows.MainGraph.FormulaView"
x:Name="FormulaFunction_win"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -6,9 +7,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph" xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:FormulaViewModel}" d:DataContext="{d:DesignInstance local:FormulaViewModel}"
Title="TableFunction" Height="300" Width="400" Title="FormulaFunction" Height="320" Width="400">
MaxWidth="400"
MinWidth="400">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="60"/> <RowDefinition Height="60"/>
@@ -31,25 +30,21 @@
<ColumnDefinition Width="50"/> <ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="y(x)=" <TextBlock Grid.Column="0" Text="y(x) ="
FontStyle="Italic"
Margin="5" Margin="5"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBox Grid.Column="1" Text="{Binding Formula, UpdateSourceTrigger=PropertyChanged}"
<TextBox Grid.Column="1" Text="{Binding Description}"
Margin="5"/> Margin="5"/>
</Grid> </Grid>
</Grid> </Grid>
<TextBlock Grid.Row="1" <TextBlock Grid.Row="1"
Margin="5" Margin="5"
Background="LightYellow" Background="LightYellow"
Text="y(x) = формула" Text="{Binding FormulaText, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center" TextAlignment="Center"
FontSize="20" FontSize="20"
TextWrapping="Wrap" TextWrapping="Wrap">
FontStyle="Italic">
</TextBlock> </TextBlock>
<Grid Grid.Row="2"> <Grid Grid.Row="2">
<Grid.RowDefinitions> <Grid.RowDefinitions>
@@ -75,7 +70,7 @@
</Grid> </Grid>
<Button Grid.Row="4" Margin="5" Content="Save" <Button Grid.Row="4" Margin="5" Content="Save"
Command="{Binding DrawGraphCommand}" Command="{Binding DrawGraphCommand}"
CommandParameter="{Binding ElementName=TableFunction_win}"> CommandParameter="{Binding ElementName=FormulaFunction_win}">
</Button> </Button>
</Grid> </Grid>
</Window> </Window>

View File

@@ -1,15 +1,52 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelper.Infrastructure;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
namespace StructureHelper.Windows.MainGraph 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; private IOneVariableFunction function;
public IOneVariableFunction Function public IOneVariableFunction Function
{ {
@@ -19,13 +56,49 @@ namespace StructureHelper.Windows.MainGraph
function = value; 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();
}
} }
} }

View File

@@ -18,15 +18,44 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="100"/> <RowDefinition Height="100"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ListBox Grid.Row="0" Grid.Column="0" Margin="5" <ListView Grid.Row="0" Grid.Column="0" Margin="5"
ItemsSource="{Binding Functions, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Functions, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedFuntion, UpdateSourceTrigger=PropertyChanged}"> SelectedItem="{Binding SelectedFuntion, UpdateSourceTrigger=PropertyChanged}">
<ListBox.ItemTemplate> <ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/> <TextBlock Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListView.ItemTemplate>
</ListBox> </ListView>
<Grid Grid.Row="1" Grid.Column="0"> <Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/>

View File

@@ -6,6 +6,7 @@ using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
using StructureHelperLogics.Models.Graphs; using StructureHelperLogics.Models.Graphs;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows.Input; using System.Windows.Input;
@@ -47,6 +48,7 @@ namespace StructureHelper.Windows.MainGraph
private RelayCommand deleteCommand; private RelayCommand deleteCommand;
private RelayCommand copyCommand; private RelayCommand copyCommand;
private RelayCommand treeCommand; private RelayCommand treeCommand;
private RelayCommand drawGraphCommand;
public ICommand AddTableCommand public ICommand AddTableCommand
{ {
get => addTableCommand ??= new RelayCommand(o => AddTable()); get => addTableCommand ??= new RelayCommand(o => AddTable());
@@ -71,47 +73,47 @@ namespace StructureHelper.Windows.MainGraph
{ {
get => treeCommand ??= new RelayCommand(o => Tree()); get => treeCommand ??= new RelayCommand(o => Tree());
} }
public ICommand DrawGraphCommand
{
get => drawGraphCommand ??= new RelayCommand(o => DrawGraph());
}
public GraphViewModel() public GraphViewModel()
{ {
Functions = new ObservableCollection<IOneVariableFunction>(); Functions = new ObservableCollection<IOneVariableFunction>();
var f1 = new TableFunction(); var f1 = new TableFunction();
f1.Name = "Пробная табличная системная функция 1"; f1.Name = "Табличная системная функция";
f1.Table = new List<GraphPoint>(); f1.Table = new List<GraphPoint>()
{
new GraphPoint(1, 0),
new GraphPoint(0, 1),
};
f1.IsUser = false; f1.IsUser = false;
f1.Description = "Описание 1"; f1.Description = "Описание табличной системной функции";
var f2 = new TableFunction();
var f4 = new TableFunction();
f4.Name = "Табличная системная функция";
f4.Table = new List<GraphPoint>()
{
new GraphPoint(1, 0),
new GraphPoint(0, 1),
};
f4.IsUser = false;
f4.Description = "Описание табличной системной функции";
/*var f2 = new TableFunction();
f2.Name = "Пробная табличная пользовательская функция 2"; f2.Name = "Пробная табличная пользовательская функция 2";
f2.Table = new List<GraphPoint>(); f2.Table = new List<GraphPoint>();
f2.IsUser = true; f2.IsUser = true;
f2.Description = "Описание 2"; f2.Description = "Описание 2";*/
var f3 = new FormulaFunction(); var f3 = new FormulaFunction();
f3.Name = "Пробная формульная системная функция 3"; f3.Name = "Формульная системная функция";
f3.Formula = "x^2"; f3.Formula = "x^2";
f3.IsUser = false; f3.IsUser = false;
f3.Description = "Описание 3"; f3.Description = "Описание формульной системной функции";
Functions.Add(f1); Functions.Add(f1);
Functions.Add(f2); //Functions.Add(f2);
Functions.Add(f3); Functions.Add(f3);
Functions.Add(f4);
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) /*public GraphViewModel(IGraph graph)
{ {
@@ -148,8 +150,6 @@ namespace StructureHelper.Windows.MainGraph
var tableView = new TableView(); var tableView = new TableView();
tableView.DataContext = tableViewModel; tableView.DataContext = tableViewModel;
tableView.ShowDialog(); tableView.ShowDialog();
//SelectedFunction.Name = tableViewModel.Function.Name; //!!!!!!!!!!
//SelectedFunction.Description = tableViewModel.Function.Description; //!!!!!!!!!!
} }
else if (SelectedFuntion.Type == FunctionType.FormulaFunction) else if (SelectedFuntion.Type == FunctionType.FormulaFunction)
{ {
@@ -157,13 +157,23 @@ namespace StructureHelper.Windows.MainGraph
var formulaView = new FormulaView(); var formulaView = new FormulaView();
formulaView.DataContext = formulaViewModel; formulaView.DataContext = formulaViewModel;
formulaView.ShowDialog(); formulaView.ShowDialog();
//SelectedFunction.Name = formulaViewModel.Function.Name; //!!!!!!!!!!
//SelectedFunction.Description = formulaViewModel.Function.Description; //!!!!!!!!!!
} }
} }
private void Delete() 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() private void Copy()
{ {
@@ -187,5 +197,20 @@ namespace StructureHelper.Windows.MainGraph
treeGraph.DataContext = treeGraphVM; treeGraph.DataContext = treeGraphVM;
treeGraph.ShowDialog(); treeGraph.ShowDialog();
} }
private void DrawGraph()
{
var labels = new List<string>();
var lineSeries = new LineSeries();
var seriesCollection = new SeriesCollection();
var chartValues = new ChartValues<double>();
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;
}
} }
} }

View File

@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
@@ -22,7 +23,7 @@ namespace StructureHelper.Windows.MainGraph
private RelayCommand deletePointCommand; private RelayCommand deletePointCommand;
public ICommand DrawGraphCommand public ICommand DrawGraphCommand
{ {
get => drawGraphCommand ??= new RelayCommand(o => DrawGraph(o)); get => drawGraphCommand ??= new RelayCommand(o => Save(o));
} }
public ICommand AddPointCommand public ICommand AddPointCommand
{ {
@@ -84,7 +85,8 @@ namespace StructureHelper.Windows.MainGraph
{ {
Table = new ObservableCollection<GraphPoint>() Table = new ObservableCollection<GraphPoint>()
{ {
new GraphPoint(), new GraphPoint(0, 0),
new GraphPoint(0, 0),
}; };
Name = DEFAULT_NAME; Name = DEFAULT_NAME;
Description = DEFAULT_DESCRIPTION; Description = DEFAULT_DESCRIPTION;
@@ -96,7 +98,7 @@ namespace StructureHelper.Windows.MainGraph
Name = Function.Name; Name = Function.Name;
Description = Function.Description; Description = Function.Description;
} }
private void DrawGraph(object parameter) private void Save(object parameter)
{ {
if (Function is null) if (Function is null)
{ {
@@ -112,12 +114,31 @@ namespace StructureHelper.Windows.MainGraph
} }
private void AddPoint() private void AddPoint()
{ {
var point = new GraphPoint(); var point = new GraphPoint(0, 0);
Table.Add(point); if (SelectedPoint is null)
{
Table.Add(point);
}
else
{
var selectedPointIndex = Table.IndexOf(SelectedPoint);
Table.Insert(selectedPointIndex + 1, point);
}
} }
private void DeletePoint() private void DeletePoint()
{ {
Table.Remove(SelectedPoint); if (Table.Count < 3)
{
return;
}
if (SelectedPoint is null)
{
Table.RemoveAt(Table.Count - 1);
}
else
{
Table.Remove(SelectedPoint);
}
} }
} }
} }

View File

@@ -29,9 +29,7 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="x=" <TextBlock Grid.Column="0" Text="x ="
FontStyle="Italic"
Margin="5"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBox Grid.Column="1" Text="{Binding Argument}" <TextBox Grid.Column="1" Text="{Binding Argument}"
@@ -47,8 +45,7 @@
Text="{Binding Trace}" Text="{Binding Trace}"
TextAlignment="Center" TextAlignment="Center"
FontSize="20" FontSize="20"
TextWrapping="Wrap" TextWrapping="Wrap">
FontStyle="Italic">
</TextBlock> </TextBlock>
</ScrollViewer> </ScrollViewer>
<Grid Grid.Row="2"> <Grid Grid.Row="2">
@@ -65,9 +62,7 @@
<ColumnDefinition Width="50"/> <ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="y(x)=" <TextBlock Grid.Column="0" Text="y(x) ="
FontStyle="Italic"
Margin="5"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"

View File

@@ -32,44 +32,43 @@
<TextBlock Grid.Column="0" <TextBlock Grid.Column="0"
Grid.Row="1" Grid.Row="1"
Text="{Binding X_or_Y_text}" Text="{Binding X_or_Y_text}"
FontStyle="Italic"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"
Grid.Row="1" Grid.Row="1"
Text="{Binding GREATER}" Text="{Binding GREATER}"
FontStyle="Italic"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBox Grid.Column="2" <TextBox Grid.Column="2"
Grid.Row="1" Grid.Row="1"
Text="{Binding LeftBound}" Text="{Binding LeftBound,
UpdateSourceTrigger=PropertyChanged,
StringFormat=\{0:n\}}"
Margin="5"/> Margin="5"/>
<TextBlock Grid.Column="0" <TextBlock Grid.Column="0"
Grid.Row="2" Grid.Row="2"
Text="{Binding X_or_Y_text}" Text="{Binding X_or_Y_text}"
FontStyle="Italic"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"
Grid.Row="2" Grid.Row="2"
Text="{Binding LESS}" Text="{Binding LESS}"
FontStyle="Italic"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBox Grid.Column="2" <TextBox Grid.Column="2"
Grid.Row="2" Grid.Row="2"
Text="{Binding RightBound}" Text="{Binding RightBound,
UpdateSourceTrigger=PropertyChanged,
StringFormat=\{0:n\}}"
Margin="5"/> Margin="5"/>
</Grid> </Grid>
<TextBlock Grid.Row="1" <TextBlock Grid.Row="1"
Margin="5" Margin="5"
Background="LightYellow" Background="LightYellow"
Text="{Binding LimitText}" Text="{Binding LimitText, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center" TextAlignment="Center"
FontSize="20" FontSize="20"
TextWrapping="Wrap" TextWrapping="Wrap">
FontStyle="Italic">
</TextBlock> </TextBlock>
<Button Grid.Row="4" Margin="5" Content="Save"> <Button Grid.Row="4" Margin="5" Content="Save">
</Button> </Button>

View File

@@ -9,7 +9,7 @@ namespace StructureHelper.Windows.TreeGraph
{ {
public class LimViewModel : ViewModelBase public class LimViewModel : ViewModelBase
{ {
public char GREATER { get; } = '\u2A7E'; public char GREATER { get; } = '\u2265';
public char LESS { get; } = '\u2264'; public char LESS { get; } = '\u2264';
public char IN { get; } = '\u2208'; public char IN { get; } = '\u2208';
public char LEFT_BOUND { get; } = '['; public char LEFT_BOUND { get; } = '[';
@@ -25,19 +25,33 @@ namespace StructureHelper.Windows.TreeGraph
public string LimitText public string LimitText
{ {
get => limitText; get => limitText;
set => limitText = value; set
{
limitText = value;
OnPropertyChanged(nameof(LimitText));
}
} }
private double leftBound; private double leftBound;
private double rightBound; private double rightBound;
public double LeftBound public double LeftBound
{ {
get => 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 public double RightBound
{ {
get => 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() public LimViewModel()
{ {

View File

@@ -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<Node> Nodes { get; set; }
public string Name { get; set; }
}
}

View File

@@ -28,23 +28,23 @@
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="scale factor=" <TextBlock Grid.Column="0" Text="scale factor ="
FontStyle="Italic"
Margin="5"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBox Grid.Column="1" Text="{Binding ScaleFormula}" <TextBox Grid.Column="1" Text="{Binding ScaleFactor,
UpdateSourceTrigger=PropertyChanged,
StringFormat=\{0:n\}}"
Margin="5"/> Margin="5"/>
</Grid> </Grid>
</Grid> </Grid>
<TextBlock Grid.Row="1" <TextBlock Grid.Row="1"
Margin="5" Margin="5"
Background="LightYellow" Background="LightYellow"
Text="y=sf(x)" Text="{Binding ScaleText,
UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center" TextAlignment="Center"
FontSize="20" FontSize="20"
TextWrapping="Wrap" TextWrapping="Wrap">
FontStyle="Italic">
</TextBlock> </TextBlock>
<Button Grid.Row="4" Margin="5" Content="Save"> <Button Grid.Row="4" Margin="5" Content="Save">
</Button> </Button>

View File

@@ -9,20 +9,48 @@ namespace StructureHelper.Windows.TreeGraph
{ {
public class ScaleViewModel : ViewModelBase public class ScaleViewModel : ViewModelBase
{ {
private bool isArg = false;
private double scaleFactor; private double scaleFactor;
private string scaleText; 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 public double ScaleFactor
{ {
get => 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 public string ScaleText
{ {
get => 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}";
}
} }
} }
} }

View File

@@ -18,13 +18,15 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TreeView Grid.Row="0" Grid.Column="0" Margin="5" <TreeView Grid.Row="0"
ItemsSource="{Binding Nodes}"> Grid.Column="0"
<TreeView.ItemTemplate> Margin="5"
<DataTemplate> ItemsSource="{Binding ItemsSource}">
<TextBlock Text="{Binding Name}"/> <TreeView.Resources>
</DataTemplate> <HierarchicalDataTemplate DataType="{x:Type local:Node}" ItemsSource="{Binding Nodes}">
</TreeView.ItemTemplate> <TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView> </TreeView>
<Grid Grid.Row="1" Grid.Column="0"> <Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View File

@@ -39,12 +39,21 @@ namespace StructureHelper.Windows.TreeGraph
{ {
get => _deleteCommand ??= new RelayCommand(o => Delete()); get => _deleteCommand ??= new RelayCommand(o => Delete());
} }
private ObservableCollection<IOneVariableFunction> nodes; private ObservableCollection<IOneVariableFunction> functions;
public ObservableCollection<IOneVariableFunction> Nodes { get; set; } public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public ObservableCollection<Node> Nodes { get; set; }
public TreeGraphViewModel(IOneVariableFunction function) public TreeGraphViewModel(IOneVariableFunction function)
{ {
Nodes = new ObservableCollection<IOneVariableFunction>(); Functions = new ObservableCollection<IOneVariableFunction>();
Nodes.Add(function); Functions.Add(function);
Nodes = new ObservableCollection<Node>()
{
new Node(),
new Node(),
new Node(),
new Node(),
new Node(),
};
} }
private void GetY() private void GetY()
{ {
@@ -55,7 +64,20 @@ namespace StructureHelper.Windows.TreeGraph
} }
private void Scale(object parameter) 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(); var v = new ScaleView();
v.DataContext = vm; v.DataContext = vm;
v.ShowDialog(); v.ShowDialog();
@@ -69,10 +91,15 @@ namespace StructureHelper.Windows.TreeGraph
} }
private void Edit() private void Edit()
{ {
} }
private void Delete() private void Delete()
{ {
}
private void RefreshTree()
{
} }
} }
} }

View File

@@ -1,6 +1,8 @@
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Functions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -14,6 +16,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public FunctionType Type { get; set; } public FunctionType Type { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public List<GraphPoint> Table { get; set; }
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public bool Check(); public bool Check();
public double GetByX(double xValue); public double GetByX(double xValue);
} }

View File

@@ -2,6 +2,7 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -11,14 +12,22 @@ namespace StructureHelperCommon.Models.Functions
{ {
public class FormulaFunction : IOneVariableFunction public class FormulaFunction : IOneVariableFunction
{ {
private const string COPY = "copy";
public bool IsUser { get; set; } public bool IsUser { get; set; }
public FunctionType Type { get; set; } public FunctionType Type { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Description { get ; set; } public string Description { get ; set; }
public List<GraphPoint> Table { get; set; }
public string Formula { get; set; } public string Formula { get; set; }
public Guid Id => throw new NotImplementedException(); public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public FormulaFunction()
{
Type = FunctionType.FormulaFunction;
}
public bool Check() public bool Check()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@@ -30,11 +39,10 @@ namespace StructureHelperCommon.Models.Functions
//Здесь будет стратегия //Здесь будет стратегия
formulaFunction.Type = Type; formulaFunction.Type = Type;
formulaFunction.Name = Name; formulaFunction.Name = $"{Name} {COPY}";
formulaFunction.Description = Description; formulaFunction.Description = Description;
formulaFunction.Formula = Formula; formulaFunction.Formula = Formula;
formulaFunction.IsUser = true; formulaFunction.IsUser = true;
return formulaFunction; return formulaFunction;
} }

View File

@@ -6,9 +6,20 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Functions namespace StructureHelperCommon.Models.Functions
{ {
public class GraphPoint public class GraphPoint : ICloneable
{ {
public double X { get; set; } public double X { get; set; }
public double Y { 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;
}
} }
} }

View File

@@ -12,7 +12,9 @@ namespace StructureHelperCommon.Models.Functions
{ {
public class TableFunction : IOneVariableFunction public class TableFunction : IOneVariableFunction
{ {
private const string COPY = "copy";
private string name; private string name;
public bool IsUser { get; set; } public bool IsUser { get; set; }
public FunctionType Type { get; set; } public FunctionType Type { get; set; }
public string Name public string Name
@@ -27,8 +29,12 @@ namespace StructureHelperCommon.Models.Functions
public List<GraphPoint> Table { get; set; } public List<GraphPoint> Table { get; set; }
public Guid Id => throw new NotImplementedException(); public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public event PropertyChangedEventHandler? PropertyChanged; public TableFunction()
{
Type = FunctionType.TableFunction;
}
public bool Check() public bool Check()
{ {
@@ -41,9 +47,11 @@ namespace StructureHelperCommon.Models.Functions
//Здесь будет стратегия //Здесь будет стратегия
tableFunction.Type = Type; tableFunction.Type = Type;
tableFunction.Name = Name; tableFunction.Name = $"{Name} {COPY}";
tableFunction.Description = Description; tableFunction.Description = Description;
tableFunction.Table = Table; var newTable = new List<GraphPoint>();
Table.ForEach(x => newTable.Add(x.Clone() as GraphPoint));
tableFunction.Table = newTable;
tableFunction.IsUser = true; tableFunction.IsUser = true;
return tableFunction; return tableFunction;