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));
}
}
}
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()));
}
}
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));
}
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);
}
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);
}
Aggregations