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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations