Search in sources :

Example 16 with IScanPointGeneratorModel

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

Example 17 with IScanPointGeneratorModel

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

the class PtychographySubmitScanSection method getRasterStepModel.

/**
 * Get the {@link TwoAxisGridStepModel} that is configured for this client (for raster scanning).
 * <p>
 * This may already be set in the mapping bean: if not, we need to obtain it from the controller and redraw the GUI
 * accordingly.
 *
 * @return the model, or {@code null} in the (unlikely) event that none is configured in the client.
 */
private TwoAxisGridStepModel getRasterStepModel() {
    final IScanPointGeneratorModel scanPath = getMappingBean().getScanDefinition().getMappingScanRegion().getScanPath();
    if (scanPath instanceof TwoAxisPtychographyModel) {
        return (TwoAxisGridStepModel) scanPath;
    }
    final RegionAndPathController controller = getService(RegionAndPathController.class);
    final TwoAxisGridStepModel model = (TwoAxisGridStepModel) controller.getScanPathListAndLinkPath().stream().filter(TwoAxisGridStepModel.class::isInstance).findFirst().orElse(null);
    if (model != null) {
        controller.changePath(model);
    }
    return model;
}
Also used : RegionAndPathController(uk.ac.diamond.daq.mapping.ui.experiment.RegionAndPathController) TwoAxisGridStepModel(org.eclipse.scanning.api.points.models.TwoAxisGridStepModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) TwoAxisPtychographyModel(org.eclipse.scanning.api.points.models.TwoAxisPtychographyModel)

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