Search in sources :

Example 1 with IScanPointGeneratorModel

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

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel 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 3 with IScanPointGeneratorModel

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

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel in project gda-core by openGDA.

the class OuterScannablesBlock method createScannableControls.

/**
 * Create a control (checkbox + scan path specification) for each scannable chosen to be displayed
 */
private void createScannableControls() {
    removeOldBindings();
    disposeScanPathEditors();
    // Ensure scannables are shown in alphabetical order (case insensitive)
    outerScannables.sort(comparing(IScanModelWrapper<IScanPointGeneratorModel>::getName, CASE_INSENSITIVE_ORDER));
    if (scannablesComposite != null) {
        scannablesComposite.dispose();
    }
    dataBindingContext = new DataBindingContext();
    final Map<String, Binding> checkBoxBindings = new HashMap<>();
    scannablesComposite = new Composite(sectionComposite, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(scannablesComposite);
    GridLayoutFactory.swtDefaults().numColumns(4).margins(0, 0).applyTo(scannablesComposite);
    // Create a control for each scannable to be shown
    for (IScanModelWrapper<IScanPointGeneratorModel> scannableAxisParameters : outerScannables) {
        final String scannableName = scannableAxisParameters.getName();
        // Create checkbox and bind to "includeInScan" in the model
        final Button checkBox = new Button(scannablesComposite, SWT.CHECK);
        checkBox.setText(scannableName);
        final IObservableValue<Boolean> checkBoxValue = WidgetProperties.buttonSelection().observe(checkBox);
        final IObservableValue<Boolean> activeValue = PojoProperties.value("includeInScan", Boolean.class).observe(scannableAxisParameters);
        final Binding checkBoxBinding = dataBindingContext.bindValue(checkBoxValue, activeValue);
        checkBoxBindings.put(scannableName, checkBoxBinding);
        // Create control to display/edit scan path definition
        final ScanPathEditor scanPathEditor = new ScanPathEditor(scannablesComposite, SWT.NONE, scannableAxisParameters);
        GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(scanPathEditor);
        scanPathEditor.addIObserver(scanPathObserver);
        scanPathEditors.add(scanPathEditor);
        // Button to delete scannable
        final Button deleteScannableButton = new Button(scannablesComposite, SWT.NONE);
        deleteScannableButton.setImage(Activator.getImage("icons/cross.png"));
        deleteScannableButton.setToolTipText("Delete scannable");
        deleteScannableButton.addListener(SWT.Selection, event -> deleteScannable(scannableAxisParameters));
        // when the include in scan checkbox is changed we need to revalidate the model
        // as this determines the severity of the validation status. We also call for the
        // scan path to be recalculated in case any change to the preview is needed
        checkBoxBinding.getModel().addChangeListener(evt -> {
            scanPathEditor.revalidate();
            updatePoints();
        });
    }
    if (scannablesChangedListener != null) {
        scannablesChangedListener.scannablesChanged(outerScannables);
    }
}
Also used : Binding(org.eclipse.core.databinding.Binding) Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) Button(org.eclipse.swt.widgets.Button) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 5 with IScanPointGeneratorModel

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel in project gda-core by openGDA.

the class QueuePreventingScanSubmitterTest method getTestScanBean.

private ScanBean getTestScanBean() throws UnknownHostException {
    IScanPointGeneratorModel model = mock(IScanPointGeneratorModel.class);
    CompoundModel compoundModel = mock(CompoundModel.class);
    when(compoundModel.getModels()).thenReturn(Arrays.asList(model));
    ScanRequest scanRequest = mock(ScanRequest.class);
    doReturn(compoundModel).when(scanRequest).getCompoundModel();
    ScanBean bean = new ScanBean(scanRequest);
    bean.setName("test scan");
    return bean;
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Aggregations

IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)17 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)6 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)5 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 Composite (org.eclipse.swt.widgets.Composite)4 ScanPathModelWrapper (uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper)4 ArrayList (java.util.ArrayList)3 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)3 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3 Label (org.eclipse.swt.widgets.Label)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)2 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IScanPathModel (org.eclipse.scanning.api.points.models.IScanPathModel)2 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)2 Button (org.eclipse.swt.widgets.Button)2