diff --git a/src/main/java/ch/psi/mxsc/Controller.java b/src/main/java/ch/psi/mxsc/Controller.java index d90d841..c128ee0 100644 --- a/src/main/java/ch/psi/mxsc/Controller.java +++ b/src/main/java/ch/psi/mxsc/Controller.java @@ -3,6 +3,7 @@ */ package ch.psi.mxsc; +import ch.psi.mxsc.Puck.PuckType; import ch.psi.pshell.core.Context; import ch.psi.pshell.core.DevicePool; import ch.psi.pshell.core.DevicePoolListener; @@ -43,6 +44,37 @@ public class Controller { Esera; } + public enum PuckTypes { + unipuck, + minispine, + mixed + } + + PuckTypes puckTypes = PuckTypes.mixed; + + public PuckTypes getPuckTypes() { + return puckTypes; + } + + void updatePuckTypes(){ + try{ + puckTypes = PuckTypes.valueOf(getMainFrame().eval("get_puck_types()", true).toString()); + } catch( Exception ex){ + puckTypes = PuckTypes.mixed; + } + switch(puckTypes){ + case unipuck: + setSinglePuckType(PuckType.Unipuck); + break; + case minispine: + setSinglePuckType(PuckType.Minispine); + break; + case mixed: + //setSinglePuckType(PuckType.Unknown); + break; + } + } + final PuckSensorAccess puckSensorAccess = PuckSensorAccess.RaspberryPi; static String PUCK_ESERA_DEVICE = "onewire"; @@ -55,7 +87,7 @@ public class Controller { for (int i = 0; i < NUMBER_OF_PUCKS; i++) { puckState[i] = new PuckState(i + 1); } - this.mainFrame = (MainPanel)mainFrame; + this.mainFrame = (MainPanel) mainFrame; instance = this; } @@ -102,7 +134,7 @@ public class Controller { } } hexiposi = (Device) getMainFrame().getDevice("hexiposi"); - if (hexiposi!=null){ + if (hexiposi != null) { hexiposi.addListener(new DeviceAdapter() { @Override public void onValueChanged(Device device, Object value, Object former) { @@ -119,11 +151,11 @@ public class Controller { public PuckState[] getPuckStates() { return puckState; } - - public Puck getPuck(String name){ + + public Puck getPuck(String name) { return basePlate.getPuckByName(name); } - + EseraDetection detection; //From 1 to PUCKS_NUMBER @@ -161,7 +193,7 @@ public class Controller { try { return getMainFrame().eval("is_led_room_temp()", true).equals(true); } catch (Exception ex) { - return null; + return null; } } @@ -169,26 +201,26 @@ public class Controller { try { return getMainFrame().eval("is_room_temp()", true).equals(true); } catch (Exception ex) { - return null; + return null; } } - - public String getWorkingMode(){ + + public String getWorkingMode() { try { return String.valueOf(getMainFrame().eval("robot.working_mode", true)); } catch (Exception ex) { - return "Unknown"; - } + return "Unknown"; + } } - - public boolean isManualMode(){ + + public boolean isManualMode() { try { return getMainFrame().eval("is_manual_mode()", true).equals(true); } catch (Exception ex) { - return false; + return false; } } - + public void imageDetectPucks() throws Context.ContextStateException { imageDetectPucks(null, null, null); } @@ -203,7 +235,7 @@ public class Controller { Map> map = (Map>) ret; setImageDetection(map); } else { - getMainFrame().showException((Exception)ex); + getMainFrame().showException((Exception) ex); } return ret; }); @@ -213,21 +245,32 @@ public class Controller { public void clearImageDetection() throws Context.ContextStateException, ScriptException, IOException, InterruptedException { Map> map = (Map>) getMainFrame().eval("clear_detection(None)"); setImageDetection(map); - updateView(); + updateView(); } - void setImageDetection(Map> map){ - for (Puck.ImageDetection id : Puck.ImageDetection.values()) { - for (String name : map.get(id.toString())) { + void setImageDetection(Map> map) { + for (Puck.PuckType puckType : Puck.PuckType.values()) { + for (String name : map.get(puckType.toString())) { Puck p = basePlate.getPuckByName(name); if (p != null) { - p.setImageDetection(id); + p.setPuckType(puckType); } } - } + } } - + + void setSinglePuckType(Puck.PuckType puckType) { + for (Puck p : basePlate.getPucks()) { + p.setPuckType(puckType); + } + } + void resetPuckTypes() { + for (Puck p : basePlate.getPucks()) { + p.setPuckType(Puck.PuckType.Unknown); + } + } + BasePlatePanel puckPanel; void onPuckPressed(Puck puck){ //JPanel panel = new SinglePuckPanel(puck); diff --git a/src/main/java/ch/psi/mxsc/MainPanel.form b/src/main/java/ch/psi/mxsc/MainPanel.form index 419f8a6..33ecba2 100644 --- a/src/main/java/ch/psi/mxsc/MainPanel.form +++ b/src/main/java/ch/psi/mxsc/MainPanel.form @@ -86,13 +86,13 @@ - - + + - - + + @@ -274,12 +274,12 @@ - + - + @@ -321,24 +321,32 @@ + + + - - - + + + + + + - + - + + + @@ -346,6 +354,14 @@ + + + + + + + + @@ -361,12 +377,12 @@ - - - - + + + + - + @@ -394,7 +410,7 @@ - + @@ -476,11 +492,11 @@ - + - + @@ -590,6 +606,8 @@ + + @@ -606,11 +624,15 @@ - + - + - + + + + + @@ -654,6 +676,22 @@ + + + + + + + + + + + + + + + + diff --git a/src/main/java/ch/psi/mxsc/MainPanel.java b/src/main/java/ch/psi/mxsc/MainPanel.java index 0418baf..4ba4944 100644 --- a/src/main/java/ch/psi/mxsc/MainPanel.java +++ b/src/main/java/ch/psi/mxsc/MainPanel.java @@ -1,7 +1,6 @@ /* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ - package ch.psi.mxsc; import ch.psi.pshell.core.Plugin; @@ -12,53 +11,67 @@ import ch.psi.pshell.imaging.RendererMode; import ch.psi.pshell.imaging.Source; import ch.psi.pshell.ui.App; import ch.psi.pshell.ui.Panel; +import ch.psi.utils.Config; +import ch.psi.utils.swing.ConfigDialog; +import ch.psi.utils.swing.PropertiesDialog; +import ch.psi.utils.swing.StandardDialog; import ch.psi.utils.swing.SwingUtils; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dialog; import java.awt.Dimension; +import java.awt.Frame; import java.awt.GridBagLayout; import java.awt.Image; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.WindowConstants; /** * */ public class MainPanel extends Panel { - /** Creates new form Panel */ - - public MainPanel() { - initComponents(); + + /** + * Creates new form Panel + */ + + public MainPanel() { + initComponents(); getContext().getPluginManager().addDynamicClass(PuckDetection.class); Controller.createInstance(this); - basePlatePanel.setMode(BasePlatePanel.Mode.single); + basePlatePanel.setMode(BasePlatePanel.Mode.single); labelRoomTemperature.setVisible(false); labeManualMode.setVisible(false); setExpertMode(false); setDefaultDetail(); } - - @Override - protected void onLoaded(){ - if (App.isDetached()){ + + @Override + protected void onLoaded() { + if (App.isDetached()) { Image img = new ImageIcon(this.getClass().getResource("/apple_transparent_white_100x50.png")).getImage(); - SwingUtils.getWindow(this).setIconImage(img); + SwingUtils.getWindow(this).setIconImage(img); } } - - @Override - public void onInitialize(int runCount) { + + @Override + public void onInitialize(int runCount) { stopTimer(); Controller.getInstance().onInitialize(runCount); - basePlatePanel.setDevice((Device) getDevice("BasePlate")); - basePlatePanel.getDevice().setSelectable(true); - try{ + basePlatePanel.setDevice((Device) getDevice("BasePlate")); + basePlatePanel.getDevice().setSelectable(true); + try { devicesPanel.initialize(); ((Device) getDevice("dewar_level")).addListener(new DeviceAdapter() { @Override @@ -74,7 +87,7 @@ public class MainPanel extends Panel { updateFillingDeware(value); } }); - updateFillingDeware(((Device) getDevice("filling_dewar")).take()); + updateFillingDeware(((Device) getDevice("filling_dewar")).take()); ((Device) getDevice("ln2_main_power")).addListener(new DeviceAdapter() { @Override @@ -82,7 +95,7 @@ public class MainPanel extends Panel { updateFillingControl(value); } }); - updateFillingControl(((Device) getDevice("ln2_main_power")).take()); + updateFillingControl(((Device) getDevice("ln2_main_power")).take()); ((Device) getDevice("air_pressure_ok")).addListener(new DeviceAdapter() { @Override @@ -114,10 +127,11 @@ public class MainPanel extends Panel { updatePsysSafety(value); } }); - updatePsysSafety(((Device) getDevice("feedback_psys_safety")).take()); - } catch (Exception ex){ - this.getLogger().log(Level.SEVERE,null, ex); + updatePsysSafety(((Device) getDevice("feedback_psys_safety")).take()); + } catch (Exception ex) { + this.getLogger().log(Level.SEVERE, null, ex); } + Controller.getInstance().updatePuckTypes(); startTimer(10000, 1000); updateCameraView(); @@ -126,230 +140,233 @@ public class MainPanel extends Panel { @Override protected void onTimer() { devicesPanel.update(); - try{ + try { labelRoomTemperature.setVisible(Controller.getInstance().isRoomTemp()); - } catch( Exception ex){ + } catch (Exception ex) { labelRoomTemperature.setVisible(false); } - try{ + try { labeManualMode.setVisible(Controller.getInstance().isManualMode()); - } catch( Exception ex){ + } catch (Exception ex) { labeManualMode.setVisible(false); - } - } - - void updateLevel(Object value){ - if ((value == null) || !(value instanceof Number)){ + } + } + + void updateLevel(Object value) { + if ((value == null) || !(value instanceof Number)) { progressLN2.setIndeterminate(true); } else { progressLN2.setIndeterminate(false); - double val = ((Number)value).doubleValue() * 10.0; - progressLN2.setValue(Math.min(Math.max((int)val, 0), 1000)); - } + double val = ((Number) value).doubleValue() * 10.0; + progressLN2.setValue(Math.min(Math.max((int) val, 0), 1000)); + } } - - void updateFillingDeware(Object value){ - if ((value == null) || !(value instanceof Boolean)){ + + void updateFillingDeware(Object value) { + if ((value == null) || !(value instanceof Boolean)) { ledFillingDewar.setColor(Color.BLACK); - } else if ((Boolean)value){ + } else if ((Boolean) value) { ledFillingDewar.setColor(Color.GREEN); } else { ledFillingDewar.setColor(Color.BLACK); - } - } - - void updateFillingControl(Object value){ - if ((value == null) || !(value instanceof Boolean)){ + } + } + + void updateFillingControl(Object value) { + if ((value == null) || !(value instanceof Boolean)) { ledFillingControl.setColor(Color.BLACK); - } else if ((Boolean)value){ + } else if ((Boolean) value) { ledFillingControl.setColor(Color.GREEN); } else { ledFillingControl.setColor(Color.BLACK); - } - } - - void updateAirPressure(Object value){ - if ((value == null) || !(value instanceof Boolean)){ + } + } + + void updateAirPressure(Object value) { + if ((value == null) || !(value instanceof Boolean)) { ledAirPressure.setColor(Color.BLACK); - } else if ((Boolean)value){ + } else if ((Boolean) value) { ledAirPressure.setColor(Color.GREEN); } else { ledAirPressure.setColor(Color.RED); - } - } - - void updateN2Pressure(Object value){ - if ((value == null) || !(value instanceof Boolean)){ + } + } + + void updateN2Pressure(Object value) { + if ((value == null) || !(value instanceof Boolean)) { ledN2Pressure.setColor(Color.BLACK); - } else if ((Boolean)value){ + } else if ((Boolean) value) { ledN2Pressure.setColor(Color.GREEN); } else { ledN2Pressure.setColor(Color.RED); - } - } + } + } - void updateLocalSafety(Object value){ - if ((value == null) || !(value instanceof Boolean)){ + void updateLocalSafety(Object value) { + if ((value == null) || !(value instanceof Boolean)) { ledLocalSafety.setColor(Color.BLACK); - } else if ((Boolean)value){ + } else if ((Boolean) value) { ledLocalSafety.setColor(Color.GREEN); } else { ledLocalSafety.setColor(Color.RED); - } - } + } + } - void updatePsysSafety(Object value){ - if ((value == null) || !(value instanceof Boolean)){ + void updatePsysSafety(Object value) { + if ((value == null) || !(value instanceof Boolean)) { ledPsysSafety.setColor(Color.BLACK); - } else if ((Boolean)value){ + } else if ((Boolean) value) { ledPsysSafety.setColor(Color.GREEN); } else { ledPsysSafety.setColor(Color.RED); - } - } - - void updateCameraView(){ - Source source = buttonCamera.isSelected() ? (Source)this.getDevice("img"): null; - basePlatePanel.setCameraView(source); + } } - void execute(String statement){ + void updateCameraView() { + Source source = buttonCamera.isSelected() ? (Source) this.getDevice("img") : null; + basePlatePanel.setCameraView(source); + } + + void execute(String statement) { execute(statement, false); } - - void execute(String statement, boolean background){ + + void execute(String statement, boolean background) { execute(statement, background, false); } - - void execute(String statement, boolean background, boolean showReturn){ + + void execute(String statement, boolean background, boolean showReturn) { try { evalAsync(statement, background).handle((ret, ex) -> { - if (ex != null){ - showException((Exception)ex); - } else if (showReturn){ + if (ex != null) { + showException((Exception) ex); + } else if (showReturn) { showMessage("Return", String.valueOf(ret)); } return ret; }); } catch (Exception ex) { showException(ex); - } + } } - - - void execute(String script, Object args, boolean background, boolean showReturn){ + + void execute(String script, Object args, boolean background, boolean showReturn) { try { runAsync(script, args, background).handle((ret, ex) -> { - if (ex != null){ - showException((Exception)ex); - } else if (showReturn){ + if (ex != null) { + showException((Exception) ex); + } else if (showReturn) { showMessage("Return", String.valueOf(ret)); } return ret; }); } catch (Exception ex) { showException(ex); - } - } - - void updateViewType(){ - try{ + } + } + + void updateViewType() { + try { updateCameraView(); } catch (Exception ex) { showException(ex); - } - + } + } - + boolean viewDewar = true; RoomTempBasePlatePanel roomTempPanel; - void updateViewMode(){ - try{ - if (btViewDewar.isSelected() != viewDewar){ + + void updateViewMode() { + try { + if (btViewDewar.isSelected() != viewDewar) { viewDewar = btViewDewar.isSelected(); - if (viewDewar){ - ((GroupLayout)getLayout()).replace(roomTempPanel, basePlatePanel); + if (viewDewar) { + ((GroupLayout) getLayout()).replace(roomTempPanel, basePlatePanel); } else { - if (roomTempPanel == null){ + if (roomTempPanel == null) { roomTempPanel = new RoomTempBasePlatePanel(); roomTempPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("RT Humidifier")); } - ((GroupLayout)getLayout()).replace(basePlatePanel, roomTempPanel); + ((GroupLayout) getLayout()).replace(basePlatePanel, roomTempPanel); } } } catch (Exception ex) { showException(ex); - } - + } + } - - - void setExpertMode(boolean expert){ + + void setExpertMode(boolean expert) { buttonExpertCommands.setVisible(expert); buttonRecovery.setVisible(expert); buttonCalibrateImage.setVisible(expert); + buttonCalibrateCover.setVisible(expert); devicesPanel.setActive(expert); buttonRelease.setVisible(expert); panelViewType.setVisible(expert); panelDetection.setVisible(expert); - - if (checkExpert.isSelected()!=expert){ - checkExpert.setSelected(expert); + buttonDetectCover.setVisible(expert); + buttonConfig.setVisible(expert); + + if (checkExpert.isSelected() != expert) { + checkExpert.setSelected(expert); } - if (expert==false){ + if (expert == false) { buttonCamera.setSelected(false); buttonDrawing.setSelected(true); - updateViewType(); + updateViewType(); } } - + Plugin commandsPlugin; - void showCommandsPanel(){ - if (commandsPlugin!=null){ + + void showCommandsPanel() { + if (commandsPlugin != null) { getContext().getPluginManager().unloadPlugin(commandsPlugin); } commandsPlugin = getContext().getPluginManager().loadInitializePlugin(getContext().getSetup().expandPath("{plugins}/Commands.java")); } - + Plugin recoveryPlugin; - void showRecoveryPanel(){ - if (recoveryPlugin!=null){ + + void showRecoveryPanel() { + if (recoveryPlugin != null) { getContext().getPluginManager().unloadPlugin(recoveryPlugin); } - recoveryPlugin = getContext().getPluginManager().loadInitializePlugin(getContext().getSetup().expandPath("{plugins}/Recovery.java")); + recoveryPlugin = getContext().getPluginManager().loadInitializePlugin(getContext().getSetup().expandPath("{plugins}/Recovery.java")); } - - - void setDefaultDetail() { + + void setDefaultDetail() { JLabel label = new JLabel(); - label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/apple_transparent_white_100x50.png"))); - JPanel panel = new JPanel(); + label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/apple_transparent_white_100x50.png"))); + JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); panel.add(label); setDetail(panel); //setContext(label); } - + void setDetail(Component c) { panelContext.removeAll(); - panelContext.setLayout(new BorderLayout()); + panelContext.setLayout(new BorderLayout()); //panelContext.setLayout(new GridBagLayout()); panelContext.add(c); updateUI(); } - + Component getDetail() { return this.getComponent(0); } - - Dimension getDetailSize(){ + + Dimension getDetailSize() { return panelContext.getSize(); } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents @@ -372,6 +389,7 @@ public class MainPanel extends Panel { buttonPuckDet = new javax.swing.JButton(); panelHexiposi = new javax.swing.JPanel(); hexiposiPanel = new ch.psi.mxsc.HexiposiPanel(); + buttonDetectCover = new javax.swing.JButton(); panelViewType = new javax.swing.JPanel(); buttonCamera = new javax.swing.JToggleButton(); buttonDrawing = new javax.swing.JToggleButton(); @@ -392,6 +410,8 @@ public class MainPanel extends Panel { buttonExpertCommands = new javax.swing.JButton(); buttonRecovery = new javax.swing.JButton(); buttonCalibrateImage = new javax.swing.JButton(); + buttonCalibrateCover = new javax.swing.JButton(); + buttonConfig = new javax.swing.JButton(); jPanel4 = new javax.swing.JPanel(); ledFillingControl = new ch.psi.pshell.swing.Led(); ledFillingDewar = new ch.psi.pshell.swing.Led(); @@ -533,11 +553,11 @@ public class MainPanel extends Panel { panelDetectionLayout.setHorizontalGroup( panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelDetectionLayout.createSequentialGroup() - .addContainerGap(12, Short.MAX_VALUE) + .addContainerGap(14, Short.MAX_VALUE) .addGroup(panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(buttonClearDet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPuckDet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(12, Short.MAX_VALUE)) + .addContainerGap(14, Short.MAX_VALUE)) ); panelDetectionLayout.setVerticalGroup( panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -550,22 +570,34 @@ public class MainPanel extends Panel { ); panelHexiposi.setBorder(javax.swing.BorderFactory.createTitledBorder("Cover")); + panelHexiposi.setPreferredSize(new java.awt.Dimension(112, 153)); + + buttonDetectCover.setText("Image"); + buttonDetectCover.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDetectCoverActionPerformed(evt); + } + }); javax.swing.GroupLayout panelHexiposiLayout = new javax.swing.GroupLayout(panelHexiposi); panelHexiposi.setLayout(panelHexiposiLayout); panelHexiposiLayout.setHorizontalGroup( panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelHexiposiLayout.createSequentialGroup() - .addGap(0, 4, Short.MAX_VALUE) - .addComponent(hexiposiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 4, Short.MAX_VALUE)) + .addContainerGap(13, Short.MAX_VALUE) + .addGroup(panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(buttonDetectCover) + .addComponent(hexiposiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(14, Short.MAX_VALUE)) ); panelHexiposiLayout.setVerticalGroup( panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelHexiposiLayout.createSequentialGroup() - .addGap(0, 24, Short.MAX_VALUE) + .addContainerGap(15, Short.MAX_VALUE) .addComponent(hexiposiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(35, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE) + .addComponent(buttonDetectCover) + .addContainerGap()) ); panelViewType.setBorder(javax.swing.BorderFactory.createTitledBorder("View")); @@ -578,7 +610,7 @@ public class MainPanel extends Panel { }); buttonDrawing.setSelected(true); - buttonDrawing.setText("Drawing"); + buttonDrawing.setText("Design"); buttonDrawing.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonDrawingActionPerformed(evt); @@ -590,11 +622,11 @@ public class MainPanel extends Panel { panelViewTypeLayout.setHorizontalGroup( panelViewTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelViewTypeLayout.createSequentialGroup() - .addGap(2, 2, 2) - .addGroup(panelViewTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonCamera, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonDrawing)) - .addGap(2, 2, 2)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(panelViewTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(buttonDrawing) + .addComponent(buttonCamera)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); panelViewTypeLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonCamera, buttonDrawing}); @@ -616,16 +648,16 @@ public class MainPanel extends Panel { .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, basePlatePanelLayout.createSequentialGroup() .addContainerGap() .addGroup(basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(panelLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(panelDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(panelLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(panelViewType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelHexiposi, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(panelHexiposi, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(panelViewType, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); - basePlatePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {panelDetection, panelHexiposi, panelLegend, panelViewType}); + basePlatePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {panelDetection, panelViewType}); basePlatePanelLayout.setVerticalGroup( basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -685,11 +717,11 @@ public class MainPanel extends Panel { .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(progressLN2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap(65, Short.MAX_VALUE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -774,6 +806,20 @@ public class MainPanel extends Panel { } }); + buttonCalibrateCover.setText("Cover Ref"); + buttonCalibrateCover.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCalibrateCoverActionPerformed(evt); + } + }); + + buttonConfig.setText("Config"); + buttonConfig.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigActionPerformed(evt); + } + }); + javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup( @@ -786,7 +832,9 @@ public class MainPanel extends Panel { .addComponent(buttonExpertCommands, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(checkExpert, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonRecovery, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonCalibrateImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(buttonCalibrateImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonCalibrateCover, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonConfig, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); jPanel5Layout.setVerticalGroup( @@ -799,11 +847,15 @@ public class MainPanel extends Panel { .addComponent(checkExpert) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonExpertCommands) - .addGap(18, 18, 18) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(buttonRecovery) - .addGap(18, 18, 18) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(buttonCalibrateImage) - .addGap(49, 49, 49)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonCalibrateCover) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonConfig) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("LN2 Control")); @@ -1158,9 +1210,8 @@ public class MainPanel extends Panel { .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); @@ -1171,15 +1222,15 @@ public class MainPanel extends Panel { private void buttonCameraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCameraActionPerformed buttonDrawing.setSelected(!buttonCamera.isSelected()); - updateViewType(); + updateViewType(); }//GEN-LAST:event_buttonCameraActionPerformed private void buttonExpertCommandsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExpertCommandsActionPerformed - try{ + try { showCommandsPanel(); } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonExpertCommandsActionPerformed //Dialog dlgDetPlot; @@ -1188,9 +1239,9 @@ public class MainPanel extends Panel { JComponent dlgDetPlotComp; JComponent dlgDetTextComp; JComponent dlgDetRendererComp; - + private void buttonPuckDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPuckDetActionPerformed - try{ + try { /* if ((dlgDetPlot == null) || (!dlgDetPlot.isShowing())){ dlgDetPlotComp = new ch.psi.pshell.plot.LinePlotJFree(); @@ -1202,27 +1253,27 @@ public class MainPanel extends Panel { ((javax.swing.JTextArea)dlgDetTextComp).setEditable(false); dlgDetText = SwingUtils.showDialog(getTopLevel(), "Puck Detection", new Dimension(600,400), dlgDetTextComp); } - */ - if (!App.isDetached()){ - if ((dlgDetRenderer == null)|| (!dlgDetRenderer.isShowing())){ + */ + if (!App.isDetached()) { + if ((dlgDetRenderer == null) || (!dlgDetRenderer.isShowing())) { dlgDetRendererComp = new Renderer(); - ((Renderer)dlgDetRendererComp).setMode(RendererMode.Fit); - dlgDetRenderer = SwingUtils.showDialog(getTopLevel(), "Puck Detection", new Dimension(600,400), dlgDetRendererComp); - } + ((Renderer) dlgDetRendererComp).setMode(RendererMode.Fit); + dlgDetRenderer = SwingUtils.showDialog(getTopLevel(), "Puck Detection", new Dimension(600, 400), dlgDetRendererComp); + } } Controller.getInstance().imageDetectPucks(dlgDetPlotComp, dlgDetRendererComp, dlgDetTextComp); } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonPuckDetActionPerformed private void buttonClearDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearDetActionPerformed - try{ + try { Controller.getInstance().clearImageDetection(); } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonClearDetActionPerformed private void buttonReleaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReleaseActionPerformed @@ -1253,25 +1304,78 @@ public class MainPanel extends Panel { }//GEN-LAST:event_btViewRTActionPerformed private void buttonRecoveryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRecoveryActionPerformed - try{ + try { showRecoveryPanel(); } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonRecoveryActionPerformed private void buttonCalibrateImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrateImageActionPerformed execute("imgproc/CameraCalibration", null, false, true); }//GEN-LAST:event_buttonCalibrateImageActionPerformed + private void buttonDetectCoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetectCoverActionPerformed + try { + execute("cover_detection_debug=True"); + runAsync("imgproc/CoverDetection", null, false).handle((ret, ex) -> { + execute("cover_detection_debug=False", true); + if (ex != null) { + showException((Exception) ex); + } else { + showMessage("Return", String.valueOf(ret)); + } + return ret; + }); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonDetectCoverActionPerformed + + private void buttonCalibrateCoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrateCoverActionPerformed + execute("imgproc/CoverDetectionCalibration", null, false, true); + }//GEN-LAST:event_buttonCalibrateCoverActionPerformed + + private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed + try { + final PropertiesDialog dlg = new PropertiesDialog((Frame) getTopLevelAncestor(), false); + dlg.setTitle("System Configuration"); + Properties props = new Properties(); + String fileName = getSessionPath() + "/OpenedFiles.dat"; + try (FileInputStream in = new FileInputStream(fileName)) { + props.load(in); + } + + dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + dlg.setListener((StandardDialog sd, boolean accepted) -> { + if (sd.getResult()) { + try (FileOutputStream out = new FileOutputStream(fileName);) { + props.store(out, null); + } catch (IOException ex) { + SwingUtils.showException(MainPanel.this, ex); + } + } + }); + dlg.setVisible(true); + SwingUtils.centerComponent(getTopLevelAncestor(), dlg); + dlg.requestFocus(); + + } catch (Exception ex) { + SwingUtils.showException(MainPanel.this, ex); + } + }//GEN-LAST:event_buttonConfigActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private ch.psi.mxsc.BasePlatePanel basePlatePanel; private javax.swing.JToggleButton btViewDewar; private javax.swing.JToggleButton btViewRT; + private javax.swing.JButton buttonCalibrateCover; private javax.swing.JButton buttonCalibrateImage; private javax.swing.JToggleButton buttonCamera; private javax.swing.JButton buttonClearDet; + private javax.swing.JButton buttonConfig; + private javax.swing.JButton buttonDetectCover; private javax.swing.JToggleButton buttonDrawing; private javax.swing.JButton buttonExpertCommands; private javax.swing.JButton buttonInitHexiposi1; diff --git a/src/main/java/ch/psi/mxsc/Puck.java b/src/main/java/ch/psi/mxsc/Puck.java index cf8cbfe..d8de0bf 100644 --- a/src/main/java/ch/psi/mxsc/Puck.java +++ b/src/main/java/ch/psi/mxsc/Puck.java @@ -82,17 +82,17 @@ public class Puck extends DeviceBase { final static PointDouble labelPositionWithImage = new PointDouble(0.0, 36.0); - ImageDetection imageDetection = ImageDetection.Unknown; + PuckType puckType = PuckType.Unknown; - public ImageDetection getImageDetection(){ - return imageDetection; + public PuckType getPuckType(){ + return puckType; } - public void setImageDetection(ImageDetection value){ - imageDetection = value; + public void setPuckType(PuckType value){ + puckType = value; } - public enum ImageDetection{ + public enum PuckType{ Empty, Minispine, Unipuck, @@ -306,8 +306,8 @@ public class Puck extends DeviceBase { ret = isHighlithted() ? new Color(212, 212, 212) : Color.LIGHT_GRAY; break; case Present: - if ((imageDetection != null) && (imageDetection != ImageDetection.Unknown)){ - switch (imageDetection){ + if ((puckType != null) && (puckType != PuckType.Unknown)){ + switch (puckType){ case Minispine: ret = isHighlithted() ? new Color(0, 200, 80) : new Color(128, 232, 152); break;