use of org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EdgePropertyReader 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);
}
}
}
}
Aggregations