From 5cade2868817d2b5fc6aa4ceb7278fe3861b1d64 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Sun, 22 Oct 2023 15:57:10 +0200 Subject: [PATCH] Added possibility to divide step size to 0.001 (#2350) --- .../services/JogService.java | 19 +++--- .../com/willwinder/ugs/nbp/jog/JogPanel.java | 66 ++++++++++--------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/ugs-core/src/com/willwinder/universalgcodesender/services/JogService.java b/ugs-core/src/com/willwinder/universalgcodesender/services/JogService.java index 2ec2ca7211..39731a20a2 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/services/JogService.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/services/JogService.java @@ -76,8 +76,10 @@ private static double divideSize(double size) { return 1; } else if (size <= 1 && size > 0.1) { return 0.1; - } else if (size <= 0.1 ) { + } else if (size <= 0.1 && size > 0.01) { return 0.01; + } else if (size <= 0.01 ) { + return 0.001; } return size; } @@ -147,7 +149,7 @@ public void multiplyZStepSize() { } public void multiplyABCStepSize() { - setStepSizeABC(multiplySize(getStepSizeZ())); + setStepSizeABC(multiplySize(getStepSizeABC())); } public void multiplyFeedRate() { @@ -240,8 +242,7 @@ public void adjustManualLocationZ(int z) { Units preferredUnits = getSettings().getPreferredUnits(); backend.adjustManualLocation(new PartialPosition(null, null, z * stepSize, preferredUnits), feedRate); } catch (Exception e) { - //NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE); - //DialogDisplayer.getDefault().notify(nd); + logger.log(Level.SEVERE, "Could not jog the machine", e); } } @@ -267,8 +268,7 @@ public void adjustManualLocationXY(int x, int y) { Double dy = y == 0 ? null : y * stepSize; backend.adjustManualLocation(new PartialPosition(dx, dy, null, preferredUnits), feedRate); } catch (Exception e) { - //NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE); - //DialogDisplayer.getDefault().notify(nd); + logger.log(Level.WARNING, "Could not perform jog", e); } } @@ -288,8 +288,7 @@ public void adjustManualLocationABC(int a, int b, int c) { Double dc = c == 0 ? null : c * stepSize; backend.adjustManualLocation(new PartialPosition(null, null, null, da, db, dc, preferredUnits), feedRate); } catch (Exception e) { - //NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE); - //DialogDisplayer.getDefault().notify(nd); + logger.log(Level.WARNING, "Could not perform jog", e); } } @@ -315,7 +314,7 @@ public void cancelJog() { try { backend.getController().cancelJog(); } catch (Exception e) { - logger.log(Level.WARNING, "Couldn't cancel the jog", e); + logger.log(Level.WARNING, "Could not cancel the jog", e); } } @@ -323,7 +322,7 @@ public void jogTo(PartialPosition position) { try { backend.getController().jogMachineTo(position, getFeedRate()); } catch (Exception e) { - logger.log(Level.WARNING, "Couldn't jog to position " + position, e); + logger.log(Level.WARNING, "Couldn't jog to position " + position, e); } } } diff --git a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java index 2ab78fab0b..2e521e4f8c 100644 --- a/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java +++ b/ugs-platform/ugs-platform-plugin-jog/src/main/java/com/willwinder/ugs/nbp/jog/JogPanel.java @@ -36,7 +36,6 @@ This file is part of Universal Gcode Sender (UGS). import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.Dimension; @@ -67,6 +66,9 @@ public class JogPanel extends JPanel implements SteppedSizeManager.SteppedSizeCh * jog is activated. Given in milliseconds */ private static final int LONG_PRESS_DELAY = 500; + public static final String JOG_ROTARY_BUTTON_CONSTRAINTS = "grow, hidemode 3, sg button"; + public static final String STEP_CONSTRAINTS = "growx, hidemode 3"; + public static final String JOG_BUTTON_CONSTRAINTS = "grow, sg button"; /** * A list of listeners @@ -221,13 +223,13 @@ private JPanel createConfigurationPanel() { configurationPanel.setLayout(new MigLayout("fill, inset 0, gap 2, flowy", "[shrinkprio 200, right][25%, shrinkprio 100][25%, center, shrinkprio 0, nogrid]", "[center][center][center]")); configurationPanel.add(xyStepLabel, "growx"); - configurationPanel.add(zStepLabel, "growx, hidemode 3"); - configurationPanel.add(abcStepLabel, "growx, hidemode 3"); + configurationPanel.add(zStepLabel, STEP_CONSTRAINTS); + configurationPanel.add(abcStepLabel, STEP_CONSTRAINTS); configurationPanel.add(feedRateLabel, "growx, wrap"); configurationPanel.add(xyStepSizeSpinner, "growx"); - configurationPanel.add(zStepSizeSpinner, "growx, hidemode 3"); - configurationPanel.add(abcStepSizeSpinner, "growx, hidemode 3"); + configurationPanel.add(zStepSizeSpinner, STEP_CONSTRAINTS); + configurationPanel.add(abcStepSizeSpinner, STEP_CONSTRAINTS); configurationPanel.add(feedRateSpinner, "growx, wrap"); configurationPanel.add(unitToggleButton, "grow"); @@ -241,30 +243,30 @@ private JPanel createXYZPanel() { JPanel xyzPanel = new JPanel(); xyzPanel.setLayout(new MigLayout("fill, wrap 4, inset 0, gap 2")); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XNEG_YPOS), "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_YPOS), "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XPOS_YPOS), "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_ZPOS), "grow, sg button"); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XNEG_YPOS), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_YPOS), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XPOS_YPOS), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_ZPOS), JOG_BUTTON_CONSTRAINTS); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_XNEG), "grow, sg button"); - xyzPanel.add(stealFocusButton, "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_XPOS), "grow, sg button"); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_XNEG), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(stealFocusButton, JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_XPOS), JOG_BUTTON_CONSTRAINTS); JPanel space = new JPanel(); space.setOpaque(false); - xyzPanel.add(space, "grow, sg button"); - - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XNEG_YNEG), "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_YNEG), "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XPOS_YNEG), "grow, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_ZNEG), "grow, sg button"); - - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_ANEG), "grow, hidemode 3, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_APOS), "grow, hidemode 3, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_BNEG), "grow, hidemode 3, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_BPOS), "grow, hidemode 3, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_CNEG), "grow, hidemode 3, sg button"); - xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_CPOS), "grow, hidemode 3, sg button"); + xyzPanel.add(space, JOG_BUTTON_CONSTRAINTS); + + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XNEG_YNEG), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_YNEG), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_DIAG_XPOS_YNEG), JOG_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_ZNEG), JOG_BUTTON_CONSTRAINTS); + + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_ANEG), JOG_ROTARY_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_APOS), JOG_ROTARY_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_BNEG), JOG_ROTARY_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_BPOS), JOG_ROTARY_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_CNEG), JOG_ROTARY_BUTTON_CONSTRAINTS); + xyzPanel.add(getButtonFromEnum(JogPanelButtonEnum.BUTTON_CPOS), JOG_ROTARY_BUTTON_CONSTRAINTS); return xyzPanel; } @@ -290,12 +292,12 @@ protected void onMouseClicked(MouseEvent e) { @Override protected void onMousePressed(MouseEvent e) { - + // Not needed } @Override protected void onMouseRelease(MouseEvent e) { - + // Not needed } @Override @@ -324,9 +326,9 @@ protected void onMouseLongRelease(MouseEvent e) { abcStepSizeSpinner.addChangeListener(this); feedRateSpinner.addChangeListener(this); - unitToggleButton.addActionListener((actionEvent) -> listeners.forEach(JogPanelListener::onToggleUnit)); - increaseStepSizeButton.addActionListener((actionEvent) -> listeners.forEach(JogPanelListener::onIncreaseStepSize)); - decreaseStepSizeButton.addActionListener((actionEvent) -> listeners.forEach(JogPanelListener::onDecreaseStepSize)); + unitToggleButton.addActionListener(actionEvent -> listeners.forEach(JogPanelListener::onToggleUnit)); + increaseStepSizeButton.addActionListener(actionEvent -> listeners.forEach(JogPanelListener::onIncreaseStepSize)); + decreaseStepSizeButton.addActionListener(actionEvent -> listeners.forEach(JogPanelListener::onDecreaseStepSize)); } /** @@ -359,7 +361,7 @@ private JButton getButtonFromEnum(JogPanelButtonEnum buttonEnum) { private JButton createJogButton(JogPanelButtonEnum buttonEnum) { JButton button = new JogButton(buttonEnum); button.setMinimumSize(new Dimension(MINIMUM_BUTTON_SIZE, MINIMUM_BUTTON_SIZE)); - button.addActionListener((e) -> stealFocusButton.requestFocusInWindow()); + button.addActionListener(e -> stealFocusButton.requestFocusInWindow()); jogButtons.put(buttonEnum, button); return button; } @@ -376,7 +378,7 @@ private JButton createImageButton(String baseUri) { button.setMinimumSize(new Dimension(MINIMUM_BUTTON_SIZE, MINIMUM_BUTTON_SIZE)); button.setMargin(new Insets(0, 0, 0, 0)); button.setFocusable(false); - button.addActionListener((e) -> stealFocusButton.requestFocusInWindow()); + button.addActionListener(e -> stealFocusButton.requestFocusInWindow()); return button; }