Search in sources :

Example 36 with Bounds

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

the class ConnectionAcceptorControlImplTest method testCreateConnections.

@Test
public void testCreateConnections() {
    // New default connection for a graph element.
    Element element = mock(Element.class);
    View<?> content = mock(View.class);
    Bounds bounds = Bounds.create(0d, 0d, 10d, 20d);
    when(element.getContent()).thenReturn(content);
    when(content.getBounds()).thenReturn(bounds);
    MagnetConnection c1 = ConnectionAcceptorControlImpl.createConnection(element);
    assertEquals(5, c1.getLocation().getX(), 0);
    assertEquals(10, c1.getLocation().getY(), 0);
    assertEquals(MagnetConnection.MAGNET_CENTER, c1.getMagnetIndex().getAsInt());
    assertFalse(c1.isAuto());
    // New default connection for wires.
    WiresConnection wiresConnection = mock(WiresConnection.class);
    when(wiresConnection.isAutoConnection()).thenReturn(true);
    WiresMagnet wiresMagnet = mock(WiresMagnet.class);
    when(wiresMagnet.getX()).thenReturn(122d);
    when(wiresMagnet.getY()).thenReturn(543d);
    when(wiresMagnet.getIndex()).thenReturn(7);
    MagnetConnection c2 = (MagnetConnection) ConnectionAcceptorControlImpl.createConnection(wiresConnection, wiresMagnet);
    assertEquals(122, c2.getLocation().getX(), 0);
    assertEquals(543, c2.getLocation().getY(), 0);
    assertEquals(7, c2.getMagnetIndex().getAsInt());
    assertTrue(c2.isAuto());
    // Asset connections to concrete locations, when no concrete magnets assigned.
    when(wiresConnection.getPoint()).thenReturn(new Point2D(122d, 543d));
    final Connection pointConnection = ConnectionAcceptorControlImpl.createConnection(wiresConnection, null);
    assertEquals(122d, pointConnection.getLocation().getX(), 0);
    assertEquals(543d, pointConnection.getLocation().getY(), 0);
    // Connections (view magnets) can be nullified.
    assertNull(ConnectionAcceptorControlImpl.createConnection(null));
    assertNull(ConnectionAcceptorControlImpl.createConnection(null, null));
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) Element(org.kie.workbench.common.stunner.core.graph.Element) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) Test(org.junit.Test)

Example 37 with Bounds

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

the class CanvasLayoutUtilsTest method getNextFromNewTaskWithNonEmptyPositionWithParent.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextFromNewTaskWithNonEmptyPositionWithParent() {
    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(false);
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    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(graphInstanceParent.graph);
    when(graphBoundsIndexer.getAt(280.0, 100.0, 100.0, 100.0, graphInstanceParent.parentNode)).thenReturn(graphInstanceParent.intermNode);
    graphInstanceParent.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, newNode);
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstanceParent.intermNode;
    double[] size = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > size[1]);
}
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 38 with Bounds

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

the class CanvasLayoutUtilsTest method getNextFromRootWithParent.

@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    Node node = mock(Node.class);
    Bounds boundsNode = Bounds.create(100d, 100d, 300d, 200d);
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, node);
    Node<View<?>, Edge> start = (Node<View<?>, Edge>) graphInstanceParent.startNode;
    double[] size = GraphUtils.getNodeSize(start.getContent());
    assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > size[1]);
}
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) Test(org.junit.Test)

Example 39 with Bounds

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

the class CanvasLayoutUtilsTest method getNextNewTaskWithNonEmptyPosition.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextNewTaskWithNonEmptyPosition() {
    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 newNode = mock(Node.class);
    Bounds boundsNewNode = Bounds.create(200d, 300d, 300d, 400d);
    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, 100.0, 100.0, null)).thenReturn(graphInstance.intermNode);
    graphInstance.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
    Node<View<?>, Edge> startNode = (Node<View<?>, Edge>) graphInstance.startNode;
    double[] sizeStartNode = GraphUtils.getNodeSize(startNode.getContent());
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
    double[] sizeIntermNode = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() == sizeStartNode[0] + CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > sizeIntermNode[1]);
}
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 40 with Bounds

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

the class LayoutHelperTest method setup.

@Before
public void setup() {
    final Bounds graphNode1Bounds = Bounds.create(1, 2, 3, 4);
    when(graphNode1.getContent()).thenReturn(graphNode1Content);
    when(graphNode1Content.getBounds()).thenReturn(graphNode1Bounds);
    final Bounds graphNode2Bounds = Bounds.create(1, 2, 3, 4);
    when(graphNode2.getContent()).thenReturn(graphNode2Content);
    when(graphNode2Content.getBounds()).thenReturn(graphNode2Bounds);
    final Bounds rootNodeBounds = Bounds.create(1, 2, 3, 4);
    when(rootNode.getContent()).thenReturn(rootNodeContent);
    when(rootNodeContent.getBounds()).thenReturn(rootNodeBounds);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(rootNode.getUUID()).thenReturn(ROOT_NODE_ID);
    when(graphNode1.getUUID()).thenReturn("GRAPH_NODE_1");
    when(graphNode2.getUUID()).thenReturn("GRAPH_NODE_2");
    when(diagram.getMetadata().getCanvasRootUUID()).thenReturn(ROOT_NODE_ID);
    when(layoutService.hasLayoutInformation(graph)).thenReturn(false);
    final GraphNodeStoreImpl store = new GraphNodeStoreImpl();
    store.add(rootNode);
    store.add(graphNode1);
    store.add(graphNode2);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(store);
}
Also used : GraphNodeStoreImpl(org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Before(org.junit.Before)

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