Search in sources :

Example 81 with Bounds

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

the class CanvasLayoutUtilsTest method getNextOutOfCanvas.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextOutOfCanvas() {
    when(ruleManager.evaluate(eq(ruleSet), Mockito.<RuleEvaluationContext>any())).thenReturn(ruleViolations);
    when(ruleViolations.violations(Violation.Type.ERROR)).thenReturn(ruleViolationIterable);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator()).thenReturn(ruleViolationIterator);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator().hasNext()).thenReturn(true);
    this.graphTestHandler = new TestingGraphMockHandler();
    graphInstance = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    Node node = mock(Node.class);
    Bounds boundsNode = Bounds.create(100d, 0d, 300d, 1400d);
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    Node newNode = mock(Node.class);
    Bounds boundsNewNode = Bounds.create(100d, 200d, 300d, 300d);
    View viewNewNode = mock(View.class);
    when(newNode.getContent()).thenReturn(viewNewNode);
    when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstance.graph);
    when(graphBoundsIndexer.getAt(140.0, 0.0, 200.0, 100.0, null)).thenReturn(node);
    graphInstance.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
    double[] size = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() > size[0]);
    assertTrue(next.getY() == CanvasLayoutUtils.getPaddingY());
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 82 with Bounds

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

the class CanvasLayoutUtilsTest method getNextFromRoot.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextFromRoot() {
    Node node1 = mock(Node.class);
    Bounds boundsNode1 = Bounds.create(100d, 100d, 300d, 200d);
    View viewNode1 = mock(View.class);
    when(node1.getContent()).thenReturn(viewNode1);
    when(viewNode1.getBounds()).thenReturn(boundsNode1);
    Node node2 = mock(Node.class);
    Bounds boundsNode2 = Bounds.create(100d, 100d, 300d, 200d);
    View viewNode2 = mock(View.class);
    when(node2.getContent()).thenReturn(viewNode2);
    when(viewNode2.getBounds()).thenReturn(boundsNode2);
    Node nodeRoot = mock(Node.class);
    double rootWidth = 40d;
    double rootHeight = 40d;
    Bounds rootBounds = Bounds.create(0d, 0d, rootWidth, rootHeight);
    View rootView = mock(View.class);
    when(nodeRoot.getContent()).thenReturn(rootView);
    when(rootView.getBounds()).thenReturn(rootBounds);
    List<Node> nodes = new ArrayList<>();
    List<Edge> edges = new ArrayList<>();
    Edge edge = mock(Edge.class);
    edges.add(edge);
    when(nodeRoot.getOutEdges()).thenReturn(edges);
    when(edge.getTargetNode()).thenReturn(node1);
    when(nodeRoot.getContent()).thenReturn(rootView);
    nodes.add(nodeRoot);
    when(graph.nodes()).thenReturn(nodes);
    when(node2.getInEdges()).thenReturn(edges);
    when(nodeRoot.asNode()).thenReturn(nodeRoot);
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, nodeRoot, node2);
    assertTrue(next.getX() > rootWidth);
    assertTrue(next.getY() > NEW_NODE_HEIGHT);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 83 with Bounds

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

the class LayoutHelperTest method applyLayout.

@Test
public void applyLayout() {
    final LayoutHelper helper = new LayoutHelper(layoutService);
    helper.applyLayout(diagram, layoutExecutor);
    verify(rootNodeContent).setBounds(argumentCaptor.capture());
    final Bounds bounds = argumentCaptor.getValue();
    isCloseToZero(bounds.getLowerRight());
    isCloseToZero(bounds.getUpperLeft());
}
Also used : HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Test(org.junit.Test)

Example 84 with Bounds

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

the class ProcessPostConverter method adjustMagnet.

private static void adjustMagnet(BpmnEdge.Simple edge, boolean targetConnection) {
    EdgePropertyReader propertyReader = (EdgePropertyReader) edge.getPropertyReader();
    BPMNEdge bpmnEdge = propertyReader.getDefinitionResolver().getEdge(propertyReader.getElement().getId());
    if (bpmnEdge.getWaypoint().size() >= 2) {
        Point wayPoint;
        org.eclipse.dd.dc.Bounds bounds;
        Bounds nodeBounds;
        Connection magnetConnection;
        Point2D magnetLocation;
        if (targetConnection) {
            wayPoint = bpmnEdge.getWaypoint().get(bpmnEdge.getWaypoint().size() - 1);
            bounds = edge.getTarget().getPropertyReader().getShape().getBounds();
            magnetConnection = edge.getTargetConnection();
            magnetLocation = magnetConnection.getLocation();
            nodeBounds = edge.getTarget().value().getContent().getBounds();
        } else {
            wayPoint = bpmnEdge.getWaypoint().get(0);
            bounds = edge.getSource().getPropertyReader().getShape().getBounds();
            magnetConnection = edge.getSourceConnection();
            magnetLocation = magnetConnection.getLocation();
            nodeBounds = edge.getSource().value().getContent().getBounds();
        }
        // establish the magnet location using original elements for safety, since elements like events and gateways have
        // fixed sizes in Stunner.
        double wayPointX = wayPoint.getX();
        double wayPointY = wayPoint.getY();
        double boundX = bounds.getX();
        double boundY = bounds.getY();
        double width = bounds.getWidth();
        double height = bounds.getHeight();
        if (equals(wayPointY, boundY, PRECISION)) {
            // magnet is on top in the aris node
            magnetLocation.setX(nodeBounds.getWidth() / 2);
            magnetLocation.setY(0);
        } else if (equals(wayPointY, boundY + height, PRECISION)) {
            // magnet is on bottom in the aris node
            magnetLocation.setX(nodeBounds.getWidth() / 2);
            magnetLocation.setY(nodeBounds.getHeight());
        } else if (equals(wayPointX, boundX, PRECISION)) {
            // magnet is on the left in the aris node
            magnetLocation.setX(0);
            magnetLocation.setY(nodeBounds.getHeight() / 2);
        } else if (equals(wayPointX, boundX + width, PRECISION)) {
            // magnet is on the right the aris node
            magnetLocation.setX(nodeBounds.getWidth());
            magnetLocation.setY(nodeBounds.getHeight() / 2);
        } else {
            if (magnetConnection instanceof MagnetConnection) {
                ((MagnetConnection) magnetConnection).setAuto(true);
            }
        }
    }
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) EdgePropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EdgePropertyReader) 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) Point(org.eclipse.dd.dc.Point) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 85 with Bounds

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

the class ProcessPostConverter method adjustLane.

private static void adjustLane(BpmnNode lane, Padding padding) {
    if (lane.hasChildren()) {
        ViewPort viewPort = ViewPort.of(lane, false);
        Bounds laneBounds = lane.value().getContent().getBounds();
        Bound laneUl = laneBounds.getUpperLeft();
        Bound laneLr = laneBounds.getLowerRight();
        laneUl.setX(viewPort.getUpperLeftX() - padding.getLeft());
        laneUl.setY(viewPort.getUpperLeftY() - padding.getTop());
        laneLr.setX(viewPort.getLowerRightX() + padding.getRight());
        laneLr.setY(viewPort.getLowerRightY() + padding.getBottom());
        RectangleDimensionsSet laneRectangle = ((Lane) lane.value().getContent().getDefinition()).getDimensionsSet();
        laneRectangle.setWidth(new Width(laneBounds.getWidth()));
        laneRectangle.setHeight(new Height(laneBounds.getHeight()));
    }
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) Height(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.Height) RectangleDimensionsSet(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.RectangleDimensionsSet) Width(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.Width)

Aggregations

Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)95 Test (org.junit.Test)42 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)26 Node (org.kie.workbench.common.stunner.core.graph.Node)24 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)20 Graph (org.kie.workbench.common.stunner.core.graph.Graph)9 ArrayList (java.util.ArrayList)8 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)7 HasBounds (org.kie.workbench.common.stunner.core.graph.content.HasBounds)7 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)7 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)6 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)6 Before (org.junit.Before)5 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)5 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)5 List (java.util.List)4 Ignore (org.junit.Ignore)4 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)4