Search in sources :

Example 1 with BoundsImpl

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

the class AddCanvasNodeCommandTest method testExecuteAndSetViewBounds.

@Test
@SuppressWarnings("unchecked")
public void testExecuteAndSetViewBounds() {
    when(content.getBounds()).thenReturn(BoundsImpl.build(0d, 0d, 0d, 0d));
    final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
    assertNotEquals(CommandResult.Type.ERROR, result.getType());
    verify(canvasHandler, times(1)).register(eq(SHAPE_SET_ID), eq(candidate));
    verify(canvasHandler, times(1)).applyElementMutation(eq(candidate), any(MutationContext.class));
    final ArgumentCaptor<Bounds> boundsArgumentCaptor = ArgumentCaptor.forClass(Bounds.class);
    verify(content, times(1)).setBounds(boundsArgumentCaptor.capture());
    final BoundsImpl bounds = (BoundsImpl) boundsArgumentCaptor.getValue();
    assertEquals(0d, bounds.getX(), 0d);
    assertEquals(0d, bounds.getY(), 0d);
    assertEquals(50d, bounds.getWidth(), 0d);
    assertEquals(50d, bounds.getHeight(), 0d);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) MutationContext(org.kie.workbench.common.stunner.core.client.shape.MutationContext) Test(org.junit.Test)

Example 2 with BoundsImpl

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

the class UpdateElementPositionCommand method getTargetBounds.

@SuppressWarnings("unchecked")
private BoundsImpl getTargetBounds(final Element<? extends View<?>> element) {
    final double[] oldSize = GraphUtils.getNodeSize(element.getContent());
    final double w = oldSize[0];
    final double h = oldSize[1];
    return new BoundsImpl(new BoundImpl(location.getX(), location.getY()), new BoundImpl(location.getX() + w, location.getY() + h));
}
Also used : BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)

Example 3 with BoundsImpl

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

the class DefinitionUtils method buildBounds.

@SuppressWarnings("unchecked")
public Bounds buildBounds(final Object definition, final double x, final double y) {
    final DefinitionAdapter<Object> adapter = definitionManager.adapters().registry().getDefinitionAdapter(definition.getClass());
    final Object r = adapter.getMetaProperty(PropertyMetaTypes.RADIUS, definition);
    Double width = null;
    Double height = null;
    if (null != r) {
        final Double rv = (Double) definitionManager.adapters().forProperty().getValue(r);
        if (null != rv) {
            width = rv * 2;
            height = width;
        }
    } else {
        final Object w = adapter.getMetaProperty(PropertyMetaTypes.WIDTH, definition);
        final Object h = adapter.getMetaProperty(PropertyMetaTypes.HEIGHT, definition);
        if (null != w && null != h) {
            width = (Double) definitionManager.adapters().forProperty().getValue(w);
            height = (Double) definitionManager.adapters().forProperty().getValue(h);
        }
    }
    final double _width = null != width ? width : 0d;
    final double _height = null != height ? height : 0d;
    return new BoundsImpl(new BoundImpl(x, y), new BoundImpl(x + _width, y + _height));
}
Also used : BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)

Example 4 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 getNextFromNewTaskWithNonEmptyPositionWithParent.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextFromNewTaskWithNonEmptyPositionWithParent() {
    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(false);
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    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(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) 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 5 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 getNextFromRootWithParent.

@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    Node node = mock(Node.class);
    Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(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) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) 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) 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