Java Code Examples for org.activiti.bpmn.model.BpmnModel#getGraphicInfo()

The following examples show how to use org.activiti.bpmn.model.BpmnModel#getGraphicInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelImageService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected GraphicInfo calculateDiagramSize(BpmnModel bpmnModel) {
  GraphicInfo diagramInfo = new GraphicInfo();

  for (Pool pool : bpmnModel.getPools()) {
    GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
    double elementMaxX = graphicInfo.getX() + graphicInfo.getWidth();
    double elementMaxY = graphicInfo.getY() + graphicInfo.getHeight();

    if (elementMaxX > diagramInfo.getWidth()) {
      diagramInfo.setWidth(elementMaxX);
    }
    if (elementMaxY > diagramInfo.getHeight()) {
      diagramInfo.setHeight(elementMaxY);
    }
  }

  for (Process process : bpmnModel.getProcesses()) {
    calculateWidthForFlowElements(process.getFlowElements(), bpmnModel, diagramInfo);
    calculateWidthForArtifacts(process.getArtifacts(), bpmnModel, diagramInfo);
  }
  return diagramInfo;
}
 
Example 2
Source File: ModelImageService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void calculateWidthForFlowElements(Collection<FlowElement> elementList, BpmnModel bpmnModel, GraphicInfo diagramInfo) {
  for (FlowElement flowElement : elementList) {
    List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();
    if (flowElement instanceof SequenceFlow) {
      List<GraphicInfo> flowGraphics = bpmnModel.getFlowLocationGraphicInfo(flowElement.getId());
      if (flowGraphics != null && flowGraphics.size() > 0) {
        graphicInfoList.addAll(flowGraphics);
      }
    } else {
      GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowElement.getId());
      if (graphicInfo != null) {
        graphicInfoList.add(graphicInfo);
      }
    }

    processGraphicInfoList(graphicInfoList, diagramInfo);
  }
}
 
Example 3
Source File: BpmnImageTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected GraphicInfo calculateDiagramSize(BpmnModel bpmnModel) {
	GraphicInfo diagramInfo = new GraphicInfo();

    for (Pool pool : bpmnModel.getPools()) {
      GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
      double elementMaxX = graphicInfo.getX() + graphicInfo.getWidth();
      double elementMaxY = graphicInfo.getY() + graphicInfo.getHeight();
      
      if (elementMaxX > diagramInfo.getWidth()) {
    	  diagramInfo.setWidth(elementMaxX);
      }
      if (elementMaxY > diagramInfo.getHeight()) {
    	  diagramInfo.setHeight(elementMaxY);
      }
    }
    
    for (Process process : bpmnModel.getProcesses()) {
    	calculateWidthForFlowElements(process.getFlowElements(), bpmnModel, diagramInfo);
    	calculateWidthForArtifacts(process.getArtifacts(), bpmnModel, diagramInfo);
    }
    return diagramInfo;
}
 
Example 4
Source File: ModelImageService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void scaleDiagram(BpmnModel bpmnModel, double scaleFactor) {
  for (Pool pool : bpmnModel.getPools()) {
    GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
    scaleGraphicInfo(graphicInfo, scaleFactor);
  }

  for (Process process : bpmnModel.getProcesses()) {
    scaleFlowElements(process.getFlowElements(), bpmnModel, scaleFactor);
    scaleArtifacts(process.getArtifacts(), bpmnModel, scaleFactor);
    for (Lane lane : process.getLanes()) {
      scaleGraphicInfo(bpmnModel.getGraphicInfo(lane.getId()), scaleFactor);
    }
  }
}
 
Example 5
Source File: BpmnImageTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void scaleDiagram(BpmnModel bpmnModel, double scaleFactor) {
    for (Pool pool : bpmnModel.getPools()) {
      GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
      scaleGraphicInfo(graphicInfo, scaleFactor);
    }
    
    for (Process process : bpmnModel.getProcesses()) {
    	scaleFlowElements(process.getFlowElements(), bpmnModel, scaleFactor);
    	scaleArtifacts(process.getArtifacts(), bpmnModel, scaleFactor);
    	for (Lane lane : process.getLanes()) {
    		scaleGraphicInfo(bpmnModel.getGraphicInfo(lane.getId()), scaleFactor);
		}
    }
}
 
Example 6
Source File: DefaultProcessDiagramGenerator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * This method makes coordinates of connection flow better.
 * @param processDiagramCanvas
 * @param bpmnModel
 * @param sourceElement
 * @param targetElement
 * @param graphicInfoList
 * @return
 */
protected static List<GraphicInfo> connectionPerfectionizer(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, BaseElement sourceElement, BaseElement targetElement, List<GraphicInfo> graphicInfoList) {
  GraphicInfo sourceGraphicInfo = bpmnModel.getGraphicInfo(sourceElement.getId());
  GraphicInfo targetGraphicInfo = bpmnModel.getGraphicInfo(targetElement.getId());
  
  DefaultProcessDiagramCanvas.SHAPE_TYPE sourceShapeType = getShapeType(sourceElement);
  DefaultProcessDiagramCanvas.SHAPE_TYPE targetShapeType = getShapeType(targetElement);
  
  return processDiagramCanvas.connectionPerfectionizer(sourceShapeType, targetShapeType, sourceGraphicInfo, targetGraphicInfo, graphicInfoList);
}
 
Example 7
Source File: AssociationJsonConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {

  Association association = (Association) baseElement;
  ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(association.getId(), STENCIL_ASSOCIATION, 172, 212, 128, 212);
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(association.getSourceRef()).getWidth() / 2.0);
  dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(association.getSourceRef()).getHeight() / 2.0);
  dockersArrayNode.add(dockNode);

  List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(association.getId());
  if (graphicInfoList.size() > 2) {
    for (int i = 1; i < graphicInfoList.size() - 1; i++) {
      GraphicInfo graphicInfo = graphicInfoList.get(i);
      dockNode = objectMapper.createObjectNode();
      dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
      dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
      dockersArrayNode.add(dockNode);
    }
  }

  GraphicInfo targetGraphicInfo = model.getGraphicInfo(association.getTargetRef());
  GraphicInfo flowGraphicInfo = graphicInfoList.get(graphicInfoList.size() - 1);

  double diffTopY = Math.abs(flowGraphicInfo.getY() - targetGraphicInfo.getY());
  double diffRightX = Math.abs(flowGraphicInfo.getX() - (targetGraphicInfo.getX() + targetGraphicInfo.getWidth()));
  double diffBottomY = Math.abs(flowGraphicInfo.getY() - (targetGraphicInfo.getY() + targetGraphicInfo.getHeight()));

  dockNode = objectMapper.createObjectNode();
  if (diffTopY < 5) {
    dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, 0.0);

  } else if (diffRightX < 5) {
    dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth());
    dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);

  } else if (diffBottomY < 5) {
    dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight());

  } else {
    dockNode.put(EDITOR_BOUNDS_X, 0.0);
    dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
  }
  dockersArrayNode.add(dockNode);
  flowNode.set("dockers", dockersArrayNode);
  ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
  outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
  flowNode.set("outgoing", outgoingArrayNode);
  flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));

  ObjectNode propertiesNode = objectMapper.createObjectNode();
  propertiesNode.put(PROPERTY_OVERRIDE_ID, association.getId());

  flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);

  shapesArrayNode.add(flowNode);
}