Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added some radio buttons to control units for jogging. Closes #54
  • Loading branch information
winder committed Nov 15, 2014
1 parent 5e57ce1 commit b6bb048
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 24 deletions.
50 changes: 44 additions & 6 deletions src/com/willwinder/universalgcodesender/MainWindow.form
Expand Up @@ -23,6 +23,8 @@
<Property name="text" type="java.lang.String" value="jMenuItem4"/>
</Properties>
</Component>
<Component class="javax.swing.ButtonGroup" name="jogUnitsGroup">
</Component>
<Menu class="javax.swing.JMenuBar" name="mainMenuBar">
<SubComponents>
<Menu class="javax.swing.JMenu" name="settingsMenu">
Expand Down Expand Up @@ -675,7 +677,7 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="keyboardMovementPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="80" max="32767" attributes="0"/>
<EmptySpace min="0" pref="33" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
Expand Down Expand Up @@ -733,13 +735,21 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="arrowMovementEnabled" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="movementButtonPanel" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="stepSizeLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stepSizeSpinner" min="-2" pref="70" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="inchRadioButton" min="-2" max="-2" attributes="0"/>
<Component id="stepSizeLabel" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="stepSizeSpinner" min="-2" pref="70" max="-2" attributes="0"/>
</Group>
<Component id="mmRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="movementButtonPanel" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
Expand All @@ -752,8 +762,12 @@
<Component id="stepSizeSpinner" linkSize="1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="movementButtonPanel" min="-2" max="-2" attributes="0"/>
<Component id="inchRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="mmRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="movementButtonPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -880,6 +894,30 @@
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="inchRadioButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="jogUnitsGroup"/>
</Property>
<Property name="text" type="java.lang.String" value="inch"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="inchRadioButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JRadioButton" name="mmRadioButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="jogUnitsGroup"/>
</Property>
<Property name="text" type="java.lang.String" value="millimeters"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mmRadioButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="performHomingCycleButton">
Expand Down
88 changes: 77 additions & 11 deletions src/com/willwinder/universalgcodesender/MainWindow.java
Expand Up @@ -35,7 +35,6 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.universalgcodesender.uielements.GrblFirmwareSettingsDialog;
import com.willwinder.universalgcodesender.uielements.StepSizeSpinnerModel;
import com.willwinder.universalgcodesender.visualizer.VisualizerWindow;
import com.willwinder.universalgcodesender.Version;
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import java.awt.Color;
Expand All @@ -57,7 +56,6 @@ This file is part of Universal Gcode Sender (UGS).
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -74,7 +72,7 @@ This file is part of Universal Gcode Sender (UGS).
*/
public class MainWindow extends javax.swing.JFrame
implements KeyListener, ControllerListener, MainWindowAPI {
private static String VERSION = Version.getVersion() + " " + Version.getTimestamp();
final private static String VERSION = Version.getVersion() + " " + Version.getTimestamp();
private PendantUI pendantUI;
private Settings settings;

Expand All @@ -98,6 +96,7 @@ private void initComponents() {
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jogUnitsGroup = new javax.swing.ButtonGroup();
scrollWindowCheckBox = new javax.swing.JCheckBox();
bottomTabbedPane = new javax.swing.JTabbedPane();
jScrollPane2 = new javax.swing.JScrollPane();
Expand Down Expand Up @@ -142,6 +141,8 @@ private void initComponents() {
zPlusButton = new javax.swing.JButton();
yPlusButton = new javax.swing.JButton();
stepSizeLabel = new javax.swing.JLabel();
inchRadioButton = new javax.swing.JRadioButton();
mmRadioButton = new javax.swing.JRadioButton();
performHomingCycleButton = new javax.swing.JButton();
killAlarmLock = new javax.swing.JButton();
toggleCheckMode = new javax.swing.JButton();
Expand Down Expand Up @@ -583,17 +584,40 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
stepSizeLabel.setText("Step size:");
stepSizeLabel.setEnabled(false);

jogUnitsGroup.add(inchRadioButton);
inchRadioButton.setText("inch");
inchRadioButton.setEnabled(false);
inchRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inchRadioButtonActionPerformed(evt);
}
});

jogUnitsGroup.add(mmRadioButton);
mmRadioButton.setText("millimeters");
mmRadioButton.setEnabled(false);
mmRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mmRadioButtonActionPerformed(evt);
}
});

org.jdesktop.layout.GroupLayout keyboardMovementPanelLayout = new org.jdesktop.layout.GroupLayout(keyboardMovementPanel);
keyboardMovementPanel.setLayout(keyboardMovementPanelLayout);
keyboardMovementPanelLayout.setHorizontalGroup(
keyboardMovementPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(arrowMovementEnabled)
.add(movementButtonPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(keyboardMovementPanelLayout.createSequentialGroup()
.addContainerGap()
.add(stepSizeLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stepSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(movementButtonPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(keyboardMovementPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(keyboardMovementPanelLayout.createSequentialGroup()
.add(keyboardMovementPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(inchRadioButton)
.add(stepSizeLabel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stepSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(mmRadioButton)))
);
keyboardMovementPanelLayout.setVerticalGroup(
keyboardMovementPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
Expand All @@ -604,8 +628,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.add(stepSizeLabel)
.add(stepSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(inchRadioButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(mmRadioButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(movementButtonPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

keyboardMovementPanelLayout.linkSize(new java.awt.Component[] {stepSizeLabel, stepSizeSpinner}, org.jdesktop.layout.GroupLayout.VERTICAL);
Expand Down Expand Up @@ -1862,6 +1890,14 @@ private void customGcodeText5ActionPerformed(java.awt.event.ActionEvent evt) {//
this.settings.setCustomGcode5(this.customGcodeText5.getText());
}//GEN-LAST:event_customGcodeText5ActionPerformed

private void inchRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inchRadioButtonActionPerformed
this.inDefaultUnits = false;
}//GEN-LAST:event_inchRadioButtonActionPerformed

private void mmRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mmRadioButtonActionPerformed
this.inDefaultUnits = false;
}//GEN-LAST:event_mmRadioButtonActionPerformed

private void executeCustomGcode(String str)
{
str = str.replaceAll("(\\r\\n|\\n\\r|\\r|\\n)", "");
Expand Down Expand Up @@ -1927,6 +1963,9 @@ public static void main(String args[]) {
/* Apply the settings to the MainWindow bofore showing it */
mw.arrowMovementEnabled.setSelected(mw.settings.isManualModeEnabled());
mw.stepSizeSpinner.setValue(mw.settings.getManualModeStepSize());
boolean unitsAreMM = mw.settings.getDefaultUnits() == "mm";
mw.mmRadioButton.setSelected(unitsAreMM);
mw.inchRadioButton.setSelected(!unitsAreMM);
mw.fileChooser = new JFileChooser(mw.settings.getFileName());
mw.commPortComboBox.setSelectedItem(mw.settings.getPort());
mw.baudrateSelectionComboBox.setSelectedItem(mw.settings.getPortRate());
Expand Down Expand Up @@ -1979,6 +2018,7 @@ public void run() {
mw.settings.setFileName(mw.fileChooser.getSelectedFile().getAbsolutePath());
}

mw.settings.setDefaultUnits(mw.inchRadioButton.isSelected() ? "inch" : "mm");
mw.settings.setManualModeStepSize(mw.getStepSize());
mw.settings.setManualModeEnabled(mw.arrowMovementEnabled.isSelected());
mw.settings.setPort(mw.commPortComboBox.getSelectedItem().toString());
Expand Down Expand Up @@ -2125,7 +2165,18 @@ public void adjustManualLocation(int dirX, int dirY, int dirZ, double stepSize)
String formattedStepSize = formatter.format(stepSize);

// Build G91 command.
StringBuilder command = new StringBuilder("G91 G0 ");
StringBuilder command = new StringBuilder();

// Set jog command to the preferred units.
if (!this.inDefaultUnits) {
if (this.inchRadioButton.isSelected())
command.append("G20 ");
else
command.append("G21 ");
this.inDefaultUnits = true;
}

command.append("G91 G0 ");

if (dirX != 0) {
command.append(" X");
Expand Down Expand Up @@ -2296,6 +2347,8 @@ private void updateManualControls(boolean enabled) {
this.zPlusButton.setEnabled(enabled);
this.stepSizeLabel.setEnabled(enabled);
this.stepSizeSpinner.setEnabled(enabled);
this.inchRadioButton.setEnabled(enabled);
this.mmRadioButton.setEnabled(enabled);
}

private void updateWorkflowControls(boolean enabled) {
Expand Down Expand Up @@ -2391,7 +2444,9 @@ private void setLocalLabels() {
this.stepSizeLabel.setText(Localization.getString("mainWindow.swing.stepSizeLabel"));
this.visualizeButton.setText(Localization.getString("mainWindow.swing.visualizeButton"));
this.workPositionLabel.setText(Localization.getString("mainWindow.swing.workPositionLabel"));
this.macroInstructions.setText(Localization.getString("mainWindow.swing.macroInstructions")+"yep");
this.macroInstructions.setText(Localization.getString("mainWindow.swing.macroInstructions"));
this.inchRadioButton.setText(Localization.getString("mainWindow.swing.inchRadioButton"));
this.mmRadioButton.setText(Localization.getString("mainWindow.swing.mmRadioButton"));
}

// Scans for comm ports and puts them in the comm port combo box.
Expand Down Expand Up @@ -2629,6 +2684,14 @@ public void commandComment(String comment) {

@Override
public void commandComplete(final GcodeCommand command) {
String gcodeString = command.getCommandString().toLowerCase();

// Check if the units were changed away from the default.
if ((this.inchRadioButton.isSelected() && gcodeString.contains("g21")) ||
(this.mmRadioButton.isSelected() && gcodeString.contains("g20"))) {
this.inDefaultUnits = false;
}

java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -2741,7 +2804,7 @@ public void updateSystemState(SystemStateBean systemStateBean) {
private int sentRows = 0;
private long jobEstimate = 0L;
private boolean G91Mode = false;

private boolean inDefaultUnits = false;
// Other windows
VisualizerWindow vw = null;

Expand Down Expand Up @@ -2800,12 +2863,14 @@ public enum ControlState {
private javax.swing.JMenuItem grblConnectionSettingsMenuItem;
private javax.swing.JMenuItem grblFirmwareSettingsMenuItem;
private javax.swing.JButton helpButtonMachineControl;
private javax.swing.JRadioButton inchRadioButton;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.ButtonGroup jogUnitsGroup;
private javax.swing.JPanel keyboardMovementPanel;
private javax.swing.JButton killAlarmLock;
private javax.swing.JLabel latestCommentLabel;
Expand All @@ -2822,6 +2887,7 @@ public enum ControlState {
private javax.swing.JLabel macroInstructions;
private javax.swing.JPanel macroPanel;
private javax.swing.JMenuBar mainMenuBar;
private javax.swing.JRadioButton mmRadioButton;
private javax.swing.JPanel movementButtonPanel;
private javax.swing.JButton opencloseButton;
private javax.swing.JButton pauseButton;
Expand Down
9 changes: 8 additions & 1 deletion src/com/willwinder/universalgcodesender/Settings.java
Expand Up @@ -27,7 +27,7 @@ public class Settings {
private boolean convertArcsToLines = false;
private double smallArcThreshold = 2.0;
private double smallArcSegmentLength = 1.3;

private String defaultUnits = "mm";
private String customGcode1 = "G91 X0 Y0;";
private String customGcode2 = "";
private String customGcode3 = "";
Expand Down Expand Up @@ -223,6 +223,13 @@ public void setPendantConfig(PendantConfigBean pendantConfig) {
this.pendantConfig = pendantConfig;
}

public String getDefaultUnits() {
return defaultUnits;
}

public void setDefaultUnits(String units) {
defaultUnits = units;
}

public String getCustomGcode1() {
return customGcode1;
Expand Down
Expand Up @@ -103,7 +103,7 @@ public void updateRow(final GcodeCommand command) {

// Check for modified command string
if (commandString != getModel().getValueAt(row, COL_INDEX_COMMAND)) {
System.out.printf("Row mismatch [%s] does not match row %d [%s].]n", commandString, row, getModel().getValueAt(row, COL_INDEX_COMMAND) ) ;
System.out.printf("Row mismatch [%s] does not match row %d [%s].]\n", commandString, row, getModel().getValueAt(row, COL_INDEX_COMMAND) ) ;
}

getModel().setValueAt(command.isSent(), row, COL_INDEX_SENT);
Expand Down

0 comments on commit b6bb048

Please sign in to comment.