From 3fedc2c2fad4ed96066e09bd3568861856587dac Mon Sep 17 00:00:00 2001 From: 9swampy Date: Mon, 23 Aug 2021 22:22:21 +0100 Subject: [PATCH] Introduce ObservablePoint and ObservableFrame to render better SheetNfp and FinalNfp re https://github.com/fel88/DeepNestPort/issues/16#issuecomment-904131686 --- DeepNestLib/INfp.cs | 11 + DeepNestLib/NFP.cs | 13 +- DeepNestLib/Placement/PartPlacementWorker.cs | 24 +- DeepNestPort/dxfs/Donut.dxf | 1462 +++++++++++++++++ DeepNestPort/dxfs/Stuffing7With12.dnest | 175 ++ .../Models/ObservableFrame.cs | 12 + .../Models/ObservablePoint.cs | 20 + .../Ui/Converters/PointsConverter.cs | 5 + .../DrawingContextBoundZoomPreview.xaml | 10 + .../Ui/ViewModels/PreviewViewModel.cs | 23 +- .../ViewModels/ZoomPreviewDrawingContext.cs | 22 + 11 files changed, 1745 insertions(+), 32 deletions(-) create mode 100644 DeepNestPort/dxfs/Donut.dxf create mode 100644 DeepNestPort/dxfs/Stuffing7With12.dnest create mode 100644 DeepNestSharp.Domain/Models/ObservableFrame.cs create mode 100644 DeepNestSharp.Domain/Models/ObservablePoint.cs diff --git a/DeepNestLib/INfp.cs b/DeepNestLib/INfp.cs index 25c29c48..7ff9ab77 100644 --- a/DeepNestLib/INfp.cs +++ b/DeepNestLib/INfp.cs @@ -44,8 +44,19 @@ public interface INfp : IMinMaxXY, IPolygon, IPlacement NFP GetHull(); + /// + /// Shifts the polygon and all it's children iteratively by the specified PartPlacement(X,Y) offset. + /// + /// The amount to shift. + /// A partial clone of the polygon. INfp Shift(IPartPlacement shift); + /// + /// Shifts the polygon and all it's children iteratively by the specified X,Y offset. + /// + /// Distance to shift on X axis. + /// Distance to shift on Y axis. + /// A partial clone of the polygon. INfp Shift(double x, double y); /// diff --git a/DeepNestLib/NFP.cs b/DeepNestLib/NFP.cs index 605f888c..1d411b3a 100644 --- a/DeepNestLib/NFP.cs +++ b/DeepNestLib/NFP.cs @@ -540,22 +540,13 @@ public string ToOpenScadPolygon() return resultBuilder.ToString(); } - /// - /// Shifts the polygon and all it's children iteratively by the specified PartPlacement(X,Y) offset. - /// - /// - /// + /// public INfp Shift(IPartPlacement shift) { return Shift(shift.X, shift.Y); } - /// - /// Shifts the polygon and all it's children iteratively by the specified X,Y offset. - /// - /// Distance to shift on X axis. - /// Distance to shift on Y axis. - /// A partial clone of the polygon. + /// public INfp Shift(double x, double y) { NFP shifted = new NFP(); diff --git a/DeepNestLib/Placement/PartPlacementWorker.cs b/DeepNestLib/Placement/PartPlacementWorker.cs index c5cd4d61..e8158a34 100644 --- a/DeepNestLib/Placement/PartPlacementWorker.cs +++ b/DeepNestLib/Placement/PartPlacementWorker.cs @@ -174,22 +174,23 @@ public InnerFlowResult ProcessPart(INfp inputPart, int inputPartIndex) if (Placements.Count == 0) { this.VerboseLog("First placement, put it on the bottom left corner. . ."); - - // first placement, put it on the bottom left corner - for (int j = 0; j < SheetNfp.Length; j++) + var processedPartOrigin = processedPart[0]; + for (int nfpCandidateIndex = 0; nfpCandidateIndex < SheetNfp.Length; nfpCandidateIndex++) { - for (int k = 0; k < SheetNfp[j].Length; k++) + var nfpCandidate = SheetNfp[nfpCandidateIndex]; + for (int pointIndex = 0; pointIndex < nfpCandidate.Points.Length; pointIndex++) { + var nfpPoint = nfpCandidate.Points[pointIndex]; + var proposedX = nfpPoint.X - processedPartOrigin.X; + var proposedY = nfpPoint.Y - processedPartOrigin.Y; if (position == null || - ((SheetNfp[j][k].X - processedPart[0].X) < position.X) || - ( - GeometryUtil.AlmostEqual(SheetNfp[j][k].X - processedPart[0].X, position.X) - && ((SheetNfp[j][k].Y - processedPart[0].Y) < position.Y))) + proposedX < position.X || + (GeometryUtil.AlmostEqual(proposedX, position.X) && proposedY < position.Y)) { position = new PartPlacement(processedPart) { - X = SheetNfp[j][k].X - processedPart[0].X, - Y = SheetNfp[j][k].Y - processedPart[0].Y, + X = proposedX, + Y = proposedY, Id = processedPart.Id, Rotation = processedPart.Rotation, Source = processedPart.Source, @@ -206,6 +207,7 @@ public InnerFlowResult ProcessPart(INfp inputPart, int inputPartIndex) // console.log(sheetNfp); } + SheetNfp = new SheetNfp(SheetNfp.Items, Sheet, processedPart.Shift(position)); AddPlacement(inputPart, processedPart, position, inputPartIndex); } else if (SheetNfp != null && SheetNfp.CanAcceptPart) @@ -429,7 +431,7 @@ public InnerFlowResult ProcessPart(INfp inputPart, int inputPartIndex) if (position != null) { - FinalNfp = new NfpCandidateList(finalNfp.ToArray(), Sheet, new NFP(processedPart, WithChildren.Included).Shift(position)); + FinalNfp = new NfpCandidateList(finalNfp.ToArray(), Sheet, processedPart.Shift(position)); AddPlacement(inputPart, processedPart, position, inputPartIndex); if (position.MergedLength.HasValue) { diff --git a/DeepNestPort/dxfs/Donut.dxf b/DeepNestPort/dxfs/Donut.dxf new file mode 100644 index 00000000..05d73ce2 --- /dev/null +++ b/DeepNestPort/dxfs/Donut.dxf @@ -0,0 +1,1462 @@ + 0 +SECTION + 2 +BLOCKS + 0 +ENDSEC + 0 +SECTION + 2 +ENTITIES + 0 +LINE + 8 +0 + 10 +6.2717 + 20 +-59.6713 + 11 +12.4747 + 21 +-58.6888 + 0 +LINE + 8 +0 + 10 +12.4747 + 20 +-58.6888 + 11 +18.541 + 21 +-57.0634 + 0 +LINE + 8 +0 + 10 +18.541 + 20 +-57.0634 + 11 +24.4042 + 21 +-54.8127 + 0 +LINE + 8 +0 + 10 +24.4042 + 20 +-54.8127 + 11 +30 + 21 +-51.9615 + 0 +LINE + 8 +0 + 10 +30 + 20 +-51.9615 + 11 +35.2671 + 21 +-48.541 + 0 +LINE + 8 +0 + 10 +35.2671 + 20 +-48.541 + 11 +40.1478 + 21 +-44.5887 + 0 +LINE + 8 +0 + 10 +40.1478 + 20 +-44.5887 + 11 +44.5887 + 21 +-40.1478 + 0 +LINE + 8 +0 + 10 +44.5887 + 20 +-40.1478 + 11 +48.541 + 21 +-35.2671 + 0 +LINE + 8 +0 + 10 +48.541 + 20 +-35.2671 + 11 +51.9615 + 21 +-30 + 0 +LINE + 8 +0 + 10 +51.9615 + 20 +-30 + 11 +54.8127 + 21 +-24.4042 + 0 +LINE + 8 +0 + 10 +54.8127 + 20 +-24.4042 + 11 +57.0634 + 21 +-18.541 + 0 +LINE + 8 +0 + 10 +57.0634 + 20 +-18.541 + 11 +58.6888 + 21 +-12.4747 + 0 +LINE + 8 +0 + 10 +58.6888 + 20 +-12.4747 + 11 +59.6713 + 21 +-6.2717 + 0 +LINE + 8 +0 + 10 +59.6713 + 20 +-6.2717 + 11 +60 + 21 +0 + 0 +LINE + 8 +0 + 10 +60 + 20 +0 + 11 +59.6713 + 21 +6.2717 + 0 +LINE + 8 +0 + 10 +59.6713 + 20 +6.2717 + 11 +58.6888 + 21 +12.4747 + 0 +LINE + 8 +0 + 10 +58.6888 + 20 +12.4747 + 11 +57.0634 + 21 +18.541 + 0 +LINE + 8 +0 + 10 +57.0634 + 20 +18.541 + 11 +54.8127 + 21 +24.4042 + 0 +LINE + 8 +0 + 10 +54.8127 + 20 +24.4042 + 11 +51.9615 + 21 +30 + 0 +LINE + 8 +0 + 10 +51.9615 + 20 +30 + 11 +48.541 + 21 +35.2671 + 0 +LINE + 8 +0 + 10 +48.541 + 20 +35.2671 + 11 +44.5887 + 21 +40.1478 + 0 +LINE + 8 +0 + 10 +44.5887 + 20 +40.1478 + 11 +40.1478 + 21 +44.5887 + 0 +LINE + 8 +0 + 10 +40.1478 + 20 +44.5887 + 11 +35.2671 + 21 +48.541 + 0 +LINE + 8 +0 + 10 +35.2671 + 20 +48.541 + 11 +30 + 21 +51.9615 + 0 +LINE + 8 +0 + 10 +30 + 20 +51.9615 + 11 +24.4042 + 21 +54.8127 + 0 +LINE + 8 +0 + 10 +24.4042 + 20 +54.8127 + 11 +18.541 + 21 +57.0634 + 0 +LINE + 8 +0 + 10 +18.541 + 20 +57.0634 + 11 +12.4747 + 21 +58.6888 + 0 +LINE + 8 +0 + 10 +12.4747 + 20 +58.6888 + 11 +6.2717 + 21 +59.6713 + 0 +LINE + 8 +0 + 10 +6.2717 + 20 +59.6713 + 11 +0 + 21 +60 + 0 +LINE + 8 +0 + 10 +0 + 20 +60 + 11 +-6.2717 + 21 +59.6713 + 0 +LINE + 8 +0 + 10 +-6.2717 + 20 +59.6713 + 11 +-12.4747 + 21 +58.6888 + 0 +LINE + 8 +0 + 10 +-12.4747 + 20 +58.6888 + 11 +-18.541 + 21 +57.0634 + 0 +LINE + 8 +0 + 10 +-18.541 + 20 +57.0634 + 11 +-24.4042 + 21 +54.8127 + 0 +LINE + 8 +0 + 10 +-24.4042 + 20 +54.8127 + 11 +-30 + 21 +51.9615 + 0 +LINE + 8 +0 + 10 +-30 + 20 +51.9615 + 11 +-35.2671 + 21 +48.541 + 0 +LINE + 8 +0 + 10 +-35.2671 + 20 +48.541 + 11 +-40.1478 + 21 +44.5887 + 0 +LINE + 8 +0 + 10 +-40.1478 + 20 +44.5887 + 11 +-44.5887 + 21 +40.1478 + 0 +LINE + 8 +0 + 10 +-44.5887 + 20 +40.1478 + 11 +-48.541 + 21 +35.2671 + 0 +LINE + 8 +0 + 10 +-48.541 + 20 +35.2671 + 11 +-51.9615 + 21 +30 + 0 +LINE + 8 +0 + 10 +-51.9615 + 20 +30 + 11 +-54.8127 + 21 +24.4042 + 0 +LINE + 8 +0 + 10 +-54.8127 + 20 +24.4042 + 11 +-57.0634 + 21 +18.541 + 0 +LINE + 8 +0 + 10 +-57.0634 + 20 +18.541 + 11 +-58.6888 + 21 +12.4747 + 0 +LINE + 8 +0 + 10 +-58.6888 + 20 +12.4747 + 11 +-59.6713 + 21 +6.2717 + 0 +LINE + 8 +0 + 10 +-59.6713 + 20 +6.2717 + 11 +-60 + 21 +0 + 0 +LINE + 8 +0 + 10 +-60 + 20 +0 + 11 +-59.6713 + 21 +-6.2717 + 0 +LINE + 8 +0 + 10 +-59.6713 + 20 +-6.2717 + 11 +-58.6888 + 21 +-12.4747 + 0 +LINE + 8 +0 + 10 +-58.6888 + 20 +-12.4747 + 11 +-57.0634 + 21 +-18.541 + 0 +LINE + 8 +0 + 10 +-57.0634 + 20 +-18.541 + 11 +-54.8127 + 21 +-24.4042 + 0 +LINE + 8 +0 + 10 +-54.8127 + 20 +-24.4042 + 11 +-51.9615 + 21 +-30 + 0 +LINE + 8 +0 + 10 +-51.9615 + 20 +-30 + 11 +-48.541 + 21 +-35.2671 + 0 +LINE + 8 +0 + 10 +-48.541 + 20 +-35.2671 + 11 +-44.5887 + 21 +-40.1478 + 0 +LINE + 8 +0 + 10 +-44.5887 + 20 +-40.1478 + 11 +-40.1478 + 21 +-44.5887 + 0 +LINE + 8 +0 + 10 +-40.1478 + 20 +-44.5887 + 11 +-35.2671 + 21 +-48.541 + 0 +LINE + 8 +0 + 10 +-35.2671 + 20 +-48.541 + 11 +-30 + 21 +-51.9615 + 0 +LINE + 8 +0 + 10 +-30 + 20 +-51.9615 + 11 +-24.4042 + 21 +-54.8127 + 0 +LINE + 8 +0 + 10 +-24.4042 + 20 +-54.8127 + 11 +-18.541 + 21 +-57.0634 + 0 +LINE + 8 +0 + 10 +-18.541 + 20 +-57.0634 + 11 +-12.4747 + 21 +-58.6888 + 0 +LINE + 8 +0 + 10 +-12.4747 + 20 +-58.6888 + 11 +-6.2717 + 21 +-59.6713 + 0 +LINE + 8 +0 + 10 +-6.2717 + 20 +-59.6713 + 11 +0 + 21 +-60 + 0 +LINE + 8 +0 + 10 +0 + 20 +-60 + 11 +6.2717 + 21 +-59.6713 + 0 +LINE + 8 +0 + 10 +-3.13585 + 20 +-29.8356 + 11 +-6.23735 + 21 +-29.3444 + 0 +LINE + 8 +0 + 10 +-6.23735 + 20 +-29.3444 + 11 +-9.27051 + 21 +-28.5317 + 0 +LINE + 8 +0 + 10 +-9.27051 + 20 +-28.5317 + 11 +-12.2021 + 21 +-27.4064 + 0 +LINE + 8 +0 + 10 +-12.2021 + 20 +-27.4064 + 11 +-15 + 21 +-25.9808 + 0 +LINE + 8 +0 + 10 +-15 + 20 +-25.9808 + 11 +-17.6335 + 21 +-24.2705 + 0 +LINE + 8 +0 + 10 +-17.6335 + 20 +-24.2705 + 11 +-20.0739 + 21 +-22.2943 + 0 +LINE + 8 +0 + 10 +-20.0739 + 20 +-22.2943 + 11 +-22.2943 + 21 +-20.0739 + 0 +LINE + 8 +0 + 10 +-22.2943 + 20 +-20.0739 + 11 +-24.2705 + 21 +-17.6335 + 0 +LINE + 8 +0 + 10 +-24.2705 + 20 +-17.6335 + 11 +-25.9808 + 21 +-15 + 0 +LINE + 8 +0 + 10 +-25.9808 + 20 +-15 + 11 +-27.4064 + 21 +-12.2021 + 0 +LINE + 8 +0 + 10 +-27.4064 + 20 +-12.2021 + 11 +-28.5317 + 21 +-9.27051 + 0 +LINE + 8 +0 + 10 +-28.5317 + 20 +-9.27051 + 11 +-29.3444 + 21 +-6.23735 + 0 +LINE + 8 +0 + 10 +-29.3444 + 20 +-6.23735 + 11 +-29.8356 + 21 +-3.13585 + 0 +LINE + 8 +0 + 10 +-29.8356 + 20 +-3.13585 + 11 +-30 + 21 +0 + 0 +LINE + 8 +0 + 10 +-30 + 20 +0 + 11 +-29.8356 + 21 +3.13585 + 0 +LINE + 8 +0 + 10 +-29.8356 + 20 +3.13585 + 11 +-29.3444 + 21 +6.23735 + 0 +LINE + 8 +0 + 10 +-29.3444 + 20 +6.23735 + 11 +-28.5317 + 21 +9.27051 + 0 +LINE + 8 +0 + 10 +-28.5317 + 20 +9.27051 + 11 +-27.4064 + 21 +12.2021 + 0 +LINE + 8 +0 + 10 +-27.4064 + 20 +12.2021 + 11 +-25.9808 + 21 +15 + 0 +LINE + 8 +0 + 10 +-25.9808 + 20 +15 + 11 +-24.2705 + 21 +17.6335 + 0 +LINE + 8 +0 + 10 +-24.2705 + 20 +17.6335 + 11 +-22.2943 + 21 +20.0739 + 0 +LINE + 8 +0 + 10 +-22.2943 + 20 +20.0739 + 11 +-20.0739 + 21 +22.2943 + 0 +LINE + 8 +0 + 10 +-20.0739 + 20 +22.2943 + 11 +-17.6335 + 21 +24.2705 + 0 +LINE + 8 +0 + 10 +-17.6335 + 20 +24.2705 + 11 +-15 + 21 +25.9808 + 0 +LINE + 8 +0 + 10 +-15 + 20 +25.9808 + 11 +-12.2021 + 21 +27.4064 + 0 +LINE + 8 +0 + 10 +-12.2021 + 20 +27.4064 + 11 +-9.27051 + 21 +28.5317 + 0 +LINE + 8 +0 + 10 +-9.27051 + 20 +28.5317 + 11 +-6.23735 + 21 +29.3444 + 0 +LINE + 8 +0 + 10 +-6.23735 + 20 +29.3444 + 11 +-3.13585 + 21 +29.8356 + 0 +LINE + 8 +0 + 10 +-3.13585 + 20 +29.8356 + 11 +0 + 21 +30 + 0 +LINE + 8 +0 + 10 +0 + 20 +30 + 11 +3.13585 + 21 +29.8356 + 0 +LINE + 8 +0 + 10 +3.13585 + 20 +29.8356 + 11 +6.23735 + 21 +29.3444 + 0 +LINE + 8 +0 + 10 +6.23735 + 20 +29.3444 + 11 +9.27051 + 21 +28.5317 + 0 +LINE + 8 +0 + 10 +9.27051 + 20 +28.5317 + 11 +12.2021 + 21 +27.4064 + 0 +LINE + 8 +0 + 10 +12.2021 + 20 +27.4064 + 11 +15 + 21 +25.9808 + 0 +LINE + 8 +0 + 10 +15 + 20 +25.9808 + 11 +17.6335 + 21 +24.2705 + 0 +LINE + 8 +0 + 10 +17.6335 + 20 +24.2705 + 11 +20.0739 + 21 +22.2943 + 0 +LINE + 8 +0 + 10 +20.0739 + 20 +22.2943 + 11 +22.2943 + 21 +20.0739 + 0 +LINE + 8 +0 + 10 +22.2943 + 20 +20.0739 + 11 +24.2705 + 21 +17.6335 + 0 +LINE + 8 +0 + 10 +24.2705 + 20 +17.6335 + 11 +25.9808 + 21 +15 + 0 +LINE + 8 +0 + 10 +25.9808 + 20 +15 + 11 +27.4064 + 21 +12.2021 + 0 +LINE + 8 +0 + 10 +27.4064 + 20 +12.2021 + 11 +28.5317 + 21 +9.27051 + 0 +LINE + 8 +0 + 10 +28.5317 + 20 +9.27051 + 11 +29.3444 + 21 +6.23735 + 0 +LINE + 8 +0 + 10 +29.3444 + 20 +6.23735 + 11 +29.8356 + 21 +3.13585 + 0 +LINE + 8 +0 + 10 +29.8356 + 20 +3.13585 + 11 +30 + 21 +0 + 0 +LINE + 8 +0 + 10 +30 + 20 +0 + 11 +29.8356 + 21 +-3.13585 + 0 +LINE + 8 +0 + 10 +29.8356 + 20 +-3.13585 + 11 +29.3444 + 21 +-6.23735 + 0 +LINE + 8 +0 + 10 +29.3444 + 20 +-6.23735 + 11 +28.5317 + 21 +-9.27051 + 0 +LINE + 8 +0 + 10 +28.5317 + 20 +-9.27051 + 11 +27.4064 + 21 +-12.2021 + 0 +LINE + 8 +0 + 10 +27.4064 + 20 +-12.2021 + 11 +25.9808 + 21 +-15 + 0 +LINE + 8 +0 + 10 +25.9808 + 20 +-15 + 11 +24.2705 + 21 +-17.6335 + 0 +LINE + 8 +0 + 10 +24.2705 + 20 +-17.6335 + 11 +22.2943 + 21 +-20.0739 + 0 +LINE + 8 +0 + 10 +22.2943 + 20 +-20.0739 + 11 +20.0739 + 21 +-22.2943 + 0 +LINE + 8 +0 + 10 +20.0739 + 20 +-22.2943 + 11 +17.6335 + 21 +-24.2705 + 0 +LINE + 8 +0 + 10 +17.6335 + 20 +-24.2705 + 11 +15 + 21 +-25.9808 + 0 +LINE + 8 +0 + 10 +15 + 20 +-25.9808 + 11 +12.2021 + 21 +-27.4064 + 0 +LINE + 8 +0 + 10 +12.2021 + 20 +-27.4064 + 11 +9.27051 + 21 +-28.5317 + 0 +LINE + 8 +0 + 10 +9.27051 + 20 +-28.5317 + 11 +6.23735 + 21 +-29.3444 + 0 +LINE + 8 +0 + 10 +6.23735 + 20 +-29.3444 + 11 +3.13585 + 21 +-29.8356 + 0 +LINE + 8 +0 + 10 +3.13585 + 20 +-29.8356 + 11 +0 + 21 +-30 + 0 +LINE + 8 +0 + 10 +0 + 20 +-30 + 11 +-3.13585 + 21 +-29.8356 + 0 +ENDSEC + 0 +SECTION + 2 +OBJECTS + 0 +DICTIONARY + 0 +ENDSEC + 0 +EOF diff --git a/DeepNestPort/dxfs/Stuffing7With12.dnest b/DeepNestPort/dxfs/Stuffing7With12.dnest new file mode 100644 index 00000000..65019dc0 --- /dev/null +++ b/DeepNestPort/dxfs/Stuffing7With12.dnest @@ -0,0 +1,175 @@ +{ + "DetailLoadInfos": [ + { + "Name": "_1.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_1.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": true, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_2.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_2.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_3.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_3.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_4.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_4.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_5.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_5.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_6.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_6.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_7.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_7.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": true, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_8.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_8.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_9.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_9.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_10.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_10.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": true, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_11.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_11.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": false, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "_12.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\_12.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": true, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + }, + { + "Name": "Donut.dxf", + "Path": "C:\\Git\\DeepNestPort\\DeepNestPort\\dxfs\\Donut.dxf", + "Quantity": 1, + "IsExists": true, + "IsIncluded": true, + "IsPriority": false, + "IsMultiplied": false, + "StrictAngle": 0 + } + ], + "SheetLoadInfos": [ + { + "Width": 300, + "Height": 160, + "Quantity": 3 + } + ], + "Config": { + "ClipperScale": 10000000, + "ClipByHull": true, + "CurveTolerance": 0.2, + "DrawSimplification": true, + "ExploreConcave": false, + "ExportExecutions": false, + "ExportExecutionPath": "C:\\Temp\\PartPlacementWorker", + "MergeLines": false, + "UseMinkowskiCache": true, + "MutationRate": 400, + "OffsetTreePhase": true, + "PlacementType": 1, + "PopulationSize": 200, + "Rotations": 4, + "SaveAsFileTypeIndex": 1, + "Scale": 25, + "SheetHeight": 800, + "SheetQuantity": 3, + "SheetSpacing": 0, + "SheetWidth": 1200, + "Simplify": false, + "Spacing": 0, + "TimeRatio": 0.5, + "Tolerance": 2, + "ToleranceSvg": 0.005, + "UseHoles": false, + "UseParallel": false, + "UsePriority": false, + "StrictAngles": 0, + "Multiplier": 1, + "ParallelNests": 10, + "ShowPartPositions": true + } +} \ No newline at end of file diff --git a/DeepNestSharp.Domain/Models/ObservableFrame.cs b/DeepNestSharp.Domain/Models/ObservableFrame.cs new file mode 100644 index 00000000..e0631c82 --- /dev/null +++ b/DeepNestSharp.Domain/Models/ObservableFrame.cs @@ -0,0 +1,12 @@ +namespace DeepNestSharp.Domain.Models +{ + using DeepNestLib; + + public class ObservableFrame : ObservableNfp + { + public ObservableFrame(INfp nfp) + : base(new NFP(nfp, WithChildren.Excluded)) + { + } + } +} diff --git a/DeepNestSharp.Domain/Models/ObservablePoint.cs b/DeepNestSharp.Domain/Models/ObservablePoint.cs new file mode 100644 index 00000000..989c0908 --- /dev/null +++ b/DeepNestSharp.Domain/Models/ObservablePoint.cs @@ -0,0 +1,20 @@ +namespace DeepNestSharp.Domain.Models +{ + using DeepNestLib; + + public class ObservablePoint : ObservableNfp + { + public ObservablePoint(INfp nfp) + : base(FirstPoint(nfp)) + { + + } + + private static INfp FirstPoint(INfp nfp) + { + var result = new NFP(nfp, WithChildren.Excluded); + result.ReplacePoints(new SvgPoint[] { nfp.Points[0] }); + return result; + } + } +} diff --git a/DeepNestSharp/Ui/Converters/PointsConverter.cs b/DeepNestSharp/Ui/Converters/PointsConverter.cs index 93095b5a..4df4d08a 100644 --- a/DeepNestSharp/Ui/Converters/PointsConverter.cs +++ b/DeepNestSharp/Ui/Converters/PointsConverter.cs @@ -5,11 +5,16 @@ using System.Windows.Media; using DeepNestLib; using DeepNestLib.Placement; + using DeepNestSharp.Domain.Models; public class PointsConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { + if (value is ObservablePoint obsPoint) + { + return new System.Windows.Point(obsPoint[0].X, obsPoint[0].Y); + } if (value is INfp item) { var result = new PointCollection(item.Length); diff --git a/DeepNestSharp/Ui/UserControls/DrawingContextBoundZoomPreview.xaml b/DeepNestSharp/Ui/UserControls/DrawingContextBoundZoomPreview.xaml index f1eaef70..6264610b 100644 --- a/DeepNestSharp/Ui/UserControls/DrawingContextBoundZoomPreview.xaml +++ b/DeepNestSharp/Ui/UserControls/DrawingContextBoundZoomPreview.xaml @@ -79,6 +79,16 @@ + + + + + + + + + + diff --git a/DeepNestSharp/Ui/ViewModels/PreviewViewModel.cs b/DeepNestSharp/Ui/ViewModels/PreviewViewModel.cs index e0d63dfc..94db0f04 100644 --- a/DeepNestSharp/Ui/ViewModels/PreviewViewModel.cs +++ b/DeepNestSharp/Ui/ViewModels/PreviewViewModel.cs @@ -352,10 +352,7 @@ private void InitialiseDrawingContext(object? sender) lastActiveViewModel = sheetNfpViewModel; if (sheetNfpViewModel.SelectedItem is INfp sheetNfpItem) { - var sheet = new Sheet(sheetNfpViewModel.NfpCandidateList?.Sheet, WithChildren.Included); - sheet.Children.Add(sheetNfpItem); - sheet.Children.Add(sheetNfpViewModel.NfpCandidateList?.Part); - Set(new ObservableNfp(sheet)); + Set(sheetNfpViewModel, sheetNfpItem); } } @@ -396,7 +393,7 @@ private void ResetDrawingContext() this.ZoomDrawingContext.Clear(); } - private void ActiveViewModel_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + private void ActiveViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e) { if (sender == mainViewModel.ActiveDocument) { @@ -429,15 +426,21 @@ private void ActiveViewModel_PropertyChanged(object? sender, System.ComponentMod e.PropertyName == nameof(NfpCandidateListViewModel.SelectedItem) && sheetNfpViewModel.SelectedItem is INfp sheetNfpItem) { - var sheet = new Sheet(sheetNfpViewModel.NfpCandidateList?.Sheet, WithChildren.Included); - sheet.Children.Add(sheetNfpItem); - var part = new NFP(sheetNfpViewModel.NfpCandidateList?.Part, WithChildren.Included); - sheet.Children.Add(part); - Set(new ObservableNfp(sheet)); + Set(sheetNfpViewModel, sheetNfpItem); } } } + private void Set(NfpCandidateListViewModel sheetNfpViewModel, INfp sheetNfpItem) + { + var sheet = new Sheet(sheetNfpViewModel.NfpCandidateList?.Sheet, WithChildren.Included); + sheet.Children.Add(sheetNfpItem); + var part = new NFP(sheetNfpViewModel.NfpCandidateList?.Part, WithChildren.Included); + Set(new ObservableNfp(sheet)); + this.ZoomDrawingContext.AppendChild(new ObservableFrame(part)); + this.ZoomDrawingContext.AppendChild(new ObservablePoint(part)); + } + private void Set(ObservableSheetPlacement item) { ResetDrawingContext(); diff --git a/DeepNestSharp/Ui/ViewModels/ZoomPreviewDrawingContext.cs b/DeepNestSharp/Ui/ViewModels/ZoomPreviewDrawingContext.cs index 45c50257..b0be5a13 100644 --- a/DeepNestSharp/Ui/ViewModels/ZoomPreviewDrawingContext.cs +++ b/DeepNestSharp/Ui/ViewModels/ZoomPreviewDrawingContext.cs @@ -73,6 +73,10 @@ private void AppendChild(INfp c) { AppendChild(observableHole); } + else if (c is ObservablePoint observablePoint) + { + AppendChild(observablePoint); + } else { AppendChild(new ObservableHole(c)); @@ -91,5 +95,23 @@ private void AppendChild(ObservableHole child) AppendChild(new ObservableHole(c)); } } + + /// + /// Adding in children as so can fill differently. + /// + /// Child to add; presumption's it will be a Point. + internal void AppendChild(ObservablePoint child) + { + this.Add(child); + } + + /// + /// Adding in children as so can fill differently. + /// + /// Child to add; presumption's it will be a Frame. + internal void AppendChild(ObservableFrame child) + { + this.Add(child); + } } } \ No newline at end of file