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