use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class ProcessingSelectionWizardPage method finishPage.
@Override
public void finishPage() {
if (ProcessingMode.OTHER.equals(mode)) {
String path = existingConfigText.getText();
configWrapper.setAppName(appText.getText());
configWrapper.setName(new File(path).getName());
configWrapper.setPathToConfig(path);
return;
}
final IDetectorModel detectorModel = getSelectedDetector().getModel();
final Optional<String> malcolmDetectorDatasetName = detectorModel instanceof IMalcolmModel ? getDetectorDatasetNameForMalcolm((IMalcolmModel) detectorModel) : Optional.empty();
configureProcessingModel(detectorModel, malcolmDetectorDatasetName);
if (!ProcessingMode.NEW_DAWN.equals(selectedMode())) {
return;
}
// Clone the detector model - we don't want to change the one in the mapping bean
IDetectorModel detectorModelCopy = null;
try {
detectorModelCopy = (IDetectorModel) BeanUtils.cloneBean(detectorModel);
} catch (Exception e) {
logger.error("Could not make a copy of the detector model: " + detectorModel.getName(), e);
return;
}
// setup the acquire page with the detector model for the appropriate detector and
// the name of the detector group (may be different if the detector is a malcolm detector).
AcquireDataWizardPage acquirePage = (AcquireDataWizardPage) getNextPage();
acquirePage.setAcquireDetectorModel(detectorModelCopy);
acquirePage.setDetectorDataGroupName(malcolmDetectorDatasetName.orElse(detectorModel.getName()));
// set template file on wizard, so that other pages can be created appropriately
final String templateFile = getSelectedTemplateFile().getPath();
try {
((IOperationModelWizard) getWizard()).setTemplateFile(templateFile);
} catch (Exception e) {
final String exceptionMessage = "Error setting template file on wizard. Could not create operations pages.";
final String userMessage = "Could not open template file, please contact beamline representative";
logger.error(exceptionMessage, e);
final MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
messageBox.setMessage(userMessage);
messageBox.open();
throw new RuntimeException(exceptionMessage, e);
}
}
use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class ScanRequestConverter method mergeDetectorAndProcessing.
private void mergeDetectorAndProcessing(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
// disable all the existing detectors in the mapping bean, also create a map of them by
// detector name (note: the name in the IDetectorModel, not the name in the wrapper)
final Map<String, IScanModelWrapper<IDetectorModel>> detectorModelWrappers;
if (mappingBean.getDetectorParameters() == null) {
detectorModelWrappers = Collections.emptyMap();
} else {
detectorModelWrappers = new HashMap<>(mappingBean.getDetectorParameters().size());
for (IScanModelWrapper<IDetectorModel> detectorModelWrapper : mappingBean.getDetectorParameters()) {
((DetectorModelWrapper) detectorModelWrapper).setIncludeInScan(false);
detectorModelWrappers.put(detectorModelWrapper.getModel().getName(), detectorModelWrapper);
}
}
// merge in the detectors and processing from the scan request. If there already is
// a detector or processor with that name it is enabled and the model is replaced
// with the model in the ScanRequest
final Map<String, IDetectorModel> detectorsAndProcessingMap = scanRequest.getDetectors();
if (detectorsAndProcessingMap != null) {
for (String name : detectorsAndProcessingMap.keySet()) {
final IDetectorModel model = detectorsAndProcessingMap.get(name);
List<IScanModelWrapper<IDetectorModel>> detectorParams = mappingBean.getDetectorParameters();
if (detectorParams == null) {
// create the list of detector wrapper in the bean if not present
detectorParams = new ArrayList<>(4);
mappingBean.setDetectorParameters(detectorParams);
}
if (detectorModelWrappers.containsKey(name)) {
// Get the wrapper for the detector. Set it to be included in the scan
// and overwrite the model with the model in the scan request
final IScanModelWrapper<IDetectorModel> wrapper = detectorModelWrappers.get(name);
wrapper.setIncludeInScan(true);
wrapper.setModel(model);
} else {
// The scan includes an unknown detector. This can only occur if the mapping bean has changed in spring
throw new IllegalArgumentException("Unknown detector " + name);
}
}
}
}
use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class FocusScanSetupPage method handleDetectorSelectionChange.
/**
* Handle a change in the combo box that selects the detector to use.
*
* @param selection
* the new selection in the combo box
*/
private void handleDetectorSelectionChange(ISelection selection) {
uiSync.asyncExec(() -> {
final IDetectorModel selectedModel = getDetectorWrapperForSelection(selection).getModel();
axesLabel.setText(getAxesMessage(selectedModel));
focusScanBean.setDetector(selectedModel);
});
}
use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class FocusScanSetupPage method createDetectorControls.
private void createDetectorControls(Composite parent) {
Label label = new Label(parent, SWT.SINGLE);
label.setText("Detector:");
GridDataFactory.swtDefaults().applyTo(label);
final Composite detectorComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(detectorComposite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(detectorComposite);
// Combo to choose detector
final ComboViewer detectorCombo = new ComboViewer(detectorComposite, SWT.READ_ONLY);
detectorCombo.setContentProvider(ArrayContentProvider.getInstance());
detectorCombo.setLabelProvider(new LabelProvider() {
@SuppressWarnings("unchecked")
@Override
public String getText(Object element) {
return ((IScanModelWrapper<IDetectorModel>) element).getName();
}
});
// Get detector wrappers from mapping bean and add as input to combo
detectorCombo.addSelectionChangedListener(evt -> handleDetectorSelectionChange(evt.getSelection()));
GridDataFactory.fillDefaults().grab(true, false).applyTo(detectorCombo.getControl());
final Button configureDetectorButton = new Button(detectorComposite, SWT.PUSH);
configureDetectorButton.setImage(Activator.getImage("icons/pencil.png"));
configureDetectorButton.setToolTipText("Edit parameters");
configureDetectorButton.addListener(SWT.Selection, event -> editDetectorParameters(getDetectorWrapperForSelection(detectorCombo.getSelection())));
final Label exposureTimeLabel = new Label(parent, SWT.NONE);
exposureTimeLabel.setText("Exposure Time:");
final Text exposureTimeText = new Text(parent, SWT.BORDER);
exposureTimeText.setToolTipText("Set the exposure time for this detector");
GridDataFactory.fillDefaults().grab(true, false).applyTo(exposureTimeText);
@SuppressWarnings("unchecked") final IObservableValue<String> exposureTextValue = WidgetProperties.text(SWT.Modify).observe(exposureTimeText);
detectorCombo.addSelectionChangedListener(event -> {
if (exposureTimeBinding != null) {
exposureTimeBinding.dispose();
bindingContext.removeBinding(exposureTimeBinding);
}
final Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement();
@SuppressWarnings("unchecked") final IDetectorModel model = ((IScanModelWrapper<IDetectorModel>) selected).getModel();
@SuppressWarnings("unchecked") final IObservableValue<Double> exposureTimeValue = PojoProperties.value("exposureTime").observe(model);
exposureTimeBinding = bindingContext.bindValue(exposureTextValue, exposureTimeValue);
});
populateDetectorCombo(detectorCombo);
}
use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class FocusScanConverter method convertToScanRequest.
public ScanRequest convertToScanRequest(FocusScanBean focusScanBean) {
logger.debug("Converting focusScanBean to scan request");
final ScanRequest scanRequest = new ScanRequest();
final IMapPathModel lineModel = createLineModel(focusScanBean);
final ILineMappingRegion lineRegion = focusScanBean.getLineRegion();
final ScanRegion scanRegion = new ScanRegion(lineRegion.toROI(), lineModel.getxAxisName(), lineModel.getyAxisName());
final AxialStepModel focusModel = createFocusPathModel(focusScanBean);
final CompoundModel compoundModel = new CompoundModel(Arrays.asList(focusModel, lineModel));
compoundModel.setRegions(Arrays.asList(scanRegion));
scanRequest.setCompoundModel(compoundModel);
// add detectors
final IDetectorModel detectorModel = focusScanBean.getDetector();
final Map<String, IDetectorModel> detectorsMap = new HashMap<>();
detectorsMap.put(detectorModel.getName(), detectorModel);
scanRequest.setDetectors(detectorsMap);
return scanRequest;
}
Aggregations