From 573b7d4273eff546884fd312951e8b3ce06cefd4 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Tue, 23 Jan 2024 20:58:01 +0100 Subject: [PATCH] Add possibility to export the autoleveled gcode --- .../resources/MessagesBundle_en_US.properties | 2 ++ .../surfacescanner/MeshLevelManager.java | 21 +++--------------- .../ugs/platform/surfacescanner/Utils.java | 22 +++++++++++++++++++ .../surfacescanner/ui/AutoLevelerToolbar.java | 1 + 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ugs-core/src/resources/MessagesBundle_en_US.properties b/ugs-core/src/resources/MessagesBundle_en_US.properties index 5d7f25af76..ac5308454b 100644 --- a/ugs-core/src/resources/MessagesBundle_en_US.properties +++ b/ugs-core/src/resources/MessagesBundle_en_US.properties @@ -501,6 +501,8 @@ autoleveler.option.offset-y = Probe Y offset autoleveler.option.offset-z = Probe Z offset autoleveler.probe-failed = Probe failed autoleveler.panel.clear = Clear scan +autoleveler.panel.export = Export gcode +autoleveler.panel.export.tooltip = Exports the autoleveled gcode experimental.feature = This is an experimental feature. Please use caution and report any bugs you find on GitHub. # Window title for platform GUI platform-title = Universal Gcode Sender diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/MeshLevelManager.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/MeshLevelManager.java index 8c5496b213..1cb1a2a9eb 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/MeshLevelManager.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/MeshLevelManager.java @@ -1,5 +1,5 @@ /* - Copyright 2023 Will Winder + Copyright 2023-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -18,11 +18,8 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.platform.surfacescanner; -import com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils; -import com.willwinder.universalgcodesender.gcode.processors.ArcExpander; +import static com.willwinder.ugs.platform.surfacescanner.Utils.createCommandProcessor; import com.willwinder.universalgcodesender.gcode.processors.CommandProcessorList; -import com.willwinder.universalgcodesender.gcode.processors.LineSplitter; -import com.willwinder.universalgcodesender.gcode.processors.MeshLeveler; import com.willwinder.universalgcodesender.model.BackendAPI; import com.willwinder.universalgcodesender.utils.AutoLevelSettings; import com.willwinder.universalgcodesender.utils.GUIHelpers; @@ -51,19 +48,7 @@ public void update() { return; } - commandProcessorList = new CommandProcessorList(); - - // Step 1: Convert arcs to line segments. - commandProcessorList.add(new ArcExpander(true, autoLevelSettings.getAutoLevelArcSliceLength(), GcodePreprocessorUtils.getDecimalFormatter())); - - // Step 2: Line splitter. No line should be longer than some fraction of "resolution" - commandProcessorList.add(new LineSplitter(autoLevelSettings.getStepResolution() / 4)); - - // Step 3: Adjust Z heights codes based on mesh offsets. - commandProcessorList.add( - new MeshLeveler(autoLevelSettings.getZSurface(), - surfaceScanner.getProbePositionGrid())); - + commandProcessorList = createCommandProcessor(autoLevelSettings, surfaceScanner); backend.applyCommandProcessor(commandProcessorList); } catch (Exception ex) { GUIHelpers.displayErrorDialog(ex.getMessage()); diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/Utils.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/Utils.java index 2d6fd7b07b..5cb21510b7 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/Utils.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/Utils.java @@ -18,9 +18,15 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.platform.surfacescanner; +import com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils; +import com.willwinder.universalgcodesender.gcode.processors.ArcExpander; +import com.willwinder.universalgcodesender.gcode.processors.CommandProcessorList; +import com.willwinder.universalgcodesender.gcode.processors.LineSplitter; +import com.willwinder.universalgcodesender.gcode.processors.MeshLeveler; import com.willwinder.universalgcodesender.i18n.Localization; import com.willwinder.universalgcodesender.model.Position; import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.utils.AutoLevelSettings; import javax.swing.*; import java.awt.*; @@ -77,4 +83,20 @@ public static Position getRoundPosition(Position position) { double z = Math.round(position.getZ() * 1000d) / 1000d; return new Position(x, y, z, position.getUnits()); } + + public static CommandProcessorList createCommandProcessor(AutoLevelSettings autoLevelSettings, SurfaceScanner surfaceScanner) { + CommandProcessorList result = new CommandProcessorList(); + + // Step 1: Convert arcs to line segments. + result.add(new ArcExpander(true, autoLevelSettings.getAutoLevelArcSliceLength(), GcodePreprocessorUtils.getDecimalFormatter())); + + // Step 2: Line splitter. No line should be longer than some fraction of "resolution" + result.add(new LineSplitter(autoLevelSettings.getStepResolution() / 4)); + + // Step 3: Adjust Z heights codes based on mesh offsets. + result.add( + new MeshLeveler(autoLevelSettings.getZSurface(), + surfaceScanner.getProbePositionGrid())); + return result; + } } diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerToolbar.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerToolbar.java index 0faaeeb099..c7e4ee7879 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerToolbar.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerToolbar.java @@ -35,6 +35,7 @@ public AutoLevelerToolbar(SurfaceScanner surfaceScanner) { add(new JButton(new SaveScannedSurfaceAction(surfaceScanner))); add(new JButton(new ClearScannedSurfaceAction(surfaceScanner))); add(Box.createGlue()); + add(new JButton(new ExportGcodeAction(surfaceScanner))); add(new JButton(new GenerateTestDataAction(surfaceScanner))); add(new JButton(new OpenSettingsAction())); }