From d21a493b4688fc3cafba10c289e8e940670cde2a Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 3 Sep 2024 14:58:15 -0700 Subject: [PATCH] enable xyz grid button --- .../gui/frames/XYZGridFrame.java | 27 +++++++------ .../gui/tabs/AcquisitionTab.java | 6 ++- .../tabs/acquisition/MultiPositionPanel.java | 40 ++++++++++++------- .../gui/tabs/acquisition/TimePointsPanel.java | 1 + .../model/DeviceManager.java | 12 +++++- .../lightsheetmanager/model/XYZGrid.java | 11 +++-- .../model/devices/Stage.java | 18 +++++++++ .../model/devices/XYStage.java | 2 +- 8 files changed, 81 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/frames/XYZGridFrame.java b/src/main/java/org/micromanager/lightsheetmanager/gui/frames/XYZGridFrame.java index 71971c6..88c6504 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/frames/XYZGridFrame.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/frames/XYZGridFrame.java @@ -63,6 +63,7 @@ private void createUserInterface() { "[]10[]" )); + Spinner.setDefaultSize(7); Button.setDefaultSize(160, 26); btnComputeGrid_ = new Button("Compute Grid"); btnEditPositionList_ = new Button("Edit Position List..."); @@ -80,7 +81,7 @@ private void createUserInterface() { Panel.setMigLayoutDefault( "insets 10 10 10 10", - "[]15[]", + "[]10[]", "[]10[]" ); final Panel pnlX = new Panel(cbxUseX_); @@ -89,9 +90,9 @@ private void createUserInterface() { final Panel pnlButtons = new Panel(); // X - final JLabel lblXStart = new JLabel("X start [\u00B5m]:"); - final JLabel lblXStop = new JLabel("X stop [\u00B5m]:"); - final JLabel lblXDelta = new JLabel("X delta [\u00B5m]:"); + final JLabel lblXStart = new JLabel("X start [µm]:"); + final JLabel lblXStop = new JLabel("X stop [µm]:"); + final JLabel lblXDelta = new JLabel("X delta [µm]:"); final JLabel lblXCount = new JLabel("Slice count:"); spnXStart_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0); @@ -99,9 +100,9 @@ private void createUserInterface() { spnXDelta_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0); // Y - final JLabel lblYStart = new JLabel("Y start [\u00B5m]:"); - final JLabel lblYStop = new JLabel("Y stop [\u00B5m]:"); - final JLabel lblYDelta = new JLabel("Y delta [\u00B5m]:"); + final JLabel lblYStart = new JLabel("Y start [µm]:"); + final JLabel lblYStop = new JLabel("Y stop [µm]:"); + final JLabel lblYDelta = new JLabel("Y delta [µm]:"); final JLabel lblYCount = new JLabel("Y count:"); spnYStart_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0); @@ -109,9 +110,9 @@ private void createUserInterface() { spnYDelta_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0); // Z - final JLabel lblZStart = new JLabel("Z start [\u00B5m]:"); - final JLabel lblZStop = new JLabel("Z stop [\u00B5m]:"); - final JLabel lblZDelta = new JLabel("Z delta [\u00B5m]:"); + final JLabel lblZStart = new JLabel("Z start [µm]:"); + final JLabel lblZStop = new JLabel("Z stop [µm]:"); + final JLabel lblZDelta = new JLabel("Z delta [µm]:"); final JLabel lblZCount = new JLabel("Z count:"); spnZStart_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0); @@ -120,6 +121,7 @@ private void createUserInterface() { final Panel pnlSettings = new Panel("Grid Settings"); final JLabel lblOverlap = new JLabel("Overlap (Y and Z) [%]"); + Spinner.setDefaultSize(4); spnOverlapYZ_ = Spinner.createIntegerSpinner(10, 0, 100, 1); cbxClearPositions_ = new CheckBox("Clear position list if YZ unused", false); @@ -160,12 +162,13 @@ private void createUserInterface() { pnlButtons.add(btnRunOverviewAcq_, ""); add(pnlY, "growx"); - add(pnlZ, "wrap"); + add(pnlZ, "growx, wrap"); add(pnlX, "growx"); add(pnlSettings, "wrap"); add(pnlButtons, ""); - pack(); + pack(); // fit window size to layout + setIconImage(Icons.MICROSCOPE.getImage()); } private void createEventHandlers() { diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/AcquisitionTab.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/AcquisitionTab.java index 5d7b66e..2335b04 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/AcquisitionTab.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/AcquisitionTab.java @@ -112,7 +112,7 @@ private void createUserInterface() { "Multiple positions (XY)", acqSettings.isUsingMultiplePositions()); pnlMultiPositions_ = new MultiPositionPanel(model_, cbxUseMultiplePositions_); // disable elements based on acqSettings - pnlMultiPositions_.setEnabled(acqSettings.isUsingMultiplePositions()); + pnlMultiPositions_.setPanelEnabled(acqSettings.isUsingMultiplePositions()); // time points cbxUseTimePoints_ = new CheckBox( @@ -308,6 +308,10 @@ public SliceSettingsPanel getSliceSettingsPanel() { return pnlSliceSettings_; } + public MultiPositionPanel getMultiPositionPanel() { + return pnlMultiPositions_; + } + private void acqFinishedCallback() { try { SwingUtilities.invokeAndWait(() -> { diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/MultiPositionPanel.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/MultiPositionPanel.java index 5d2d422..42b6dbe 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/MultiPositionPanel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/MultiPositionPanel.java @@ -1,6 +1,5 @@ package org.micromanager.lightsheetmanager.gui.tabs.acquisition; -import org.micromanager.lightsheetmanager.api.internal.DefaultAcquisitionSettingsSCAPE; import org.micromanager.lightsheetmanager.gui.components.Button; import org.micromanager.lightsheetmanager.gui.components.CheckBox; import org.micromanager.lightsheetmanager.gui.components.Label; @@ -30,17 +29,17 @@ public MultiPositionPanel(final LightSheetManager model, final CheckBox cbxUseMu } private void createUserInterface() { - final DefaultAcquisitionSettingsSCAPE acqSettings = - model_.acquisitions().settings(); - Spinner.setDefaultSize(7); + // post move delay lblPostMoveDelay_ = new Label("Post-move delay [ms]:"); + Spinner.setDefaultSize(8); spnPostMoveDelay_ = Spinner.createIntegerSpinner( - acqSettings.postMoveDelay(), 0, Integer.MAX_VALUE, 100); - btnEditPositionList_ = new Button("Edit Position List", 120, 24); - btnOpenXYZGrid_ = new Button("XYZ Grid", 80, 24); + model_.acquisitions().settings().postMoveDelay(), + 0, Integer.MAX_VALUE, 100); - btnOpenXYZGrid_.setEnabled(false); + // XYZ grid + btnEditPositionList_ = new Button("Edit Position List...", 130, 24); + btnOpenXYZGrid_ = new Button("XYZ Grid...", 90, 24); add(btnEditPositionList_, ""); add(btnOpenXYZGrid_, "wrap"); @@ -50,21 +49,32 @@ private void createUserInterface() { private void createEventHandlers() { - btnOpenXYZGrid_.registerListener(e -> xyzGridFrame_.setVisible(true)); + // open XYZ grid + btnOpenXYZGrid_.registerListener(e -> { + if (model_.devices().hasDevice("SampleXY") + && model_.devices().hasDevice("SampleZ")) { + xyzGridFrame_.setVisible(true); + } else { + model_.studio().logs().showError( + "SampleXY and SampleZ must not be \"Undefined\" to use the XYZ grid."); + } + }); + + // open position list btnEditPositionList_.registerListener(e -> model_.studio().app().showPositionList()); - spnPostMoveDelay_.registerListener(e -> { - model_.acquisitions().settingsBuilder().postMoveDelay(spnPostMoveDelay_.getInt()); - //System.out.println("getPostMoveDelay: " + model_.acquisitions().getAcquisitionSettings().getPostMoveDelay()); - }); + spnPostMoveDelay_.registerListener(e -> model_.acquisitions() + .settingsBuilder().postMoveDelay(spnPostMoveDelay_.getInt())); } - @Override - public void setEnabled(final boolean state) { + public void setPanelEnabled(final boolean state) { lblPostMoveDelay_.setEnabled(state); spnPostMoveDelay_.setEnabled(state); btnEditPositionList_.setEnabled(state); } + public XYZGridFrame getXYZGridFrame() { + return xyzGridFrame_; + } } diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/TimePointsPanel.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/TimePointsPanel.java index af1c6c3..ed36686 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/TimePointsPanel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/acquisition/TimePointsPanel.java @@ -35,6 +35,7 @@ private void createUserInterface() { "[]5[]" ); + Spinner.setDefaultSize(6); lblNumTimePoints_ = new Label("Number:"); lblTimePointInterval_ = new Label("Interval [s]:"); spnNumTimePoints_ = Spinner.createIntegerSpinner( diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java b/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java index 6c3360d..1225623 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java @@ -45,7 +45,8 @@ public class DeviceManager { private final Studio studio_; private final CMMCore core_; - private Map deviceMap_; + /* Maps the Device Adapter device name to a Device object */ + private final Map deviceMap_; private static String deviceAdapterName_; @@ -463,4 +464,13 @@ public void checkDevices(final JFrame frame) { } } + /** + * Return true if the device is set to a value other than "Undefined". + * + * @param deviceName the device adapter name ("SampleXY", "SampleZ", etc.) + * @return true if the device is present + */ + public boolean hasDevice(final String deviceName) { + return !deviceMap_.get(deviceName).getDeviceName().equals("Undefined"); + } } diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/XYZGrid.java b/src/main/java/org/micromanager/lightsheetmanager/model/XYZGrid.java index e5732cd..7410a0f 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/XYZGrid.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/XYZGrid.java @@ -4,9 +4,8 @@ import org.micromanager.PositionList; import org.micromanager.StagePosition; import org.micromanager.lightsheetmanager.LightSheetManager; -import org.micromanager.lightsheetmanager.api.data.DISPIMDevice; -import org.micromanager.lightsheetmanager.model.devices.vendor.ASIXYStage; -import org.micromanager.lightsheetmanager.model.devices.vendor.ASIZStage; +import org.micromanager.lightsheetmanager.model.devices.Stage; +import org.micromanager.lightsheetmanager.model.devices.XYStage; import org.micromanager.lightsheetmanager.model.utils.GeometryUtils; import org.micromanager.lightsheetmanager.model.utils.NumberUtils; @@ -38,7 +37,7 @@ public class XYZGrid { private int overlapYZ_; private boolean clearYZ_; - private LightSheetManager model_; + private final LightSheetManager model_; public XYZGrid(final LightSheetManager model) { model_ = Objects.requireNonNull(model); @@ -88,8 +87,8 @@ private int updateGridZCount() { */ public void computeGrid() { - ASIXYStage xyStage = model_.devices().getDevice(DISPIMDevice.SAMPLE_XY); - ASIZStage zStage = model_.devices().getDevice(DISPIMDevice.SAMPLE_Z); + XYStage xyStage = model_.devices().getDevice("SampleXY"); + Stage zStage = model_.devices().getDevice("SampleZ"); final int numX = useX_ ? updateGridXCount() : 1; final int numY = useY_ ? updateGridYCount() : 1; diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/devices/Stage.java b/src/main/java/org/micromanager/lightsheetmanager/model/devices/Stage.java index 76d7dc3..a5c219b 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/devices/Stage.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/devices/Stage.java @@ -7,4 +7,22 @@ public class Stage extends DeviceBase { public Stage(final Studio studio, final String deviceName) { super(studio, deviceName); } + + public void setPosition(final double position) { + try { + core_.setPosition(deviceName_, position); + } catch (Exception e) { + studio_.logs().showError("could not set position for " + deviceName_); + } + } + + public double getPosition() { + try { + return core_.getPosition(deviceName_); + } catch (Exception e) { + studio_.logs().showError("could not get position for " + deviceName_); + return 0.0; + } + } + } \ No newline at end of file diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/devices/XYStage.java b/src/main/java/org/micromanager/lightsheetmanager/model/devices/XYStage.java index 197605c..b29aed0 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/devices/XYStage.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/devices/XYStage.java @@ -24,7 +24,7 @@ public void setRelativeXYPosition(final int x, final int y) { } } - public void setXYPosition(final int x, final int y) { + public void setXYPosition(final double x, final double y) { try { core_.setXYPosition(deviceName_, x, y); } catch (Exception e) {