Add tree graph commands
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<Window x:Class="StructureHelper.Windows.MainGraph.FormulaView"
|
||||
x:Name="FormulaFunction_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"
|
||||
@@ -6,9 +7,7 @@
|
||||
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:FormulaViewModel}"
|
||||
Title="TableFunction" Height="300" Width="400"
|
||||
MaxWidth="400"
|
||||
MinWidth="400">
|
||||
Title="FormulaFunction" Height="320" Width="400">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="60"/>
|
||||
@@ -31,25 +30,21 @@
|
||||
<ColumnDefinition Width="50"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="y(x)="
|
||||
FontStyle="Italic"
|
||||
<TextBlock Grid.Column="0" Text="y(x) ="
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
|
||||
|
||||
<TextBox Grid.Column="1" Text="{Binding Description}"
|
||||
<TextBox Grid.Column="1" Text="{Binding Formula, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="5"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="5"
|
||||
Background="LightYellow"
|
||||
Text="y(x) = формула"
|
||||
Text="{Binding FormulaText, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextAlignment="Center"
|
||||
FontSize="20"
|
||||
TextWrapping="Wrap"
|
||||
FontStyle="Italic">
|
||||
TextWrapping="Wrap">
|
||||
</TextBlock>
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.RowDefinitions>
|
||||
@@ -75,7 +70,7 @@
|
||||
</Grid>
|
||||
<Button Grid.Row="4" Margin="5" Content="Save"
|
||||
Command="{Binding DrawGraphCommand}"
|
||||
CommandParameter="{Binding ElementName=TableFunction_win}">
|
||||
CommandParameter="{Binding ElementName=FormulaFunction_win}">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
private string name;
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set
|
||||
{
|
||||
name = value;
|
||||
}
|
||||
}
|
||||
private string description;
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
set
|
||||
{
|
||||
description = value;
|
||||
}
|
||||
}
|
||||
public FormulaViewModel()
|
||||
{
|
||||
|
||||
Name = DEFAULT_NAME;
|
||||
Description = DEFAULT_DESCRIPTION;
|
||||
}
|
||||
public FormulaViewModel(FormulaFunction function)
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +18,44 @@
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="100"/>
|
||||
</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}"
|
||||
SelectedItem="{Binding SelectedFuntion, UpdateSourceTrigger=PropertyChanged}">
|
||||
<ListBox.ItemTemplate>
|
||||
<ListView.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</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>
|
||||
<TextBlock Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
<Grid Grid.Row="1" Grid.Column="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
|
||||
@@ -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<IOneVariableFunction>();
|
||||
var f1 = new TableFunction();
|
||||
f1.Name = "Пробная табличная системная функция 1";
|
||||
f1.Table = new List<GraphPoint>();
|
||||
f1.Name = "Табличная системная функция";
|
||||
f1.Table = new List<GraphPoint>()
|
||||
{
|
||||
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<GraphPoint>()
|
||||
{
|
||||
new GraphPoint(1, 0),
|
||||
new GraphPoint(0, 1),
|
||||
};
|
||||
f4.IsUser = false;
|
||||
f4.Description = "Описание табличной системной функции";
|
||||
|
||||
/*var f2 = new TableFunction();
|
||||
f2.Name = "Пробная табличная пользовательская функция 2";
|
||||
f2.Table = new List<GraphPoint>();
|
||||
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<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);
|
||||
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,14 +157,24 @@ 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()
|
||||
{
|
||||
if (SelectedFuntion is null)
|
||||
{
|
||||
var lastFunction = Functions[Functions.Count - 1];
|
||||
if (lastFunction.IsUser)
|
||||
{
|
||||
Functions.Remove(lastFunction);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Functions.Remove(SelectedFuntion);
|
||||
}
|
||||
}
|
||||
private void Copy()
|
||||
{
|
||||
if (SelectedFuntion is null)
|
||||
@@ -187,5 +197,20 @@ namespace StructureHelper.Windows.MainGraph
|
||||
treeGraph.DataContext = treeGraphVM;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<GraphPoint>()
|
||||
{
|
||||
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();
|
||||
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()
|
||||
{
|
||||
if (Table.Count < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (SelectedPoint is null)
|
||||
{
|
||||
Table.RemoveAt(Table.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Table.Remove(SelectedPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="x="
|
||||
FontStyle="Italic"
|
||||
Margin="5"
|
||||
<TextBlock Grid.Column="0" Text="x ="
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBox Grid.Column="1" Text="{Binding Argument}"
|
||||
@@ -47,8 +45,7 @@
|
||||
Text="{Binding Trace}"
|
||||
TextAlignment="Center"
|
||||
FontSize="20"
|
||||
TextWrapping="Wrap"
|
||||
FontStyle="Italic">
|
||||
TextWrapping="Wrap">
|
||||
</TextBlock>
|
||||
</ScrollViewer>
|
||||
<Grid Grid.Row="2">
|
||||
@@ -65,9 +62,7 @@
|
||||
<ColumnDefinition Width="50"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="y(x)="
|
||||
FontStyle="Italic"
|
||||
Margin="5"
|
||||
<TextBlock Grid.Column="0" Text="y(x) ="
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
|
||||
@@ -32,44 +32,43 @@
|
||||
<TextBlock Grid.Column="0"
|
||||
Grid.Row="1"
|
||||
Text="{Binding X_or_Y_text}"
|
||||
FontStyle="Italic"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Text="{Binding GREATER}"
|
||||
FontStyle="Italic"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBox Grid.Column="2"
|
||||
Grid.Row="1"
|
||||
Text="{Binding LeftBound}"
|
||||
Text="{Binding LeftBound,
|
||||
UpdateSourceTrigger=PropertyChanged,
|
||||
StringFormat=\{0:n\}}"
|
||||
Margin="5"/>
|
||||
<TextBlock Grid.Column="0"
|
||||
Grid.Row="2"
|
||||
Text="{Binding X_or_Y_text}"
|
||||
FontStyle="Italic"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
Text="{Binding LESS}"
|
||||
FontStyle="Italic"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBox Grid.Column="2"
|
||||
Grid.Row="2"
|
||||
Text="{Binding RightBound}"
|
||||
Text="{Binding RightBound,
|
||||
UpdateSourceTrigger=PropertyChanged,
|
||||
StringFormat=\{0:n\}}"
|
||||
Margin="5"/>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="5"
|
||||
Background="LightYellow"
|
||||
Text="{Binding LimitText}"
|
||||
Text="{Binding LimitText, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextAlignment="Center"
|
||||
FontSize="20"
|
||||
TextWrapping="Wrap"
|
||||
FontStyle="Italic">
|
||||
TextWrapping="Wrap">
|
||||
</TextBlock>
|
||||
<Button Grid.Row="4" Margin="5" Content="Save">
|
||||
</Button>
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
15
StructureHelper/Windows/TreeGraph/Node.cs
Normal file
15
StructureHelper/Windows/TreeGraph/Node.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -28,23 +28,23 @@
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="scale factor="
|
||||
FontStyle="Italic"
|
||||
Margin="5"
|
||||
<TextBlock Grid.Column="0" Text="scale factor ="
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBox Grid.Column="1" Text="{Binding ScaleFormula}"
|
||||
<TextBox Grid.Column="1" Text="{Binding ScaleFactor,
|
||||
UpdateSourceTrigger=PropertyChanged,
|
||||
StringFormat=\{0:n\}}"
|
||||
Margin="5"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="5"
|
||||
Background="LightYellow"
|
||||
Text="y=sf(x)"
|
||||
Text="{Binding ScaleText,
|
||||
UpdateSourceTrigger=PropertyChanged}"
|
||||
TextAlignment="Center"
|
||||
FontSize="20"
|
||||
TextWrapping="Wrap"
|
||||
FontStyle="Italic">
|
||||
TextWrapping="Wrap">
|
||||
</TextBlock>
|
||||
<Button Grid.Row="4" Margin="5" Content="Save">
|
||||
</Button>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
public ScaleViewModel()
|
||||
set
|
||||
{
|
||||
scaleText = value;
|
||||
OnPropertyChanged(nameof(ScaleText));
|
||||
}
|
||||
}
|
||||
public ScaleViewModel(bool isArg)
|
||||
{
|
||||
this.isArg = isArg;
|
||||
if (isArg)
|
||||
{
|
||||
ScaleText = $"{X_DEFAULT_SCALE_TEXT}";
|
||||
}
|
||||
else
|
||||
{
|
||||
ScaleText= $"{Y_DEFAULT_SCALE_TEXT}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TreeView Grid.Row="0" Grid.Column="0" Margin="5"
|
||||
ItemsSource="{Binding Nodes}">
|
||||
<TreeView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
</DataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
<TreeView Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="5"
|
||||
ItemsSource="{Binding ItemsSource}">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type local:Node}" ItemsSource="{Binding Nodes}">
|
||||
<TextBlock Text="{Binding Path=Name}" />
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
<Grid Grid.Row="1" Grid.Column="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
@@ -39,12 +39,21 @@ namespace StructureHelper.Windows.TreeGraph
|
||||
{
|
||||
get => _deleteCommand ??= new RelayCommand(o => Delete());
|
||||
}
|
||||
private ObservableCollection<IOneVariableFunction> nodes;
|
||||
public ObservableCollection<IOneVariableFunction> Nodes { get; set; }
|
||||
private ObservableCollection<IOneVariableFunction> functions;
|
||||
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
|
||||
public ObservableCollection<Node> Nodes { get; set; }
|
||||
public TreeGraphViewModel(IOneVariableFunction function)
|
||||
{
|
||||
Nodes = new ObservableCollection<IOneVariableFunction>();
|
||||
Nodes.Add(function);
|
||||
Functions = new ObservableCollection<IOneVariableFunction>();
|
||||
Functions.Add(function);
|
||||
Nodes = new ObservableCollection<Node>()
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<GraphPoint> Table { get; set; }
|
||||
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
|
||||
public bool Check();
|
||||
public double GetByX(double xValue);
|
||||
}
|
||||
|
||||
@@ -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<GraphPoint> Table { get; set; }
|
||||
public string Formula { get; set; }
|
||||
|
||||
public Guid Id => throw new NotImplementedException();
|
||||
|
||||
public ObservableCollection<IOneVariableFunction> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<GraphPoint> Table { get; set; }
|
||||
|
||||
public Guid Id => throw new NotImplementedException();
|
||||
public ObservableCollection<IOneVariableFunction> 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<GraphPoint>();
|
||||
Table.ForEach(x => newTable.Add(x.Clone() as GraphPoint));
|
||||
tableFunction.Table = newTable;
|
||||
tableFunction.IsUser = true;
|
||||
|
||||
return tableFunction;
|
||||
|
||||
Reference in New Issue
Block a user