use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BpmnJsonConverter method readEdgeDI.
private void readEdgeDI(Map<String, JsonNode> edgeMap, Map<String, List<JsonNode>> sourceAndTargetMap, BpmnModel bpmnModel) {
for (String edgeId : edgeMap.keySet()) {
JsonNode edgeNode = edgeMap.get(edgeId);
List<JsonNode> sourceAndTargetList = sourceAndTargetMap.get(edgeId);
JsonNode sourceRefNode = null;
JsonNode targetRefNode = null;
if (sourceAndTargetList != null && sourceAndTargetList.size() > 1) {
sourceRefNode = sourceAndTargetList.get(0);
targetRefNode = sourceAndTargetList.get(1);
}
if (sourceRefNode == null) {
LOGGER.info("Skipping edge {} because source ref is null", edgeId);
continue;
}
if (targetRefNode == null) {
LOGGER.info("Skipping edge {} because target ref is null", edgeId);
continue;
}
JsonNode dockersNode = edgeNode.get(EDITOR_DOCKERS);
double sourceDockersX = dockersNode.get(0).get(EDITOR_BOUNDS_X).asDouble();
double sourceDockersY = dockersNode.get(0).get(EDITOR_BOUNDS_Y).asDouble();
GraphicInfo sourceInfo = bpmnModel.getGraphicInfo(BpmnJsonConverterUtil.getElementId(sourceRefNode));
GraphicInfo targetInfo = bpmnModel.getGraphicInfo(BpmnJsonConverterUtil.getElementId(targetRefNode));
double sourceRefLineX = sourceInfo.getX() + sourceDockersX;
double sourceRefLineY = sourceInfo.getY() + sourceDockersY;
double nextPointInLineX;
double nextPointInLineY;
nextPointInLineX = dockersNode.get(1).get(EDITOR_BOUNDS_X).asDouble();
nextPointInLineY = dockersNode.get(1).get(EDITOR_BOUNDS_Y).asDouble();
if (dockersNode.size() == 2) {
nextPointInLineX += targetInfo.getX();
nextPointInLineY += targetInfo.getY();
}
Line2D firstLine = new Line2D(sourceRefLineX, sourceRefLineY, nextPointInLineX, nextPointInLineY);
String sourceRefStencilId = BpmnJsonConverterUtil.getStencilId(sourceRefNode);
String targetRefStencilId = BpmnJsonConverterUtil.getStencilId(targetRefNode);
List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();
AbstractContinuousCurve2D source2D = null;
if (DI_CIRCLES.contains(sourceRefStencilId)) {
source2D = new Circle2D(sourceInfo.getX() + sourceDockersX, sourceInfo.getY() + sourceDockersY, sourceDockersX);
} else if (DI_RECTANGLES.contains(sourceRefStencilId)) {
source2D = createRectangle(sourceInfo);
} else if (DI_GATEWAY.contains(sourceRefStencilId)) {
source2D = createGateway(sourceInfo);
}
if (source2D != null) {
Collection<Point2D> intersections = source2D.intersections(firstLine);
if (intersections != null && intersections.size() > 0) {
Point2D intersection = intersections.iterator().next();
graphicInfoList.add(createGraphicInfo(intersection.x(), intersection.y()));
} else {
graphicInfoList.add(createGraphicInfo(sourceRefLineX, sourceRefLineY));
}
}
Line2D lastLine = null;
if (dockersNode.size() > 2) {
for (int i = 1; i < dockersNode.size() - 1; i++) {
double x = dockersNode.get(i).get(EDITOR_BOUNDS_X).asDouble();
double y = dockersNode.get(i).get(EDITOR_BOUNDS_Y).asDouble();
graphicInfoList.add(createGraphicInfo(x, y));
}
double startLastLineX = dockersNode.get(dockersNode.size() - 2).get(EDITOR_BOUNDS_X).asDouble();
double startLastLineY = dockersNode.get(dockersNode.size() - 2).get(EDITOR_BOUNDS_Y).asDouble();
double endLastLineX = dockersNode.get(dockersNode.size() - 1).get(EDITOR_BOUNDS_X).asDouble();
double endLastLineY = dockersNode.get(dockersNode.size() - 1).get(EDITOR_BOUNDS_Y).asDouble();
endLastLineX += targetInfo.getX();
endLastLineY += targetInfo.getY();
lastLine = new Line2D(startLastLineX, startLastLineY, endLastLineX, endLastLineY);
} else {
lastLine = firstLine;
}
AbstractContinuousCurve2D target2D = null;
if (DI_RECTANGLES.contains(targetRefStencilId)) {
target2D = createRectangle(targetInfo);
} else if (DI_CIRCLES.contains(targetRefStencilId)) {
double targetDockersX = dockersNode.get(dockersNode.size() - 1).get(EDITOR_BOUNDS_X).asDouble();
double targetDockersY = dockersNode.get(dockersNode.size() - 1).get(EDITOR_BOUNDS_Y).asDouble();
target2D = new Circle2D(targetInfo.getX() + targetDockersX, targetInfo.getY() + targetDockersY, targetDockersX);
} else if (DI_GATEWAY.contains(targetRefStencilId)) {
target2D = createGateway(targetInfo);
}
if (target2D != null) {
Collection<Point2D> intersections = target2D.intersections(lastLine);
if (intersections != null && intersections.size() > 0) {
Point2D intersection = intersections.iterator().next();
graphicInfoList.add(createGraphicInfo(intersection.x(), intersection.y()));
} else {
graphicInfoList.add(createGraphicInfo(lastLine.getPoint2().x(), lastLine.getPoint2().y()));
}
}
bpmnModel.addFlowGraphicInfoList(edgeId, graphicInfoList);
}
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method connectionPerfectionizer.
/**
* This method makes coordinates of connection flow better.
* @param sourceShapeType
* @param targetShapeType
* @param sourceGraphicInfo
* @param targetGraphicInfo
* @param graphicInfoList
*
*/
public List<GraphicInfo> connectionPerfectionizer(SHAPE_TYPE sourceShapeType, SHAPE_TYPE targetShapeType, GraphicInfo sourceGraphicInfo, GraphicInfo targetGraphicInfo, List<GraphicInfo> graphicInfoList) {
Shape shapeFirst = createShape(sourceShapeType, sourceGraphicInfo);
Shape shapeLast = createShape(targetShapeType, targetGraphicInfo);
if (graphicInfoList != null && graphicInfoList.size() > 0) {
GraphicInfo graphicInfoFirst = graphicInfoList.get(0);
GraphicInfo graphicInfoLast = graphicInfoList.get(graphicInfoList.size() - 1);
if (shapeFirst != null) {
graphicInfoFirst.setX(shapeFirst.getBounds2D().getCenterX());
graphicInfoFirst.setY(shapeFirst.getBounds2D().getCenterY());
}
if (shapeLast != null) {
graphicInfoLast.setX(shapeLast.getBounds2D().getCenterX());
graphicInfoLast.setY(shapeLast.getBounds2D().getCenterY());
}
Point p = null;
if (shapeFirst != null) {
Line2D.Double lineFirst = new Line2D.Double(graphicInfoFirst.getX(), graphicInfoFirst.getY(), graphicInfoList.get(1).getX(), graphicInfoList.get(1).getY());
p = getIntersection(shapeFirst, lineFirst);
if (p != null) {
graphicInfoFirst.setX(p.getX());
graphicInfoFirst.setY(p.getY());
}
}
if (shapeLast != null) {
Line2D.Double lineLast = new Line2D.Double(graphicInfoLast.getX(), graphicInfoLast.getY(), graphicInfoList.get(graphicInfoList.size() - 2).getX(), graphicInfoList.get(graphicInfoList.size() - 2).getY());
p = getIntersection(shapeLast, lineLast);
if (p != null) {
graphicInfoLast.setX(p.getX());
graphicInfoLast.setY(p.getY());
}
}
}
return graphicInfoList;
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class MessageFlowJsonConverter method convertToJson.
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
MessageFlow messageFlow = (MessageFlow) baseElement;
ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(messageFlow.getId(), STENCIL_MESSAGE_FLOW, 172, 212, 128, 212);
ArrayNode dockersArrayNode = objectMapper.createArrayNode();
ObjectNode dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(messageFlow.getSourceRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(messageFlow.getSourceRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
if (model.getFlowLocationGraphicInfo(messageFlow.getId()).size() > 2) {
for (int i = 1; i < model.getFlowLocationGraphicInfo(messageFlow.getId()).size() - 1; i++) {
GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(messageFlow.getId()).get(i);
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
dockersArrayNode.add(dockNode);
}
}
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(messageFlow.getTargetRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(messageFlow.getTargetRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
flowNode.put("dockers", dockersArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getTargetRef()));
flowNode.put("outgoing", outgoingArrayNode);
flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(messageFlow.getTargetRef()));
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, messageFlow.getId());
if (StringUtils.isNotEmpty(messageFlow.getName())) {
propertiesNode.put(PROPERTY_NAME, messageFlow.getName());
}
flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
shapesArrayNode.add(flowNode);
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class SequenceFlowJsonConverter method convertToJson.
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
SequenceFlow sequenceFlow = (SequenceFlow) baseElement;
ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(sequenceFlow.getId(), STENCIL_SEQUENCE_FLOW, 172, 212, 128, 212);
ArrayNode dockersArrayNode = objectMapper.createArrayNode();
ObjectNode dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getSourceRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getSourceRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
if (model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() > 2) {
for (int i = 1; i < model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() - 1; i++) {
GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(sequenceFlow.getId()).get(i);
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
dockersArrayNode.add(dockNode);
}
}
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getTargetRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getTargetRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
flowNode.put("dockers", dockersArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));
flowNode.put("outgoing", outgoingArrayNode);
flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, sequenceFlow.getId());
if (StringUtils.isNotEmpty(sequenceFlow.getName())) {
propertiesNode.put(PROPERTY_NAME, sequenceFlow.getName());
}
if (StringUtils.isNotEmpty(sequenceFlow.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, sequenceFlow.getDocumentation());
}
if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
propertiesNode.put(PROPERTY_SEQUENCEFLOW_CONDITION, sequenceFlow.getConditionExpression());
}
if (StringUtils.isNotEmpty(sequenceFlow.getSourceRef())) {
FlowElement sourceFlowElement = container.getFlowElement(sequenceFlow.getSourceRef());
if (sourceFlowElement != null) {
String defaultFlowId = null;
if (sourceFlowElement instanceof ExclusiveGateway) {
ExclusiveGateway parentExclusiveGateway = (ExclusiveGateway) sourceFlowElement;
defaultFlowId = parentExclusiveGateway.getDefaultFlow();
} else if (sourceFlowElement instanceof Activity) {
Activity parentActivity = (Activity) sourceFlowElement;
defaultFlowId = parentActivity.getDefaultFlow();
}
if (defaultFlowId != null && defaultFlowId.equals(sequenceFlow.getId())) {
propertiesNode.put(PROPERTY_SEQUENCEFLOW_DEFAULT, true);
}
}
}
if (sequenceFlow.getExecutionListeners().size() > 0) {
BpmnJsonConverterUtil.convertListenersToJson(sequenceFlow.getExecutionListeners(), true, propertiesNode);
}
flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
shapesArrayNode.add(flowNode);
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class EventSubProcessJsonConverter method convertElementToJson.
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
SubProcess subProcess = (SubProcess) baseElement;
propertiesNode.put("activitytype", "Event-Sub-Process");
propertiesNode.put("subprocesstype", "Embedded");
ArrayNode subProcessShapesArrayNode = objectMapper.createArrayNode();
GraphicInfo graphicInfo = model.getGraphicInfo(subProcess.getId());
processor.processFlowElements(subProcess, model, subProcessShapesArrayNode, graphicInfo.getX(), graphicInfo.getY());
flowElementNode.put("childShapes", subProcessShapesArrayNode);
}
Aggregations