diff --git a/FieldVisualizer/Entities/Values/Primitives/TrianglePrimitive.cs b/FieldVisualizer/Entities/Values/Primitives/TrianglePrimitive.cs index c377fe0..b6be9c7 100644 --- a/FieldVisualizer/Entities/Values/Primitives/TrianglePrimitive.cs +++ b/FieldVisualizer/Entities/Values/Primitives/TrianglePrimitive.cs @@ -1,9 +1,5 @@ using StructureHelperCommon.Models.Shapes; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FieldVisualizer.Entities.Values.Primitives { diff --git a/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs b/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs index 10c1708..5df04a1 100644 --- a/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs +++ b/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs @@ -241,7 +241,7 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels // Create the PathFigure using triangle vertices. var figure = new PathFigure { - StartPoint = new Point(triangle.Point1.X, triangle.Point1.Y), + StartPoint = new Point(triangle.Point1.X, - triangle.Point1.Y), IsClosed = true, IsFilled = true }; @@ -249,8 +249,8 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels // Add the remaining vertices as LineSegments var segments = new PathSegmentCollection { - new LineSegment(new Point(triangle.Point2.X, triangle.Point2.Y), true), - new LineSegment(new Point(triangle.Point3.X, triangle.Point3.Y), true) + new LineSegment(new Point(triangle.Point2.X, - triangle.Point2.Y), true), + new LineSegment(new Point(triangle.Point3.X, - triangle.Point3.Y), true) // Closing is handled by IsClosed = true, so we don't need to add a segment back to Point1 }; figure.Segments = segments; diff --git a/FieldVisualizer/Windows/WndFieldViewer.xaml.cs b/FieldVisualizer/Windows/WndFieldViewer.xaml.cs index 01cae36..ad8f528 100644 --- a/FieldVisualizer/Windows/WndFieldViewer.xaml.cs +++ b/FieldVisualizer/Windows/WndFieldViewer.xaml.cs @@ -1,19 +1,8 @@ using FieldVisualizer.Entities.Values.Primitives; -using FieldVisualizer.Windows.UserControls; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; -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.Shapes; namespace FieldVisualizer.Windows { diff --git a/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs b/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs index 4fa1de8..649568a 100644 --- a/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs +++ b/StructureHelper/Infrastructure/UI/DataContexts/ShapeViewPrimitive.cs @@ -53,7 +53,8 @@ namespace StructureHelper.Infrastructure.UI.DataContexts private System.Windows.Point GetSystemPoint(IPoint2D helperPoint) { - return new(DeltaX + shapeNDMPrimitive.Center.X + helperPoint.X, DeltaY - shapeNDMPrimitive.Center.Y - helperPoint.Y); + //return new(DeltaX + shapeNDMPrimitive.Center.X + helperPoint.X, DeltaY - shapeNDMPrimitive.Center.Y - helperPoint.Y); + return new(DeltaX + helperPoint.X, DeltaY - helperPoint.Y); } } } diff --git a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml index 64a67f4..2ca388d 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml @@ -337,6 +337,15 @@ + + + + + + + + + @@ -395,6 +404,24 @@ + + + + + + + + + + + + + + + + + + @@ -444,6 +471,15 @@ + + + + + + + + + diff --git a/StructureHelper/Services/ResultViewers/ShowIsoFieldResult.cs b/StructureHelper/Services/ResultViewers/ShowIsoFieldResult.cs index 402157a..5a70668 100644 --- a/StructureHelper/Services/ResultViewers/ShowIsoFieldResult.cs +++ b/StructureHelper/Services/ResultViewers/ShowIsoFieldResult.cs @@ -2,8 +2,6 @@ using FieldVisualizer.WindowsOperation; using LoaderCalculator.Data.Matrix; using LoaderCalculator.Data.Ndms; -using LoaderCalculator.Data.ResultData; -using LoaderCalculator.Logics; using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Services; @@ -11,9 +9,6 @@ using StructureHelperLogics.NdmCalculations.Cracking; using StructureHelperLogics.NdmCalculations.Triangulations; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace StructureHelper.Services.ResultViewers { diff --git a/StructureHelper/StructureHelper.csproj b/StructureHelper/StructureHelper.csproj index 3732ff2..7d4251c 100644 --- a/StructureHelper/StructureHelper.csproj +++ b/StructureHelper/StructureHelper.csproj @@ -68,6 +68,7 @@ + diff --git a/StructureHelper/Windows/Shapes/Point2DViewModel.cs b/StructureHelper/Windows/Shapes/Point2DViewModel.cs index 0471729..908b1e1 100644 --- a/StructureHelper/Windows/Shapes/Point2DViewModel.cs +++ b/StructureHelper/Windows/Shapes/Point2DViewModel.cs @@ -12,13 +12,14 @@ namespace StructureHelper.Windows.Shapes public double X { - get => point.X - center.X; + get => point.X + center.X; set { try { double val = value; - point.X = val + center.X; + point.X = val - center.X; + OnPropertyChanged(nameof(X)); } catch (Exception ex) { @@ -29,13 +30,14 @@ namespace StructureHelper.Windows.Shapes public double Y { - get => point.Y - center.Y; + get => point.Y + center.Y; set { try { double val = value; - point.Y = val + center.Y; + point.Y = val - center.Y; + OnPropertyChanged(nameof(Y)); } catch (Exception ex) { @@ -44,6 +46,13 @@ namespace StructureHelper.Windows.Shapes } } + public void Refresh() + { + OnPropertyChanged(nameof(X)); + OnPropertyChanged(nameof(Y)); + + } + public Point2DViewModel(IPoint2D point, IPoint2D center) { this.point = point; diff --git a/StructureHelper/Windows/Shapes/PolygonShapeView.xaml b/StructureHelper/Windows/Shapes/PolygonShapeView.xaml index c3c7965..e56a7dc 100644 --- a/StructureHelper/Windows/Shapes/PolygonShapeView.xaml +++ b/StructureHelper/Windows/Shapes/PolygonShapeView.xaml @@ -72,6 +72,50 @@ + + + + + + + + diff --git a/StructureHelper/Windows/Shapes/PolygonShapeViewModel.cs b/StructureHelper/Windows/Shapes/PolygonShapeViewModel.cs index 574e06d..75c7ee6 100644 --- a/StructureHelper/Windows/Shapes/PolygonShapeViewModel.cs +++ b/StructureHelper/Windows/Shapes/PolygonShapeViewModel.cs @@ -1,4 +1,7 @@ -using StructureHelper.Infrastructure; +using netDxf; +using netDxf.Entities; +using netDxf.Header; +using StructureHelper.Infrastructure; using StructureHelper.Infrastructure.UI.GraphicalPrimitives; using StructureHelper.Windows.Shapes.Logics; using StructureHelper.Windows.UserControls.WorkPlanes; @@ -18,12 +21,15 @@ namespace StructureHelper.Windows.Shapes public class PolygonShapeViewModel : OkCancelViewModelBase { private const int minVertexCount = 3; - private readonly IPoint2D center; + private readonly IPoint2D absoluteCenter; + private readonly IPoint2D localCenter; private readonly ILinePolygonShape polygonShape; + private IReadOnlyList vertices => polygonShape.Vertices; private IObjectConvertStrategy, ILinePolygonShape> logic; + private RelayCommand importFromDxfCommand; + private RelayCommand exportToDxfCommand; public Point2DViewModel Center { get; } - public PolygonShapeViewModel(ILinePolygonShape polygonShape) : this(polygonShape, new Point2D() { X = 0, Y = 0 }) { } public VertexViewModel SelectedVertex { get; set; } public ObservableCollection Vertices { get;} = new(); public WorkPlaneRootViewModel WorkPlaneRoot { get;} = new(); @@ -31,17 +37,85 @@ namespace StructureHelper.Windows.Shapes public PolygonShapeViewModel(ILinePolygonShape polygonShape, IPoint2D center) { this.polygonShape = polygonShape; - this.center = center; - Center = new(this.center); + this.absoluteCenter = center; + this.localCenter = new Point2D(); + Center = new(this.absoluteCenter); + ReloadVertices(); + Redraw(null); + } + + private void ReloadVertices() + { + Vertices.Clear(); foreach (var item in this.polygonShape.Vertices) { - Vertices.Add(new VertexViewModel(item, this.center)); + Vertices.Add(new VertexViewModel(item, localCenter)); } - Redraw(null); } private RelayCommand addVertexCommand; public ICommand AddVertexCommand => addVertexCommand ??= new RelayCommand(AddVertex); + public ICommand FlipVerticalCommand => flipVerticalCommand ??= new RelayCommand(FlipVertical); + public ICommand FlipHorizontalCommand => flipHorizontalCommand ??= new RelayCommand(FlipHorizontal); + + public ICommand ImportFromDxfCommand => importFromDxfCommand ??= new RelayCommand(ImportFromDxf); + + private void ImportFromDxf(object commandParameter) + { + // your DXF file name + string file = "sample.dxf"; + // this check is optional but recommended before loading a DXF file + DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file); + // netDxf is only compatible with AutoCad2000 and higher DXF versions + if (dxfVersion < DxfVersion.AutoCad2000) return; + // load file + DxfDocument loaded = DxfDocument.Load(file); + } + + public ICommand ExportToDxfCommand => exportToDxfCommand ??= new RelayCommand(ExportToDxf); + + private void ExportToDxf(object commandParameter) + { + // your DXF file name + string file = "sample.dxf"; + + // create a new document, by default it will create an AutoCad2000 DXF version + DxfDocument doc = new DxfDocument(); + // an entity + List polylineVertices = []; + foreach (var item in vertices) + { + Polyline2DVertex vertex = new Polyline2DVertex(item.Point.X, item.Point.Y); + polylineVertices.Add(vertex); + } + Polyline2D polyline2D = new Polyline2D(polylineVertices) { IsClosed = true}; + //polyline2D.Layer = + // add your entities here + doc.Entities.Add(polyline2D); + // save to file + doc.Save(file); + } + + private void FlipHorizontal(object obj) + { + foreach (var item in vertices) + { + item.Point.Y = - item.Point.Y; + } + ReloadVertices(); + Redraw(null); + } + + private void FlipVertical(object obj) + { + foreach (var item in vertices) + { + item.Point.X = - item.Point.X; + } + ReloadVertices(); + Redraw(null); + } + public ILinePolygonShape GetPolygonShape() { ILinePolygonShape polygonShape = new LinePolygonShape(Guid.NewGuid()); @@ -49,8 +123,8 @@ namespace StructureHelper.Windows.Shapes foreach (var item in Vertices) { Vertex vertex = new(Guid.NewGuid()); - vertex.Point.X = item.Point.X; - vertex.Point.Y = item.Point.Y; + vertex.Point.X = item.Point.X - localCenter.X; + vertex.Point.Y = item.Point.Y - localCenter.Y; polygonShape.AddVertex(vertex); } return polygonShape; @@ -79,6 +153,10 @@ namespace StructureHelper.Windows.Shapes WorkPlaneRoot.PrimitiveCollection.Primitives.Clear(); var polygon = GetPolygonShape(); WorkPlaneRoot.PrimitiveCollection.Primitives.Add(logic.Convert(polygon)[0]); + //foreach (var item in Vertices) + //{ + // item.Refresh(); + //} } private RelayCommand addVertexBeforeCommand; @@ -116,6 +194,9 @@ namespace StructureHelper.Windows.Shapes } private RelayCommand deleteVertexCommand; + private RelayCommand flipVerticalCommand; + private RelayCommand flipHorizontalCommand; + public ICommand DeleteVertexCommand => deleteVertexCommand ??= new RelayCommand(DeleteVertex, o => SelectedVertex is not null && Vertices.Count >= minVertexCount); diff --git a/StructureHelper/Windows/Shapes/VertexViewModel.cs b/StructureHelper/Windows/Shapes/VertexViewModel.cs index 7aa3d87..7db5289 100644 --- a/StructureHelper/Windows/Shapes/VertexViewModel.cs +++ b/StructureHelper/Windows/Shapes/VertexViewModel.cs @@ -6,13 +6,21 @@ namespace StructureHelper.Windows.Shapes public class VertexViewModel : ViewModelBase { private readonly IVertex vertex; + + public Point2DViewModel Point { get; private set; } + public VertexViewModel(IVertex vertex) : this(vertex, new Point2D()) { } public VertexViewModel(IVertex vertex, IPoint2D center) { this.vertex = vertex; Point = new(this.vertex.Point, center); } + public void Refresh() + { + Point.Refresh(); + } + public VertexViewModel(Vertex vertex) : this(vertex, new Point2D()) { } diff --git a/StructureHelperLogics/NdmCalculations/Triangulations/LinePolygonTriangulationLogic.cs b/StructureHelperLogics/NdmCalculations/Triangulations/LinePolygonTriangulationLogic.cs index f9e9c8d..c284dd7 100644 --- a/StructureHelperLogics/NdmCalculations/Triangulations/LinePolygonTriangulationLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Triangulations/LinePolygonTriangulationLogic.cs @@ -62,7 +62,7 @@ namespace StructureHelperLogics.NdmCalculations.Triangulations var contour = new List(); foreach (var vertex in vertices) { - contour.Add(new TriangleNet.Geometry.Vertex(vertex.Point.X, vertex.Point.Y)); + contour.Add(new TriangleNet.Geometry.Vertex(vertex.Point.X + options.Center.X, vertex.Point.Y + options.Center.Y)); } // Add contour to polygon — this automatically defines the connecting segments