Search in sources :

Example 6 with DiagramNode

use of org.camunda.bpm.engine.repository.DiagramNode in project camunda-bpm-platform by camunda.

the class ProcessDiagramLayoutFactory method getDiagramBoundsFromBpmnDi.

protected DiagramNode getDiagramBoundsFromBpmnDi(Document bpmnModel) {
    Double minX = null;
    Double minY = null;
    Double maxX = null;
    Double maxY = null;
    // Node positions and dimensions
    NodeList setOfBounds = bpmnModel.getElementsByTagNameNS(BpmnParser.BPMN_DC_NS, "Bounds");
    for (int i = 0; i < setOfBounds.getLength(); i++) {
        Element element = (Element) setOfBounds.item(i);
        Double x = Double.valueOf(element.getAttribute("x"));
        Double y = Double.valueOf(element.getAttribute("y"));
        Double width = Double.valueOf(element.getAttribute("width"));
        Double height = Double.valueOf(element.getAttribute("height"));
        if (x == 0.0 && y == 0.0 && width == 0.0 && height == 0.0) {
        // Ignore empty labels like the ones produced by Yaoqiang:
        // <bpmndi:BPMNLabel><dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel>
        } else {
            if (minX == null || x < minX) {
                minX = x;
            }
            if (minY == null || y < minY) {
                minY = y;
            }
            if (maxX == null || maxX < (x + width)) {
                maxX = (x + width);
            }
            if (maxY == null || maxY < (y + height)) {
                maxY = (y + height);
            }
        }
    }
    // Edge bend points
    NodeList waypoints = bpmnModel.getElementsByTagNameNS(BpmnParser.OMG_DI_NS, "waypoint");
    for (int i = 0; i < waypoints.getLength(); i++) {
        Element waypoint = (Element) waypoints.item(i);
        Double x = Double.valueOf(waypoint.getAttribute("x"));
        Double y = Double.valueOf(waypoint.getAttribute("y"));
        if (minX == null || x < minX) {
            minX = x;
        }
        if (minY == null || y < minY) {
            minY = y;
        }
        if (maxX == null || maxX < x) {
            maxX = x;
        }
        if (maxY == null || maxY < y) {
            maxY = y;
        }
    }
    DiagramNode diagramBounds = new DiagramNode("BPMNDiagram");
    diagramBounds.setX(minX);
    diagramBounds.setY(minY);
    diagramBounds.setWidth(maxX - minX);
    diagramBounds.setHeight(maxY - minY);
    return diagramBounds;
}
Also used : DiagramNode(org.camunda.bpm.engine.repository.DiagramNode) NodeList(org.w3c.dom.NodeList) DiagramElement(org.camunda.bpm.engine.repository.DiagramElement) Element(org.w3c.dom.Element)

Example 7 with DiagramNode

use of org.camunda.bpm.engine.repository.DiagramNode in project camunda-bpm-platform by camunda.

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 ProcessEngineException("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.camunda.bpm.engine.repository.DiagramNode) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 8 with DiagramNode

use of org.camunda.bpm.engine.repository.DiagramNode in project camunda-bpm-platform by camunda.

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.camunda.bpm.engine.repository.DiagramNode) TreeMap(java.util.TreeMap)

Example 9 with DiagramNode

use of org.camunda.bpm.engine.repository.DiagramNode in project camunda-bpm-platform by camunda.

the class ProcessDiagramRetrievalTest method generateHtmlCode.

private static String generateHtmlCode(String imageUrl, DiagramLayout processDiagramLayout, String highlightedActivityId) {
    StringBuilder html = new StringBuilder();
    html.append("<!DOCTYPE html>\n");
    html.append("<html>\n");
    html.append("  <head>\n");
    html.append("    <style type=\"text/css\"><!--\n");
    html.append("      .BPMNElement {\n");
    html.append("        position: absolute;\n");
    html.append("        border: 2px dashed lightBlue;\n");
    html.append("        border-radius: 5px; -moz-border-radius: 5px;\n");
    html.append("      }\n");
    if (highlightedActivityId != null && highlightedActivityId.length() > 0) {
        html.append("      #" + highlightedActivityId + " {border: 2px solid red;}\n");
    }
    html.append("    --></style>");
    html.append("  </head>\n");
    html.append("  <body>\n");
    html.append("    <div style=\"position: relative\">\n");
    html.append("      <img src=\"" + imageUrl + "\" />\n");
    List<DiagramNode> nodes = new ArrayList<DiagramNode>(processDiagramLayout.getNodes());
    // sort the nodes according to their ID property.
    Collections.sort(nodes, new DiagramNodeComparator());
    for (DiagramNode node : nodes) {
        html.append("      <div");
        html.append(" class=\"BPMNElement\"");
        html.append(" id=\"" + node.getId() + "\"");
        html.append(" style=\"");
        html.append(" left: " + (int) (node.getX() - 2) + "px;");
        html.append(" top: " + (int) (node.getY() - 2) + "px;");
        html.append(" width: " + node.getWidth().intValue() + "px;");
        html.append(" height: " + node.getHeight().intValue() + "px;\"></div>\n");
    }
    html.append("    </div>\n");
    html.append("  </body>\n");
    html.append("</html>");
    return html.toString();
}
Also used : DiagramNode(org.camunda.bpm.engine.repository.DiagramNode) ArrayList(java.util.ArrayList)

Aggregations

DiagramNode (org.camunda.bpm.engine.repository.DiagramNode)9 HashMap (java.util.HashMap)3 DiagramElement (org.camunda.bpm.engine.repository.DiagramElement)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)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.camunda.bpm.engine.repository.DiagramLayout)1 Node (org.w3c.dom.Node)1