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