Skip to content

Commit

Permalink
First implementation round. GCodeDriver Axis management is still redu…
Browse files Browse the repository at this point in the history
…ndantly in there.
  • Loading branch information
markmaker committed May 2, 2020
1 parent c6c100e commit 51ea613
Show file tree
Hide file tree
Showing 19 changed files with 994 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/main/java/org/openpnp/gui/support/AxesComboBoxModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2020 <mark@makr.zone>
* inspired and based on work
* Copyright (C) 2011 Jason von Nieda <jason@vonnieda.org>
*
* This file is part of OpenPnP.
*
* OpenPnP 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.
*
* OpenPnP 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 OpenPnP. If not, see
* <http://www.gnu.org/licenses/>.
*
* For more information about OpenPnP visit http://openpnp.org
*/

package org.openpnp.gui.support;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import javax.swing.DefaultComboBoxModel;

import org.openpnp.spi.Axis;
import org.openpnp.spi.base.AbstractControllerAxis;
import org.openpnp.spi.base.AbstractMachine;

@SuppressWarnings({"serial", "rawtypes"})
public class AxesComboBoxModel extends DefaultComboBoxModel implements PropertyChangeListener {
private Comparator<Axis> comparator = new Comparator<Axis>() {
@Override
public int compare(Axis o1, Axis o2) {
return o1.getName().compareTo(o2.getName());
}
};
final private AbstractMachine machine;
final private boolean addEmpty;
final private boolean controllerOnly;

public AxesComboBoxModel(AbstractMachine machine, boolean controllerOnly, boolean addEmpty) {
this.machine = machine;
this.addEmpty = addEmpty;
this.controllerOnly = controllerOnly;
addAllElements();
if (machine != null) { // we're not in Window Builder Design Mode
this.machine.addPropertyChangeListener("axes", this);
}
}

private void addAllElements() {
if (machine == null) {
return;// we're in Window Builder Design Mode
}
ArrayList<Axis> axes = null;
axes = new ArrayList<>(machine.getAxes());
Collections.sort(axes, comparator);
for (Axis axis : axes) {
if (!controllerOnly || axis instanceof AbstractControllerAxis) {
addElement(axis.getName());
}
}
if (addEmpty) {
addElement(new String());
}
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
removeAllElements();
addAllElements();
}
}
54 changes: 54 additions & 0 deletions src/main/java/org/openpnp/gui/support/NamedConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2019 <mark@makr.zone>
*
* This file is part of OpenPnP.
*
* OpenPnP 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.
*
* OpenPnP 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 OpenPnP. If not, see
* <http://www.gnu.org/licenses/>.
*
* For more information about OpenPnP visit http://openpnp.org
*/

package org.openpnp.gui.support;

import java.util.List;

import org.jdesktop.beansbinding.Converter;
import org.openpnp.model.Named;

public class NamedConverter<NamedType extends Named> extends Converter<NamedType, String> {
final List<NamedType> pool;

public NamedConverter(List<NamedType> pool) {
super();
this.pool = pool;
}

@Override
public String convertForward(NamedType named) {
if (named == null) {
return "";
}
else {
return named.getName();
}
}

@Override
public NamedType convertReverse(String s) {
for (NamedType named : pool) {
if (named.getName().equals(s)) {
return named;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2020 <mark@makr.zone>
* inspired and based on work
* Copyright (C) 2011 Jason von Nieda <jason@vonnieda.org>
*
* This file is part of OpenPnP.
*
* OpenPnP 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.
*
* OpenPnP 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 OpenPnP. If not, see
* <http://www.gnu.org/licenses/>.
*
* For more information about OpenPnP visit http://openpnp.org
*/

package org.openpnp.gui.wizards;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import org.openpnp.gui.components.ComponentDecorators;
import org.openpnp.gui.support.AbstractConfigurationWizard;
import org.openpnp.machine.reference.ReferenceControllerAxis;
import org.openpnp.spi.Axis;
import org.openpnp.spi.base.AbstractAxis;

import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec;

@SuppressWarnings("serial")
public abstract class AbstractAxisConfigurationWizard extends AbstractConfigurationWizard {
protected JPanel panelProperties;
protected JLabel lblName;
protected JTextField name;
protected JLabel lblType;
protected JComboBox type;

public AbstractAxisConfigurationWizard() {
panelProperties = new JPanel();
panelProperties.setBorder(new TitledBorder(null, "Properties", TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPanel.add(panelProperties);
panelProperties.setLayout(new FormLayout(new ColumnSpec[] {
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,},
new RowSpec[] {
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,}));

lblType = new JLabel("Type");
panelProperties.add(lblType, "2, 2, right, default");

type = new JComboBox(Axis.Type.values());
panelProperties.add(type, "4, 2, fill, default");

lblName = new JLabel("Name");
panelProperties.add(lblName, "2, 4, right, default");

name = new JTextField();
panelProperties.add(name, "4, 4, fill, default");
name.setColumns(20);
}

protected abstract AbstractAxis getAxis();

@Override
public void createBindings() {
addWrappedBinding(getAxis(), "type", type, "selectedItem");
addWrappedBinding(getAxis(), "name", name, "text");

ComponentDecorators.decorateWithAutoSelect(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (C) 2020 <mark@makr.zone>
* inspired and based on work
* Copyright (C) 2011 Jason von Nieda <jason@vonnieda.org>
*
* This file is part of OpenPnP.
*
* OpenPnP 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.
*
* OpenPnP 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 OpenPnP. If not, see
* <http://www.gnu.org/licenses/>.
*
* For more information about OpenPnP visit http://openpnp.org
*/

package org.openpnp.gui.wizards;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.openpnp.gui.support.AxesComboBoxModel;
import org.openpnp.gui.support.NamedConverter;
import org.openpnp.model.Configuration;
import org.openpnp.spi.Axis;
import org.openpnp.spi.base.AbstractControllerAxis;
import org.openpnp.spi.base.AbstractMachine;

import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.ComboBoxModel;

@SuppressWarnings("serial")
public abstract class AbstractTransformedAxisConfigurationWizard extends AbstractAxisConfigurationWizard {
protected final AbstractMachine machine;

protected JPanel panelTransformation;
protected JComboBox inputAxisX;
protected JLabel lblInputAxisY;
protected JComboBox inputAxisY;
protected JLabel lblInputAxisX;
protected JLabel lblInputAxisZ;
protected JComboBox inputAxisZ;
protected JLabel lblInputAxisRotation;
protected JComboBox inputAxisRotation;

public AbstractTransformedAxisConfigurationWizard(AbstractMachine machine) {
super();
this.machine = machine;

panelTransformation = new JPanel();
panelTransformation.setBorder(new TitledBorder(null, getTransformationSettingsTitle(), TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPanel.add(panelTransformation);
panelTransformation.setLayout(new FormLayout(new ColumnSpec[] {
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("default:grow"),},
new RowSpec[] {
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,}));

lblInputAxisX = new JLabel("Input X");
panelTransformation.add(lblInputAxisX, "2, 2, right, default");

inputAxisX = new JComboBox(new AxesComboBoxModel(machine, true, true));
panelTransformation.add(inputAxisX, "4, 2, fill, default");

lblInputAxisY = new JLabel("Input Y");
panelTransformation.add(lblInputAxisY, "2, 4, right, default");

inputAxisY = new JComboBox(new AxesComboBoxModel(machine, true, true));
panelTransformation.add(inputAxisY, "4, 4, fill, default");

lblInputAxisZ = new JLabel("Input Z");
panelTransformation.add(lblInputAxisZ, "2, 6, right, default");

inputAxisZ = new JComboBox(new AxesComboBoxModel(machine, true, true));
panelTransformation.add(inputAxisZ, "4, 6, fill, default");

lblInputAxisRotation = new JLabel("Input Rotation");
panelTransformation.add(lblInputAxisRotation, "2, 8, right, default");

inputAxisRotation = new JComboBox(new AxesComboBoxModel(machine, true, true));
panelTransformation.add(inputAxisRotation, "4, 8, fill, default");
}

protected abstract String getTransformationSettingsTitle();

@Override
public void createBindings() {
super.createBindings();
NamedConverter<Axis> axisConverter = new NamedConverter<>(machine.getAxes());

addWrappedBinding(getAxis(), "inputAxisX", inputAxisX, "selectedItem", axisConverter);
addWrappedBinding(getAxis(), "inputAxisY", inputAxisY, "selectedItem", axisConverter);
addWrappedBinding(getAxis(), "inputAxisZ", inputAxisZ, "selectedItem", axisConverter);
addWrappedBinding(getAxis(), "inputAxisRotation", inputAxisRotation, "selectedItem", axisConverter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.openpnp.machine.reference;

import javax.swing.Icon;

import org.openpnp.gui.support.Wizard;
import org.openpnp.machine.reference.wizards.ReferenceControllerAxisConfigurationWizard;
import org.openpnp.spi.base.AbstractControllerAxis;

public class ReferenceControllerAxis extends AbstractControllerAxis {

@Override
public Wizard getConfigurationWizard() {
return new ReferenceControllerAxisConfigurationWizard(this);
}

}

0 comments on commit 51ea613

Please sign in to comment.