This commit is contained in:
gac-x09la
2022-02-07 09:49:39 +01:00
parent 34661df5b9
commit f6b0954e8f
15 changed files with 290 additions and 52 deletions

View File

@@ -15,8 +15,12 @@ import ch.psi.pshell.plot.MatrixPlotSeries;
import ch.psi.pshell.plot.Plot;
import ch.psi.pshell.swing.DataPanel;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.PanelProcessor;
import ch.psi.pshell.ui.Preferences;
import ch.psi.pshell.ui.Processor;
import ch.psi.pshell.ui.QueueProcessor;
import ch.psi.pshell.ui.View;
import ch.psi.utils.Arr;
import ch.psi.utils.Convert;
import ch.psi.utils.IO;
@@ -77,7 +81,29 @@ public class SIStem extends PanelProcessor {
final JComboBox[] deviceCombos;
String[] additionalPositioners ;
boolean intialized;
static{
QueueProcessor.DEFAULT_INFO_COLUMN = "Time";
View view = App.getInstance().getMainFrame();
if (view!=null){
List<QueueProcessor> queues =view.getQueues();
for (QueueProcessor qp : queues){
String filename = qp.getFileName();
if ((filename!=null)&&(!filename.isBlank())&&!qp.hasChanged()){
System.out.println("Reload: " + filename);
try {
view.getDocumentsTab().remove(qp.getPanel());
view.openProcessor(QueueProcessor.class, filename);
} catch (Exception ex) {
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
}
}
}
public SIStem() {
initComponents();
modelInactive = (DefaultTableModel) tableInactive.getModel();
@@ -184,6 +210,7 @@ public class SIStem extends PanelProcessor {
detectorPlot.getAxis(Plot.AxisId.X).setLabel("X-Scale (energy)");
detectorPlot.getAxis(Plot.AxisId.Y).setLabel("Y-Scale (distance or angle)");
clear();
startTimer(2000, 100);
}
void addDevice(ProcessVariable dev, DefaultTableModel model, int row, Object[] data) {
@@ -223,8 +250,10 @@ public class SIStem extends PanelProcessor {
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
if ((runCount == 0)&&(getFileName()==null)) {
clear();
if (runCount == 0) {
if (getFileName()==null){
clear();
}
}
if (!intialized) {
@@ -283,6 +312,13 @@ public class SIStem extends PanelProcessor {
public void onExecutedFile(String fileName, Object result) {
}
@Override
public void onTimer() {
if (getState().isInitialized()){
updateTime();
}
}
//Callback to perform update - in event thread
@Override
protected void doUpdate() {
@@ -504,6 +540,8 @@ public class SIStem extends PanelProcessor {
}
} finally{
updateControls();
updatingTime=false;
updateTime();
}
}
@@ -553,6 +591,7 @@ public class SIStem extends PanelProcessor {
getLogger().log(Level.WARNING, null, ex);
}
}
textTime.setText("");
}
@Override
@@ -601,22 +640,29 @@ public class SIStem extends PanelProcessor {
if (currentFile == null) {
return;
}
Processor p = getView().getRunningProcessor(true);
HashMap args = new HashMap();
args.put("NAME", getScanName());
this.runAsync("templates/SIStem", args).handle((ret, ex) -> {
if (ex != null) {
}
try {
} catch (Exception e) {
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, e);
}
args.put("NAME", getScanName());
this.runAsync("templates/SIStem", args).handle((ret, ex) -> {
if (ex != null) {
if ((p==null)||!(p instanceof QueueProcessor)){
if (getView().getPreferences().getScriptPopupDialog() != Preferences.ScriptPopupDialog.None) {
if (!getContext().isAborted()) {
showException((Exception)ex);
}
}
}
}
return ret;
});
}
@Override
public Object getResult() {
return getContext().getLastScriptResult();
}
String getScanName() {
String scan = null;
if (currentFile != null) {
@@ -945,6 +991,56 @@ public class SIStem extends PanelProcessor {
void onPlotHide() {
detectorPlot.clear();
}
volatile boolean updatingTime;
void updateTime(){
if (!updatingTime){
String cmd="calc_acquisition_time(";
int samples = 1;
for (int i = 0; i < modelScanned.getRowCount(); i++) {
Integer points = (Integer) modelScanned.getValueAt(i, 3);
samples*=points;
}
cmd+="samples="+Math.max(samples,1) + ", ";
if (!((String)comboAcquisition.getSelectedItem()).isBlank()){
cmd+="mode='"+String.valueOf(comboAcquisition.getSelectedItem()) + "', ";
}
if (!textLowEnergy.getText().isBlank()){
cmd+="enl="+(String)textLowEnergy.getText() + ", ";
}
if (!textHighEnergy.getText().isBlank()){
cmd+="enh="+(String)textHighEnergy.getText() + ", ";
}
if (!textStepEnergy.getText().isBlank()){
cmd+="ens="+(String)textStepEnergy.getText() + ", ";
}
if (!textLowThetaY.getText().isBlank()){
cmd+="tyl="+(String)textLowThetaY.getText() + ", ";
}
if (!textHighThetaY.getText().isBlank()){
cmd+="tyh="+(String)textHighThetaY.getText() + ", ";
}
if (!textStepThetaY.getText().isBlank()){
cmd+="tys="+(String)textStepThetaY.getText() + ", ";
}
cmd+=")";
updatingTime=true;
try {
this.evalAsync(cmd, true).handle((ret, ex) -> {
String text = ((ex != null) || (ret==null)) ? "" : String.valueOf(ret);
SwingUtilities.invokeLater(()->{
textTime.setText(text);
});
updatingTime=false;
return ret;
});
} catch (Context.ContextStateException ex) {
Logger.getLogger(SIStem.class.getName()).log(Level.WARNING, null, ex);
updatingTime=false;
}
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@@ -1053,6 +1149,8 @@ public class SIStem extends PanelProcessor {
buttonSave = new javax.swing.JButton();
buttonClear = new javax.swing.JButton();
buttonData = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
textTime = new javax.swing.JTextField();
buttonScienta.setText("Scienta Panel");
buttonScienta.addActionListener(new java.awt.event.ActionListener() {
@@ -1919,6 +2017,11 @@ public class SIStem extends PanelProcessor {
}
});
jLabel2.setText("Acquisition Time:");
textTime.setEditable(false);
textTime.setHorizontalAlignment(javax.swing.JTextField.CENTER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@@ -1931,6 +2034,10 @@ public class SIStem extends PanelProcessor {
.addComponent(buttonScienta)
.addGap(18, 18, 18)
.addComponent(buttonData)
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textTime, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonStart)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
@@ -1974,7 +2081,9 @@ public class SIStem extends PanelProcessor {
.addComponent(buttonScienta)
.addComponent(buttonStart)
.addComponent(buttonAbort)
.addComponent(buttonData))
.addComponent(buttonData)
.addComponent(jLabel2)
.addComponent(textTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
@@ -2060,7 +2169,13 @@ public class SIStem extends PanelProcessor {
getView().getDocumentsTab().setSelectedComponent(tq);
}
if (currentFile != null) {
tq.addNewFile(currentFile.getPath());
if (tq.getTableInfoCol()!=null){
tq.addNewFile(currentFile.getPath(), "", textTime.getText());
} else {
String args = (textTime.getText().isBlank()) ? "": "\"Time\":"+textTime.getText();
tq.addNewFile(currentFile.getPath(), args);
}
}
} catch (Exception ex) {
showException(ex);
@@ -2196,6 +2311,7 @@ public class SIStem extends PanelProcessor {
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel22;
@@ -2252,6 +2368,7 @@ public class SIStem extends PanelProcessor {
private javax.swing.JTextArea textSnapshots;
private javax.swing.JTextField textStepEnergy;
private javax.swing.JTextField textStepThetaY;
private javax.swing.JTextField textTime;
private javax.swing.JTextField textXChannelMax;
private javax.swing.JTextField textXChannelMin;
private javax.swing.JTextField textYChannelMax;