diff --git a/src/main/java/org/micromanager/lightsheetmanager/LightSheetManagerPlugin.java b/src/main/java/org/micromanager/lightsheetmanager/LightSheetManagerPlugin.java index a8a256f..307fcc3 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/LightSheetManagerPlugin.java +++ b/src/main/java/org/micromanager/lightsheetmanager/LightSheetManagerPlugin.java @@ -14,7 +14,7 @@ public class LightSheetManagerPlugin implements MenuPlugin, SciJavaPlugin { public static final String copyright = "Applied Scientific Instrumentation (ASI), 2022-2024"; public static final String description = "A plugin to control various types of light sheet microscopes."; public static final String menuName = "Light Sheet Manager"; - public static final String version = "0.4.3"; + public static final String version = "0.4.4"; private Studio studio_; private LightSheetManagerFrame frame_; diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/AcquisitionMode.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/AcquisitionMode.java index 2839d4e..e795e4c 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/AcquisitionMode.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/AcquisitionMode.java @@ -2,6 +2,9 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; // TODO: account for different naming on each geometry type (SLICE_SCAN_ONLY) @@ -21,6 +24,9 @@ public enum AcquisitionMode { private final String text_; + private static final Map stringToEnum = + Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); + AcquisitionMode(final String text) { text_ = text; } @@ -30,8 +36,8 @@ public String toString() { return text_; } - public static AcquisitionMode getByIndex(final int index) { - return values()[index]; + public static AcquisitionMode fromString(final String symbol) { + return stringToEnum.getOrDefault(symbol, AcquisitionMode.NONE); } public static String[] toArray() { diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusFitType.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusFitType.java index f6b96c5..5f96109 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusFitType.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusFitType.java @@ -18,7 +18,7 @@ public enum AutofocusFitType { Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); AutofocusFitType(final String text) { - this.text_ = text; + text_ = text; } public static String[] toArray() { diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusMode.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusMode.java index 047c952..40be707 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusMode.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusMode.java @@ -12,13 +12,13 @@ public enum AutofocusMode { FIXED_PIEZO_SWEEP_SLICE("Fixed piezo, sweep slice"), FIXED_SLICE_SWEEP_PIEZO("Fixed slice, sweep piezo"); - private final String name; + private final String name_; private static final Map stringToEnum = Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); AutofocusMode(final String name) { - this.name = name; + name_ = name; } public static String[] toArray() { @@ -33,7 +33,7 @@ public static AutofocusMode fromString(final String symbol) { @Override public String toString() { - return name; + return name_; } } diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusType.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusType.java index b26b7b8..e2faaf5 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusType.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/AutofocusType.java @@ -22,13 +22,13 @@ public enum AutofocusType { FFT_BANDPASS("FFTBandpass"), TENENGRAD("Tenengrad"); - private final String name; + private final String name_; private static final Map stringToEnum = Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); AutofocusType(final String name) { - this.name = name; + name_ = name; } public static String[] toArray() { @@ -43,7 +43,7 @@ public static AutofocusType fromString(final String symbol) { @Override public String toString() { - return name; + return name_; } } \ No newline at end of file diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/CameraMode.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/CameraMode.java index 0a0f6bd..41d47b4 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/CameraMode.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/CameraMode.java @@ -21,23 +21,19 @@ public enum CameraMode { PSEUDO_OVERLAP("Pseudo Overlap"), VIRTUAL_SLIT("Virtual Slit"); - private final String text; + private final String text_; private static final Map stringToEnum = Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); CameraMode(final String text) { - this.text = text; + text_ = text; } public static CameraMode fromString(final String symbol) { return stringToEnum.getOrDefault(symbol, CameraMode.EDGE); } - public static CameraMode getByIndex(final int index) { - return values()[index]; - } - /** * @return an array of Strings containing all possible camera trigger modes. */ @@ -117,7 +113,7 @@ public static String[] getAvailableModes(CameraLibrary camLib) { @Override public String toString() { - return text; + return text_; } } diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/GeometryType.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/GeometryType.java index 6599f35..c58cf84 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/GeometryType.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/GeometryType.java @@ -16,15 +16,15 @@ public enum GeometryType { private static final Map stringToEnum = Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); - private final String label; + private final String label_; GeometryType(final String label) { - this.label = label; + label_ = label; } @Override public String toString() { - return label; + return label_; } public static GeometryType fromString(final String symbol) { diff --git a/src/main/java/org/micromanager/lightsheetmanager/api/data/LightSheetType.java b/src/main/java/org/micromanager/lightsheetmanager/api/data/LightSheetType.java index 33b3645..baa49ec 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/api/data/LightSheetType.java +++ b/src/main/java/org/micromanager/lightsheetmanager/api/data/LightSheetType.java @@ -12,15 +12,15 @@ public enum LightSheetType { private static final Map stringToEnum = Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e)); - private final String label; + private final String label_; LightSheetType(final String label) { - this.label = label; + label_ = label; } @Override public String toString() { - return label; + return label_; } public static LightSheetType fromString(final String symbol) { 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 3cfaa95..5a85df1 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/AcquisitionTab.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/AcquisitionTab.java @@ -264,8 +264,9 @@ private void createEventHandlers() { // select the acquisition mode cmbAcquisitionModes_.registerListener(e -> { - final int index = cmbAcquisitionModes_.getSelectedIndex(); - model_.acquisitions().settingsBuilder().acquisitionMode(AcquisitionMode.getByIndex(index)); + final String selected = cmbAcquisitionModes_.getSelected(); + model_.acquisitions().settingsBuilder() + .acquisitionMode(AcquisitionMode.fromString(selected)); }); // TODO: should timing recalc be part of setting use advanced timing value in model? diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java index 99be902..e82fbc1 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java @@ -1,10 +1,12 @@ package org.micromanager.lightsheetmanager.gui.tabs.setup; +import org.micromanager.lightsheetmanager.api.data.CameraMode; import org.micromanager.lightsheetmanager.api.data.GeometryType; import org.micromanager.lightsheetmanager.gui.components.Button; import org.micromanager.lightsheetmanager.gui.components.Panel; import org.micromanager.lightsheetmanager.gui.data.Icons; import org.micromanager.lightsheetmanager.model.LightSheetManagerModel; +import org.micromanager.lightsheetmanager.model.devices.cameras.CameraBase; import java.util.Objects; @@ -96,26 +98,37 @@ private void createEventHandlers() { btnInvertedPath_.registerListener(e -> { // TODO: make this work, needs Device Adapter pull request and name for camera... closeLiveModeWindow(); - final String cameraName = model_.devices() - .getDevice("PreviewCamera").getDeviceName(); - try { - model_.studio().core().setCameraDevice(cameraName); - } catch (Exception ex) { - model_.studio().logs().showError("could not set camera to " + cameraName); + final CameraBase camera = model_.devices().getDevice("PreviewCamera"); + if (camera != null) { + try { + model_.studio().core().setCameraDevice(camera.getDeviceName()); + camera.setTriggerMode(CameraMode.INTERNAL); + } catch (Exception ex) { + model_.studio().logs().showError("could not set camera to " + camera.getDeviceName()); + } + model_.studio().live().setLiveModeOn(true); + } else { + model_.studio().logs().showError( + "No device for \"PreviewCamera\" set in the device adapter."); } - model_.studio().live().setLiveModeOn(true); }); + // live mode btnLiveMode_.registerListener(e -> { closeLiveModeWindow(); - final String cameraName = model_.devices() - .getDevice("ImagingCamera").getDeviceName(); - try { - model_.studio().core().setCameraDevice(cameraName); - } catch (Exception ex) { - model_.studio().logs().showError("could not set camera to " + cameraName); + final CameraBase camera = model_.devices().getDevice("ImagingCamera"); + if (camera != null) { + try { + model_.studio().core().setCameraDevice(camera.getDeviceName()); + camera.setTriggerMode(CameraMode.INTERNAL); + } catch (Exception ex) { + model_.studio().logs().showError("could not set camera to " + camera.getDeviceName()); + } + model_.studio().live().setLiveModeOn(true); + } else { + model_.studio().logs().showError( + "No device for \"ImagingCamera\" set in the device adapter."); } - model_.studio().live().setLiveModeOn(true); }); break; default: diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java b/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java index 8c4f74d..6343e71 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/DeviceManager.java @@ -220,8 +220,10 @@ private void createXYStageDevice() { // return deviceMap_.get(deviceName); // } + // TODO: consider using Optional to improve the API /** - * Returns the device given by {@code deviceName} as type {@code T}. + * Returns the device given by {@code deviceName} as type {@code T}, + * if the device is not found, {@code null} is returned. * The caller is responsible for assigning the returned * value to the correct type. *

@@ -229,12 +231,11 @@ private void createXYStageDevice() { * of DeviceBase, avoiding the ClassCastException at compile time. * * @param deviceName the device name - * @return the device as a subclass of DeviceBase + * @return the device or null if device not found * @param the generic type to cast the result to */ @SuppressWarnings("unchecked") public T getDevice(final String deviceName) { - //System.out.println(deviceName + " " + deviceMap_.get(deviceName).getDeviceName()); return (T) deviceMap_.get(deviceName); } diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/LightSheetManagerModel.java b/src/main/java/org/micromanager/lightsheetmanager/model/LightSheetManagerModel.java index 1a73bcb..e4279cb 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/LightSheetManagerModel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/LightSheetManagerModel.java @@ -27,9 +27,8 @@ public class LightSheetManagerModel implements LightSheetManager { private UserSettings userSettings_; private PluginSettings pluginSettings_; - private DeviceManager deviceManager_; - - private XYZGrid xyzGrid_; + private final XYZGrid xyzGrid_; + private final DeviceManager deviceManager_; private AcquisitionEngine acqEngine_; private AcquisitionTableData acqTableData_; @@ -41,9 +40,9 @@ public LightSheetManagerModel(final Studio studio) { pluginSettings_ = new PluginSettings(); userSettings_ = new UserSettings(this); xyzGrid_ = new XYZGrid(this); + deviceManager_ = new DeviceManager(studio_, this); - // set during setup if there is an error - // displayed in the error ui + // set during setup if there is an errordisplayed in the error ui errorText_ = ""; } @@ -54,8 +53,6 @@ public LightSheetManagerModel(final Studio studio) { */ public boolean setup() { - deviceManager_ = new DeviceManager(studio_, this); - // first we check to see if the device adapter is present if (!deviceManager_.hasDeviceAdapter()) { return false; diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngine.java b/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngine.java index 4e64c26..8bf1538 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngine.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngine.java @@ -126,6 +126,7 @@ public Future requestRun(boolean speedTest) { } else { studio_.logs().logMessage("Preparing Acquisition: plugin version " + LightSheetManagerPlugin.version); // TODO: put this here? generic setup tasks? put in own method? + System.out.println("acqSettings_.acquisitionMode(): " + acqSettings_.acquisitionMode()); if (acqSettings_.acquisitionMode() == AcquisitionMode.NONE) { studio_.logs().showError("please select a valid acquisition mode!"); return; // early exit diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java b/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java index 5be8c5e..38d56ef 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java @@ -87,6 +87,7 @@ public int roiReadoutRowsSplitReadout(Rectangle roi, Rectangle sensor) { @Override public void setTriggerMode(CameraMode cameraMode) { + System.out.println("this!"); mode_ = cameraMode; } diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/DemoCamera.java b/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/DemoCamera.java index 051a985..dbdf3a9 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/DemoCamera.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/DemoCamera.java @@ -27,7 +27,9 @@ public DemoCamera(Studio studio, String deviceName) { @Override public void setTriggerMode(final CameraMode cameraMode) { - // do nothing - no camera trigger modes - always internal + // do nothing - no camera trigger modes - always internal - log for debug convenience + studio_.logs().logMessage( + "setTriggerMode(" + cameraMode + ") called but the DemoCamera is always in internal mode."); } @Override