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 @@ + + +