Search in sources :

Example 1 with Bounds

use of org.camunda.bpm.model.bpmn.instance.dc.Bounds in project camunda-bpmn-model by camunda.

the class AbstractActivityBuilder method calculateXCoordinate.

protected double calculateXCoordinate(Bounds boundaryEventBounds) {
    BpmnShape attachedToElement = findBpmnShape(element);
    double x = 0;
    if (attachedToElement != null) {
        Bounds attachedToBounds = attachedToElement.getBounds();
        Collection<BoundaryEvent> boundaryEvents = element.getParentElement().getChildElementsByType(BoundaryEvent.class);
        Collection<BoundaryEvent> attachedBoundaryEvents = new ArrayList<BoundaryEvent>();
        Iterator<BoundaryEvent> iterator = boundaryEvents.iterator();
        while (iterator.hasNext()) {
            BoundaryEvent tmp = iterator.next();
            if (tmp.getAttachedTo().equals(element)) {
                attachedBoundaryEvents.add(tmp);
            }
        }
        double attachedToX = attachedToBounds.getX();
        double attachedToWidth = attachedToBounds.getWidth();
        double boundaryWidth = boundaryEventBounds.getWidth();
        switch(attachedBoundaryEvents.size()) {
            case 2:
                {
                    x = attachedToX + attachedToWidth / 2 + boundaryWidth / 2;
                    break;
                }
            case 3:
                {
                    x = attachedToX + attachedToWidth / 2 - 1.5 * boundaryWidth;
                    break;
                }
            default:
                {
                    x = attachedToX + attachedToWidth / 2 - boundaryWidth / 2;
                    break;
                }
        }
    }
    return x;
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) BoundaryEvent(org.camunda.bpm.model.bpmn.instance.BoundaryEvent) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) ArrayList(java.util.ArrayList)

Example 2 with Bounds

use of org.camunda.bpm.model.bpmn.instance.dc.Bounds in project camunda-bpmn-model by camunda.

the class CoordinatesGenerationTest method shouldPlaceManyBranchesForExclusiveGateway.

@Test
public void shouldPlaceManyBranchesForExclusiveGateway() {
    ProcessBuilder builder = Bpmn.createExecutableProcess();
    instance = builder.startEvent(START_EVENT_ID).exclusiveGateway("id").userTask(USER_TASK_ID).moveToNode("id").endEvent(END_EVENT_ID).moveToNode("id").serviceTask(SERVICE_TASK_ID).moveToNode("id").sequenceFlowId("s1").sendTask(SEND_TASK_ID).done();
    Bounds userTaskBounds = findBpmnShape(USER_TASK_ID).getBounds();
    assertShapeCoordinates(userTaskBounds, 286, 78);
    Bounds endEventBounds = findBpmnShape(END_EVENT_ID).getBounds();
    assertShapeCoordinates(endEventBounds, 286, 208);
    Bounds serviceTaskBounds = findBpmnShape(SERVICE_TASK_ID).getBounds();
    assertShapeCoordinates(serviceTaskBounds, 286, 294);
    Bounds sendTaskBounds = findBpmnShape(SEND_TASK_ID).getBounds();
    assertShapeCoordinates(sendTaskBounds, 286, 424);
    Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge("s1").getWaypoints();
    Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();
    Waypoint waypoint = iterator.next();
    assertWaypointCoordinates(waypoint, 211, 143);
    while (iterator.hasNext()) {
        waypoint = iterator.next();
    }
    assertWaypointCoordinates(waypoint, 286, 464);
}
Also used : ProcessBuilder(org.camunda.bpm.model.bpmn.builder.ProcessBuilder) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) Waypoint(org.camunda.bpm.model.bpmn.instance.di.Waypoint) Test(org.junit.Test)

Example 3 with Bounds

use of org.camunda.bpm.model.bpmn.instance.dc.Bounds in project camunda-bpmn-model by camunda.

the class CoordinatesGenerationTest method shouldPlaceTwoBranchesForExclusiveGateway.

@Test
public void shouldPlaceTwoBranchesForExclusiveGateway() {
    ProcessBuilder builder = Bpmn.createExecutableProcess();
    instance = builder.startEvent(START_EVENT_ID).exclusiveGateway("id").sequenceFlowId("s1").userTask(USER_TASK_ID).moveToNode("id").sequenceFlowId("s2").endEvent(END_EVENT_ID).done();
    Bounds userTaskBounds = findBpmnShape(USER_TASK_ID).getBounds();
    assertShapeCoordinates(userTaskBounds, 286, 78);
    Bounds endEventBounds = findBpmnShape(END_EVENT_ID).getBounds();
    assertShapeCoordinates(endEventBounds, 286, 208);
    Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge("s2").getWaypoints();
    Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();
    Waypoint waypoint = iterator.next();
    assertWaypointCoordinates(waypoint, 211, 143);
    while (iterator.hasNext()) {
        waypoint = iterator.next();
    }
    assertWaypointCoordinates(waypoint, 286, 226);
}
Also used : ProcessBuilder(org.camunda.bpm.model.bpmn.builder.ProcessBuilder) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) Waypoint(org.camunda.bpm.model.bpmn.instance.di.Waypoint) Test(org.junit.Test)

Example 4 with Bounds

use of org.camunda.bpm.model.bpmn.instance.dc.Bounds in project camunda-bpmn-model by camunda.

the class CoordinatesGenerationTest method shouldPlaceStartEvent.

@Test
public void shouldPlaceStartEvent() {
    ProcessBuilder builder = Bpmn.createExecutableProcess();
    instance = builder.startEvent(START_EVENT_ID).done();
    Bounds startBounds = findBpmnShape(START_EVENT_ID).getBounds();
    assertShapeCoordinates(startBounds, 100, 100);
}
Also used : ProcessBuilder(org.camunda.bpm.model.bpmn.builder.ProcessBuilder) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) Test(org.junit.Test)

Example 5 with Bounds

use of org.camunda.bpm.model.bpmn.instance.dc.Bounds in project camunda-bpmn-model by camunda.

the class AbstractBaseElementBuilder method setWaypointsWithSourceAndTarget.

protected void setWaypointsWithSourceAndTarget(BpmnEdge edge, FlowNode edgeSource, FlowNode edgeTarget) {
    BpmnShape source = findBpmnShape(edgeSource);
    BpmnShape target = findBpmnShape(edgeTarget);
    if (source != null && target != null) {
        Bounds sourceBounds = source.getBounds();
        Bounds targetBounds = target.getBounds();
        double sourceX = sourceBounds.getX();
        double sourceY = sourceBounds.getY();
        double sourceWidth = sourceBounds.getWidth();
        double sourceHeight = sourceBounds.getHeight();
        double targetX = targetBounds.getX();
        double targetY = targetBounds.getY();
        double targetHeight = targetBounds.getHeight();
        Waypoint w1 = createInstance(Waypoint.class);
        if (edgeSource.getOutgoing().size() == 1) {
            w1.setX(sourceX + sourceWidth);
            w1.setY(sourceY + sourceHeight / 2);
            edge.addChildElement(w1);
        } else {
            w1.setX(sourceX + sourceWidth / 2);
            w1.setY(sourceY + sourceHeight);
            edge.addChildElement(w1);
            Waypoint w2 = createInstance(Waypoint.class);
            w2.setX(sourceX + sourceWidth / 2);
            w2.setY(targetY + targetHeight / 2);
            edge.addChildElement(w2);
        }
        Waypoint w3 = createInstance(Waypoint.class);
        w3.setX(targetX);
        w3.setY(targetY + targetHeight / 2);
        edge.addChildElement(w3);
    }
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) Waypoint(org.camunda.bpm.model.bpmn.instance.di.Waypoint)

Aggregations

Bounds (org.camunda.bpm.model.bpmn.instance.dc.Bounds)60 ProcessBuilder (org.camunda.bpm.model.bpmn.builder.ProcessBuilder)45 Test (org.junit.Test)45 Waypoint (org.camunda.bpm.model.bpmn.instance.di.Waypoint)33 BpmnShape (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)12 StartEvent (org.camunda.bpm.model.bpmn.instance.StartEvent)2 SubProcess (org.camunda.bpm.model.bpmn.instance.SubProcess)2 ArrayList (java.util.ArrayList)1 BoundaryEvent (org.camunda.bpm.model.bpmn.instance.BoundaryEvent)1 BpmnPlane (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnPlane)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)1 ModelElementTypeBuilder (org.camunda.bpm.model.xml.type.ModelElementTypeBuilder)1