Search in sources :

Example 41 with BpmnShape

use of org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape 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 42 with BpmnShape

use of org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape in project camunda-bpmn-model by camunda.

the class AbstractBaseElementBuilder method findBpmnShape.

protected BpmnShape findBpmnShape(BaseElement node) {
    Collection<BpmnShape> allShapes = modelInstance.getModelElementsByType(BpmnShape.class);
    Iterator<BpmnShape> iterator = allShapes.iterator();
    while (iterator.hasNext()) {
        BpmnShape shape = iterator.next();
        if (shape.getBpmnElement().equals(node)) {
            return shape;
        }
    }
    return null;
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)

Example 43 with BpmnShape

use of org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape 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 44 with BpmnShape

use of org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape in project camunda-bpmn-model by camunda.

the class AbstractEventSubProcessBuilder method startEvent.

public StartEventBuilder startEvent(String id) {
    StartEvent start = createChild(StartEvent.class, id);
    BpmnShape startShape = createBpmnShape(start);
    BpmnShape subProcessShape = findBpmnShape(getElement());
    if (subProcessShape != null) {
        Bounds subProcessBounds = subProcessShape.getBounds();
        Bounds startBounds = startShape.getBounds();
        double subProcessX = subProcessBounds.getX();
        double subProcessY = subProcessBounds.getY();
        double subProcessHeight = subProcessBounds.getHeight();
        double startHeight = startBounds.getHeight();
        startBounds.setX(subProcessX + SPACE);
        startBounds.setY(subProcessY + subProcessHeight / 2 - startHeight / 2);
    }
    return start.builder();
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds) StartEvent(org.camunda.bpm.model.bpmn.instance.StartEvent)

Example 45 with BpmnShape

use of org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape in project camunda-bpmn-model by camunda.

the class ProcessBuilder method eventSubProcess.

public EventSubProcessBuilder eventSubProcess(String id) {
    // Create a subprocess, triggered by an event, and add it to modelInstance
    SubProcess subProcess = createChild(SubProcess.class, id);
    subProcess.setTriggeredByEvent(true);
    // Create Bpmn shape so subprocess will be drawn
    BpmnShape targetBpmnShape = createBpmnShape(subProcess);
    // find the lowest shape in the process
    // place event sub process underneath
    setEventSubProcessCoordinates(targetBpmnShape);
    resizeSubProcess(targetBpmnShape);
    // Return the eventSubProcessBuilder
    EventSubProcessBuilder eventSubProcessBuilder = new EventSubProcessBuilder(modelInstance, subProcess);
    return eventSubProcessBuilder;
}
Also used : SubProcess(org.camunda.bpm.model.bpmn.instance.SubProcess) BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)

Aggregations

BpmnShape (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)46 ProcessBuilder (org.camunda.bpm.model.bpmn.builder.ProcessBuilder)21 Test (org.junit.Test)21 Bounds (org.camunda.bpm.model.bpmn.instance.dc.Bounds)12 SubProcess (org.camunda.bpm.model.bpmn.instance.SubProcess)4 StartEvent (org.camunda.bpm.model.bpmn.instance.StartEvent)3 BoundaryEvent (org.camunda.bpm.model.bpmn.instance.BoundaryEvent)2 Waypoint (org.camunda.bpm.model.bpmn.instance.di.Waypoint)2 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)2 ArrayList (java.util.ArrayList)1 BpmnPlane (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnPlane)1 LabeledShape (org.camunda.bpm.model.bpmn.instance.di.LabeledShape)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1 ModelElementTypeBuilder (org.camunda.bpm.model.xml.type.ModelElementTypeBuilder)1 SequenceBuilder (org.camunda.bpm.model.xml.type.child.SequenceBuilder)1