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);
}
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());
}
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;
}
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 };
}
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();
}
Aggregations