Search in sources :

Example 26 with GraphicInfo

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);
    }
}
Also used : GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ArrayList(java.util.ArrayList) Circle2D(math.geom2d.conic.Circle2D) JsonNode(com.fasterxml.jackson.databind.JsonNode) Line2D(math.geom2d.line.Line2D) Point2D(math.geom2d.Point2D) AbstractContinuousCurve2D(math.geom2d.curve.AbstractContinuousCurve2D)

Example 27 with GraphicInfo

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;
}
Also used : Shape(java.awt.Shape) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Point(java.awt.Point) Line2D(java.awt.geom.Line2D)

Example 28 with GraphicInfo

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MessageFlow(org.activiti.bpmn.model.MessageFlow)

Example 29 with GraphicInfo

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);
}
Also used : ExclusiveGateway(org.activiti.bpmn.model.ExclusiveGateway) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Activity(org.activiti.bpmn.model.Activity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 30 with GraphicInfo

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);
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

GraphicInfo (org.activiti.bpmn.model.GraphicInfo)30 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 SubProcess (org.activiti.bpmn.model.SubProcess)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 FlowElement (org.activiti.bpmn.model.FlowElement)7 ArrayList (java.util.ArrayList)6 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)6 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)4 FlowNode (org.activiti.bpmn.model.FlowNode)4 MessageFlow (org.activiti.bpmn.model.MessageFlow)4 Process (org.activiti.bpmn.model.Process)4 Activity (org.activiti.bpmn.model.Activity)3 Artifact (org.activiti.bpmn.model.Artifact)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ExternalResource (com.vaadin.terminal.ExternalResource)2 StreamResource (com.vaadin.terminal.StreamResource)2 Embedded (com.vaadin.ui.Embedded)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 Panel (com.vaadin.ui.Panel)2