Function bounds done, add other decorators

This commit is contained in:
Иван Ивашкин
2024-10-30 22:49:43 +05:00
parent 49d04c7bcc
commit 94387d0d0b
16 changed files with 223 additions and 35 deletions

View File

@@ -131,8 +131,6 @@ namespace StructureHelper.Windows.Graphs
VisualProps = new();
}
private void DrawSeries()
{
SetLines();

View File

@@ -71,7 +71,7 @@
VerticalAlignment="Center"/>
<TextBlock Grid.Column="0"
Grid.Row="1"
Text="{Binding X_or_Y_text}"
Text="{Binding X}"
VerticalAlignment="Center"
HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1"
@@ -87,7 +87,7 @@
Margin="5"/>
<TextBlock Grid.Column="0"
Grid.Row="2"
Text="{Binding X_or_Y_text}"
Text="{Binding X}"
VerticalAlignment="Center"
HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1"
@@ -153,7 +153,10 @@
Margin="5"
Text="Color:"
VerticalAlignment="Center"/>
<ComboBox Grid.Row="1" Text="{Binding Description}" Margin="5"/>
<ComboBox Grid.Row="1"
Margin="5"
ItemsSource="{Binding Colors}"
SelectedItem="{Binding CurrentColor}"/>
</Grid>
<Button Grid.Row="7" Margin="5" Content="Save"
Command="{Binding SaveCommand}"

View File

@@ -11,30 +11,61 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace StructureHelper.Windows.MainGraph
{
public class FormulaViewModel : ViewModelBase
{
private const string ERROR_BOUNDS = "The left bound must be less than the right bound";
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;
public char GREATER { get; } = '\u2265';
public char LESS { get; } = '\u2264';
public char X { get; } = 'x';
private RelayCommand saveCommand;
public int Step { get; set; }
private double leftBound;
public double LeftBound
{
get => leftBound;
set
{
leftBound = value;
LimitText = $"x\u2208[{value};{RightBound}]";
OnPropertyChanged(nameof(LeftBound));
}
}
private double rightBound;
public double RightBound
{
get => rightBound;
set
{
rightBound = value;
LimitText = $"x\u2208[{LeftBound};{value}]";
OnPropertyChanged(nameof(RightBound));
}
}
public Color CurrentColor { get; set; }
public ObservableCollection<Color> Colors { get; set; }
public ICommand SaveCommand
{
get => saveCommand ??= new RelayCommand(o => Save(o));
}
private string formula;
public string Formula
{
get => formula;
set
{
formula = value;
FormulaText = $"y(x)={Formula}";
OnPropertyChanged(nameof(Formula));
}
}
private string formulaText = "y(x)=";
@@ -43,8 +74,8 @@ namespace StructureHelper.Windows.MainGraph
get => formulaText;
set
{
formulaText = $"y(x)={Formula}";
OnPropertyChanged(nameof(Formula));
formulaText = value;
OnPropertyChanged(nameof(FormulaText));
}
}
private IOneVariableFunction function;
@@ -74,17 +105,36 @@ namespace StructureHelper.Windows.MainGraph
description = value;
}
}
private string limitText;
public string LimitText
{
get => limitText;
set
{
limitText = value;
OnPropertyChanged(nameof(LimitText));
}
}
public FormulaViewModel()
{
Name = DEFAULT_NAME;
Description = DEFAULT_DESCRIPTION;
Step = DEFAULT_STEP;
LeftBound = DEFAULT_LEFT_BOUND;
RightBound = DEFAULT_RIGHT_BOUND;
LimitText = $"x\u2208[{LeftBound};{RightBound}]";
CurrentColor = Brushes.AliceBlue.Color;
}
public FormulaViewModel(FormulaFunction formulaFunction)
{
Function = formulaFunction;
Formula = formulaFunction.Formula;
Step = formulaFunction.Step;
Name = Function.Name;
Description = Function.Description;
LeftBound = Function.MinArg;
RightBound = Function.MaxArg;
CurrentColor = Function.Color;
}
private void Save(object parameter)
{
@@ -97,6 +147,11 @@ namespace StructureHelper.Windows.MainGraph
Function.IsUser = true;
(Function as FormulaFunction).Formula = Formula;
var window = parameter as Window;
if (LeftBound > RightBound)
{
MessageBox.Show($"{ERROR_BOUNDS}");
return;
}
window.DialogResult = true;
window.Close();
}

View File

@@ -11,6 +11,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace StructureHelper.Windows.MainGraph
{
@@ -222,6 +223,8 @@ namespace StructureHelper.Windows.MainGraph
chartValues.Add(Math.Round(graphPoint.Y));
}
lineSeries.Values = chartValues;
lineSeries.Stroke = Brushes.Blue;
lineSeries.Fill = Brushes.Transparent;
Labels = labels;
seriesCollection.Add(lineSeries);
SeriesCollection = seriesCollection;

View File

@@ -18,6 +18,7 @@ namespace StructureHelper.Windows.TreeGraph
public char LEFT_BOUND { get; } = '[';
public char RIGHT_BOUND { get; } = ']';
public char SEMICOLON { get; } = ';';
private const string ERROR_BOUNDS = "The left bound must be less than the right bound";
private const string X = "x";
private const string Y = "y";
private string x_or_y_text;
@@ -79,6 +80,11 @@ namespace StructureHelper.Windows.TreeGraph
private void Save(object parameter)
{
var window = parameter as Window;
if (LeftBound > RightBound)
{
MessageBox.Show($"{ERROR_BOUNDS}");
return;
}
window.DialogResult = true;
window.Close();
}

View File

@@ -11,7 +11,7 @@
Width="1000" MinHeight="400" MinWidth="600">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350"/>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
@@ -49,7 +49,6 @@
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
@@ -73,9 +72,6 @@
Background="DodgerBlue"
Command="{Binding LimitCommand}"
CommandParameter="y"/>
<Button Grid.Column="5" Margin="5" Content="Edit"
Background="LightYellow"
Command="{Binding EditCommand}"/>
<Button Grid.Column="6" Margin="5" Content="Delete"
Background="LightPink"
Command="{Binding DeleteCommand}"/>

View File

@@ -12,6 +12,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using StructureHelperCommon.Models.Functions.Decorator;
using System.Windows.Media;
namespace StructureHelper.Windows.TreeGraph
{
@@ -25,7 +26,6 @@ namespace StructureHelper.Windows.TreeGraph
private RelayCommand _getYCommand;
private RelayCommand _scaleCommand;
private RelayCommand _limCommand;
private RelayCommand _editCommand;
private RelayCommand _deleteCommand;
private TreeGraphView _treeGraphView_win;
private IOneVariableFunction selectedFunction;
@@ -80,10 +80,6 @@ namespace StructureHelper.Windows.TreeGraph
{
get => _limCommand ??= new RelayCommand(o => Limit(o));
}
public ICommand EditCommand
{
get => _editCommand ??= new RelayCommand(o => Edit());
}
public ICommand DeleteCommand
{
get => _deleteCommand ??= new RelayCommand(o => Delete());
@@ -121,22 +117,31 @@ namespace StructureHelper.Windows.TreeGraph
return;
}
ScaleViewModel vm = null;
var v = new ScaleView();
var type = parameter as string;
if (type.Equals("x"))
{
vm = new ScaleViewModel(true);
var v = new ScaleView();
v.DataContext = vm;
if (v.ShowDialog() == true)
{
SelectedFuntion = new ScaleXDecorator(SelectedFuntion, vm.ScaleFactor);
var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this);
selectedTreeViewItem.Children.Add(child);
selectedTreeViewItem.IsExpanded = true;
}
}
else if (type.Equals("y"))
{
vm = new ScaleViewModel(false);
v.DataContext = vm;
if (v.ShowDialog() == true)
{
SelectedFuntion = new ScaleYDecorator(SelectedFuntion, vm.ScaleFactor);
var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this);
selectedTreeViewItem.Children.Add(child);
selectedTreeViewItem.IsExpanded = true;
}
}
else
{
@@ -151,26 +156,36 @@ namespace StructureHelper.Windows.TreeGraph
return;
}
LimViewModel vm = null;
var v = new LimView();
var type = parameter as string;
if (type.Equals("x"))
{
vm = new LimViewModel(true);
v.DataContext = vm;
if (v.ShowDialog() == true)
{
SelectedFuntion = new LimXDecorator(SelectedFuntion, vm.LeftBound, vm.RightBound);
var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this);
selectedTreeViewItem.Children.Add(child);
selectedTreeViewItem.IsExpanded = true;
}
}
else if (type.Equals("y"))
{
vm = new LimViewModel(false);
v.DataContext = vm;
if (v.ShowDialog() == true)
{
SelectedFuntion = new LimYDecorator(SelectedFuntion, vm.LeftBound, vm.RightBound);
var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this);
selectedTreeViewItem.Children.Add(child);
selectedTreeViewItem.IsExpanded = true;
}
}
else
{
return;
}
var v = new LimView();
v.DataContext = vm;
v.ShowDialog();
}
private void Edit()
{
}
private void Delete()
{
@@ -204,6 +219,8 @@ namespace StructureHelper.Windows.TreeGraph
chartValues.Add(Math.Round(graphPoint.Y));
}
lineSeries.Values = chartValues;
lineSeries.Stroke = Brushes.Blue;
lineSeries.Fill = Brushes.Transparent;
Labels = labels;
seriesCollection.Add(lineSeries);
SeriesCollection = seriesCollection;

View File

@@ -1,9 +1,11 @@
using StructureHelperCommon.Infrastructures.Enums;
using LiveCharts;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Functions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -26,6 +28,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public Guid Id => throw new NotImplementedException();
public IShiftTraceLogger? TraceLogger { get; set; }
public Color Color { get; set; }
public FunctionDecorator(IOneVariableFunction function)
{
this.function = function;
@@ -42,5 +46,9 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
{
return function.GetByX(xValue);
}
public virtual SeriesCollection GetSeriesCollection()
{
return function.GetSeriesCollection();
}
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Enums;
using LiveCharts;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Functions;
using System;
using System.Collections.Generic;
@@ -7,6 +8,7 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
@@ -22,8 +24,10 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public List<GraphPoint> Table { get; set; }
public double MinArg { get; set; }
public double MaxArg { get; set; }
public Color Color { get; set; }
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public bool Check();
public double GetByX(double xValue);
public SeriesCollection GetSeriesCollection();
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using LiveCharts;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,6 +14,7 @@ namespace StructureHelperCommon.Models.Functions.Decorator
private double rightBound;
public LimXDecorator(IOneVariableFunction function, double leftBound, double rightBound) : base(function)
{
Name = $"x\u2208[{leftBound};{rightBound}]";
this.leftBound = leftBound;
this.rightBound = rightBound;
}
@@ -28,5 +30,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
return 0;
}
public override SeriesCollection GetSeriesCollection()
{
return base.GetSeriesCollection();
}
}
}

View File

@@ -0,0 +1,39 @@
using LiveCharts;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Functions.Decorator
{
public class LimYDecorator : FunctionDecorator
{
private double leftBound;
private double rightBound;
public LimYDecorator(IOneVariableFunction function, double leftBound, double rightBound) : base(function)
{
Name = $"y\u2208[{leftBound};{rightBound}]";
this.leftBound = leftBound;
this.rightBound = rightBound;
}
public override bool Check()
{
return base.Check();
}
public override double GetByX(double xValue)
{
var y = base.GetByX(xValue);
if (y > leftBound && y < rightBound)
{
return y;
}
return 0;
}
public override SeriesCollection GetSeriesCollection()
{
return base.GetSeriesCollection();
}
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using LiveCharts;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,7 +14,7 @@ namespace StructureHelperCommon.Models.Functions.Decorator
public ScaleXDecorator(IOneVariableFunction function, double factor) : base(function)
{
this.factor = factor;
Name = $"{function.Name}, y=f({factor}x)";
Name = $"y=f({factor}x)";
}
public override bool Check()
{
@@ -23,5 +24,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
{
return base.GetByX(factor * xValue);
}
public override SeriesCollection GetSeriesCollection()
{
return base.GetSeriesCollection();
}
}
}

View File

@@ -0,0 +1,32 @@
using LiveCharts;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Functions.Decorator
{
public class ScaleYDecorator : FunctionDecorator
{
private double factor;
public ScaleYDecorator(IOneVariableFunction function, double factor) : base(function)
{
this.factor = factor;
Name = $"y={factor}f(x)";
}
public override bool Check()
{
return base.Check();
}
public override double GetByX(double xValue)
{
return factor * base.GetByX(xValue);
}
public override SeriesCollection GetSeriesCollection()
{
return base.GetSeriesCollection();
}
}
}

View File

@@ -1,9 +1,11 @@
using Microsoft.VisualBasic.ApplicationServices;
using LiveCharts;
using Microsoft.VisualBasic.ApplicationServices;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -42,6 +44,7 @@ namespace StructureHelperCommon.Models.Functions
public double MinArg { get; set; }
public double MaxArg { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public Color Color { get; set; }
public FormulaFunction(bool isUser = false)
{
@@ -86,7 +89,7 @@ namespace StructureHelperCommon.Models.Functions
yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временное тестовой выражение квадратичной параболы, будет разбор выражения
return yValue;
}
public List<GraphPoint> CalculateTable()
private List<GraphPoint> CalculateTable()
{
var table = new List<GraphPoint>();
var stepLenght = Math.Abs(MaxArg - MinArg) / Step;
@@ -97,5 +100,9 @@ namespace StructureHelperCommon.Models.Functions
}
return table;
}
public SeriesCollection GetSeriesCollection()
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,9 +1,11 @@
using StructureHelperCommon.Infrastructures.Enums;
using LiveCharts;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -30,6 +32,7 @@ namespace StructureHelperCommon.Models.Functions
public double MinArg { get; set; }
public double MaxArg { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public Color Color { get; set; }
public TableFunction(bool isUser = false)
{
@@ -71,7 +74,12 @@ namespace StructureHelperCommon.Models.Functions
{
//Реализовать взятие значения из таблицы и интерполяцию по таблице
return 100;
return 0;
}
public SeriesCollection GetSeriesCollection()
{
throw new NotImplementedException();
}
}
}

View File

@@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="NLog" Version="5.3.3" />
</ItemGroup>