Search in sources :

Example 16 with IDetectorModel

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);
    }
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IOperationModelWizard(org.dawnsci.processing.ui.api.IOperationModelWizard) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) File(java.io.File) URISyntaxException(java.net.URISyntaxException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) EventException(org.eclipse.scanning.api.event.EventException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 17 with IDetectorModel

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);
            }
        }
    }
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)

Example 18 with IDetectorModel

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);
    });
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel)

Example 19 with IDetectorModel

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);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) NumberAndUnitsComposite(uk.ac.gda.client.NumberAndUnitsComposite) FocusScanUtils.createNumberAndUnitsLengthComposite(uk.ac.diamond.daq.mapping.ui.experiment.focus.FocusScanUtils.createNumberAndUnitsLengthComposite) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) PlottableMapObject(org.dawnsci.mapping.ui.datamodel.PlottableMapObject) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 20 with IDetectorModel

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

Aggregations

IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)20 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)9 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 Test (org.junit.Test)6 ScanningException (org.eclipse.scanning.api.scan.ScanningException)5 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)4 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)4 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)4 HashMap (java.util.HashMap)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)3 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)3 MandelbrotModel (org.eclipse.scanning.example.detector.MandelbrotModel)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)2 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)2