Skip to content

Commit

Permalink
Added possibility to divide step size to 0.001 (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Oct 22, 2023
1 parent 60b5931 commit 5cade28
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -147,7 +149,7 @@ public void multiplyZStepSize() {
}

public void multiplyABCStepSize() {
setStepSizeABC(multiplySize(getStepSizeZ()));
setStepSizeABC(multiplySize(getStepSizeABC()));
}

public void multiplyFeedRate() {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -315,15 +314,15 @@ 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);
}
}

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 5cade28

Please sign in to comment.