Refactoring WIP
This commit is contained in:
30
Infrastructure/UI/DataContexts/Ellipse.cs
Normal file
30
Infrastructure/UI/DataContexts/Ellipse.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Windows.MainWindow;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
public class Ellipse : PrimitiveBase
|
||||
{
|
||||
private double square;
|
||||
public double Square
|
||||
{
|
||||
get => square;
|
||||
set
|
||||
{
|
||||
square = value;
|
||||
PrimitiveWidth = Math.Round(Math.Sqrt(4 * value / Math.PI), 2);
|
||||
OnPropertyChanged(nameof(PrimitiveWidth));
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Ellipse(double square, double ellipseX, double ellipseY, MainViewModel mainViewModel) : base(PrimitiveType.Ellipse, ellipseX, ellipseY, mainViewModel)
|
||||
{
|
||||
Square = square;
|
||||
ShowedX = 0;
|
||||
ShowedY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
258
Infrastructure/UI/DataContexts/PrimitiveBase.cs
Normal file
258
Infrastructure/UI/DataContexts/PrimitiveBase.cs
Normal file
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelper.Windows.MainWindow;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
public abstract class PrimitiveBase : ViewModelBase
|
||||
{
|
||||
#region Поля
|
||||
|
||||
private readonly PrimitiveType type;
|
||||
private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured;
|
||||
private Brush brush;
|
||||
private MaterialDefinitionBase material;
|
||||
private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight, showedX, showedY, delta = 0.5;
|
||||
private int showedZIndex = 1, zIndex;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Свойства
|
||||
|
||||
public PrimitiveType Type => type;
|
||||
public bool Captured
|
||||
{
|
||||
set => OnPropertyChanged(value, ref captured);
|
||||
get => captured;
|
||||
}
|
||||
public bool ParameterCaptured
|
||||
{
|
||||
set => OnPropertyChanged(value, ref parameterCaptured);
|
||||
get => parameterCaptured;
|
||||
}
|
||||
public bool ElementLock
|
||||
{
|
||||
get => elementLock;
|
||||
set => OnPropertyChanged(value, ref elementLock);
|
||||
}
|
||||
public Brush Brush
|
||||
{
|
||||
get => brush;
|
||||
set => OnPropertyChanged(value, ref brush);
|
||||
}
|
||||
public MaterialDefinitionBase Material
|
||||
{
|
||||
get => material;
|
||||
set
|
||||
{
|
||||
MaterialName = material.MaterialClass;
|
||||
OnPropertyChanged(value, ref material);
|
||||
OnPropertyChanged(nameof(MaterialName));
|
||||
}
|
||||
}
|
||||
private string materialName = string.Empty;
|
||||
public string MaterialName
|
||||
{
|
||||
get => materialName;
|
||||
set => OnPropertyChanged(value, ref materialName);
|
||||
}
|
||||
public bool ParamsPanelVisibilty
|
||||
{
|
||||
get => paramsPanelVisibilty;
|
||||
set => OnPropertyChanged(value, ref paramsPanelVisibilty);
|
||||
}
|
||||
public bool PopupCanBeClosed
|
||||
{
|
||||
get => popupCanBeClosed;
|
||||
set => OnPropertyChanged(value, ref popupCanBeClosed);
|
||||
}
|
||||
public double ShowedOpacity
|
||||
{
|
||||
get => showedOpacity;
|
||||
set
|
||||
{
|
||||
Opacity = (100 - value) / 100;
|
||||
OnPropertyChanged(nameof(Opacity));
|
||||
OnPropertyChanged(value, ref showedOpacity);
|
||||
}
|
||||
}
|
||||
public double Opacity
|
||||
{
|
||||
get => opacity;
|
||||
set => OnPropertyChanged(value, ref opacity);
|
||||
}
|
||||
public int ShowedZIndex
|
||||
{
|
||||
get => showedZIndex;
|
||||
set
|
||||
{
|
||||
ZIndex = value - 1;
|
||||
OnPropertyChanged(nameof(ZIndex));
|
||||
OnPropertyChanged(value, ref showedZIndex);
|
||||
}
|
||||
}
|
||||
public int ZIndex
|
||||
{
|
||||
get => zIndex;
|
||||
set => OnPropertyChanged(value, ref zIndex);
|
||||
}
|
||||
public double X
|
||||
{
|
||||
get => x;
|
||||
set => OnPropertyChanged(value, ref x);
|
||||
}
|
||||
public double Y
|
||||
{
|
||||
get => y;
|
||||
set => OnPropertyChanged(value, ref y);
|
||||
}
|
||||
public double Xy1
|
||||
{
|
||||
get => xY1;
|
||||
set => OnPropertyChanged(value, ref xY1);
|
||||
}
|
||||
public double Yx1
|
||||
{
|
||||
get => yX1;
|
||||
set => OnPropertyChanged(value, ref yX1);
|
||||
}
|
||||
public double PrimitiveWidth
|
||||
{
|
||||
get => primitiveWidth;
|
||||
set => OnPropertyChanged(value, ref primitiveWidth);
|
||||
}
|
||||
public double PrimitiveHeight
|
||||
{
|
||||
get => primitiveHeight;
|
||||
set => OnPropertyChanged(value, ref primitiveHeight);
|
||||
}
|
||||
public double ShowedX
|
||||
{
|
||||
get => showedX;
|
||||
set
|
||||
{
|
||||
UpdateCoordinatesX(value);
|
||||
OnPropertyChanged(value, ref showedX);
|
||||
OnPropertyChanged(nameof(X));
|
||||
}
|
||||
}
|
||||
public double ShowedY
|
||||
{
|
||||
get => showedY;
|
||||
set
|
||||
{
|
||||
UpdateCoordinatesY(value);
|
||||
OnPropertyChanged(value, ref showedY);
|
||||
OnPropertyChanged(nameof(Y));
|
||||
}
|
||||
}
|
||||
public bool BorderCaptured
|
||||
{
|
||||
get => borderCaptured;
|
||||
set => OnPropertyChanged(value, ref borderCaptured);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Команды
|
||||
public ICommand PrimitiveLeftButtonDown { get; }
|
||||
public ICommand PrimitiveLeftButtonUp { get; }
|
||||
public ICommand RectanglePreviewMouseMove { get; }
|
||||
public ICommand EllipsePreviewMouseMove { get; }
|
||||
public ICommand PrimitiveDoubleClick { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
protected PrimitiveBase(PrimitiveType type, double rectX, double rectY, MainViewModel mainViewModel)
|
||||
{
|
||||
this.type = type;
|
||||
Yx1 = rectX;
|
||||
Xy1 = rectY;
|
||||
var randomR = new Random().Next(150, 255);
|
||||
var randomG = new Random().Next(0, 255);
|
||||
var randomB = new Random().Next(30, 130);
|
||||
var color = Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB);
|
||||
Brush = new SolidColorBrush(color);
|
||||
PrimitiveLeftButtonUp = new RelayCommand(o => Captured = false);
|
||||
PrimitiveLeftButtonDown = new RelayCommand(o => Captured = true);
|
||||
RectanglePreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
if (!(o is Rectangle rect)) return;
|
||||
if (Captured && !rect.BorderCaptured && !ElementLock)
|
||||
{
|
||||
var deltaX = PrimitiveWidth / 2;
|
||||
var deltaY = PrimitiveHeight / 2;
|
||||
|
||||
if (rect.ShowedX % 10 <= delta || rect.ShowedX % 10 >= 10 - delta)
|
||||
rect.ShowedX = Math.Round((mainViewModel.PanelX - deltaX - Yx1) / 10) * 10;
|
||||
else
|
||||
rect.ShowedX = mainViewModel.PanelX - deltaX - Yx1;
|
||||
|
||||
if (rect.ShowedY % 10 <= delta || rect.ShowedY % 10 >= 10 - delta)
|
||||
rect.ShowedY = -(Math.Round((mainViewModel.PanelY - deltaY - Xy1 + rect.PrimitiveHeight) / 10) * 10);
|
||||
else
|
||||
rect.ShowedY = -(mainViewModel.PanelY - deltaY - Xy1 + rect.PrimitiveHeight);
|
||||
}
|
||||
if (ParameterCaptured)
|
||||
{
|
||||
//RectParameterX = rect.ShowedX;
|
||||
//RectParameterY = rect.ShowedY;
|
||||
//RectParameterWidth = rect.PrimitiveWidth;
|
||||
//RectParameterHeight = rect.PrimitiveHeight;
|
||||
//ParameterOpacity = rect.ShowedOpacity;
|
||||
//ElementLock = rect.ElementLock;
|
||||
}
|
||||
});
|
||||
EllipsePreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
if (!(o is Ellipse ellipse)) return;
|
||||
if (ellipse.Captured && !ellipse.ElementLock)
|
||||
{
|
||||
var ellipseDelta = ellipse.PrimitiveWidth / 2;
|
||||
|
||||
if (ellipse.ShowedX % 10 <= ellipseDelta || ellipse.ShowedX % 10 >= 10 - ellipseDelta)
|
||||
ellipse.ShowedX = Math.Round((mainViewModel.PanelX - Yx1) / 10) * 10;
|
||||
else
|
||||
ellipse.ShowedX = mainViewModel.PanelX - ellipseDelta - Yx1;
|
||||
|
||||
if (ellipse.ShowedY % 10 <= ellipseDelta || ellipse.ShowedY % 10 >= 10 - ellipseDelta)
|
||||
ellipse.ShowedY = -(Math.Round((mainViewModel.PanelY - Xy1) / 10) * 10);
|
||||
else
|
||||
ellipse.ShowedY = -(mainViewModel.PanelY - ellipseDelta - Xy1);
|
||||
}
|
||||
if (ParameterCaptured)
|
||||
{
|
||||
//EllipseParameterX = ellipse.ShowedX;
|
||||
//EllipseParameterY = ellipse.ShowedY;
|
||||
//EllipseParameterSquare = ellipse.Square;
|
||||
//ParameterOpacity = ellipse.ShowedOpacity;
|
||||
//ElementLock = ellipse.ElementLock;
|
||||
}
|
||||
});
|
||||
PrimitiveDoubleClick = new RelayCommand(o =>
|
||||
{
|
||||
PopupCanBeClosed = false;
|
||||
Captured = false;
|
||||
ParamsPanelVisibilty = true;
|
||||
|
||||
//if (primitive is Rectangle rect)
|
||||
// rect.BorderCaptured = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void UpdateCoordinatesX(double showedX)
|
||||
{
|
||||
if (Type == PrimitiveType.Rectangle) X = showedX + Yx1;
|
||||
if (Type == PrimitiveType.Ellipse) X = showedX + Yx1 - PrimitiveWidth / 2;
|
||||
}
|
||||
private void UpdateCoordinatesY(double showedY)
|
||||
{
|
||||
if (Type == PrimitiveType.Rectangle) Y = -showedY + Xy1 - PrimitiveHeight;
|
||||
if (Type == PrimitiveType.Ellipse) Y = -showedY + Xy1 - PrimitiveWidth / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Infrastructure/UI/DataContexts/Rectangle.cs
Normal file
19
Infrastructure/UI/DataContexts/Rectangle.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Windows.MainWindow;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
public class Rectangle : PrimitiveBase
|
||||
{
|
||||
public Rectangle(double primitiveWidth, double primitiveHeight, double rectX, double rectY, MainViewModel mainViewModel) : base(PrimitiveType.Rectangle, rectX, rectY, mainViewModel)
|
||||
{
|
||||
PrimitiveWidth = primitiveWidth;
|
||||
PrimitiveHeight = primitiveHeight;
|
||||
ShowedX = 0;
|
||||
ShowedY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Infrastructure/UI/DataTemplates/EllipseTemplate.xaml
Normal file
15
Infrastructure/UI/DataTemplates/EllipseTemplate.xaml
Normal file
@@ -0,0 +1,15 @@
|
||||
<UserControl x:Class="StructureHelper.Infrastructure.UI.DataTemplates.EllipseTemplate"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:StructureHelper"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:mouseEventTriggers="clr-namespace:StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers"
|
||||
xmlns:dataContexts="clr-namespace:StructureHelper.Infrastructure.UI.DataContexts"
|
||||
xmlns:userControls="clr-namespace:StructureHelper.Infrastructure.UI.UserControls"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<ContentControl Content="{StaticResource EllipsePrimitive}"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
16
Infrastructure/UI/DataTemplates/EllipseTemplate.xaml.cs
Normal file
16
Infrastructure/UI/DataTemplates/EllipseTemplate.xaml.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataTemplates
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для EllipseTemplate.xaml
|
||||
/// </summary>
|
||||
public partial class EllipseTemplate : UserControl
|
||||
{
|
||||
public EllipseTemplate()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Infrastructure/UI/DataTemplates/RectangleTemplate.xaml
Normal file
28
Infrastructure/UI/DataTemplates/RectangleTemplate.xaml
Normal file
@@ -0,0 +1,28 @@
|
||||
<UserControl x:Class="StructureHelper.Infrastructure.UI.DataTemplates.RectangleTemplate"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:StructureHelper"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:infrastructure="clr-namespace:StructureHelper.Infrastructure"
|
||||
xmlns:mouseEventTriggers="clr-namespace:StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers"
|
||||
xmlns:userControls="clr-namespace:StructureHelper.Infrastructure.UI.UserControls"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<ContentControl Content="{StaticResource RectanglePrimitive}"/>
|
||||
<Rectangle Cursor="SizeNWSE" Width="20" Height="20" Fill="{Binding Brush}" VerticalAlignment="Bottom" HorizontalAlignment="Right">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="PreviewMouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.LeftButtonDown}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseUp">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.LeftButtonUp}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseMove">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
16
Infrastructure/UI/DataTemplates/RectangleTemplate.xaml.cs
Normal file
16
Infrastructure/UI/DataTemplates/RectangleTemplate.xaml.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataTemplates
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для RectangleTemplate.xaml
|
||||
/// </summary>
|
||||
public partial class RectangleTemplate : UserControl
|
||||
{
|
||||
public RectangleTemplate()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
89
Infrastructure/UI/Styles.xaml
Normal file
89
Infrastructure/UI/Styles.xaml
Normal file
@@ -0,0 +1,89 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:mouseEventTriggers="clr-namespace:StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:dataContexts="clr-namespace:StructureHelper.Infrastructure.UI.DataContexts"
|
||||
mc:Ignorable="d" >
|
||||
|
||||
<Style TargetType="Shape" x:Key="ShapeStyle">
|
||||
<Setter Property="Fill" Value="{Binding Brush, Mode=TwoWay}"/>
|
||||
<Setter Property="Opacity" Value="{Binding Opacity, Mode=TwoWay}"/>
|
||||
<Setter Property="ToolTip">
|
||||
<Setter.Value>
|
||||
<ToolTip Background="White" BorderBrush="Black" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="50"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="Координата X:"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="{Binding ShowedX}"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="Координата Y:"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="{Binding ShowedY}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="Ширина:"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="{Binding PrimitiveWidth}"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="Высота:"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="{Binding PrimitiveHeight}"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="Материал:"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" Margin="3" BorderThickness="0" Text="{Binding MaterialName, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</ToolTip>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="EllipseStyle" TargetType="Ellipse" BasedOn="{StaticResource ShapeStyle}">
|
||||
<Style.Setters>
|
||||
<Setter Property="Width" Value="{Binding PrimitiveWidth}"/>
|
||||
<Setter Property="Height" Value="{Binding PrimitiveWidth}"/>
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="RectangleStyle" TargetType="Rectangle" BasedOn="{StaticResource ShapeStyle}">
|
||||
<Setter Property="Width" Value="{Binding PrimitiveWidth}"/>
|
||||
<Setter Property="Height" Value="{Binding PrimitiveHeight}"/>
|
||||
</Style>
|
||||
|
||||
<Rectangle x:Key="RectanglePrimitive" Style="{StaticResource RectangleStyle}" d:DataContext="{d:DesignInstance dataContexts:PrimitiveBase}" >
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="PreviewMouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonDown}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseUp">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseMove">
|
||||
<i:InvokeCommandAction Command="{Binding RectanglePreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
|
||||
</mouseEventTriggers:DoubleClickEventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Rectangle>
|
||||
|
||||
<Ellipse x:Key="EllipsePrimitive" Style="{StaticResource EllipseStyle}" d:DataContext="{d:DesignInstance dataContexts:PrimitiveBase}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="PreviewMouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonDown}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseUp">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseMove">
|
||||
<i:InvokeCommandAction Command="{Binding EllipsePreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
|
||||
</mouseEventTriggers:DoubleClickEventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Ellipse>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers
|
||||
{
|
||||
public class DoubleClickEventTrigger : EventTriggerBase<MouseButtonEventArgs>
|
||||
{
|
||||
public DoubleClickEventTrigger() : base(args => args.ClickCount == 2) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers
|
||||
{
|
||||
public class MouseWheelDownEventTrigger : EventTriggerBase<MouseWheelEventArgs>
|
||||
{
|
||||
public MouseWheelDownEventTrigger() : base(args => args.Delta > 0) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers
|
||||
{
|
||||
public class MouseWheelUpEventTrigger : EventTriggerBase<MouseWheelEventArgs>
|
||||
{
|
||||
public MouseWheelUpEventTrigger() : base(args => args.Delta < 0) { }
|
||||
}
|
||||
}
|
||||
142
Infrastructure/UI/UserControls/PrimitivePopup.xaml
Normal file
142
Infrastructure/UI/UserControls/PrimitivePopup.xaml
Normal file
@@ -0,0 +1,142 @@
|
||||
<UserControl x:Class="StructureHelper.Infrastructure.UI.UserControls.PrimitivePopup"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:StructureHelper.Infrastructure.UI.UserControls"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:dataContexts="clr-namespace:StructureHelper.Infrastructure.UI.DataContexts"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<!--Rectangle-->
|
||||
<local:PrimitivePopup IsOpen="{Binding ParamsPanelVisibilty}" d:DataContext="{d:DesignInstance dataContexts:Rectangle}" Type="Rectangle">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseLeave">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetPopupCanBeClosedTrue}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="MouseEnter">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetPopupCanBeClosedFalse}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Border Background="White" BorderBrush="Black" BorderThickness="1">
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="170"/>
|
||||
<ColumnDefinition Width="170"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Координата X" Margin="10"/>
|
||||
<TextBox Grid.Column="1" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RectParameterX, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Координата Y" Margin="10"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RectParameterY, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Ширина" Margin="10"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RectParameterWidth, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Высота" Margin="10"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RectParameterHeight, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Материал" Margin="10"/>
|
||||
<Button Grid.Row="4" Grid.Column="1" Margin="10" Background="White"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.OpenMaterialCatalogWithSelection}" CommandParameter="{Binding}"
|
||||
Content="{Binding MaterialName, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Цвет"/>
|
||||
<Button Grid.Row="5" Grid.Column="1" Margin="10" Background="{Binding Brush, Mode=TwoWay}"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetColor}" CommandParameter="{Binding}"/>
|
||||
<TextBlock Grid.Row="6" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Прозрачность"/>
|
||||
<TextBox Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" Margin="10,10,50,10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ParameterOpacity, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Text="%" Margin="25,10"/>
|
||||
<TextBlock Grid.Row="7" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Заблокировать объект" Grid.ColumnSpan="2"/>
|
||||
<CheckBox Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ElementLock, Mode=TwoWay}"></CheckBox>
|
||||
<TextBlock Grid.Row="8" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Z-порядок"/>
|
||||
<StackPanel Grid.Row="8" Grid.Column="1" Orientation="Horizontal">
|
||||
<TextBox VerticalAlignment="Center" HorizontalAlignment="Left" Width="50" Margin="10"
|
||||
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveIndex, Mode=TwoWay}"/>
|
||||
<TextBlock VerticalAlignment="Center" Text="Max = "/>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitivesCount, Mode=TwoWay}"/>
|
||||
</StackPanel>
|
||||
<Button Grid.Row="9" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Установить впереди всех" Margin="10"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetInFrontOfAll}" CommandParameter="{Binding}"/>
|
||||
<Button Grid.Row="9" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Установить позади всех" Margin="10"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetInBackOfAll}" CommandParameter="{Binding}"/>
|
||||
<Button Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10" Content="Установить параметры"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetParameters}" CommandParameter="{Binding}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</local:PrimitivePopup>
|
||||
<!--Ellipse-->
|
||||
<local:PrimitivePopup IsOpen="{Binding ParamsPanelVisibilty}" d:DataContext="{d:DesignInstance dataContexts:Ellipse}" Type="Ellipse">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseLeave">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetPopupCanBeClosedTrue}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="MouseEnter">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetPopupCanBeClosedFalse}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Border Background="White" BorderBrush="Black" BorderThickness="1">
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="170"/>
|
||||
<ColumnDefinition Width="170"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Координата центра X" Margin="10"/>
|
||||
<TextBox Grid.Column="1" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.EllipseParameterX, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Координата центра Y" Margin="10"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.EllipseParameterY, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Площадь" Margin="10"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Margin="10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.EllipseParameterSquare, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Материал" Margin="10"/>
|
||||
<Button Grid.Row="4" Grid.Column="1" Margin="10" Background="White"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.OpenMaterialCatalogWithSelection}" CommandParameter="{Binding}"
|
||||
Content="{Binding MaterialName, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Цвет"/>
|
||||
<Button Grid.Row="5" Grid.Column="1" Margin="10" Background="{Binding Brush, Mode=TwoWay}"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetColor}" CommandParameter="{Binding}"/>
|
||||
<TextBlock Grid.Row="6" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Прозрачность"/>
|
||||
<TextBox Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" Margin="10,10,50,10" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ParameterOpacity, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Text="%" Margin="25,10"/>
|
||||
<TextBlock Grid.Row="7" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Заблокировать объект" Grid.ColumnSpan="2"/>
|
||||
<CheckBox Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ElementLock, Mode=TwoWay}"></CheckBox>
|
||||
<TextBlock Grid.Row="8" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Z-порядок"/>
|
||||
<StackPanel Grid.Row="8" Grid.Column="1" Orientation="Horizontal">
|
||||
<TextBox VerticalAlignment="Center" HorizontalAlignment="Left" Width="50" Margin="10"
|
||||
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveIndex, Mode=TwoWay}"/>
|
||||
<TextBlock VerticalAlignment="Center" Text="Max = "/>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitivesCount, Mode=TwoWay}"/>
|
||||
</StackPanel>
|
||||
<Button Grid.Row="9" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Установить впереди всех" Margin="10"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetInFrontOfAll}" CommandParameter="{Binding}"/>
|
||||
<Button Grid.Row="9" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Установить позади всех" Margin="10"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetInBackOfAll}" CommandParameter="{Binding}"/>
|
||||
<Button Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10" Content="Установить параметры"
|
||||
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetParameters}" CommandParameter="{Binding}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</local:PrimitivePopup>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
47
Infrastructure/UI/UserControls/PrimitivePopup.xaml.cs
Normal file
47
Infrastructure/UI/UserControls/PrimitivePopup.xaml.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for PrimitivePopup.xaml
|
||||
/// </summary>
|
||||
public partial class PrimitivePopup : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty TypeProperty =
|
||||
DependencyProperty.Register("Type", typeof(PrimitiveType), typeof(PrimitivePopup));
|
||||
|
||||
public static readonly DependencyProperty IsOpenProperty =
|
||||
DependencyProperty.Register("IsOpen", typeof(bool), typeof(PrimitivePopup));
|
||||
|
||||
private PrimitiveType type;
|
||||
private bool isOpen;
|
||||
public PrimitiveType Type
|
||||
{
|
||||
get => type;
|
||||
set
|
||||
{
|
||||
if (value != type)
|
||||
{
|
||||
type = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOpen
|
||||
{
|
||||
get => isOpen;
|
||||
set
|
||||
{
|
||||
if (value != isOpen)
|
||||
isOpen = value;
|
||||
}
|
||||
}
|
||||
|
||||
public PrimitivePopup()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user