diff --git a/config/plugins.properties b/config/plugins.properties index 417bb79..3c08d64 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,5 +1,5 @@ Cameras.java=enabled LaserGunAlignment.java=disabled test2.java=disabled -GunSolenoidAlignment.java=enabled +GunSolenoidAlignment.java=disabled test.java=disabled diff --git a/devices/S10BC02-DSCR220.properties b/devices/S10BC02-DSCR220.properties new file mode 100644 index 0000000..c65f5c8 --- /dev/null +++ b/devices/S10BC02-DSCR220.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 13:07:24 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=true +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/S10BC02-DSRM310.properties b/devices/S10BC02-DSRM310.properties new file mode 100644 index 0000000..f4210ae --- /dev/null +++ b/devices/S10BC02-DSRM310.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 13:07:30 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=true +scale=1.0 +spatialCalOffsetX=0.0 +spatialCalOffsetY=0.0 +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/S10BD01-DSCR030.properties b/devices/S10BD01-DSCR030.properties new file mode 100644 index 0000000..fe14ace --- /dev/null +++ b/devices/S10BD01-DSCR030.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 13:07:27 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=true +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/S10DI01-DSCR020.properties b/devices/S10DI01-DSCR020.properties new file mode 100644 index 0000000..ac879c3 --- /dev/null +++ b/devices/S10DI01-DSCR020.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 13:08:31 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=true +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/S10MA01-DSCR090.properties b/devices/S10MA01-DSCR090.properties new file mode 100644 index 0000000..52a4453 --- /dev/null +++ b/devices/S10MA01-DSCR090.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 12:30:16 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/SARBD01-DSCR050.properties b/devices/SARBD01-DSCR050.properties new file mode 100644 index 0000000..89f085e --- /dev/null +++ b/devices/SARBD01-DSCR050.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 12:52:45 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/SARBD01-DSCR110.properties b/devices/SARBD01-DSCR110.properties new file mode 100644 index 0000000..e099471 --- /dev/null +++ b/devices/SARBD01-DSCR110.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 13:09:04 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=true +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/SLG-LCAM-L122.properties b/devices/SLG-LCAM-L122.properties new file mode 100644 index 0000000..576bf1c --- /dev/null +++ b/devices/SLG-LCAM-L122.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 12:53:52 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/SLG-LCAM-L123.properties b/devices/SLG-LCAM-L123.properties new file mode 100644 index 0000000..70fb673 --- /dev/null +++ b/devices/SLG-LCAM-L123.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 12:52:53 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/SLG-LCAM-L124.properties b/devices/SLG-LCAM-L124.properties new file mode 100644 index 0000000..66fd244 --- /dev/null +++ b/devices/SLG-LCAM-L124.properties @@ -0,0 +1,26 @@ +#Fri Aug 26 13:08:36 CEST 2016 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +flipHorizontally=false +flipVertically=false +grayscale=false +imageHeight=0 +imageWidth=0 +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=true +scale=1.0 +spatialCalOffsetX=0.0 +spatialCalOffsetY=0.0 +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/cam1.properties b/devices/cam1.properties index 4a0d48f..1bbf07d 100644 --- a/devices/cam1.properties +++ b/devices/cam1.properties @@ -1,4 +1,4 @@ -#Fri Aug 26 10:58:13 CEST 2016 +#Fri Aug 26 15:33:18 CEST 2016 colormap=Grayscale colormapAutomatic=true colormapMax=30000.0 @@ -6,8 +6,8 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=2160 -imageWidth=2560 +imageHeight=1628 +imageWidth=1280 invert=false offsetX=0.0 offsetY=0.0 diff --git a/devices/cam2.properties b/devices/cam2.properties index 8bfd765..4e846ed 100644 --- a/devices/cam2.properties +++ b/devices/cam2.properties @@ -1,4 +1,4 @@ -#Fri Aug 26 10:58:28 CEST 2016 +#Fri Aug 26 15:33:18 CEST 2016 colormap=Grayscale colormapAutomatic=true colormapMax=255.0 @@ -6,8 +6,8 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=2160 -imageWidth=2560 +imageHeight=1680 +imageWidth=1744 invert=false offsetX=0.0 offsetY=0.0 diff --git a/plugins/Cameras.form b/plugins/Cameras.form index ff9cfab..9348898 100644 --- a/plugins/Cameras.form +++ b/plugins/Cameras.form @@ -16,13 +16,68 @@ - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/Cameras.java b/plugins/Cameras.java index 5ce8d1a..57ff2d4 100644 --- a/plugins/Cameras.java +++ b/plugins/Cameras.java @@ -2,8 +2,24 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import javax.swing.DefaultComboBoxModel; import ch.psi.pshell.ui.Panel; +import ch.psi.pshell.imaging.ImageListener; import ch.psi.utils.State; +import ch.psi.utils.IO; +import ch.psi.utils.swing.SwingUtils; +import ch.psi.pshell.epics.PsiCamera; +import ch.psi.pshell.core.JsonSerializer; +import ch.psi.pshell.imaging.Data; +import java.awt.Dimension; +import java.awt.image.BufferedImage; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; /** * @@ -13,11 +29,31 @@ public class Cameras extends Panel { public Cameras() { initComponents(); } + + final String configFolder= "/afs/psi.ch/intranet/SF/Applications/config/camtool"; + File[] cameraConfigFiles = new File[0]; + PsiCamera camera; + CameraConfig config; //Overridable callbacks @Override public void onInitialize(int runCount) { - + cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"}); + DefaultComboBoxModel model = new DefaultComboBoxModel(); + for (File file:cameraConfigFiles) { + String prefix = IO.getPrefix(file); + if (!prefix.startsWith("#")){ + model.addElement(prefix); + } + } + comboCameras.setModel(model); + if (model.getSize()>0){ + try { + setCamera((String)comboCameras.getSelectedItem()); + } catch (Exception ex) { + } + } + startTimer(1000); } @Override @@ -35,22 +71,193 @@ public class Cameras extends Panel { protected void doUpdate() { } + + public static class CameraConfig{ + public HashMap kwargs; + public ArrayList args; + public ArrayList links; + public String type; + public HashMap state; + public CameraConfig image_source; + public HashMap subcomponents; + + public ArrayList getCalibration(){ + return (ArrayList) state.get("calibration"); + } + public Double getCalibrationHeight(){ + return (Double) state.get("calibration_height"); + } + public Double getCalibrationWidth(){ + return (Double) state.get("calibration_width"); + } + public Double getCalibrationHorizontalAngle(){ + return (Double) state.get("calibration_horizontal_angle"); + } + public Double getCalibrationVerticalAngle(){ + return (Double) state.get("calibration_vertical_angle"); + } + public Boolean getMirrorX(){ + return (Boolean) state.get("mirror_x"); + } + public Boolean getMirrorY(){ + return (Boolean) state.get("mirror_y"); + } + public Integer getRotate(){ + return (Integer) state.get("rotate"); + } + public ArrayList getOrigin(){ + return (ArrayList) state.get("origin"); + } + public ArrayList getRoi(){ + return (ArrayList) state.get("roi"); + } + public Boolean getRoiEnable(){ + if ((state.get("roi_enable")==null) ||(state.get("roi")==null)){ + return false; + } + return (Boolean) state.get("roi_enable"); + } + public ArrayList getUnitSize(){ + return (ArrayList) state.get("unit_size"); + } + + public Integer getRun(){ + return (Integer) state.get("run"); + } + } + + void setCamera(String cameraName) throws IOException, InterruptedException{ + if (camera!=null){ + camera.close(); + camera = null; + } + try{ + Path configFile= Paths.get(configFolder, cameraName + ".json"); + String json = new String(Files.readAllBytes(configFile)); + //SwingUtils.showMessage(null, "", json); + camera = new PsiCamera(cameraName, cameraName); + try{ + config = (CameraConfig) JsonSerializer.decode(json, CameraConfig.class); + camera.getConfig().flipHorizontally = config.getMirrorX(); + camera.getConfig().flipVertically = config.getMirrorY(); + camera.getConfig().rotation = config.getRotate(); + camera.getConfig().rotationCrop = true; + camera.getConfig().roiX = config.getRoiEnable() ? config.getRoi().get(0) : 0; + camera.getConfig().roiY = config.getRoiEnable() ?config.getRoi().get(1) : 0; + camera.getConfig().roiWidth = config.getRoiEnable() ?config.getRoi().get(2) : -1; + camera.getConfig().roiHeight = config.getRoiEnable() ?config.getRoi().get(3): -1; + camera.getConfig().spatialCalOffsetX = (config.getOrigin()!=null) ? config.getOrigin().get(0) : Double.NaN; + camera.getConfig().spatialCalOffsetY = (config.getOrigin()!=null) ? config.getOrigin().get(1) : Double.NaN; + camera.getConfig().spatialCalScaleX = (config.getUnitSize()!=null) && (config.getOrigin().get(0)!=0) ? 1.0/(config.getOrigin().get(0)*1000) : Double.NaN; + camera.getConfig().spatialCalScaleY= (config.getUnitSize()!=null) && (config.getOrigin().get(1)!=0) ? 1.0/(config.getOrigin().get(1)*1000) : Double.NaN; + + } catch (Exception ex){ + config = null; + showException(ex); + } + camera.getConfig().save(); + + camera.addListener(renderer); + camera.addListener(new ImageListener() { + @Override + public void onImage(Object o, BufferedImage bi, Data data) { + if ((renderer.getReticle()!=null) && (bi!=null)){ + renderer.getReticle().setSize(new Dimension(bi.getWidth(), bi.getHeight())); + } + camera.removeListener(this); + } + @Override + public void onError(Object o, Exception excptn) { + } + }); + renderer.setShowReticle(true); + camera.initialize(); + + } finally{ + onTimer(); + } + } + + @Override + protected void onTimer() { + textState.setText((camera==null) ? "" : camera.getState().toString()); + } + @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { + renderer = new ch.psi.pshell.imaging.Renderer(); + jLabel1 = new javax.swing.JLabel(); + comboCameras = new javax.swing.JComboBox(); + jLabel2 = new javax.swing.JLabel(); + textState = new javax.swing.JTextField(); + + jLabel1.setText("Camera:"); + + comboCameras.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboCamerasActionPerformed(evt); + } + }); + + jLabel2.setText("State:"); + + textState.setEditable(false); + textState.setHorizontalAlignment(javax.swing.JTextField.CENTER); + textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); + textState.setEnabled(false); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 449, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(comboCameras, 0, 348, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel2) + .addGap(4, 4, 4) + .addComponent(textState, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))) + .addGap(26, 26, 26)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 137, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE) + .addGap(6, 6, 6)) ); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState}); + }// //GEN-END:initComponents + private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed + try{ + String camera = (String) comboCameras.getSelectedItem(); + setCamera(camera); + } catch(Exception ex){ + showException(ex); + } + }//GEN-LAST:event_comboCamerasActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox comboCameras; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private ch.psi.pshell.imaging.Renderer renderer; + private javax.swing.JTextField textState; // End of variables declaration//GEN-END:variables }