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()));
}
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));
}
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);
}
}
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);
}
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;
}
Aggregations