Search in sources :

Example 1 with BoundingBox

use of org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox in project kie-wb-common by kiegroup.

the class ShapeUtils method updateEdgeConnection.

@SuppressWarnings("unchecked")
public static void updateEdgeConnection(final AbstractCanvasHandler context, final Connection connection, final Node<? extends View<?>, Edge> node) {
    if (null != node && null == connection.getLocation() && connection instanceof MagnetConnection) {
        final MagnetConnection magnetConnection = (MagnetConnection) connection;
        final OptionalInt magnetIndex = magnetConnection.getMagnetIndex();
        if (magnetIndex.orElse(-1) == MagnetConnection.MAGNET_CENTER) {
            final Shape<ShapeView<?>> nodeShape = context.getCanvas().getShape(node.getUUID());
            final BoundingBox boundingBox = nodeShape.getShapeView().getBoundingBox();
            magnetConnection.setLocation(new Point2D(boundingBox.getWidth() / 2, boundingBox.getHeight() / 2));
        }
    }
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) OptionalInt(java.util.OptionalInt) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)

Example 2 with BoundingBox

use of org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox in project kie-wb-common by kiegroup.

the class AbstractRegistrationCanvasNodeCommand method register.

@SuppressWarnings("unchecked")
protected void register(final AbstractCanvasHandler context) {
    context.register(shapeSetId, candidate);
    // Update view bounds for the element, if not set, by using the values from the shape view.
    final double[] size = GraphUtils.getNodeSize(candidate.getContent());
    if (size[0] <= 0 || size[1] <= 0) {
        final Shape shape = context.getCanvas().getShape(candidate.getUUID());
        final ShapeView shapeView = shape.getShapeView();
        final Point2D location = GraphUtils.getPosition(candidate.getContent());
        final BoundingBox boundingBox = shapeView.getBoundingBox();
        candidate.getContent().setBounds(Bounds.create(location.getX(), location.getY(), location.getX() + boundingBox.getWidth(), location.getY() + boundingBox.getHeight()));
    }
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)

Example 3 with BoundingBox

use of org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox in project kie-wb-common by kiegroup.

the class AbstractCanvasInlineTextEditorControlTest method initShape.

private void initShape(final double x, final double y, final double scrollX, final double scrollY, final double zoom) {
    boundingBox = new BoundingBox(0, 0, BOUNDING_BOX_WIDTH, BOUNDING_BOX_HEIGHT);
    when(testShapeView.getShapeAbsoluteLocation()).thenReturn(new Point2D(x, y));
    when(testShapeView.getBoundingBox()).thenReturn(boundingBox);
    when(canvas.getTransform()).thenReturn(transform);
    when(transform.getTranslate()).thenReturn(new Point2D(scrollX, scrollY));
    when(transform.getScale()).thenReturn(new Point2D(zoom, zoom));
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox)

Example 4 with BoundingBox

use of org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox in project kie-wb-common by kiegroup.

the class SetCanvasConnectionCommandTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    super.setUp();
    when(edge.getUUID()).thenReturn(EDGE_ID);
    when(edge.getContent()).thenReturn(edgeContent);
    when(edgeContent.getSourceConnection()).thenReturn(Optional.empty());
    when(edgeContent.getTargetConnection()).thenReturn(Optional.empty());
    when(source.getUUID()).thenReturn(SOURCE_ID);
    when(target.getUUID()).thenReturn(TARGET_ID);
    when(edge.getSourceNode()).thenReturn(source);
    when(edge.getTargetNode()).thenReturn(target);
    when(sourceShape.getShapeView()).thenReturn(sourceShapeView);
    when(targetShape.getShapeView()).thenReturn(targetShapeView);
    when(canvas.getShape(eq(EDGE_ID))).thenReturn(edgeShape);
    when(canvas.getShape(eq(SOURCE_ID))).thenReturn(sourceShape);
    when(canvas.getShape(eq(TARGET_ID))).thenReturn(targetShape);
    when(sourceShape.getShapeView()).thenReturn(sourceShapeView);
    when(sourceShapeView.getBoundingBox()).thenReturn(new BoundingBox(0d, 0d, 10d, 10d));
    when(targetShapeView.getBoundingBox()).thenReturn(new BoundingBox(0d, 0d, 20d, 20d));
    this.tested = new SetCanvasConnectionCommand(edge);
}
Also used : BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) Before(org.junit.Before)

Example 5 with BoundingBox

use of org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox in project kie-wb-common by kiegroup.

the class LienzoResizeNodeCommandTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() {
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shapeView.getMagnets()).thenReturn(magnets);
    when(magnets.getMagnet(eq(0))).thenReturn(magnet);
    when(magnet.getX()).thenReturn(3d);
    when(magnet.getY()).thenReturn(4d);
    BoundingBox boundingBox = new BoundingBox(1, 2, 75, 50);
    tested = new LienzoResizeNodeCommand(node, boundingBox);
}
Also used : BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) Before(org.junit.Before)

Aggregations

BoundingBox (org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox)9 Before (org.junit.Before)4 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)3 Test (org.junit.Test)2 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)2 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)2 Circle (com.ait.lienzo.client.core.shape.Circle)1 OptionalInt (java.util.OptionalInt)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)1