Search in sources :

Example 46 with Bounds

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

the class AbstractActivityBuilder method setBoundaryEventCoordinates.

protected void setBoundaryEventCoordinates(BpmnShape bpmnShape) {
    BpmnShape activity = findBpmnShape(element);
    Bounds boundaryBounds = bpmnShape.getBounds();
    double x = 0;
    double y = 0;
    if (activity != null) {
        Bounds activityBounds = activity.getBounds();
        double activityY = activityBounds.getY();
        double activityHeight = activityBounds.getHeight();
        double boundaryHeight = boundaryBounds.getHeight();
        x = calculateXCoordinate(boundaryBounds);
        y = activityY + activityHeight - boundaryHeight / 2;
    }
    boundaryBounds.setX(x);
    boundaryBounds.setY(y);
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds)

Example 47 with Bounds

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

the class AbstractBaseElementBuilder method setCoordinates.

protected void setCoordinates(BpmnShape shape) {
    BpmnShape source = findBpmnShape(element);
    Bounds shapeBounds = shape.getBounds();
    double x = 0;
    double y = 0;
    if (source != null) {
        Bounds sourceBounds = source.getBounds();
        double sourceX = sourceBounds.getX();
        double sourceWidth = sourceBounds.getWidth();
        x = sourceX + sourceWidth + SPACE;
        if (element instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) element;
            Collection<SequenceFlow> outgoing = flowNode.getOutgoing();
            if (outgoing.size() == 0) {
                double sourceY = sourceBounds.getY();
                double sourceHeight = sourceBounds.getHeight();
                double targetHeight = shapeBounds.getHeight();
                y = sourceY + sourceHeight / 2 - targetHeight / 2;
            } else {
                SequenceFlow[] sequenceFlows = outgoing.toArray(new SequenceFlow[outgoing.size()]);
                SequenceFlow last = sequenceFlows[outgoing.size() - 1];
                BpmnShape targetShape = findBpmnShape(last.getTarget());
                if (targetShape != null) {
                    Bounds targetBounds = targetShape.getBounds();
                    double lastY = targetBounds.getY();
                    double lastHeight = targetBounds.getHeight();
                    y = lastY + lastHeight + SPACE;
                }
            }
        }
    }
    shapeBounds.setX(x);
    shapeBounds.setY(y);
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds)

Example 48 with Bounds

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

the class AbstractBaseElementBuilder method createBpmnShape.

public BpmnShape createBpmnShape(FlowNode node) {
    BpmnPlane bpmnPlane = findBpmnPlane();
    if (bpmnPlane != null) {
        BpmnShape bpmnShape = createInstance(BpmnShape.class);
        bpmnShape.setBpmnElement(node);
        Bounds nodeBounds = createInstance(Bounds.class);
        if (node instanceof SubProcess) {
            bpmnShape.setExpanded(true);
            nodeBounds.setWidth(350);
            nodeBounds.setHeight(200);
        } else if (node instanceof Activity) {
            nodeBounds.setWidth(100);
            nodeBounds.setHeight(80);
        } else if (node instanceof Event) {
            nodeBounds.setWidth(36);
            nodeBounds.setHeight(36);
        } else if (node instanceof Gateway) {
            nodeBounds.setWidth(50);
            nodeBounds.setHeight(50);
            if (node instanceof ExclusiveGateway) {
                bpmnShape.setMarkerVisible(true);
            }
        }
        nodeBounds.setX(0);
        nodeBounds.setY(0);
        bpmnShape.addChildElement(nodeBounds);
        bpmnPlane.addChildElement(bpmnShape);
        return bpmnShape;
    }
    return null;
}
Also used : BpmnPlane(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnPlane) BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds)

Example 49 with Bounds

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

the class BpmnDiTest method shouldCreateValidBpmnDi.

@Test
public void shouldCreateValidBpmnDi() {
    modelInstance = Bpmn.createProcess("process").startEvent("start").sequenceFlowId("flow").endEvent("end").done();
    process = modelInstance.getModelElementById("process");
    startEvent = modelInstance.getModelElementById("start");
    sequenceFlow = modelInstance.getModelElementById("flow");
    endEvent = modelInstance.getModelElementById("end");
    // create bpmn diagram
    BpmnDiagram bpmnDiagram = modelInstance.newInstance(BpmnDiagram.class);
    bpmnDiagram.setId("diagram");
    bpmnDiagram.setName("diagram");
    bpmnDiagram.setDocumentation("bpmn diagram element");
    bpmnDiagram.setResolution(120.0);
    modelInstance.getDefinitions().addChildElement(bpmnDiagram);
    // create plane for process
    BpmnPlane processPlane = modelInstance.newInstance(BpmnPlane.class);
    processPlane.setId("plane");
    processPlane.setBpmnElement(process);
    bpmnDiagram.setBpmnPlane(processPlane);
    // create shape for start event
    BpmnShape startEventShape = modelInstance.newInstance(BpmnShape.class);
    startEventShape.setId("startShape");
    startEventShape.setBpmnElement(startEvent);
    processPlane.getDiagramElements().add(startEventShape);
    // create bounds for start event shape
    Bounds startEventBounds = modelInstance.newInstance(Bounds.class);
    startEventBounds.setHeight(36.0);
    startEventBounds.setWidth(36.0);
    startEventBounds.setX(632.0);
    startEventBounds.setY(312.0);
    startEventShape.setBounds(startEventBounds);
    // create shape for end event
    BpmnShape endEventShape = modelInstance.newInstance(BpmnShape.class);
    endEventShape.setId("endShape");
    endEventShape.setBpmnElement(endEvent);
    processPlane.getDiagramElements().add(endEventShape);
    // create bounds for end event shape
    Bounds endEventBounds = modelInstance.newInstance(Bounds.class);
    endEventBounds.setHeight(36.0);
    endEventBounds.setWidth(36.0);
    endEventBounds.setX(718.0);
    endEventBounds.setY(312.0);
    endEventShape.setBounds(endEventBounds);
    // create edge for sequence flow
    BpmnEdge flowEdge = modelInstance.newInstance(BpmnEdge.class);
    flowEdge.setId("flowEdge");
    flowEdge.setBpmnElement(sequenceFlow);
    flowEdge.setSourceElement(startEventShape);
    flowEdge.setTargetElement(endEventShape);
    processPlane.getDiagramElements().add(flowEdge);
    // create waypoints for sequence flow edge
    Waypoint startWaypoint = modelInstance.newInstance(Waypoint.class);
    startWaypoint.setX(668.0);
    startWaypoint.setY(330.0);
    flowEdge.getWaypoints().add(startWaypoint);
    Waypoint endWaypoint = modelInstance.newInstance(Waypoint.class);
    endWaypoint.setX(718.0);
    endWaypoint.setY(330.0);
    flowEdge.getWaypoints().add(endWaypoint);
}
Also used : Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) Waypoint(org.camunda.bpm.model.bpmn.instance.di.Waypoint) Test(org.junit.Test)

Example 50 with Bounds

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

the class CoordinatesGenerationTest method shouldPlaceBusinessRuleTask.

@Test
public void shouldPlaceBusinessRuleTask() {
    ProcessBuilder builder = Bpmn.createExecutableProcess();
    instance = builder.startEvent(START_EVENT_ID).sequenceFlowId(SEQUENCE_FLOW_ID).businessRuleTask(TASK_ID).done();
    Bounds businessRuleTaskBounds = findBpmnShape(TASK_ID).getBounds();
    assertShapeCoordinates(businessRuleTaskBounds, 186, 78);
    Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge(SEQUENCE_FLOW_ID).getWaypoints();
    Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();
    Waypoint waypoint = iterator.next();
    assertWaypointCoordinates(waypoint, 136, 118);
    while (iterator.hasNext()) {
        waypoint = iterator.next();
    }
    assertWaypointCoordinates(waypoint, 186, 118);
}
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)

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