From 1cf54603bc762a85a0c3d402251db83482a244a8 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Sun, 30 Oct 2022 22:20:58 +0500 Subject: [PATCH] Head material was added --- .../Converters/Common/InvertBoolConverter.cs | 33 +++++++++++++++ .../UI/DataContexts/PrimitiveBase.cs | 37 +++++++++++++++-- .../UI/DataTemplates/RectangleTemplate.xaml | 5 ++- Infrastructure/UI/Styles.xaml | 6 ++- Models/Materials/HeadMaterial.cs | 27 ++++++++++++ Models/Materials/IHeadMaterial.cs | 16 ++++++++ StructureHelper.csproj | 11 +++++ .../ColorPickerWindow/ColorPickerView.xaml | 6 ++- .../ColorPickerWindow/ColorPickerViewModel.cs | 16 ++++---- Windows/MainWindow/MainModel.cs | 3 ++ Windows/MainWindow/MainView.xaml | 26 +++++++++++- Windows/MainWindow/MainViewModel.cs | 27 +++++++++--- .../Materials/HeadMaterialsView.xaml | 41 +++++++++++++++++++ .../Materials/HeadMaterialsView.xaml.cs | 40 ++++++++++++++++++ .../PrimitivePropertiesView.xaml | 20 +++++++-- .../PrimitivePropertiesView.xaml.cs | 5 +++ .../Materials/HeadMaterialsViewModel.cs | 36 ++++++++++++++++ .../PrimitivePropertiesViewModel.cs | 39 +++++++++++++++--- 18 files changed, 363 insertions(+), 31 deletions(-) create mode 100644 Infrastructure/UI/Converters/Common/InvertBoolConverter.cs create mode 100644 Models/Materials/HeadMaterial.cs create mode 100644 Models/Materials/IHeadMaterial.cs create mode 100644 Windows/MainWindow/Materials/HeadMaterialsView.xaml create mode 100644 Windows/MainWindow/Materials/HeadMaterialsView.xaml.cs create mode 100644 Windows/ViewModels/Materials/HeadMaterialsViewModel.cs diff --git a/Infrastructure/UI/Converters/Common/InvertBoolConverter.cs b/Infrastructure/UI/Converters/Common/InvertBoolConverter.cs new file mode 100644 index 0000000..3dc8b18 --- /dev/null +++ b/Infrastructure/UI/Converters/Common/InvertBoolConverter.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace StructureHelper.Infrastructure.UI.Converters.Common +{ + [ValueConversion(typeof(bool), typeof(bool))] + public class InvertBoolConverter : IValueConverter + { + public InvertBoolConverter() + { + } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value is bool) + { + return !((bool)value); + } + + return true; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return Convert(value, targetType, parameter, culture); + } + } +} diff --git a/Infrastructure/UI/DataContexts/PrimitiveBase.cs b/Infrastructure/UI/DataContexts/PrimitiveBase.cs index 6607e9b..03bb9c5 100644 --- a/Infrastructure/UI/DataContexts/PrimitiveBase.cs +++ b/Infrastructure/UI/DataContexts/PrimitiveBase.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Windows; +using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using StructureHelper.Infrastructure.Enums; @@ -25,6 +27,9 @@ namespace StructureHelper.Infrastructure.UI.DataContexts private double maxElementSize; private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured; private Brush brush; + private bool setMaterialColor; + private Color color; + private IHeadMaterial headMaterial; private MaterialDefinitionBase material; private double prestrain_kx, prestrain_ky, prestrain_epsz; private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight, showedX, showedY; @@ -91,6 +96,30 @@ namespace StructureHelper.Infrastructure.UI.DataContexts OnPropertyChanged(value, ref centerY); } } + + public IHeadMaterial HeadMaterial + { + get => headMaterial; + set + { + OnPropertyChanged(value, ref headMaterial); + } + } + + public bool SetMaterialColor + { + get => setMaterialColor; + set { OnPropertyChanged(value, ref setMaterialColor);} + } + public Color Color + { + get => setMaterialColor? headMaterial.Color :color; + set + { + SetMaterialColor = false; + OnPropertyChanged(value, ref color); + } + } public int MinElementDivision { get => minElementDivision; @@ -119,8 +148,8 @@ namespace StructureHelper.Infrastructure.UI.DataContexts } public Brush Brush { - get => brush; - set => OnPropertyChanged(value, ref brush); + get => new SolidColorBrush(Color); + set { } } public MaterialDefinitionBase Material { @@ -259,8 +288,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts var randomR = new Random(new Random((int)DateTime.Now.Ticks % 1000).Next(50)).Next(0, 255); var randomG = new Random(new Random((int)DateTime.Now.Ticks % 200).Next(100, 200)).Next(0, 255); var randomB = new Random(new Random((int)DateTime.Now.Ticks % 50).Next(500, 1000)).Next(0, 255); - var color = Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB); - Brush = new SolidColorBrush(color); + color = Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB); PrimitiveLeftButtonUp = new RelayCommand(o => Captured = false); PrimitiveLeftButtonDown = new RelayCommand(o => Captured = true); @@ -273,6 +301,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts }); OwnerVm = ownerVM; + SetMaterialColor = true; } protected readonly MainViewModel OwnerVm; diff --git a/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml b/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml index ce24c9f..7b4053c 100644 --- a/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml +++ b/Infrastructure/UI/DataTemplates/RectangleTemplate.xaml @@ -29,7 +29,7 @@ --> - + @@ -41,6 +41,9 @@ + diff --git a/Infrastructure/UI/Styles.xaml b/Infrastructure/UI/Styles.xaml index d282a76..7af6e64 100644 --- a/Infrastructure/UI/Styles.xaml +++ b/Infrastructure/UI/Styles.xaml @@ -12,7 +12,11 @@