Search in sources :

Example 1 with IMalcolmModel

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;
}
Also used : HashMap(java.util.HashMap) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 2 with IMalcolmModel

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);
    });
}
Also used : ValidationException(org.eclipse.scanning.api.ValidationException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) URISyntaxException(java.net.URISyntaxException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) ValidationException(org.eclipse.scanning.api.ValidationException) EventException(org.eclipse.scanning.api.event.EventException)

Example 3 with IMalcolmModel

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());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) Test(org.junit.Test)

Example 4 with IMalcolmModel

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);
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 5 with IMalcolmModel

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());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanningAcquisition(uk.ac.diamond.daq.mapping.api.document.scanning.ScanningAcquisition) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) ArrayList(java.util.ArrayList) ApplyNexusTemplatesRequest(uk.ac.gda.api.acquisition.configuration.processing.ApplyNexusTemplatesRequest) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)10 ScanningException (org.eclipse.scanning.api.scan.ScanningException)6 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 URISyntaxException (java.net.URISyntaxException)3 EventException (org.eclipse.scanning.api.event.EventException)3 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 IOperationModelWizard (org.dawnsci.processing.ui.api.IOperationModelWizard)1 Dialog (org.eclipse.jface.dialogs.Dialog)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ValidationException (org.eclipse.scanning.api.ValidationException)1