Search in sources :

Example 1 with EdgePropertyReader

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);
            }
        }
    }
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) EdgePropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EdgePropertyReader) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point(org.eclipse.dd.dc.Point) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Aggregations

BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)1 Point (org.eclipse.dd.dc.Point)1 EdgePropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EdgePropertyReader)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)1 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1