Search in sources :

Example 1 with PermutationMatrix

use of org.csstudio.swt.widgets.symbol.util.PermutationMatrix in project yamcs-studio by yamcs.

the class ImageEditPart method registerImageRotationPropertyHandlers.

/**
 * Registers image rotation property change handlers for the properties defined in {@link MonitorBoolSymbolModel}.
 */
public void registerImageRotationPropertyHandlers() {
    // degree rotation property
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
            if (oldValue == null || newValue == null)
                return false;
            ImageFigure imageFigure = (ImageFigure) figure;
            int newDegree = getWidgetModel().getDegree((Integer) newValue);
            int oldDegree = getWidgetModel().getDegree((Integer) oldValue);
            PermutationMatrix oldMatrix = new PermutationMatrix((double[][]) getPropertyValue(ImageModel.PERMUTATION_MATRIX));
            PermutationMatrix newMatrix = PermutationMatrix.generateRotationMatrix(newDegree - oldDegree);
            PermutationMatrix result = newMatrix.multiply(oldMatrix);
            // As we use only % Pi/2 angles, we can round to integer values
            // => equals work better
            result.roundToIntegers();
            setPropertyValue(ImageModel.PERMUTATION_MATRIX, result.getMatrix());
            setPropertyValue(ImageModel.PROP_DEGREE, (Integer) newValue);
            imageFigure.setPermutationMatrix(result);
            autoSizeWidget(imageFigure);
            return false;
        }
    };
    setPropertyChangeHandler(ImageModel.PROP_DEGREE, handler);
    // flip horizontal rotation property
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
            if (oldValue == null || newValue == null)
                return false;
            ImageFigure imageFigure = (ImageFigure) figure;
            // imageFigure.setFlipH((Boolean) newValue);
            PermutationMatrix newMatrix = PermutationMatrix.generateFlipHMatrix();
            PermutationMatrix oldMatrix = imageFigure.getPermutationMatrix();
            PermutationMatrix result = newMatrix.multiply(oldMatrix);
            // As we use only % Pi/2 angles, we can round to integer values
            // => equals work better
            result.roundToIntegers();
            setPropertyValue(ImageModel.PERMUTATION_MATRIX, result.getMatrix());
            setPropertyValue(ImageModel.PROP_FLIP_HORIZONTAL, (Boolean) newValue);
            imageFigure.setPermutationMatrix(result);
            autoSizeWidget(imageFigure);
            return false;
        }
    };
    setPropertyChangeHandler(ImageModel.PROP_FLIP_HORIZONTAL, handler);
    // flip vertical rotation property
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
            if (oldValue == null || newValue == null)
                return false;
            ImageFigure imageFigure = (ImageFigure) figure;
            // imageFigure.setFlipV((Boolean) newValue);
            PermutationMatrix newMatrix = PermutationMatrix.generateFlipVMatrix();
            PermutationMatrix oldMatrix = imageFigure.getPermutationMatrix();
            PermutationMatrix result = newMatrix.multiply(oldMatrix);
            // As we use only % Pi/2 angles, we can round to integer values
            // => equals work better
            result.roundToIntegers();
            setPropertyValue(ImageModel.PERMUTATION_MATRIX, result.getMatrix());
            setPropertyValue(ImageModel.PROP_FLIP_VERTICAL, (Boolean) newValue);
            imageFigure.setPermutationMatrix(result);
            autoSizeWidget(imageFigure);
            return false;
        }
    };
    setPropertyChangeHandler(ImageModel.PROP_FLIP_VERTICAL, handler);
}
Also used : IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) ImageFigure(org.csstudio.opibuilder.widgets.figures.ImageFigure) PermutationMatrix(org.csstudio.swt.widgets.symbol.util.PermutationMatrix) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 ImageFigure (org.csstudio.opibuilder.widgets.figures.ImageFigure)1 PermutationMatrix (org.csstudio.swt.widgets.symbol.util.PermutationMatrix)1 IFigure (org.eclipse.draw2d.IFigure)1