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

Binary file not shown.

View File

@@ -18,27 +18,36 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="ledLidControlActive" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="ledKnownPosition" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="textPosition" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="ledLidInitialized" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="ledValidSegment" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
<Component id="textSegment" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="96" max="32767" attributes="0"/>
<Component id="buttonInitHexiposi" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="136" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="buttonAbort" linkSize="1" min="-2" pref="73" max="-2" attributes="0"/>
<Component id="buttonRecover" linkSize="1" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="144" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="116" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -47,44 +56,66 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="ledLidControlActive" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="ledKnownPosition" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="textPosition" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="ledLidInitialized" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="ledValidSegment" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel7" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="textSegment" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="buttonInitHexiposi" min="-2" max="-2" attributes="0"/>
<Component id="buttonRecover" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="buttonAbort" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="ch.psi.pshell.swing.Led" name="ledLidControlActive">
<Component class="ch.psi.pshell.swing.Led" name="ledKnownPosition">
</Component>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" value="Known position"/>
</Properties>
</Component>
<Component class="ch.psi.pshell.swing.Led" name="ledLidInitialized">
<Component class="ch.psi.pshell.swing.Led" name="ledValidSegment">
</Component>
<Component class="javax.swing.JLabel" name="jLabel7">
<Properties>
<Property name="text" type="java.lang.String" value="Valid segment"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="buttonInitHexiposi">
<Component class="javax.swing.JButton" name="buttonRecover">
<Properties>
<Property name="text" type="java.lang.String" value="Recover"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonRecoverActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="buttonAbort">
<Properties>
<Property name="text" type="java.lang.String" value="Abort"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonInitHexiposiActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAbortActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="textPosition">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="textSegment">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>
</Form>

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
}