Refactoring WIP

This commit is contained in:
Nikolai Smirnov
2022-07-08 11:38:25 +05:00
parent fc4f1f1db3
commit 2c4df04c5c
43 changed files with 832 additions and 833 deletions

View File

@@ -1,4 +1,4 @@
namespace StructureHelper
namespace StructureHelper.Windows.MainWindow
{
public class MainModel
{

View File

@@ -1,11 +1,14 @@
<Window x:Class="StructureHelper.MainView"
<Window x:Class="StructureHelper.Windows.MainWindow.MainView"
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:infrastructure="clr-namespace:StructureHelper.Infrastructure"
xmlns:dataTemplates="clr-namespace:StructureHelper.Infrastructure.UI.DataTemplates"
xmlns:dataContexts="clr-namespace:StructureHelper.Infrastructure.UI.DataContexts"
xmlns:mouseEventTriggers="clr-namespace:StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers"
xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:MainViewModel}"
Title="StructureHelper" Height="700" Width="1000">
@@ -13,238 +16,11 @@
<KeyBinding Command="{Binding SetParameters}" Key="Enter"/>
</Window.InputBindings>
<Window.Resources>
<DataTemplate x:Key="rectangleTemplate">
<DockPanel>
<Border x:Name="Border" Width="{Binding BorderWidth, Mode=TwoWay}" Height="{Binding BorderHeight, Mode=TwoWay}" Background="{Binding Brush, Mode=TwoWay}"
Opacity="{Binding Opacity, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveLeftButtonDown}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseUp">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.BorderPreviewMouseMove}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<infrastructure:DoubleClickEventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
</infrastructure:DoubleClickEventTrigger>
</i:Interaction.Triggers>
<Border.ToolTip>
<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 ShowedRectX}"/>
<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 ShowedRectY}"/>
<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 BorderWidth}"/>
<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 BorderHeight}"/>
<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>
</Border.ToolTip>
<Rectangle Name="testRect" Fill="{Binding Brush, Mode=TwoWay}" Width="20" Height="20" StrokeThickness="2" Stroke="{Binding Brush, Mode=TwoWay}" HorizontalAlignment="Right" VerticalAlignment="Bottom" Cursor="SizeNWSE">
<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>
</Border>
<Popup IsOpen="{Binding ParamsPanelVisibilty}">
<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>
</Popup>
</DockPanel>
<DataTemplate DataType="{x:Type dataContexts:Rectangle}">
<dataTemplates:RectangleTemplate/>
</DataTemplate>
<DataTemplate x:Key="ellipseTemplate">
<DockPanel>
<Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}" Fill="{Binding Brush, Mode=TwoWay}" Opacity="{Binding Opacity, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveLeftButtonDown}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseUp">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.EllipsePreviewMouseMove}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<infrastructure:DoubleClickEventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
</infrastructure:DoubleClickEventTrigger>
</i:Interaction.Triggers>
<Ellipse.ToolTip>
<ToolTip Background="White" BorderBrush="Black" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<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 ShowedEllipseX}"/>
<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 ShowedEllipseY}"/>
<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 ShowedDiameter}"/>
<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>
</Ellipse.ToolTip>
</Ellipse>
<Popup IsOpen="{Binding ParamsPanelVisibilty}">
<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>
</Popup>
</DockPanel>
<DataTemplate DataType="{x:Type dataContexts:Ellipse}">
<dataTemplates:EllipseTemplate/>
</DataTemplate>
</Window.Resources>
<Grid>
@@ -262,15 +38,15 @@
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
<Canvas ClipToBounds="True" Width="{Binding CanvasWidth}" Height="{Binding CanvasHeight}">
<i:Interaction.Behaviors>
<local:MouseBehaviour MouseX="{Binding PanelX, Mode=OneWayToSource}" MouseY="{Binding PanelY, Mode=OneWayToSource}"/>
<infrastructure:MouseBehaviour MouseX="{Binding PanelX, Mode=OneWayToSource}" MouseY="{Binding PanelY, Mode=OneWayToSource}"/>
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<infrastructure:MouseWheelDownEventTrigger EventName="PreviewMouseWheel">
<i:InvokeCommandAction Command="{Binding ScaleCanvasDown}" CommandParameter="{Binding}"/>
</infrastructure:MouseWheelDownEventTrigger>
<infrastructure:MouseWheelUpEventTrigger EventName="PreviewMouseWheel">
<i:InvokeCommandAction Command="{Binding ScaleCanvasUp}" CommandParameter="{Binding}"/>
</infrastructure:MouseWheelUpEventTrigger>
<mouseEventTriggers:MouseWheelDownEventTrigger EventName="PreviewMouseWheel">
<i:InvokeCommandAction Command="{Binding ScaleCanvasDown}"/>
</mouseEventTriggers:MouseWheelDownEventTrigger>
<mouseEventTriggers:MouseWheelUpEventTrigger EventName="PreviewMouseWheel">
<i:InvokeCommandAction Command="{Binding ScaleCanvasUp}"/>
</mouseEventTriggers:MouseWheelUpEventTrigger>
</i:Interaction.Triggers>
<Canvas.RenderTransform>
<TransformGroup>
@@ -294,7 +70,7 @@
</Canvas.Background>
<Line X1="0" X2="{Binding XX2}" Y1="{Binding XY1}" Y2="{Binding XY1}" Stroke="Red" StrokeThickness="1"/>
<Line X1="{Binding YX1}" X2="{Binding YX1}" Y1="0" Y2="{Binding YY2}" Stroke="ForestGreen" StrokeThickness="1"/>
<ItemsControl ItemsSource="{Binding Rectangles}" ItemTemplate="{StaticResource rectangleTemplate}">
<ItemsControl ItemsSource="{Binding Primitives}" d:DataContext="{d:DesignInstance dataContexts:PrimitiveBase}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
@@ -303,22 +79,8 @@
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
<Setter Property="Canvas.Left" Value="{Binding RectX}"/>
<Setter Property="Canvas.Top" Value="{Binding RectY}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
<ItemsControl ItemsSource="{Binding Ellipses}" ItemTemplate="{StaticResource ellipseTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
<Setter Property="Canvas.Left" Value="{Binding EllipseX}"/>
<Setter Property="Canvas.Top" Value="{Binding EllipseY}"/>
<Setter Property="Canvas.Left" Value="{Binding X}"/>
<Setter Property="Canvas.Top" Value="{Binding Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>

View File

@@ -1,6 +1,6 @@
using System.Windows;
namespace StructureHelper
namespace StructureHelper.Windows.MainWindow
{
public partial class MainView : Window
{

View File

@@ -3,16 +3,18 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.Extensions;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.MaterialCatalogWindow;
using StructureHelper.Windows.ColorPickerWindow;
namespace StructureHelper
namespace StructureHelper.Windows.MainWindow
{
public class MainViewModel : ViewModelBase
{
private MainModel rectanglesModel;
private MainView rectanglesView;
public ObservableCollection<RectangleDefinition> Rectangles { get; set; }
public ObservableCollection<EllipseDefinition> Ellipses { get; set; }
public ObservableCollection<PrimitiveDefinitionBase> Primitives { get; set; }
public ObservableCollection<PrimitiveBase> Primitives { get; set; }
public ICommand AddRectangle { get; }
private double panelX, panelY, scrollPanelX, scrollPanelY;
@@ -157,19 +159,13 @@ namespace StructureHelper
set => OnPropertyChanged(value, ref yY2);
}
private double delta = 0.5;
public ICommand LeftButtonDown { get; }
public ICommand LeftButtonUp { get; }
public ICommand PreviewMouseMove { get; }
public ICommand PrimitiveLeftButtonDown { get; }
public ICommand PrimitiveLeftButtonUp { get; }
public ICommand BorderPreviewMouseMove { get; }
public ICommand PrimitiveDoubleClick { get; }
public ICommand SetParameters { get; }
public ICommand ClearSelection { get; }
public ICommand SetPopupCanBeClosedTrue { get; }
public ICommand SetPopupCanBeClosedFalse { get; }
public ICommand OpenMaterialCatalog { get; }
public ICommand OpenMaterialCatalogWithSelection { get; }
public ICommand SetColor { get; }
@@ -178,7 +174,11 @@ namespace StructureHelper
public ICommand ScaleCanvasDown { get; }
public ICommand ScaleCanvasUp { get; }
public ICommand AddEllipse { get; }
public ICommand EllipsePreviewMouseMove { get; }
public ICommand SetPopupCanBeClosedTrue { get; }
public ICommand SetPopupCanBeClosedFalse { get; }
private double delta = 0.5;
public MainViewModel() { }
public MainViewModel(MainModel rectanglesModel, MainView rectanglesView)
@@ -193,67 +193,29 @@ namespace StructureHelper
YX1 = CanvasWidth / 2;
YY2 = CanvasHeight;
BorderPreviewMouseMove = new RelayCommand(o =>
{
if (!(o is RectangleDefinition rect)) return;
if (rect.Captured && !rect.BorderCaptured && !rect.ElementLock)
{
var deltaX = rect.BorderWidth / 2;
var deltaY = rect.BorderHeight / 2;
if (rect.ShowedRectX % 10 <= delta || rect.ShowedRectX % 10 >= 10 - delta)
rect.ShowedRectX = Math.Round((PanelX - deltaX - YX1) / 10) * 10;
else
rect.ShowedRectX = PanelX - deltaX - YX1;
if (rect.ShowedRectY % 10 <= delta || rect.ShowedRectY % 10 >= 10 - delta)
rect.ShowedRectY = -(Math.Round((PanelY - deltaY - XY1 + rect.BorderHeight) / 10) * 10);
else
rect.ShowedRectY = -(PanelY - deltaY - XY1 + rect.BorderHeight);
}
if (rect.ParameterCaptured)
{
RectParameterX = rect.ShowedRectX;
RectParameterY = rect.ShowedRectY;
RectParameterWidth = rect.BorderWidth;
RectParameterHeight = rect.BorderHeight;
ParameterOpacity = rect.ShowedOpacity;
ElementLock = rect.ElementLock;
}
});
PrimitiveLeftButtonUp = new RelayCommand(o =>
{
if (o is PrimitiveDefinitionBase primitive) primitive.Captured = false;
});
PrimitiveLeftButtonDown = new RelayCommand(o =>
{
if (!(o is PrimitiveDefinitionBase primitive)) return;
primitive.Captured = true;
foreach (var primitiveDefinition in Primitives)
primitiveDefinition.ParameterCaptured = false;
primitive.ParameterCaptured = true;
});
LeftButtonUp = new RelayCommand(o =>
{
if (o is RectangleDefinition rect) rect.BorderCaptured = false;
if (o is Rectangle rect) rect.BorderCaptured = false;
});
LeftButtonDown = new RelayCommand(o =>
{
if (o is RectangleDefinition rect) rect.BorderCaptured = true;
if (o is Rectangle rect) rect.BorderCaptured = true;
});
PreviewMouseMove = new RelayCommand(o =>
{
if (o is RectangleDefinition rect && rect.BorderCaptured && rect.Captured && !rect.ElementLock)
if (o is Rectangle rect && rect.BorderCaptured && !rect.ElementLock)
{
if (rect.BorderWidth % 10 < delta || rect.BorderWidth % 10 >= delta)
rect.BorderWidth = Math.Round(PanelX / 10) * 10 - rect.RectX + 10;
if (rect.PrimitiveWidth % 10 < delta || rect.PrimitiveWidth % 10 >= delta)
rect.PrimitiveWidth = Math.Round(PanelX / 10) * 10 - rect.X + 10;
else
rect.BorderWidth = PanelX - rect.RectX + 10;
rect.PrimitiveWidth = PanelX - rect.X + 10;
if (rect.BorderHeight % 10 < delta || rect.BorderHeight % 10 >= delta)
rect.BorderHeight = Math.Round(PanelY / 10) * 10 - rect.RectY + 10;
if (rect.PrimitiveHeight % 10 < delta || rect.PrimitiveHeight % 10 >= delta)
rect.PrimitiveHeight = Math.Round(PanelY / 10) * 10 - rect.Y + 10;
else
rect.BorderHeight = PanelY - rect.RectY + 10;
rect.PrimitiveHeight = PanelY - rect.Y + 10;
}
});
SetParameters = new RelayCommand(o =>
@@ -269,16 +231,16 @@ namespace StructureHelper
switch (primitive)
{
case RectangleDefinition rectangle:
rectangle.ShowedRectX = RectParameterX;
rectangle.ShowedRectY = RectParameterY;
rectangle.BorderWidth = RectParameterWidth;
rectangle.BorderHeight = RectParameterHeight;
case Rectangle rectangle:
rectangle.ShowedX = RectParameterX;
rectangle.ShowedY = RectParameterY;
rectangle.PrimitiveWidth = RectParameterWidth;
rectangle.PrimitiveHeight = RectParameterHeight;
break;
case EllipseDefinition ellipse:
case Ellipse ellipse:
ellipse.Square = EllipseParameterSquare;
ellipse.ShowedEllipseX = EllipseParameterX;
ellipse.ShowedEllipseY = EllipseParameterY;
ellipse.ShowedX = EllipseParameterX;
ellipse.ShowedY = EllipseParameterY;
break;
}
}
@@ -289,26 +251,8 @@ namespace StructureHelper
if (primitive != null && primitive.PopupCanBeClosed)
primitive.ParamsPanelVisibilty = false;
});
PrimitiveDoubleClick = new RelayCommand(o =>
{
if (!(o is PrimitiveDefinitionBase primitive)) return;
primitive.PopupCanBeClosed = false;
primitive.Captured = false;
primitive.ParamsPanelVisibilty = true;
if (primitive is RectangleDefinition rect)
rect.BorderCaptured = false;
});
SetPopupCanBeClosedTrue = new RelayCommand(o =>
{
var primitiveParamsVisible = Primitives.FirstOrDefault(x => x.ParameterCaptured);
if (primitiveParamsVisible != null) primitiveParamsVisible.PopupCanBeClosed = true;
});
SetPopupCanBeClosedFalse = new RelayCommand(o =>
{
var primitiveParamsVisible = Primitives.FirstOrDefault(x => x.ParameterCaptured);
if (primitiveParamsVisible != null) primitiveParamsVisible.PopupCanBeClosed = false;
});
OpenMaterialCatalog = new RelayCommand(o =>
{
var materialCatalogView = new MaterialCatalogView();
@@ -316,19 +260,19 @@ namespace StructureHelper
});
OpenMaterialCatalogWithSelection = new RelayCommand(o =>
{
var primitive = o as PrimitiveDefinitionBase;
var primitive = o as PrimitiveBase;
var materialCatalogView = new MaterialCatalogView(true, primitive);
materialCatalogView.ShowDialog();
});
SetColor = new RelayCommand(o =>
{
var primitive = o as PrimitiveDefinitionBase;
var primitive = o as PrimitiveBase;
var colorPickerView = new ColorPickerView(primitive);
colorPickerView.ShowDialog();
});
SetInFrontOfAll = new RelayCommand(o =>
{
if (!(o is PrimitiveDefinitionBase primitive)) return;
if (!(o is PrimitiveBase primitive)) return;
foreach (var primitiveDefinition in Primitives)
if (primitiveDefinition.ShowedZIndex > primitive.ShowedZIndex && primitiveDefinition != primitive)
primitiveDefinition.ShowedZIndex--;
@@ -337,7 +281,7 @@ namespace StructureHelper
});
SetInBackOfAll = new RelayCommand(o =>
{
if (!(o is PrimitiveDefinitionBase primitive)) return;
if (!(o is PrimitiveBase primitive)) return;
foreach (var primitiveDefinition in Primitives)
if (primitiveDefinition.ShowedZIndex < primitive.ShowedZIndex && primitiveDefinition != primitive)
primitiveDefinition.ShowedZIndex++;
@@ -359,48 +303,29 @@ namespace StructureHelper
ScaleValue /= scaleRate;
});
Primitives = new ObservableCollection<PrimitiveDefinitionBase>();
Rectangles = new ObservableCollection<RectangleDefinition>();
Ellipses = new ObservableCollection<EllipseDefinition>();
Primitives = new ObservableCollection<PrimitiveBase>();
AddRectangle = new RelayCommand(o =>
{
var rectangle = new RectangleDefinition(60, 40, YX1, XY1);
Rectangles.Add(rectangle);
var rectangle = new Rectangle(60, 40, YX1, XY1, this);
Primitives.Add(rectangle);
PrimitivesCount = Primitives.Count;
});
AddEllipse = new RelayCommand(o =>
{
var ellipse = new EllipseDefinition(2000, YX1, XY1);
Ellipses.Add(ellipse);
var ellipse = new Ellipse(2000, YX1, XY1, this);
Primitives.Add(ellipse);
PrimitivesCount = Primitives.Count;
});
EllipsePreviewMouseMove = new RelayCommand(o =>
SetPopupCanBeClosedTrue = new RelayCommand(o =>
{
if (!(o is EllipseDefinition ellipse)) return;
if (ellipse.Captured && !ellipse.ElementLock)
{
var ellipseDelta = ellipse.Diameter / 2;
if (ellipse.ShowedEllipseX % 10 <= ellipseDelta || ellipse.ShowedEllipseX % 10 >= 10 - ellipseDelta)
ellipse.ShowedEllipseX = Math.Round((PanelX - YX1) / 10) * 10;
else
ellipse.ShowedEllipseX = PanelX - ellipseDelta - YX1;
if (ellipse.ShowedEllipseY % 10 <= ellipseDelta || ellipse.ShowedEllipseY % 10 >= 10 - ellipseDelta)
ellipse.ShowedEllipseY = -(Math.Round((PanelY - XY1) / 10) * 10);
else
ellipse.ShowedEllipseY = -(PanelY - ellipseDelta - XY1);
}
if (ellipse.ParameterCaptured)
{
EllipseParameterX = ellipse.ShowedEllipseX;
EllipseParameterY = ellipse.ShowedEllipseY;
EllipseParameterSquare = ellipse.Square;
ParameterOpacity = ellipse.ShowedOpacity;
ElementLock = ellipse.ElementLock;
}
if (!(o is PrimitiveBase primitive)) return;
primitive.PopupCanBeClosed = true;
});
SetPopupCanBeClosedFalse = new RelayCommand(o =>
{
if (!(o is PrimitiveBase primitive)) return;
primitive.PopupCanBeClosed = false;
});
}
}