diff --git a/config/settings.properties b/config/settings.properties index 4f0e2bc..140fb84 100644 --- a/config/settings.properties +++ b/config/settings.properties @@ -1,2 +1,2 @@ -#Tue Mar 10 09:05:12 CET 2020 +#Tue Mar 10 09:18:28 CET 2020 FdaBrowser=false diff --git a/config/variables.properties b/config/variables.properties index b292cb0..dbc2f66 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,2 +1,2 @@ -#Mon Mar 09 18:49:49 CET 2020 -FileSequentialNumber=51 +#Tue Mar 10 10:46:04 CET 2020 +FileSequentialNumber=59 diff --git a/plugins/EnergyScan.form b/plugins/EnergyScan.form index edee536..7886cd9 100644 --- a/plugins/EnergyScan.form +++ b/plugins/EnergyScan.form @@ -1,293 +1,293 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
- - - - - - - - - - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - -
-
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+
diff --git a/plugins/EnergyScan.java b/plugins/EnergyScan.java index 8637c3c..e244864 100644 --- a/plugins/EnergyScan.java +++ b/plugins/EnergyScan.java @@ -1,502 +1,522 @@ -import ch.psi.pshell.core.JsonSerializer; -import ch.psi.pshell.epics.Positioner; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.IO; -import ch.psi.utils.State; -import ch.psi.utils.Sys; -import ch.psi.utils.swing.SwingUtils; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.DefaultTableModel; - -/** - * - */ -public class EnergyScan extends Panel { - - final DefaultTableModel model; - Positioner energy; - File currentFile; - public static final String FILE_EXTENSION = "ens"; - public static final String DEFAULT_FOLDER = "{home}/parameters"; - - public EnergyScan() { - initComponents(); - model = (DefaultTableModel) table.getModel(); - } - - //Overridable callbacks - @Override - public void onInitialize(int runCount) { - energy = (Positioner) this.getDevice("energy"); - } - - @Override - public void onStateChange(State state, State former) { - buttonStart.setEnabled(state==State.Ready); - buttonAbort.setEnabled(state.isProcessing()); - buttonScienta.setEnabled(state.isInitialized()); - updateSeq(); - } - - void updateSeq(){ - try{ - textFileId.setText(String.valueOf(getContext().getFileSequentialNumber())); - } catch (Exception ex){ - textFileId.setText(""); - } - } - - @Override - public void onExecutedFile(String fileName, Object result) { - } - - - //Callback to perform update - in event thread - @Override - protected void doUpdate() { - } - - void checkValues(){ - if (model.getRowCount() == 0){ - throw new IllegalArgumentException(); - } - for (int i=0; i< model.getRowCount(); i++){ - Double start = (Double) model.getValueAt(i, 0); - Double stop = (Double) model.getValueAt(i, 1); - Double step = (Double) model.getValueAt(i, 2); - if ( Double.isNaN(start) || Double.isNaN(stop) || Double.isNaN(step) || - (start >= stop) || (step<0) || - (start < energy.getMinValue()) || - (stop > energy.getMaxValue()) ){ - throw new IllegalArgumentException(); - } - } - } - - String getScanName(){ - String name = textName.getText().strip(); - return name.isEmpty() ? null : name; - } - - void start() throws Exception{ - checkValues(); - String lastOutput = getContext().getDataManager().getLastOutput(); - - HashMap args = new HashMap(); - ArrayList regions = new ArrayList(); - for (int i=0; i< model.getRowCount(); i++){ - ArrayList region = new ArrayList(); - region.add(model.getValueAt(i, 0)); - region.add(model.getValueAt(i, 1)); - region.add(model.getValueAt(i, 2)); - regions.add(region); - } - args.put("NAME", getScanName()); - args.put("REGIONS", regions); - this.runAsync("templates/EnergyScan", args).handle((ret,ex)->{ - if (ex!=null){ - } - if (checkAutoSaveArgs.isSelected()){ - //Save scan attributes - String output = getContext().getDataManager().getLastOutput(); - if ((output!=null) && !output.isEmpty() &&!output.equals(lastOutput)){ - try { - save(Paths.get(output + "." + FILE_EXTENSION)); - } catch (IOException e) { - Logger.getLogger(EnergyScan.class.getName()).log(Level.WARNING, null, e); - } - } - } - return ret; - }); - } - - - public void save() throws IOException { - JFileChooser chooser = new JFileChooser(getContext().getSetup().expandPath(DEFAULT_FOLDER)); - FileNameExtensionFilter filter = new FileNameExtensionFilter("Energy scan definition file", FILE_EXTENSION); - chooser.setFileFilter(filter); - chooser.setFileHidingEnabled(false); - try { - if (currentFile != null) { - chooser.setSelectedFile(currentFile); - } else if (getScanName()!=null){ - File file = Paths.get(chooser.getCurrentDirectory().getAbsolutePath(),getScanName()).toFile(); - chooser.setSelectedFile(file); - } - } catch (Exception ex) { - this.showException(ex); - } - int rVal = chooser.showSaveDialog(this); - if (rVal == JFileChooser.APPROVE_OPTION) { - String fileName = chooser.getSelectedFile().getAbsolutePath(); - if (IO.getExtension(chooser.getSelectedFile().getAbsolutePath()).isEmpty()) { - fileName += "." + FILE_EXTENSION; - } - save(Paths.get(fileName)); - } - } - - public void save(Path path) throws IOException { - currentFile = path.toFile(); - ArrayList data = new ArrayList(); - data.add(new Object[][]{new Object[]{textName.getText()}}); - data.add(model.getDataVector()); - String json = JsonSerializer.encode(data, true); - Files.write(path, json.getBytes()); - } - - public void open() throws IOException { - JFileChooser chooser = new JFileChooser(getContext().getSetup().expandPath(DEFAULT_FOLDER)); - FileNameExtensionFilter filter = new FileNameExtensionFilter("Energy scan definition file", FILE_EXTENSION); - chooser.setFileFilter(filter); - chooser.setFileHidingEnabled(true); - - int rVal = chooser.showOpenDialog(this); - if (rVal == JFileChooser.APPROVE_OPTION) { - open(chooser.getSelectedFile().toPath()); - } - } - - public void open(Path path) throws IOException { - String json = new String(Files.readAllBytes(path)); - currentFile = path.toFile(); - Object[][][] vector = (Object[][][]) JsonSerializer.decode(json, Object[][][].class); - textName.setText(String.valueOf(vector[0][0][0])); - model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table)); - } - - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jScrollPane2 = new javax.swing.JScrollPane(); - jEditorPane1 = new javax.swing.JEditorPane(); - buttonStart = new javax.swing.JButton(); - buttonAbort = new javax.swing.JButton(); - checkAutoSaveArgs = new javax.swing.JCheckBox(); - buttonScienta = new javax.swing.JButton(); - jPanel2 = new javax.swing.JPanel(); - textName = new javax.swing.JTextField(); - jPanel1 = new javax.swing.JPanel(); - jScrollPane1 = new javax.swing.JScrollPane(); - table = new javax.swing.JTable(); - buttonAdd = new javax.swing.JButton(); - buttonDelete = new javax.swing.JButton(); - jLabel1 = new javax.swing.JLabel(); - buttonOpen = new javax.swing.JButton(); - buttonSave = new javax.swing.JButton(); - jLabel2 = new javax.swing.JLabel(); - textFileId = new javax.swing.JTextField(); - buttonResetId = new javax.swing.JButton(); - - jScrollPane2.setViewportView(jEditorPane1); - - buttonStart.setText("Start"); - buttonStart.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStartActionPerformed(evt); - } - }); - - buttonAbort.setText("Abort"); - buttonAbort.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonAbortActionPerformed(evt); - } - }); - - checkAutoSaveArgs.setText("Auto save parameters"); - - buttonScienta.setText("Scienta Panel"); - buttonScienta.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonScientaActionPerformed(evt); - } - }); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters")); - - jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Regions")); - - table.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - - }, - new String [] { - "Start", "End", "Step" - } - ) { - Class[] types = new Class [] { - java.lang.Double.class, java.lang.Double.class, java.lang.Double.class - }; - - public Class getColumnClass(int columnIndex) { - return types [columnIndex]; - } - }); - jScrollPane1.setViewportView(table); - - buttonAdd.setText("Add"); - buttonAdd.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonAddActionPerformed(evt); - } - }); - - buttonDelete.setText("Delete"); - buttonDelete.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDeleteActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(buttonAdd) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDelete) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAdd, buttonDelete}); - - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonAdd) - .addComponent(buttonDelete)) - .addContainerGap()) - ); - - jLabel1.setText("Name:"); - - buttonOpen.setText("Open"); - buttonOpen.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonOpenActionPerformed(evt); - } - }); - - buttonSave.setText("Save"); - buttonSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSaveActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textName) - .addGap(18, 18, 18) - .addComponent(buttonOpen) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonSave))) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonOpen, buttonSave}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(textName) - .addComponent(buttonOpen) - .addComponent(buttonSave) - .addComponent(jLabel1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(12, 12, 12)) - ); - - jLabel2.setText("File ID:"); - - textFileId.setEditable(false); - textFileId.setHorizontalAlignment(javax.swing.JTextField.CENTER); - - buttonResetId.setText("Reset"); - buttonResetId.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonResetIdActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(33, 33, 33) - .addComponent(buttonAbort) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(checkAutoSaveArgs) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addComponent(buttonScienta) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonResetId))) - .addContainerGap()))) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart}); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonResetId, textFileId}); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonScienta, checkAutoSaveArgs}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(7, 7, 7) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(checkAutoSaveArgs) - .addComponent(jLabel2) - .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonScienta) - .addComponent(buttonResetId)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonStart) - .addComponent(buttonAbort)) - .addContainerGap()) - ); - }// //GEN-END:initComponents - - private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed - try{ - start(); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonStartActionPerformed - - private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed - try{ - abort(); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonAbortActionPerformed - - private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed - try{ - //model.addRow(new Object[]{energy.getMinValue(), energy.getMaxValue(), 10.0}); - model.addRow(new Object[]{500.0, 1000.0, 100.0}); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonAddActionPerformed - - private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed - try{ - if ((model.getRowCount()>0) && (table.getSelectedRow()>=0)){ - model.removeRow(table.getSelectedRow()); - } - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonDeleteActionPerformed - - private void buttonOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOpenActionPerformed - try{ - open(); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonOpenActionPerformed - - private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed - try{ - save(); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonSaveActionPerformed - - private void buttonScientaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScientaActionPerformed - try{ - this.showDevicePanel("scienta"); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonScientaActionPerformed - - private void buttonResetIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetIdActionPerformed - try{ - this.getContext().setFileSequentialNumber(0); - updateSeq(); - } catch (Exception ex){ - showException(ex); - } - }//GEN-LAST:event_buttonResetIdActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton buttonAbort; - private javax.swing.JButton buttonAdd; - private javax.swing.JButton buttonDelete; - private javax.swing.JButton buttonOpen; - private javax.swing.JButton buttonResetId; - private javax.swing.JButton buttonSave; - private javax.swing.JButton buttonScienta; - private javax.swing.JButton buttonStart; - private javax.swing.JCheckBox checkAutoSaveArgs; - private javax.swing.JEditorPane jEditorPane1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JTable table; - private javax.swing.JTextField textFileId; - private javax.swing.JTextField textName; - // End of variables declaration//GEN-END:variables -} + +import ch.psi.pshell.core.JsonSerializer; +import ch.psi.pshell.epics.Positioner; +import ch.psi.pshell.ui.PanelProcessor; +import ch.psi.utils.IO; +import ch.psi.utils.State; +import ch.psi.utils.swing.SwingUtils; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.DefaultTableModel; + +/** + * + */ +public class EnergyScan extends PanelProcessor { + + final DefaultTableModel model; + Positioner energy; + File currentFile; + public static final String FILE_EXTENSION = "ens"; + + public EnergyScan() { + initComponents(); + model = (DefaultTableModel) table.getModel(); + } + + @Override + public String getType() { + return "Energy Scan"; + } + + @Override + public boolean createMenuNew() { + return true; + } + + @Override + public boolean createFilePanel() { + return true; + } + + @Override + public String getDescription() { + return "Energy scan definition file (*." + FILE_EXTENSION + ")"; + } + + @Override + public String[] getExtensions() { + return new String[]{FILE_EXTENSION}; + } + + @Override + public String getHomePath() { + return "{home}/parameters"; + } + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + energy = (Positioner) getDevice("energy"); + } + + @Override + public void onStateChange(State state, State former) { + buttonStart.setEnabled(state == State.Ready); + buttonAbort.setEnabled(state.isProcessing()); + buttonScienta.setEnabled(state.isInitialized()); + updateSeq(); + } + + void updateSeq() { + try { + textFileId.setText(String.valueOf(getContext().getFileSequentialNumber())); + } catch (Exception ex) { + textFileId.setText(""); + } + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + //Callback to perform update - in event thread + @Override + protected void doUpdate() { + } + + void checkValues() { + if (model.getRowCount() == 0) { + throw new IllegalArgumentException(); + } + Positioner energy = (Positioner) getDevice("energy"); + for (int i = 0; i < model.getRowCount(); i++) { + Double start = (Double) model.getValueAt(i, 0); + Double stop = (Double) model.getValueAt(i, 1); + Double step = (Double) model.getValueAt(i, 2); + if (Double.isNaN(start) || Double.isNaN(stop) || Double.isNaN(step) + || (start >= stop) || (step < 0) + || (start < energy.getMinValue()) + || (stop > energy.getMaxValue())) { + throw new IllegalArgumentException(); + } + } + } + + String getScanName() { + String name = textName.getText().trim(); + return name.isEmpty() ? null : name; + } + + @Override + public void execute() throws Exception { + checkValues(); + String lastOutput = getContext().getDataManager().getLastOutput(); + + HashMap args = new HashMap(); + ArrayList regions = new ArrayList(); + for (int i = 0; i < model.getRowCount(); i++) { + ArrayList region = new ArrayList(); + region.add(model.getValueAt(i, 0)); + region.add(model.getValueAt(i, 1)); + region.add(model.getValueAt(i, 2)); + regions.add(region); + } + args.put("FILE", null); + args.put("NAME", getScanName()); + args.put("REGIONS", regions); + this.runAsync("templates/EnergyScan", args).handle((ret, ex) -> { + if (ex != null) { + } + if (checkAutoSaveArgs.isSelected()) { + //Save scan attributes + String output = getContext().getDataManager().getLastOutput(); + if ((output != null) && !output.isEmpty() && !output.equals(lastOutput)) { + try { + saveAs(output + "." + FILE_EXTENSION); + } catch (IOException e) { + Logger.getLogger(EnergyScan.class.getName()).log(Level.WARNING, null, e); + } + } + } + return ret; + }); + } + + @Override + public void saveAs(String fileName) throws IOException { + currentFile = new File(fileName); + ArrayList data = new ArrayList(); + data.add(new Object[][]{new Object[]{textName.getText()}}); + data.add(model.getDataVector()); + String json = JsonSerializer.encode(data, true); + Files.write(currentFile.toPath(), json.getBytes()); + } + + @Override + public void open(String fileName) throws IOException { + if (fileName==null){ + currentFile = null; + textName.setText(""); + model.setRowCount(0); + } else { + Path path = Paths.get(fileName); + String json = new String(Files.readAllBytes(path)); + currentFile = path.toFile(); + Object[][][] vector = (Object[][][]) JsonSerializer.decode(json, Object[][][].class); + textName.setText(String.valueOf(vector[0][0][0])); + model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table)); + } + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane2 = new javax.swing.JScrollPane(); + jEditorPane1 = new javax.swing.JEditorPane(); + buttonStart = new javax.swing.JButton(); + buttonAbort = new javax.swing.JButton(); + checkAutoSaveArgs = new javax.swing.JCheckBox(); + buttonScienta = new javax.swing.JButton(); + jPanel2 = new javax.swing.JPanel(); + textName = new javax.swing.JTextField(); + jPanel1 = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + table = new javax.swing.JTable(); + buttonAdd = new javax.swing.JButton(); + buttonDelete = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + buttonOpen = new javax.swing.JButton(); + buttonSave = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + textFileId = new javax.swing.JTextField(); + buttonResetId = new javax.swing.JButton(); + + jScrollPane2.setViewportView(jEditorPane1); + + buttonStart.setText("Start"); + buttonStart.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStartActionPerformed(evt); + } + }); + + buttonAbort.setText("Abort"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + checkAutoSaveArgs.setText("Auto save parameters"); + + buttonScienta.setText("Scienta Panel"); + buttonScienta.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonScientaActionPerformed(evt); + } + }); + + jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters")); + + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Regions")); + + table.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Start", "End", "Step" + } + ) { + Class[] types = new Class [] { + java.lang.Double.class, java.lang.Double.class, java.lang.Double.class + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + }); + jScrollPane1.setViewportView(table); + + buttonAdd.setText("Add"); + buttonAdd.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAddActionPerformed(evt); + } + }); + + buttonDelete.setText("Delete"); + buttonDelete.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDeleteActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(buttonAdd) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonDelete) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAdd, buttonDelete}); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonAdd) + .addComponent(buttonDelete)) + .addContainerGap()) + ); + + jLabel1.setText("Name:"); + + buttonOpen.setText("Open"); + buttonOpen.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonOpenActionPerformed(evt); + } + }); + + buttonSave.setText("Save"); + buttonSave.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonSaveActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(jPanel2Layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textName) + .addGap(18, 18, 18) + .addComponent(buttonOpen) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonSave))) + .addContainerGap()) + ); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(textName) + .addComponent(buttonOpen) + .addComponent(buttonSave) + .addComponent(jLabel1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(12, 12, 12)) + ); + + jLabel2.setText("File ID:"); + + textFileId.setEditable(false); + textFileId.setHorizontalAlignment(javax.swing.JTextField.CENTER); + + buttonResetId.setText("Reset"); + buttonResetId.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonResetIdActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(33, 33, 33) + .addComponent(buttonAbort) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(checkAutoSaveArgs) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonScienta) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonResetId))) + .addContainerGap()))) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart}); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonResetId, textFileId}); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonScienta, checkAutoSaveArgs}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(7, 7, 7) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(checkAutoSaveArgs) + .addComponent(jLabel2) + .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonScienta) + .addComponent(buttonResetId)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonStart) + .addComponent(buttonAbort)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed + try { + execute(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonStartActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + try { + abort(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonAbortActionPerformed + + private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed + try { + //model.addRow(new Object[]{energy.getMinValue(), energy.getMaxValue(), 10.0}); + model.addRow(new Object[]{500.0, 1000.0, 100.0}); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonAddActionPerformed + + private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed + try { + if ((model.getRowCount() > 0) && (table.getSelectedRow() >= 0)) { + model.removeRow(table.getSelectedRow()); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonDeleteActionPerformed + + private void buttonOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOpenActionPerformed + try { + open(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonOpenActionPerformed + + private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed + try { + JFileChooser chooser = new JFileChooser(getContext().getSetup().expandPath(getHomePath())); + FileNameExtensionFilter filter = new FileNameExtensionFilter(getDescription(), getExtensions()); + chooser.setFileFilter(filter); + try { + if (currentFile != null) { + chooser.setSelectedFile(currentFile); + } else if (getScanName() != null) { + File file = Paths.get(chooser.getCurrentDirectory().getAbsolutePath(), getScanName()).toFile(); + chooser.setSelectedFile(file); + } + } catch (Exception ex) { + this.showException(ex); + } + int rVal = chooser.showSaveDialog(this); + if (rVal == JFileChooser.APPROVE_OPTION) { + String fileName = chooser.getSelectedFile().getAbsolutePath(); + if (IO.getExtension(chooser.getSelectedFile().getAbsolutePath()).isEmpty()) { + fileName += "." + FILE_EXTENSION; + } + saveAs(fileName); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonSaveActionPerformed + + private void buttonScientaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScientaActionPerformed + try { + this.showDevicePanel("scienta"); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonScientaActionPerformed + + private void buttonResetIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetIdActionPerformed + try { + this.getContext().setFileSequentialNumber(0); + updateSeq(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonResetIdActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonAdd; + private javax.swing.JButton buttonDelete; + private javax.swing.JButton buttonOpen; + private javax.swing.JButton buttonResetId; + private javax.swing.JButton buttonSave; + private javax.swing.JButton buttonScienta; + private javax.swing.JButton buttonStart; + private javax.swing.JCheckBox checkAutoSaveArgs; + private javax.swing.JEditorPane jEditorPane1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTable table; + private javax.swing.JTextField textFileId; + private javax.swing.JTextField textName; + // End of variables declaration//GEN-END:variables + +} diff --git a/script/queues/test.que b/script/queues/test.que new file mode 100644 index 0000000..192c7d1 --- /dev/null +++ b/script/queues/test.que @@ -0,0 +1 @@ +[ [ [ true, "parameters/Jerome_O_K_edge_BaF.ens", "", "Resume", "" ], [ true, "parameters/Na_K_edge_Yanisha.ens", "", "Resume", "" ] ] ] \ No newline at end of file diff --git a/script/templates/EnergyScan.py b/script/templates/EnergyScan.py index 3a039ce..c85da97 100644 --- a/script/templates/EnergyScan.py +++ b/script/templates/EnergyScan.py @@ -1,35 +1,43 @@ - -if get_exec_pars().source == CommandSource.ui: - REGIONS = [[523.0, 527.0, 2.0], [527.0, 535.0, 4.0], [535.0, 558.0, 2.0]] - NAME = None -IOC_AUTO_SAVE = False -DUMMY_TRIGGER = True #Trigger detector to update the array sizes and calibration - - - -set_device_alias(scienta.getSpectrum(), "spectrum") -set_device_alias(scienta.getDataMatrix(), "image") -set_device_alias(scienta.stats[0], "sum") - -sensors=[i0, scienta.stats[0], scienta.getSpectrum()] #), scienta.getDataMatrix()] - -def trigger(position, scan): - scienta.start() - scienta.waitNewImage(-1) - - -if DUMMY_TRIGGER: - trigger(None, None) - - -if IOC_AUTO_SAVE: - capture.write(1) - - - -try: - rscan(energy, sensors, REGIONS, latency = 0.0, before_read=trigger, after_read=after_readout, name = NAME) -finally: - if IOC_AUTO_SAVE: - capture.write(0) - scienta.zeroSupplies() \ No newline at end of file +if get_exec_pars().debug: + print "Setting debug parameters" + REGIONS = [[523.0, 527.0, 2.0], [527.0, 535.0, 4.0], [535.0, 558.0, 2.0]] + NAME = None + FILE = None + +if FILE: + FILE = get_context().setup.expandPath("{home}/parameters/" + FILE) + import json + with open(FILE) as json_file: + cfg = json.load(json_file) + NAME , REGIONS= cfg[0][0][0], cfg[1] + print "FILE: ", FILE +print "NAME: ", NAME +print "REGIONS: ", REGIONS + +IOC_AUTO_SAVE = False +DUMMY_TRIGGER = True #Trigger detector to update the array sizes and calibration + +set_device_alias(scienta.getSpectrum(), "spectrum") +set_device_alias(scienta.getDataMatrix(), "image") +set_device_alias(scienta.stats[0], "sum") + +sensors=[i0, scienta.stats[0], scienta.getSpectrum()] #), scienta.getDataMatrix()] + +def trigger(position, scan): + scienta.start() + scienta.waitNewImage(-1) + + +if DUMMY_TRIGGER: + trigger(None, None) + + +if IOC_AUTO_SAVE: + capture.write(1) + +try: + rscan(energy, sensors, REGIONS, latency = 0.0, before_read=trigger, after_read=after_readout, name = NAME) +finally: + if IOC_AUTO_SAVE: + capture.write(0) + scienta.zeroSupplies() diff --git a/script/test/test1.py b/script/test/test1.py new file mode 100644 index 0000000..718ff25 --- /dev/null +++ b/script/test/test1.py @@ -0,0 +1 @@ +time.sleep(5.0) \ No newline at end of file diff --git a/script/test/test2.py b/script/test/test2.py new file mode 100644 index 0000000..718ff25 --- /dev/null +++ b/script/test/test2.py @@ -0,0 +1 @@ +time.sleep(5.0) \ No newline at end of file diff --git a/script/test/test3.py b/script/test/test3.py new file mode 100644 index 0000000..718ff25 --- /dev/null +++ b/script/test/test3.py @@ -0,0 +1 @@ +time.sleep(5.0) \ No newline at end of file