From 35fccfaa119578fae9674ff193b9b80de688591a Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Sun, 14 Sep 2025 19:47:23 +0500 Subject: [PATCH] Add polygon shape --- DataAccess/DataAccess.csproj | 2 +- FieldVisualizer/FieldVisualizer.csproj | 2 +- FiledVisualzerDemo/FieldVisualzerDemo.csproj | 2 +- StructureHelper/App.xaml | 1 + .../Infrastructure/Enums/PrimitiveType.cs | 9 +- .../UI/DataContexts/CircleViewPrimitive.cs | 10 +- .../Factories/ViewPrimitiveFactory.cs | 13 -- .../UI/DataContexts/PointViewPrimitive.cs | 14 +- .../UI/DataContexts/PrimitiveOperations.cs | 10 +- .../UI/DataContexts/ShapeViewPrimitive.cs | 59 ++++++++ .../UI/DataTemplates/PolygonTemplate.xaml | 23 +++ .../UI/DataTemplates/PolygonTemplate.xaml.cs | 28 ++++ .../PolygonShapePrimitive.cs | 44 ++++++ .../UI/Resources/ButtonStyles.xaml | 69 +++++++++ .../UI/Resources/ShapeEditTemplates.xaml | 4 - .../UI/Resources/ShapeTemplates.xaml | 20 +++ StructureHelper/Infrastructure/UI/Styles.xaml | 7 + StructureHelper/StructureHelper.csproj | 2 +- StructureHelper/StructureHelper.csproj.user | 6 + .../CrossSections}/AnalysisViewModelLogic.cs | 0 .../{ => CrossSections}/CrossSectionView.xaml | 13 ++ .../CrossSectionView.xaml.cs | 0 .../CrossSectionViewModel.cs | 0 .../ForceCombinationViewModelLogic.cs | 0 .../CrossSections}/HasDivisionViewModel.cs | 0 .../CrossSections}/HelpLogic.cs | 0 .../ICalculatorsViewModelLogic.cs | 0 .../IForceCombinationViewModelLogic.cs | 0 .../CrossSections}/PrimitiveViewModelLogic.cs | 100 +++++++++---- .../CrossSections}/SecondOrderViewModel.cs | 0 .../PrimitivePropertiesView.xaml | 10 ++ .../PrimitivePropertiesView.xaml.cs | 14 +- .../PrimitivePropertiesViewModel.cs | 36 ++++- ...onShapeToGraphicPrimitveConvertStrategy.cs | 29 ++++ .../Windows/Shapes/Point2DViewModel.cs | 55 ++++++++ .../Windows/Shapes/PolygonShapeView.xaml | 111 +++++++++++++++ .../Windows/Shapes/PolygonShapeView.xaml.cs | 19 +++ .../Windows/Shapes/PolygonShapeViewModel.cs | 131 ++++++++++++++++++ .../Windows/Shapes/VertexViewModel.cs | 20 +++ .../Windows/UserControls/WorkPlane.xaml | 7 + .../WorkPlanes/PrimitiveTemplateSelector.cs | 2 + .../WorkPlanes/WorkPlaneRoot.xaml | 1 + .../Settings/ProgramSetting.cs | 3 +- .../Shapes/Logics/PolygonGeometryUtils.cs | 12 ++ ...ategy.cs => PolygonShapeUpdateStrategy.cs} | 2 +- .../Shapes/Logics/ShapeUpdateStrategy.cs | 19 ++- .../Models/Shapes/PolygonShape.cs | 3 +- StructureHelperCommon/Models/Shapes/Vertex.cs | 11 +- .../StructureHelperCommon.csproj | 4 +- .../Logics/NdmPrimitiveUpdateStrategy.cs | 4 + .../RectanglePrimitiveUpdateStrategy.cs | 6 - .../Logics/ShapeNDMPrimitiveUpdateStrategy.cs | 15 +- .../Primitives/RectangleNdmPrimitive.cs | 3 +- .../Primitives/ShapeNdmPrimitive.cs | 21 ++- .../StructureHelperLogics.csproj | 2 +- .../StructureHelperTests.csproj | 2 +- 56 files changed, 867 insertions(+), 113 deletions(-) delete mode 100644 StructureHelper/Infrastructure/UI/DataContexts/Factories/ViewPrimitiveFactory.cs create mode 100644 StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs create mode 100644 StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml create mode 100644 StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml.cs create mode 100644 StructureHelper/Infrastructure/UI/GraphicalPrimitives/PolygonShapePrimitive.cs create mode 100644 StructureHelper/Infrastructure/UI/Resources/ShapeTemplates.xaml rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/AnalysisViewModelLogic.cs (100%) rename StructureHelper/Windows/MainWindow/{ => CrossSections}/CrossSectionView.xaml (96%) rename StructureHelper/Windows/MainWindow/{ => CrossSections}/CrossSectionView.xaml.cs (100%) rename StructureHelper/Windows/MainWindow/{ => CrossSections}/CrossSectionViewModel.cs (100%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/ForceCombinationViewModelLogic.cs (100%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/HasDivisionViewModel.cs (100%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/HelpLogic.cs (100%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/ICalculatorsViewModelLogic.cs (100%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/IForceCombinationViewModelLogic.cs (100%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/PrimitiveViewModelLogic.cs (80%) rename StructureHelper/Windows/{ViewModels/NdmCrossSections => MainWindow/CrossSections}/SecondOrderViewModel.cs (100%) rename StructureHelper/Windows/{ViewModels/PrimitiveProperties => PrimitivePropertiesWindow}/PrimitivePropertiesViewModel.cs (90%) create mode 100644 StructureHelper/Windows/Shapes/Logics/PolygonShapeToGraphicPrimitveConvertStrategy.cs create mode 100644 StructureHelper/Windows/Shapes/Point2DViewModel.cs create mode 100644 StructureHelper/Windows/Shapes/PolygonShapeView.xaml create mode 100644 StructureHelper/Windows/Shapes/PolygonShapeView.xaml.cs create mode 100644 StructureHelper/Windows/Shapes/PolygonShapeViewModel.cs create mode 100644 StructureHelper/Windows/Shapes/VertexViewModel.cs rename StructureHelperCommon/Models/Shapes/Logics/{PolygonUpdateStrategy.cs => PolygonShapeUpdateStrategy.cs} (94%) diff --git a/DataAccess/DataAccess.csproj b/DataAccess/DataAccess.csproj index 99c31d7..10399b9 100644 --- a/DataAccess/DataAccess.csproj +++ b/DataAccess/DataAccess.csproj @@ -1,7 +1,7 @@  - net6.0-windows + net8.0-windows7.0 enable enable diff --git a/FieldVisualizer/FieldVisualizer.csproj b/FieldVisualizer/FieldVisualizer.csproj index dc9183b..9864ca7 100644 --- a/FieldVisualizer/FieldVisualizer.csproj +++ b/FieldVisualizer/FieldVisualizer.csproj @@ -1,7 +1,7 @@ - net6.0-windows7.0 + net8.0-windows7.0 enable true disable diff --git a/FiledVisualzerDemo/FieldVisualzerDemo.csproj b/FiledVisualzerDemo/FieldVisualzerDemo.csproj index b5219a8..79d4d64 100644 --- a/FiledVisualzerDemo/FieldVisualzerDemo.csproj +++ b/FiledVisualzerDemo/FieldVisualzerDemo.csproj @@ -2,7 +2,7 @@ WinExe - net6.0-windows7.0 + net8.0-windows7.0 enable true disable diff --git a/StructureHelper/App.xaml b/StructureHelper/App.xaml index 5ba44ad..64fd224 100644 --- a/StructureHelper/App.xaml +++ b/StructureHelper/App.xaml @@ -24,6 +24,7 @@ + diff --git a/StructureHelper/Infrastructure/Enums/PrimitiveType.cs b/StructureHelper/Infrastructure/Enums/PrimitiveType.cs index fd86219..841adb7 100644 --- a/StructureHelper/Infrastructure/Enums/PrimitiveType.cs +++ b/StructureHelper/Infrastructure/Enums/PrimitiveType.cs @@ -2,9 +2,10 @@ { public enum PrimitiveType { - Point, - Rectangle, - Circle, - Reinforcement + Point = 0, + Rectangle = 1, + Circle = 2, + Reinforcement = 3, + Polygon = 4 } } \ No newline at end of file diff --git a/StructureHelper/Infrastructure/UI/DataContexts/CircleViewPrimitive.cs b/StructureHelper/Infrastructure/UI/DataContexts/CircleViewPrimitive.cs index 9923862..06dfd3b 100644 --- a/StructureHelper/Infrastructure/UI/DataContexts/CircleViewPrimitive.cs +++ b/StructureHelper/Infrastructure/UI/DataContexts/CircleViewPrimitive.cs @@ -29,15 +29,9 @@ namespace StructureHelper.Infrastructure.UI.DataContexts public double PrimitiveLeft => DeltaX - Diameter / 2d; public double PrimitiveTop => DeltaY - Diameter / 2d; - public CircleViewPrimitive(INdmPrimitive primitive) : base(primitive) + public CircleViewPrimitive(IEllipseNdmPrimitive primitive) : base(primitive) { - if (primitive is not IEllipseNdmPrimitive) - { - throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $"\nExpected: {nameof(IEllipseNdmPrimitive)}, But was: {nameof(primitive)}"); - } - var circle = primitive as IEllipseNdmPrimitive; - this.primitive = circle; - DivisionViewModel = new HasDivisionViewModel(circle.DivisionSize); + DivisionViewModel = new HasDivisionViewModel(primitive.DivisionSize); } public override INdmPrimitive GetNdmPrimitive() diff --git a/StructureHelper/Infrastructure/UI/DataContexts/Factories/ViewPrimitiveFactory.cs b/StructureHelper/Infrastructure/UI/DataContexts/Factories/ViewPrimitiveFactory.cs deleted file mode 100644 index 82d9ada..0000000 --- a/StructureHelper/Infrastructure/UI/DataContexts/Factories/ViewPrimitiveFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StructureHelper.Infrastructure.UI.DataContexts -{ - internal static class ViewPrimitiveFactory - { - // to do public static PrimitiveBase GetViewPrimitive() { } - } -} diff --git a/StructureHelper/Infrastructure/UI/DataContexts/PointViewPrimitive.cs b/StructureHelper/Infrastructure/UI/DataContexts/PointViewPrimitive.cs index d539543..b423999 100644 --- a/StructureHelper/Infrastructure/UI/DataContexts/PointViewPrimitive.cs +++ b/StructureHelper/Infrastructure/UI/DataContexts/PointViewPrimitive.cs @@ -1,11 +1,5 @@ -using System; -using StructureHelper.Infrastructure.Enums; -using StructureHelper.UnitSystem.Systems; -using StructureHelper.Windows.MainWindow; -using StructureHelperLogics.Models.Primitives; -using StructureHelperLogics.Models.Materials; -using StructureHelperCommon.Models.Shapes; -using StructureHelperLogics.NdmCalculations.Primitives; +using StructureHelperLogics.NdmCalculations.Primitives; +using System; namespace StructureHelper.Infrastructure.UI.DataContexts { @@ -38,10 +32,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts public double Diameter { get => Math.Sqrt(primitive.Area / Math.PI) * 2; } - public override INdmPrimitive GetNdmPrimitive() - { - return primitive; - } public override void Refresh() { RefreshPlacement(); diff --git a/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveOperations.cs b/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveOperations.cs index 436961b..f30b7fe 100644 --- a/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveOperations.cs +++ b/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveOperations.cs @@ -25,16 +25,18 @@ namespace StructureHelper.Infrastructure.UI.DataContexts public static PrimitiveBase ConvertNdmPrimitiveToPrimitiveBase(INdmPrimitive primitive) { PrimitiveBase viewItem; - if (primitive is IRectangleNdmPrimitive) + if (primitive is IRectangleNdmPrimitive rect) { - var rect = primitive as IRectangleNdmPrimitive; viewItem = new RectangleViewPrimitive(rect); } - else if (primitive is IEllipseNdmPrimitive) + else if (primitive is IEllipseNdmPrimitive circle) { - var circle = primitive as IEllipseNdmPrimitive; viewItem = new CircleViewPrimitive(circle); } + else if (primitive is IShapeNDMPrimitive shapeNDMPrimitive) + { + viewItem = new ShapeViewPrimitive(shapeNDMPrimitive); + } else if (primitive is IPointNdmPrimitive & primitive is not RebarNdmPrimitive) { var point = primitive as IPointNdmPrimitive; diff --git a/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs b/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs new file mode 100644 index 0000000..7e4f289 --- /dev/null +++ b/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs @@ -0,0 +1,59 @@ +using FieldVisualizer.Entities.Values.Primitives; +using StructureHelper.Infrastructure.Enums; +using StructureHelper.Windows.ViewModels.NdmCrossSections; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models.Shapes; +using StructureHelperLogics.NdmCalculations.Primitives; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Windows.Media; + +namespace StructureHelper.Infrastructure.UI.DataContexts +{ + public class ShapeViewPrimitive : PrimitiveBase + { + IShapeNDMPrimitive shapeNDMPrimitive; + + public PathGeometry PathGeometry { get; set; } + + public ShapeViewPrimitive(IShapeNDMPrimitive shapeNDMPrimitive) : base(shapeNDMPrimitive) + { + this.shapeNDMPrimitive = shapeNDMPrimitive; + DivisionViewModel = new HasDivisionViewModel(this.shapeNDMPrimitive.DivisionSize); + UpdatePath(); + } + + public override void Refresh() + { + UpdatePath(); + OnPropertyChanged(nameof(CenterX)); + OnPropertyChanged(nameof(CenterY)); + OnPropertyChanged(nameof(PathGeometry)); + base.Refresh(); + } + + private void UpdatePath() + { + var shape = shapeNDMPrimitive.Shape; + if (shape is not IPolygonShape polygon) + { + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(shape)); + } + var points = polygon.Vertices.Select(x => x.Point).ToList(); + if (points.Count == 0) return; + + IPoint2D StartPoint = points[0]; + System.Windows.Point systemPoint = GetSystemPoint(StartPoint); + var figure = new PathFigure { StartPoint = systemPoint }; + for (int i = 1; i < points.Count; i++) + figure.Segments.Add(new LineSegment(GetSystemPoint(points[i]), true)); + figure.IsClosed = true; + PathGeometry = new PathGeometry(new[] { figure }); + } + + private System.Windows.Point GetSystemPoint(IPoint2D helperPoint) + { + return new(DeltaX + shapeNDMPrimitive.Center.X + helperPoint.X, DeltaY - shapeNDMPrimitive.Center.Y - helperPoint.Y); + } + } +} diff --git a/StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml b/StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml new file mode 100644 index 0000000..80858cb --- /dev/null +++ b/StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + diff --git a/StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml.cs b/StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml.cs new file mode 100644 index 0000000..70b450c --- /dev/null +++ b/StructureHelper/Infrastructure/UI/DataTemplates/PolygonTemplate.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace StructureHelper.Infrastructure.UI.DataTemplates +{ + /// + /// Логика взаимодействия для PolygonTemplate.xaml + /// + public partial class PolygonTemplate : UserControl + { + public PolygonTemplate() + { + InitializeComponent(); + } + } +} diff --git a/StructureHelper/Infrastructure/UI/GraphicalPrimitives/PolygonShapePrimitive.cs b/StructureHelper/Infrastructure/UI/GraphicalPrimitives/PolygonShapePrimitive.cs new file mode 100644 index 0000000..01b5cc1 --- /dev/null +++ b/StructureHelper/Infrastructure/UI/GraphicalPrimitives/PolygonShapePrimitive.cs @@ -0,0 +1,44 @@ +using StructureHelper.Windows.Shapes; +using StructureHelper.Windows.UserControls; +using StructureHelperCommon.Models.Shapes; +using StructureHelperLogics.NdmCalculations.Primitives; +using System; +using System.Linq; +using System.Windows.Media; +using System.Windows.Shapes; +using PrimitiveVisualProperty = StructureHelperCommon.Models.VisualProperties.PrimitiveVisualProperty; + +namespace StructureHelper.Infrastructure.UI.GraphicalPrimitives +{ + public class PolygonShapePrimitive : IGraphicalPrimitive + { + private readonly PolygonShapeViewModel polygonShapeViewModel; + public string Name => "Polygon"; + public PathGeometry PathGeometry { get; set; } + public PrimitiveVisualPropertyViewModel VisualProperty { get; } = new(new PrimitiveVisualProperty(Guid.Empty)); + + public PolygonShapePrimitive(PolygonShapeViewModel polygonShapeViewModel) + { + this.polygonShapeViewModel = polygonShapeViewModel; + VisualProperty.Color = (Color)ColorConverter.ConvertFromString("DarkGray"); + VisualProperty.FactoredOpacity = 90; + + var polygon = polygonShapeViewModel.GetPolygonShape(); + var points = polygon.Vertices.Select(x => x.Point).ToList(); + if (points.Count == 0) return; + + IPoint2D StartPoint = points[0]; + System.Windows.Point systemPoint = GetSystemPoint(StartPoint); + var figure = new PathFigure { StartPoint = systemPoint }; + for (int i = 1; i < points.Count; i++) + figure.Segments.Add(new LineSegment(GetSystemPoint(points[i]), true)); + figure.IsClosed = true; + PathGeometry = new PathGeometry(new[] { figure }); + } + + private System.Windows.Point GetSystemPoint(IPoint2D helperPoint) + { + return new(helperPoint.X, helperPoint.Y); + } + } +} diff --git a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml index 47afc7f..64a67f4 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml @@ -101,9 +101,11 @@ + + @@ -117,6 +119,9 @@ + + +