Search in sources :

Example 6 with GraphicInfo

use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.

the class DefaultProcessDiagramGenerator method getLineCenter.

protected static GraphicInfo getLineCenter(List<GraphicInfo> graphicInfoList) {
    GraphicInfo gi = new GraphicInfo();
    int[] xPoints = new int[graphicInfoList.size()];
    int[] yPoints = new int[graphicInfoList.size()];
    double length = 0;
    double[] lengths = new double[graphicInfoList.size()];
    lengths[0] = 0;
    double m;
    for (int i = 1; i < graphicInfoList.size(); i++) {
        GraphicInfo graphicInfo = graphicInfoList.get(i);
        GraphicInfo previousGraphicInfo = graphicInfoList.get(i - 1);
        if (i == 1) {
            xPoints[0] = (int) previousGraphicInfo.getX();
            yPoints[0] = (int) previousGraphicInfo.getY();
        }
        xPoints[i] = (int) graphicInfo.getX();
        yPoints[i] = (int) graphicInfo.getY();
        length += Math.sqrt(Math.pow((int) graphicInfo.getX() - (int) previousGraphicInfo.getX(), 2) + Math.pow((int) graphicInfo.getY() - (int) previousGraphicInfo.getY(), 2));
        lengths[i] = length;
    }
    m = length / 2;
    int p1 = 0, p2 = 1;
    for (int i = 1; i < lengths.length; i++) {
        double len = lengths[i];
        p1 = i - 1;
        p2 = i;
        if (len > m) {
            break;
        }
    }
    GraphicInfo graphicInfo1 = graphicInfoList.get(p1);
    GraphicInfo graphicInfo2 = graphicInfoList.get(p2);
    double AB = (int) graphicInfo2.getX() - (int) graphicInfo1.getX();
    double OA = (int) graphicInfo2.getY() - (int) graphicInfo1.getY();
    double OB = lengths[p2] - lengths[p1];
    double ob = m - lengths[p1];
    double ab = AB * ob / OB;
    double oa = OA * ob / OB;
    double mx = graphicInfo1.getX() + ab;
    double my = graphicInfo1.getY() + oa;
    gi.setX(mx);
    gi.setY(my);
    return gi;
}
Also used : GraphicInfo(org.activiti.bpmn.model.GraphicInfo)

Example 7 with GraphicInfo

use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.

the class BpmnParse method createBPMNEdge.

public void createBPMNEdge(String key, List<GraphicInfo> graphicList) {
    FlowElement flowElement = bpmnModel.getFlowElement(key);
    if (flowElement != null && sequenceFlows.containsKey(key)) {
        TransitionImpl sequenceFlow = sequenceFlows.get(key);
        List<Integer> waypoints = new ArrayList<Integer>();
        for (GraphicInfo waypointInfo : graphicList) {
            waypoints.add((int) waypointInfo.getX());
            waypoints.add((int) waypointInfo.getY());
        }
        sequenceFlow.setWaypoints(waypoints);
    } else if (bpmnModel.getArtifact(key) != null) {
    // it's an association, so nothing to do
    } else {
        LOGGER.warn("Invalid reference in 'bpmnElement' attribute, sequenceFlow " + key + " not found");
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) GraphicInfo(org.activiti.bpmn.model.GraphicInfo)

Example 8 with GraphicInfo

use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.

the class BpmnEdgeParser method parse.

public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
    String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
    List<GraphicInfo> wayPointList = new ArrayList<GraphicInfo>();
    while (xtr.hasNext()) {
        xtr.next();
        if (xtr.isStartElement() && ELEMENT_DI_LABEL.equalsIgnoreCase(xtr.getLocalName())) {
            while (xtr.hasNext()) {
                xtr.next();
                if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
                    GraphicInfo graphicInfo = new GraphicInfo();
                    BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
                    graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue());
                    graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue());
                    graphicInfo.setWidth(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)).intValue());
                    graphicInfo.setHeight(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)).intValue());
                    model.addLabelGraphicInfo(id, graphicInfo);
                    break;
                } else if (xtr.isEndElement() && ELEMENT_DI_LABEL.equalsIgnoreCase(xtr.getLocalName())) {
                    break;
                }
            }
        } else if (xtr.isStartElement() && ELEMENT_DI_WAYPOINT.equalsIgnoreCase(xtr.getLocalName())) {
            GraphicInfo graphicInfo = new GraphicInfo();
            BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
            graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue());
            graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue());
            wayPointList.add(graphicInfo);
        } else if (xtr.isEndElement() && ELEMENT_DI_EDGE.equalsIgnoreCase(xtr.getLocalName())) {
            break;
        }
    }
    model.addFlowGraphicInfoList(id, wayPointList);
}
Also used : ArrayList(java.util.ArrayList) GraphicInfo(org.activiti.bpmn.model.GraphicInfo)

Example 9 with GraphicInfo

use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.

the class BpmnJsonConverter method readShapeDI.

private void readShapeDI(JsonNode objectNode, double parentX, double parentY, Map<String, JsonNode> shapeMap, Map<String, JsonNode> sourceRefMap, BpmnModel bpmnModel) {
    if (objectNode.get(EDITOR_CHILD_SHAPES) != null) {
        for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) {
            String stencilId = BpmnJsonConverterUtil.getStencilId(jsonChildNode);
            if (STENCIL_SEQUENCE_FLOW.equals(stencilId) == false) {
                GraphicInfo graphicInfo = new GraphicInfo();
                JsonNode boundsNode = jsonChildNode.get(EDITOR_BOUNDS);
                ObjectNode upperLeftNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_UPPER_LEFT);
                graphicInfo.setX(upperLeftNode.get(EDITOR_BOUNDS_X).asDouble() + parentX);
                graphicInfo.setY(upperLeftNode.get(EDITOR_BOUNDS_Y).asDouble() + parentY);
                ObjectNode lowerRightNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_LOWER_RIGHT);
                graphicInfo.setWidth(lowerRightNode.get(EDITOR_BOUNDS_X).asDouble() - graphicInfo.getX() + parentX);
                graphicInfo.setHeight(lowerRightNode.get(EDITOR_BOUNDS_Y).asDouble() - graphicInfo.getY() + parentY);
                String childShapeId = jsonChildNode.get(EDITOR_SHAPE_ID).asText();
                bpmnModel.addGraphicInfo(BpmnJsonConverterUtil.getElementId(jsonChildNode), graphicInfo);
                shapeMap.put(childShapeId, jsonChildNode);
                ArrayNode outgoingNode = (ArrayNode) jsonChildNode.get("outgoing");
                if (outgoingNode != null && outgoingNode.size() > 0) {
                    for (JsonNode outgoingChildNode : outgoingNode) {
                        JsonNode resourceNode = outgoingChildNode.get(EDITOR_SHAPE_ID);
                        if (resourceNode != null) {
                            sourceRefMap.put(resourceNode.asText(), jsonChildNode);
                        }
                    }
                }
                readShapeDI(jsonChildNode, graphicInfo.getX(), graphicInfo.getY(), shapeMap, sourceRefMap, bpmnModel);
            }
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 10 with GraphicInfo

use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.

the class BpmnJsonConverter method convertToJson.

public ObjectNode convertToJson(BpmnModel model) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;
    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }
        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }
    maxX += 50;
    maxY += 50;
    if (maxX < 1485) {
        maxX = 1485;
    }
    if (maxY < 700) {
        maxY = 700;
    }
    modelNode.put("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
    modelNode.put("resourceId", "canvas");
    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "BPMNDiagram");
    modelNode.put("stencil", stencilNode);
    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
    modelNode.put("stencilset", stencilsetNode);
    ArrayNode shapesArrayNode = objectMapper.createArrayNode();
    Process mainProcess = null;
    if (model.getPools().size() > 0) {
        mainProcess = model.getProcess(model.getPools().get(0).getId());
    } else {
        mainProcess = model.getMainProcess();
    }
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    if (StringUtils.isNotEmpty(mainProcess.getId())) {
        propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
    }
    if (StringUtils.isNotEmpty(mainProcess.getName())) {
        propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
    }
    if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
    }
    if (mainProcess.isExecutable() == false) {
        propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
    }
    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
    }
    BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);
    BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
    BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
    BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
    BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);
    if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
        BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
    }
    modelNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    boolean poolHasDI = false;
    if (model.getPools().size() > 0) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo != null) {
                poolHasDI = true;
                break;
            }
        }
    }
    if (model.getPools().size() > 0 && poolHasDI) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo == null)
                continue;
            ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL, graphicInfo.getX() + graphicInfo.getWidth(), graphicInfo.getY() + graphicInfo.getHeight(), graphicInfo.getX(), graphicInfo.getY());
            shapesArrayNode.add(poolNode);
            ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
            poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
            poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
            if (pool.isExecutable() == false) {
                poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
            }
            if (StringUtils.isNotEmpty(pool.getName())) {
                poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
            }
            poolNode.put(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);
            ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
            poolNode.put(EDITOR_CHILD_SHAPES, laneShapesArrayNode);
            ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
            poolNode.put("outgoing", outgoingArrayNode);
            Process process = model.getProcess(pool.getId());
            if (process != null) {
                Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
                for (Lane lane : process.getLanes()) {
                    GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
                    if (laneGraphicInfo == null)
                        continue;
                    ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE, laneGraphicInfo.getX() + laneGraphicInfo.getWidth(), laneGraphicInfo.getY() + laneGraphicInfo.getHeight(), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    laneShapesArrayNode.add(laneNode);
                    ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
                    lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
                    }
                    laneNode.put(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);
                    ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
                    laneNode.put(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
                    laneNode.put("outgoing", objectMapper.createArrayNode());
                    laneMap.put(lane.getId(), elementShapesArrayNode);
                }
                for (FlowElement flowElement : process.getFlowElements()) {
                    Lane laneForElement = null;
                    GraphicInfo laneGraphicInfo = null;
                    FlowElement lookForElement = null;
                    if (flowElement instanceof SequenceFlow) {
                        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                        lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
                    } else {
                        lookForElement = flowElement;
                    }
                    for (Lane lane : process.getLanes()) {
                        if (lane.getFlowReferences().contains(lookForElement.getId())) {
                            laneGraphicInfo = model.getGraphicInfo(lane.getId());
                            if (laneGraphicInfo != null) {
                                laneForElement = lane;
                            }
                            break;
                        }
                    }
                    if (flowElement instanceof SequenceFlow || laneForElement != null) {
                        processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    }
                }
                processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
            }
            for (MessageFlow messageFlow : model.getMessageFlows().values()) {
                if (messageFlow.getSourceRef().equals(pool.getId())) {
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
                }
            }
        }
        processMessageFlows(model, shapesArrayNode);
    } else {
        processFlowElements(model.getMainProcess(), model, shapesArrayNode, 0.0, 0.0);
        processMessageFlows(model, shapesArrayNode);
    }
    modelNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);
    return modelNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) MessageFlow(org.activiti.bpmn.model.MessageFlow) FlowElement(org.activiti.bpmn.model.FlowElement) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

GraphicInfo (org.activiti.bpmn.model.GraphicInfo)30 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 SubProcess (org.activiti.bpmn.model.SubProcess)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 FlowElement (org.activiti.bpmn.model.FlowElement)7 ArrayList (java.util.ArrayList)6 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)6 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)4 FlowNode (org.activiti.bpmn.model.FlowNode)4 MessageFlow (org.activiti.bpmn.model.MessageFlow)4 Process (org.activiti.bpmn.model.Process)4 Activity (org.activiti.bpmn.model.Activity)3 Artifact (org.activiti.bpmn.model.Artifact)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ExternalResource (com.vaadin.terminal.ExternalResource)2 StreamResource (com.vaadin.terminal.StreamResource)2 Embedded (com.vaadin.ui.Embedded)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 Panel (com.vaadin.ui.Panel)2