Search in sources :

Example 6 with DiagramNode

use of org.activiti.engine.repository.DiagramNode in project Activiti by Activiti.

the class ProcessDiagramLayoutFactory method getElementBoundsFromBpmnDi.

protected Map<String, DiagramNode> getElementBoundsFromBpmnDi(Document bpmnModel) {
    Map<String, DiagramNode> listOfBounds = new HashMap<String, DiagramNode>();
    // iterate over all DI shapes
    NodeList shapes = bpmnModel.getElementsByTagNameNS(BpmnParser.BPMN_DI_NS, "BPMNShape");
    for (int i = 0; i < shapes.getLength(); i++) {
        Element shape = (Element) shapes.item(i);
        String bpmnElementId = shape.getAttribute("bpmnElement");
        // get bounds of shape
        NodeList childNodes = shape.getChildNodes();
        for (int j = 0; j < childNodes.getLength(); j++) {
            Node childNode = childNodes.item(j);
            if (childNode instanceof Element && BpmnParser.BPMN_DC_NS.equals(childNode.getNamespaceURI()) && "Bounds".equals(childNode.getLocalName())) {
                DiagramNode bounds = parseBounds((Element) childNode);
                bounds.setId(bpmnElementId);
                listOfBounds.put(bpmnElementId, bounds);
                break;
            }
        }
    }
    return listOfBounds;
}
Also used : DiagramNode(org.activiti.engine.repository.DiagramNode) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) DiagramElement(org.activiti.engine.repository.DiagramElement) Node(org.w3c.dom.Node) DiagramNode(org.activiti.engine.repository.DiagramNode)

Example 7 with DiagramNode

use of org.activiti.engine.repository.DiagramNode in project Activiti by Activiti.

the class ProcessDiagramLayoutFactory method getDiagramBoundsFromImage.

protected DiagramNode getDiagramBoundsFromImage(BufferedImage image, int offsetTop, int offsetBottom) {
    int width = image.getWidth();
    int height = image.getHeight();
    Map<Integer, Boolean> rowIsWhite = new TreeMap<Integer, Boolean>();
    Map<Integer, Boolean> columnIsWhite = new TreeMap<Integer, Boolean>();
    for (int row = 0; row < height; row++) {
        if (!rowIsWhite.containsKey(row)) {
            rowIsWhite.put(row, true);
        }
        if (row <= offsetTop || row > image.getHeight() - offsetBottom) {
            rowIsWhite.put(row, true);
        } else {
            for (int column = 0; column < width; column++) {
                if (!columnIsWhite.containsKey(column)) {
                    columnIsWhite.put(column, true);
                }
                int pixel = image.getRGB(column, row);
                int alpha = (pixel >> 24) & 0xff;
                int red = (pixel >> 16) & 0xff;
                int green = (pixel >> 8) & 0xff;
                int blue = (pixel >> 0) & 0xff;
                if (!(alpha == 0 || (red >= GREY_THRESHOLD && green >= GREY_THRESHOLD && blue >= GREY_THRESHOLD))) {
                    rowIsWhite.put(row, false);
                    columnIsWhite.put(column, false);
                }
            }
        }
    }
    int marginTop = 0;
    for (int row = 0; row < height; row++) {
        if (rowIsWhite.get(row)) {
            ++marginTop;
        } else {
            // Margin Top Found
            break;
        }
    }
    int marginLeft = 0;
    for (int column = 0; column < width; column++) {
        if (columnIsWhite.get(column)) {
            ++marginLeft;
        } else {
            // Margin Left Found
            break;
        }
    }
    int marginRight = 0;
    for (int column = width - 1; column >= 0; column--) {
        if (columnIsWhite.get(column)) {
            ++marginRight;
        } else {
            // Margin Right Found
            break;
        }
    }
    int marginBottom = 0;
    for (int row = height - 1; row >= 0; row--) {
        if (rowIsWhite.get(row)) {
            ++marginBottom;
        } else {
            // Margin Bottom Found
            break;
        }
    }
    DiagramNode diagramBoundsImage = new DiagramNode();
    diagramBoundsImage.setX((double) marginLeft);
    diagramBoundsImage.setY((double) marginTop);
    diagramBoundsImage.setWidth((double) (width - marginRight - marginLeft));
    diagramBoundsImage.setHeight((double) (height - marginBottom - marginTop));
    return diagramBoundsImage;
}
Also used : DiagramNode(org.activiti.engine.repository.DiagramNode) TreeMap(java.util.TreeMap)

Example 8 with DiagramNode

use of org.activiti.engine.repository.DiagramNode in project Activiti by Activiti.

the class ProcessDiagramLayoutFactory method fixFlowNodePositionsIfModelFromAdonis.

protected Map<String, DiagramNode> fixFlowNodePositionsIfModelFromAdonis(Document bpmnModel, Map<String, DiagramNode> elementBoundsFromBpmnDi) {
    if (isExportedFromAdonis50(bpmnModel)) {
        Map<String, DiagramNode> mapOfFixedBounds = new HashMap<String, DiagramNode>();
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        xPath.setNamespaceContext(new Bpmn20NamespaceContext());
        for (Entry<String, DiagramNode> entry : elementBoundsFromBpmnDi.entrySet()) {
            String elementId = entry.getKey();
            DiagramNode elementBounds = entry.getValue();
            String expression = "local-name(//bpmn:*[@id = '" + elementId + "'])";
            try {
                XPathExpression xPathExpression = xPath.compile(expression);
                String elementLocalName = xPathExpression.evaluate(bpmnModel);
                if (!"participant".equals(elementLocalName) && !"lane".equals(elementLocalName) && !"textAnnotation".equals(elementLocalName) && !"group".equals(elementLocalName)) {
                    elementBounds.setX(elementBounds.getX() - elementBounds.getWidth() / 2);
                    elementBounds.setY(elementBounds.getY() - elementBounds.getHeight() / 2);
                }
            } catch (XPathExpressionException e) {
                throw new ActivitiException("Error while evaluating the following XPath expression on a BPMN XML document: '" + expression + "'.", e);
            }
            mapOfFixedBounds.put(elementId, elementBounds);
        }
        return mapOfFixedBounds;
    } else {
        return elementBoundsFromBpmnDi;
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) DiagramNode(org.activiti.engine.repository.DiagramNode) ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Aggregations

DiagramNode (org.activiti.engine.repository.DiagramNode)8 HashMap (java.util.HashMap)3 DiagramElement (org.activiti.engine.repository.DiagramElement)3 ActivitiException (org.activiti.engine.ActivitiException)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 TreeMap (java.util.TreeMap)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XPathFactory (javax.xml.xpath.XPathFactory)1 DiagramLayout (org.activiti.engine.repository.DiagramLayout)1 Node (org.w3c.dom.Node)1