Search in sources :

Example 11 with IScanPathModel

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

the class ScanpathTest method createModelCreatesCorrectModelForGrid.

@Test
public void createModelCreatesCorrectModelForGrid() throws Exception {
    pathParams = Arrays.asList(5, 6);
    IScanPathModel model = GRID_POINTS.createModel(scannables, pathParams, bboxParams, mutators);
    assertThat(model, is(instanceOf(TwoAxisGridPointsModel.class)));
    TwoAxisGridPointsModel gModel = (TwoAxisGridPointsModel) model;
    assertThat(gModel.getScannableNames(), contains("name1", "name2"));
    assertThat(gModel.getBoundingBox().getxAxisStart(), is(1.0));
    assertThat(gModel.getBoundingBox().getyAxisStart(), is(2.0));
    assertThat(gModel.getBoundingBox().getxAxisLength(), is(3.0));
    assertThat(gModel.getBoundingBox().getyAxisLength(), is(4.0));
    assertThat(gModel.getxAxisPoints(), is(5));
    assertThat(gModel.getyAxisPoints(), is(6));
    assertThat(gModel.getBoundingBox().getyAxisStart(), is(2.0));
    assertThat(gModel.getOrientation(), is(Orientation.HORIZONTAL));
    assertThat(gModel.isAlternating(), is(false));
    assertThat(gModel.isContinuous(), is(false));
}
Also used : TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel) Test(org.junit.Test)

Example 12 with IScanPathModel

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

the class ScanpathTest method createModelCreatesCorrectModelForSpiral.

@Test
public void createModelCreatesCorrectModelForSpiral() throws Exception {
    pathParams = Arrays.asList(5.0);
    mutators.put(Mutator.CONTINUOUS, Arrays.asList(blankArray));
    IScanPathModel model = SPIRAL.createModel(scannables, pathParams, bboxParams, mutators);
    assertThat(model, is(instanceOf(TwoAxisSpiralModel.class)));
    TwoAxisSpiralModel sModel = (TwoAxisSpiralModel) model;
    assertThat(sModel.getScannableNames(), contains("name1", "name2"));
    assertThat(sModel.getBoundingBox().getxAxisStart(), is(1.0));
    assertThat(sModel.getBoundingBox().getyAxisStart(), is(2.0));
    assertThat(sModel.getBoundingBox().getxAxisLength(), is(3.0));
    assertThat(sModel.getBoundingBox().getyAxisLength(), is(4.0));
    assertThat(sModel.getScale(), is(5.0));
    assertThat(sModel.getBoundingBox().getyAxisStart(), is(2.0));
    assertThat(sModel.isContinuous(), is(true));
}
Also used : TwoAxisSpiralModel(org.eclipse.scanning.api.points.models.TwoAxisSpiralModel) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel) Test(org.junit.Test)

Example 13 with IScanPathModel

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

the class ScanpathTest method createModelCreatesCorrectModelForSinglePoint.

@Test
public void createModelCreatesCorrectModelForSinglePoint() throws Exception {
    pathParams = Arrays.asList(5.1, 6.2);
    IScanPathModel model = SINGLE_POINT.createModel(scannables, pathParams, bboxParams, mutators);
    assertThat(model, is(instanceOf(TwoAxisPointSingleModel.class)));
    TwoAxisPointSingleModel eModel = (TwoAxisPointSingleModel) model;
    assertThat(eModel.getScannableNames(), contains("name1", "name2"));
    assertThat(eModel.getX(), is(5.1));
    assertThat(eModel.getY(), is(6.2));
}
Also used : TwoAxisPointSingleModel(org.eclipse.scanning.api.points.models.TwoAxisPointSingleModel) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel) Test(org.junit.Test)

Example 14 with IScanPathModel

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

the class RegionAndPathSection method rebuildMappingSection.

/**
 * Call this to rebuild the mapping section. Only required when the underlying beans are swapped.
 */
protected void rebuildMappingSection() {
    // Remove the old controls
    if (regionEditor != null) {
        regionEditor.dispose();
    }
    if (pathEditor != null) {
        pathEditor.dispose();
    }
    // Scan Region
    final IMappingScanRegionShape mappingScanRegion = controller.getScanRegionFromBean().getRegion();
    if (mappingScanRegion == null) {
        // We can't build a UI to edit null
        return;
    }
    regionEditor = RegionEditorProvider.createRegionEditor(mappingScanRegion, controller.getMappingRegionUnits(), getEclipseContext());
    regionEditor.createEditorPart(regionAndPathComposite);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(regionAndPathComposite);
    // Scan Path
    final IScanPathModel scanPath = controller.getScanRegionFromBean().getScanPath();
    if (scanPath == null) {
        // We can't build a UI to edit null
        return;
    }
    pathEditor = PathEditorProvider.createPathComposite(scanPath, getEclipseContext());
    pathEditor.createEditorPart(regionAndPathComposite);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(regionAndPathComposite);
    detectorsChanged(getMappingBean().getDetectorParameters().stream().filter(IScanModelWrapper<IDetectorModel>::isIncludeInScan).collect(toList()));
    relayoutMappingView();
}
Also used : IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel)

Example 15 with IScanPathModel

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

the class RegionAndPathSection method createControls.

@Override
public void createControls(Composite parent) {
    super.createControls(parent);
    // Make a custom section for handling the mapping region
    regionAndPathComposite = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(regionAndPathComposite);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(regionAndPathComposite);
    // Prepare a grid data factory for controls which will need to grab space horizontally
    final GridDataFactory horizontalGrabGridData = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
    // Make the region selection
    final Composite regionComboComposite = new Composite(regionAndPathComposite, SWT.NONE);
    horizontalGrabGridData.span(1, 1).applyTo(regionComboComposite);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(regionComboComposite);
    final Label regionLabel = new Label(regionComboComposite, SWT.NONE);
    regionLabel.setText("Region shape:");
    regionSelector = new ComboViewer(regionComboComposite);
    horizontalGrabGridData.applyTo(regionSelector.getControl());
    regionSelector.getCombo().setToolTipText("Select a scan region shape. The shape can then be drawn on the map, or you can type numbers below.");
    final MultiFunctionButton newRegion = new MultiFunctionButton();
    newRegion.addFunction("Draw region", "Draw region by dragging on map", new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/map--pencil.png")), () -> regionSelector.setSelection(regionSelector.getSelection()));
    newRegion.addFunction("Place default region", "Place the default region on current stage position", new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/map-pin.png")), this::createDefaultRegionAtStagePosition);
    newRegion.draw(regionComboComposite);
    // Make the path selection
    final Composite pathComboComposite = new Composite(regionAndPathComposite, SWT.NONE);
    horizontalGrabGridData.applyTo(pathComboComposite);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(pathComboComposite);
    final Label pathLabel = new Label(pathComboComposite, SWT.NONE);
    pathLabel.setText("Scan path:");
    pathSelector = new ComboViewer(pathComboComposite);
    pathSelector.getCombo().setToolTipText(getMessage(SCAN_PATH_SHAPE_TP));
    horizontalGrabGridData.applyTo(pathSelector.getControl());
    final Button configureStageButton = new Button(pathComboComposite, SWT.PUSH);
    configureStageButton.setToolTipText("Configure mapping stage");
    configureStageButton.setImage(getImage("icons/gear.png"));
    configureStageButton.addListener(SWT.Selection, event -> {
        final MappingStageInfo mappingStage = getService(MappingStageInfo.class);
        final EditMappingStageDialog dialog = new EditMappingStageDialog(getShell(), mappingStage, selectedMalcolmDeviceName);
        if (dialog.open() == Window.OK) {
            rebuildMappingSection();
        }
    });
    // Add logic
    regionSelector.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IMappingScanRegionShape) {
                final IMappingScanRegionShape mappingRegion = (IMappingScanRegionShape) element;
                return mappingRegion.getName();
            }
            return super.getText(element);
        }
    });
    regionSelector.setContentProvider(ArrayContentProvider.getInstance());
    final List<IMappingScanRegionShape> scanRegions = controller.getTemplateRegions();
    scanRegionMap = scanRegions.stream().collect(toMap(IMappingScanRegionShape::getName, identity()));
    regionSelector.setInput(scanRegions.toArray());
    regionSelector.addSelectionChangedListener(controller.getRegionSelectorListener());
    pathSelector.setContentProvider(ArrayContentProvider.getInstance());
    pathSelector.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IScanPathModel) {
                final IScanPathModel scanPath = (IScanPathModel) element;
                return scanPath.getName();
            }
            return super.getText(element);
        }
    });
    pathSelector.addSelectionChangedListener(event -> {
        logger.debug("Path selection event: {}", event);
        // Get the new selection.
        final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        final IScanPointGeneratorModel selectedPath = (IScanPointGeneratorModel) selection.getFirstElement();
        controller.changePath(selectedPath);
        rebuildMappingSection();
    });
    /*
		 * We disable mouse wheel events on these combo boxes
		 * because, being on a scrollable composite,
		 * users frequently mouse scroll on them by mistake
		 */
    regionSelector.getCombo().addListener(SWT.MouseWheel, this::disableEvent);
    pathSelector.getCombo().addListener(SWT.MouseWheel, this::disableEvent);
    // Listen for property changes that affect this section
    GDAClientActivator.getDefault().getPreferenceStore().addPropertyChangeListener(propertyChangeListener);
    updateControls();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) MappingStageInfo(uk.ac.diamond.daq.mapping.impl.MappingStageInfo) MultiFunctionButton(uk.ac.diamond.daq.mapping.ui.MultiFunctionButton) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel) IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ComboViewer(org.eclipse.jface.viewers.ComboViewer) MultiFunctionButton(uk.ac.diamond.daq.mapping.ui.MultiFunctionButton) Button(org.eclipse.swt.widgets.Button) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Aggregations

IScanPathModel (org.eclipse.scanning.api.points.models.IScanPathModel)16 Test (org.junit.Test)13 IMappingScanRegionShape (uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape)3 TwoAxisGridPointsModel (org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel)2 TwoAxisGridStepModel (org.eclipse.scanning.api.points.models.TwoAxisGridStepModel)2 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 AxialArrayModel (org.eclipse.scanning.api.points.models.AxialArrayModel)1 AxialPointsModel (org.eclipse.scanning.api.points.models.AxialPointsModel)1 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)1 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)1 TwoAxisGridPointsRandomOffsetModel (org.eclipse.scanning.api.points.models.TwoAxisGridPointsRandomOffsetModel)1 TwoAxisLinePointsModel (org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel)1 TwoAxisLineStepModel (org.eclipse.scanning.api.points.models.TwoAxisLineStepModel)1 TwoAxisLissajousModel (org.eclipse.scanning.api.points.models.TwoAxisLissajousModel)1 TwoAxisPointSingleModel (org.eclipse.scanning.api.points.models.TwoAxisPointSingleModel)1 TwoAxisSpiralModel (org.eclipse.scanning.api.points.models.TwoAxisSpiralModel)1 Image (org.eclipse.swt.graphics.Image)1