Search in sources :

Example 11 with Bound

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

the class DeleteNodeCommandTest method testGetChildPosition.

@Test
public void testGetChildPosition() {
    final double parentX = 10;
    final double parentY = 5;
    final double nodeX = 7;
    final double nodeY = 22;
    final double expectedX = parentX + nodeX;
    final double expectedY = parentY + nodeY;
    final DeleteNodeCommand.CanvasDeleteProcessor processor = mock(DeleteNodeCommand.CanvasDeleteProcessor.class);
    final Node node = mock(Node.class);
    final Element parent = mock(Element.class);
    final View parentContent = mock(View.class);
    final View nodeContent = mock(View.class);
    final Bounds parentBounds = mock(Bounds.class);
    final Bound upParent = new Bound(parentX, parentY);
    final Bounds nodeBounds = mock(Bounds.class);
    final Bound upNode = new Bound(nodeX, nodeY);
    when(parentBounds.getUpperLeft()).thenReturn(upParent);
    when(parentContent.getBounds()).thenReturn(parentBounds);
    when(parent.getContent()).thenReturn(parentContent);
    when(nodeBounds.getUpperLeft()).thenReturn(upNode);
    when(nodeContent.getBounds()).thenReturn(nodeBounds);
    when(node.getContent()).thenReturn(nodeContent);
    when(processor.getChildPosition(node, parent)).thenCallRealMethod();
    final Point2D actualPosition = processor.getChildPosition(node, parent);
    assertEquals(expectedX, actualPosition.getX(), 0.01);
    assertEquals(expectedY, actualPosition.getY(), 0.01);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) Node(org.kie.workbench.common.stunner.core.graph.Node) Element(org.kie.workbench.common.stunner.core.graph.Element) 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) Test(org.junit.Test)

Example 12 with Bound

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

the class StunnerClientLogger method logBounds.

public static void logBounds(final Element<? extends View<?>> item) {
    final Bounds bounds = item.getContent().getBounds();
    final Bound ul = bounds.getUpperLeft();
    final Bound lr = bounds.getLowerRight();
    LOGGER.log(Level.FINE, "Bounds for [" + item.getUUID() + "] ARE " + "{ UL=[" + ul.getX() + ", " + ul.getY() + "] " + "LR=[ " + lr.getX() + ", " + lr.getY() + "] }");
    LOGGER.log(Level.FINE, "Bound attributes for [" + item.getUUID() + "] ARE " + "[X=" + ul.getX() + ", Y=" + ul.getY() + "] " + "[W=[ " + (lr.getX() - ul.getX()) + ", H=" + (lr.getY() - ul.getY()) + "] }");
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 13 with Bound

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

the class GraphUtilsTest method testComputeGraphHashCode.

@SuppressWarnings("all")
@Test
public void testComputeGraphHashCode() {
    final GraphImpl graph = (GraphImpl) graphInstance.graph;
    final int hashCode = GraphUtils.computeGraphHashCode(graph);
    // Assert hash is time inmutable
    assertEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
    // Change some node's shape location.
    View nodeContent = (View) graphInstance.startNode.getContent();
    Bound lowerRight = nodeContent.getBounds().getLowerRight();
    Double x = lowerRight.getX();
    Double y = lowerRight.getY();
    nodeContent.getBounds().setLowerRight(Bound.create(123d, 123d));
    assertNotEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
    nodeContent.getBounds().setLowerRight(Bound.create(x, y));
    // Rollback node's location changed.
    assertEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
    // Change some connection.
    ViewConnector<MagnetConnection> connectorContent = (ViewConnector) graphInstance.edge1.getContent();
    MagnetConnection sconnection = (MagnetConnection) connectorContent.getSourceConnection().get();
    MagnetConnection tconnection = (MagnetConnection) connectorContent.getTargetConnection().get();
    Point2D sconnectionLocation = sconnection.getLocation();
    Point2D tconnectionLocation = tconnection.getLocation();
    sconnection.setLocation(Point2D.create(123d, 123d));
    tconnection.setLocation(Point2D.create(321d, 321d));
    assertNotEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
    sconnection.setLocation(sconnectionLocation);
    tconnection.setLocation(tconnectionLocation);
    // Rollback connection changed.
    assertEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 14 with Bound

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

the class ProcessPostConverter method scaleBoundaryEventPosition.

/**
 * Scales a boundary event position accordingly with his positioning on the target node.
 */
private static void scaleBoundaryEventPosition(BpmnNode boundaryEvent, Bounds subProcessOriginalBounds, Bounds subProcessCurrentBounds, double widthFactor, double heightFactor) {
    Bounds bounds = boundaryEvent.value().getContent().getBounds();
    Bound ul = bounds.getUpperLeft();
    Bound lr = bounds.getLowerRight();
    double width = bounds.getWidth();
    double height = bounds.getHeight();
    if (ul.getX() > 0 && ul.getY() <= 0) {
        ul.setX(ul.getX() * widthFactor);
    } else if (ul.getX() >= (subProcessOriginalBounds.getWidth() - width / 2) && ul.getY() > 0) {
        ul.setX(ul.getX() + subProcessCurrentBounds.getWidth() - subProcessOriginalBounds.getWidth());
        ul.setY(ul.getY() * heightFactor);
    } else if (ul.getX() > 0 && ul.getY() >= (subProcessOriginalBounds.getHeight() - height / 2)) {
        ul.setX(ul.getX() * widthFactor);
        ul.setY(ul.getY() + subProcessCurrentBounds.getHeight() - subProcessOriginalBounds.getHeight());
    } else if (ul.getX() <= 0 && ul.getY() > 0) {
        ul.setY(ul.getY() * heightFactor);
    }
    lr.setX(ul.getX() + width);
    lr.setY(ul.getY() + height);
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 15 with Bound

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

the class ProcessPostConverter method applyTranslationIfRequired.

private void applyTranslationIfRequired(double x, double y, double deltaX, double deltaY, BpmnNode node) {
    Bounds bounds = node.value().getContent().getBounds();
    Bound ul = bounds.getUpperLeft();
    if (ul.getX() >= x && ul.getY() >= y) {
        translate(node, deltaX, deltaY);
    } else if (ul.getX() >= x && ul.getY() < y) {
        translate(node, deltaX, 0);
    } else if (ul.getX() < x && ul.getY() >= y) {
        translate(node, 0, deltaY);
    }
}
Also used : 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