use of org.eclipse.scanning.api.points.models.AxialMultiStepModel in project gda-core by openGDA.
the class MultiStepEditorDialog method createDialogArea.
@Override
public Control createDialogArea(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(comp);
Button loadButton = new Button(comp, SWT.PUSH);
loadButton.setImage(Activator.getImage("icons/folder-import.png"));
loadButton.setToolTipText("Load multi-step model");
Button saveButton = new Button(comp, SWT.PUSH);
saveButton.setImage(Activator.getImage("icons/folder-export.png"));
saveButton.setToolTipText("Save multi-step model");
if (model == null) {
model = new AxialMultiStepModel();
model.setName(scannableName);
}
final IModelProvider<AxialMultiStepModel> modelProvider = new IModelProvider<AxialMultiStepModel>() {
@Override
public AxialMultiStepModel getModel() throws Exception {
return model;
}
@Override
public void updateModel(AxialMultiStepModel model) throws Exception {
// updateModel is not needed for this implementation
// Overriding because super throws IllegalArgumentException
}
};
ed = new TypeEditor<>(modelProvider, comp, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(ed);
try {
ed.setModel(model);
} catch (Exception e) {
logger.error("Could not set model:", e);
}
((MultiStepComposite) ed.getUI()).updateUnits(scannableName);
// Disabling scannable name combo since dialog is tied to single scannable
((MultiStepComposite) ed.getUI()).setNameComboEnabled(false);
// Load default values
((MultiStepComposite) ed.getUI()).getStepModels().setBeanConfigurator(getBeanConfigurator());
// save & load logic
ModelPersistAction<AxialMultiStepModel> load = new ModelPersistAction<>(ed, PersistType.LOAD);
loadButton.addListener(SWT.Selection, event -> load.run());
ModelPersistAction<AxialMultiStepModel> save = new ModelPersistAction<>(ed, PersistType.SAVE);
saveButton.addListener(SWT.Selection, event -> save.run());
return ed;
}
use of org.eclipse.scanning.api.points.models.AxialMultiStepModel in project gda-core by openGDA.
the class XanesScanningUtils method createModelFromEdgeSelection.
/**
* Create a step model for each range of energies around the edge
*
* @param edgeEnergy
* energy of the edge to be scanned
* @param energyScannableName
* name of the scannable to control the energy
* @return corresponding step model
*/
public static IScanPointGeneratorModel createModelFromEdgeSelection(double edgeEnergy, String energyScannableName) {
final List<AxialStepModel> stepModels = new ArrayList<>(xanesStepRanges.length);
// Create a step model for each range of energies around the edge
for (double[] range : xanesStepRanges) {
stepModels.add(new AxialStepModel(energyScannableName, roundDouble(edgeEnergy + range[0]), roundDouble(edgeEnergy + range[1]), range[2]));
}
// Create a multi-step model containing these step models
final AxialMultiStepModel model = new AxialMultiStepModel(energyScannableName, stepModels);
model.setContinuous(false);
return model;
}
use of org.eclipse.scanning.api.points.models.AxialMultiStepModel in project gda-core by openGDA.
the class ScanPathEditor method convertTextToModel.
/**
* Convert text representing a scan path to a {@link AxialMultiStepModel}
*
* @param text
* The text to convert (can be empty)
* @param scannableName
* The name of the scannable to which the scan path refers
* @return The corresponding multi-step model
*/
private AxialMultiStepModel convertTextToModel(String text, String scannableName) {
AxialMultiStepModel multiAxialStepModel = new AxialMultiStepModel();
if (!text.isEmpty()) {
final Object oldModel = (new StringToScanPathConverter(scannableName)).convert(text);
if (oldModel instanceof AxialMultiStepModel) {
multiAxialStepModel = (AxialMultiStepModel) oldModel;
} else if (oldModel instanceof AxialStepModel) {
multiAxialStepModel.getModels().add((AxialStepModel) oldModel);
} else if (oldModel instanceof AxialArrayModel) {
final double[] positions = ((AxialArrayModel) oldModel).getPositions();
for (int i = 0; i < positions.length - 1; i++) {
final AxialStepModel stepModel = new AxialStepModel(scannableName, positions[i], positions[i + 1], positions[i + 1] - positions[i]);
multiAxialStepModel.getModels().add(stepModel);
}
}
}
multiAxialStepModel.setName(scannableName);
return multiAxialStepModel;
}
Aggregations