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
+99 -54
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);