use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method drawEventBasedGateway.
public void drawEventBasedGateway(GraphicInfo graphicInfo, double scaleFactor) {
// rhombus
drawGateway(graphicInfo);
if (scaleFactor == 1.0) {
int x = (int) graphicInfo.getX();
int y = (int) graphicInfo.getY();
int width = (int) graphicInfo.getWidth();
int height = (int) graphicInfo.getHeight();
double scale = .6;
GraphicInfo eventInfo = new GraphicInfo();
eventInfo.setX(x + width * (1 - scale) / 2);
eventInfo.setY(y + height * (1 - scale) / 2);
eventInfo.setWidth(width * scale);
eventInfo.setHeight(height * scale);
drawCatchingEvent(eventInfo, true, null, "eventGateway", scaleFactor);
double r = width / 6.;
// create pentagon (coords with respect to center)
// top right corner
int topX = (int) (.95 * r);
int topY = (int) (-.31 * r);
// bottom right corner
int bottomX = (int) (.59 * r);
int bottomY = (int) (.81 * r);
int[] xPoints = new int[] { 0, topX, bottomX, -bottomX, -topX };
int[] yPoints = new int[] { -(int) r, topY, bottomY, bottomY, topY };
Polygon pentagon = new Polygon(xPoints, yPoints, 5);
pentagon.translate(x + width / 2, y + width / 2);
// draw
g.drawPolygon(pentagon);
}
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramGenerator method generateProcessDiagram.
protected DefaultProcessDiagramCanvas generateProcessDiagram(BpmnModel bpmnModel, String imageType, List<String> highLightedActivities, List<String> highLightedFlows, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader, double scaleFactor) {
prepareBpmnModel(bpmnModel);
DefaultProcessDiagramCanvas processDiagramCanvas = initProcessDiagramCanvas(bpmnModel, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
// Draw pool shape, if process is participant in collaboration
for (Pool pool : bpmnModel.getPools()) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
processDiagramCanvas.drawPoolOrLane(pool.getName(), graphicInfo);
}
// Draw lanes
for (Process process : bpmnModel.getProcesses()) {
for (Lane lane : process.getLanes()) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(lane.getId());
processDiagramCanvas.drawPoolOrLane(lane.getName(), graphicInfo);
}
}
// Draw activities and their sequence-flows
for (Process process : bpmnModel.getProcesses()) {
for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) {
drawActivity(processDiagramCanvas, bpmnModel, flowNode, highLightedActivities, highLightedFlows, scaleFactor);
}
}
// Draw artifacts
for (Process process : bpmnModel.getProcesses()) {
for (Artifact artifact : process.getArtifacts()) {
drawArtifact(processDiagramCanvas, bpmnModel, artifact);
}
List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
if (subProcesses != null) {
for (SubProcess subProcess : subProcesses) {
for (Artifact subProcessArtifact : subProcess.getArtifacts()) {
drawArtifact(processDiagramCanvas, bpmnModel, subProcessArtifact);
}
}
}
}
return processDiagramCanvas;
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BpmnJsonConverter method convertToJson.
public ObjectNode convertToJson(BpmnModel model) {
ObjectNode modelNode = objectMapper.createObjectNode();
double maxX = 0.0;
double maxY = 0.0;
for (GraphicInfo flowInfo : model.getLocationMap().values()) {
if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
maxX = flowInfo.getX() + flowInfo.getWidth();
}
if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
maxY = flowInfo.getY() + flowInfo.getHeight();
}
}
maxX += 50;
maxY += 50;
if (maxX < 1485) {
maxX = 1485;
}
if (maxY < 700) {
maxY = 700;
}
modelNode.put("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
modelNode.put("resourceId", "canvas");
ObjectNode stencilNode = objectMapper.createObjectNode();
stencilNode.put("id", "BPMNDiagram");
modelNode.put("stencil", stencilNode);
ObjectNode stencilsetNode = objectMapper.createObjectNode();
stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
modelNode.put("stencilset", stencilsetNode);
ArrayNode shapesArrayNode = objectMapper.createArrayNode();
Process mainProcess = null;
if (model.getPools().size() > 0) {
mainProcess = model.getProcess(model.getPools().get(0).getId());
} else {
mainProcess = model.getMainProcess();
}
ObjectNode propertiesNode = objectMapper.createObjectNode();
if (StringUtils.isNotEmpty(mainProcess.getId())) {
propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
}
if (StringUtils.isNotEmpty(mainProcess.getName())) {
propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
}
if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
}
if (mainProcess.isExecutable() == false) {
propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
}
if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
}
BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);
BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);
if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
}
modelNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
boolean poolHasDI = false;
if (model.getPools().size() > 0) {
for (Pool pool : model.getPools()) {
GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
if (graphicInfo != null) {
poolHasDI = true;
break;
}
}
}
if (model.getPools().size() > 0 && poolHasDI) {
for (Pool pool : model.getPools()) {
GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
if (graphicInfo == null)
continue;
ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL, graphicInfo.getX() + graphicInfo.getWidth(), graphicInfo.getY() + graphicInfo.getHeight(), graphicInfo.getX(), graphicInfo.getY());
shapesArrayNode.add(poolNode);
ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
if (pool.isExecutable() == false) {
poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
}
if (StringUtils.isNotEmpty(pool.getName())) {
poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
}
poolNode.put(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);
ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
poolNode.put(EDITOR_CHILD_SHAPES, laneShapesArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
poolNode.put("outgoing", outgoingArrayNode);
Process process = model.getProcess(pool.getId());
if (process != null) {
Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
for (Lane lane : process.getLanes()) {
GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
if (laneGraphicInfo == null)
continue;
ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE, laneGraphicInfo.getX() + laneGraphicInfo.getWidth(), laneGraphicInfo.getY() + laneGraphicInfo.getHeight(), laneGraphicInfo.getX(), laneGraphicInfo.getY());
laneShapesArrayNode.add(laneNode);
ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
if (StringUtils.isNotEmpty(lane.getName())) {
lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
}
laneNode.put(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);
ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
laneNode.put(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
laneNode.put("outgoing", objectMapper.createArrayNode());
laneMap.put(lane.getId(), elementShapesArrayNode);
}
for (FlowElement flowElement : process.getFlowElements()) {
Lane laneForElement = null;
GraphicInfo laneGraphicInfo = null;
FlowElement lookForElement = null;
if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
} else {
lookForElement = flowElement;
}
for (Lane lane : process.getLanes()) {
if (lane.getFlowReferences().contains(lookForElement.getId())) {
laneGraphicInfo = model.getGraphicInfo(lane.getId());
if (laneGraphicInfo != null) {
laneForElement = lane;
}
break;
}
}
if (flowElement instanceof SequenceFlow || laneForElement != null) {
processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()), laneGraphicInfo.getX(), laneGraphicInfo.getY());
}
}
processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(pool.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
}
}
}
processMessageFlows(model, shapesArrayNode);
} else {
processFlowElements(model.getMainProcess(), model, shapesArrayNode, 0.0, 0.0);
processMessageFlows(model, shapesArrayNode);
}
modelNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);
return modelNode;
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BpmnEdgeParser method parse.
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
List<GraphicInfo> wayPointList = new ArrayList<GraphicInfo>();
while (xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement() && ELEMENT_DI_LABEL.equalsIgnoreCase(xtr.getLocalName())) {
while (xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
GraphicInfo graphicInfo = new GraphicInfo();
BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue());
graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue());
graphicInfo.setWidth(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)).intValue());
graphicInfo.setHeight(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)).intValue());
model.addLabelGraphicInfo(id, graphicInfo);
break;
} else if (xtr.isEndElement() && ELEMENT_DI_LABEL.equalsIgnoreCase(xtr.getLocalName())) {
break;
}
}
} else if (xtr.isStartElement() && ELEMENT_DI_WAYPOINT.equalsIgnoreCase(xtr.getLocalName())) {
GraphicInfo graphicInfo = new GraphicInfo();
BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue());
graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue());
wayPointList.add(graphicInfo);
} else if (xtr.isEndElement() && ELEMENT_DI_EDGE.equalsIgnoreCase(xtr.getLocalName())) {
break;
}
}
model.addFlowGraphicInfoList(id, wayPointList);
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BpmnParse method createBPMNEdge.
public void createBPMNEdge(String key, List<GraphicInfo> graphicList) {
FlowElement flowElement = bpmnModel.getFlowElement(key);
if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
List<Integer> waypoints = new ArrayList<Integer>();
for (GraphicInfo waypointInfo : graphicList) {
waypoints.add((int) waypointInfo.getX());
waypoints.add((int) waypointInfo.getY());
}
sequenceFlow.setWaypoints(waypoints);
} else if (bpmnModel.getArtifact(key) != null) {
// it's an association, so nothing to do
} else {
LOGGER.warn("Invalid reference in 'bpmnElement' attribute, sequenceFlow " + key + " not found");
}
}
Aggregations