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