Display of cover position cache

This commit is contained in:
gac-S_Changer
2024-12-04 14:49:53 +01:00
parent a838cb3e74
commit ac75b13444
8 changed files with 168 additions and 123 deletions

View File

@@ -225,7 +225,7 @@ public class BasePlatePanel extends DevicePanel {
ImageListener imageListener = new ImageListener() {
@Override
public void onImage(Object origin, BufferedImage image, Data data) {
img = image;
img = (source == null )? null : image;
repaint();
}
@@ -235,14 +235,16 @@ public class BasePlatePanel extends DevicePanel {
repaint();
}
};
void setCameraView(Source source){
img = null;
void setCameraView(Source source){
if (this.source!=null){
this.source.removeListener(imageListener);
}
this.source = source;
if (source!=null){
source.addListener(imageListener);
img = source.getOutput();
} else {
img = null;
}
repaint();
}

View File

@@ -3,6 +3,7 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.Puck.Detection;
import ch.psi.mxsc.Puck.PuckType;
import ch.psi.pshell.core.CommandInfo;
import ch.psi.pshell.core.Context;
@@ -22,8 +23,11 @@ import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -291,9 +295,8 @@ public class Controller {
void onTimer() {
try {
setPuckLoading(getPuckLoading());
//setPuckLoading(null);
} catch (Exception ex) {
setPuckLoading(false);
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
}
try {
@@ -404,20 +407,27 @@ public class Controller {
}
updateView();
}
public boolean isSelectedPuck(Puck puck) {
return puck.isSegmentSelected();
}
public List<Puck> getSelectedPucks() {
public List<Puck> getFreePucks() {
List<Puck> ret = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_PUCKS; i++) {
if (isSelectedPuck(basePlate.getPucks()[i])) {
ret.add(basePlate.getPucks()[i]);
for (Puck p : basePlate.getPucks()) {
if (p.getDetection() == Detection.Empty ) {
ret.add(p);
}
}
return ret;
}
public Puck getFreePuck(){
List<Puck> pucks = getFreePucks();
if (pucks.isEmpty()){
return null;
}
Random random = new Random();
return pucks.get(random.nextInt(pucks.size()));
}
public Boolean isLedRoomTemp() {
try {
@@ -442,6 +452,15 @@ public class Controller {
return null;
}
}
public Boolean isDoorClosed() {
try {
return getMainFrame().eval("is_door_closed()", true).equals(true);
} catch (Exception ex) {
return null;
}
}
public void setServiceMode(boolean value){
try{
@@ -469,14 +488,6 @@ public class Controller {
}
}
public Boolean getPuckLoading() {
try {
return getMainFrame().eval("is_puck_loading()", true).equals(true);
} catch (Exception ex) {
return null;
}
}
public String getWorkingMode() {
try {
return String.valueOf(getMainFrame().eval("robot.working_mode", true));
@@ -681,15 +692,23 @@ public class Controller {
Puck.Detection[] currentDetection;
boolean puckReaderOk = true;
void setPuckLoading(Boolean value) {
if (value == null) {
value = false;
}
if (value != puckLoading) {
//true->load
//false->unload
//null->finish transfer mode
void setPuckLoading(Boolean load) {
if (load != puckLoading) {
if (load!=null){
if (isDoorClosed()){
return;
}
} else {
Controller.getInstance().setLaserPos((Puck)null);
}
if ((dialogAskPuckDatamatrix != null) && (dialogAskPuckDatamatrix.isShowing())) {
dialogAskPuckDatamatrix.setVisible(false);
}
puckLoading = value;
}
hideDialogPuckLoading();
puckLoading = load;
onPuckScanned(null);
Device reader = getPuckBarcodeReader();
if (reader != null) {
@@ -710,14 +729,14 @@ public class Controller {
return ret;
};
try {
if (puckLoading) {
if (puckLoading!=null) {
getMainFrame().evalAsync(name + ".enable(); " + name + ".polling = 100", true).handle(errorHandler);
currentDetection = basePlate.getDetection();
} else if (getState().isInitialized()) {
getMainFrame().evalAsync(name + ".polling = 0; " + name + ".disable()", true).handle(errorHandler);
onPuckScanned(null);
}
getMainFrame().evalAsync("onPuckLoadingChange(" + (puckLoading ? "True" : "False") + ")");
getMainFrame().evalAsync("onPuckLoadingChange(" + ((puckLoading!=null) ? "True" : "False") + ")");
} catch (Exception ex) {
errorHandler.apply(null, ex);
}
@@ -726,12 +745,27 @@ public class Controller {
}
}
public boolean isPuckLoading() {
if (puckLoading == null) {
return false;
}
public Boolean isPuckLoading() {
return puckLoading;
}
public void setLaserPos(String pos){
try {
getMainFrame().evalAsync("set_laser_pos(" + ((pos==null) ? "" : ("'" + pos + "'") ) + ")" ,true);
} catch (Context.ContextStateException ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void setLaserPos(Puck puck){
if (puck==null){
setLaserPos((String)null);
} else {
setLaserPos(puck.getName());
}
}
void playSound(String name) {
try {
@@ -742,7 +776,7 @@ public class Controller {
}
public void onPuckBarcode(String datamatrix) {
if (isPuckLoading()) {
if (isPuckLoading()!=null) {
playSound("scanned");
System.out.println("Detected Puck: " + datamatrix);
onPuckScanned(datamatrix);
@@ -755,21 +789,19 @@ public class Controller {
}
void onPuckDetectionChanged() {
if (isPuckLoading()) {
if (isPuckLoading()!=null) {
Puck.Detection[] detection = basePlate.getDetection();
for (int i = 0; i < Controller.NUMBER_OF_PUCKS; i++) {
Puck puck = basePlate.getPucks()[i];
if (isSelectedPuck(puck)) {
boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present);
boolean detectedPuckRemoved = (currentDetection[i] != Puck.Detection.Empty) && (detection[i] == Puck.Detection.Empty);
if (detectedPuckInserted) {
onPuckInserted(puck);
boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present);
boolean detectedPuckRemoved = (currentDetection[i] != Puck.Detection.Empty) && (detection[i] == Puck.Detection.Empty);
if (detectedPuckInserted) {
onPuckInserted(puck);
} else if (detectedPuckRemoved) {
playSound("unmounted");
onPuckUnmounted(puck);
}
} else if (detectedPuckRemoved) {
playSound("unmounted");
onPuckUnmounted(puck);
}
}
@@ -902,13 +934,24 @@ public class Controller {
}
void showDialogPuckLoading() {
void showDialogPuckLoading(boolean load) {
if ((dialogPuckLoading != null) && (dialogPuckLoading.isVisible())) {
return;
}
dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), false);
dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), load, false);
dialogPuckLoading.setLocationRelativeTo(mainFrame);
dialogPuckLoading.setVisible(true);
dialogPuckLoading.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try{
setPuckLoading(null);
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
}
}
});
}
void hideDialogPuckLoading() {
@@ -919,21 +962,23 @@ public class Controller {
}
}
void onPuckLoadingModeChange(boolean puckLoadMode) {
void onPuckLoadingModeChange(Boolean puckLoadMode) {
if (puckMountMode == PuckMountMode.Dialog) {
if (puckLoadMode) {
showDialogPuckLoading();
if (puckLoadMode!=null) {
showDialogPuckLoading(puckLoadMode);
mainFrame.setViewDesign();
} else {
hideDialogPuckLoading();
mainFrame.setViewCamera();
}
}
}
void onPuckScanned(String datamatrix) {
if (isPuckLoading()) {
if (isPuckLoading()!=null) {
getMainFrame().setPuckDatamatrix(datamatrix);
if (puckMountMode == PuckMountMode.Dialog) {
showDialogPuckLoading();
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckScanned(datamatrix);
}
} else {
@@ -942,9 +987,9 @@ public class Controller {
}
void onPuckMounted(Puck puck, String datamatrix) {
if (isPuckLoading()) {
if (isPuckLoading()!=null) {
if (puckMountMode == PuckMountMode.Dialog) {
showDialogPuckLoading();
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckMounted(puck, datamatrix);
} else {
if (!datamatrix.isEmpty()) {
@@ -957,7 +1002,7 @@ public class Controller {
}
void onPuckUnmounted(Puck puck) {
if (isPuckLoading()) {
if (isPuckLoading()!=null) {
try{
Sample sample = getMountedSample();
if ((sample!=null) && (sample.getPuck() == puck)){
@@ -971,7 +1016,7 @@ public class Controller {
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
}
if (puckMountMode == PuckMountMode.Dialog) {
showDialogPuckLoading();
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckUnmounted(puck);
} else {
linkPuckDatamatrix(puck, null, true);

View File

@@ -20,7 +20,7 @@ public class ControllerRT extends Controller{
ControllerRT(Panel mainFrame) {
//basePlate = new BasePlate();
basePlate.addListener(basePlateListener);
setPuckLoading(false);
setPuckLoading(null);
for (PuckState ps : getPuckStates()){
ps.set(1, 0);
}

View File

@@ -283,10 +283,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="buttonSampleLoad" pref="90" max="32767" attributes="0"/>
<Component id="buttonSampleUnload" max="32767" attributes="0"/>
</Group>
<Component id="buttonSampleLoad" pref="90" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@@ -294,11 +291,9 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="buttonSampleLoad" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="buttonSampleUnload" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -312,14 +307,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonSampleLoadActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="buttonSampleUnload">
<Properties>
<Property name="text" type="java.lang.String" value="Unload"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonSampleUnloadActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelCover">

View File

@@ -74,10 +74,12 @@ public class MainPanel extends Panel {
Boolean manualMode;
Boolean roomTemperature;
public final String PUCK_LOADING_STATUS = "Puck loading";
public final String PUCK_UNLOADING_STATUS = "Puck unloading";
StatusBar statusBar;
JPopupMenu samplePopupMenu;
JMenuItem menuMountSample;
JMenuItem menuUnmoountSample;
boolean doorsHaveOpened;
public enum BasePlateLayout {
@@ -408,6 +410,7 @@ public class MainPanel extends Panel {
((Device) getDevice("feedback_psys_safety")).addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
doorsHaveOpened = Boolean.FALSE.equals(value);
updatePsysSafety(value);
}
});
@@ -453,6 +456,15 @@ public class MainPanel extends Panel {
Controller.getInstance().onStateChange(state, former);
}
public void setViewCamera(){
buttonCamera.setSelected(true);
SwingUtilities.invokeLater(()->{updateCameraView();});
}
public void setViewDesign(){
buttonDrawing.setSelected(true);
SwingUtilities.invokeLater(()->{updateCameraView();});
}
@Override
protected void onTimer() {
try {
@@ -488,10 +500,11 @@ public class MainPanel extends Panel {
Controller.getInstance().onTimer();
if (getState() == State.Ready) {
if (Boolean.TRUE.equals(Controller.getInstance().isPuckLoading())) {
setStatus(PUCK_LOADING_STATUS);
Boolean puckLoading = Controller.getInstance().isPuckLoading();
if (puckLoading==null){
setStatus("Ready");
} else {
setStatus("Ready");
setStatus(puckLoading ? PUCK_LOADING_STATUS : PUCK_UNLOADING_STATUS);
}
} else {
status = null;
@@ -580,7 +593,7 @@ public class MainPanel extends Panel {
ledDryer.setColor(Color.GREEN);
}
}
void updatePsysSafety(Object value) {
if ((value == null) || !(value instanceof Boolean)) {
ledPsysSafety.setColor(Color.BLACK);
@@ -591,7 +604,15 @@ public class MainPanel extends Panel {
} else {
ledPsysSafety.setColor(Color.RED);
}
}
if (!Boolean.TRUE.equals(value)){
try {
Controller.getInstance().setPuckLoading(null);
} catch (Exception ex) {
getLogger().log(Level.WARNING, null, ex);
}
}
buttonSampleLoad.setEnabled(!Boolean.TRUE.equals(value));
}
void updateMode(Object value) {
if ((value != null) && (value instanceof Map)) {
@@ -1005,9 +1026,24 @@ public class MainPanel extends Panel {
if ((value!=null) && (value instanceof String) && ((String)value).toLowerCase().startsWith("no cover")){
textCoverDet.setText("No Cover");
} else {
textCoverDet.setText((fmm==null) ? "" :fmm.x + ", " + fmm.y);
textCoverDet.setText((fmm==null) ? "" :fmm.x + ", " + fmm.y);
if ( getState().isReady() &&
!checkExpert.isSelected() &&
Boolean.FALSE.equals(Controller.getInstance().isDoorClosed())){
try{
if ((fmm!=null)){
Controller.getInstance().setPuckLoading(null);
} else {
if (doorsHaveOpened){
doorsHaveOpened=false;
Controller.getInstance().setPuckLoading(true);
}
}
} catch (Exception e) {
getLogger().log(Level.WARNING, null, e);
}
}
}
String text;
try {
List cache = (List)eval("get_cover_location_cache()", true);
@@ -1031,10 +1067,6 @@ public class MainPanel extends Panel {
};
void sampleTransfer(boolean load) throws Exception{
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@@ -1060,7 +1092,6 @@ public class MainPanel extends Panel {
jLabel23 = new javax.swing.JLabel();
panelDetection = new javax.swing.JPanel();
buttonSampleLoad = new javax.swing.JButton();
buttonSampleUnload = new javax.swing.JButton();
panelCover = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
textCoverDet = new javax.swing.JTextField();
@@ -1224,32 +1255,21 @@ public class MainPanel extends Panel {
}
});
buttonSampleUnload.setText("Unload");
buttonSampleUnload.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSampleUnloadActionPerformed(evt);
}
});
javax.swing.GroupLayout panelDetectionLayout = new javax.swing.GroupLayout(panelDetection);
panelDetection.setLayout(panelDetectionLayout);
panelDetectionLayout.setHorizontalGroup(
panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelDetectionLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(buttonSampleLoad, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addComponent(buttonSampleUnload, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(buttonSampleLoad, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addContainerGap())
);
panelDetectionLayout.setVerticalGroup(
panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelDetectionLayout.createSequentialGroup()
.addContainerGap()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonSampleLoad)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonSampleUnload)
.addContainerGap())
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
panelCover.setBorder(javax.swing.BorderFactory.createTitledBorder("Cover Detection"));
@@ -2005,7 +2025,7 @@ public class MainPanel extends Panel {
}// </editor-fold>//GEN-END:initComponents
private void buttonCameraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCameraActionPerformed
updateViewType();
setViewCamera();
}//GEN-LAST:event_buttonCameraActionPerformed
private void buttonExpertCommandsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExpertCommandsActionPerformed
@@ -2052,7 +2072,7 @@ public class MainPanel extends Panel {
}//GEN-LAST:event_checkExpertActionPerformed
private void buttonDrawingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDrawingActionPerformed
updateViewType();
setViewDesign();
}//GEN-LAST:event_buttonDrawingActionPerformed
private void btViewDewarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btViewDewarActionPerformed
@@ -2125,17 +2145,9 @@ public class MainPanel extends Panel {
}
}//GEN-LAST:event_checkServiceActionPerformed
private void buttonSampleUnloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSampleUnloadActionPerformed
try {
sampleTransfer(true);
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonSampleUnloadActionPerformed
private void buttonSampleLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSampleLoadActionPerformed
try {
sampleTransfer(false);
Controller.getInstance().setPuckLoading(true);
} catch (Exception ex) {
showException(ex);
}
@@ -2156,7 +2168,6 @@ public class MainPanel extends Panel {
private javax.swing.JButton buttonRecovery;
private javax.swing.JButton buttonRelease;
private javax.swing.JButton buttonSampleLoad;
private javax.swing.JButton buttonSampleUnload;
private javax.swing.JCheckBox checkExpert;
private javax.swing.JCheckBox checkService;
private ch.psi.mxsc.DevicesPanel devicesPanel;

View File

@@ -331,10 +331,6 @@ public class Puck extends DeviceBase {
}
public boolean isSegmentSelected() {
return false;
}
public int getIndex() {
return index;
}

View File

@@ -88,7 +88,7 @@ public class PuckGraphics {
if (MainPanel.BASE_PLATE_LAYOUT == MainPanel.BasePlateLayout.rt){
return puck.isSelected();
}
return puck.isSelected() || puck.isSegmentSelected();
return puck.isSelected();
}
Color getEmptyColor(){
@@ -237,9 +237,7 @@ public class PuckGraphics {
if (MainPanel.BASE_PLATE_LAYOUT == MainPanel.BasePlateLayout.rt){
selectedWidth = 3;
}
return drawBackground ?
puck.isSegmentSelected() ? selectedWidth : normalWidth :
puck.isSegmentSelected() ? selectedWidth : normalWidth;
return normalWidth;
}
int getReferenceDrawSize() {

View File

@@ -22,6 +22,7 @@ import javax.swing.table.DefaultTableModel;
public class PuckLoadingDialog extends JDialog {
Path dialogPersistPath;
DefaultTableModel model;
final boolean load;
final int INDEX_DEWAR = 0;
final int INDEX_DATAMATRIX = 1;
@@ -29,9 +30,10 @@ public class PuckLoadingDialog extends JDialog {
/**
* Creates new form PuckLoadingDialog
*/
public PuckLoadingDialog(java.awt.Frame parent, boolean modal) {
super(parent, "Puck Loading", modal);
public PuckLoadingDialog(java.awt.Frame parent, boolean load, boolean modal) {
super(parent, load ? "Puck Loading" : "Puck Unloading", modal);
initComponents();
this.load = load;
this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
this.setName("PuckLoadingDialog");
dialogPersistPath = Paths.get(Context.getInstance().getSetup().getContextPath(), getClass().getSimpleName());
@@ -91,8 +93,11 @@ public class PuckLoadingDialog extends JDialog {
if ((datamatrix != null) && (!datamatrix.isEmpty())){
setStatusLabel("Scanned puck " + datamatrix, 5000);
makeVisible(datamatrix);
Puck puck = Controller.getInstance().getFreePuck();
Controller.getInstance().setLaserPos(puck.getName());
} else {
setStatusLabel(null, -1);
setStatusLabel(null, -1);
Controller.getInstance().setLaserPos((Puck)null);
}
setSugestionLabel(null, -1);
buttonSet.setEnabled(false);
@@ -103,6 +108,7 @@ public class PuckLoadingDialog extends JDialog {
Puck detectedPuck;
String detectedDatamatrix;
void onPuckMounted(Puck puck, String datamatrix){
Controller.getInstance().setLaserPos((Puck)null);
if ((datamatrix != null) && (!datamatrix.isEmpty())) {
Controller.getInstance().linkPuckDatamatrix(puck, datamatrix, false);
setStatusLabel("Mounted puck " + datamatrix + " at " + puck.getName(), 5000);
@@ -413,7 +419,7 @@ public class PuckLoadingDialog extends JDialog {
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
PuckLoadingDialog dialog = new PuckLoadingDialog(new javax.swing.JFrame(), true);
PuckLoadingDialog dialog = new PuckLoadingDialog(new javax.swing.JFrame(), true, true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {