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), 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 node = mock(Node.class);
Bounds boundsNode = Bounds.create(100d, 0d, 300d, 1400d);
View viewNode = mock(View.class);
when(node.getContent()).thenReturn(viewNode);
when(viewNode.getBounds()).thenReturn(boundsNode);
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(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 CanvasLayoutUtilsTest method getNextFromRoot.
// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextFromRoot() {
Node node1 = mock(Node.class);
Bounds boundsNode1 = Bounds.create(100d, 100d, 300d, 200d);
View viewNode1 = mock(View.class);
when(node1.getContent()).thenReturn(viewNode1);
when(viewNode1.getBounds()).thenReturn(boundsNode1);
Node node2 = mock(Node.class);
Bounds boundsNode2 = Bounds.create(100d, 100d, 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 = Bounds.create(0d, 0d, 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 LayoutHelperTest method applyLayout.
@Test
public void applyLayout() {
final LayoutHelper helper = new LayoutHelper(layoutService);
helper.applyLayout(diagram, layoutExecutor);
verify(rootNodeContent).setBounds(argumentCaptor.capture());
final Bounds bounds = argumentCaptor.getValue();
isCloseToZero(bounds.getLowerRight());
isCloseToZero(bounds.getUpperLeft());
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class ProcessPostConverter method adjustMagnet.
private static void adjustMagnet(BpmnEdge.Simple edge, boolean targetConnection) {
EdgePropertyReader propertyReader = (EdgePropertyReader) edge.getPropertyReader();
BPMNEdge bpmnEdge = propertyReader.getDefinitionResolver().getEdge(propertyReader.getElement().getId());
if (bpmnEdge.getWaypoint().size() >= 2) {
Point wayPoint;
org.eclipse.dd.dc.Bounds bounds;
Bounds nodeBounds;
Connection magnetConnection;
Point2D magnetLocation;
if (targetConnection) {
wayPoint = bpmnEdge.getWaypoint().get(bpmnEdge.getWaypoint().size() - 1);
bounds = edge.getTarget().getPropertyReader().getShape().getBounds();
magnetConnection = edge.getTargetConnection();
magnetLocation = magnetConnection.getLocation();
nodeBounds = edge.getTarget().value().getContent().getBounds();
} else {
wayPoint = bpmnEdge.getWaypoint().get(0);
bounds = edge.getSource().getPropertyReader().getShape().getBounds();
magnetConnection = edge.getSourceConnection();
magnetLocation = magnetConnection.getLocation();
nodeBounds = edge.getSource().value().getContent().getBounds();
}
// establish the magnet location using original elements for safety, since elements like events and gateways have
// fixed sizes in Stunner.
double wayPointX = wayPoint.getX();
double wayPointY = wayPoint.getY();
double boundX = bounds.getX();
double boundY = bounds.getY();
double width = bounds.getWidth();
double height = bounds.getHeight();
if (equals(wayPointY, boundY, PRECISION)) {
// magnet is on top in the aris node
magnetLocation.setX(nodeBounds.getWidth() / 2);
magnetLocation.setY(0);
} else if (equals(wayPointY, boundY + height, PRECISION)) {
// magnet is on bottom in the aris node
magnetLocation.setX(nodeBounds.getWidth() / 2);
magnetLocation.setY(nodeBounds.getHeight());
} else if (equals(wayPointX, boundX, PRECISION)) {
// magnet is on the left in the aris node
magnetLocation.setX(0);
magnetLocation.setY(nodeBounds.getHeight() / 2);
} else if (equals(wayPointX, boundX + width, PRECISION)) {
// magnet is on the right the aris node
magnetLocation.setX(nodeBounds.getWidth());
magnetLocation.setY(nodeBounds.getHeight() / 2);
} else {
if (magnetConnection instanceof MagnetConnection) {
((MagnetConnection) magnetConnection).setAuto(true);
}
}
}
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class ProcessPostConverter method adjustLane.
private static void adjustLane(BpmnNode lane, Padding padding) {
if (lane.hasChildren()) {
ViewPort viewPort = ViewPort.of(lane, false);
Bounds laneBounds = lane.value().getContent().getBounds();
Bound laneUl = laneBounds.getUpperLeft();
Bound laneLr = laneBounds.getLowerRight();
laneUl.setX(viewPort.getUpperLeftX() - padding.getLeft());
laneUl.setY(viewPort.getUpperLeftY() - padding.getTop());
laneLr.setX(viewPort.getLowerRightX() + padding.getRight());
laneLr.setY(viewPort.getLowerRightY() + padding.getBottom());
RectangleDimensionsSet laneRectangle = ((Lane) lane.value().getContent().getDefinition()).getDimensionsSet();
laneRectangle.setWidth(new Width(laneBounds.getWidth()));
laneRectangle.setHeight(new Height(laneBounds.getHeight()));
}
}
Aggregations