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