Search in sources :

Example 1 with AxialMultiStepModel

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;
}
Also used : ModelPersistAction(org.eclipse.scanning.device.ui.model.ModelPersistAction) MultiStepComposite(org.eclipse.scanning.device.ui.composites.MultiStepComposite) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) MultiStepComposite(org.eclipse.scanning.device.ui.composites.MultiStepComposite) IModelProvider(org.eclipse.scanning.api.IModelProvider) AxialMultiStepModel(org.eclipse.scanning.api.points.models.AxialMultiStepModel)

Example 2 with AxialMultiStepModel

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;
}
Also used : ArrayList(java.util.ArrayList) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) AxialMultiStepModel(org.eclipse.scanning.api.points.models.AxialMultiStepModel)

Example 3 with AxialMultiStepModel

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;
}
Also used : AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) AxialMultiStepModel(org.eclipse.scanning.api.points.models.AxialMultiStepModel) AxialArrayModel(org.eclipse.scanning.api.points.models.AxialArrayModel)

Aggregations

AxialMultiStepModel (org.eclipse.scanning.api.points.models.AxialMultiStepModel)3 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)2 ArrayList (java.util.ArrayList)1 IModelProvider (org.eclipse.scanning.api.IModelProvider)1 AxialArrayModel (org.eclipse.scanning.api.points.models.AxialArrayModel)1 MultiStepComposite (org.eclipse.scanning.device.ui.composites.MultiStepComposite)1 ModelPersistAction (org.eclipse.scanning.device.ui.model.ModelPersistAction)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1