use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class TimeSeriesScanView method createScanBean.
private ScanBean createScanBean() {
final IMalcolmModel malcolmModel = malcolmModelEditor.getModel();
final String malcolmDeviceName = malcolmModel.getName();
final ScanRequest scanRequest = new ScanRequest();
// add the malcolm model to the scan request
final Map<String, IDetectorModel> detectors = new HashMap<>();
detectors.put(malcolmDeviceName, malcolmModel);
scanRequest.setDetectors(detectors);
// extract the models from the outer scannables
final List<IScanPointGeneratorModel> pointsModels = outerScannablesBlock.getOuterScannables().stream().filter(IScanModelWrapper<IScanPointGeneratorModel>::isIncludeInScan).map(IScanModelWrapper<IScanPointGeneratorModel>::getModel).collect(toCollection(ArrayList::new));
final int numSteps = numStepsSpinner.getSelection();
pointsModels.add(new StaticModel(numSteps));
scanRequest.setCompoundModel(new CompoundModel(pointsModels));
final ScanBean scanBean = new ScanBean(scanRequest);
scanBean.setName(String.format("%s - Time Series", malcolmDeviceName));
return scanBean;
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class TimeSeriesScanView method displayValidationResult.
private void displayValidationResult(Object result, boolean initialValidation) {
if (malcolmModelEditor == null)
return;
final IMalcolmModel malcolmModel = malcolmModelEditor.getModel();
Display.getDefault().asyncExec(() -> {
// note getShell().getDisplay() can throw NPE initially
if (result instanceof ValidationException) {
MessageDialog.openError(getShell(), "Validation Error", "The given configuration is invalid: " + ((Exception) result).getMessage());
} else if (result instanceof Exception) {
logger.error("Error getting malcolm device '{}', {}", malcolmModel.getName(), result);
MessageDialog.openError(getShell(), "Error", "Could not get malcolm device " + malcolmModel.getName());
} else if (!initialValidation) {
// only show message for ok if button pressed
MessageDialog.openInformation(getShell(), "Validation Successful", "The given configuration is valid.");
}
malcolmModelEditor.updateValidatedModel(result instanceof IMalcolmModel ? (IMalcolmModel) result : null);
});
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class ScanRequestFactoryTest method testEmptyTemplateFile.
@Test
public void testEmptyTemplateFile() throws Exception {
IMalcolmModel model = Mockito.mock(IMalcolmModel.class);
when(detectorModel.getModel()).thenReturn(model);
ScanRequestFactory scanRequestFactory = new ScanRequestFactory(loadScanningAcquisition());
ScanRequest scanRequest = scanRequestFactory.createScanRequest(runnableService);
Assert.assertTrue(scanRequest.getTemplateFilePaths().isEmpty());
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class ProcessingSelectionWizardPage method createDetectorSelectionControls.
private void createDetectorSelectionControls(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(composite);
GridDataFactory.fillDefaults().applyTo(composite);
// Label for select detector combo
Label label = new Label(composite, SWT.NONE);
label.setText("Detector:");
GridDataFactory.swtDefaults().applyTo(label);
// Combo viewer for detector selection
detectorsComboViewer = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
GridDataFactory.swtDefaults().applyTo(detectorsComboViewer.getControl());
detectorsComboViewer.setContentProvider(ArrayContentProvider.getInstance());
detectorsComboViewer.setLabelProvider(new LabelProvider() {
@SuppressWarnings("unchecked")
@Override
public String getText(Object element) {
return ((IScanModelWrapper<IDetectorModel>) element).getName();
}
});
detectorsComboViewer.setInput(detectors);
if (!detectors.isEmpty()) {
detectorsComboViewer.setSelection(new StructuredSelection(getDefaultDetector()));
}
detectorsComboViewer.addSelectionChangedListener(evt -> {
@SuppressWarnings("unchecked") IScanModelWrapper<IDetectorModel> selectedWrapper = (IScanModelWrapper<IDetectorModel>) ((IStructuredSelection) evt.getSelection()).getFirstElement();
IDetectorModel detectorModel = selectedWrapper.getModel();
if (detectorModel instanceof IMalcolmModel && !getDetectorDatasetNameForMalcolm((IMalcolmModel) detectorModel).isPresent()) {
MessageDialog.openError(getShell(), "Setup Processing", "Could not get primary dataset for malcolm device: " + detectorModel.getName());
setPageComplete(false);
} else {
setPageComplete(true);
}
});
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class ScanRequestFactoryTest method testNotEmptyTemplateFile.
@Test
public void testNotEmptyTemplateFile() throws Exception {
IMalcolmModel model = Mockito.mock(IMalcolmModel.class);
when(detectorModel.getModel()).thenReturn(model);
ScanningAcquisition scanningAcquisition = loadScanningAcquisition();
URL file1 = new URL("file:/lev1/lev2");
URL file2 = new URL("file:/lev3/lev4");
List<URL> paths = new ArrayList<>();
paths.add(file1);
paths.add(file2);
ApplyNexusTemplatesRequest request = (new ApplyNexusTemplatesRequest.Builder()).withValue(paths).build();
scanningAcquisition.getAcquisitionConfiguration().setProcessingRequest(new ArrayList<>());
scanningAcquisition.getAcquisitionConfiguration().getProcessingRequest().add(request);
ScanRequestFactory scanRequestFactory = new ScanRequestFactory(scanningAcquisition);
ScanRequest scanRequest = scanRequestFactory.createScanRequest(runnableService);
Assert.assertEquals(2, scanRequest.getTemplateFilePaths().size());
}
Aggregations