From 90177b9d95106498e9edfa07575eb83ae5f796d2 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 26 Apr 2022 13:40:16 -0700 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFImproved=20leveling=20polygon=20select?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Limit recalculating slice settings display --- .../PrintLeveling/LevelingFunctions.cs | 40 ++++++++++++------- .../Library/Export/GCodeExport.cs | 2 +- .../View3D/TrackballTumbleWidgetExtended.cs | 17 ++++++++ .../SlicerConfiguration/SliceSettingsRow.cs | 5 ++- Submodules/agg-sharp | 2 +- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs index 714bdf941..ed58873eb 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs @@ -41,11 +41,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { private Vector2 bedSize; private Dictionary<(int, int), int> positionToRegion = new Dictionary<(int, int), int>(); - private PrinterConfig printer; public LevelingFunctions(PrinterConfig printer, PrintLevelingData levelingData) { - this.printer = printer; this.SampledPositions = new List(levelingData.SampledPositions); bedSize = printer.Settings.GetValue(SettingsKey.bed_size); @@ -186,6 +184,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling private LevelingTriangle GetCorrectRegion(Vector3 currentDestination) { + var position2D = new Vector2(currentDestination); int xIndex = (int)Math.Round(currentDestination.X * 100 / bedSize.X); int yIndex = (int)Math.Round(currentDestination.Y * 100 / bedSize.Y); @@ -198,12 +197,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling currentDestination.Z = 0; for (int regionIndex = 0; regionIndex < Regions.Count; regionIndex++) { - var dist = (Regions[regionIndex].Center - currentDestination).LengthSquared; - if (Regions[regionIndex].PointInPolyXY(currentDestination.X, currentDestination.Y)) + if (Regions[regionIndex].PointInPolyXY(position2D)) { // we found the one it is in return Regions[regionIndex]; } + + var dist = Regions[regionIndex].DistanceXY(position2D); if (dist < bestDist) { bestIndex = regionIndex; @@ -236,9 +236,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling public Vector3 GetPositionWithZOffset(Vector3 currentDestination) { - var destinationAtZ0 = new Vector3(currentDestination.X, currentDestination.Y, 0); - + var destinationAtZ0 = new Vector3(currentDestination.X, currentDestination.Y, 0); double hitDistance = this.Plane.GetDistanceToIntersection(destinationAtZ0, Vector3.UnitZ); + currentDestination.Z += hitDistance; return currentDestination; @@ -254,16 +254,28 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling return -1; } - public bool PointInPolyXY(double x, double y) + public double DistanceXY(Vector2 position) + { + var vertex0 = new Vector2(V0[0], V0[1]); + var vertex1 = new Vector2(V1[0], V1[1]); + var vertex2 = new Vector2(V2[0], V2[1]); + + var distToEdge0 = Vector2.DistancePointToLine(position, vertex0, vertex1); + var distToEdge1 = Vector2.DistancePointToLine(position, vertex1, vertex2); + var distToEdge2 = Vector2.DistancePointToLine(position, vertex2, vertex0); + + return Math.Min(distToEdge0, Math.Min(distToEdge1, distToEdge2)); + } + + public bool PointInPolyXY(Vector2 position) { // check the bounding rect - Vector2 vertex0 = new Vector2(V0[0], V0[1]); - Vector2 vertex1 = new Vector2(V1[0], V1[1]); - Vector2 vertex2 = new Vector2(V2[0], V2[1]); - Vector2 hitPosition = new Vector2(x, y); - int sumOfLineSides = FindSideOfLine(vertex0, vertex1, hitPosition); - sumOfLineSides += FindSideOfLine(vertex1, vertex2, hitPosition); - sumOfLineSides += FindSideOfLine(vertex2, vertex0, hitPosition); + var vertex0 = new Vector2(V0[0], V0[1]); + var vertex1 = new Vector2(V1[0], V1[1]); + var vertex2 = new Vector2(V2[0], V2[1]); + int sumOfLineSides = FindSideOfLine(vertex0, vertex1, position); + sumOfLineSides += FindSideOfLine(vertex1, vertex2, position); + sumOfLineSides += FindSideOfLine(vertex2, vertex0, position); if (sumOfLineSides == -3 || sumOfLineSides == 3) { return true; diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index 6319012c8..126f3654e 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -176,7 +176,7 @@ namespace MatterHackers.MatterControl.Library.Export return null; } } - else if (firstItem.AssetPath == Printer.Bed.EditContext.SourceFilePath) + else if (assetStream?.ContentType == "mcx") { // If item is bedplate, save any pending changes before starting the print await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), Printer, Printer.Bed.SaveChanges); diff --git a/MatterControlLib/PartPreviewWindow/View3D/TrackballTumbleWidgetExtended.cs b/MatterControlLib/PartPreviewWindow/View3D/TrackballTumbleWidgetExtended.cs index 1947d2319..e15d0b91b 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/TrackballTumbleWidgetExtended.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/TrackballTumbleWidgetExtended.cs @@ -632,6 +632,23 @@ namespace MatterHackers.MatterControl.PartPreviewWindow FinishProjectionSwitch(); var rayAtMousePosition = world.GetRayForLocalBounds(mousePosition); + + // TODO: + // Check if we are in a GCode View + var showingGCode = false; + if (showingGCode) + { + // find the layer height that we are currenly showing + // create a plane at that height + // check if the ray intersects this plane + // if we are above the plane set our origin to this intersection + // if we are below the plane set it as a limit to the cast distance distance + + // Consideration: Think about what to do if we would be hitting the top of the part that is the layer height plane. + // The issue is that there is no mesh geometry at that height but the user will see gcode that they might think + // they should be able to click on. + } + var intersectionInfo = Object3DControlLayer.Scene.GetBVHData().GetClosestIntersection(rayAtMousePosition); var rayAtScreenCenter = world.GetRayForLocalBounds(new Vector2(Width / 2, Height / 2)); if (intersectionInfo != null) diff --git a/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs b/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs index 780898bc4..09e0f2558 100644 --- a/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs +++ b/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs @@ -471,10 +471,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { var data = GetStyleData(printer, theme, settingsContext, settingData.SlicerConfigName, settingData.ShowAsOverride); - if (this.HighlightColor != data.highlightColor) + if (this.HighlightColor != data.highlightColor + && this.Parent != null) { this.HighlightColor = data.highlightColor; - // make sur the value is also updated + // make sure the value is also updated printer.Settings.OnSettingChanged(settingData.SlicerConfigName); } if (restoreButton != null) diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 1fca5e0a2..444ce5470 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 1fca5e0a2e913392761a3cb5fc6ab9f8abbc1c52 +Subproject commit 444ce54704973489addef582e27353a0f84b59ac