Skip to content

Commit

Permalink
Probe module fixes (#2389)
Browse files Browse the repository at this point in the history
* Fixed scaling in probe preview components
* Added a new spinner that can show units and moved them to the generic package
* Added unit abbreviation to all spinners
* Fixed small styling problem and added action for opening the probe settings
  • Loading branch information
breiler committed Dec 14, 2023
1 parent 93bc66c commit 3eb1055
Show file tree
Hide file tree
Showing 22 changed files with 443 additions and 184 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Will Winder
Copyright 2021-2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand All @@ -25,7 +25,7 @@ public enum TextFieldUnit {
MM("mm"),
INCH("\""),
MM_PER_MINUTE("mm/min"),
INCHES_PER_MINUTE("inches/min"),
INCHES_PER_MINUTE("inch/min"),
ROTATIONS_PER_MINUTE("rpm"),
PERCENT("%"),
DEGREE("°");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package com.willwinder.ugs.platform.surfacescanner.ui;
/*
Copyright 2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender.uielements.components;

import com.willwinder.universalgcodesender.uielements.TextFieldUnit;
import com.willwinder.universalgcodesender.uielements.TextFieldUnitFormatter;

import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;

/**
* A spinner that shows the percent character at the end when not editing.
*
* @author Joacim Breiler
*/
public class PercentSpinner extends JSpinner {

private final SpinnerNumberModel spinnerNumberModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This file is part of Universal Gcode Sender (UGS).
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.platform.surfacescanner.ui;
package com.willwinder.universalgcodesender.uielements.components;

import javax.swing.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
Copyright 2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender.uielements.components;

import com.willwinder.universalgcodesender.uielements.TextFieldUnit;
import com.willwinder.universalgcodesender.uielements.TextFieldUnitFormatter;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.text.DefaultFormatterFactory;

/**
* Spinner that shows the given unit with its abbreviation
*
* @author Joacim Breiler
*/
public class UnitSpinner extends JSpinner {

private SpinnerNumberModel spinnerNumberModel;
private NumberEditor numberEditor;

public UnitSpinner(double value, TextFieldUnit units) {
this(value, units, null, null, 0.01d);
}

public UnitSpinner(double value, TextFieldUnit units, Double minimum, Double maximum, Double stepSize) {
spinnerNumberModel = new SpinnerNumberModel(Double.valueOf(value), minimum, maximum, stepSize);
setModel(spinnerNumberModel);
setValue(value);
setUnits(units);
}

public void setUnits(TextFieldUnit units) {
if(units == TextFieldUnit.MM) {
spinnerNumberModel.setStepSize(0.01);
} else {
spinnerNumberModel.setStepSize(0.001);
}

numberEditor = new JSpinner.NumberEditor(this);
numberEditor.getTextField().setFormatterFactory(new DefaultFormatterFactory(
new TextFieldUnitFormatter(units, 3),
new TextFieldUnitFormatter(units, 3),
new TextFieldUnitFormatter(units, 3, false)));
numberEditor.getTextField().setHorizontalAlignment(SwingConstants.LEFT);
setEditor(numberEditor);
}

public double getDoubleValue() {
return (Double) getModel().getValue();
}


public void setMinimum(double min) {
spinnerNumberModel.setMinimum(min);
if (getDoubleValue() < min) {
setValue(min);
}
}

@Override
public Object getNextValue() {
if (super.getNextValue() == null) {
return null;
}

double power = 1d / spinnerNumberModel.getStepSize().doubleValue();
return Math.round((Double) super.getNextValue() * power) / power;
}

@Override
public Object getPreviousValue() {
if (super.getPreviousValue() == null) {
return null;
}

double power = 1d / spinnerNumberModel.getStepSize().doubleValue();
return Math.round((Double) super.getPreviousValue() * power) / power;
}
}
3 changes: 3 additions & 0 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,17 @@ mainWindow.swing.getState = Get State
platform.window.probe-module = Probe Module
platform.window.probe-module.tooltip = A suite of utilities to manage probe operations.
probe.find-rate = Fast find rate
probe.find-rate.tooltip = The fast find rate for moving towards the probe
probe.measure-rate = Slow measure rate
probe.measure-rate.tooltip = The slow measure rate for moving towards the probe
probe.x-distance = Probe X Distance
probe.y-distance = Probe Y Distance
probe.retract-amount = Retract amount
probe.retract-amount.tooltip = Distance to retract after the fast probe cycle before running the slow probe
probe.hole-diameter = Approximate hole diameter
probe.hole-center-hint = Move probe to approximate center
probe.work-coordinates = Work Coordinates
probe.action.settings = Settings...
probe.action.z = Probe and zero Z
probe.action.z.confirmation = Are you sure you want to probe Z with current settings?
probe.action.xy = Probe and zero XY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.lib.Mode;
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup;
import com.willwinder.ugs.nbp.lib.services.LocalizingService;
import static com.willwinder.ugs.nbp.lib.services.LocalizingService.lang;
import com.willwinder.ugs.nbp.lib.services.TopComponentLocalizer;
import com.willwinder.ugs.platform.probe.renderable.*;
import com.willwinder.ugs.platform.probe.ui.*;
import com.willwinder.ugs.platform.probe.renderable.HoleCenterPathPreview;
import com.willwinder.ugs.platform.probe.renderable.ProbePreviewManager;
import com.willwinder.ugs.platform.probe.renderable.XYProbePathPreview;
import com.willwinder.ugs.platform.probe.renderable.XYZProbePathPreview;
import com.willwinder.ugs.platform.probe.renderable.ZProbePathPreview;
import com.willwinder.ugs.platform.probe.ui.ProbeHoleCenterPanel;
import com.willwinder.ugs.platform.probe.ui.ProbeOutsideXYPanel;
import com.willwinder.ugs.platform.probe.ui.ProbeXYZPanel;
import com.willwinder.ugs.platform.probe.ui.ProbeZPanel;
import com.willwinder.ugs.platform.probe.ui.SettingsPanel;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.listeners.UGSEventListener;
import com.willwinder.universalgcodesender.model.BackendAPI;
Expand All @@ -39,10 +48,9 @@ This file is part of Universal Gcode Sender (UGS).
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

import javax.swing.*;
import java.awt.*;

import static com.willwinder.ugs.nbp.lib.services.LocalizingService.lang;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;

/**
* Top component which displays something.
Expand All @@ -63,10 +71,10 @@ This file is part of Universal Gcode Sender (UGS).
)
public final class ProbeTopComponent extends TopComponent implements UGSEventListener {
public static final String preferredId = "AdvancedProbeTopComponent";
public final static String ProbeTitle = Localization.getString("platform.window.probe-module", lang);
public final static String ProbeTooltip = Localization.getString("platform.window.probe-module.tooltip", lang);
public final static String ProbeActionId = "com.willwinder.ugs.platform.probe.ProbeTopComponent.renamed";
public final static String ProbeCategory = LocalizingService.CATEGORY_WINDOW;
public static final String ProbeTitle = Localization.getString("platform.window.probe-module", lang);
public static final String ProbeTooltip = Localization.getString("platform.window.probe-module.tooltip", lang);
public static final String ProbeActionId = "com.willwinder.ugs.platform.probe.ProbeTopComponent.renamed";
public static final String ProbeCategory = LocalizingService.CATEGORY_WINDOW;
// hole diameter tab
private static final String HC_TAB = "Hole center";
// xyz tab
Expand All @@ -76,9 +84,9 @@ public final class ProbeTopComponent extends TopComponent implements UGSEventLis
// z-probe tab
private static final String Z_TAB = "Z";
private static final String SETTINGS_TAB = "Settings";
private final ProbePreviewManager probePreviewManager;
private final JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT);
private final BackendAPI backend;
private transient final ProbePreviewManager probePreviewManager;
private final JTabbedPane jtp = new JTabbedPane(SwingConstants.LEFT);
private transient final BackendAPI backend;
private ProbeHoleCenterPanel probeHoleCenterPanel;
private ProbeXYZPanel probeXYZPanel;
private ProbeOutsideXYPanel probeXYPanel;
Expand Down Expand Up @@ -144,16 +152,21 @@ private void initComponents() {
settingsPanel = new SettingsPanel();

jtp.add(Z_TAB, probeZPanel);
jtp.add(HC_TAB, probeHoleCenterPanel);
jtp.add(XYZ_TAB, probeXYZPanel);
jtp.add(OUTSIDE_TAB, probeXYPanel);
jtp.add(XYZ_TAB, probeXYZPanel);
jtp.add(HC_TAB, probeHoleCenterPanel);
jtp.add(SETTINGS_TAB, settingsPanel);
jtp.setSelectedIndex(ProbeSettings.getSelectedTabIdx());

this.setLayout(new BorderLayout());
this.add(jtp);
}

public void selectSettingsTab() {
// Select the settings tab (which is last)
jtp.setSelectedIndex(jtp.getTabCount() - 1);
}

@Override
public void componentOpened() {
controlChangeListener();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.platform.probe.actions;

import com.willwinder.ugs.nbp.lib.services.LocalizingService;
import com.willwinder.ugs.platform.probe.ProbeTopComponent;
import com.willwinder.universalgcodesender.i18n.Localization;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.windows.WindowManager;

import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;

/**
* Opens the probe module and highlights the settings tab.
*
* @author Joacim Breiler
*/
@ActionID(
category = LocalizingService.CATEGORY_MACHINE,
id = "com.willwinder.ugs.platform.probe.actions.OpenProbeSettingsAction")
@ActionRegistration(
displayName = "Settings",
lazy = false)
@ActionReferences({
@ActionReference(
path = LocalizingService.MENU_MACHINE_PROBE,
position = 50,
separatorBefore = 49)})
public class OpenProbeSettingsAction extends AbstractAction {

public OpenProbeSettingsAction() {
putValue("menuText", Localization.getString("probe.action.settings"));
putValue(NAME, Localization.getString("probe.action.settings"));
}

@Override
public void actionPerformed(ActionEvent e) {
ProbeTopComponent outputWindow = (ProbeTopComponent) WindowManager.getDefault().findTopComponent(ProbeTopComponent.preferredId);
outputWindow.open();
outputWindow.requestActive();
outputWindow.selectSettingsTab();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AbstractProbePreview(int priority, String title) {
probeService = Lookup.getDefault().lookup(ProbeService.class);
}

public abstract void setContext(ProbeParameters pc, Position startWork, Position startMachine);
public abstract void setContext(ProbeParameters pc, Position startWork);

public abstract void updateSettings();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public abstract class CornerProbePathPreview extends AbstractProbePreview {
private final Position spacing = new Position(0, 0, 0);
private final Position thickness = new Position(0, 0, 0);
private Position startWork = null;
private Position startMachine = null;
private ProbeParameters pc = null;

private final GLUT glut;
Expand All @@ -50,10 +49,9 @@ public CornerProbePathPreview(String title) {
glut = new GLUT();
}

public void setContext(ProbeParameters pc, Position startWork, Position startMachine) {
public void setContext(ProbeParameters pc, Position startWork) {
this.pc = pc;
this.startWork = startWork;
this.startMachine = startMachine;
}

public void updateSpacing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.gl2.GLUT;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import com.willwinder.ugs.nbm.visualizer.shared.Renderable;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW;
import com.willwinder.ugs.platform.probe.ProbeParameters;
import com.willwinder.ugs.platform.probe.ProbeSettings;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.model.Position;

import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW;
import com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.Triangle;
import static com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.drawArrow;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.model.Position;
import com.willwinder.universalgcodesender.model.UnitUtils;

/**
*
Expand Down Expand Up @@ -217,14 +216,16 @@ public HoleCenterPathPreview() {
ProbeSettings.addPreferenceChangeListener(e -> this.hcDiameter = ProbeSettings.getHcDiameter());
}

public void setContext(ProbeParameters pc, Position startWork, Position startMachine) {
public void setContext(ProbeParameters pc, Position startWork) {
this.pc = pc;
this.startWork = startWork;
}

@Override
public void updateSettings() {
updateSpacing(ProbeSettings.getHcDiameter());
UnitUtils.Units settingsUnits = ProbeSettings.getSettingsUnits();
double scaleFactor = UnitUtils.scaleUnits(settingsUnits, UnitUtils.Units.MM);
updateSpacing(ProbeSettings.getHcDiameter() * scaleFactor);
}

@Override
Expand Down

0 comments on commit 3eb1055

Please sign in to comment.