ScaleXDecorator done

This commit is contained in:
Иван Ивашкин
2024-10-29 23:58:25 +05:00
parent 2738b1b7b3
commit 49d04c7bcc
18 changed files with 173 additions and 78 deletions

View File

@@ -161,8 +161,8 @@ namespace StructureHelper.Windows.MainGraph
formulaView.ShowDialog(); formulaView.ShowDialog();
SelectedFuntion = formulaViewModel.Function; SelectedFuntion = formulaViewModel.Function;
} }
//var graphView = parameter as GraphView; var graphView = parameter as GraphView;
//graphView.Refresh(); graphView.Refresh();
} }
private void Delete() private void Delete()
{ {

View File

@@ -55,7 +55,7 @@ namespace StructureHelper.Windows.TreeGraph
private void GetValue() private void GetValue()
{ {
Value = Function.GetByX(Argument); Value = Function.GetByX(Argument);
Trace = "Calculation logic"; Trace = "трасса";
} }
} }
} }

View File

@@ -1,4 +1,5 @@
<Window x:Class="StructureHelper.Windows.TreeGraph.LimView" <Window x:Class="StructureHelper.Windows.TreeGraph.LimView"
x:Name="LimView_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"
@@ -70,7 +71,9 @@
FontSize="20" FontSize="20"
TextWrapping="Wrap"> TextWrapping="Wrap">
</TextBlock> </TextBlock>
<Button Grid.Row="4" Margin="5" Content="Save"> <Button Grid.Row="4" Margin="5" Content="Save"
Command="{Binding SaveCommand}"
CommandParameter="{Binding ElementName=LimView_win}">
</Button> </Button>
</Grid> </Grid>
</Window> </Window>

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
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.Input;
namespace StructureHelper.Windows.TreeGraph namespace StructureHelper.Windows.TreeGraph
{ {
@@ -20,6 +22,11 @@ namespace StructureHelper.Windows.TreeGraph
private const string Y = "y"; private const string Y = "y";
private string x_or_y_text; private string x_or_y_text;
private string limitText; private string limitText;
private RelayCommand saveCommand;
public ICommand SaveCommand
{
get => saveCommand ??= new RelayCommand(o => Save(o));
}
public string X_or_Y_text public string X_or_Y_text
{ {
get => x_or_y_text; get => x_or_y_text;
@@ -69,5 +76,11 @@ namespace StructureHelper.Windows.TreeGraph
} }
LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{LeftBound}" + $"{SEMICOLON}" + $"{rightBound}" + $"{RIGHT_BOUND}"; LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{LeftBound}" + $"{SEMICOLON}" + $"{rightBound}" + $"{RIGHT_BOUND}";
} }
private void Save(object parameter)
{
var window = parameter as Window;
window.DialogResult = true;
window.Close();
}
} }
} }

View File

@@ -1,4 +1,5 @@
<Window x:Class="StructureHelper.Windows.TreeGraph.ScaleView" <Window x:Class="StructureHelper.Windows.TreeGraph.ScaleView"
x:Name="ScaleView_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"
@@ -46,7 +47,9 @@
FontSize="20" FontSize="20"
TextWrapping="Wrap"> TextWrapping="Wrap">
</TextBlock> </TextBlock>
<Button Grid.Row="4" Margin="5" Content="Save"> <Button Grid.Row="4" Margin="5" Content="Save"
Command="{Binding SaveCommand}"
CommandParameter="{Binding ElementName=ScaleView_win}">
</Button> </Button>
</Grid> </Grid>
</Window> </Window>

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
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.Input;
namespace StructureHelper.Windows.TreeGraph namespace StructureHelper.Windows.TreeGraph
{ {
@@ -14,6 +16,11 @@ namespace StructureHelper.Windows.TreeGraph
private string scaleText; private string scaleText;
private const string X_DEFAULT_SCALE_TEXT = "y=f(sx)"; private const string X_DEFAULT_SCALE_TEXT = "y=f(sx)";
private const string Y_DEFAULT_SCALE_TEXT = "y=sf(x)"; private const string Y_DEFAULT_SCALE_TEXT = "y=sf(x)";
private RelayCommand saveCommand;
public ICommand SaveCommand
{
get => saveCommand ??= new RelayCommand(o => Save(o));
}
public double ScaleFactor public double ScaleFactor
{ {
get => scaleFactor; get => scaleFactor;
@@ -52,5 +59,11 @@ namespace StructureHelper.Windows.TreeGraph
ScaleText= $"{Y_DEFAULT_SCALE_TEXT}"; ScaleText= $"{Y_DEFAULT_SCALE_TEXT}";
} }
} }
private void Save(object parameter)
{
var window = parameter as Window;
window.DialogResult = true;
window.Close();
}
} }
} }

View File

@@ -11,6 +11,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using StructureHelperCommon.Models.Functions.Decorator;
namespace StructureHelper.Windows.TreeGraph namespace StructureHelper.Windows.TreeGraph
{ {
@@ -114,11 +115,24 @@ namespace StructureHelper.Windows.TreeGraph
} }
private void Scale(object parameter) private void Scale(object parameter)
{ {
var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel;
if (selectedTreeViewItem is null)
{
return;
}
ScaleViewModel vm = null; ScaleViewModel vm = null;
var type = parameter as string; var type = parameter as string;
if (type.Equals("x")) if (type.Equals("x"))
{ {
vm = new ScaleViewModel(true); 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);
}
} }
else if (type.Equals("y")) else if (type.Equals("y"))
{ {
@@ -128,12 +142,14 @@ namespace StructureHelper.Windows.TreeGraph
{ {
return; return;
} }
var v = new ScaleView();
v.DataContext = vm;
v.ShowDialog();
} }
private void Limit(object parameter) private void Limit(object parameter)
{ {
var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel;
if (selectedTreeViewItem is null)
{
return;
}
LimViewModel vm = null; LimViewModel vm = null;
var type = parameter as string; var type = parameter as string;
if (type.Equals("x")) if (type.Equals("x"))

View File

@@ -23,7 +23,7 @@ namespace StructureHelper.Windows.TreeGraph
public TreeViewItemViewModel(IOneVariableFunction function, TreeGraphViewModel treeGraphViewModel) : this(function, null, treeGraphViewModel) public TreeViewItemViewModel(IOneVariableFunction function, TreeGraphViewModel treeGraphViewModel) : this(function, null, treeGraphViewModel)
{ {
} }
private TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent, TreeGraphViewModel treeGraphViewModel) public TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent, TreeGraphViewModel treeGraphViewModel)
{ {
_function = function; _function = function;
_parent = parent; _parent = parent;

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1"> <ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="StructureHelperCommon.Models.Functions.TableFunction" BaseTypeListCollapsed="true"> <Class Name="StructureHelperCommon.Models.Functions.TableFunction" BaseTypeListCollapsed="true">
<Position X="3" Y="3" Width="1.5" /> <Position X="3" Y="5.75" Width="1.5" />
<TypeIdentifier> <TypeIdentifier>
<HashCode>AAAAAAgAAAAAAAAAAAAAAAQAAAAIAAAAAQAAAAAAAAA=</HashCode> <HashCode>BAACgEgAAAAgACIAAAAAQAYAAAAMAAAAAQAAAAAAgBA=</HashCode>
<FileName>Models\Functions\TableFunction.cs</FileName> <FileName>Models\Functions\TableFunction.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
<Lollipop Position="0.2" /> <Lollipop Position="0.2" />
</Class> </Class>
<Class Name="StructureHelperCommon.Models.Functions.FormulaFunction" BaseTypeListCollapsed="true"> <Class Name="StructureHelperCommon.Models.Functions.FormulaFunction" BaseTypeListCollapsed="true">
<Position X="1.25" Y="3" Width="1.5" /> <Position X="1.25" Y="5.75" Width="1.5" />
<TypeIdentifier> <TypeIdentifier>
<HashCode>AAAAAAgAAAAAAAAAAAAAAAQAAAAIAAAAAQAAAAAAAAA=</HashCode> <HashCode>BAACgEgAAAAgACJAAgAAQAYAAAAIBAAAIQAAAAAAgBA=</HashCode>
<FileName>Models\Functions\FormulaFunction.cs</FileName> <FileName>Models\Functions\FormulaFunction.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
<Lollipop Position="0.2" /> <Lollipop Position="0.2" />
@@ -19,30 +19,9 @@
<Interface Name="StructureHelperCommon.Infrastructures.Interfaces.IOneVariableFunction"> <Interface Name="StructureHelperCommon.Infrastructures.Interfaces.IOneVariableFunction">
<Position X="2" Y="0.5" Width="1.5" /> <Position X="2" Y="0.5" Width="1.5" />
<TypeIdentifier> <TypeIdentifier>
<HashCode>AAAAAAgAAAAAAAAAAAAAAAQAAAAIAAAAAQAAAAAAAAA=</HashCode> <HashCode>BAAAgEgAAAAgACAAAAAAQAYAAAAIAAAAAQAAAAAAgAA=</HashCode>
<FileName>Infrastructures\Interfaces\IOneVariableFunction.cs</FileName> <FileName>Infrastructures\Interfaces\IOneVariableFunction.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
</Interface> </Interface>
<Interface Name="StructureHelperCommon.Models.Functions.IScaleFunction">
<Position X="7.75" Y="3" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Models\Functions\IScaleFunction.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="StructureHelperCommon.Models.Functions.ILimitFunction">
<Position X="5.75" Y="3" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Models\Functions\ILimitFunction.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="StructureHelperCommon.Infrastructures.Interfaces.IFunctionDecorator">
<Position X="6.25" Y="0.5" Width="2.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Infrastructures\Interfaces\IFunctionDecorator.cs</FileName>
</TypeIdentifier>
</Interface>
<Font Name="Segoe UI" Size="9" /> <Font Name="Segoe UI" Size="9" />
</ClassDiagram> </ClassDiagram>

View File

@@ -0,0 +1,46 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Functions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
public abstract class FunctionDecorator : IOneVariableFunction
{
protected IOneVariableFunction function;
public bool IsUser { get; set; }
public string Group { get; set; }
public FunctionType Type { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<GraphPoint> Table { get; set; }
public double MinArg { get; set; }
public double MaxArg { get; set; }
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public Guid Id => throw new NotImplementedException();
public IShiftTraceLogger? TraceLogger { get; set; }
public FunctionDecorator(IOneVariableFunction function)
{
this.function = function;
}
public virtual bool Check()
{
return function.Check();
}
public virtual object Clone()
{
return function.Clone();
}
public virtual double GetByX(double xValue)
{
return function.GetByX(xValue);
}
}
}

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
public interface IFunctionDecorator
{
public IOneVariableFunction OneVariableFunction { get; }
}
}

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces namespace StructureHelperCommon.Infrastructures.Interfaces
{ {
public interface IOneVariableFunction : ICloneable, ISaveable public interface IOneVariableFunction : ICloneable, ISaveable, ILogic
{ {
public const string GROUP_TYPE_1 = "System function"; public const string GROUP_TYPE_1 = "System function";
public const string GROUP_TYPE_2 = "User function"; public const string GROUP_TYPE_2 = "User function";

View File

@@ -0,0 +1,32 @@
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 LimXDecorator : FunctionDecorator
{
private double leftBound;
private double rightBound;
public LimXDecorator(IOneVariableFunction function, double leftBound, double rightBound) : base(function)
{
this.leftBound = leftBound;
this.rightBound = rightBound;
}
public override bool Check()
{
return base.Check();
}
public override double GetByX(double xValue)
{
if (xValue > leftBound && xValue < rightBound)
{
return base.GetByX(xValue);
}
return 0;
}
}
}

View File

@@ -0,0 +1,27 @@
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 ScaleXDecorator : FunctionDecorator
{
private double factor;
public ScaleXDecorator(IOneVariableFunction function, double factor) : base(function)
{
this.factor = factor;
Name = $"{function.Name}, y=f({factor}x)";
}
public override bool Check()
{
return base.Check();
}
public override double GetByX(double xValue)
{
return base.GetByX(factor * xValue);
}
}
}

View File

@@ -41,6 +41,7 @@ namespace StructureHelperCommon.Models.Functions
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>(); public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public double MinArg { get; set; } public double MinArg { get; set; }
public double MaxArg { get; set; } public double MaxArg { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public FormulaFunction(bool isUser = false) public FormulaFunction(bool isUser = false)
{ {

View File

@@ -1,14 +0,0 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Functions
{
public interface ILimitFunction : IFunctionDecorator
{
public void Limit();
}
}

View File

@@ -1,14 +0,0 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Functions
{
public interface IScaleFunction : IFunctionDecorator
{
public void Scale();
}
}

View File

@@ -29,6 +29,7 @@ namespace StructureHelperCommon.Models.Functions
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>(); public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public double MinArg { get; set; } public double MinArg { get; set; }
public double MaxArg { get; set; } public double MaxArg { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public TableFunction(bool isUser = false) public TableFunction(bool isUser = false)
{ {
@@ -68,7 +69,9 @@ namespace StructureHelperCommon.Models.Functions
public double GetByX(double xValue) public double GetByX(double xValue)
{ {
throw new NotImplementedException(); //Реализовать взятие значения из таблицы и интерполяцию по таблице
return 100;
} }
} }
} }