Search in sources :

Example 1 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class FocusScanConverterTest method testConvertFocusScanBean.

@Test
public void testConvertFocusScanBean() {
    final ScanRequest scanRequest = focusScanConverter.convertToScanRequest(focusScanBean);
    // test compound model
    final CompoundModel compoundModel = scanRequest.getCompoundModel();
    assertNotNull(compoundModel);
    final List<IScanPointGeneratorModel> models = compoundModel.getModels();
    assertEquals(2, models.size());
    // test outer model - the focus model
    assertThat(models.get(0), is(instanceOf(AxialStepModel.class)));
    final AxialStepModel focusModel = (AxialStepModel) models.get(0);
    assertEquals(1, focusModel.getScannableNames().size());
    assertEquals(focusScanBean.getFocusScannableName(), focusModel.getScannableNames().get(0));
    assertEquals(focusScanBean.getFocusCentre() - focusScanBean.getFocusRange() + focusModel.getStep() / 2, focusModel.getStart(), 1e-15);
    assertEquals(focusScanBean.getFocusCentre() + focusScanBean.getFocusRange() - focusModel.getStep() / 2 + focusModel.getStep() / 100, focusModel.getStop(), 1e-15);
    assertEquals(focusScanBean.getFocusRange() * 2 / focusScanBean.getNumberOfFocusSteps(), focusModel.getStep(), 1e-15);
    // test inner model - the line model
    assertThat(models.get(1), is(instanceOf(TwoAxisLinePointsModel.class)));
    final TwoAxisLinePointsModel lineModel = (TwoAxisLinePointsModel) models.get(1);
    assertEquals(2, lineModel.getScannableNames().size());
    assertEquals(mappingStageInfo.getPlotYAxisName(), lineModel.getScannableNames().get(1));
    assertEquals(mappingStageInfo.getPlotXAxisName(), lineModel.getScannableNames().get(0));
    assertEquals(focusScanBean.getNumberOfLinePoints(), lineModel.getPoints());
    final BoundingLine boundingLine = lineModel.getBoundingLine();
    assertNotNull(boundingLine);
    final LinearROI expectedRegion = (LinearROI) focusScanBean.getLineRegion().toROI();
    assertEquals(expectedRegion.getPointX(), boundingLine.getxStart(), 1e-15);
    assertEquals(expectedRegion.getPointY(), boundingLine.getyStart(), 1e-15);
    assertEquals(expectedRegion.getAngle(), boundingLine.getAngle(), 1e-15);
    assertEquals(expectedRegion.getLength(), boundingLine.getLength(), 1e-15);
    // test scan regions
    assertEquals(1, compoundModel.getRegions().size());
    final ScanRegion scanRegion = compoundModel.getRegions().iterator().next();
    assertEquals(2, scanRegion.getScannables().size());
    assertEquals(mappingStageInfo.getPlotYAxisName(), scanRegion.getScannables().get(1));
    assertEquals(mappingStageInfo.getPlotXAxisName(), scanRegion.getScannables().get(0));
    assertThat(scanRegion.getRoi(), is(instanceOf(LinearROI.class)));
    assertEquals(expectedRegion, scanRegion.getRoi());
    // test detectors
    final Map<String, IDetectorModel> detectors = scanRequest.getDetectors();
    assertNotNull(detectors);
    assertEquals(1, detectors.size());
    assertTrue(detectors.containsKey("mandelbrot"));
    assertThat(detectors.get("mandelbrot"), is(instanceOf(MandelbrotModel.class)));
    // test that the remaining fields have not been set
    assertThat(scanRequest.getMonitorNamesPerPoint(), is(empty()));
    assertThat(scanRequest.getMonitorNamesPerScan(), is(empty()));
    assertThat(scanRequest.getScanMetadata(), is(nullValue()));
    assertThat(scanRequest.getAfterScript(), is(nullValue()));
    assertThat(scanRequest.getBeforeScript(), is(nullValue()));
    assertThat(scanRequest.isAlwaysRunAfterScript(), is(false));
    assertThat(scanRequest.getStartPosition(), is(nullValue()));
    assertThat(scanRequest.getEndPosition(), is(nullValue()));
    assertThat(scanRequest.getFilePath(), is(nullValue()));
}
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) TwoAxisLinePointsModel(org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) BoundingLine(org.eclipse.scanning.api.points.models.BoundingLine) Test(org.junit.Test)

Example 2 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class ScanRequestConverterTest method testUnknownDetector.

@Test(expected = IllegalArgumentException.class)
public void testUnknownDetector() throws Exception {
    final String detName = "mandelbrot";
    final String displayName = "Mandelbrot Detector";
    final IDetectorModel detModel = new MandelbrotModel();
    detModel.setName(detName);
    mappingBean.setDetectorParameters(Arrays.asList(new DetectorModelWrapper(displayName, detModel, true)));
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    assertEquals(detModel, scanRequest.getDetectors().get(detName));
    // Act again - convert scan request back to mapping bean, throws exception
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Example 3 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel 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 4 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class ClausesContext method addDetector.

/**
 * Adds an {@link IDetectorModel} corresponding to the supplied {@link IRunnableDevice} to the map of detectors,
 * setting the exposure time if specified
 *
 * @param detector				The {@link IRunnableDevice} corresponding to the detector
 * @param exposure				The exposure time of the {@link Detector} to be set if specified
 * @throws ScanningException	If the {@link IDetectorModel} for the {@link IRunnableDevice} is null.
 */
public void addDetector(final IRunnableDevice<?> detector, final double exposure) throws ScanningException {
    nullCheck(detector, IRunnableDevice.class.getSimpleName());
    IDetectorModel model = (IDetectorModel) detector.getModel();
    if (model == null) {
        throw new ScanningException(String.format("Could not get model for detector %s", detector.getName()));
    }
    if (exposure > 0) {
        model.setExposureTime(exposure);
    }
    detectorMap.put(detector.getName(), model);
    detectorClauseSeen = true;
    clauseProcessed = true;
    LOGGER.debug("Detector added for {}", detector.getName());
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IRunnableDevice(org.eclipse.scanning.api.device.IRunnableDevice)

Example 5 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel 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

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