Init commit
This commit is contained in:
47
Windows/AddMaterialWindow/AddMaterialView.xaml
Normal file
47
Windows/AddMaterialWindow/AddMaterialView.xaml
Normal file
@@ -0,0 +1,47 @@
|
||||
<Window x:Class="StructureHelper.AddMaterialView"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:AddMaterialViewModel}"
|
||||
Title="Добавление материала" Height="350" Width="400">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="40"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="{Binding RowHeight}"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="{Binding RowHeight}"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2.2*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Группа материалов"/>
|
||||
<ComboBox Grid.Row="0" Grid.Column="1" Margin="10" ItemsSource="{Binding Materials}" DisplayMemberPath="Name" SelectedItem="{Binding MaterialCollection}"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Класс"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Margin="10" Text="{Binding MaterialClass}"/>
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Модуль упругости" IsEnabled="{Binding IsNotConcrete}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Margin="10" IsEnabled="{Binding IsNotConcrete}" Text="{Binding YoungModulus}"/>
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Нормативная прочность на сжатие"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Margin="10" Text="{Binding CompressiveStrengthCoef}"/>
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Нормативная прочность на растяжение" IsEnabled="{Binding IsNotConcrete}"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1" Margin="10" Text="{Binding TensileStrengthCoef}" IsEnabled="{Binding IsNotConcrete}"/>
|
||||
<TextBlock Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Коэффициент надежности при сжатии"/>
|
||||
<TextBox Grid.Row="5" Grid.Column="1" Margin="10" Text="{Binding MaterialCoefInCompress}"/>
|
||||
<TextBlock Grid.Row="6" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Коэффициент надежности при расширении"/>
|
||||
<TextBox Grid.Row="6" Grid.Column="1" Margin="10" Text="{Binding MaterialCoefInTension}"/>
|
||||
</Grid>
|
||||
<Button Grid.Row="1" Grid.Column="0" Margin="10" HorizontalAlignment="Left" Content="Добавить материал" Command="{Binding AddMaterial}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
17
Windows/AddMaterialWindow/AddMaterialView.xaml.cs
Normal file
17
Windows/AddMaterialWindow/AddMaterialView.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для AddMaterialView.xaml
|
||||
/// </summary>
|
||||
public partial class AddMaterialView : Window
|
||||
{
|
||||
public AddMaterialView(MaterialCatalogModel model, MaterialCatalogViewModel materialCatalogViewModel)
|
||||
{
|
||||
var viewModel = new AddMaterialViewModel(model, this, materialCatalogViewModel);
|
||||
DataContext = viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Windows/AddMaterialWindow/AddMaterialViewModel.cs
Normal file
82
Windows/AddMaterialWindow/AddMaterialViewModel.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using StructureHelper.Infrastructure;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class AddMaterialViewModel : ViewModelBase
|
||||
{
|
||||
private MaterialCatalogModel model;
|
||||
private AddMaterialView view;
|
||||
private MaterialCatalogViewModel materialCatalogViewModel;
|
||||
public ObservableCollection<NamedList<MaterialDefinitionBase>> Materials { get; set; }
|
||||
private NamedList<MaterialDefinitionBase> materialCollection;
|
||||
public NamedList<MaterialDefinitionBase> MaterialCollection
|
||||
{
|
||||
get => materialCollection;
|
||||
set
|
||||
{
|
||||
OnPropertyChanged(value, materialCollection);
|
||||
OnPropertyChanged(nameof(IsNotConcrete));
|
||||
OnPropertyChanged(nameof(RowHeight));
|
||||
}
|
||||
}
|
||||
public bool IsNotConcrete => MaterialCollection.Name != "Бетон";
|
||||
|
||||
private string materialClass;
|
||||
private double youngModulus, compressiveStrengthCoef, tensileStrengthCoef, materialCoefInCompress, materialCoefInTension;
|
||||
|
||||
public string MaterialClass
|
||||
{
|
||||
get => materialClass;
|
||||
set => OnPropertyChanged(value, ref materialClass);
|
||||
}
|
||||
|
||||
public double YoungModulus
|
||||
{
|
||||
get => youngModulus;
|
||||
set => OnPropertyChanged(value, ref youngModulus);
|
||||
}
|
||||
public double CompressiveStrengthCoef
|
||||
{
|
||||
get => compressiveStrengthCoef;
|
||||
set => OnPropertyChanged(value, ref compressiveStrengthCoef);
|
||||
}
|
||||
public double TensileStrengthCoef
|
||||
{
|
||||
get => tensileStrengthCoef;
|
||||
set => OnPropertyChanged(value, ref tensileStrengthCoef);
|
||||
}
|
||||
public double MaterialCoefInCompress
|
||||
{
|
||||
get => materialCoefInCompress;
|
||||
set => OnPropertyChanged(value, ref materialCoefInCompress);
|
||||
}
|
||||
public double MaterialCoefInTension
|
||||
{
|
||||
get => materialCoefInTension;
|
||||
set => OnPropertyChanged(value, ref materialCoefInTension);
|
||||
}
|
||||
|
||||
public int RowHeight => IsNotConcrete ? 40 : 0;
|
||||
public ICommand AddMaterial { get; }
|
||||
public AddMaterialViewModel() { }
|
||||
public AddMaterialViewModel(MaterialCatalogModel model, AddMaterialView view, MaterialCatalogViewModel materialCatalogViewModel)
|
||||
{
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
this.materialCatalogViewModel = materialCatalogViewModel;
|
||||
Materials = new ObservableCollection<NamedList<MaterialDefinitionBase>>(model.Materials);
|
||||
MaterialCollection = Materials.First();
|
||||
|
||||
AddMaterial = new RelayCommand(o =>
|
||||
{
|
||||
if (MaterialCollection.Name == "Бетон")
|
||||
this.materialCatalogViewModel.ConcreteDefinitions.Add(new ConcreteDefinition(MaterialClass, 0, CompressiveStrengthCoef, TensileStrengthCoef, MaterialCoefInCompress, MaterialCoefInTension));
|
||||
if (MaterialCollection.Name == "Арматура")
|
||||
this.materialCatalogViewModel.RebarDefinitions.Add(new RebarDefinition(MaterialClass, YoungModulus, CompressiveStrengthCoef, TensileStrengthCoef, MaterialCoefInCompress, MaterialCoefInTension));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Windows/ColorPickerWindow/ColorPickerView.xaml
Normal file
41
Windows/ColorPickerWindow/ColorPickerView.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<Window x:Class="StructureHelper.ColorPickerView"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:ColorPickerViewModel}"
|
||||
Title="Выбрать цвет" Height="200" Width="500" Topmost="True" ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Красный"/>
|
||||
<Slider Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Value="{Binding Red}" Minimum="0" Maximum="255"/>
|
||||
<TextBox Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Text="{Binding Red}"/>
|
||||
|
||||
<Border Grid.Column="3" Grid.RowSpan="3" Margin="10" BorderBrush="Black" BorderThickness="1">
|
||||
<Rectangle Fill="{Binding SelectedColor}"/>
|
||||
</Border>
|
||||
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Зеленый"/>
|
||||
<Slider Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Value="{Binding Green}" Minimum="0" Maximum="255"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Text="{Binding Green}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Синий"/>
|
||||
<Slider Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Value="{Binding Blue}" Minimum="0" Maximum="255"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Text="{Binding Blue}"/>
|
||||
|
||||
<Button Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Выбрать цвет" Command="{Binding SetColor}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
17
Windows/ColorPickerWindow/ColorPickerView.xaml.cs
Normal file
17
Windows/ColorPickerWindow/ColorPickerView.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для ColorPickerView.xaml
|
||||
/// </summary>
|
||||
public partial class ColorPickerView : Window
|
||||
{
|
||||
public ColorPickerView(PrimitiveDefinition primitive)
|
||||
{
|
||||
var viewModel = new ColorPickerViewModel(primitive);
|
||||
DataContext = viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Windows/ColorPickerWindow/ColorPickerViewModel.cs
Normal file
64
Windows/ColorPickerWindow/ColorPickerViewModel.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class ColorPickerViewModel : ViewModelBase
|
||||
{
|
||||
private int red, green, blue;
|
||||
|
||||
public int Red
|
||||
{
|
||||
get => red;
|
||||
set => OnColorItemChanged(value, ref red);
|
||||
}
|
||||
public int Green
|
||||
{
|
||||
get => green;
|
||||
set => OnColorItemChanged(value, ref green);
|
||||
}
|
||||
public int Blue
|
||||
{
|
||||
get => blue;
|
||||
set => OnColorItemChanged(value, ref blue);
|
||||
}
|
||||
|
||||
private SolidColorBrush selectedColor;
|
||||
public SolidColorBrush SelectedColor
|
||||
{
|
||||
get => selectedColor;
|
||||
set => OnPropertyChanged(value, selectedColor);
|
||||
}
|
||||
public ICommand SetColor { get; }
|
||||
public ColorPickerViewModel(PrimitiveDefinitionBase primitive)
|
||||
{
|
||||
if (primitive != null)
|
||||
{
|
||||
var solidBrush = primitive.Brush;
|
||||
Red = solidBrush.Color.R;
|
||||
Green = solidBrush.Color.G;
|
||||
Blue = solidBrush.Color.B;
|
||||
|
||||
SetColor = new RelayCommand(o => primitive.Brush = SelectedColor);
|
||||
}
|
||||
}
|
||||
private void OnColorItemChanged(int value, ref int colorItem, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (value >= 0 && value <= 255 && Math.Abs(colorItem - value) > 0.001)
|
||||
{
|
||||
colorItem = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
UpdateSelectedColor();
|
||||
}
|
||||
}
|
||||
private void UpdateSelectedColor()
|
||||
{
|
||||
var color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue);
|
||||
SelectedColor = new SolidColorBrush(color);
|
||||
OnPropertyChanged(nameof(SelectedColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Windows/MainWindow/MainModel.cs
Normal file
7
Windows/MainWindow/MainModel.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class MainModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
318
Windows/MainWindow/MainView.xaml
Normal file
318
Windows/MainWindow/MainView.xaml
Normal file
@@ -0,0 +1,318 @@
|
||||
<Window x:Class="StructureHelper.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"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:MainViewModel}"
|
||||
Title="StructureHelper" Height="700" Width="1000">
|
||||
<Window.InputBindings>
|
||||
<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>
|
||||
<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>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border BorderBrush="Black" Background="White" BorderThickness="1" Margin="5">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="PreviewMouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding ClearSelection}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<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}"/>
|
||||
</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>
|
||||
</i:Interaction.Triggers>
|
||||
<Canvas.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleX="{Binding ScaleValue}" ScaleY="{Binding ScaleValue}"
|
||||
CenterX="{Binding ScrollPanelX}" CenterY="{Binding ScrollPanelY}"/>
|
||||
</TransformGroup>
|
||||
</Canvas.RenderTransform>
|
||||
<Canvas.Background>
|
||||
<DrawingBrush Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
|
||||
<DrawingBrush.Drawing>
|
||||
<GeometryDrawing Brush="Black">
|
||||
<GeometryDrawing.Geometry>
|
||||
<GeometryGroup FillRule="EvenOdd">
|
||||
<RectangleGeometry Rect="0,0,50,50"/>
|
||||
<RectangleGeometry Rect="0,0,49.5,49.5"/>
|
||||
</GeometryGroup>
|
||||
</GeometryDrawing.Geometry>
|
||||
</GeometryDrawing>
|
||||
</DrawingBrush.Drawing>
|
||||
</DrawingBrush>
|
||||
</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 Primitives}" ItemTemplate="{Binding}">
|
||||
<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 X}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Y}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
</ItemsControl>
|
||||
</Canvas>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<Button Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Content="Справочник" Command="{Binding OpenMaterialCatalog}"/>
|
||||
<Button Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10" Content="Добавить прямоугольник" Command="{Binding AddRectangle}"/>
|
||||
<Button Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10" Content="Добавить точку" Command="{Binding AddEllipse}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
15
Windows/MainWindow/MainView.xaml.cs
Normal file
15
Windows/MainWindow/MainView.xaml.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public partial class MainView : Window
|
||||
{
|
||||
public MainView()
|
||||
{
|
||||
var model = new MainModel();
|
||||
var viewModel = new MainViewModel(model, this);
|
||||
DataContext = viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
408
Windows/MainWindow/MainViewModel.cs
Normal file
408
Windows/MainWindow/MainViewModel.cs
Normal file
@@ -0,0 +1,408 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using StructureHelper.Infrastructure;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
private MainModel rectanglesModel;
|
||||
private MainView rectanglesView;
|
||||
public ObservableCollection<RectangleDefinition> Rectangles { get; set; }
|
||||
public ObservableCollection<EllipseDefinition> Ellipses { get; set; }
|
||||
public ObservableCollection<PrimitiveDefinition> Primitives { get; set; }
|
||||
public ICommand AddRectangle { get; }
|
||||
|
||||
private double panelX, panelY, scrollPanelX, scrollPanelY;
|
||||
|
||||
public double PanelX
|
||||
{
|
||||
get => panelX;
|
||||
set => OnPropertyChanged(value, ref panelX);
|
||||
}
|
||||
public double PanelY
|
||||
{
|
||||
get => panelY;
|
||||
set => OnPropertyChanged(value, ref panelY);
|
||||
}
|
||||
public double ScrollPanelX
|
||||
{
|
||||
get => scrollPanelX;
|
||||
set => OnPropertyChanged(value, ref scrollPanelX);
|
||||
}
|
||||
public double ScrollPanelY
|
||||
{
|
||||
get => scrollPanelY;
|
||||
set => OnPropertyChanged(value, ref scrollPanelY);
|
||||
}
|
||||
|
||||
private double rectParameterX, rectParameterY, rectParameterWidth, rectParameterHeight;
|
||||
|
||||
public double RectParameterX
|
||||
{
|
||||
get => rectParameterX;
|
||||
set => OnPropertyChanged(value, ref rectParameterX);
|
||||
}
|
||||
public double RectParameterY
|
||||
{
|
||||
get => rectParameterY;
|
||||
set => OnPropertyChanged(value, ref rectParameterY);
|
||||
}
|
||||
public double RectParameterWidth
|
||||
{
|
||||
get => rectParameterWidth;
|
||||
set => OnPropertyChanged(value, ref rectParameterWidth);
|
||||
}
|
||||
public double RectParameterHeight
|
||||
{
|
||||
get => rectParameterHeight;
|
||||
set => OnPropertyChanged(value, ref rectParameterHeight);
|
||||
}
|
||||
|
||||
private double parameterOpacity = 0;
|
||||
|
||||
public double ParameterOpacity
|
||||
{
|
||||
get => parameterOpacity;
|
||||
set
|
||||
{
|
||||
if (value >= 0 && value <= 100)
|
||||
OnPropertyChanged(value, ref parameterOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
private double ellipseParameterX, ellipseParameterY, ellipseParameterSquare;
|
||||
public double EllipseParameterX
|
||||
{
|
||||
get => ellipseParameterX;
|
||||
set => OnPropertyChanged(value, ref ellipseParameterX);
|
||||
}
|
||||
|
||||
public double EllipseParameterY
|
||||
{
|
||||
get => ellipseParameterY;
|
||||
set => OnPropertyChanged(value, ref ellipseParameterY);
|
||||
}
|
||||
|
||||
public double EllipseParameterSquare
|
||||
{
|
||||
get => ellipseParameterSquare;
|
||||
set => OnPropertyChanged(value, ref ellipseParameterSquare);
|
||||
}
|
||||
private bool elementLock;
|
||||
public bool ElementLock
|
||||
{
|
||||
get => elementLock;
|
||||
set => OnPropertyChanged(value, ref elementLock);
|
||||
}
|
||||
|
||||
private int primitivesCount;
|
||||
public int PrimitivesCount
|
||||
{
|
||||
get => primitivesCount;
|
||||
set => OnPropertyChanged(value, ref primitivesCount);
|
||||
}
|
||||
|
||||
private int primitiveIndex = 1;
|
||||
public int PrimitiveIndex
|
||||
{
|
||||
get => primitiveIndex;
|
||||
set
|
||||
{
|
||||
if (value >= 0 && value <= primitivesCount)
|
||||
OnPropertyChanged(value, ref primitiveIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private double scaleValue = 1.0;
|
||||
public double ScaleValue
|
||||
{
|
||||
get => scaleValue;
|
||||
set => OnPropertyChanged(value, ref scaleValue);
|
||||
}
|
||||
|
||||
private double canvasWidth, canvasHeight, xX2, xY1, yX1, yY2;
|
||||
public double CanvasWidth
|
||||
{
|
||||
get => canvasWidth;
|
||||
set => OnPropertyChanged(value, ref canvasWidth);
|
||||
}
|
||||
|
||||
public double CanvasHeight
|
||||
{
|
||||
get => canvasHeight;
|
||||
set => OnPropertyChanged(value, ref canvasHeight);
|
||||
}
|
||||
|
||||
public double XX2
|
||||
{
|
||||
get => xX2;
|
||||
set => OnPropertyChanged(value, ref xX2);
|
||||
}
|
||||
public double XY1
|
||||
{
|
||||
get => xY1;
|
||||
set => OnPropertyChanged(value, ref xY1);
|
||||
}
|
||||
public double YX1
|
||||
{
|
||||
get => yX1;
|
||||
set => OnPropertyChanged(value, ref yX1);
|
||||
}
|
||||
public double YY2
|
||||
{
|
||||
get => yY2;
|
||||
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; }
|
||||
public ICommand SetInFrontOfAll { get; }
|
||||
public ICommand SetInBackOfAll { get; }
|
||||
public ICommand ScaleCanvasDown { get; }
|
||||
public ICommand ScaleCanvasUp { get; }
|
||||
public ICommand AddEllipse { get; }
|
||||
public ICommand EllipsePreviewMouseMove { get; }
|
||||
|
||||
public MainViewModel() { }
|
||||
public MainViewModel(MainModel rectanglesModel, MainView rectanglesView)
|
||||
{
|
||||
this.rectanglesModel = rectanglesModel;
|
||||
this.rectanglesView = rectanglesView;
|
||||
|
||||
CanvasWidth = 1500;
|
||||
CanvasHeight = 1000;
|
||||
XX2 = CanvasWidth;
|
||||
XY1 = CanvasHeight / 2;
|
||||
YX1 = CanvasWidth / 2;
|
||||
YY2 = CanvasHeight;
|
||||
|
||||
BorderPreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
var rect = o as RectangleDefinition;
|
||||
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 =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
primitive.Captured = false;
|
||||
});
|
||||
PrimitiveLeftButtonDown = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
primitive.Captured = true;
|
||||
foreach (var primitiveDefinition in Primitives)
|
||||
primitiveDefinition.ParameterCaptured = false;
|
||||
primitive.ParameterCaptured = true;
|
||||
});
|
||||
LeftButtonUp = new RelayCommand(o =>
|
||||
{
|
||||
var rect = o as RectangleDefinition;
|
||||
rect.BorderCaptured = false;
|
||||
});
|
||||
LeftButtonDown = new RelayCommand(o =>
|
||||
{
|
||||
var rect = o as RectangleDefinition;
|
||||
rect.BorderCaptured = true;
|
||||
});
|
||||
PreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
var rect = o as RectangleDefinition;
|
||||
if (rect.BorderCaptured && rect.Captured && !rect.ElementLock)
|
||||
{
|
||||
if (rect.BorderWidth % 10 < delta || rect.BorderWidth % 10 >= delta)
|
||||
rect.BorderWidth = Math.Round(PanelX / 10) * 10 - rect.RectX + 10;
|
||||
else
|
||||
rect.BorderWidth = PanelX - rect.RectX + 10;
|
||||
|
||||
if (rect.BorderHeight % 10 < delta || rect.BorderHeight % 10 >= delta)
|
||||
rect.BorderHeight = Math.Round(PanelY / 10) * 10 - rect.RectY + 10;
|
||||
else
|
||||
rect.BorderHeight = PanelY - rect.RectY + 10;
|
||||
}
|
||||
});
|
||||
SetParameters = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = Primitives.FirstOrDefault(x => x.ParameterCaptured);
|
||||
primitive.ElementLock = ElementLock;
|
||||
primitive.ShowedOpacity = ParameterOpacity;
|
||||
Primitives.MoveElementToSelectedIndex(primitive, PrimitiveIndex);
|
||||
foreach (var primitiveDefinition in Primitives)
|
||||
primitiveDefinition.ShowedZIndex = Primitives.IndexOf(primitiveDefinition) + 1;
|
||||
|
||||
if (primitive is RectangleDefinition rectangle)
|
||||
{
|
||||
rectangle.ShowedRectX = RectParameterX;
|
||||
rectangle.ShowedRectY = RectParameterY;
|
||||
rectangle.BorderWidth = RectParameterWidth;
|
||||
rectangle.BorderHeight = RectParameterHeight;
|
||||
}
|
||||
|
||||
if (primitive is EllipseDefinition ellipse)
|
||||
{
|
||||
ellipse.Square = EllipseParameterSquare;
|
||||
ellipse.ShowedEllipseX = EllipseParameterX;
|
||||
ellipse.ShowedEllipseY = EllipseParameterY;
|
||||
}
|
||||
});
|
||||
ClearSelection = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = Primitives.FirstOrDefault(x => x.ParamsPanelVisibilty);
|
||||
if (primitive != null && primitive.PopupCanBeClosed)
|
||||
primitive.ParamsPanelVisibilty = false;
|
||||
});
|
||||
PrimitiveDoubleClick = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
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);
|
||||
primitiveParamsVisible.PopupCanBeClosed = true;
|
||||
});
|
||||
SetPopupCanBeClosedFalse = new RelayCommand(o =>
|
||||
{
|
||||
var primitiveParamsVisible = Primitives.FirstOrDefault(x => x.ParameterCaptured);
|
||||
primitiveParamsVisible.PopupCanBeClosed = false;
|
||||
});
|
||||
OpenMaterialCatalog = new RelayCommand(o =>
|
||||
{
|
||||
var materialCatalogView = new MaterialCatalogView();
|
||||
materialCatalogView.ShowDialog();
|
||||
});
|
||||
OpenMaterialCatalogWithSelection = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
var materialCatalogView = new MaterialCatalogView(true, primitive);
|
||||
materialCatalogView.ShowDialog();
|
||||
});
|
||||
SetColor = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
var colorPickerView = new ColorPickerView(primitive);
|
||||
colorPickerView.ShowDialog();
|
||||
});
|
||||
SetInFrontOfAll = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
foreach (var primitiveDefinition in Primitives)
|
||||
if (primitiveDefinition.ShowedZIndex > primitive.ShowedZIndex && primitiveDefinition != primitive)
|
||||
primitiveDefinition.ShowedZIndex--;
|
||||
primitive.ShowedZIndex = PrimitivesCount;
|
||||
OnPropertyChanged(nameof(primitive.ShowedZIndex));
|
||||
});
|
||||
SetInBackOfAll = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveDefinition;
|
||||
foreach (var primitiveDefinition in Primitives)
|
||||
if (primitiveDefinition.ShowedZIndex < primitive.ShowedZIndex && primitiveDefinition != primitive)
|
||||
primitiveDefinition.ShowedZIndex++;
|
||||
primitive.ShowedZIndex = 1;
|
||||
OnPropertyChanged(nameof(primitive.ShowedZIndex));
|
||||
});
|
||||
ScaleCanvasDown = new RelayCommand(o =>
|
||||
{
|
||||
var scaleRate = 1.1;
|
||||
ScrollPanelX = PanelX;
|
||||
ScrollPanelY = PanelY;
|
||||
ScaleValue *= scaleRate;
|
||||
});
|
||||
ScaleCanvasUp = new RelayCommand(o =>
|
||||
{
|
||||
var scaleRate = 1.1;
|
||||
ScrollPanelX = PanelX;
|
||||
ScrollPanelY = PanelY;
|
||||
ScaleValue /= scaleRate;
|
||||
});
|
||||
|
||||
Primitives = new ObservableCollection<PrimitiveDefinition>();
|
||||
Rectangles = new ObservableCollection<RectangleDefinition>();
|
||||
Ellipses = new ObservableCollection<EllipseDefinition>();
|
||||
AddRectangle = new RelayCommand(o =>
|
||||
{
|
||||
var rectangle = new RectangleDefinition(60, 40, YX1, XY1);
|
||||
Rectangles.Add(rectangle);
|
||||
Primitives.Add(rectangle);
|
||||
PrimitivesCount = Primitives.Count;
|
||||
});
|
||||
AddEllipse = new RelayCommand(o =>
|
||||
{
|
||||
var ellipse = new EllipseDefinition(2000, YX1, XY1);
|
||||
Ellipses.Add(ellipse);
|
||||
Primitives.Add(ellipse);
|
||||
PrimitivesCount = Primitives.Count;
|
||||
});
|
||||
EllipsePreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
if (!(o is EllipseDefinition ellipse)) return;
|
||||
if (ellipse.Captured && !ellipse.ElementLock)
|
||||
{
|
||||
var delta = ellipse.Diameter / 2;
|
||||
|
||||
if (ellipse.ShowedEllipseX % 10 <= delta || ellipse.ShowedEllipseX % 10 >= 10 - delta)
|
||||
ellipse.ShowedEllipseX = Math.Round((PanelX - YX1) / 10) * 10;
|
||||
else
|
||||
ellipse.ShowedEllipseX = PanelX - delta - YX1;
|
||||
|
||||
if (ellipse.ShowedEllipseY % 10 <= delta || ellipse.ShowedEllipseY % 10 >= 10 - delta)
|
||||
ellipse.ShowedEllipseY = -(Math.Round((PanelY - XY1) / 10) * 10);
|
||||
else
|
||||
ellipse.ShowedEllipseY = -(PanelY - delta - XY1);
|
||||
}
|
||||
if (ellipse.ParameterCaptured)
|
||||
{
|
||||
EllipseParameterX = ellipse.ShowedEllipseX;
|
||||
EllipseParameterY = ellipse.ShowedEllipseY;
|
||||
EllipseParameterSquare = ellipse.Square;
|
||||
ParameterOpacity = ellipse.ShowedOpacity;
|
||||
ElementLock = ellipse.ElementLock;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user