Search in sources :

Example 6 with BoundsImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl 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), 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 newNode = mock(Node.class);
    Bounds boundsNewNode = new BoundsImpl(new BoundImpl(200d, 300d), new BoundImpl(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) 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 7 with BoundsImpl

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

the class CreateNodeActionTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    when(canvasHandler.getGraphIndex()).thenReturn(graphIndex);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getShapeFactory(eq(SSID_UUID))).thenReturn(shapeFactory);
    when(canvas.getLayer()).thenReturn(layer);
    when(diagram.getGraph()).thenReturn(graph);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getShapeSetId()).thenReturn(SSID_UUID);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(graphIndex.get(eq(NODE_UUID))).thenReturn(element);
    when(graphIndex.getNode(eq(NODE_UUID))).thenReturn(element);
    when(graphIndex.get(eq(EDGE_UUID))).thenReturn(edge);
    when(graphIndex.getEdge(eq(EDGE_UUID))).thenReturn(edge);
    when(graphIndex.get(eq(TARGET_NODE_UUID))).thenReturn(targetNode);
    when(graphIndex.getNode(eq(TARGET_NODE_UUID))).thenReturn(targetNode);
    when(element.getUUID()).thenReturn(NODE_UUID);
    when(element.getContent()).thenReturn(elementContent);
    when(element.asNode()).thenReturn(element);
    when(edge.getUUID()).thenReturn(EDGE_UUID);
    when(edge.asEdge()).thenReturn(edge);
    when(targetNode.getUUID()).thenReturn(TARGET_NODE_UUID);
    when(targetNode.asNode()).thenReturn(targetNode);
    when(targetNode.getContent()).thenReturn(targetNodeContent);
    when(sessionCommandManager.execute(eq(canvasHandler), any(Command.class))).thenReturn(CanvasCommandResultBuilder.SUCCESS);
    when(elementContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 100d)));
    when(targetNodeContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 100d)));
    when(clientFactoryManager.newElement(anyString(), eq(EDGE_ID))).thenReturn((Element) edge);
    when(clientFactoryManager.newElement(anyString(), eq(TARGET_NODE_ID))).thenReturn((Element) targetNode);
    CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory = new DefaultCanvasCommandFactory(null, null);
    this.tested = new CreateNodeAction(definitionUtils, clientFactoryManager, canvasLayoutUtils, canvasElementSelectedEvent, translationService, sessionCommandManager, canvasCommandFactory).setEdgeId(EDGE_ID).setNodeId(TARGET_NODE_ID);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) DefaultCanvasCommandFactory(org.kie.workbench.common.stunner.core.client.canvas.command.DefaultCanvasCommandFactory) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Before(org.junit.Before)

Example 8 with BoundsImpl

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

the class AbstractGraphFactory method build.

@Override
@SuppressWarnings("unchecked   ")
public Graph<DefinitionSet, Node> build(final String uuid, final String definitionSetId) {
    final GraphImpl graph = new GraphImpl<>(uuid, new GraphNodeStoreImpl());
    final DefinitionSet content = new DefinitionSetImpl(definitionSetId);
    graph.setContent(content);
    graph.getLabels().add(definitionSetId);
    content.setBounds(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(getWidth(), getHeight())));
    return graph;
}
Also used : GraphNodeStoreImpl(org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl) DefinitionSetImpl(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSetImpl) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)

Example 9 with BoundsImpl

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

the class AbstractCloneCommandTest method setUp.

public void setUp() {
    super.init(0, 0);
    // creating the mock graph for test
    TestingGraphMockHandler handler = new TestingGraphMockHandler();
    graphInstance = TestingGraphInstanceBuilder.newGraph3(handler);
    graph = graphInstance.graph;
    graphIndex = handler.graphIndex;
    // mocking the clone nodes on the graphIndex
    ArgumentCaptor<Node> nodeArgumentCaptor = ArgumentCaptor.forClass(Node.class);
    when(handler.graphIndex.addNode(nodeArgumentCaptor.capture())).thenAnswer(t -> {
        // Node node = (Node)t.getArguments()[0];
        when(graphIndex.getNode(eq(nodeArgumentCaptor.getValue().getUUID()))).thenReturn(nodeArgumentCaptor.getValue());
        return graphIndex;
    });
    // edge mock
    connectorContent = new ViewConnectorImpl(connectorDefinition, new BoundsImpl(new BoundImpl(1d, 1d), new BoundImpl(1d, 1d)));
    sourceConnection = MagnetConnection.Builder.forElement(graphInstance.startNode);
    connectorContent.setSourceConnection(sourceConnection);
    targetConnection = MagnetConnection.Builder.forElement(graphInstance.intermNode);
    connectorContent.setTargetConnection(targetConnection);
    graphInstance.edge1.setContent(connectorContent);
    graphInstance.edge2.setContent(connectorContent);
    when(definitionManager.cloneManager()).thenReturn(cloneManager);
    when(cloneManager.clone(definition, ClonePolicy.ALL)).thenReturn(definition);
    when(cloneManager.clone(connectorDefinition, ClonePolicy.ALL)).thenReturn(connectorDefinition);
    when(graphCommandExecutionContext.getGraphIndex()).thenReturn(graphIndex);
    when(candidateContent.getDefinition()).thenReturn(definition);
    when(factoryManager.newElement(anyString(), any(Class.class))).thenReturn(cloneElement);
    when(cloneElement.asNode()).thenReturn(clone);
    when(cloneElement.asEdge()).thenReturn(cloneEdge);
    when(cloneEdge.getContent()).thenReturn(connectorContent);
    when(cloneEdge.getUUID()).thenReturn(CLONE_EDGE_UUID);
    when(clone.getContent()).thenReturn(cloneContent);
    when(clone.getUUID()).thenReturn(CLONE_UUID);
    when(cloneElement.getUUID()).thenReturn(CLONE_UUID);
    when(cloneContent.getBounds()).thenReturn(bounds);
    when(bounds.getUpperLeft()).thenReturn(bound);
    when(bounds.getLowerRight()).thenReturn(bound);
    when(childrenTraverseProcessorManagedInstance.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
}
Also used : ViewConnectorImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnectorImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)

Example 10 with BoundsImpl

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

the class GraphUtilsTest method checkBoundsExceededTest.

@Test
public void checkBoundsExceededTest() {
    Bounds parentBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(200d, 200d));
    Bounds childBounds = new BoundsImpl(new BoundImpl(51d, 51d), new BoundImpl(199d, 199d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(51d, 51d), new BoundImpl(200d, 200d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(199d, 199d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(200d, 200d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(200d, 200d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(199d, 199d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(50d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(51d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Test(org.junit.Test)

Aggregations

BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)31 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)28 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Test (org.junit.Test)11 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)9 Before (org.junit.Before)7 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)6 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)6 Ignore (org.junit.Ignore)4 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 Command (org.kie.workbench.common.stunner.core.command.Command)3 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)3 Consumer (java.util.function.Consumer)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 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2