Search in sources :

Example 1 with DiagramNode

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

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.activiti.engine.repository.DiagramNode)

Example 2 with DiagramNode

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

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.activiti.engine.repository.DiagramElement) DiagramNode(org.activiti.engine.repository.DiagramNode) HashMap(java.util.HashMap) DiagramLayout(org.activiti.engine.repository.DiagramLayout)

Example 3 with DiagramNode

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

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.activiti.engine.repository.DiagramNode)

Example 4 with DiagramNode

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

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 ActivitiException("Error while reading process diagram image.", e);
    }
    DiagramNode diagramBoundsImage = getDiagramBoundsFromImage(image, offsetTop, offsetBottom);
    return diagramBoundsImage;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) DiagramNode(org.activiti.engine.repository.DiagramNode) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 5 with DiagramNode

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

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.activiti.engine.repository.DiagramNode) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) DiagramElement(org.activiti.engine.repository.DiagramElement)

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