Search in sources :

Example 16 with Bound

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

the class ProcessPostConverter method adjustEdgeConnection.

private static void adjustEdgeConnection(BpmnEdge.Simple edge, boolean targetConnection) {
    Point2D siblingPoint = null;
    Connection magnetConnection;
    Point2D magnetPoint;
    BpmnNode connectionPointNode;
    List<Point2D> controlPoints = edge.getControlPoints();
    if (targetConnection) {
        magnetConnection = edge.getTargetConnection();
        magnetPoint = magnetConnection.getLocation();
        connectionPointNode = edge.getTarget();
        if (controlPoints.size() >= 1) {
            siblingPoint = controlPoints.get(controlPoints.size() - 1);
        }
    } else {
        magnetConnection = edge.getSourceConnection();
        magnetPoint = magnetConnection.getLocation();
        connectionPointNode = edge.getSource();
        if (controlPoints.size() >= 1) {
            siblingPoint = controlPoints.get(0);
        }
    }
    if (siblingPoint != null) {
        Bounds bounds = connectionPointNode.value().getContent().getBounds();
        Bound nodeUl = bounds.getUpperLeft();
        if (connectionPointNode.isDocked()) {
            // boundary nodes coordinates are relative to the target node, so we need to de-relativize the coordinates.
            BpmnNode dockedNodeTarget = findDockedNodeTarget(connectionPointNode);
            if (dockedNodeTarget != null) {
                double width = bounds.getWidth();
                double height = bounds.getHeight();
                Bounds dockedNodeTargetBounds = dockedNodeTarget.value().getContent().getBounds();
                Bound dockingNodeUL = dockedNodeTargetBounds.getUpperLeft();
                // translate to absolute coordinates
                nodeUl = new Bound(nodeUl.getX() + dockingNodeUL.getX(), nodeUl.getY() + dockingNodeUL.getY());
                Bound nodeLr = new Bound(nodeUl.getX() + width, nodeUl.getY() + height);
                bounds = Bounds.create(nodeUl, nodeLr);
            }
        }
        if (!(magnetConnection instanceof MagnetConnection && ((MagnetConnection) magnetConnection).isAuto())) {
            if (equals(magnetPoint.getY(), 0, PRECISION) || equals(magnetPoint.getY(), bounds.getHeight(), PRECISION)) {
                // magnet point is on top or bottom
                if (siblingPoint.getY() != (magnetPoint.getY() + nodeUl.getY())) {
                    siblingPoint.setX(nodeUl.getX() + (bounds.getWidth() / 2));
                }
            } else {
                // magnet point is on left or right
                if (siblingPoint.getX() != (magnetPoint.getX() + nodeUl.getX())) {
                    siblingPoint.setY(nodeUl.getY() + (bounds.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) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 17 with Bound

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

the class GraphBoundsIndexerImpl method getNodeAbsoluteCoordinates.

private double[] getNodeAbsoluteCoordinates(final Node node, final double parentX, final double parentY) {
    final View content = (View) node.getContent();
    final Bounds bounds = content.getBounds();
    final Bound ulBound = bounds.getUpperLeft();
    final Bound lrBound = bounds.getLowerRight();
    final double ulX = ulBound.getX() + parentX;
    final double ulY = ulBound.getY() + parentY;
    final double lrX = lrBound.getX() + parentX;
    final double lrY = lrBound.getY() + parentY;
    return new double[] { ulX, ulY, lrX, lrY };
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 18 with Bound

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

the class GraphUtils method getSize.

private static double[] getSize(Bounds bounds) {
    final Bound ul = bounds.getUpperLeft();
    final Bound lr = bounds.getLowerRight();
    final double w = lr.getX() - ul.getX();
    final double h = lr.getY() - ul.getY();
    return new double[] { Math.abs(w), Math.abs(h) };
}
Also used : Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 19 with Bound

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

the class GraphUtils method getPosition.

public static Point2D getPosition(final View element) {
    final Bound ul = element.getBounds().getUpperLeft();
    final double x = ul.getX();
    final double y = ul.getY();
    return new Point2D(x, y);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 20 with Bound

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

the class ClientBPMNDocumentationServiceTest method createNode.

private Node createNode(Object content) {
    NodeImpl node = new NodeImpl(UUID.uuid());
    node.setContent(new ViewImpl<>(content, new Bounds(new Bound(0d, 0d), new Bound(1d, 1d))));
    return node;
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Aggregations

Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)40 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)24 View (org.kie.workbench.common.stunner.core.graph.content.view.View)22 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)12 Test (org.junit.Test)10 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)9 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)7 List (java.util.List)6 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)6 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)5 ArrayList (java.util.ArrayList)4 Optional (java.util.Optional)4 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)4 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3