Search in sources :

Example 1 with LienzoLayer

use of org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer in project kie-wb-common by kiegroup.

the class LienzoCanvasExport method toImageData.

@Override
public String toImageData(final AbstractCanvasHandler canvasHandler, final CanvasURLExportSettings settings) {
    final LienzoLayer layer = getLayer(canvasHandler);
    final int[] bounds = boundsProvider.compute(layer, settings);
    return LienzoLayerUtils.layerToDataURL(layer, getDataType(settings.getUrlDataType()), bounds[0], bounds[1], bounds[2], bounds[3], BG_COLOR);
}
Also used : LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer)

Example 2 with LienzoLayer

use of org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer in project kie-wb-common by kiegroup.

the class LienzoCanvasExport method toContext2D.

@Override
public IContext2D toContext2D(final AbstractCanvasHandler canvasHandler, final CanvasExportSettings settings) {
    final LienzoLayer layer = getLayer(canvasHandler);
    final com.ait.lienzo.client.core.shape.Layer lienzoLayer = layer.getLienzoLayer();
    final Viewport viewport = lienzoLayer.getViewport();
    final int[] bounds = boundsProvider.compute(layer, settings);
    final IContext2D svgContext2D = Context2DFactory.create(new SvgExportSettings(bounds[2], bounds[3], lienzoLayer.getContext()));
    // Reset the transform before drawing to the target context.
    final Transform transform = viewport.getTransform();
    viewport.setTransform(new Transform());
    // Draw into the target context.
    lienzoLayer.draw(new Context2D(new DelegateNativeContext2D(svgContext2D, canvasHandler)));
    // Set again the previous transform.
    viewport.setTransform(transform);
    // Draw again the native canvas context2d (this is necessary otherwise the canvas becomes empty)
    lienzoLayer.draw();
    return svgContext2D;
}
Also used : LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer) Context2D(com.ait.lienzo.client.core.Context2D) IContext2D(org.uberfire.ext.editor.commons.client.file.exports.svg.IContext2D) SvgExportSettings(org.uberfire.ext.editor.commons.client.file.exports.svg.SvgExportSettings) Viewport(com.ait.lienzo.client.core.shape.Viewport) IContext2D(org.uberfire.ext.editor.commons.client.file.exports.svg.IContext2D) Transform(com.ait.lienzo.client.core.types.Transform)

Example 3 with LienzoLayer

use of org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer in project kie-wb-common by kiegroup.

the class CanvasBoundsIndexerImpl method getAt.

@Override
@SuppressWarnings("unchecked")
public Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode) {
    final WiresCanvas canvas = (WiresCanvas) canvasHandler.getAbstractCanvas();
    final LienzoLayer lienzoLayer = canvas.getView().getLayer();
    Node node;
    final String viewUUID_UL = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y);
    final String viewUUID_UR = LienzoLayerUtils.getUUID_At(lienzoLayer, x + width, y);
    final String viewUUID_CC = LienzoLayerUtils.getUUID_At(lienzoLayer, x + (width / 2), y + (height / 2));
    final String viewUUID_LL = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y + height);
    final String viewUUID_LR = LienzoLayerUtils.getUUID_At(lienzoLayer, x + width, y + height);
    if (null != viewUUID_UL && viewUUID_UL.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_UL);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_UR && viewUUID_UR.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_UR);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_CC && viewUUID_CC.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_CC);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_LL && viewUUID_LL.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_LL);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_LR && viewUUID_LR.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_LR);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    }
    return null;
}
Also used : WiresCanvas(org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresCanvas) LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 4 with LienzoLayer

use of org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer in project kie-wb-common by kiegroup.

the class CanvasBoundsIndexerImpl method getAt.

@Override
@SuppressWarnings("unchecked")
public Node<View<?>, Edge> getAt(final double x, final double y) {
    final WiresCanvas canvas = (WiresCanvas) canvasHandler.getAbstractCanvas();
    final LienzoLayer lienzoLayer = canvas.getView().getLayer();
    final String viewUUID = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y);
    if (null != viewUUID && viewUUID.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID);
        if (null != shape) {
            return canvasHandler.getGraphIndex().getNode(shape.getUUID());
        }
    }
    return null;
}
Also used : WiresCanvas(org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresCanvas) LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer)

Example 5 with LienzoLayer

use of org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer in project kie-wb-common by kiegroup.

the class AbstractMediatorControl method enable.

@Override
public void enable(final C canvas) {
    super.enable(canvas);
    this.mediator = buildMediator();
    final LienzoLayer lienzoLayer = (LienzoLayer) canvas.getLayer();
    mediators = lienzoLayer.getLienzoLayer().getViewport().getMediators();
    mediators.push(getMediator());
}
Also used : LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer)

Aggregations

LienzoLayer (org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer)10 Test (org.junit.Test)2 WiresCanvas (org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresCanvas)2 Context2D (com.ait.lienzo.client.core.Context2D)1 Viewport (com.ait.lienzo.client.core.shape.Viewport)1 Transform (com.ait.lienzo.client.core.types.Transform)1 LienzoPanel (com.ait.lienzo.client.widget.LienzoPanel)1 Before (org.junit.Before)1 StunnerWiresControlFactory (org.kie.workbench.common.stunner.client.lienzo.wires.StunnerWiresControlFactory)1 StunnerWiresHandlerFactory (org.kie.workbench.common.stunner.client.lienzo.wires.StunnerWiresHandlerFactory)1 WiresManagerFactoryImpl (org.kie.workbench.common.stunner.client.lienzo.wires.WiresManagerFactoryImpl)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 IContext2D (org.uberfire.ext.editor.commons.client.file.exports.svg.IContext2D)1 SvgExportSettings (org.uberfire.ext.editor.commons.client.file.exports.svg.SvgExportSettings)1