Skip to content

Commit

Permalink
- Filter PlacementsTableModel, show only active board side.
Browse files Browse the repository at this point in the history
- Added option to AutoHome after machine enabled. To activate, need to set checkbox in machine settings.
- Windows saves sizes and position in Multiple Windows Mode
- Save configureation menu button
- Camera window can be split in vertical or horizontal style
- Added new approach to pick rotation for Strip Feeder. To activate, need to set checkbox in machine settings.
- Some changes in job order. Now user can change job order by sorting table.
- Job autosave after each placement.
- Added peel off actuator option for Drag Feeder.
- Drag Feeder improve accurance of feed, now drag distance can be addaptive with vision enablde.
- Drag Feeder can work with 0402.
  • Loading branch information
aneox committed Jul 2, 2018
1 parent 5131a74 commit 618594b
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ installers
.classpath
src/main/resources/icons/src/Soft_Scraps_by_deleket
.github_changelog_generator
hs_err*
*.log
8 changes: 7 additions & 1 deletion src/main/java/org/openpnp/gui/JobPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import org.openpnp.util.FiniteStateMachine;
import org.openpnp.util.MovableUtils;
import org.openpnp.util.UiUtils;
import org.pmw.tinylog.Logger;

import com.google.common.eventbus.Subscribe;

Expand Down Expand Up @@ -245,7 +246,12 @@ else if (e.getFirstRow() == 0 && e.getLastRow() == Integer.MAX_VALUE) {
updatePanelizationIconState();

}

if (job.getBoardLocations().size() > 0) {
BoardLocation boardLocation = getSelectedBoardLocation();
jobPlacementsPanel.setBoardLocation(boardLocation);
}
else
jobPlacementsPanel.setBoardLocation(null);
}
});

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/org/openpnp/gui/JobPlacementsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.PatternSyntaxException;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand All @@ -26,11 +27,13 @@
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableRowSorter;

import org.openpnp.events.PlacementSelectedEvent;
import org.openpnp.gui.components.AutoSelectTextTable;
Expand Down Expand Up @@ -60,10 +63,12 @@
import org.openpnp.util.MovableUtils;
import org.openpnp.util.UiUtils;
import org.openpnp.util.Utils2D;
import org.pmw.tinylog.Logger;

public class JobPlacementsPanel extends JPanel {
private JTable table;
private PlacementsTableModel tableModel;
private TableRowSorter<PlacementsTableModel> tableSorter;
private ActionGroup boardLocationSelectionActionGroup;
private ActionGroup singleSelectionActionGroup;
private ActionGroup multiSelectionActionGroup;
Expand Down Expand Up @@ -143,9 +148,10 @@ public JobPlacementsPanel(JobPanel jobPanel) {
toolBarPlacements.add(btnEditFeeder);

tableModel = new PlacementsTableModel(configuration);
tableSorter = new TableRowSorter<>(tableModel);

table = new AutoSelectTextTable(tableModel);
table.setAutoCreateRowSorter(true);
table.setRowSorter(tableSorter);
table.getTableHeader().setDefaultRenderer(new MultisortTableHeaderCellRenderer());
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setDefaultEditor(Side.class, new DefaultCellEditor(sidesComboBox));
Expand Down Expand Up @@ -258,6 +264,17 @@ public void setBoardLocation(BoardLocation boardLocation) {
else {
tableModel.setBoardLocation(boardLocation);
boardLocationSelectionActionGroup.setEnabled(true);

RowFilter<PlacementsTableModel, Object> rf = null;
// If current expression doesn't parse, don't update.
try {
rf = RowFilter.regexFilter("(?i)" + boardLocation.getSide().toString());
}
catch (PatternSyntaxException e) {
Logger.warn("Side sort failed", e);
return;
}
tableSorter.setRowFilter(rf);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/openpnp/gui/MachineControlsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ public void actionPerformed(ActionEvent arg0) {
Machine machine = Configuration.get().getMachine();
boolean enable = !machine.isEnabled();
try {
Configuration.get().getMachine().setEnabled(enable);
setEnabled(true);
Configuration.get().getMachine().setEnabled(enable);
setEnabled(true);
if (machine.getHomeAfterEnabled() && machine.isEnabled()) {
selectedTool.getHead().home();
}
}
catch (Exception t1) {
MessageBoxes.errorBox(MachineControlsPanel.this, "Enable Failure",
Expand Down
108 changes: 105 additions & 3 deletions src/main/java/org/openpnp/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ public class MainFrame extends JFrame {
private static final String PREF_WINDOW_STYLE_MULTIPLE = "MainFrame.windowStyleMultiple";
private static final boolean PREF_WINDOW_STYLE_MULTIPLE_DEF = false;

private static final String PREF_CAMERA_WINDOW_X = "CameraFrame.windowX";
private static final int PREF_CAMERA_WINDOW_X_DEF = 0;
private static final String PREF_CAMERA_WINDOW_Y = "CameraFrame.windowY";
private static final int PREF_CAMERA_WINDOW_Y_DEF = 0;
private static final String PREF_CAMERA_WINDOW_WIDTH = "CameraFrame.windowWidth";
private static final int PREF_CAMERA_WINDOW_WIDTH_DEF = 800;
private static final String PREF_CAMERA_WINDOW_HEIGHT = "CameraFrame.windowHeight";
private static final int PREF_CAMERA_WINDOW_HEIGHT_DEF = 600;

private static final String PREF_MACHINECONTROLS_WINDOW_X = "MachineControlsFrame.windowX";
private static final int PREF_MACHINECONTROLS_WINDOW_X_DEF = 0;
private static final String PREF_MACHINECONTROLS_WINDOW_Y = "MachineControlsFrame.windowY";
private static final int PREF_MACHINECONTROLS_WINDOW_Y_DEF = 0;
private static final String PREF_MACHINECONTROLS_WINDOW_WIDTH = "MachineControlsFrame.windowWidth";
private static final int PREF_MACHINECONTROLS_WINDOW_WIDTH_DEF = 490;
private static final String PREF_MACHINECONTROLS_WINDOW_HEIGHT = "MachineControlsFrame.windowHeight";
private static final int PREF_MACHINECONTROLS_WINDOW_HEIGHT_DEF = 340;

private final Configuration configuration;

private static MainFrame mainFrame;
Expand All @@ -120,6 +138,8 @@ public class MainFrame extends JFrame {
private JPanel panelCameraAndInstructions;
private JPanel panelMachine;
private MachineSetupPanel machineSetupPanel;
private JDialog frameCamera;
private JDialog frameMachineControls;

public static MainFrame get() {
return mainFrame;
Expand Down Expand Up @@ -232,6 +252,8 @@ public void windowClosing(WindowEvent e) {
mnFile.addSeparator();
mnFile.add(new JMenuItem(jobPanel.saveJobAction));
mnFile.add(new JMenuItem(jobPanel.saveJobAsAction));
mnFile.addSeparator();
mnFile.add(new JMenuItem(saveConfigAction));


// File -> Import
Expand Down Expand Up @@ -564,21 +586,47 @@ public void propertyChange(PropertyChangeEvent evt) {
public void splitWindows() {
if (prefs.getBoolean(PREF_WINDOW_STYLE_MULTIPLE, PREF_WINDOW_STYLE_MULTIPLE_DEF)) {
// pin panelCameraAndInstructions to a separate JFrame
JDialog frameCamera = new JDialog(this, "OpenPnp - Camera", false);
frameCamera = new JDialog(this, "OpenPnp - Camera", false);
// as of today no smart way found to get an adjusted size
// ... so main window size is used for the camera window
frameCamera.setSize(getFrames()[0].getSize());
frameCamera.add(panelCameraAndInstructions);
frameCamera.setVisible(true);
frameCamera.addComponentListener(cameraWindowListener);

if (prefs.getInt(PREF_CAMERA_WINDOW_WIDTH, 50) < 50) {
prefs.putInt(PREF_CAMERA_WINDOW_WIDTH, PREF_CAMERA_WINDOW_WIDTH_DEF);
}

if (prefs.getInt(PREF_CAMERA_WINDOW_HEIGHT, 50) < 50) {
prefs.putInt(PREF_CAMERA_WINDOW_HEIGHT, PREF_CAMERA_WINDOW_HEIGHT_DEF);
}

frameCamera.setBounds(prefs.getInt(PREF_CAMERA_WINDOW_X, PREF_CAMERA_WINDOW_X_DEF),
prefs.getInt(PREF_CAMERA_WINDOW_Y, PREF_CAMERA_WINDOW_Y_DEF),
prefs.getInt(PREF_CAMERA_WINDOW_WIDTH, PREF_CAMERA_WINDOW_WIDTH_DEF),
prefs.getInt(PREF_CAMERA_WINDOW_HEIGHT, PREF_CAMERA_WINDOW_HEIGHT_DEF));

// pin machineControlsPanel to a separate JFrame
JDialog frameMachineControls = new JDialog(this, "OpenPnp - Machine Controls", false);
frameMachineControls = new JDialog(this, "OpenPnp - Machine Controls", false);
// as of today no smart way found to get an adjusted size
// ... so hardcoded values used (usually not a good idea)
frameMachineControls.add(machineControlsPanel);
frameMachineControls.setVisible(true);
frameMachineControls.pack();
frameMachineControls.addComponentListener(machineControlsWindowListener);

if (prefs.getInt(PREF_MACHINECONTROLS_WINDOW_WIDTH, 50) < 50) {
prefs.putInt(PREF_MACHINECONTROLS_WINDOW_WIDTH, PREF_MACHINECONTROLS_WINDOW_WIDTH_DEF);
}

if (prefs.getInt(PREF_MACHINECONTROLS_WINDOW_HEIGHT, 50) < 50) {
prefs.putInt(PREF_MACHINECONTROLS_WINDOW_HEIGHT, PREF_MACHINECONTROLS_WINDOW_HEIGHT_DEF);
}

frameMachineControls.setBounds(prefs.getInt(PREF_MACHINECONTROLS_WINDOW_X, PREF_MACHINECONTROLS_WINDOW_X_DEF),
prefs.getInt(PREF_MACHINECONTROLS_WINDOW_Y, PREF_MACHINECONTROLS_WINDOW_Y_DEF),
prefs.getInt(PREF_MACHINECONTROLS_WINDOW_WIDTH, PREF_MACHINECONTROLS_WINDOW_WIDTH_DEF),
prefs.getInt(PREF_MACHINECONTROLS_WINDOW_HEIGHT, PREF_MACHINECONTROLS_WINDOW_HEIGHT_DEF));
// move the splitPaneDivider to position 0 to fill the gap of the
// relocated panels 'panelCameraAndInstructions' & 'machineControlsPanel'
splitPaneMachineAndTabs.setDividerLocation(0);
Expand Down Expand Up @@ -700,6 +748,25 @@ public void about() {
dialog.setVisible(true);
}

public boolean saveConfig() {
// Save the configuration
try {
configuration.save();
}
catch (Exception e) {
String message = "There was a problem saving the configuration. The reason was:\n\n" + e.getMessage()
+ "\n\n";
message = message.replaceAll("\n", "<br/>");
message = message.replaceAll("\r", "");
message = "<html><body width=\"400\">" + message + "</body></html>";
JOptionPane.showMessageDialog(this, message, "Configuration Save Error", JOptionPane.ERROR_MESSAGE);
return false;
}

Logger.debug("Config saved successfully!");
return true;
}

public boolean quit() {
Logger.info("Shutting down...");
try {
Expand Down Expand Up @@ -772,6 +839,34 @@ public void componentResized(ComponentEvent e) {
}
};

private ComponentListener cameraWindowListener = new ComponentAdapter() {
@Override
public void componentMoved(ComponentEvent e) {
prefs.putInt(PREF_CAMERA_WINDOW_X, frameCamera.getLocation().x);
prefs.putInt(PREF_CAMERA_WINDOW_Y, frameCamera.getLocation().y);
}

@Override
public void componentResized(ComponentEvent e) {
prefs.putInt(PREF_CAMERA_WINDOW_WIDTH, frameCamera.getSize().width);
prefs.putInt(PREF_CAMERA_WINDOW_HEIGHT, frameCamera.getSize().height);
}
};

private ComponentListener machineControlsWindowListener = new ComponentAdapter() {
@Override
public void componentMoved(ComponentEvent e) {
prefs.putInt(PREF_MACHINECONTROLS_WINDOW_X, frameMachineControls.getLocation().x);
prefs.putInt(PREF_MACHINECONTROLS_WINDOW_Y, frameMachineControls.getLocation().y);
}

@Override
public void componentResized(ComponentEvent e) {
prefs.putInt(PREF_MACHINECONTROLS_WINDOW_WIDTH, frameMachineControls.getSize().width);
prefs.putInt(PREF_MACHINECONTROLS_WINDOW_HEIGHT, frameMachineControls.getSize().height);
}
};

private Action inchesUnitSelected = new AbstractAction(LengthUnit.Inches.name()) {
{
putValue(MNEMONIC_KEY, KeyEvent.VK_I);
Expand Down Expand Up @@ -816,6 +911,13 @@ public void actionPerformed(ActionEvent arg0) {
}
};

private Action saveConfigAction = new AbstractAction("Save configuration") {
@Override
public void actionPerformed(ActionEvent arg0) {
saveConfig();
}
};

private Action quitAction = new AbstractAction("Exit") {
{
putValue(MNEMONIC_KEY, KeyEvent.VK_X);
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/openpnp/gui/components/CameraPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
public class CameraPanel extends JPanel {
private static int maximumFps = 15;
private static final String SHOW_NONE_ITEM = "Show None";
private static final String SHOW_ALL_ITEM = "Show All";
private static final String SHOW_ALL_ITEM_H = "Show All Horizontal";
private static final String SHOW_ALL_ITEM_V = "Show All Vertical";

private Map<Camera, CameraView> cameraViews = new LinkedHashMap<>();

Expand Down Expand Up @@ -111,7 +112,8 @@ public void addCamera(Camera camera) {
else if (cameraViews.size() == 2) {
// Otherwise this is the second camera so mix in the
// show all item.
camerasCombo.insertItemAt(SHOW_ALL_ITEM, 1);
camerasCombo.insertItemAt(SHOW_ALL_ITEM_H, 1);
camerasCombo.insertItemAt(SHOW_ALL_ITEM_V, 2);
}
}

Expand Down Expand Up @@ -154,7 +156,7 @@ private void createUi() {
* @return
*/
public void ensureCameraVisible(Camera camera) {
if (camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM)) {
if (camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM_H) || camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM_V)) {
return;
}
setSelectedCamera(camera);
Expand Down Expand Up @@ -193,12 +195,16 @@ public void actionPerformed(ActionEvent ev) {
camerasPanel.add(panel);
selectedCameraView = null;
}
else if (camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM)) {
else if (camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM_H) || camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM_V)) {
int rows = (int) Math.ceil(Math.sqrt(cameraViews.size()));
if (rows == 0) {
rows = 1;
}
camerasPanel.setLayout(new GridLayout(rows, 0, 1, 1));
if (camerasCombo.getSelectedItem().equals(SHOW_ALL_ITEM_H))
camerasPanel.setLayout(new GridLayout(rows, 0, 1, 1));
else
camerasPanel.setLayout(new GridLayout(0, rows, 1, 1));

for (CameraView cameraView : cameraViews.values()) {
cameraView.setMaximumFps(maximumFps / Math.max(cameraViews.size(), 1));
cameraView.setShowName(true);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/openpnp/machine/reference/ReferenceMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class ReferenceMachine extends AbstractMachine {
@Element(required = false)
protected FiducialLocator fiducialLocator = new ReferenceFiducialLocator();

@Element(required = false)
private boolean homeAfterEnabled = false;

@Element(required = false)
private boolean usePickRotationInsteadOfRotationInTapeForStripFeeders = false;

private boolean enabled;

private List<Class<? extends Feeder>> registeredFeederClasses = new ArrayList<>();
Expand Down Expand Up @@ -298,4 +304,20 @@ public PnpJobProcessor getPnpJobProcessor() {
public PasteDispenseJobProcessor getPasteDispenseJobProcessor() {
return pasteDispenseJobProcessor;
}

public boolean getHomeAfterEnabled() {
return homeAfterEnabled;
}

public boolean getUsePickRotationInsteadOfRotationInTapeForStripFeeders() {
return usePickRotationInsteadOfRotationInTapeForStripFeeders;
}

public void setHomeAfterEnabled(boolean newValue) {
this.homeAfterEnabled = newValue;
}

public void setUsePickRotationInsteadOfRotationInTapeForStripFeeders(boolean newValue) {
this.usePickRotationInsteadOfRotationInTapeForStripFeeders = newValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.openpnp.machine.reference;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -426,8 +427,9 @@ protected void doPlan() throws Exception {
fireTextStatus("Planning placements.");

// Get the list of unfinished placements and sort them by part height.

List<JobPlacement> jobPlacements = getPendingJobPlacements().stream()
.sorted(Comparator.comparing(JobPlacement::getPartHeight))
.sorted(Comparator.comparing(JobPlacement::getPartId))
.collect(Collectors.toList());

if (jobPlacements.isEmpty()) {
Expand Down Expand Up @@ -788,6 +790,10 @@ protected void doPlace() throws Exception {
}

Logger.debug("Place {} with {}", part, nozzle.getName());

File file = job.getFile();
Configuration.get().saveJob(job, file);
Configuration.get().save();
}

clearStepComplete();
Expand Down
Loading

0 comments on commit 618594b

Please sign in to comment.