From d6509246280c80b85fd6f7a47c6be0038f6a3991 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Wed, 14 Feb 2024 21:27:03 +0500 Subject: [PATCH] Visual properies of cross section were changed --- .../UI/DataContexts/PrimitiveBase.cs | 35 ++-- .../MainWindow/AxisCanvases/AxisCanvasVM.cs | 123 +++++++++++ .../AxisCanvasView.xaml} | 15 +- .../AxisCanvasView.xaml.cs} | 5 +- .../CrossSectionVisualPropertyVM.cs | 153 ++++++++++++++ .../Windows/MainWindow/CrossSectionView.xaml | 41 +++- .../MainWindow/CrossSectionViewModel.cs | 192 +++++------------- .../CrossSectionVisualPropertyVM.cs | 83 -------- .../PrimitiveViewModelLogic.cs | 78 ++++--- 9 files changed, 438 insertions(+), 287 deletions(-) create mode 100644 StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasVM.cs rename StructureHelper/Windows/MainWindow/{VisualPropertyView.xaml => AxisCanvases/AxisCanvasView.xaml} (70%) rename StructureHelper/Windows/MainWindow/{VisualPropertyView.xaml.cs => AxisCanvases/AxisCanvasView.xaml.cs} (82%) create mode 100644 StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs delete mode 100644 StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs diff --git a/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs b/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs index c0f3d50..47bfe52 100644 --- a/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs +++ b/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs @@ -2,13 +2,15 @@ using StructureHelper.Services.Primitives; using StructureHelper.Windows.MainWindow; using StructureHelper.Windows.ViewModels.NdmCrossSections; +using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.NdmCalculations.Primitives; +using System; using System.Windows.Input; using System.Windows.Media; namespace StructureHelper.Infrastructure.UI.DataContexts { - public abstract class PrimitiveBase : ViewModelBase + public abstract class PrimitiveBase : ViewModelBase, IObserver { #region Поля private IPrimitiveRepository primitiveRepository; @@ -236,12 +238,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts this.primitive = primitive; } - public void RegisterDeltas(double dx, double dy) - { - DeltaX = dx; - DeltaY = dy; - } - public CrossSectionViewModel OwnerVM { get; private set; } public double DeltaX { get; private set; } @@ -253,14 +249,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts return primitive; } - //public virtual void RefreshNdmPrimitive() - //{ - //} - - public void RefreshColor() - { - OnPropertyChanged(nameof(Color)); - } public virtual void Refresh() { OnPropertyChanged(nameof(Name)); @@ -273,5 +261,22 @@ namespace StructureHelper.Infrastructure.UI.DataContexts OnPropertyChanged(nameof(PrimitiveWidth)); OnPropertyChanged(nameof(PrimitiveHeight)); } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnNext(IRectangleShape value) + { + DeltaX = value.Width / 2d; + DeltaY = value.Height / 2d; + Refresh(); + } } } diff --git a/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasVM.cs b/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasVM.cs new file mode 100644 index 0000000..ed20331 --- /dev/null +++ b/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasVM.cs @@ -0,0 +1,123 @@ +using StructureHelper.Infrastructure; +using StructureHelper.Windows.ViewModels; +using StructureHelperCommon.Models.Shapes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using System.Windows.Media; + +namespace StructureHelper.Windows.MainWindow +{ + public class AxisCanvasVM : OkCancelViewModelBase, IRectangleShape + { + private double axisLineThickness; + private double gridLineThickness; + private double gridSize; + private double width; + private double height; + private Color xAxisColor; + private Color yAxisColor; + private Color gridColor; + + /// + /// Thickness of x-, and y- axis line + /// + public double AxisLineThickness + { + get => axisLineThickness; + set + { + axisLineThickness = value; + OnPropertyChanged(nameof(AxisLineThickness)); + } + } + /// + /// Thickness of lines of coordinate mesh + /// + public double GridLineThickness + { + get => gridLineThickness; + set + { + gridLineThickness = value; + OnPropertyChanged(nameof(GridLineThickness)); + } + } + /// + /// Size of coordinate mesh + /// + public double GridSize + { + get => gridSize; set + { + gridSize = value; + OnPropertyChanged(nameof(GridSize)); + } + } + /// + /// Width of work plane + /// + public double Width + { + get => width; set + { + width = value; + OnPropertyChanged(nameof(Width)); + } + } + /// + /// Height of work plane + /// + public double Height + { + get => height; set + { + height = value; + OnPropertyChanged(nameof(Height)); + } + } + + public double Angle { get; set; } + + public Color XAxisColor + { + get => xAxisColor; set + { + xAxisColor = value; + OnPropertyChanged(nameof(XAxisColor)); + } + } + public Color YAxisColor + { + get => yAxisColor; set + { + yAxisColor = value; + OnPropertyChanged(nameof(YAxisColor)); + } + } + + public Color GridColor + { + get => gridColor; set + { + gridColor = value; + OnPropertyChanged(nameof(GridColor)); + } + } + + public AxisCanvasVM() + { + AxisLineThickness = 2d; + GridLineThickness = 0.25d; + GridSize = 0.05d; + Width = 1.2d; + Height = 1.2d; + XAxisColor = Colors.Red; + YAxisColor = Colors.ForestGreen; + GridColor = Colors.DarkGray; + } + } +} diff --git a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml b/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasView.xaml similarity index 70% rename from StructureHelper/Windows/MainWindow/VisualPropertyView.xaml rename to StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasView.xaml index f29ca80..9e39907 100644 --- a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml +++ b/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasView.xaml @@ -1,13 +1,18 @@ - + + + + + @@ -27,8 +32,10 @@ - + - + + + diff --git a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs b/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasView.xaml.cs similarity index 82% rename from StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs rename to StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasView.xaml.cs index 029214b..66dfcbe 100644 --- a/StructureHelper/Windows/MainWindow/VisualPropertyView.xaml.cs +++ b/StructureHelper/Windows/MainWindow/AxisCanvases/AxisCanvasView.xaml.cs @@ -17,11 +17,12 @@ namespace StructureHelper.Windows.MainWindow /// /// Логика взаимодействия для VisualPropertyView.xaml /// - public partial class VisualPropertyView : Window + public partial class AxisCanvasView : Window { - public VisualPropertyView(CrossSectionVisualPropertyVM vm) + public AxisCanvasView(AxisCanvasVM vm) { InitializeComponent(); + vm.ParentWindow = this; DataContext = vm; } } diff --git a/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs b/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs new file mode 100644 index 0000000..f69ddb9 --- /dev/null +++ b/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs @@ -0,0 +1,153 @@ +using Autofac.Features.Metadata; +using StructureHelper.Infrastructure; +using StructureHelper.Infrastructure.UI.DataContexts; +using StructureHelper.Windows.ViewModels.NdmCrossSections; +using StructureHelperCommon.Models.Shapes; +using StructureHelperLogics.NdmCalculations.Primitives; +using System; +using System.Windows.Input; +using System.Windows.Media; + +namespace StructureHelper.Windows.MainWindow +{ + public class CrossSectionVisualPropertyVM : ViewModelBase + { + private double scaleValue; + private ICommand previewMouseMove; + private double delta = 0.0005; + private readonly double scaleRate = 1.1d; + + public AxisCanvasVM AxisCanvasVM { get; set; } + + /// + /// Thickness of x-, and y- axis line + /// + public double AxisLineThickness => AxisCanvasVM.AxisLineThickness / scaleValue; + + /// + /// Thickness of lines of coordinate mesh + /// + public double GridLineThickness => AxisCanvasVM.GridLineThickness / scaleValue; + + /// + /// Size of coordinate mesh + /// + public double GridSize => AxisCanvasVM.GridSize; + /// + /// Width of work plane + /// + public double Width => AxisCanvasVM.Width; + /// + /// Height of work plane + /// + public double Height => AxisCanvasVM.Height; + public double HalfOfWidth => AxisCanvasVM.Width / 2d; + public double HalfOfHeight => AxisCanvasVM.Height / 2d; + + public string CanvasViewportSize + { + get + { + string s = GridSize.ToString(); + s = s.Replace(',', '.'); + return $"0,0,{s},{s}"; + } + + } + + public double ScaleValue + { + get => Math.Round(scaleValue); + set + { + OnPropertyChanged(value, ref scaleValue); + OnPropertyChanged(nameof(AxisLineThickness)); + OnPropertyChanged(nameof(GridLineThickness)); + } + } + + public ICommand PreviewMouseMove + { + get => previewMouseMove ??= new RelayCommand(o => PreviewMouseMoveMethod(o)); + } + private void PreviewMouseMoveMethod(object o) + { + if (o is RectangleViewPrimitive rect && rect.BorderCaptured && !rect.ElementLock) + { + if (rect.PrimitiveWidth % 10d < delta || rect.PrimitiveWidth % 10d >= delta) + rect.PrimitiveWidth = Math.Round(PanelX / 10d) * 10d - rect.PrimitiveLeft + 10d; + else + rect.PrimitiveWidth = PanelX - rect.PrimitiveLeft + 10d; + + if (rect.PrimitiveHeight % 10d < delta || rect.PrimitiveHeight % 10d >= delta) + rect.PrimitiveHeight = Math.Round(PanelY / 10d) * 10d - rect.PrimitiveTop + 10d; + else + rect.PrimitiveHeight = PanelY - rect.PrimitiveTop + 10d; + } + } + + public Brush XAxisColorBrush => new SolidColorBrush(AxisCanvasVM.XAxisColor); + public Brush YAxisColorBrush => new SolidColorBrush(AxisCanvasVM.YAxisColor); + public Brush GridColorBrush => new SolidColorBrush(AxisCanvasVM.GridColor); + + internal void Refresh() + { + OnPropertyChanged(nameof(Width)); + OnPropertyChanged(nameof(Height)); + OnPropertyChanged(nameof(HalfOfWidth)); + OnPropertyChanged(nameof(HalfOfHeight)); + OnPropertyChanged(nameof(GridSize)); + OnPropertyChanged(nameof(AxisLineThickness)); + OnPropertyChanged(nameof(GridLineThickness)); + OnPropertyChanged(nameof(CanvasViewportSize)); + OnPropertyChanged(nameof(XAxisColorBrush)); + OnPropertyChanged(nameof(YAxisColorBrush)); + OnPropertyChanged(nameof(GridColorBrush)); + } + + private double panelX, panelY, scrollPanelX, scrollPanelY; + private ICommand scaleCanvasDown; + private ICommand scaleCanvasUp; + + 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); + } + + public ICommand ScaleCanvasDown => scaleCanvasDown ??= new RelayCommand(o => + { + ScrollPanelX = PanelX; + ScrollPanelY = PanelY; + ScaleValue *= scaleRate; + }); + public ICommand ScaleCanvasUp => scaleCanvasUp ??= new RelayCommand(o => + { + ScrollPanelX = PanelX; + ScrollPanelY = PanelY; + ScaleValue /= scaleRate; + }); + + public CrossSectionViewModel ParentViewModel { get; set; } + + public CrossSectionVisualPropertyVM() + { + AxisCanvasVM = new(); + } + } +} diff --git a/StructureHelper/Windows/MainWindow/CrossSectionView.xaml b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml index 79d5191..ba96004 100644 --- a/StructureHelper/Windows/MainWindow/CrossSectionView.xaml +++ b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml @@ -362,11 +362,17 @@ - - + + - + @@ -388,7 +394,7 @@ - + @@ -434,15 +440,30 @@ Viewport="{Binding CanvasViewportSize}" ViewportUnits="Absolute" Viewbox="{Binding CanvasViewportSize}" ViewboxUnits="Absolute"> - + - + - - + + @@ -466,7 +487,7 @@ - + @@ -478,7 +499,7 @@ - + diff --git a/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs b/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs index 2629b08..27c6b40 100644 --- a/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs +++ b/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs @@ -29,7 +29,6 @@ namespace StructureHelper.Windows.MainWindow { private ICrossSection section; private ICrossSectionRepository repository => section.SectionRepository; - private readonly double scaleRate = 1.1d; public CrossSectionVisualPropertyVM VisualProperty { get; private set; } @@ -44,65 +43,7 @@ namespace StructureHelper.Windows.MainWindow private CrossSectionModel Model { 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 scaleValue; - - public double ScaleValue - { - get => Math.Round(scaleValue); - set - { - OnPropertyChanged(value, ref scaleValue); - OnPropertyChanged(nameof(AxisLineThickness)); - OnPropertyChanged(nameof(GridLineThickness)); - } - } - - public double AxisLineThickness - { - get => VisualProperty.AxisLineThickness / scaleValue; - } - - public double GridLineThickness - { - get => VisualProperty.GridLineThickness / scaleValue; - } - - public string CanvasViewportSize - { - get - { - string s = VisualProperty.GridSize.ToString(); - s = s.Replace(',', '.'); - return $"0,0,{s},{s}"; - } - - } - - public double GridSize => VisualProperty.GridSize; - public ObservableCollection HeadMaterials { get @@ -114,24 +55,7 @@ namespace StructureHelper.Windows.MainWindow } return collection; } - } - - /// - /// Right edge of work plane, coordinate X - /// - public double RightLimitX => VisualProperty.WorkPlainWidth; - /// - /// Bottom edge of work plane Y - /// - public double BottomLimitY => VisualProperty.WorkPlainHeight; - /// - /// Middle of coordinate X - /// - public double MiddleLimitX => VisualProperty.WorkPlainWidth / 2d; - /// - /// Middle of coordinate Y - /// - public double MiddleLimitY => VisualProperty.WorkPlainHeight / 2d; + } public ICommand Calculate { get; } public ICommand EditCalculationPropertyCommand { get; } @@ -153,7 +77,7 @@ namespace StructureHelper.Windows.MainWindow public ICommand LeftButtonDown { get; } public ICommand LeftButtonUp { get; } public ICommand MovePrimitiveToGravityCenterCommand { get; } - public ICommand PreviewMouseMove { get; } + public ICommand ClearSelection { get; } public ICommand OpenMaterialCatalog { get; } public ICommand OpenMaterialCatalogWithSelection { get; } @@ -161,8 +85,7 @@ namespace StructureHelper.Windows.MainWindow public ICommand SetColor { get; } public ICommand SetInFrontOfAll { get; } public ICommand SetInBackOfAll { get; } - public ICommand ScaleCanvasDown { get; } - public ICommand ScaleCanvasUp { get; } + public ICommand SetPopupCanBeClosedTrue { get; } public ICommand SetPopupCanBeClosedFalse { get; } public RelayCommand ShowVisualProperty @@ -172,17 +95,12 @@ namespace StructureHelper.Windows.MainWindow return showVisualProperty ?? (showVisualProperty = new RelayCommand(o=> { - var wnd = new VisualPropertyView(VisualProperty); + var wnd = new AxisCanvasView(VisualProperty.AxisCanvasVM); wnd.ShowDialog(); - OnPropertyChanged(nameof(AxisLineThickness)); - OnPropertyChanged(nameof(CanvasViewportSize)); - OnPropertyChanged(nameof(GridSize)); - OnPropertyChanged(nameof(RightLimitX)); - OnPropertyChanged(nameof(BottomLimitY)); - OnPropertyChanged(nameof(MiddleLimitX)); - OnPropertyChanged(nameof(MiddleLimitY)); - PrimitiveLogic.WorkPlaneWidth = VisualProperty.WorkPlainWidth; - PrimitiveLogic.WorkPlaneHeight = VisualProperty.WorkPlainHeight; + if (wnd.DialogResult == false) { return; } + VisualProperty.Refresh(); + PrimitiveLogic.Width = VisualProperty.Width; + PrimitiveLogic.Height = VisualProperty.Height; PrimitiveLogic.Refresh(); })); } @@ -192,36 +110,37 @@ namespace StructureHelper.Windows.MainWindow { get { - return selectPrimitive ?? - (selectPrimitive = new RelayCommand(obj=> + return selectPrimitive ??= new RelayCommand(obj=> { if (obj is PrimitiveBase) { SelectedPrimitive = obj as PrimitiveBase; } - })); + }); } } - private double delta = 0.0005; private RelayCommand showVisualProperty; private RelayCommand selectPrimitive; public CrossSectionViewModel(CrossSectionModel model) { - VisualProperty = new CrossSectionVisualPropertyVM(); + VisualProperty = new CrossSectionVisualPropertyVM() + { + ScaleValue = 500d, + ParentViewModel = this + }; Model = model; section = model.Section; CombinationsLogic = new ActionsViewModel(repository); MaterialsLogic = new MaterialsViewModel(repository); - MaterialsLogic.AfterItemsEdit += afterMaterialEdit; + MaterialsLogic.AfterItemsEdit += AfterMaterialEdit; CalculatorsLogic = new AnalysisVewModelLogic(repository); PrimitiveLogic = new PrimitiveViewModelLogic(section) { - WorkPlaneWidth = VisualProperty.WorkPlainWidth, - WorkPlaneHeight = VisualProperty.WorkPlainHeight + Width = VisualProperty.Width, + Height = VisualProperty.Height }; - scaleValue = 500d; LeftButtonUp = new RelayCommand(o => { @@ -231,35 +150,6 @@ namespace StructureHelper.Windows.MainWindow { if (o is RectangleViewPrimitive rect) rect.BorderCaptured = true; }); - PreviewMouseMove = new RelayCommand(o => - { - if (o is RectangleViewPrimitive rect && rect.BorderCaptured && !rect.ElementLock) - { - if (rect.PrimitiveWidth % 10d < delta || rect.PrimitiveWidth % 10d >= delta) - rect.PrimitiveWidth = Math.Round(PanelX / 10d) * 10d - rect.PrimitiveLeft + 10d; - else - rect.PrimitiveWidth = PanelX - rect.PrimitiveLeft + 10d; - - if (rect.PrimitiveHeight % 10d < delta || rect.PrimitiveHeight % 10d >= delta) - rect.PrimitiveHeight = Math.Round(PanelY / 10d) * 10d - rect.PrimitiveTop + 10d; - else - rect.PrimitiveHeight = PanelY - rect.PrimitiveTop + 10d; - } - }); - - ScaleCanvasDown = new RelayCommand(o => - { - ScrollPanelX = PanelX; - ScrollPanelY = PanelY; - ScaleValue *= scaleRate; - }); - - ScaleCanvasUp = new RelayCommand(o => - { - ScrollPanelX = PanelX; - ScrollPanelY = PanelY; - ScaleValue /= scaleRate; - }); AddBeamCase = new RelayCommand(o => { @@ -301,17 +191,14 @@ namespace StructureHelper.Windows.MainWindow SetPopupCanBeClosedFalse = new RelayCommand(o => { - if (!(o is PrimitiveBase primitive)) return; + if (o is not PrimitiveBase primitive) return; primitive.PopupCanBeClosed = false; }); } - private void afterMaterialEdit(SelectItemVM sender, CRUDVMEventArgs e) + private void AfterMaterialEdit(SelectItemVM sender, CRUDVMEventArgs e) { - foreach (var primitive in PrimitiveLogic.Items) - { - primitive.RefreshColor(); - } + PrimitiveLogic.Refresh(); } private bool CheckMaterials() @@ -338,12 +225,26 @@ namespace StructureHelper.Windows.MainWindow } private IEnumerable GetColumnCasePrimitives() { - var template = new RectangleBeamTemplate(0.5d, 0.5d) { CoverGap = 0.05, WidthCount = 3, HeightCount = 3, TopDiameter = 0.025d, BottomDiameter = 0.025d }; + var template = new RectangleBeamTemplate(0.5d, 0.5d) + { + CoverGap = 0.05, + WidthCount = 3, + HeightCount = 3, + TopDiameter = 0.025d, + BottomDiameter = 0.025d + }; return GetCasePrimitives(template); } private IEnumerable GetSlabCasePrimitives() { - var template = new RectangleBeamTemplate(1d, 0.2d) { CoverGap = 0.04, WidthCount = 5, HeightCount = 2, TopDiameter = 0.012d, BottomDiameter = 0.012d }; + var template = new RectangleBeamTemplate(1d, 0.2d) + { + CoverGap = 0.04, + WidthCount = 5, + HeightCount = 2, + TopDiameter = 0.012d, + BottomDiameter = 0.012d + }; return GetCasePrimitives(template); } @@ -363,11 +264,15 @@ namespace StructureHelper.Windows.MainWindow geometryLogic = new CircleGeometryLogic(circleTemplate); wnd = new CircleView(circleTemplate); } - else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"Was: {nameof(template)}"); } - wnd.ShowDialog(); - if (wnd.DialogResult == true) + else { - + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(template)); + } + wnd.ShowDialog(); + if (wnd.DialogResult == false) + { + return new List(); + } var newSection = new SectionTemplate(geometryLogic).GetCrossSection(); var newRepository = newSection.SectionRepository; repository.HeadMaterials.AddRange(newRepository.HeadMaterials); @@ -378,10 +283,6 @@ namespace StructureHelper.Windows.MainWindow CombinationsLogic.AddItems(newRepository.ForceActions); CalculatorsLogic.AddItems(newRepository.CalculatorsList); var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives); - foreach (var item in primitives) - { - item.RegisterDeltas(VisualProperty.WorkPlainWidth / 2, VisualProperty.WorkPlainHeight / 2); - } PrimitiveLogic.Refresh(); foreach (var item in newRepository.HeadMaterials) { @@ -392,8 +293,7 @@ namespace StructureHelper.Windows.MainWindow GlobalRepository.Actions.Create(item); } return primitives; - } - return new List(); + } } } \ No newline at end of file diff --git a/StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs b/StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs deleted file mode 100644 index b5d10d6..0000000 --- a/StructureHelper/Windows/MainWindow/CrossSectionVisualPropertyVM.cs +++ /dev/null @@ -1,83 +0,0 @@ -using StructureHelper.Infrastructure; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StructureHelper.Windows.MainWindow -{ - public class CrossSectionVisualPropertyVM : ViewModelBase - { - private double axisLineThickness; - private double gridLineThickness; - private double gridSize; - private double workPlainWidth; - private double workPlainHeight; - - /// - /// Thickness of x-, and y- axis line - /// - public double AxisLineThickness - { - get => axisLineThickness; set - { - axisLineThickness = value; - OnPropertyChanged(nameof(AxisLineThickness)); - } - } - /// - /// Thickness of lines of coordinate mesh - /// - public double GridLineThickness - { - get => gridLineThickness; set - { - gridLineThickness = value; - OnPropertyChanged(nameof(GridLineThickness)); - } - } - /// - /// Size of coordinate mesh - /// - public double GridSize - { - get => gridSize; set - { - gridSize = value; - OnPropertyChanged(nameof(GridSize)); - } - } - /// - /// Width of work plane - /// - public double WorkPlainWidth - { - get => workPlainWidth; set - { - workPlainWidth = value; - OnPropertyChanged(nameof(WorkPlainWidth)); - } - } - /// - /// Height of work plane - /// - public double WorkPlainHeight - { - get => workPlainHeight; set - { - workPlainHeight = value; - OnPropertyChanged(nameof(WorkPlainHeight)); - } - } - - public CrossSectionVisualPropertyVM() - { - AxisLineThickness = 2d; - GridLineThickness = 0.25d; - GridSize = 0.05d; - WorkPlainWidth = 1.2d; - WorkPlainHeight = 1.2d; - } - } -} diff --git a/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs b/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs index 1fe12a3..790fb4a 100644 --- a/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs +++ b/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs @@ -1,13 +1,21 @@ using StructureHelper.Infrastructure; using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.UI.DataContexts; +using StructureHelper.Services.Settings; using StructureHelper.Windows.PrimitiveProperiesWindow; +using StructureHelper.Windows.PrimitiveTemplates.RCs.Beams; +using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam; using StructureHelper.Windows.Services; using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models.Materials; +using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.Primitives; +using StructureHelperLogics.Models.Templates.CrossSections.RCs; +using StructureHelperLogics.Models.Templates.RCs; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Primitives; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -19,7 +27,7 @@ using System.Windows.Input; namespace StructureHelper.Windows.ViewModels.NdmCrossSections { - public class PrimitiveViewModelLogic : ViewModelBase, ICRUDViewModel + public class PrimitiveViewModelLogic : ViewModelBase, ICRUDViewModel, IRectangleShape, IObservable { private ICrossSection section; private ICrossSectionRepository repository => section.SectionRepository; @@ -31,8 +39,9 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections private ICommand setToBack; private ICommand copyToCommand; - public double WorkPlaneWidth { get; set; } - public double WorkPlaneHeight { get; set; } + + public double Width { get; set; } + public double Height { get; set; } public PrimitiveBase SelectedItem { get; set; } @@ -42,14 +51,12 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { get { - return addCommand ?? - ( - addCommand = new RelayCommand(o => + return addCommand ??= new RelayCommand(o => { - if (!(o is PrimitiveType primitiveType)) return; + if (o is not PrimitiveType primitiveType) return; AddPrimitive(primitiveType); } - )); + ); } } @@ -96,7 +103,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections viewPrimitive = new CircleViewPrimitive(primitive); } else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); } - viewPrimitive.RegisterDeltas(WorkPlaneWidth / 2, WorkPlaneHeight / 2); + viewPrimitive.OnNext(this); repository.Primitives.Add(ndmPrimitive); ndmPrimitive.CrossSection = section; Items.Add(viewPrimitive); @@ -181,12 +188,10 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { get { - return copyCommand ?? - ( - copyCommand = new RelayCommand( + return copyCommand ??= new RelayCommand( o => CopySelectedItem(SelectedItem.GetNdmPrimitive()), o => SelectedItem != null - )); + ); } } @@ -224,8 +229,14 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections newPrimitive.Name += " copy"; repository.Primitives.Add(newPrimitive); PrimitiveBase primitiveBase; - if (newPrimitive is IRectanglePrimitive) { primitiveBase = new RectangleViewPrimitive(newPrimitive as IRectanglePrimitive); } - else if (newPrimitive is ICirclePrimitive) { primitiveBase = new CircleViewPrimitive(newPrimitive as ICirclePrimitive); } + if (newPrimitive is IRectanglePrimitive) + { + primitiveBase = new RectangleViewPrimitive(newPrimitive as IRectanglePrimitive); + } + else if (newPrimitive is ICirclePrimitive) + { + primitiveBase = new CircleViewPrimitive(newPrimitive as ICirclePrimitive); + } else if (newPrimitive is IPointPrimitive) { if (newPrimitive is RebarPrimitive) @@ -236,10 +247,13 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { primitiveBase = new PointViewPrimitive(newPrimitive as IPointPrimitive); } - + } - else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); - primitiveBase.RegisterDeltas(WorkPlaneWidth / 2, WorkPlaneHeight / 2); + else + { + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); + } + primitiveBase.OnNext(this); Items.Add(primitiveBase); OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(PrimitivesCount)); @@ -252,13 +266,12 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { get { - return setToFront ?? - (setToFront = new RelayCommand(o=> + return setToFront ??= new RelayCommand(o=> { int maxZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Max(); SelectedItem.ZIndex = maxZIndex + 1; },o => CheckMaxIndex() - )); + ); } } private bool CheckMaxIndex() @@ -281,16 +294,17 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { get { - return setToBack ?? - (setToBack = new RelayCommand(o => + return setToBack ??= new RelayCommand(o => { int minZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Min(); SelectedItem.ZIndex = minZIndex - 1; }, o => CheckMinIndex() - )); + ); } } + public double Angle { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public void AddItems(IEnumerable items) { foreach (var item in items) @@ -300,13 +314,22 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections } public void Refresh() + { + NotifyObservers(); + OnPropertyChanged(nameof(PrimitivesCount)); + } + + public void NotifyObservers() { foreach (var item in Items) { - item.RegisterDeltas(WorkPlaneWidth / 2, WorkPlaneHeight / 2); - item.Refresh(); + item.OnNext(this); } - OnPropertyChanged(nameof(PrimitivesCount)); + } + + public IDisposable Subscribe(IObserver observer) + { + throw new NotImplementedException(); } public PrimitiveViewModelLogic(ICrossSection section) @@ -315,5 +338,6 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections Items = new ObservableCollection(); AddItems(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(this.repository.Primitives)); } + } }