This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import ch.psi.pshell.core.Context;
|
||||
import ch.psi.pshell.core.JsonSerializer;
|
||||
import ch.psi.pshell.core.Nameable;
|
||||
import ch.psi.pshell.device.DiscretePositioner;
|
||||
import ch.psi.pshell.device.MasterPositioner;
|
||||
import ch.psi.pshell.device.Motor;
|
||||
@@ -72,7 +73,7 @@ public class SIStem extends PanelProcessor {
|
||||
final JComboBox[] scientaCombos;
|
||||
final JTextField[] scientaRangeFields;
|
||||
final JComboBox[] deviceCombos;
|
||||
|
||||
String[] additionalPositioners ;
|
||||
boolean intialized;
|
||||
|
||||
public SIStem() {
|
||||
@@ -207,48 +208,59 @@ public class SIStem extends PanelProcessor {
|
||||
//Overridable callbacks
|
||||
@Override
|
||||
public void onInitialize(int runCount) {
|
||||
if (runCount == 0) {
|
||||
if ((runCount == 0)&&(getFileName()==null)) {
|
||||
clear();
|
||||
}
|
||||
if (getState()==State.Ready){
|
||||
onStateChange(State.Ready, State.Initializing);
|
||||
|
||||
if (!intialized) {
|
||||
try {
|
||||
Class enumClass = (Class) eval("scienta.getLensModeClass()", true);
|
||||
String[] mode_position = (String[]) eval("id_mode.getPositions()", true);
|
||||
String[] grating_position = (String[]) eval("grating.getPositions()", true);
|
||||
List<Nameable> add_pos= (List<Nameable>) eval("get_additional_positioners()", true);
|
||||
additionalPositioners = new String[add_pos.size()];
|
||||
for (int i=0; i< add_pos.size(); i++){
|
||||
additionalPositioners[i]=add_pos.get(i).getName();
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
SwingUtils.setEnumCombo(comboLens, enumClass, true);
|
||||
SwingUtils.insertCombo(comboLens, "", 0);
|
||||
comboLens.setSelectedIndex(0);
|
||||
|
||||
comboPol.setModel(new DefaultComboBoxModel(mode_position));
|
||||
SwingUtils.insertCombo(comboPol, "", 0);
|
||||
comboPol.setSelectedIndex(0);
|
||||
|
||||
comboGrating.setModel(new DefaultComboBoxModel(grating_position));
|
||||
SwingUtils.insertCombo(comboGrating, "", 0);
|
||||
comboGrating.setSelectedIndex(0);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
String filename = getFileName();
|
||||
clear();
|
||||
if (filename!=null){
|
||||
try {
|
||||
open(filename);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
intialized = true;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
updateMaster();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChange(State state, State former) {
|
||||
if (!intialized) {
|
||||
if ((state == State.Ready) && (former == State.Initializing)) {
|
||||
try {
|
||||
Class enumClass = (Class) eval("scienta.getLensModeClass()");
|
||||
String[] mode_position = (String[]) eval("id_mode.getPositions()");
|
||||
String[] grating_position = (String[]) eval("grating.getPositions()");
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
SwingUtils.setEnumCombo(comboLens, enumClass, true);
|
||||
SwingUtils.insertCombo(comboLens, "", 0);
|
||||
comboLens.setSelectedIndex(0);
|
||||
|
||||
comboPol.setModel(new DefaultComboBoxModel(mode_position));
|
||||
SwingUtils.insertCombo(comboPol, "", 0);
|
||||
comboPol.setSelectedIndex(0);
|
||||
|
||||
comboGrating.setModel(new DefaultComboBoxModel(grating_position));
|
||||
SwingUtils.insertCombo(comboGrating, "", 0);
|
||||
comboGrating.setSelectedIndex(0);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
});
|
||||
intialized = true;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Logger.getLogger(SIStem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateControls();
|
||||
}
|
||||
|
||||
@@ -373,69 +385,72 @@ public class SIStem extends PanelProcessor {
|
||||
@Override
|
||||
public void open(String fileName) throws IOException {
|
||||
clear();
|
||||
if (fileName != null) {
|
||||
Path path = Paths.get(fileName);
|
||||
String json = new String(Files.readAllBytes(path));
|
||||
currentFile = path.toFile();
|
||||
Map config = (Map) JsonSerializer.decode(json, Map.class);
|
||||
try{
|
||||
if (fileName != null) {
|
||||
Path path = Paths.get(fileName);
|
||||
String json = new String(Files.readAllBytes(path));
|
||||
currentFile = path.toFile();
|
||||
Map config = (Map) JsonSerializer.decode(json, Map.class);
|
||||
|
||||
Map<String, Double> preActions = (Map) config.get("PRE_ACTIONS");
|
||||
List<Integer> range = (List) config.getOrDefault("RANGE", new ArrayList());
|
||||
Map<String, Double> preActions = (Map) config.get("PRE_ACTIONS");
|
||||
List<Integer> range = (List) config.getOrDefault("RANGE", new ArrayList());
|
||||
|
||||
List<String> positioners = (List) config.get("POSITIONERS");
|
||||
List<Double> start = (List) config.get("START");
|
||||
List<Double> stop = (List) config.get("STOP");
|
||||
List<Integer> steps = (List) config.get("STEPS");
|
||||
List<String> positioners = (List) config.get("POSITIONERS");
|
||||
List<Double> start = (List) config.get("START");
|
||||
List<Double> stop = (List) config.get("STOP");
|
||||
List<Integer> steps = (List) config.get("STEPS");
|
||||
|
||||
for (String name : preActions.keySet()) {
|
||||
for (JComboBox combo : deviceCombos) {
|
||||
if (name.equals(combo.getName())) {
|
||||
combo.setSelectedItem(String.valueOf(preActions.get(name)));
|
||||
break;
|
||||
for (String name : preActions.keySet()) {
|
||||
for (JComboBox combo : deviceCombos) {
|
||||
if (name.equals(combo.getName())) {
|
||||
combo.setSelectedItem(String.valueOf(preActions.get(name)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (JComboBox combo : scientaCombos) {
|
||||
if (name.equals(combo.getName())) {
|
||||
combo.setSelectedItem(String.valueOf(preActions.get(name)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (JComboBox combo : scientaCombos) {
|
||||
if (name.equals(combo.getName())) {
|
||||
combo.setSelectedItem(String.valueOf(preActions.get(name)));
|
||||
break;
|
||||
for (JTextField text : Arr.append(scientaFloatFields, scientaIntFields)) {
|
||||
if (name.equals(text.getName())) {
|
||||
text.setText(String.valueOf(preActions.get(name)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < range.size(); i++) {
|
||||
if (range.get(i) != null) {
|
||||
scientaRangeFields[i].setText(String.valueOf(range.get(i)).trim());
|
||||
}
|
||||
}
|
||||
Positioner pos = getContext().getDevicePool().getByName(name, Positioner.class);
|
||||
if (pos != null) {
|
||||
addDevice(pos, modelFixed, -1, new Object[]{name, preActions.get(name), pos.getUnit()});
|
||||
}
|
||||
}
|
||||
for (JTextField text : Arr.append(scientaFloatFields, scientaIntFields)) {
|
||||
if (name.equals(text.getName())) {
|
||||
text.setText(String.valueOf(preActions.get(name)));
|
||||
break;
|
||||
for (int i = 0; i < positioners.size(); i++) {
|
||||
String name = positioners.get(i);
|
||||
Positioner pos = getContext().getDevicePool().getByName(name, Positioner.class);
|
||||
if (pos != null) {
|
||||
addDevice(pos, modelScanned, -1, new Object[]{name, start.get(i), stop.get(i), steps.get(i) + 1, pos.getUnit()});
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < range.size(); i++) {
|
||||
if (range.get(i) != null) {
|
||||
scientaRangeFields[i].setText(String.valueOf(range.get(i)).trim());
|
||||
}
|
||||
}
|
||||
Positioner pos = getContext().getDevicePool().getByName(name, Positioner.class);
|
||||
if (pos != null) {
|
||||
addDevice(pos, modelFixed, -1, new Object[]{name, preActions.get(name), pos.getUnit()});
|
||||
}
|
||||
|
||||
setDevices(textSensors, (List<String>) config.get("SENSORS"));
|
||||
setDevices(textSnapshots, (List<String>) config.get("SNAPS"));
|
||||
setDevices(textDiagnostics, (List<String>) config.get("DIAGS"));
|
||||
setDevices(textMonitors, (List<String>) config.get("MONITORS"));
|
||||
|
||||
spinnerLatency.setValue(config.get("SETTLING_TIME"));
|
||||
spinnerPasses.setValue(config.get("PASSES"));
|
||||
checkZigzag.setSelected((Boolean) config.get("ZIGZAG"));
|
||||
checkCompression.setSelected((Boolean) config.get("COMPRESSION"));
|
||||
updateDetectorPlot();
|
||||
}
|
||||
for (int i = 0; i < positioners.size(); i++) {
|
||||
String name = positioners.get(i);
|
||||
Positioner pos = getContext().getDevicePool().getByName(name, Positioner.class);
|
||||
if (pos != null) {
|
||||
addDevice(pos, modelScanned, -1, new Object[]{name, start.get(i), stop.get(i), steps.get(i) + 1, pos.getUnit()});
|
||||
}
|
||||
}
|
||||
|
||||
setDevices(textSensors, (List<String>) config.get("SENSORS"));
|
||||
setDevices(textSnapshots, (List<String>) config.get("SNAPS"));
|
||||
setDevices(textDiagnostics, (List<String>) config.get("DIAGS"));
|
||||
setDevices(textMonitors, (List<String>) config.get("MONITORS"));
|
||||
|
||||
spinnerLatency.setValue(config.get("SETTLING_TIME"));
|
||||
spinnerPasses.setValue(config.get("PASSES"));
|
||||
checkZigzag.setSelected((Boolean) config.get("ZIGZAG"));
|
||||
checkCompression.setSelected((Boolean) config.get("COMPRESSION"));
|
||||
updateDetectorPlot();
|
||||
} finally{
|
||||
updateControls();
|
||||
}
|
||||
updateControls();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -510,14 +525,15 @@ public class SIStem extends PanelProcessor {
|
||||
List<String> names = new ArrayList<>();
|
||||
names.addAll(Arrays.asList(getContext().getDevicePool().getAllNamesOrderedByName(Motor.class)));
|
||||
names.addAll(Arrays.asList(getContext().getDevicePool().getAllNamesOrderedByName(MasterPositioner.class)));
|
||||
names.add("energy");
|
||||
names.add("exit_slit");
|
||||
names.add("fe_vert_width");
|
||||
names.add("fe_horiz_width");
|
||||
names.add("cff");
|
||||
|
||||
for (String name : names) {
|
||||
modelInactive.addRow(new Object[]{name});
|
||||
if (!names.isEmpty()){
|
||||
if (additionalPositioners!=null){
|
||||
for (String name:additionalPositioners){
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
for (String name : names) {
|
||||
modelInactive.addRow(new Object[]{name});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user