This commit is contained in:
gac-S_Changer
2018-08-08 16:01:05 +02:00
parent ce67a031cf
commit 9ef973fa49
21 changed files with 436 additions and 128 deletions

View File

@@ -5,6 +5,8 @@
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Color;
import java.util.List;
/**
*
@@ -13,6 +15,7 @@ public class Recovery extends Panel {
public Recovery() {
initComponents();
startTimer(3000, 200);
}
//Overridable callbacks
@@ -23,83 +26,80 @@ public class Recovery extends Panel {
@Override
public void onStateChange(State state, State former) {
updateButton();
}
void updateButton(){
buttonRecover.setEnabled((getContext().getState() == State.Ready) &&
(!textSegment.getText().trim().isEmpty()) &&
(textPosition.getText().trim().isEmpty()) );
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
//Callback to perform update - in event thread
@Override
protected void doUpdate() {
}
@Override
public boolean isActive() {
return true;
}
void execute(String statement){
execute(statement, false);
}
void execute(String statement, boolean background){
execute(statement, background, false);
}
void execute(String statement, boolean background, boolean showReturn){
try {
evalAsync(statement, background).handle((ret, ex) -> {
if (ex != null){
showException((Exception)ex);
} else if (showReturn){
SwingUtils.showMessage(getTopLevel(), "Return", String.valueOf(ret));
}
return ret;
});
protected void onTimer() {
try{
List segment = (List) eval("get_current_segment()", true);
ledValidSegment.setColor((segment == null) ? Color.RED : Color.GREEN);
textSegment.setText((segment == null) ? "": segment.get(0) + "->" + segment.get(1) + " [" + segment.get(2) + "mm]");
} catch (Exception ex) {
showException(ex);
System.out.println(ex);
ledValidSegment.setColor(Color.BLACK);
textSegment.setText("");
}
}
void execute(String script, Object args){
try {
runAsync(script, args).handle((ret, ex) -> {
if (ex != null){
showException((Exception)ex);
}
return ret;
});
try{
String point = (String) eval("robot.get_current_point()", true);
ledKnownPosition.setColor((point == null) ? Color.RED : Color.GREEN);
textPosition.setText((point == null) ? "": point);
} catch (Exception ex) {
showException(ex);
}
}
System.out.println(ex);
ledKnownPosition.setColor(Color.BLACK);
textPosition.setText("");
}
updateButton();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
ledLidControlActive = new ch.psi.pshell.swing.Led();
ledKnownPosition = new ch.psi.pshell.swing.Led();
jLabel6 = new javax.swing.JLabel();
ledLidInitialized = new ch.psi.pshell.swing.Led();
ledValidSegment = new ch.psi.pshell.swing.Led();
jLabel7 = new javax.swing.JLabel();
buttonInitHexiposi = new javax.swing.JButton();
buttonRecover = new javax.swing.JButton();
buttonAbort = new javax.swing.JButton();
textPosition = new javax.swing.JTextField();
textSegment = new javax.swing.JTextField();
jLabel6.setText("Known position");
jLabel7.setText("Valid segment");
buttonInitHexiposi.setText("Recover");
buttonInitHexiposi.setEnabled(false);
buttonInitHexiposi.addActionListener(new java.awt.event.ActionListener() {
buttonRecover.setText("Recover");
buttonRecover.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonInitHexiposiActionPerformed(evt);
buttonRecoverActionPerformed(evt);
}
});
buttonAbort.setText("Abort");
buttonAbort.setEnabled(false);
buttonAbort.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAbortActionPerformed(evt);
}
});
textPosition.setEditable(false);
textSegment.setEditable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@@ -110,48 +110,98 @@ public class Recovery extends Panel {
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ledLidControlActive, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ledKnownPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6))
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(textPosition))
.addGroup(layout.createSequentialGroup()
.addComponent(ledLidInitialized, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ledValidSegment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7))))
.addComponent(jLabel7)
.addGap(16, 16, 16)
.addComponent(textSegment)))
.addGap(8, 8, 8))
.addGroup(layout.createSequentialGroup()
.addContainerGap(96, Short.MAX_VALUE)
.addComponent(buttonInitHexiposi)))
.addContainerGap(116, Short.MAX_VALUE))
.addContainerGap(136, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(buttonAbort, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonRecover))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 144, Short.MAX_VALUE)))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonRecover});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledLidControlActive, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addComponent(ledKnownPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(textPosition, 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(ledLidInitialized, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addComponent(ledValidSegment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(textSegment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(buttonInitHexiposi)
.addComponent(buttonRecover)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(buttonAbort)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void buttonInitHexiposiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInitHexiposiActionPerformed
private void buttonRecoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRecoverActionPerformed
try{
this.showDevicePanel("hexiposi");
buttonAbort.setEnabled(true);
evalAsync("recover()", false).handle((ret, ex) -> {
if (ex != null){
showException((Exception)ex);
} else {
SwingUtils.showMessage(getTopLevel(), "Return", String.valueOf(ret));
}
buttonAbort.setEnabled(false);
return ret;
});
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonInitHexiposiActionPerformed
}//GEN-LAST:event_buttonRecoverActionPerformed
private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed
try {
abort();
try{
eval("robot.disable()", true);
} catch (Exception ex){
this.showException(ex);
}
try{
eval("stop_task()", true);
} catch (Exception ex){
this.showException(ex);
}
try{
eval("robot.reset_motion()", true);
} catch (Exception ex){
this.showException(ex);
}
} catch (InterruptedException ex) {
showException(ex);
}
}//GEN-LAST:event_buttonAbortActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonInitHexiposi;
private javax.swing.JButton buttonAbort;
private javax.swing.JButton buttonRecover;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private ch.psi.pshell.swing.Led ledLidControlActive;
private ch.psi.pshell.swing.Led ledLidInitialized;
private ch.psi.pshell.swing.Led ledKnownPosition;
private ch.psi.pshell.swing.Led ledValidSegment;
private javax.swing.JTextField textPosition;
private javax.swing.JTextField textSegment;
// End of variables declaration//GEN-END:variables
}