diff --git a/plugins/ScreenPanel3.form b/plugins/ScreenPanel3.form
index bc4a4f3..8f0edfa 100644
--- a/plugins/ScreenPanel3.form
+++ b/plugins/ScreenPanel3.form
@@ -1058,6 +1058,7 @@
+
diff --git a/plugins/ScreenPanel3.java b/plugins/ScreenPanel3.java
index cc49097..6bc280b 100644
--- a/plugins/ScreenPanel3.java
+++ b/plugins/ScreenPanel3.java
@@ -47,6 +47,7 @@ import ch.psi.pshell.scripting.ScriptManager;
import ch.psi.pshell.swing.DeviceValueChart;
import ch.psi.pshell.swing.ValueSelection;
import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener;
+import ch.psi.pshell.ui.Console;
import ch.psi.utils.Arr;
import ch.psi.utils.ArrayProperties;
import ch.psi.utils.Convert;
@@ -254,6 +255,7 @@ public class ScreenPanel3 extends Panel {
Frame currentFrame;
int imageBufferLenght = 1;
Text imagePauseOverlay;
+ final Console console;
public ScreenPanel3() {
try {
@@ -550,10 +552,43 @@ public class ScreenPanel3 extends Panel {
});
if (MainFrame.isDark()) {
textState.setDisabledTextColor(textState.getForeground());
- }
+ }
+
} catch (Exception ex) {
ex.printStackTrace();
}
+
+ console = (!App.hasArgument("console")) ? null : new Console() {
+ /*
+ protected void onConsoleCommand(String name, String[] pars, String trimming) throws Exception {
+ switch (name) {
+ case "cam":
+ comboCameras.setSelectedItem(tokens[1]);
+ break;
+ }
+ }*/
+ @Override
+ protected void onConsoleCommand(String command) {
+ String[] tokens = command.split(" ");
+ if ((tokens.length > 1) && tokens[0].equals("cam")){
+ try{
+ if (!tokens[1].equals(comboCameras.getSelectedItem())){
+ setComboTypeSelection("All");
+ updateCameraList();
+ comboCameras.setSelectedItem(tokens[1]);
+ if (!tokens[1].equals(comboCameras.getSelectedItem())){
+ throw new Exception("Invalid camera name : " + tokens[1]);
+ }
+ System.out.println("Console set camera: " + tokens[1]);
+ }
+ } catch (Exception ex){
+ System.err.println(ex);
+ }
+ } else {
+ System.err.println("Invalid command: " + command);
+ }
+ }
+ };
}
void setIntegration(int frames) {
@@ -585,6 +620,9 @@ public class ScreenPanel3 extends Panel {
buttonServer.setSelected(!direct);
buttonDirect.setSelected(direct);
}
+ if (App.hasArgument("console")) {
+ console.start();
+ }
}
@Override
@@ -599,6 +637,13 @@ public class ScreenPanel3 extends Panel {
} catch (Exception ex) {
ex.printStackTrace();
}
+ try {
+ if (console != null) {
+ console.stop();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
super.onStop();
}
@@ -628,8 +673,8 @@ public class ScreenPanel3 extends Panel {
updateCameraList();
comboCameras.setEnabled(true);
comboType.setEnabled(true);
- setComboCameraSelection(-1);
- setComboTypeSelection(0);
+ setComboCameraSelection(null);
+ setComboTypeSelection("All");
if (comboCameras.getModel().getSize() > 0) {
try {
@@ -794,10 +839,12 @@ public class ScreenPanel3 extends Panel {
Thread devicesInitTask;
void setCamera(String cameraName) throws IOException, InterruptedException {
- System.out.println("Initializing");
+ System.out.println("Initializing: " + cameraName);
parseUserOverlays();
errorOverlay = null;
lastMarkerPos = null;
+ lastFrame = null;
+ lastPipelinePars = null;
if (dataTableDialog != null) {
dataTableDialog.dispose();
@@ -901,7 +948,7 @@ public class ScreenPanel3 extends Panel {
}
server.start(pipelineName, instanceName);
- updateServerControls();
+ updatePipelineControls();
checkThreshold.setEnabled(true);
checkGoodRegion.setEnabled(true);
} else {
@@ -977,7 +1024,7 @@ public class ScreenPanel3 extends Panel {
} catch (Exception ex) {
showException(ex);
renderer.clearOverlays();
- updateServerControls();
+ updatePipelineControls();
if (renderer.getDevice() == null) {
//renderer.setZoom(1.0);
//renderer.setMode(RendererMode.Zoom);
@@ -1256,40 +1303,97 @@ public class ScreenPanel3 extends Panel {
updatingColormap = false;
}
- boolean updatingServerControls;
-
- void updateServerControls() {
- if (server != null) {
- updatingServerControls = true;
- try {
- checkBackground.setSelected(server.getBackgroundSubtraction());
- Double threshold = (server.getThreshold());
- checkThreshold.setSelected(threshold != null);
- spinnerThreshold.setValue((threshold == null) ? 0 : threshold);
- Map gr = (server.getGoodRegion());
- checkGoodRegion.setSelected(gr != null);
- if (gr != null) {
- spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue());
- spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue());
- }
- Map slicing = (server.getSlicing());
- checkSlicing.setSelected(slicing != null);
- if (slicing != null) {
- spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue());
- spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue());
- spinnerSlOrientation.setValue((String) slicing.get("orientation"));
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ void updatePipelineProperties(){
goodRegion = checkGoodRegion.isSelected();
spinnerThreshold.setVisible(checkThreshold.isSelected());
setGoodRegionOptionsVisible(goodRegion);
slicing = goodRegion && checkSlicing.isSelected();
setSlicingOptionsVisible(slicing);
- updatingServerControls = false;
+ updatingServerControls = false;
+ }
+
+ boolean updatingServerControls;
+
+ void updatePipelineControls() {
+ if (server != null) {
+ updatingServerControls = true;
+ if (server.isStarted()){
+ try {
+ checkBackground.setSelected(server.getBackgroundSubtraction());
+ Double threshold = (server.getThreshold());
+ checkThreshold.setSelected(threshold != null);
+ spinnerThreshold.setValue((threshold == null) ? 0 : threshold);
+ Map gr = (server.getGoodRegion());
+ checkGoodRegion.setSelected(gr != null);
+ if (gr != null) {
+ spinnerGrThreshold.setValue(((Number) gr.get("threshold")).doubleValue());
+ spinnerGrScale.setValue(((Number) gr.get("gfscale")).doubleValue());
+ }
+ Map slicing = (server.getSlicing());
+ checkSlicing.setSelected(slicing != null);
+ if (slicing != null) {
+ spinnerSlNumber.setValue(((Number) slicing.get("number_of_slices")).intValue());
+ spinnerSlScale.setValue(((Number) slicing.get("scale")).doubleValue());
+ spinnerSlOrientation.setValue((String) slicing.get("orientation"));
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ updatePipelineProperties();
}
}
+
+ boolean changedPipelinePars(Map pars1, Map pars2) {
+ String[] keys = new String[]{"image_background_enable", "image_threshold", "image_good_region",
+ "threshold", "gfscale", "image_slices", "number_of_slices", "scale", "orientation"};
+ for (String key:keys){
+ Object o1 = pars1.get(key);
+ Object o2 = pars2.get(key);
+ if (o1==null){
+ if (o2!=null){
+ return true;
+ }
+ } else if (!o1.equals(o2)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void updatePipelineControls(Map pars) {
+ if (pars!=null){
+ updatingServerControls = true;
+ try {
+ boolean background = (boolean) pars.get("image_background_enable");
+ checkBackground.setSelected(background);
+ Double threshold = (Double) (pars.get("image_threshold"));
+ checkThreshold.setSelected(threshold != null);
+ spinnerThreshold.setValue((threshold == null) ? 0 : threshold);
+ Map gr = (Map) pars.get("image_good_region");
+ checkGoodRegion.setSelected(gr != null);
+ if (gr != null) {
+ Double value = ((Number) gr.get("threshold")).doubleValue();
+ spinnerGrThreshold.setValue(value);
+ Double scale = ((Number) gr.get("gfscale")).doubleValue();
+ spinnerGrScale.setValue(scale);
+ }
+ Map slicing = (Map) (pars.get("image_slices"));
+ checkSlicing.setSelected(slicing != null);
+ if (slicing != null) {
+ int slices = ((Number) slicing.get("number_of_slices")).intValue();
+ spinnerSlNumber.setValue(slices);
+ double scale = ((Number) slicing.get("scale")).doubleValue();
+ spinnerSlScale.setValue(scale);
+ String orientation = (String) slicing.get("orientation");
+ spinnerSlOrientation.setValue(orientation);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ updatePipelineProperties();
+ }
+ }
void setGoodRegionOptionsVisible(boolean visible) {
spinnerGrThreshold.setVisible(visible);
@@ -1346,6 +1450,10 @@ public class ScreenPanel3 extends Panel {
updatingButtons = false;
}
}
+
+ Frame lastFrame = null;
+ Map lastPipelinePars = null;
+
@Override
protected void onTimer() {
@@ -1369,6 +1477,23 @@ public class ScreenPanel3 extends Panel {
updateColormap();
updateButtons();
checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing()));
+
+ try{
+ Frame frame = getCurrentFrame();
+ if (frame!=lastFrame){
+ lastFrame = frame;
+ if (frame!=null){
+ Map pars = getProcessingParameters(frame.cache);
+ if((lastPipelinePars==null) || changedPipelinePars(pars, lastPipelinePars)){
+ //System.out.println("Update pipeline: " + pars);
+ lastPipelinePars = pars;
+ updatePipelineControls(pars);
+ }
+ }
+ }
+ } catch (Exception ex){
+ ex.printStackTrace();
+ }
}
Pen penFit = new Pen(new Color(192, 105, 0), 0);
@@ -2047,7 +2172,7 @@ public class ScreenPanel3 extends Panel {
}
ArrayList frames = new ArrayList<>();
frames.add(frame);
- this.saveFrames("camera_snapshot", frames);
+ this.saveFrames(cameraName + "_camera_snapshot", frames);
//Enforce the same timestamp to data & image files.
snapshotFile = getContext().getExecutionPars().getPath() + ".png";
@@ -2085,8 +2210,9 @@ public class ScreenPanel3 extends Panel {
message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n");
message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n");
message.append("Comment: ").append(textComment.getText()).append("\n");
- if ((fitOv != null) && (fitOv.length > 5)) {
- Overlays.Text text = (Overlays.Text) fitOv[5];
+ //Add slicing message
+ if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length-1] instanceof Overlays.Text)) {
+ Overlays.Text text = (Overlays.Text) fitOv[fitOv.length-1];
message.append(text.getText()).append("\n");
}
elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile});
@@ -2095,9 +2221,9 @@ public class ScreenPanel3 extends Panel {
void saveStack() throws Exception {
synchronized (imageBuffer) {
- saveFrames("camera_stack", imageBuffer);
+ saveFrames(cameraName + "_camera_stack", imageBuffer);
}
- SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000);
+ SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath());
}
public static String getCameraType(String name) {
@@ -2340,6 +2466,11 @@ public class ScreenPanel3 extends Panel {
dev.setPolling(1000);
chart.setDevice(dev);
JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName + " " + id, null, chart);
+ //TODO:
+ //PlotBase plot = chart.getPlot();
+ //if (plot!=null){
+ // plot.setPlotBackgroundColor(Color.BLACK);
+ //}
}
}
}
@@ -3205,6 +3336,7 @@ public class ScreenPanel3 extends Panel {
toolBar.add(buttonReticle);
buttonTitle.setIcon(getIcon("Title"));
+ buttonTitle.setSelected(true);
buttonTitle.setText(" ");
buttonTitle.setToolTipText("Show Camera Name");
buttonTitle.setFocusable(false);
@@ -3502,7 +3634,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
}
}
}//GEN-LAST:event_spinnerThresholdonChange
@@ -3516,7 +3648,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
updatingServerControls = true;
checkBackground.setSelected(false);
updatingServerControls = false;
@@ -3537,7 +3669,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
}
}
}//GEN-LAST:event_checkThresholdActionPerformed
@@ -3556,7 +3688,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
}
}
}//GEN-LAST:event_checkGoodRegionActionPerformed
@@ -3569,7 +3701,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
}
}
}//GEN-LAST:event_spinnerGrThresholdonChange
@@ -3603,7 +3735,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
}
}
}//GEN-LAST:event_checkSlicingActionPerformed
@@ -3616,7 +3748,7 @@ public class ScreenPanel3 extends Panel {
}
} catch (Exception ex) {
showException(ex);
- updateServerControls();
+ updatePipelineControls();
}
}
}//GEN-LAST:event_spinnerSlicingChange
@@ -3765,11 +3897,13 @@ public class ScreenPanel3 extends Panel {
private void comboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeActionPerformed
try {
- updateCameraList();
- if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) {
- setCamera(null);
- } else {
- setCamera(cameraName);
+ if (!updatingCameraSelection) {
+ updateCameraList();
+ if ((cameraName != null) && (!cameraName.equals(comboCameras.getSelectedItem()))) {
+ setCamera(null);
+ } else {
+ setCamera(cameraName);
+ }
}
} catch (Exception ex) {