Search in sources :

Example 1 with IScanModelWrapper

use of uk.ac.diamond.daq.mapping.api.IScanModelWrapper in project gda-core by openGDA.

the class ScanRequestConverterTest method testOuterScannableAddedToMappingBeanIfNotThereAlready.

@Test
public void testOuterScannableAddedToMappingBeanIfNotThereAlready() {
    // Arrange
    final IScanPointGeneratorModel outerModel = new AxialStepModel(Z_AXIS_NAME, -3, 2, 0.5);
    final List<IScanModelWrapper<IScanPointGeneratorModel>> outerScannables = Arrays.asList(new ScanPathModelWrapper(Z_AXIS_NAME, outerModel, true));
    mappingBean.getScanDefinition().setOuterScannables(outerScannables);
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Creates a new wrapper for the outer scannable in newMappingBean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    assertThat(newMappingBean.getScanDefinition().getOuterScannables(), contains(outerScannables.toArray()));
}
Also used : ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) Test(org.junit.Test)

Example 2 with IScanModelWrapper

use of uk.ac.diamond.daq.mapping.api.IScanModelWrapper in project gda-core by openGDA.

the class ScanRequestConverterTest method testOuterScannableIsSet.

@Test
public void testOuterScannableIsSet() throws Exception {
    // Arrange
    final IScanPointGeneratorModel outerModel = new AxialStepModel(Z_AXIS_NAME, -3, 2, 0.5);
    final List<IScanModelWrapper<IScanPointGeneratorModel>> outerScannables = Arrays.asList(new ScanPathModelWrapper(Z_AXIS_NAME, outerModel, true));
    mappingBean.getScanDefinition().setOuterScannables(outerScannables);
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    // Check there are now 2 models the outer z AxialStepModel and the inner Grid model
    assertThat(scanRequest.getCompoundModel().getModels().size(), is(equalTo(2)));
    final AxialStepModel recoveredOuterModel = (AxialStepModel) scanRequest.getCompoundModel().getModels().get(0);
    // Check the outer scannable model is first in the list
    assertThat(recoveredOuterModel, is(outerModel));
    // Check it has the correct axis name
    assertThat(recoveredOuterModel.getName(), is(Z_AXIS_NAME));
    // setup the new mapping bean with an outer scannable for the same axis, but disabled
    // and with a different model, and another enabled and for a different axis
    newMappingBean.getScanDefinition().setOuterScannables(Arrays.asList(new ScanPathModelWrapper(Z_AXIS_NAME, new AxialStepModel(Z_AXIS_NAME, 0, 5, 0.25), false), new ScanPathModelWrapper("energy", new AxialStepModel("energy", 10000, 15000, 1000), true)));
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again - check the new mapping bean is the same as the old one
    List<IScanModelWrapper<IScanPointGeneratorModel>> newOuterScannables = newMappingBean.getScanDefinition().getOuterScannables();
    assertThat(newOuterScannables.size(), is(2));
    assertThat(newOuterScannables.get(0).getName(), is(equalTo(Z_AXIS_NAME)));
    assertThat(newOuterScannables.get(0).getModel(), is(equalTo(outerModel)));
    assertThat(newOuterScannables.get(0).isIncludeInScan(), is(true));
    assertThat(newOuterScannables.get(1).getName(), is(equalTo("energy")));
    assertThat(newOuterScannables.get(1).isIncludeInScan(), is(false));
}
Also used : ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) Test(org.junit.Test)

Example 3 with IScanModelWrapper

use of uk.ac.diamond.daq.mapping.api.IScanModelWrapper in project gda-core by openGDA.

the class OuterScannablesBlock method addScannableInternal.

/**
 * Adds a scannable without updating the UI or notifying listeners.
 * @param scannableName
 * @param includeInScan
 */
private void addScannableInternal(String scannableName, boolean includeInScan) {
    final Optional<IScanModelWrapper<IScanPointGeneratorModel>> optWrapper = getScannableWrapper(scannableName);
    if (optWrapper.isPresent()) {
        optWrapper.get().setIncludeInScan(includeInScan);
        return;
    }
    if (availableScannableNames.contains(scannableName)) {
        outerScannables.add(new ScanPathModelWrapper(scannableName, null, includeInScan));
    } else {
        final String message = String.format("Cannot add %s as outer scannable: not one of the permitted scannables", scannableName);
        final Status status = new Status(IStatus.WARNING, "uk.ac.diamond.daq.mapping.ui", "Scannable configuration");
        ErrorDialog.openError(getShell(), "Configuration error", message, status);
        logger.warn(message);
    }
}
Also used : ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper)

Example 4 with IScanModelWrapper

use of uk.ac.diamond.daq.mapping.api.IScanModelWrapper in project gda-core by openGDA.

the class DetectorsSection method createDetectorControls.

private void createDetectorControls(List<IScanModelWrapper<IDetectorModel>> detectorParametersList) {
    // remove any old bindings
    removeOldBindings();
    if (detectorsComposite != null)
        detectorsComposite.dispose();
    dataBindingContext = new DataBindingContext();
    detectorSelectionCheckboxes = new HashMap<>();
    detectorsComposite = new Composite(sectionComposite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(detectorsComposite);
    GridLayoutFactory.swtDefaults().numColumns(DETECTORS_COLUMNS).margins(0, 0).applyTo(detectorsComposite);
    final Optional<IScanModelWrapper<IDetectorModel>> selectedMalcolmDevice = Optional.empty();
    for (IScanModelWrapper<IDetectorModel> detectorParameters : detectorParametersList) {
        // create the detector selection checkbox and bind it to the includeInScan property of the wrapper
        final Button checkBox = new Button(detectorsComposite, SWT.CHECK);
        detectorSelectionCheckboxes.put(detectorParameters.getName(), checkBox);
        checkBox.setText(detectorParameters.getName());
        final IObservableValue<Boolean> checkBoxValue = WidgetProperties.buttonSelection().observe(checkBox);
        final IObservableValue<Boolean> activeValue = PojoProperties.value("includeInScan", Boolean.class).observe(detectorParameters);
        dataBindingContext.bindValue(checkBoxValue, activeValue);
        // sets the checkbox checked if the detector was previously selected
        dataBindingContext.updateTargets();
        checkBox.addListener(SWT.Selection, event -> detectorSelectionChanged(detectorParameters));
        // create the exposure time text control and bind it the exposure time property of the wrapper
        final Text exposureTimeText = new Text(detectorsComposite, SWT.BORDER);
        exposureTimeText.setToolTipText("Exposure time");
        GridDataFactory.fillDefaults().grab(true, false).applyTo(exposureTimeText);
        final IObservableValue<String> exposureTextValue = WidgetProperties.text(SWT.Modify).observe(exposureTimeText);
        final IObservableValue<Double> exposureTimeValue = PojoProperties.value("exposureTime", Double.class).observe(detectorParameters.getModel());
        dataBindingContext.bindValue(exposureTextValue, exposureTimeValue);
        exposureTimeText.addListener(SWT.Modify, event -> updateStatusLabel());
        // Edit configuration
        final Composite configComposite = new Composite(detectorsComposite, SWT.NONE);
        GridLayoutFactory.fillDefaults().applyTo(configComposite);
        final Button configButton = new Button(configComposite, SWT.PUSH);
        configButton.setImage(getImage("icons/camera.png"));
        configButton.setToolTipText(getMessage(DETECTOR_PARAMETERS_EDIT_TP));
        configButton.addListener(SWT.Selection, event -> editDetectorParameters(detectorParameters));
    }
    // if a malcolm device is selected already, deselect and disable the checkboxes for the other detectors
    selectedMalcolmDevice.ifPresent(this::detectorSelectionChanged);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) Button(org.eclipse.swt.widgets.Button)

Example 5 with IScanModelWrapper

use of uk.ac.diamond.daq.mapping.api.IScanModelWrapper 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)

Aggregations

IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)18 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)10 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)5 Composite (org.eclipse.swt.widgets.Composite)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Test (org.junit.Test)4 ScanPathModelWrapper (uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper)4 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)3 Label (org.eclipse.swt.widgets.Label)3 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)2