Search in sources :

Example 1 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(InputStream imageStream, int offsetTop, int offsetBottom) {
    BufferedImage image;
    try {
        image = ImageIO.read(imageStream);
    } catch (IOException e) {
        throw new ProcessEngineException("Error while reading process diagram image.", e);
    }
    DiagramNode diagramBoundsImage = getDiagramBoundsFromImage(image, offsetTop, offsetBottom);
    return diagramBoundsImage;
}
Also used : DiagramNode(org.camunda.bpm.engine.repository.DiagramNode) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with DiagramNode

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

the class ProcessDiagramLayoutFactory method getBpmnProcessDiagramLayout.

/**
 * Provides positions and dimensions of elements in a BPMN process diagram as
 * provided by {@link RepositoryService#getProcessDiagram(String)}.
 *
 * @param bpmnXmlStream
 *          BPMN 2.0 XML document
 * @param imageStream
 *          BPMN 2.0 diagram in PNG format (JPEG and other formats supported
 *          by {@link ImageIO} may also work)
 * @return Layout of the process diagram
 * @return null when parameter imageStream is null
 */
public DiagramLayout getBpmnProcessDiagramLayout(Document bpmnModel, InputStream imageStream) {
    if (imageStream == null) {
        return null;
    }
    DiagramNode diagramBoundsXml = getDiagramBoundsFromBpmnDi(bpmnModel);
    DiagramNode diagramBoundsImage;
    if (isExportedFromAdonis50(bpmnModel)) {
        // Adonis header
        int offsetTop = 29;
        // Adonis footer
        int offsetBottom = 61;
        diagramBoundsImage = getDiagramBoundsFromImage(imageStream, offsetTop, offsetBottom);
    } else {
        diagramBoundsImage = getDiagramBoundsFromImage(imageStream);
    }
    Map<String, DiagramNode> listOfBounds = new HashMap<String, DiagramNode>();
    listOfBounds.put(diagramBoundsXml.getId(), diagramBoundsXml);
    // listOfBounds.putAll(getElementBoundsFromBpmnDi(bpmnModel));
    listOfBounds.putAll(fixFlowNodePositionsIfModelFromAdonis(bpmnModel, getElementBoundsFromBpmnDi(bpmnModel)));
    Map<String, DiagramElement> listOfBoundsForImage = transformBoundsForImage(diagramBoundsImage, diagramBoundsXml, listOfBounds);
    return new DiagramLayout(listOfBoundsForImage);
}
Also used : DiagramElement(org.camunda.bpm.engine.repository.DiagramElement) DiagramNode(org.camunda.bpm.engine.repository.DiagramNode) HashMap(java.util.HashMap) DiagramLayout(org.camunda.bpm.engine.repository.DiagramLayout)

Example 3 with DiagramNode

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

the class ProcessDiagramLayoutFactory method parseBounds.

protected DiagramNode parseBounds(Element boundsElement) {
    DiagramNode bounds = new DiagramNode();
    bounds.setX(Double.valueOf(boundsElement.getAttribute("x")));
    bounds.setY(Double.valueOf(boundsElement.getAttribute("y")));
    bounds.setWidth(Double.valueOf(boundsElement.getAttribute("width")));
    bounds.setHeight(Double.valueOf(boundsElement.getAttribute("height")));
    return bounds;
}
Also used : DiagramNode(org.camunda.bpm.engine.repository.DiagramNode)

Example 4 with DiagramNode

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

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.camunda.bpm.engine.repository.DiagramNode) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) DiagramElement(org.camunda.bpm.engine.repository.DiagramElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) DiagramNode(org.camunda.bpm.engine.repository.DiagramNode)

Example 5 with DiagramNode

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

the class ProcessDiagramLayoutFactory method transformBoundsForImage.

protected DiagramNode transformBoundsForImage(DiagramNode diagramBoundsImage, DiagramNode diagramBoundsXml, DiagramNode elementBounds) {
    double scalingFactorX = diagramBoundsImage.getWidth() / diagramBoundsXml.getWidth();
    double scalingFactorY = diagramBoundsImage.getWidth() / diagramBoundsXml.getWidth();
    DiagramNode elementBoundsForImage = new DiagramNode(elementBounds.getId());
    elementBoundsForImage.setX((double) Math.round((elementBounds.getX() - diagramBoundsXml.getX()) * scalingFactorX + diagramBoundsImage.getX()));
    elementBoundsForImage.setY((double) Math.round((elementBounds.getY() - diagramBoundsXml.getY()) * scalingFactorY + diagramBoundsImage.getY()));
    elementBoundsForImage.setWidth((double) Math.round(elementBounds.getWidth() * scalingFactorX));
    elementBoundsForImage.setHeight((double) Math.round(elementBounds.getHeight() * scalingFactorY));
    return elementBoundsForImage;
}
Also used : DiagramNode(org.camunda.bpm.engine.repository.DiagramNode)

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