use of org.kie.workbench.common.stunner.core.graph.content.Bound in project kie-wb-common by kiegroup.
the class DeleteNodeCommandTest method testGetChildPosition.
@Test
public void testGetChildPosition() {
final double parentX = 10;
final double parentY = 5;
final double nodeX = 7;
final double nodeY = 22;
final double expectedX = parentX + nodeX;
final double expectedY = parentY + nodeY;
final DeleteNodeCommand.CanvasDeleteProcessor processor = mock(DeleteNodeCommand.CanvasDeleteProcessor.class);
final Node node = mock(Node.class);
final Element parent = mock(Element.class);
final View parentContent = mock(View.class);
final View nodeContent = mock(View.class);
final Bounds parentBounds = mock(Bounds.class);
final Bound upParent = new Bound(parentX, parentY);
final Bounds nodeBounds = mock(Bounds.class);
final Bound upNode = new Bound(nodeX, nodeY);
when(parentBounds.getUpperLeft()).thenReturn(upParent);
when(parentContent.getBounds()).thenReturn(parentBounds);
when(parent.getContent()).thenReturn(parentContent);
when(nodeBounds.getUpperLeft()).thenReturn(upNode);
when(nodeContent.getBounds()).thenReturn(nodeBounds);
when(node.getContent()).thenReturn(nodeContent);
when(processor.getChildPosition(node, parent)).thenCallRealMethod();
final Point2D actualPosition = processor.getChildPosition(node, parent);
assertEquals(expectedX, actualPosition.getX(), 0.01);
assertEquals(expectedY, actualPosition.getY(), 0.01);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bound in project kie-wb-common by kiegroup.
the class StunnerClientLogger method logBounds.
public static void logBounds(final Element<? extends View<?>> item) {
final Bounds bounds = item.getContent().getBounds();
final Bound ul = bounds.getUpperLeft();
final Bound lr = bounds.getLowerRight();
LOGGER.log(Level.FINE, "Bounds for [" + item.getUUID() + "] ARE " + "{ UL=[" + ul.getX() + ", " + ul.getY() + "] " + "LR=[ " + lr.getX() + ", " + lr.getY() + "] }");
LOGGER.log(Level.FINE, "Bound attributes for [" + item.getUUID() + "] ARE " + "[X=" + ul.getX() + ", Y=" + ul.getY() + "] " + "[W=[ " + (lr.getX() - ul.getX()) + ", H=" + (lr.getY() - ul.getY()) + "] }");
}
use of org.kie.workbench.common.stunner.core.graph.content.Bound in project kie-wb-common by kiegroup.
the class GraphUtilsTest method testComputeGraphHashCode.
@SuppressWarnings("all")
@Test
public void testComputeGraphHashCode() {
final GraphImpl graph = (GraphImpl) graphInstance.graph;
final int hashCode = GraphUtils.computeGraphHashCode(graph);
// Assert hash is time inmutable
assertEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
// Change some node's shape location.
View nodeContent = (View) graphInstance.startNode.getContent();
Bound lowerRight = nodeContent.getBounds().getLowerRight();
Double x = lowerRight.getX();
Double y = lowerRight.getY();
nodeContent.getBounds().setLowerRight(Bound.create(123d, 123d));
assertNotEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
nodeContent.getBounds().setLowerRight(Bound.create(x, y));
// Rollback node's location changed.
assertEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
// Change some connection.
ViewConnector<MagnetConnection> connectorContent = (ViewConnector) graphInstance.edge1.getContent();
MagnetConnection sconnection = (MagnetConnection) connectorContent.getSourceConnection().get();
MagnetConnection tconnection = (MagnetConnection) connectorContent.getTargetConnection().get();
Point2D sconnectionLocation = sconnection.getLocation();
Point2D tconnectionLocation = tconnection.getLocation();
sconnection.setLocation(Point2D.create(123d, 123d));
tconnection.setLocation(Point2D.create(321d, 321d));
assertNotEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
sconnection.setLocation(sconnectionLocation);
tconnection.setLocation(tconnectionLocation);
// Rollback connection changed.
assertEquals(hashCode, GraphUtils.computeGraphHashCode(graph), 0d);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bound in project kie-wb-common by kiegroup.
the class ProcessPostConverter method scaleBoundaryEventPosition.
/**
* Scales a boundary event position accordingly with his positioning on the target node.
*/
private static void scaleBoundaryEventPosition(BpmnNode boundaryEvent, Bounds subProcessOriginalBounds, Bounds subProcessCurrentBounds, double widthFactor, double heightFactor) {
Bounds bounds = boundaryEvent.value().getContent().getBounds();
Bound ul = bounds.getUpperLeft();
Bound lr = bounds.getLowerRight();
double width = bounds.getWidth();
double height = bounds.getHeight();
if (ul.getX() > 0 && ul.getY() <= 0) {
ul.setX(ul.getX() * widthFactor);
} else if (ul.getX() >= (subProcessOriginalBounds.getWidth() - width / 2) && ul.getY() > 0) {
ul.setX(ul.getX() + subProcessCurrentBounds.getWidth() - subProcessOriginalBounds.getWidth());
ul.setY(ul.getY() * heightFactor);
} else if (ul.getX() > 0 && ul.getY() >= (subProcessOriginalBounds.getHeight() - height / 2)) {
ul.setX(ul.getX() * widthFactor);
ul.setY(ul.getY() + subProcessCurrentBounds.getHeight() - subProcessOriginalBounds.getHeight());
} else if (ul.getX() <= 0 && ul.getY() > 0) {
ul.setY(ul.getY() * heightFactor);
}
lr.setX(ul.getX() + width);
lr.setY(ul.getY() + height);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bound in project kie-wb-common by kiegroup.
the class ProcessPostConverter method applyTranslationIfRequired.
private void applyTranslationIfRequired(double x, double y, double deltaX, double deltaY, BpmnNode node) {
Bounds bounds = node.value().getContent().getBounds();
Bound ul = bounds.getUpperLeft();
if (ul.getX() >= x && ul.getY() >= y) {
translate(node, deltaX, deltaY);
} else if (ul.getX() >= x && ul.getY() < y) {
translate(node, deltaX, 0);
} else if (ul.getX() < x && ul.getY() >= y) {
translate(node, 0, deltaY);
}
}
Aggregations