Scan private master axis

This commit is contained in:
gac-x09la
2022-01-19 11:03:26 +01:00
parent 919c6f8a98
commit 34661df5b9
7 changed files with 297 additions and 24 deletions

View File

@@ -4,8 +4,10 @@ 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.MasterPositionerConfig;
import ch.psi.pshell.device.Motor;
import ch.psi.pshell.device.Positioner;
import ch.psi.pshell.device.PositionerBase;
import ch.psi.pshell.device.ProcessVariable;
import ch.psi.pshell.device.ReadonlyProcessVariable;
import ch.psi.pshell.device.Register;
@@ -205,6 +207,19 @@ public class SIStem extends PanelProcessor {
}
}
boolean hasDevice(ProcessVariable dev) {
return (hasDevice(dev, modelInactive) || hasDevice(dev, modelFixed) || hasDevice(dev, modelScanned));
}
boolean hasDevice(ProcessVariable dev, DefaultTableModel model) {
for (int i = 0; i < model.getRowCount(); i++) {
if (model.getValueAt(i, 0).equals(dev.getName())) {
return true;
}
}
return false;
}
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
@@ -376,7 +391,20 @@ public class SIStem extends PanelProcessor {
config.put("PASSES", spinnerPasses.getValue());
config.put("ZIGZAG", checkZigzag.isSelected());
config.put("COMPRESSION", checkCompression.isSelected());
if (privateMasterAxis!=null){
Map masterAxis = new HashMap();
masterAxis.put("NAME", privateMasterAxis.getName());
masterAxis.put("MASTER", privateMasterAxis.getMaster().getName());
List<String> slaves = new ArrayList<>();
for (Positioner p : privateMasterAxis.getSlaves()){
slaves.add(p.getName());
}
masterAxis.put("SLAVES", slaves);
masterAxis.put("CONFIG", privateMasterAxis.getConfig());
config.put("MASTER_AXIS", masterAxis);
}
String json = JsonSerializer.encode(config, true);
Files.write(currentFile.toPath(), json.getBytes());
updateControls();
@@ -391,6 +419,32 @@ public class SIStem extends PanelProcessor {
String json = new String(Files.readAllBytes(path));
currentFile = path.toFile();
Map config = (Map) JsonSerializer.decode(json, Map.class);
Map<String, Object> masterAxis = (Map) config.get("MASTER_AXIS");
if (masterAxis!=null){
String name = (String) masterAxis.get("NAME");
String master = (String) masterAxis.get("MASTER");
List<String> slaves = (List<String>) masterAxis.get("SLAVES");
Map<String, Object> cfg = (Map<String, Object>) masterAxis.get("CONFIG");
Positioner[] slaveDevices = new PositionerBase[slaves.size()];
for (int i=0; i<slaves.size(); i++){
slaveDevices[i] = (Positioner)getDevice(slaves.get(i));
}
MasterPositioner dev = new MasterPositioner(name, (PositionerBase)getDevice(master), slaveDevices);
if (cfg!=null){
//TODO
}
if (getContext().getDevicePool().addDevice(dev, false, true)){
privateMasterAxis = dev;
updateMaster();
buttonPrivateMasterAxis.setSelected(true);
if (!hasDevice(privateMasterAxis)){
modelInactive.addRow(new Object[]{name});
}
}
}
Map<String, Double> preActions = (Map) config.get("PRE_ACTIONS");
List<Integer> range = (List) config.getOrDefault("RANGE", new ArrayList());
@@ -456,6 +510,7 @@ public class SIStem extends PanelProcessor {
@Override
public void clear() {
currentFile = null;
deletePrivateMasterAxis();
for (JComboBox combo : deviceCombos) {
combo.setSelectedIndex(0);
}
@@ -502,6 +557,7 @@ public class SIStem extends PanelProcessor {
@Override
protected void onUnloaded() {
deletePrivateMasterAxis();
if (queueProcessor != null) {
getContext().getPluginManager().unloadPlugin(queueProcessor);
getApp().exit(this);
@@ -618,6 +674,62 @@ public class SIStem extends PanelProcessor {
}
updateControls();
}
MasterPositioner privateMasterAxis;
void createPrivateMasterAxis() throws Exception{
deletePrivateMasterAxis();
String name = getString("Enter name of the device:", "");
if ((name!=null) && (!name.isBlank())){
name=name.trim();
if (getContext().getDevicePool().getByName(name)!=null){
throw new Exception("Device name in use");
}
String[] motorNames = getContext().getDevicePool().getAllNamesOrderedByName(Motor.class);
String master = getString("Enter master motor:", motorNames, null);
if (master!=null){
ArrayList<String> slaves = new ArrayList<>();
boolean finished = false;
motorNames=Arr.removeEquals(motorNames, master);
while (!finished){
String slave = getString("Enter slave motor " + (slaves.size()+1) +":", motorNames, null);
if (slave!=null){
motorNames=Arr.removeEquals(motorNames, slave);
slaves.add(slave);
}
if((slave==null)||(motorNames.length==0)){
if (slaves.size()<1){
return;
}
Positioner[] slaveDevices = new PositionerBase[slaves.size()];
for (int i=0; i<slaves.size(); i++){
slaveDevices[i] = (Positioner)getDevice(slaves.get(i));
}
MasterPositioner dev = new MasterPositioner(name, (PositionerBase)getDevice(master), slaveDevices);
if (getContext().getDevicePool().addDevice(dev, false, true)){
privateMasterAxis = dev;
updateMaster();
modelInactive.addRow(new Object[]{name});
}
return;
}
}
}
}
}
void deletePrivateMasterAxis(){
if (privateMasterAxis!=null){
getContext().getDevicePool().removeDevice(privateMasterAxis, true);
removeDevice(privateMasterAxis, modelInactive, -1);
removeDevice(privateMasterAxis, modelFixed, -1);
removeDevice(privateMasterAxis, modelScanned, -1);
privateMasterAxis= null;
updateMaster();
buttonPrivateMasterAxis.setSelected(false);
}
}
void updateLens() throws Exception {
String lens = (String) comboLens.getSelectedItem();
@@ -917,6 +1029,7 @@ public class SIStem extends PanelProcessor {
jScrollPane8 = new javax.swing.JScrollPane();
tableMaster = new javax.swing.JTable();
buttonEditMaster = new javax.swing.JButton();
buttonPrivateMasterAxis = new javax.swing.JCheckBox();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tableInactive = new javax.swing.JTable();
@@ -1439,9 +1552,7 @@ public class SIStem extends PanelProcessor {
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel11Layout.createSequentialGroup()
.addComponent(checkCompression)
.addGap(59, 59, 59))
.addComponent(checkCompression)
.addComponent(spinnerPasses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(checkZigzag)
.addComponent(spinnerLatency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
@@ -1545,15 +1656,27 @@ public class SIStem extends PanelProcessor {
}
});
buttonPrivateMasterAxis.setText("Create private master axis");
buttonPrivateMasterAxis.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonPrivateMasterAxisActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 743, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(buttonEditMaster, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(buttonPrivateMasterAxis)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 743, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(buttonEditMaster, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel6Layout.setVerticalGroup(
@@ -1561,10 +1684,11 @@ public class SIStem extends PanelProcessor {
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(buttonEditMaster)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)))
.addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
.addComponent(buttonEditMaster))
.addGap(13, 13, 13)
.addComponent(buttonPrivateMasterAxis)
.addContainerGap())
);
jTabbedPane1.addTab("Master Axis", jPanel6);
@@ -2022,6 +2146,22 @@ public class SIStem extends PanelProcessor {
}
}//GEN-LAST:event_tableMasterMouseClicked
private void buttonPrivateMasterAxisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPrivateMasterAxisActionPerformed
try {
if (buttonPrivateMasterAxis.isSelected() != (privateMasterAxis!=null)){
if (buttonPrivateMasterAxis.isSelected()) {
createPrivateMasterAxis();
} else {
deletePrivateMasterAxis();
}
}
} catch (Exception ex) {
showException(ex);
} finally{
buttonPrivateMasterAxis.setSelected(privateMasterAxis!=null);
}
}//GEN-LAST:event_buttonPrivateMasterAxisActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton butonPlot;
@@ -2031,6 +2171,7 @@ public class SIStem extends PanelProcessor {
private javax.swing.JButton buttonData;
private javax.swing.JButton buttonEditMaster;
private javax.swing.JButton buttonOpen;
private javax.swing.JCheckBox buttonPrivateMasterAxis;
private javax.swing.JButton buttonSave;
private javax.swing.JButton buttonScienta;
private javax.swing.JButton buttonStart;