Skip to content

Commit

Permalink
set cameras to internal on setup tab live buttons; fix No scan (fixed…
Browse files Browse the repository at this point in the history
… sheet) error
  • Loading branch information
Brandon committed Jul 29, 2024
1 parent c54a2c1 commit 419438c
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -21,6 +24,9 @@ public enum AcquisitionMode {

private final String text_;

private static final Map<String, AcquisitionMode> stringToEnum =
Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e));

AcquisitionMode(final String text) {
text_ = text;
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, AutofocusMode> stringToEnum =
Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e));

AutofocusMode(final String name) {
this.name = name;
name_ = name;
}

public static String[] toArray() {
Expand All @@ -33,7 +33,7 @@ public static AutofocusMode fromString(final String symbol) {

@Override
public String toString() {
return name;
return name_;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public enum AutofocusType {
FFT_BANDPASS("FFTBandpass"),
TENENGRAD("Tenengrad");

private final String name;
private final String name_;

private static final Map<String, AutofocusType> stringToEnum =
Stream.of(values()).collect(Collectors.toMap(Object::toString, e -> e));

AutofocusType(final String name) {
this.name = name;
name_ = name;
}

public static String[] toArray() {
Expand All @@ -43,7 +43,7 @@ public static AutofocusType fromString(final String symbol) {

@Override
public String toString() {
return name;
return name_;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CameraMode> 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.
*/
Expand Down Expand Up @@ -117,7 +113,7 @@ public static String[] getAvailableModes(CameraLibrary camLib) {

@Override
public String toString() {
return text;
return text_;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public enum GeometryType {
private static final Map<String, GeometryType> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public enum LightSheetType {
private static final Map<String, LightSheetType> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,22 @@ 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.
* <P><P>
* Typesafe: The client can only cast the return value to a subclass
* 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 <T> the generic type to cast the result to
*/
@SuppressWarnings("unchecked")
public <T extends DeviceBase> T getDevice(final String deviceName) {
//System.out.println(deviceName + " " + deviceMap_.get(deviceName).getDeviceName());
return (T) deviceMap_.get(deviceName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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_ = "";
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public int roiReadoutRowsSplitReadout(Rectangle roi, Rectangle sensor) {

@Override
public void setTriggerMode(CameraMode cameraMode) {
System.out.println("this!");
mode_ = cameraMode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 419438c

Please sign in to comment.