Search in sources :

Example 26 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 = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
    View viewNode1 = mock(View.class);
    when(node1.getContent()).thenReturn(viewNode1);
    when(viewNode1.getBounds()).thenReturn(boundsNode1);
    Node node2 = mock(Node.class);
    Bounds boundsNode2 = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(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 = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(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) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) ArrayList(java.util.ArrayList) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) 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 27 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), any(RuleEvaluationContext.class))).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 = new BoundsImpl(new BoundImpl(100d, 0d), new BoundImpl(300d, 1400d));
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    Node newNode = mock(Node.class);
    Bounds boundsNewNode = new BoundsImpl(new BoundImpl(100d, 200d), new BoundImpl(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) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) 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 28 with Bounds

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

the class NodeFactoryImpl method build.

@Override
@SuppressWarnings("unchecked")
public Node<Definition<Object>, Edge> build(final String uuid, final Object definition) {
    final NodeImpl node = new NodeImpl<>(uuid);
    final Bounds bounds = definitionUtils.buildBounds(definition, 0d, 0d);
    View<Object> content = new ViewImpl<>(definition, bounds);
    node.setContent(content);
    addLabels(node.getLabels(), definition);
    return node;
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)

Example 29 with Bounds

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

the class CanvasLayoutUtils method getBoundCoordinates.

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

Example 30 with Bounds

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

the class UpdateElementPositionCommand method checkBounds.

@SuppressWarnings("unchecked")
private CommandResult<RuleViolation> checkBounds(final GraphCommandExecutionContext context) {
    final Element<? extends View<?>> element = getNodeNotNull(context);
    final Graph<DefinitionSet, Node> graph = (Graph<DefinitionSet, Node>) getGraph(context);
    final BoundsImpl newBounds = getTargetBounds(element);
    final GraphCommandResultBuilder result = new GraphCommandResultBuilder();
    final Bounds parentBounds = getParentBounds(element, graph);
    if (GraphUtils.checkBoundsExceeded(parentBounds, newBounds)) {
        ((View) element.getContent()).setBounds(newBounds);
    } else {
        result.addViolation(new BoundsExceededViolation(parentBounds).setUUID(element.getUUID()));
    }
    return result.build();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)34 View (org.kie.workbench.common.stunner.core.graph.content.view.View)18 Test (org.junit.Test)16 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Node (org.kie.workbench.common.stunner.core.graph.Node)13 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 Graph (org.kie.workbench.common.stunner.core.graph.Graph)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)6 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)5 Ignore (org.junit.Ignore)4 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)4 Consumer (java.util.function.Consumer)2 Before (org.junit.Before)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)2 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)2 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)2