Search in sources :

Example 1 with InterpolationAlgorithmFactory

use of eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory in project hale by halestudio.

the class InterpolationSettingPage method createContent.

@Override
protected void createContent(Composite page) {
    // page.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).create());
    page.setLayout(new GridLayout(1, false));
    Group groupError = new Group(page, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(groupError);
    // GridDataFactory.fillDefaults().grab(true, false).applyTo(groupError);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(groupError);
    groupError.setText("Interpolated geometries");
    // Interpolation algorithm
    Label labelAlg = new Label(groupError, SWT.NONE);
    labelAlg.setText("Interpolation algorithm: ");
    labelAlg.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
    algorithms = new ComboViewer(groupError, SWT.READ_ONLY);
    algorithms.setContentProvider(ArrayContentProvider.getInstance());
    algorithms.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof InterpolationAlgorithmFactory) {
                return ((InterpolationAlgorithmFactory) element).getDisplayName();
            }
            return super.getText(element);
        }
    });
    algorithms.getControl().setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).create());
    algorithms.setInput(InterpolationExtension.getInstance().getFactories());
    algorithms.setSelection(new StructuredSelection(InterpolationExtension.getInstance().getFactory(InterpolationHelper.DEFAULT_ALGORITHM)));
    algorithms.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateState();
        }
    });
    // label error
    Label labelError = new Label(groupError, SWT.NONE);
    labelError.setText("Maximum Position Error: ");
    labelError.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
    error = new Text(groupError, SWT.BORDER | SWT.SINGLE);
    error.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
    error.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState();
        }
    });
    // label unit
    Label labelUnit = new Label(groupError, SWT.NONE);
    labelUnit.setText("(unit)");
    labelUnit.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
    Label positionErrorDesc = new Label(groupError, SWT.NONE);
    positionErrorDesc.setText("The maximum positional error is used by the interpolation algorithm to ensure a certain level of accuracy.");
    GridDataFactory.fillDefaults().span(3, 1).applyTo(positionErrorDesc);
    Group group = new Group(page, SWT.NONE);
    group.setLayout(new GridLayout(1, false));
    group.setText("Other geometries");
    GridDataFactory.fillDefaults().span(3, 1).applyTo(group);
    moveToGrid = new Button(group, SWT.CHECK);
    moveToGrid.setText("Move all geometries to interpolation grid (if applicable)");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(moveToGrid);
    // default
    moveToGrid.setSelection(false);
    Label desc = new Label(group, SWT.NONE);
    desc.setText("Moves all geometries coordinates to the interpolation grid to allow for topological consistency with interpolated geometries.");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(desc);
    // filler
    new Label(page, SWT.NONE);
    // label with warning message
    Composite warnComp = new Composite(page, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
    updateState();
    setPageComplete(false);
}
Also used : Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) LabelProvider(org.eclipse.jface.viewers.LabelProvider) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Example 2 with InterpolationAlgorithmFactory

use of eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory in project hale by halestudio.

the class InterpolationSettingPage method updateState.

/**
 * Update the page state.
 */
private void updateState() {
    boolean complete = true;
    // enable/disable move to grid setting
    ISelection sel = algorithms.getSelection();
    boolean isGridSelected = false;
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof InterpolationAlgorithmFactory) {
            if (GridInterpolation.EXTENSION_ID.equals(((InterpolationAlgorithmFactory) selected).getIdentifier())) {
                isGridSelected = true;
            }
        }
    }
    moveToGrid.setEnabled(isGridSelected);
    if (!sel.isEmpty() && !isGridSelected) {
        // disable setting when other algorithm than grid interpolation is
        // selected
        moveToGrid.setSelection(false);
    }
    // state of maximum positional error
    if (!validateMaxError()) {
        setErrorMessage("The maximum positional error must be a floating point number.");
        complete = false;
    } else {
        setErrorMessage(null);
    }
    setPageComplete(complete);
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Example 3 with InterpolationAlgorithmFactory

use of eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory in project hale by halestudio.

the class InterpolationSettingPage method updateConfiguration.

@Override
public boolean updateConfiguration(IOProvider provider) {
    // set interpolation algorithm
    Value alg = null;
    ISelection sel = algorithms.getSelection();
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof InterpolationAlgorithmFactory) {
            String id = ((InterpolationAlgorithmFactory) selected).getIdentifier();
            alg = Value.of(id);
        }
    }
    provider.setParameter(InterpolationHelper.PARAMETER_INTERPOLATION_ALGORITHM, alg);
    // set maximum positional error
    provider.setParameter(InterpolationHelper.PARAMETER_MAX_POSITION_ERROR, Value.of(error.getText()));
    // set move to grid flag
    provider.setParameter(GridInterpolation.PARAMETER_MOVE_ALL_TO_GRID, Value.of(moveToGrid.getSelection()));
    return true;
}
Also used : Value(eu.esdihumboldt.hale.common.core.io.Value) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Example 4 with InterpolationAlgorithmFactory

use of eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory in project hale by halestudio.

the class InterpolationSettingPage method loadPreValue.

/**
 * Load max position error value
 *
 * @param provider the I/O provider to get
 */
private void loadPreValue(IOProvider provider) {
    // load interpolation algorithm
    String id = provider.getParameter(InterpolationHelper.PARAMETER_INTERPOLATION_ALGORITHM).as(String.class, InterpolationHelper.DEFAULT_ALGORITHM);
    InterpolationAlgorithmFactory fact = InterpolationExtension.getInstance().getFactory(id);
    if (fact == null) {
        fact = InterpolationExtension.getInstance().getFactory(InterpolationHelper.DEFAULT_ALGORITHM);
    }
    ISelection selection;
    if (fact == null) {
        selection = new StructuredSelection();
    } else {
        selection = new StructuredSelection(fact);
    }
    algorithms.setSelection(selection);
    // load maximum positional error
    Double value = provider.getParameter(InterpolationHelper.PARAMETER_MAX_POSITION_ERROR).as(Double.class);
    if (value != null) {
        error.setText(Double.toString(value.doubleValue()));
    } else {
        error.setText(Double.toString(InterpolationHelper.DEFAULT_MAX_POSITION_ERROR));
    }
    // load move to grid flag
    moveToGrid.setSelection(provider.getParameter(GridInterpolation.PARAMETER_MOVE_ALL_TO_GRID).as(Boolean.class, false));
    updateState();
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Example 5 with InterpolationAlgorithmFactory

use of eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory in project hale by halestudio.

the class InterpolationHelper method getInterpolation.

/**
 * Get the interpolation algorithm for a given instance reader.
 *
 * @param instanceReader the instance reader
 * @param factory the geometry factory
 * @return the interpolation algorithm
 */
public static InterpolationAlgorithm getInterpolation(IOProvider instanceReader, GeometryFactory factory) {
    // FIXME weak cache based on reader?
    String algorithmId = instanceReader.getParameter(PARAMETER_INTERPOLATION_ALGORITHM).as(String.class, DEFAULT_ALGORITHM);
    InterpolationAlgorithmFactory fact = InterpolationExtension.getInstance().getFactory(algorithmId);
    if (fact == null) {
        log.warn("Could not find interpolation algorithm with ID " + algorithmId);
        fact = InterpolationExtension.getInstance().getFactory(DEFAULT_ALGORITHM);
    }
    if (fact == null) {
        throw new IllegalStateException("Default interpolation algorithm could not be found");
    }
    InterpolationAlgorithm result;
    try {
        result = fact.createExtensionObject();
    } catch (Exception e) {
        log.error("Interpolation algorithm could be created", e);
        result = new SplitInterpolation();
    }
    double maxPositionalError = getMaxPositionalError(instanceReader);
    // configure the algorithm
    Map<String, Value> configuration = new HashMap<>();
    instanceReader.storeConfiguration(configuration);
    Map<String, String> properties = new HashMap<>();
    for (Entry<String, Value> entry : configuration.entrySet()) {
        if (!entry.getValue().isRepresentedAsDOM()) {
            properties.put(entry.getKey(), entry.getValue().getStringRepresentation());
        }
    }
    result.configure(factory, maxPositionalError, properties);
    return result;
}
Also used : SplitInterpolation(eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation) HashMap(java.util.HashMap) Value(eu.esdihumboldt.hale.common.core.io.Value) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Aggregations

InterpolationAlgorithmFactory (eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ISelection (org.eclipse.jface.viewers.ISelection)3 Value (eu.esdihumboldt.hale.common.core.io.Value)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 InterpolationAlgorithm (eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)1 SplitInterpolation (eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation)1 HashMap (java.util.HashMap)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1