Search in sources :

Example 1 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class BoundaryEventPropertyReader method getBounds.

@Override
public Bounds getBounds() {
    org.eclipse.dd.dc.Bounds bounds = shape.getBounds();
    Point2D docker = getDockerInfo();
    return BoundsImpl.build(docker.getX(), docker.getY(), docker.getX() + bounds.getWidth(), docker.getY() + bounds.getHeight());
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D)

Example 2 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D 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 3 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class AbstractCanvasControlPointCommandTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    Point2D location1 = new Point2D(0, 0);
    controlPoint1 = new ControlPointImpl(location1);
    ControlPoint controlPoint2 = new ControlPointImpl(location1, 1);
    controlPointList = Arrays.asList(controlPoint1);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shape.addControlPoints(controlPoint1)).thenReturn(Arrays.asList(controlPoint2));
    when(edge.getUUID()).thenReturn(EDGE_UUID);
    when(edge.getContent()).thenReturn(viewConnector);
    when(canvasHandler.getCanvas().getShape(EDGE_UUID)).thenReturn(shape);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Before(org.junit.Before)

Example 4 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class CloneNodeCommandTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    when(candidate.getUUID()).thenReturn(NODE_UUID);
    when(candidate.getContent()).thenReturn(candidateContent);
    when(childrenTraverseProcessorManagedInstance.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
    Point2D position = new Point2D(1, 1);
    this.cloneNodeCommand = new CloneNodeCommand(candidate, PARENT_UUID, position, null, childrenTraverseProcessorManagedInstance);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Before(org.junit.Before)

Example 5 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class GraphBoundsIndexerImpl method getAt.

@Override
public Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode) {
    Point2D parentNodePosition;
    double xToCheck = 0;
    double yToCheck = 0;
    if (parentNode != null) {
        parentNodePosition = GraphUtils.getPosition((View) parentNode.asNode().getContent());
        xToCheck = x + parentNodePosition.getX();
        yToCheck = y + parentNodePosition.getY();
    }
    Node<View<?>, Edge> element;
    Point2D[] pointsToCheck = new Point2D[5];
    pointsToCheck[0] = new Point2D(xToCheck, yToCheck);
    pointsToCheck[1] = new Point2D(xToCheck + width, yToCheck);
    pointsToCheck[2] = new Point2D(xToCheck + (width / 2), yToCheck + (height / 2));
    pointsToCheck[3] = new Point2D(xToCheck, yToCheck + height);
    pointsToCheck[4] = new Point2D(xToCheck + width, yToCheck + height);
    for (Point2D point : pointsToCheck) {
        element = findElementAt(point.getX(), point.getY());
        if (element != null) {
            if (element != parentNode) {
                return element;
            }
        }
    }
    return null;
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)55 Test (org.junit.Test)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)18 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Node (org.kie.workbench.common.stunner.core.graph.Node)15 Command (org.kie.workbench.common.stunner.core.command.Command)10 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)10 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)10 Before (org.junit.Before)9 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)6 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)5 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)5 Ignore (org.junit.Ignore)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)3 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)3 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)3 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)3