| | |
| | | package com.zt.life.modules.mainPart.taskReliability.service; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import com.zt.common.service.BaseService; |
| | |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.XhProductModelDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ProductImg; |
| | | import com.zt.life.modules.mainPart.taskReliability.dao.*; |
| | | import com.zt.life.modules.mainPart.taskReliability.dto.ModelLinePairDto; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.*; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | |
| | | public static final String OPE_TYPE_SWITCH = "switch"; |
| | | public static final String OPE_TYPE_VOTE = "vote"; |
| | | public static final String OPE_TYPE_BRIDGE = "bridge"; |
| | | |
| | | // 节点 |
| | | /* 自动布局:start与end的大小 */ |
| | | public static final int LAYOUT_START_END_SIZE_X = 60; |
| | | public static final int LAYOUT_START_END_SIZE_Y = 40; |
| | | /* 自动布局:虚框的大小 */ |
| | | public static final int LAYOUT_DASHED_BOX_SIZE_X = 60; |
| | | public static final int LAYOUT_DASHED_BOX_SIZE_Y = 40; |
| | | /* 自动布局:逻辑运算符的大小 */ |
| | | public static final int LAYOUT_OPE_NODE_SIZE_X = 50; |
| | | public static final int LAYOUT_OPE_NODE_SIZE_Y = 50; |
| | | /* 自动布局:设备节点的大小 */ |
| | | public static final int LAYOUT_DEVICE_NODE_SIZE_X = 60; |
| | | public static final int LAYOUT_DEVICE_NODE_SIZE_Y = 60; |
| | | /* 自动布局:connect的大小 */ |
| | | public static final int LAYOUT_CONNECT_SIZE_X = 10; |
| | | public static final int LAYOUT_CONNECT_SIZE_Y = 10; |
| | | |
| | | // 单元格(存放节点) |
| | | /* 自动布局:单元格大小 */ |
| | | public static final int LAYOUT_CELL_SIZE_X = 120; |
| | | public static final int LAYOUT_CELL_SIZE_Y = 120; |
| | | /* 自动布局:节点占据单元格数量 */ |
| | | public static final int LAYOUT_CELL_NUM_NODE_X = 1; |
| | | public static final int LAYOUT_CELL_NUM_NODE_Y = 1; |
| | | public static final int LAYOUT_CELL_NUM_CONNECT_X = 1; |
| | | public static final int LAYOUT_CELL_NUM_CONNECT_Y = 1; |
| | | |
| | | @Autowired |
| | | private ModelLineDao modelLineDao; |
| | |
| | | return result; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean analyze(ModelRbd modelRbd) { |
| | | boolean result = true; |
| | | if (modelRbd == null) return result; |
| | | Long modelId = modelRbd.getId(); |
| | | result = analyzeRbd(modelRbd, true); |
| | | return result; |
| | | } |
| | | |
| | | private boolean layoutRbd(ModelRbd modelRbd) { |
| | | boolean result = true; |
| | | String rbdsonStr = modelRbd.getContent(); |
| | |
| | | |
| | | // 1. 解析出节点与边 |
| | | getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList); |
| | | // 2. 计算所有节点的入口线数及出口线数 |
| | | calcInOutLineNumAllNode(modelNodeList, modelLineList); |
| | | |
| | | // 2. 转换为树型结构 |
| | | RbdTreeNode root = recognizeRbd(modelNodeList, modelLineList); |
| | | // 3. 将桥联转换为3支路的并联 |
| | | convertBridgeToThreeBranchParallel(root); |
| | | // 4. 递归计算RBD的布局空间大小 |
| | | calcLayoutSize(root); |
| | | |
| | | /* |
| | | // 3. 复制产品节点(node)到list |
| | | List<ModelNode> modelNodeAndVnodeList = modelNodeList.stream().filter(item -> |
| | | "node".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | // 4. 不断将基本模型(串联、并联、旁联、表决、桥联)替换为虚节点而简化图形,直至无法简化为止。 |
| | | // result = getAlgorithmFromRbd(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | // 6. 递归计算RBD的布局空间大小 |
| | | calcLayoutSize(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | Collections.reverse(algorithmList); |
| | | RbdTreeNode root2 = listToTree(algorithmList.get(0).getComputerList(), algorithmList, modelNodeAndVnodeList); |
| | | |
| | | RbdTreeNode root = new RbdTreeNode(); |
| | | |
| | | root.setId(Convert.toLong("20000")); |
| | | |
| | | root.setName("end"); |
| | | root.setNodeType("vnode"); |
| | | root.setAlgorithmType("parallel"); |
| | | root.setPicId("20000"); |
| | | root.setPairStartNodeId("10000"); |
| | | |
| | | root.setBlockWidthNum(root2.getBlockWidthNum() + 2); |
| | | root.setBlockHeightNum(root2.getBlockHeightNum()); |
| | | root.getChildren().add(root2); |
| | | |
| | | // 7. 递归计算RBD的布局空间参数(x、y坐标) |
| | | // 5. 递归计算RBD的布局空间参数(x、y坐标) |
| | | root.setBlockX(0); |
| | | root.setBlockY(0); |
| | | |
| | | Map<String, RbdTreeNode> nodeMap = new HashMap<>(); |
| | | calcPosition(rbdJsonArray, root, nodeMap); |
| | | calcPosition(rbdJsonArray, root, nodeMap, false); |
| | | setEdgeRouter(rbdJsonArray, nodeMap); |
| | | |
| | | // 6. 保存自动布局模型 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("cells", rbdJsonArray); |
| | | modelRbd.setContent(jsonObject.toString()); |
| | | // calcLayoutPosition(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | // 8. 保存自动布局模型 |
| | | // 更新RBD数据 |
| | | // modelRbd.setAutoLayoutContent("测试文字"); |
| | | // modelRbdDao.updateById(modelRbd); |
| | | */ |
| | | modelRbdDao.updateById(modelRbd); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private RbdTreeNode recognizeRbd(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | Map<String, Integer> vnodeCounter = new HashMap<>(); |
| | | vnodeCounter.put("vnodeCounter", 0); |
| | | RbdTreeNode root = new RbdTreeNode(); |
| | | root.setAlgorithmType("series"); |
| | | root.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | root.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | root.setNodeType("vnode"); |
| | | |
| | | ModelNode end = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | RbdTreeNode endNode = new RbdTreeNode(); |
| | | endNode.setId(end.getId()); |
| | | endNode.setName("end"); |
| | | endNode.setNodeType("end"); |
| | | endNode.setPicId(end.getPicId()); |
| | | endNode.setPairStartNodeId(end.getPairStartNodeId()); |
| | | endNode.setMyWidth(end.getWidth()); |
| | | endNode.setMyHeight(end.getHeight()); |
| | | root.getChildren().add(endNode); |
| | | ModelLine lineRight = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(end.getPicId())).collect(Collectors.toList()).get(0); |
| | | recognizeOneBranch(root, |
| | | lineRight, |
| | | null, |
| | | modelNodeList, |
| | | modelLineList, |
| | | vnodeCounter); |
| | | |
| | | return root; |
| | | } |
| | | |
| | | private void recognizeOneBranch(RbdTreeNode parent, |
| | | ModelLine lineRight, // 串联的起始线(右边) |
| | | ModelLine lineLeft, // 串联的结束线(左边) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | Map<String, Integer> vnodeCounter) { |
| | | ModelLine inLine = lineRight; |
| | | for (;;) { |
| | | ModelLine searchLine = inLine; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | searchLine.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getName()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setMyWidth(node.getWidth()); |
| | | treeNode.setMyHeight(node.getHeight()); |
| | | parent.getChildren().add(treeNode); |
| | | inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | } else if ("start".equals(node.getNodeType())) { |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getNodeType()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setMyWidth(node.getWidth()); |
| | | treeNode.setMyHeight(node.getHeight()); |
| | | parent.getChildren().add(treeNode); |
| | | break; |
| | | } else if ("connect".equals(node.getNodeType())) { |
| | | break; |
| | | } else if ("parallel,vote,switch,bridge".contains(node.getNodeType())) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | ModelNode connect = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(connect.getId()); |
| | | treeNode.setName(connect.getNodeType()); |
| | | treeNode.setNodeType(connect.getNodeType()); |
| | | treeNode.setPicId(connect.getPicId()); |
| | | treeNode.setMyWidth(connect.getWidth()); |
| | | treeNode.setMyHeight(connect.getHeight()); |
| | | subNode.getChildren().add(treeNode); |
| | | RbdTreeNode subNodeOpe = new RbdTreeNode(); |
| | | subNodeOpe.setAlgorithmType(node.getNodeType()); |
| | | subNodeOpe.setId(UUIDUtil.generateId()); |
| | | counter = vnodeCounter.get("vnodeCounter"); |
| | | subNodeOpe.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNodeOpe.setNodeType("vnode"); |
| | | subNode.getChildren().add(subNodeOpe); |
| | | treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getNodeType()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setPairStartNodeId(node.getPairStartNodeId()); |
| | | treeNode.setMyWidth(node.getWidth()); |
| | | treeNode.setMyHeight(node.getHeight()); |
| | | subNode.getChildren().add(treeNode); |
| | | recognizeOpeBlock(subNodeOpe, |
| | | node, |
| | | modelNodeList, |
| | | modelLineList, |
| | | vnodeCounter); |
| | | inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(connect.getPicId())).collect(Collectors.toList()).get(0); |
| | | } |
| | | |
| | | if (null != lineLeft) { |
| | | if (inLine.getPicId().equals(lineLeft.getPicId())) break; |
| | | } |
| | | } |
| | | if ("series".equals(parent.getAlgorithmType())) Collections.reverse(parent.getChildren()); |
| | | } |
| | | |
| | | private void recognizeOpeBlock(RbdTreeNode parent, |
| | | ModelNode rightNode, // rbd中的右节点(包括end及4种运算符) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | Map<String, Integer> vnodeCounter) { |
| | | if ("parallel,vote,switch".contains(parent.getAlgorithmType())) { |
| | | ModelNode searchNode = rightNode; |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLines = sortLine(lines, modelNodeList); |
| | | for (ModelLine line : sortedLines) { |
| | | boolean isSeries = isSeriesBranch(rightNode, line, modelNodeList, modelLineList); |
| | | if (isSeries) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, line, null, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, line,null, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | } |
| | | } else if ("bridge".contains(parent.getAlgorithmType())) { |
| | | ModelNode searchNode = rightNode; |
| | | List<ModelLine> linesRight = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLinesRight = sortLine(linesRight, modelNodeList); |
| | | List<ModelLine> linesLeft = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(searchNode.getPairStartNodeId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLinesLeft = sortLine(linesLeft, modelNodeList); |
| | | ModelLine lineTop = modelLineList.stream().filter(item -> |
| | | item.getPicId().equals(searchNode.getBridgeEdgeTopId())).collect(Collectors.toList()).get(0); |
| | | ModelLine lineBottom = modelLineList.stream().filter(item -> |
| | | item.getPicId().equals(searchNode.getBridgeEdgeBottomId())).collect(Collectors.toList()).get(0); |
| | | ModelLine verticalLineUpper = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(searchNode.getBridgeEdgeTopId())).collect(Collectors.toList()).get(0); |
| | | ModelLine verticalLineLower = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getBridgeEdgeBottomId())).collect(Collectors.toList()).get(0); |
| | | // 桥联的第1个支路 |
| | | if (isSeriesBranch(lineTop, sortedLinesLeft.get(0), modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, lineTop, sortedLinesLeft.get(0), modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, lineTop, sortedLinesLeft.get(0), modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第2个支路 |
| | | if (isSeriesBranch(sortedLinesRight.get(0), lineTop, modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, sortedLinesRight.get(0), lineTop, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, sortedLinesRight.get(0), lineTop, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第3个支路 |
| | | if (isSeriesBranch(verticalLineLower, verticalLineUpper, modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, verticalLineLower, verticalLineUpper, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, verticalLineLower, verticalLineUpper, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第4个支路 |
| | | if (isSeriesBranch(lineBottom, sortedLinesLeft.get(1), modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, lineBottom, sortedLinesLeft.get(1), modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, lineBottom, sortedLinesLeft.get(1), modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第5个支路 |
| | | if (isSeriesBranch(sortedLinesRight.get(1), lineBottom, modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, sortedLinesRight.get(1), lineBottom, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, sortedLinesRight.get(1), lineBottom, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 按自上而下的顺序排序 |
| | | */ |
| | | private List<ModelLine> sortLine(List<ModelLine> lines, |
| | | List<ModelNode> modelNodeList) { |
| | | for (ModelLine line : lines) { |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | line.setBeginY(node.getPositionY()); |
| | | } |
| | | lines.sort(Comparator.comparing(ModelLine::getBeginY)); |
| | | |
| | | return lines; |
| | | } |
| | | |
| | | private boolean isSingleNode(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode start = modelNodeList.stream().filter(item -> |
| | | "start".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | ModelNode end = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(start.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | line1.getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(end.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node2 = modelNodeList.stream().filter(item -> |
| | | line2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node1.getPicId().equals(node2.getPicId()) && "node".equals(node1.getNodeType())) result = true; |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private boolean isSeriesBranch(ModelNode rightNode, // rbd中的右节点(包括end及4种运算符) |
| | | ModelLine line, // 右节点的入口线 |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | line1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !node1.getPicId().equals(rightNode.getPairStartNodeId()); |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap, Boolean lastIsSeries) { |
| | | if ("node,start,end,connect,parallel,switch,vote,bridge".contains(block.getNodeType())) { |
| | | setNodePositionXY(rbdJsonArray, block, nodeMap); |
| | | } else { |
| | | ModelNode node2 = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node2.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node3 = modelNodeList.stream().filter(item -> |
| | | line2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !node3.getPicId().equals(rightNode.getPairStartNodeId()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | Double descentWidth = block.getDescentWidth(); |
| | | if (descentWidth == null || descentWidth == 0.0) { |
| | | descentWidth = block.getBlockWidth(); |
| | | } |
| | | Double descentHeight = block.getDescentHeight(); |
| | | if (descentHeight == null || descentHeight == 0.0) { |
| | | descentHeight = block.getBlockHeight(); |
| | | } |
| | | List<RbdTreeNode> children = block.getChildren(); |
| | | if (OPE_TYPE_SERIES.equals(block.getAlgorithmType())) { |
| | | Double subBlockX = block.getBlockX(); |
| | | for (RbdTreeNode child : children) { |
| | | |
| | | private boolean isSeriesBranch(ModelLine lineRight, // 串联的起始线(右边) |
| | | ModelLine lineLeft, // 串联的结束线(左边) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | lineRight.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !line1.getPicId().equals(lineLeft.getPicId()); |
| | | } else { |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node1.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !line2.getPicId().equals(lineLeft.getPicId()); |
| | | } |
| | | double selfBlockWidth = child.getBlockWidth() * descentWidth / block.getBlockWidth(); |
| | | child.setDescentWidth(selfBlockWidth); |
| | | child.setBlockWidth(selfBlockWidth); |
| | | if (lastIsSeries) |
| | | child.setDescentHeight(descentHeight); |
| | | else |
| | | child.setDescentHeight(block.getBlockHeight()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void setEdgeRouter(JSONArray rbdJsonArray, Map<String, RbdTreeNode> nodeMap) { |
| | | for (int i = 0; i < rbdJsonArray.size(); i++ |
| | | ) { |
| | | JSONObject jsonObject = rbdJsonArray.getJSONObject(i); |
| | | if (jsonObject.get("shape").equals("edge")) { |
| | | String sourceId = JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString(); |
| | | String targetId = JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString(); |
| | | RbdTreeNode sourceNode = nodeMap.get(sourceId); |
| | | RbdTreeNode targetNode = nodeMap.get(targetId); |
| | | if (sourceNode != null) { |
| | | if ("connect".equals(sourceNode.getNodeType()) && !"10000".equals(sourceId)){ |
| | | if (sourceNode.getY()+sourceNode.getMyHeight()/2 == targetNode.getY()+targetNode.getMyHeight()/2){ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split(",")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(",")); |
| | | }else{ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"top,bottom".split(",")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(",")); |
| | | } |
| | | } |
| | | child.setBlockHeight(block.getBlockHeight() ); |
| | | child.setBlockY(block.getBlockY()); |
| | | child.setBlockX(subBlockX); |
| | | calcPosition(rbdJsonArray, child, nodeMap,true); |
| | | subBlockX = subBlockX + selfBlockWidth; |
| | | } |
| | | if (targetNode != null) { |
| | | if ("parallel,vote".contains(targetNode.getNodeType())){ |
| | | if (sourceNode.getY()+sourceNode.getMyHeight()/2 == targetNode.getY()+targetNode.getMyHeight()/2){ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split("")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split("")); |
| | | }else{ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split("")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"top,bottom".split("")); |
| | | } |
| | | } else { |
| | | Double subBlockY = block.getBlockY() + (descentHeight - block.getObjectHeight())/ 2; |
| | | for (RbdTreeNode child : children) { |
| | | child.setDescentWidth(block.getBlockWidth()); |
| | | child.setDescentHeight(block.getBlockHeight()); |
| | | |
| | | if (!"vnode".equals(child.getNodeType())) { |
| | | child.setBlockWidth(block.getBlockWidth()); |
| | | } |
| | | |
| | | child.setBlockX(block.getBlockX()); |
| | | child.setBlockY(subBlockY); |
| | | calcPosition(rbdJsonArray, child, nodeMap, false); |
| | | subBlockY = subBlockY + child.getBlockHeight(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void setNodePositionXY(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) { |
| | | Double x = block.getBlockX() + (block.getBlockWidth() - block.getMyWidth()) / 2; |
| | | Double y = block.getBlockY() + (block.getBlockHeight() - block.getMyHeight()) / 2; |
| | | Double x = block.getBlockX() + (block.getBlockWidth() - block.getObjectWidth()) / 2; |
| | | Double y = block.getBlockY() + (block.getBlockHeight() - block.getObjectHeight()) / 2; |
| | | block.setX(x); |
| | | block.setY(y); |
| | | nodeMap.put(block.getPicId(),block); |
| | | nodeMap.put(block.getPicId(), block); |
| | | setRbdNodePosition(rbdJsonArray, block.getPicId(), x, y); |
| | | } |
| | | |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) { |
| | | if (block.getNodeType().equals("node")) { |
| | | setNodePositionXY(rbdJsonArray, block,nodeMap); |
| | | } else { |
| | | double blockWidth = block.getBlockWidthNum() * LAYOUT_CELL_SIZE_X; |
| | | double blockHeight = block.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | |
| | | Double descentWidth = block.getDescentWidth(); |
| | | if (descentWidth == null || descentWidth == 0.0) { |
| | | descentWidth = blockWidth; |
| | | } |
| | | Double descentHeight = block.getDescentHeight(); |
| | | if (descentHeight == null || descentHeight == 0.0) { |
| | | descentHeight = blockHeight; |
| | | } |
| | | |
| | | block.setBlockWidth(blockWidth); |
| | | block.setBlockHeight(blockHeight); |
| | | List<RbdTreeNode> children = block.getChildren(); |
| | | |
| | | if (OPE_TYPE_SERIES.equals(block.getAlgorithmType())) { |
| | | Double subBlockX = block.getBlockX(); |
| | | for (RbdTreeNode child : children) { |
| | | |
| | | child.setDescentWidth(blockWidth); |
| | | child.setDescentHeight(blockHeight); |
| | | |
| | | double selfWidth = child.getBlockWidthNum() * LAYOUT_CELL_SIZE_X * descentWidth / blockWidth; |
| | | child.setBlockWidth(selfWidth); |
| | | child.setBlockHeight(blockHeight); |
| | | |
| | | child.setBlockY(block.getBlockY()); |
| | | child.setBlockX(subBlockX); |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | subBlockX = subBlockX + selfWidth; |
| | | |
| | | } |
| | | } else { |
| | | |
| | | Double subBlockY = block.getBlockY() + (descentHeight - blockHeight) / 2; |
| | | Double firstSubBlockY = subBlockY; |
| | | |
| | | // 设置connect的位置 |
| | | RbdTreeNode connectBlock = new RbdTreeNode(); |
| | | connectBlock.setMyWidth(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/width")); |
| | | connectBlock.setMyHeight(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/height")); |
| | | connectBlock.setNodeType("connect"); |
| | | connectBlock.setPicId(block.getPairStartNodeId()); |
| | | connectBlock.setBlockX(block.getBlockX()); |
| | | connectBlock.setBlockY(firstSubBlockY); |
| | | connectBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | connectBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, connectBlock, nodeMap); |
| | | |
| | | for (RbdTreeNode child : children) { |
| | | child.setDescentWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | | child.setDescentHeight(blockHeight); |
| | | |
| | | child.setBlockWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | | child.setBlockHeight(child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y); |
| | | |
| | | child.setBlockX(block.getBlockX() + LAYOUT_CELL_SIZE_X); |
| | | child.setBlockY(subBlockY); |
| | | subBlockY = subBlockY + child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | } |
| | | |
| | | // 设置运算符的位置 |
| | | RbdTreeNode opeBlock = new RbdTreeNode(); |
| | | |
| | | opeBlock.setPicId(block.getPicId()); |
| | | opeBlock.setNodeType("parallel"); |
| | | opeBlock.setMyWidth(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/width")); |
| | | opeBlock.setMyHeight(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/height")); |
| | | opeBlock.setBlockX(block.getBlockX() + blockWidth - LAYOUT_CELL_SIZE_X); |
| | | opeBlock.setBlockY(firstSubBlockY); |
| | | opeBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | opeBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, opeBlock, nodeMap); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private RbdTreeNode listToTree(String id, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | |
| | | List<Algorithm> algos = algorithmList.stream().filter(item -> |
| | | id.equals(item.getId().toString())).collect(Collectors.toList()); |
| | | |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setId(Convert.toLong(id)); |
| | | ModelNode nd = modelNodeAndVnodeList.stream().filter(item -> |
| | | id.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | subNode.setName(nd.getName()); |
| | | subNode.setNodeType(nd.getNodeType()); |
| | | subNode.setPicId(nd.getPicId()); |
| | | |
| | | if (!"vnode".equals(nd.getNodeType())) { |
| | | subNode.setMyWidth(nd.getWidth()); |
| | | subNode.setMyHeight(nd.getHeight()); |
| | | } |
| | | subNode.setBlockWidthNum(nd.getVnodeCellNumX()); |
| | | subNode.setBlockHeightNum(nd.getVnodeCellNumY()); |
| | | subNode.setPairStartNodeId(nd.getPairStartNodeId()); |
| | | subNode.setPairEndNodeId(nd.getPairEndNodeId()); |
| | | if (algos.size() > 0) { |
| | | Algorithm algo = algos.get(0); |
| | | subNode.setAlgorithmType(algo.getAlgorithmType()); |
| | | String str = algo.getComputerList(); |
| | | String[] ids = str.split(","); |
| | | for (String subId : ids) { |
| | | subNode.getChildren().add(listToTree(subId, algorithmList, modelNodeAndVnodeList)); |
| | | } |
| | | } |
| | | return subNode; |
| | | } |
| | | |
| | | /* |
| | | */ |
| | | |
| | | /** |
| | | * 根据顶层RBD的位置(x,y),自顶向下递归计算各个节点的位置(x,y) |
| | | * |
| | | * @param modelRbd |
| | | * @param algorithmList |
| | | * @param modelNodeAndVnodeList |
| | | *//* |
| | | |
| | | private void calcLayoutPosition(ModelRbd modelRbd, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | String rbdsonStr = modelRbd.getContent(); |
| | | JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells"); |
| | | Algorithm endAlgo = algorithmList.stream().filter(item -> |
| | | "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0); |
| | | ModelNode topNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm topAlgo = algorithmList.stream().filter(item -> |
| | | endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | // 将topNode的坐标定为Cell(0,0),反算所有节点的坐标 |
| | | // 1. 计算节点的Cell位置 |
| | | calcNodeLayoutPositionCell(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo, 0, 0, |
| | | topNode.getVnodeCellNumX(), topNode.getVnodeCellNumY()); |
| | | // 2. 计算节点的x,y坐标位置 |
| | | calcNodeLayoutPosition(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo); |
| | | // 3. 设置start的位置 |
| | | double distance = 200.0; |
| | | double y = (topNode.getPositionCellY() + topNode.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_START_END_SIZE_Y) / 2; |
| | | setRbdNodePosition(rbdJsonArray, "10000", 0 - distance, y); |
| | | // 4. 设置end的位置 |
| | | double x = topNode.getVnodeCellNumX() * LAYOUT_CELL_SIZE_X + distance - LAYOUT_START_END_SIZE_X; |
| | | setRbdNodePosition(rbdJsonArray, "20000", x, y); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("cells", rbdJsonArray); |
| | | modelRbd.setContent(jsonObject.toString()); |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | // 递归函数(计算各节点的x,y坐标位置) |
| | | private void calcNodeLayoutPosition(JSONArray rbdJsonArray, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo) { |
| | | // 未使用设备的实际宽、高 |
| | | double x; |
| | | double y; |
| | | if ("node".equals(node.getNodeType())) { |
| | | x = node.getPositionCellX() * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_DEVICE_NODE_SIZE_X) / 2; |
| | | y = node.getPositionCellY() * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_DEVICE_NODE_SIZE_Y) / 2; |
| | | node.setPositionX(x); |
| | | node.setPositionY(y); |
| | | setRbdNodePosition(rbdJsonArray, node.getPicId(), node.getPositionX(), node.getPositionY()); |
| | | } else if ("vnode".equals(node.getNodeType())) { |
| | | String[] computerNodeListStr = algo.getComputerList().split(","); |
| | | switch (algo.getAlgorithmType()) { |
| | | case OPE_TYPE_SERIES: |
| | | case OPE_TYPE_PARALLEL: |
| | | case OPE_TYPE_SWITCH: |
| | | case OPE_TYPE_VOTE: |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | List<Algorithm> childAlgos = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId())).collect(Collectors.toList()); |
| | | Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null; |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo); |
| | | } |
| | | if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) { |
| | | // 设置connect的位置 |
| | | x = node.getPositionCellX() * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_CONNECT_SIZE_X) / 2; |
| | | y = (node.getPositionCellY() + node.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_CONNECT_SIZE_Y) / 2; |
| | | setRbdNodePosition(rbdJsonArray, node.getPairStartNodeId(), x, y); |
| | | // 设置运算符的位置 |
| | | x = (node.getPositionCellX() + node.getVnodeCellNumX() - 1) * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_OPE_NODE_SIZE_X) / 2; |
| | | y = (node.getPositionCellY() + node.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_OPE_NODE_SIZE_Y) / 2; |
| | | setRbdNodePosition(rbdJsonArray, node.getPicId(), x, y); |
| | | } |
| | | break; |
| | | case OPE_TYPE_BRIDGE: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 递归函数(计算各节点的Cell位置,以左上角为Cell位置0,0) |
| | | private void calcNodeLayoutPositionCell(JSONArray rbdJsonArray, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo, |
| | | double originCellX, |
| | | double originCellY, |
| | | double maxX, |
| | | double maxY) { |
| | | if ("node".equals(node.getNodeType())) { |
| | | //设置node(设备节点)Cell位置 |
| | | double width = LAYOUT_DEVICE_NODE_SIZE_X * maxX; |
| | | double hight = LAYOUT_DEVICE_NODE_SIZE_Y * maxY; |
| | | double x = originCellX + (width - LAYOUT_DEVICE_NODE_SIZE_X) / 2; |
| | | double y = originCellY + (hight - LAYOUT_DEVICE_NODE_SIZE_Y) / 2; |
| | | node.setPositionCellX(x); |
| | | node.setPositionCellY(y); |
| | | } else if ("vnode".equals(node.getNodeType())) { |
| | | String[] computerNodeListStr = algo.getComputerList().split(","); |
| | | switch (algo.getAlgorithmType()) { |
| | | case OPE_TYPE_SERIES: |
| | | case OPE_TYPE_PARALLEL: |
| | | case OPE_TYPE_SWITCH: |
| | | case OPE_TYPE_VOTE: |
| | | double preNodeCellX = 0.0; |
| | | double preNodeCellY = 0.0; |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | List<Algorithm> childAlgos = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId())).collect(Collectors.toList()); |
| | | Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null; |
| | | if (OPE_TYPE_SERIES.equals(algo.getAlgorithmType())) { |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo, |
| | | originCellX + preNodeCellX, |
| | | originCellY, node.getVnodeCellNumX(), node.getVnodeCellNumY() |
| | | ); |
| | | preNodeCellX += childNode.getVnodeCellNumX(); |
| | | } else { |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo, |
| | | originCellX + 1, |
| | | originCellY + preNodeCellY, node.getVnodeCellNumX(), node.getVnodeCellNumY()); |
| | | preNodeCellY += childNode.getVnodeCellNumY(); |
| | | } |
| | | } |
| | | */ |
| | | /* |
| | | // 设置运算符的Cell位置 |
| | | if (OPE_TYPE_SERIES.equals(algo.getAlgorithmType())) { |
| | | node.setPositionCellX(originCellX); |
| | | } else { |
| | | node.setPositionCellX(originCellX + node.getVnodeCellNumX() - 1); |
| | | } |
| | | node.setPositionCellY(originCellY + node.getVnodeCellNumY()/2); |
| | | *//* |
| | | |
| | | // 需节点代表整个逻辑单元,因此其坐标为originCellX和originCellX |
| | | node.setPositionCellX(originCellX); |
| | | node.setPositionCellY(originCellX); |
| | | break; |
| | | case OPE_TYPE_BRIDGE: |
| | | */ |
| | | /* |
| | | ModelNode node1 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[0].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node2 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[1].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node3 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[2].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node4 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[3].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node5 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[4].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm algo1 = algorithmList.stream().filter(item -> |
| | | node1.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm algo2 = algorithmList.stream().filter(item -> |
| | | node2.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm algo3 = algorithmList.stream().filter(item -> |
| | | node3.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm algo4 = algorithmList.stream().filter(item -> |
| | | node4.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm algo5 = algorithmList.stream().filter(item -> |
| | | node5.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | // 1,计算三行的总高度 |
| | | // 1.1 计算第一行两个节点的高度 |
| | | int firstRowCellNumY = Math.max(node1.getVnodeCellNumY(), node2.getVnodeCellNumY()); |
| | | // 1.2 计算第二行桥联节点的高度 |
| | | int secondRowCellNumY = node3.getVnodeCellNumY(); |
| | | // 1.3 计算第三行两个节点的高度 |
| | | int thirdRowCellNumY = Math.max(node4.getVnodeCellNumY(), node5.getVnodeCellNumY()); |
| | | // int totalCellNumY = firstRowCellNumY + secondRowCellNumY + thirdRowCellNumY; |
| | | // 2. 计算三行各节点的坐标 |
| | | // 2.1 计算第一行两个节点的坐标 |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node1, |
| | | algo1, |
| | | originCellX + 1, |
| | | originCellY); |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node2, |
| | | algo2, |
| | | originCellX + 1 + node1.getPositionCellX(), |
| | | originCellY); |
| | | // 2.2 计算第二行桥联节点的坐标 |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node3, |
| | | algo3, |
| | | originCellX + 1, |
| | | originCellY + firstRowCellNumY); |
| | | // 2.3 计算第三行两个节点的坐标 |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node4, |
| | | algo4, |
| | | originCellX + 1, |
| | | originCellY + firstRowCellNumY + secondRowCellNumY); |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node5, |
| | | algo5, |
| | | originCellX + 1 + node4.getPositionCellX(), |
| | | originCellY + firstRowCellNumY + secondRowCellNumY); |
| | | // 2.4 计算桥联运算符的坐标 |
| | | node.setPositionCellX(originCellX + 1); |
| | | node.setPositionCellY(originCellY + node.getVnodeCellNumY()/2); |
| | | *//* |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | private void setRbdNodePosition(JSONArray rbdJsonArray, |
| | | String id, |
| | | double x, |
| | |
| | | } |
| | | } |
| | | |
| | | private Double getRbdNodeInfo(JSONArray rbdJsonArray, |
| | | String picId, |
| | | String path) { |
| | | for (int i = 0; i < rbdJsonArray.size(); i++) { |
| | | private void setEdgeRouter(JSONArray rbdJsonArray, Map<String, RbdTreeNode> nodeMap) { |
| | | for (int i = 0; i < rbdJsonArray.size(); i++ |
| | | ) { |
| | | JSONObject jsonObject = rbdJsonArray.getJSONObject(i); |
| | | if (picId.equals(jsonObject.get("id").toString())) { |
| | | return Convert.toDouble(JsonUtils2.getJsonValueByPath(jsonObject, path.split("/"))); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 自底向上递归合计出整个RBD的大小(横向及纵向所占单元格的数量) |
| | | * |
| | | * @param modelRbd |
| | | * @param algorithmList |
| | | * @param modelNodeAndVnodeList |
| | | */ |
| | | private void calcLayoutSize( |
| | | ModelRbd modelRbd, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | Algorithm endAlgo = algorithmList.stream().filter(item -> |
| | | "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0); |
| | | ModelNode topNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm topAlgo = algorithmList.stream().filter(item -> |
| | | endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | calcNodeLayoutSize(algorithmList, modelNodeAndVnodeList, topNode, topAlgo); |
| | | } |
| | | |
| | | // 递归函数 |
| | | private void calcNodeLayoutSize(List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo) { |
| | | if ("node".equals(node.getNodeType())) { |
| | | //设置node(设备节点)布局信息 |
| | | // node.setWidth(LAYOUT_DEVICE_NODE_SIZE_X); |
| | | // node.setHeight(LAYOUT_DEVICE_NODE_SIZE_Y); |
| | | node.setCellNumX(LAYOUT_CELL_NUM_NODE_X); |
| | | node.setCellNumY(LAYOUT_CELL_NUM_NODE_Y); |
| | | node.setVnodeCellNumX(node.getCellNumX()); |
| | | node.setVnodeCellNumY(node.getCellNumY()); |
| | | } else if ("vnode".equals(node.getNodeType())) { |
| | | // 1. 设置vnode(运算节点)布局信息(其实串联没有运算符,不需要设置,但是设置了也没有坏处,所以不作区分) |
| | | // node.setWidth(LAYOUT_OPE_NODE_SIZE_X); |
| | | // node.setHeight(LAYOUT_OPE_NODE_SIZE_Y); |
| | | node.setCellNumX(LAYOUT_CELL_NUM_NODE_X); |
| | | node.setCellNumY(LAYOUT_CELL_NUM_NODE_Y); |
| | | |
| | | // 2. 设置虚节点布局信息 |
| | | // 2.1 设置虚节点内各运算对象的布局信息 |
| | | String[] computerNodeListStr = algo.getComputerList().split(","); |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | List<Algorithm> childAlgos = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId())).collect(Collectors.toList()); |
| | | Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null; |
| | | calcNodeLayoutSize(algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo); |
| | | } |
| | | // 2.2 设置虚节点总的布局信息到运算节点中 |
| | | setVnodeLayoutNum(computerNodeListStr, modelNodeAndVnodeList, node, algo); |
| | | } |
| | | } |
| | | |
| | | private void setVnodeLayoutNum(String[] computerNodeListStr, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode vnode, |
| | | Algorithm algo) { |
| | | int numX = 0; |
| | | int numY = 0; |
| | | // 1. 计算串、并、旁联、表决 |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | switch (algo.getAlgorithmType()) { |
| | | case OPE_TYPE_SERIES: |
| | | numX += childNode.getVnodeCellNumX(); |
| | | numY = childNode.getVnodeCellNumY() > numY ? childNode.getVnodeCellNumY() : numY; |
| | | break; |
| | | case OPE_TYPE_PARALLEL: |
| | | case OPE_TYPE_SWITCH: |
| | | case OPE_TYPE_VOTE: |
| | | numX = childNode.getVnodeCellNumX() > numX ? childNode.getVnodeCellNumX() : numX; |
| | | numY += childNode.getVnodeCellNumY(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) { |
| | | // 加上connect的大小 |
| | | numX += LAYOUT_CELL_NUM_CONNECT_X; |
| | | numX += vnode.getCellNumX(); |
| | | } |
| | | // 2. 计算桥联 |
| | | if (OPE_TYPE_BRIDGE.equals(algo.getAlgorithmType())) { |
| | | // 桥联支路算一行,整个桥联共3行 |
| | | // 2.1 计算第一行 |
| | | ModelNode node1 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[0].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node2 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[1].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node3 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[2].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node4 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[3].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node5 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[4].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | int numX1 = node1.getCellNumX() + node2.getCellNumX(); |
| | | int numY1 = node1.getCellNumY() > node2.getCellNumY() ? node1.getCellNumY() : node2.getCellNumY(); |
| | | // 2.2 计算第二行(桥联支路,横向画图) |
| | | int numX2 = node3.getCellNumX(); |
| | | int numY2 = node3.getCellNumY(); |
| | | // 2.3 计算第三行 |
| | | int numX3 = node4.getCellNumX() + node5.getCellNumX(); |
| | | int numY3 = node4.getCellNumY() > node5.getCellNumY() ? node4.getCellNumY() : node5.getCellNumY(); |
| | | numX = Math.max(Math.max(numX1, numX2), numX3); |
| | | numY = numY1 + numY2 + numY3; |
| | | // 2.4 加上connect的大小 |
| | | numX += LAYOUT_CELL_NUM_CONNECT_X; |
| | | numX += vnode.getCellNumX(); |
| | | } |
| | | vnode.setVnodeCellNumX(numX); |
| | | vnode.setVnodeCellNumY(numY); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean analyze(ModelRbd modelRbd) { |
| | | boolean result = true; |
| | | if (modelRbd == null) return result; |
| | | Long modelId = modelRbd.getId(); |
| | | result = analyzeRbd(modelRbd, true); |
| | | return result; |
| | | } |
| | | |
| | | private boolean analyzeRbd(ModelRbd modelRbd, boolean saveFlag) { |
| | | boolean result = true; |
| | | String rbdsonStr = modelRbd.getContent(); |
| | | |
| | | JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells"); |
| | | if (rbdJsonArray == null) return result; |
| | | |
| | | // 解析结果存放list |
| | | List<ModelNode> modelNodeList = new ArrayList<>(); |
| | | List<ModelLine> modelLineList = new ArrayList<>(); |
| | | List<Algorithm> algorithmList = new ArrayList<>(); |
| | | List<ProductImg> productImgList = new ArrayList<>(); // 暂不使用(而使用数据库中的可靠性参数) |
| | | |
| | | // 1. 解析出节点与边 |
| | | getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList); |
| | | // 2. 对于有多根入口线的产品节点,将其上的表决、旁联关系剥离成运算符节点,添加到该节点的前面,并添加相应的边 |
| | | peelOperationFromProductNode(modelRbd.getId(), modelNodeList, modelLineList); |
| | | // 3. 计算所有节点的入口线数及出口线数 |
| | | calcInOutLineNumAllNode(modelNodeList, modelLineList); |
| | | // 4. 复制产品节点(node)到list |
| | | List<ModelNode> modelNodeAndVnodeList = modelNodeList.stream().filter(item -> |
| | | "node".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | // 5. 不断将基本模型(串联、并联、旁联、表决、桥联)替换为虚节点而简化图形,直至无法简化为止。 |
| | | result = getAlgorithmFromRbd(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | // 6. 转换为算法库接口XML |
| | | if (result) { |
| | | // result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | } |
| | | |
| | | // 7. 保存模型 |
| | | if (saveFlag) saveModel(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void peelOperationFromProductNode(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | List<ModelNode> nodesToAdd = new ArrayList<>(); |
| | | List<ModelLine> linesToAdd = new ArrayList<>(); |
| | | for (ModelNode node : modelNodeList) { |
| | | List<ModelLine> inLineList = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()); |
| | | if ("node".equals(node.getNodeType()) && |
| | | StringUtils.isNotBlank(node.getNodeTypeExt()) && |
| | | inLineList.size() > 1) { |
| | | // 旁联or表决 |
| | | ModelNode nodeNew = new ModelNode(); |
| | | Long nodeNewId = UUIDUtil.generateId(); |
| | | nodeNew.setId(nodeNewId); |
| | | nodeNew.setPicId(nodeNewId.toString()); |
| | | nodeNew.setModelId(modelId); |
| | | nodeNew.setNodeType(node.getNodeTypeExt()); |
| | | nodeNew.setName(node.getNodeTypeExt()); |
| | | nodeNew.setVoteNum(node.getVoteNum()); |
| | | nodeNew.setPositionX(node.getPositionX()); |
| | | nodeNew.setPositionY(node.getPositionY()); |
| | | nodesToAdd.add(nodeNew); |
| | | |
| | | ModelLine lineNew = new ModelLine(); |
| | | Long lineNewId = UUIDUtil.generateId(); |
| | | lineNew.setId(lineNewId); |
| | | lineNew.setPicId(lineNewId.toString()); |
| | | lineNew.setModelId(modelId); |
| | | lineNew.setBeginCell(nodeNewId.toString()); |
| | | lineNew.setEndCell(node.getPicId()); |
| | | linesToAdd.add(lineNew); |
| | | |
| | | for (ModelLine line : inLineList) { |
| | | line.setEndCell(nodeNewId.toString()); |
| | | } |
| | | } |
| | | } |
| | | modelNodeList.addAll(nodesToAdd); |
| | | modelLineList.addAll(linesToAdd); |
| | | } |
| | | |
| | | private boolean getAlgorithmFromRbd(ModelRbd modelRbd, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | // 根据以下的构图规则来进行算法分解: |
| | | // 1、节点的定义 |
| | | // 1-1) 运算节点:共2个:旁联、表决,且运算节点需放在被运算节点的右侧。 |
| | | // 1-2) 产品节点:产品模型中的节点 |
| | | // 1-3) 连接节点:共3个:start、end、connect |
| | | // 1-4) 虚节点:代替基本模型,构图规则上等效于产品节点 |
| | | // 2、基本模型的定义 |
| | | // 2-1) 串联:没有专门的表示符号,由节点间的连接关系定义。2个及以上的节点(产品节点或虚节点)只构成1条路径,终端节点只有1个出口(入口个数无限制)。 |
| | | // 2-2) 并联:没有专门的表示符号,由节点间的连接关系定义。2个及以上的节点(产品节点或虚节点)都只有1个入口和出口,且这些节点拥有同一个入口节点和同一个出口节点。 |
| | | // 2-3) 旁联:由专门的旁联运算符表示,每条旁联支路只有1个节点(产品节点或虚节点),这些节点都以该旁联节点为出口节点,且这些节点拥有同一个入口节点。 |
| | | // 2-4) 表决:由专门的表决运算符表示,每条表决支路只有1个节点(产品节点或虚节点),这些节点都以该表决节点为出口节点,且这些节点拥有同一个入口节点。 |
| | | // 2-5) 桥联:没有专门的表示符号,由节点间的连接关系定义。 |
| | | // 3、根据以上基本模型的定义,不断将基本模型简化为虚节点,直至简化完毕,或者无法简化为止。 |
| | | boolean isEnd = false; // 图形简化完毕(全部简化没了) |
| | | boolean hasSimplified = false; // 至少简化了一处图形 |
| | | do { |
| | | hasSimplified = false; |
| | | hasSimplified = simplifySeries(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified); |
| | | // hasSimplified = simplifyParallel(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified); |
| | | hasSimplified = simplifyOperator("parallel", modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified); |
| | | hasSimplified = simplifyOperator("switch", modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified); |
| | | hasSimplified = simplifyOperator("vote", modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified); |
| | | hasSimplified = simplifyBridge(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified); |
| | | isEnd = simplifyEnd(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList); |
| | | } while (!isEnd && hasSimplified); |
| | | |
| | | return isEnd; |
| | | } |
| | | |
| | | private boolean simplifyEnd(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | ModelNode endNode = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | if (endNode.getInLineNum() != 1) return false; |
| | | |
| | | ModelLine lineToEnd = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(endNode.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | lineToEnd.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node.getInLineNum() != 1 || node.getOutLineNum() != 1) return false; |
| | | |
| | | ModelLine lineToNode = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode startNode = modelNodeList.stream().filter(item -> |
| | | lineToNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!"start".equals(startNode.getNodeType()) || startNode.getOutLineNum() != 1) return false; |
| | | |
| | | // 删除节点及连线 |
| | | modelLineList.remove(lineToEnd); |
| | | modelLineList.remove(lineToNode); |
| | | modelNodeList.remove(endNode); |
| | | modelNodeList.remove(node); |
| | | modelNodeList.remove(startNode); |
| | | |
| | | // 生成结束的算法步骤 |
| | | // 新增algorithm |
| | | Algorithm algorithm = new Algorithm(); |
| | | Long id = UUIDUtil.generateId(); |
| | | algorithm.setId(id); |
| | | algorithm.setModelId(modelId); |
| | | algorithm.setComputerId(id); |
| | | algorithm.setModelType(endNode.getNodeType()); |
| | | algorithm.setAlgorithmType(endNode.getNodeType()); |
| | | algorithm.setComputerList(node.getId().toString()); |
| | | algorithm.setObjectList(node.getName()); |
| | | algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1); |
| | | algorithmList.add(algorithm); |
| | | |
| | | // 新增结束的虚节点 |
| | | ModelNode vnode = new ModelNode(); |
| | | vnode.setId(id); |
| | | vnode.setPicId(id.toString()); |
| | | vnode.setModelId(modelId); |
| | | vnode.setNodeType("vnode"); |
| | | vnode.setName("v" + algorithm.getStep()); |
| | | modelNodeAndVnodeList.add(vnode); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private boolean simplifySeries(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | boolean hasSimplified) { |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode startNode : startNodes) { |
| | | if (startNode.getInLineNum() != 1) continue; |
| | | |
| | | List<ModelNode> result = new ArrayList<>(); |
| | | if (!"end".equals(startNode.getNodeType())) result.add(startNode); |
| | | seekPathSeries(modelNodeList, modelLineList, startNode, result); |
| | | if (result.size() < 2) continue; |
| | | |
| | | ModelNode endNode = result.get(result.size() - 1); |
| | | if ("start,parallel,switch,vote,bridge".contains(endNode.getNodeType()) || endNode.getOutLineNum() != 1) { |
| | | result.remove(endNode); |
| | | } |
| | | List<ModelNode> realSeriesNodes = result.stream().filter(item -> |
| | | !"connect".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (realSeriesNodes.size() < 1) { |
| | | if (result.size() < 2) continue; |
| | | // 替换成连线 |
| | | replaceToLineSeries(modelNodeList, modelLineList, result); |
| | | } else if (realSeriesNodes.size() == 1) { |
| | | if (result.size() < 2) continue; // path上只有该产品节点(node/vnode)自己,无需做什么 |
| | | // 将path替换成该节点 |
| | | replaceToTheNodeSeries(modelNodeList, modelLineList, |
| | | result, realSeriesNodes.get(0)); |
| | | } else { |
| | | // 将path替换成虚节点 |
| | | replaceToVnodeSeries(modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, result, realSeriesNodes); |
| | | } |
| | | hasSimplified = true; |
| | | } |
| | | |
| | | return hasSimplified; |
| | | } |
| | | |
| | | private void replaceToLineSeries(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<ModelNode> path) { |
| | | // 获取path的起点的出口线 |
| | | ModelNode finalNodeStart = path.get(0); |
| | | ModelNode finalNodeEnd = path.get(path.size() - 1); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNodeStart.getPicId())).collect(Collectors.toList()); |
| | | |
| | | // 删除path上的所有中间连线及path的结束点以外的节点 |
| | | for (int i = 0; i < path.size(); i++) { |
| | | ModelNode finalNode = path.get(i); |
| | | if (i < path.size() - 1) { |
| | | // 将入口线删除 |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(lines); |
| | | // 删除节点 |
| | | modelNodeList.remove(finalNode); |
| | | calcInOutLineNum(finalNode, modelLineList); |
| | | } |
| | | } |
| | | |
| | | // 将path的起点的出口线改为连接到path的结束点 |
| | | for (ModelLine line : outLines) { |
| | | line.setBeginCell(finalNodeEnd.getPicId()); |
| | | } |
| | | |
| | | calcInOutLineNum(finalNodeStart, modelLineList); |
| | | calcInOutLineNum(finalNodeEnd, modelLineList); |
| | | } |
| | | |
| | | private void replaceToTheNodeSeries(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<ModelNode> path, |
| | | ModelNode theNode) { |
| | | // 获取path的起点的出口线 |
| | | ModelNode finalNodeStart = path.get(0); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNodeStart.getPicId())).collect(Collectors.toList()); |
| | | // 获取path的结束点的入口线 |
| | | ModelNode finalNodeEnd = path.get(path.size() - 1); |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNodeEnd.getPicId())).collect(Collectors.toList()); |
| | | |
| | | // 删除path上的所有中间连线及theNode以外的节点 |
| | | for (int i = 0; i < path.size(); i++) { |
| | | ModelNode finalNode = path.get(i); |
| | | if (i < path.size() - 1) { |
| | | // 将入口线删除 |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(lines); |
| | | } |
| | | if (!finalNode.getId().equals(theNode.getId())) { |
| | | modelNodeList.remove(finalNode); |
| | | calcInOutLineNum(finalNode, modelLineList); |
| | | } |
| | | } |
| | | |
| | | // 将path的起点的出口线改为连接到theNode |
| | | for (ModelLine line : outLines) { |
| | | line.setBeginCell(theNode.getPicId()); |
| | | } |
| | | // 将path的结束点的入口线改为连接到theNode |
| | | for (ModelLine line : inLines) { |
| | | line.setEndCell(theNode.getPicId()); |
| | | } |
| | | |
| | | calcInOutLineNum(finalNodeStart, modelLineList); |
| | | calcInOutLineNum(finalNodeEnd, modelLineList); |
| | | calcInOutLineNum(theNode, modelLineList); |
| | | } |
| | | |
| | | private void replaceToVnodeSeries(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | List<ModelNode> path, |
| | | List<ModelNode> seriesNodes) { |
| | | // 新增algorithm |
| | | List<String> computerList = createVnodeComputerList("series", algorithmList, modelNodeAndVnodeList, seriesNodes); |
| | | Algorithm algorithm = new Algorithm(); |
| | | Long id = UUIDUtil.generateId(); |
| | | algorithm.setId(id); |
| | | algorithm.setModelId(modelId); |
| | | algorithm.setComputerId(id); |
| | | algorithm.setModelType("series"); |
| | | algorithm.setAlgorithmType("series"); |
| | | algorithm.setComputerList(computerList.get(0)); |
| | | algorithm.setObjectList(computerList.get(1)); |
| | | algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1); |
| | | algorithmList.add(algorithm); |
| | | |
| | | // 新增虚节点 |
| | | ModelNode vnode = new ModelNode(); |
| | | vnode.setId(id); |
| | | vnode.setPicId(id.toString()); |
| | | vnode.setModelId(modelId); |
| | | vnode.setNodeType("vnode"); |
| | | vnode.setName("v" + algorithm.getStep()); |
| | | vnode.setPositionX(path.get(0).getPositionX()); |
| | | vnode.setPositionY(path.get(0).getPositionY()); |
| | | modelNodeList.add(vnode); |
| | | modelNodeAndVnodeList.add(vnode); |
| | | |
| | | // 将path替换为该虚节点 |
| | | for (int i = 0; i < path.size(); i++) { |
| | | ModelNode finalNode = path.get(i); |
| | | if (i == 0) { |
| | | // 将该节点的出口线改为连接到虚节点 |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | for (ModelLine line : outLines) { |
| | | line.setBeginCell(vnode.getPicId()); |
| | | } |
| | | // 将该节点的入口线删除 |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(inLines); |
| | | } |
| | | if (i == path.size() - 1) { |
| | | // 将该节点的入口线改为连接到虚节点 |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | for (ModelLine line : inLines) { |
| | | line.setEndCell(vnode.getPicId()); |
| | | } |
| | | // 将该节点的出口线删除 |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(outLines); |
| | | } |
| | | // 删除该节点的出入口线 |
| | | List<ModelLine> inOutLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId()) || item.getBeginCell().equals(finalNode.getPicId()) |
| | | ).collect(Collectors.toList()); |
| | | modelLineList.removeAll(inOutLines); |
| | | // 删除该节点 |
| | | modelNodeList.remove(finalNode); |
| | | calcInOutLineNum(finalNode, modelLineList); |
| | | } |
| | | |
| | | calcInOutLineNum(vnode, modelLineList); |
| | | } |
| | | |
| | | private List<String> createVnodeComputerList(String type, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | List<ModelNode> nodes) { |
| | | // 调整节点顺序 |
| | | List<ModelNode> sortedNodes = null; |
| | | if ("bridge".equals(type)) { |
| | | if (nodes.get(1).getPositionY() < nodes.get(4).getPositionY()) { |
| | | sortedNodes = nodes; |
| | | } else { |
| | | sortedNodes = new ArrayList<>(); |
| | | sortedNodes.add(nodes.get(3)); |
| | | sortedNodes.add(nodes.get(4)); |
| | | sortedNodes.add(nodes.get(2)); |
| | | sortedNodes.add(nodes.get(0)); |
| | | sortedNodes.add(nodes.get(1)); |
| | | } |
| | | } else if ("parallel".equals(type)) { |
| | | // 把虚节点内部的并联节点全部拿出来,进行大排序 |
| | | sortedNodes = new ArrayList<>(); |
| | | for (ModelNode node : nodes) { |
| | | if ("node".equals(node.getNodeType())) { |
| | | sortedNodes.add(node); |
| | | } else { |
| | | // vnode |
| | | Algorithm algorithm = algorithmList.stream().filter(item -> |
| | | item.getId().equals(node.getId())).collect(Collectors.toList()).get(0); |
| | | if (type.equals(algorithm.getAlgorithmType())) { |
| | | String[] pNodesStrArr = algorithm.getComputerList().split(","); |
| | | for (String pNodeStr : pNodesStrArr) { |
| | | sortedNodes.add(modelNodeAndVnodeList.stream().filter(item -> |
| | | pNodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0)); |
| | | if (jsonObject.get("shape").equals("edge")) { |
| | | String sourceId = JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString(); |
| | | String targetId = JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString(); |
| | | RbdTreeNode sourceNode = nodeMap.get(sourceId); |
| | | RbdTreeNode targetNode = nodeMap.get(targetId); |
| | | if (sourceNode != null) { |
| | | if ("connect".equals(sourceNode.getNodeType()) && !"10000".equals(sourceId)) { |
| | | if (sourceNode.getY() + sourceNode.getObjectHeight() / 2 == targetNode.getY() + targetNode.getObjectHeight() / 2) { |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"), "right".split(",")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"), "left".split(",")); |
| | | } else { |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"), "top,bottom".split(",")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"), "left".split(",")); |
| | | } |
| | | algorithmList.remove(algorithm); |
| | | modelNodeAndVnodeList.remove(node); |
| | | } else { |
| | | sortedNodes.add(node); |
| | | } |
| | | } |
| | | } |
| | | sortedNodes.sort(Comparator.comparing(ModelNode::getPositionY)); |
| | | } else { |
| | | sortedNodes = Arrays.asList(new ModelNode[nodes.size()]); |
| | | Collections.copy(sortedNodes, nodes); |
| | | if ("series".equals(type)) { |
| | | Collections.reverse(sortedNodes); |
| | | } else { |
| | | sortedNodes.sort(Comparator.comparing(ModelNode::getPositionY)); |
| | | } |
| | | } |
| | | |
| | | String computerIdList = ""; |
| | | String objectList = ""; |
| | | if ("parallel".equals(type)) { |
| | | for (ModelNode node : sortedNodes) { |
| | | objectList += "".equals(objectList) ? node.getName() : "," + node.getName(); |
| | | computerIdList += "".equals(computerIdList) ? node.getId().toString() : "," + node.getId().toString(); |
| | | } |
| | | } else { |
| | | for (ModelNode node : sortedNodes) { |
| | | if ("node".equals(node.getNodeType())) { |
| | | objectList += "".equals(objectList) ? node.getName() : "," + node.getName(); |
| | | computerIdList += "".equals(computerIdList) ? node.getId().toString() : "," + node.getId().toString(); |
| | | } else { |
| | | // vnode |
| | | Algorithm algorithm = algorithmList.stream().filter(item -> |
| | | item.getId().equals(node.getId())).collect(Collectors.toList()).get(0); |
| | | if ("series".equals(type) && type.equals(algorithm.getAlgorithmType())) { |
| | | objectList += "".equals(objectList) ? algorithm.getObjectList() : "," + algorithm.getObjectList(); |
| | | computerIdList += "".equals(computerIdList) ? algorithm.getComputerList() : "," + algorithm.getComputerList(); |
| | | algorithmList.remove(algorithm); |
| | | modelNodeAndVnodeList.remove(node); |
| | | } else { |
| | | objectList += "".equals(objectList) ? node.getName() : "," + node.getName(); |
| | | computerIdList += "".equals(computerIdList) ? node.getId().toString() : "," + node.getId().toString(); |
| | | if (targetNode != null) { |
| | | if ("parallel,vote,switch,bridge".contains(targetNode.getNodeType())) { |
| | | if (sourceNode.getY() + sourceNode.getObjectHeight() / 2 == targetNode.getY() + targetNode.getObjectHeight() / 2) { |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"), "right".split("")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"), "left".split("")); |
| | | } else { |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"), "right".split("")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"), "top,bottom".split("")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<String> result = new ArrayList<>(); |
| | | result.add(computerIdList); |
| | | result.add(objectList); |
| | | return result; |
| | | } |
| | | |
| | | private void seekPathSeries(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | ModelNode startNode, |
| | | List<ModelNode> result) { |
| | | ModelLine inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (isBridgeUpperLine(inLine, modelLineList) || isBridgeLowerLine(inLine, modelLineList)) return; |
| | | List<ModelNode> nodes = modelNodeList.stream().filter(item -> |
| | | inLine.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()); |
| | | if (0 == nodes.size()) return; // 到桥联中间节点的线的起点不是Node,而是Line,所以获取的起点数可能为0 |
| | | ModelNode pathNode = nodes.get(0); |
| | | result.add(pathNode); |
| | | if (pathNode.getOutLineNum() != 1 || pathNode.getInLineNum() != 1) return; |
| | | if ("parallel,switch,vote,bridge".contains(pathNode.getNodeType())) return; |
| | | seekPathSeries(modelNodeList, modelLineList, pathNode, result); |
| | | } |
| | | |
| | | private boolean isBridgeUpperLine(ModelLine line, List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | for (ModelLine ln : modelLineList) { |
| | | if (ln.getBeginCell().equals(line.getPicId())) { |
| | | result = true; |
| | | break; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private boolean isBridgeLowerLine(ModelLine line, List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | for (ModelLine ln : modelLineList) { |
| | | if (ln.getEndCell().equals(line.getPicId())) { |
| | | result = true; |
| | | break; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private boolean simplifyParallel(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | boolean hasSimplified) { |
| | | boolean hasSimplifiedMe = false; |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode startNode : startNodes) { |
| | | if (startNode.getInLineNum() < 2) continue; |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()); |
| | | hasSimplifiedMe = simplifyParallelGroup(modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, startNode, inLines); |
| | | if (hasSimplifiedMe) { |
| | | hasSimplified = true; |
| | | } |
| | | } |
| | | |
| | | return hasSimplified; |
| | | } |
| | | |
| | | private boolean simplifyParallelGroup(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode startNode, |
| | | List<ModelLine> lines) { |
| | | boolean hasSimplified = false; |
| | | List<List<ModelNode>> pathList = new ArrayList<>(); |
| | | for (ModelLine line : lines) { |
| | | List<ModelNode> path = getOneBranchParallel(modelNodeList, modelLineList, line); |
| | | if (path.size() > 0) pathList.add(path); |
| | | } |
| | | Map<ModelNode, List<List<ModelNode>>> endNodePathsMap = groupingPathByEndNode(pathList); |
| | | for (Map.Entry<ModelNode, List<List<ModelNode>>> entry : endNodePathsMap.entrySet()) { |
| | | List<List<ModelNode>> pathOneGroup = entry.getValue(); |
| | | if (pathOneGroup.size() > 1) { |
| | | List<ModelNode> branchNodeList = new ArrayList<>(); |
| | | ModelNode endNode = getBranchNodesOneParallel(pathOneGroup, branchNodeList); |
| | | if ("connect".equals(startNode.getNodeType()) && pathOneGroup.size() == lines.size()) { |
| | | // 替换成虚节点 |
| | | modelNodeAndVnodeList.add(startNode); |
| | | replaceToVnode("parallel", modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, startNode, endNode, branchNodeList); |
| | | } else { |
| | | // 新增虚节点 |
| | | ModelNode vnode = new ModelNode(); |
| | | Long id = UUIDUtil.generateId(); |
| | | vnode.setId(id); |
| | | vnode.setPicId(id.toString()); |
| | | vnode.setModelId(modelId); |
| | | vnode.setNodeType("vnode"); |
| | | // 位置设置为并联中第一个节点的位置 |
| | | vnode.setPositionX(branchNodeList.get(0).getPositionX()); |
| | | vnode.setPositionY(branchNodeList.get(0).getPositionY()); |
| | | // vnode.setPositionX(startNode.getPositionX()); |
| | | // vnode.setPositionY(startNode.getPositionY()); |
| | | modelNodeList.add(vnode); |
| | | modelNodeAndVnodeList.add(vnode); |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long picId2 = UUIDUtil.generateId(); |
| | | modelLineNew.setId(picId2); |
| | | modelLineNew.setPicId(picId2.toString()); |
| | | modelLineNew.setModelId(modelId); |
| | | modelLineNew.setBeginCell(vnode.getPicId()); |
| | | modelLineNew.setEndCell(startNode.getPicId()); |
| | | modelLineList.add(modelLineNew); |
| | | replaceToVnode("parallel", modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, vnode, endNode, branchNodeList); |
| | | calcInOutLineNum(startNode, modelLineList); |
| | | } |
| | | hasSimplified = true; |
| | | } |
| | | } |
| | | |
| | | return hasSimplified; |
| | | } |
| | | |
| | | private List<ModelNode> getOneBranchParallel(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | ModelLine line) { |
| | | List<ModelNode> path = new ArrayList<>(); |
| | | ModelNode branchNode = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | if (inLines.size() != 1 || outLines.size() != 1) return path; |
| | | ModelLine lineToBranchNode = inLines.get(0); |
| | | ModelNode endNode = modelNodeList.stream().filter(item -> |
| | | lineToBranchNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | path.add(branchNode); |
| | | path.add(endNode); |
| | | |
| | | return path; |
| | | } |
| | | |
| | | private Map<ModelNode, List<List<ModelNode>>> groupingPathByEndNode(List<List<ModelNode>> pathList) { |
| | | Map<ModelNode, List<List<ModelNode>>> endNodePathsMap = new HashMap<>(); |
| | | for (List<ModelNode> path : pathList) { |
| | | ModelNode endNode = path.get(path.size() - 1); |
| | | if (endNodePathsMap.containsKey(endNode)) { |
| | | endNodePathsMap.get(endNode).add(path); |
| | | } else { |
| | | List<List<ModelNode>> paths = new ArrayList<>(); |
| | | paths.add(path); |
| | | endNodePathsMap.put(endNode, paths); |
| | | } |
| | | } |
| | | return endNodePathsMap; |
| | | } |
| | | |
| | | private ModelNode getBranchNodesOneParallel(List<List<ModelNode>> paths, |
| | | List<ModelNode> branchNodeList) { |
| | | ModelNode endNode = null; |
| | | for (List<ModelNode> path : paths) { |
| | | branchNodeList.add(path.get(0)); |
| | | endNode = path.get(path.size() - 1); |
| | | } |
| | | return endNode; |
| | | } |
| | | |
| | | private boolean simplifyBridge(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | boolean hasSimplified) { |
| | | boolean hasSimplifiedMe = false; |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "bridge".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode startNode : startNodes) { |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()); |
| | | if (lines.size() < 2) continue; |
| | | List<ModelLinePairDto> linePairs = getLinePairs(lines); |
| | | for (ModelLinePairDto linePair : linePairs) { |
| | | hasSimplifiedMe = simplifyBridgeOneLinePair(modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, startNode, linePair); |
| | | if (hasSimplifiedMe) { |
| | | hasSimplified = true; |
| | | break; |
| | | private void calcLayoutSize(RbdTreeNode root) { |
| | | double childrenWidth = 0.0; |
| | | double childrenHeight = 0.0; |
| | | double lineWidth = 80; |
| | | double lineHeight = 80; |
| | | if (!"vnode".equals(root.getNodeType())) { |
| | | root.setBlockWidth(root.getObjectWidth() + lineWidth); |
| | | root.setBlockHeight(root.getObjectHeight() + lineHeight); |
| | | } else { |
| | | for (RbdTreeNode treeNode : root.getChildren()) { |
| | | calcLayoutSize(treeNode); |
| | | if ("series".equals(root.getAlgorithmType())) { |
| | | childrenWidth += treeNode.getBlockWidth(); |
| | | childrenHeight = Math.max(childrenHeight, treeNode.getBlockHeight()); |
| | | } else if ("parallel,switch,vote".contains(root.getAlgorithmType())) { |
| | | childrenWidth = Math.max(childrenWidth, treeNode.getBlockWidth()); |
| | | childrenHeight += treeNode.getBlockHeight(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return hasSimplified; |
| | | } |
| | | |
| | | private boolean simplifyBridgeOneLinePair(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode startNode, |
| | | ModelLinePairDto linePair) { |
| | | ModelNode node1 = null; |
| | | ModelNode node2 = null; |
| | | ModelNode node3 = null; |
| | | ModelNode node4 = null; |
| | | ModelNode node5 = null; |
| | | ModelLine line1To2 = null; |
| | | ModelLine line4To5 = null; |
| | | /* |
| | | ModelNode nodeTmp1 = modelNodeList.stream().filter(item -> |
| | | linePair.getLine1().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode nodeTmp2 = modelNodeList.stream().filter(item -> |
| | | linePair.getLine2().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | calcInOutLineNum(nodeTmp1, modelLineList); |
| | | calcInOutLineNum(nodeTmp2, modelLineList); |
| | | if (nodeTmp1.getOutLineNum()!=1 || nodeTmp2.getOutLineNum()!=1) return false; |
| | | if (nodeTmp1.getInLineNum()<1 || nodeTmp1.getInLineNum()>2) return false; |
| | | if (nodeTmp2.getInLineNum()<1 || nodeTmp2.getInLineNum()>2) return false; |
| | | if ((nodeTmp1.getInLineNum() + nodeTmp2.getInLineNum())!=3) return false; |
| | | if (nodeTmp1.getInLineNum()==1) { |
| | | node2 = nodeTmp1; |
| | | node5 = nodeTmp2; |
| | | } else { |
| | | node2 = nodeTmp2; |
| | | node5 = nodeTmp1; |
| | | } |
| | | ModelNode finalNode = node2; |
| | | ModelLine line1To2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()).get(0); |
| | | node1 = modelNodeList.stream().filter(item -> |
| | | line1To2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node1.getInLineNum()!=1 || node1.getOutLineNum()!=2) return false; |
| | | ModelNode finalNode1 = node1; |
| | | List<ModelLine> outLinesFrom1 = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNode1.getPicId())).collect(Collectors.toList()); |
| | | if (outLinesFrom1.get(0).getEndCell().equals(node2.getPicId())) { |
| | | node3 = modelNodeList.stream().filter(item -> |
| | | outLinesFrom1.get(1).getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | } else { |
| | | node3 = modelNodeList.stream().filter(item -> |
| | | outLinesFrom1.get(0).getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | } |
| | | if (node3.getId().equals(node5.getId())) return false; |
| | | if (node3.getInLineNum()!=1 || node3.getOutLineNum()!=1) return false; |
| | | ModelNode finalNode2 = node3; |
| | | ModelLine outLineFrom3 = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNode2.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!outLineFrom3.getEndCell().equals(node5.getPicId())) return false; |
| | | ModelNode finalNode3 = node5; |
| | | List<ModelLine> inLinesTo5 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode3.getPicId())).collect(Collectors.toList()); |
| | | if (inLinesTo5.get(0).getBeginCell().equals(node3.getPicId())) { |
| | | node4 = modelNodeList.stream().filter(item -> |
| | | inLinesTo5.get(1).getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | } else { |
| | | node4 = modelNodeList.stream().filter(item -> |
| | | inLinesTo5.get(0).getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | } |
| | | if (node4.getId().equals(node1.getId())) return false; |
| | | if (node4.getId().equals(node2.getId())) return false; |
| | | if (node4.getInLineNum()!=1 || node4.getOutLineNum()!=1) return false; |
| | | ModelNode finalNode4 = node1; |
| | | ModelLine lineTo1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode4.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode finalNode5 = node4; |
| | | ModelLine lineTo4 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode5.getPicId())).collect(Collectors.toList()).get(0); |
| | | nodeTmp1 = modelNodeList.stream().filter(item -> |
| | | lineTo1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | nodeTmp2 = modelNodeList.stream().filter(item -> |
| | | lineTo4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!nodeTmp1.getId().equals(nodeTmp2.getId())) return false; |
| | | ModelNode endNode = nodeTmp1; |
| | | */ |
| | | ModelNode nodeTmp1 = modelNodeList.stream().filter(item -> |
| | | linePair.getLine1().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode nodeTmp2 = modelNodeList.stream().filter(item -> |
| | | linePair.getLine2().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (nodeTmp1.getInLineNum() != 1 || nodeTmp1.getOutLineNum() != 1) return false; |
| | | if (nodeTmp2.getInLineNum() != 1 || nodeTmp2.getOutLineNum() != 1) return false; |
| | | ModelNode finalNode = nodeTmp1; |
| | | ModelLine lineToNodeTmp1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode finalNode1 = nodeTmp2; |
| | | ModelLine lineToNodeTmp2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode1.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode nodeTmp3 = modelNodeList.stream().filter(item -> |
| | | lineToNodeTmp1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode nodeTmp4 = modelNodeList.stream().filter(item -> |
| | | lineToNodeTmp2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (nodeTmp3.getId().equals(nodeTmp4.getId())) return false; |
| | | boolean isBridgeUpperLine1 = isBridgeUpperLine(lineToNodeTmp1, modelLineList); |
| | | boolean isBridgeUpperLine2 = isBridgeUpperLine(lineToNodeTmp2, modelLineList); |
| | | if (!isBridgeUpperLine1 && !isBridgeUpperLine2) return false; |
| | | if (isBridgeUpperLine1 && isBridgeUpperLine2) return false; |
| | | boolean isBridgeLowerLine1 = isBridgeLowerLine(lineToNodeTmp1, modelLineList); |
| | | boolean isBridgeLowerLine2 = isBridgeLowerLine(lineToNodeTmp2, modelLineList); |
| | | if (!isBridgeLowerLine1 && !isBridgeLowerLine2) return false; |
| | | if (isBridgeLowerLine1 && isBridgeLowerLine2) return false; |
| | | if (isBridgeUpperLine1) { |
| | | line1To2 = lineToNodeTmp1; |
| | | line4To5 = lineToNodeTmp2; |
| | | node2 = nodeTmp1; |
| | | node5 = nodeTmp2; |
| | | } else { |
| | | line1To2 = lineToNodeTmp2; |
| | | line4To5 = lineToNodeTmp1; |
| | | node2 = nodeTmp2; |
| | | node5 = nodeTmp1; |
| | | } |
| | | ModelLine finalLine = line1To2; |
| | | ModelLine lineTo3 = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalLine.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine finalLine1 = line4To5; |
| | | ModelLine lineFrom3 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalLine1.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine finalLine2 = lineTo3; |
| | | ModelNode node3Candidate1 = modelNodeList.stream().filter(item -> |
| | | finalLine2.getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine finalLine3 = lineFrom3; |
| | | ModelNode node3Candidate2 = modelNodeList.stream().filter(item -> |
| | | finalLine3.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!node3Candidate1.getId().equals(node3Candidate2.getId())) return false; |
| | | node3 = node3Candidate1; |
| | | if (node3.getInLineNum() != 1 || node3.getOutLineNum() != 1) return false; |
| | | ModelLine finalLine4 = line1To2; |
| | | node1 = modelNodeList.stream().filter(item -> |
| | | finalLine4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node1.getInLineNum() != 1 || node1.getOutLineNum() != 1) return false; |
| | | ModelLine finalLine5 = line4To5; |
| | | node4 = modelNodeList.stream().filter(item -> |
| | | finalLine5.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node4.getInLineNum() != 1 || node4.getOutLineNum() != 1) return false; |
| | | ModelNode finalNode3 = node1; |
| | | ModelLine lineTo1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode3.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode finalNode4 = node4; |
| | | ModelLine lineTo4 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode4.getPicId())).collect(Collectors.toList()).get(0); |
| | | nodeTmp1 = modelNodeList.stream().filter(item -> |
| | | lineTo1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | nodeTmp2 = modelNodeList.stream().filter(item -> |
| | | lineTo4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!nodeTmp1.getId().equals(nodeTmp2.getId())) return false; |
| | | ModelNode endNode = nodeTmp1; |
| | | |
| | | List<ModelNode> branchNodeList = new ArrayList<>(); |
| | | branchNodeList.add(node1); |
| | | branchNodeList.add(node2); |
| | | branchNodeList.add(node3); |
| | | branchNodeList.add(node4); |
| | | branchNodeList.add(node5); |
| | | |
| | | modelNodeAndVnodeList.add(startNode); |
| | | replaceToVnode("bridge", modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, startNode, endNode, branchNodeList); |
| | | |
| | | /* |
| | | if ("connect".equals(startNode.getNodeType()) && startNode.getInLineNum()==2) { |
| | | // 替换成虚节点 |
| | | modelNodeAndVnodeList.add(startNode); |
| | | replaceToVnode("bridge", modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, startNode, endNode, branchNodeList); |
| | | } else { |
| | | // 新增虚节点 |
| | | ModelNode vnode = new ModelNode(); |
| | | Long id = UUIDUtil.generateId(); |
| | | vnode.setId(id); |
| | | vnode.setPicId(id.toString()); |
| | | vnode.setModelId(modelId); |
| | | vnode.setNodeType("vnode"); |
| | | // 将位置设置为第一个分支的 |
| | | vnode.setPositionX(node2.getPositionX()); |
| | | vnode.setPositionY(node2.getPositionY()); |
| | | // vnode.setPositionX(startNode.getPositionX()); |
| | | // vnode.setPositionY(startNode.getPositionY()); |
| | | modelNodeList.add(vnode); |
| | | modelNodeAndVnodeList.add(vnode); |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long picId2 = UUIDUtil.generateId(); |
| | | modelLineNew.setId(picId2); |
| | | modelLineNew.setPicId(picId2.toString()); |
| | | modelLineNew.setModelId(modelId); |
| | | modelLineNew.setBeginCell(vnode.getPicId()); |
| | | modelLineNew.setEndCell(startNode.getPicId()); |
| | | modelLineList.add(modelLineNew); |
| | | replaceToVnode("bridge", modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, vnode, endNode, branchNodeList); |
| | | calcInOutLineNum(startNode, modelLineList); |
| | | } |
| | | */ |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private void calcInOutLineNumAllNode(List<ModelNode> modelNodeList, List<ModelLine> modelLineList) { |
| | | for (ModelNode node : modelNodeList) { |
| | | calcInOutLineNum(node, modelLineList); |
| | | } |
| | | } |
| | | |
| | | private void calcInOutLineNum(ModelNode node, List<ModelLine> modelLineList) { |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(node.getPicId())).collect(Collectors.toList()); |
| | | node.setInLineNum(inLines.size()); |
| | | node.setOutLineNum(outLines.size()); |
| | | } |
| | | |
| | | // 找出所有2根线的组合 |
| | | private List<ModelLinePairDto> getLinePairs(List<ModelLine> lines) { |
| | | List<ModelLinePairDto> linePairs = new ArrayList<>(); |
| | | for (int i = 0; i < lines.size() - 1; i++) { |
| | | for (int j = i + 1; j < lines.size(); j++) { |
| | | ModelLinePairDto linePair = new ModelLinePairDto(); |
| | | linePair.setLine1(lines.get(i)); |
| | | linePair.setLine2(lines.get(j)); |
| | | linePairs.add(linePair); |
| | | if ("bridge".equals(root.getAlgorithmType())) { |
| | | childrenWidth = Math.max(root.getChildren().get(0).getBlockWidth() + root.getChildren().get(1).getBlockWidth(), |
| | | root.getChildren().get(2).getBlockWidth()); |
| | | childrenWidth = Math.max(root.getChildren().get(3).getBlockWidth() + root.getChildren().get(4).getBlockWidth(), |
| | | childrenWidth); |
| | | childrenHeight += Math.max(root.getChildren().get(0).getBlockHeight(), root.getChildren().get(1).getBlockHeight()); |
| | | childrenHeight += root.getChildren().get(2).getBlockHeight(); |
| | | childrenHeight += Math.max(root.getChildren().get(3).getBlockHeight(), root.getChildren().get(4).getBlockHeight()); |
| | | } |
| | | root.setObjectWidth(childrenWidth); |
| | | root.setObjectHeight(childrenHeight); |
| | | root.setBlockWidth(childrenWidth); |
| | | root.setBlockHeight(childrenHeight); |
| | | } |
| | | return linePairs; |
| | | } |
| | | |
| | | private boolean simplifyOperator(String operator, |
| | | Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | boolean hasSimplified) { |
| | | List<ModelNode> opNodes = modelNodeList.stream().filter(item -> |
| | | operator.equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (opNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode opNode : opNodes) { |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(opNode.getPicId())).collect(Collectors.toList()); |
| | | boolean thisNodeSuccess = true; |
| | | ModelNode endNode = null; |
| | | List<ModelNode> branchNodeList = new ArrayList<>(); |
| | | for (ModelLine line : lines) { |
| | | ModelNode curEndNode = handleOneBranch(modelNodeList, modelLineList, line, branchNodeList); |
| | | if (curEndNode == null) { |
| | | thisNodeSuccess = false; |
| | | break; |
| | | } |
| | | if (endNode == null) { |
| | | endNode = curEndNode; |
| | | } else { |
| | | if (!endNode.getId().equals(curEndNode.getId())) { |
| | | thisNodeSuccess = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (thisNodeSuccess) { |
| | | modelNodeAndVnodeList.add(opNode); |
| | | replaceToVnode(opNode.getNodeType(), modelId, modelNodeList, modelLineList, |
| | | algorithmList, modelNodeAndVnodeList, opNode, endNode, branchNodeList); |
| | | hasSimplified = true; |
| | | } |
| | | } |
| | | |
| | | return hasSimplified; |
| | | } |
| | | |
| | | private void replaceToVnode(String type, |
| | | Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode startNode, |
| | | ModelNode endNode, |
| | | List<ModelNode> branchNodeList) { |
| | | // 新增algorithm |
| | | List<String> computerList = createVnodeComputerList(type, algorithmList, modelNodeAndVnodeList, branchNodeList); |
| | | Algorithm algorithm = new Algorithm(); |
| | | Long id = UUIDUtil.generateId(); |
| | | algorithm.setId(id); |
| | | algorithm.setModelId(modelId); |
| | | algorithm.setComputerId(id); |
| | | algorithm.setModelType(type); |
| | | algorithm.setAlgorithmType(type); |
| | | algorithm.setComputerList(computerList.get(0)); |
| | | algorithm.setObjectList(computerList.get(1)); |
| | | if ("vote".equals(type)) algorithm.setVoteNum(startNode.getVoteNum()); |
| | | algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1); |
| | | algorithmList.add(algorithm); |
| | | |
| | | // 替换为虚节点 |
| | | for (ModelNode node : branchNodeList) { |
| | | List<ModelLine> branchNodeLineList = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId()) || item.getBeginCell().equals(node.getPicId()) |
| | | ).collect(Collectors.toList()); |
| | | modelLineList.removeAll(branchNodeLineList); |
| | | modelNodeList.remove(node); |
| | | calcInOutLineNum(node, modelLineList); |
| | | } |
| | | startNode.setId(id); |
| | | startNode.setNodeType("vnode"); |
| | | startNode.setName("v" + algorithm.getStep()); |
| | | |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long picId2 = UUIDUtil.generateId(); |
| | | modelLineNew.setId(picId2); |
| | | modelLineNew.setPicId(picId2.toString()); |
| | | modelLineNew.setModelId(modelId); |
| | | modelLineNew.setBeginCell(endNode.getPicId()); |
| | | modelLineNew.setEndCell(startNode.getPicId()); |
| | | modelLineList.add(modelLineNew); |
| | | |
| | | calcInOutLineNum(startNode, modelLineList); |
| | | calcInOutLineNum(endNode, modelLineList); |
| | | } |
| | | |
| | | private ModelNode handleOneBranch(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | ModelLine line, |
| | | List<ModelNode> branchNodeList |
| | | ) { |
| | | ModelNode branchNode = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | if (inLines.size() != 1 || outLines.size() != 1) return null; |
| | | ModelLine lineToBranchNode = inLines.get(0); |
| | | ModelNode endNode = modelNodeList.stream().filter(item -> |
| | | lineToBranchNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | |
| | | branchNodeList.add(branchNode); |
| | | return endNode; |
| | | } |
| | | |
| | | private void getNodeAndLineFromRbd(Long modelId, |
| | |
| | | modelNodeList.add(modelNode); |
| | | } |
| | | } |
| | | // calcLineSortAll(modelNodeList, modelLineList); |
| | | } |
| | | |
| | | /* |
| | | private void calcLineSortAll(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | for (ModelNode node : modelNodeList) { |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()); |
| | | if (inLines.size() < 1) continue; |
| | | for (ModelLine line : inLines) { |
| | | ModelNode beginNode = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | line.setLineSort(beginNode.getPositionY()); |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | private void saveModel(ModelRbd modelRbd, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algoList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | // 删除既有数据 |
| | | modelNodeDao.deleteByModelId(modelRbd.getId()); |
| | | modelLineDao.deleteByModelId(modelRbd.getId()); |
| | | algorithmDao.deleteByModelId(modelRbd.getId()); |
| | | modelNodeAlgorithmDao.deleteByModelId(modelRbd.getId()); |
| | | |
| | | // 插入数据 |
| | | for (ModelNode modelNode : modelNodeList) { |
| | | modelNodeDao.insert(modelNode); |
| | | } |
| | | for (ModelLine modelLine : modelLineList) { |
| | | modelLineDao.insert(modelLine); |
| | | } |
| | | for (Algorithm algorithm : algoList) { |
| | | algorithmDao.insert(algorithm); |
| | | } |
| | |
| | | modelRbdDao.updateById(modelRbd); |
| | | } |
| | | |
| | | /* ============解析模型的第1版,已不使用============ |
| | | private void analyzeRbdAndSave(Long modelId, String content, boolean saveFlag) { |
| | | String diagramJsonStr = content; |
| | | // String diagramJsonStr = "{\"cells\":[{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"26d1a5a6-0be8-4890-86a0-a33d429e6673\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"31585e99-58c7-4a98-8824-8000743b364d\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"f2286e46-84c7-4702-8670-d7cda22c34e5\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"5123ad82-18bb-46fe-9d93-138b24b54a15\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"2ab8b7f8-7fe2-490f-89c5-4250d4a62a78\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"31585e99-58c7-4a98-8824-8000743b364d\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"port\":\"f93ccd2f-dedd-47b1-9ad0-9be20c5db8a4\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"700c05a5-f151-4b28-8135-705ccf013522\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"5123ad82-18bb-46fe-9d93-138b24b54a15\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"port\":\"f93ccd2f-dedd-47b1-9ad0-9be20c5db8a4\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"feef2a57-3c72-4d69-92a6-c828c736b61a\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"port\":\"80d3bd61-1ed3-493a-b4e8-d4576e6fbfda\"},\"target\":{\"cell\":\"da634b2e-5ffc-4e1b-a636-f86ace9eb082\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"49e36d6f-6a94-4edc-9894-6dd825091706\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"2b6df966-4e19-4055-bb13-c4c083b18e58\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"ed8c1bfa-c0a6-4e9b-8697-862aef109bcf\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"323f5abe-05ed-419d-9d81-d25c7d3b19f3\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"70c6b5fb-1b48-4a2f-bacd-be0284134818\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"2b6df966-4e19-4055-bb13-c4c083b18e58\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"6a134969-623b-428e-9b0c-436bae2d6608\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"323f5abe-05ed-419d-9d81-d25c7d3b19f3\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"51de5faf-1766-4dd1-abd0-eec2e867a322\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"0bb2ba89-a92d-4b32-b3cd-45df2300fa34\",\"port\":\"61eaafd2-095b-41d6-8e34-862fb470b7a6\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#A2B1C3\"}},\"id\":\"161f78dc-1f44-4e43-9ced-e39d345aac78\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"da634b2e-5ffc-4e1b-a636-f86ace9eb082\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"0bb2ba89-a92d-4b32-b3cd-45df2300fa34\",\"port\":\"61eaafd2-095b-41d6-8e34-862fb470b7a6\"}},{\"position\":{\"x\":-350,\"y\":-280},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"31585e99-58c7-4a98-8824-8000743b364d\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":1,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":-350,\"y\":-180},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"5123ad82-18bb-46fe-9d93-138b24b54a15\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":2,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":-620,\"y\":-200},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"start\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/start.88f586e1.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"data\":{\"dataId\":\"\",\"nodeType\":\"start\",\"nodeTypeExt\":\"\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"2ad6a8d5-d86d-49e6-908a-d317b61997c1\"},{\"group\":\"right\",\"id\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},{\"group\":\"bottom\",\"id\":\"7048578f-94d9-4f75-b653-eb5f43ff55db\"},{\"group\":\"left\",\"id\":\"e7bb1134-4b4c-401d-89ea-e77ae24cbd03\"}]},\"zIndex\":3,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":-153,\"y\":-240},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"switchRight\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/switchRight.74768797.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"data\":{\"dataId\":\"\",\"nodeType\":\"switchRight\",\"nodeTypeExt\":\"\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"adceedb7-f842-4d1e-be3a-8b3cb0a7e3ce\"},{\"group\":\"right\",\"id\":\"80d3bd61-1ed3-493a-b4e8-d4576e6fbfda\"},{\"group\":\"bottom\",\"id\":\"8fa84779-80b2-4c91-8366-7dd4fa0d93ff\"},{\"group\":\"left\",\"id\":\"f93ccd2f-dedd-47b1-9ad0-9be20c5db8a4\"}]},\"zIndex\":4},{\"position\":{\"x\":-21,\"y\":-240},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"da634b2e-5ffc-4e1b-a636-f86ace9eb082\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":5,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":170,\"y\":-100},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"end\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/end.814a7041.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"0bb2ba89-a92d-4b32-b3cd-45df2300fa34\",\"data\":{\"dataId\":\"\",\"nodeType\":\"end\",\"nodeTypeExt\":\"\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"223c9b3a-6baa-4bb8-99ba-c3300db9a942\"},{\"group\":\"right\",\"id\":\"2806bc8a-4e11-4657-9af9-089907985671\"},{\"group\":\"bottom\",\"id\":\"c56eed35-95fa-4e3c-adba-9847ef705e1c\"},{\"group\":\"left\",\"id\":\"61eaafd2-095b-41d6-8e34-862fb470b7a6\"}]},\"zIndex\":6},{\"position\":{\"x\":-350,\"y\":-54},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"2b6df966-4e19-4055-bb13-c4c083b18e58\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":7},{\"position\":{\"x\":-330,\"y\":40},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"323f5abe-05ed-419d-9d81-d25c7d3b19f3\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":8},{\"position\":{\"x\":-153,\"y\":-20},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":9,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]}]}"; |
| | | private RbdTreeNode recognizeRbd(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | Map<String, Integer> vnodeCounter = new HashMap<>(); |
| | | vnodeCounter.put("vnodeCounter", 0); |
| | | RbdTreeNode root = new RbdTreeNode(); |
| | | root.setAlgorithmType("series"); |
| | | root.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | root.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | root.setNodeType("vnode"); |
| | | |
| | | JSONObject diagramJson = new JSONObject(diagramJsonStr); |
| | | JSONArray diagramJsonArray = diagramJson.getJSONArray("cells"); |
| | | if (diagramJsonArray == null) return; |
| | | ModelNode end = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | RbdTreeNode endNode = new RbdTreeNode(); |
| | | endNode.setId(end.getId()); |
| | | endNode.setName("end"); |
| | | endNode.setNodeType("end"); |
| | | endNode.setPicId(end.getPicId()); |
| | | endNode.setPairStartNodeId(end.getPairStartNodeId()); |
| | | endNode.setObjectWidth(end.getWidth()); |
| | | endNode.setObjectHeight(end.getHeight()); |
| | | root.getChildren().add(endNode); |
| | | ModelLine lineRight = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(end.getPicId())).collect(Collectors.toList()).get(0); |
| | | recognizeOneBranch(root, |
| | | lineRight, |
| | | null, |
| | | modelNodeList, |
| | | modelLineList, |
| | | vnodeCounter); |
| | | |
| | | List<ModelLine> modelLineList = new ArrayList<>(); |
| | | List<ModelNode> modelNodeList = new ArrayList<>(); |
| | | // 1. 解析出节点与边 |
| | | for (int i = 0; i < diagramJsonArray.size(); i++) { |
| | | JSONObject jsonObject = diagramJsonArray.getJSONObject(i); |
| | | String shape = jsonObject.get("shape").toString(); |
| | | if (shape.equals("edge")) { |
| | | ModelLine modelLine = new ModelLine(); |
| | | modelLine.setId(UUIDUtil.generateId()); |
| | | modelLine.setPicId(jsonObject.get("id").toString()); |
| | | modelLine.setModelId(modelId); |
| | | modelLine.setBeginCell(JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString()); |
| | | modelLine.setEndCell(JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString()); |
| | | modelLineList.add(modelLine); |
| | | } else if (shape.equals("image")){ |
| | | ModelNode modelNode = new ModelNode(); |
| | | modelNode.setId(UUIDUtil.generateId()); |
| | | modelNode.setPicId(jsonObject.get("id").toString()); |
| | | modelNode.setModelId(modelId); |
| | | modelNode.setNodeType(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeType".split("/")).toString()); |
| | | if ("node".equals(modelNode.getNodeType())) { |
| | | modelNode.setDataId(Long.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString())); |
| | | modelNode.setNodeTypeExt(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeTypeExt".split("/")).toString()); |
| | | modelNode.setName(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/label/textWrap/text".split("/")).toString()); |
| | | } |
| | | modelNodeList.add(modelNode); |
| | | } |
| | | } |
| | | |
| | | // 2. 对于有多根入口线的产品节点,将其上的表决、旁联、并联关系剥离成运算符节点,添加到该产品节点的前面,并添加相应的边 |
| | | List<ModelNode> nodesToAdd = new ArrayList<>(); |
| | | List<ModelLine> linesToAdd = new ArrayList<>(); |
| | | for (ModelNode modelNode: modelNodeList) { |
| | | String picId = modelNode.getPicId(); |
| | | List<ModelLine> lineList = modelLineList.stream().filter(item->item.getEndCell().equals(picId)).collect(Collectors.toList()); |
| | | if (lineList.size()>1){ |
| | | if ("node,end".contains(modelNode.getNodeType())){ |
| | | String nodeTypeExt = ""; |
| | | if ("node".equals(modelNode.getNodeType())) { |
| | | nodeTypeExt = modelNode.getNodeTypeExt(); |
| | | } else if ("end".equals(modelNode.getNodeType())) { |
| | | nodeTypeExt = "parallel"; |
| | | } |
| | | if (StringUtils.isNotBlank(nodeTypeExt)){ |
| | | ModelNode modelNodeNew = new ModelNode(); |
| | | Long nodeNewId = UUIDUtil.generateId(); |
| | | modelNodeNew.setId(nodeNewId); |
| | | modelNodeNew.setPicId(nodeNewId.toString()); |
| | | modelNodeNew.setModelId(modelId); |
| | | modelNodeNew.setNodeType(nodeTypeExt); |
| | | nodesToAdd.add(modelNodeNew); |
| | | |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long lineNewId = UUIDUtil.generateId(); |
| | | modelLineNew.setId(lineNewId); |
| | | modelLineNew.setPicId(lineNewId.toString()); |
| | | modelLineNew.setModelId(modelId); |
| | | modelLineNew.setBeginCell(nodeNewId.toString()); |
| | | modelLineNew.setEndCell(modelNode.getPicId()); |
| | | linesToAdd.add(modelLineNew); |
| | | |
| | | for(ModelLine nodelLine: lineList){ |
| | | nodelLine.setEndCell(nodeNewId.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | modelNodeList.addAll(nodesToAdd); |
| | | modelLineList.addAll(linesToAdd); |
| | | |
| | | // 3. 将最基本的串、并、旁联、表决替换为虚节点,不断简化图形,直至无法简化为止 |
| | | List<Algorithm> algoList = new ArrayList<>(); |
| | | boolean hasLeastOne = false; |
| | | int stepNo = 0; |
| | | do { |
| | | List<ModelNode> opNodeList = modelNodeList.stream().filter(item -> |
| | | "parallel,switch,vote,end".contains(item.getNodeType())).collect(Collectors.toList()); |
| | | if (opNodeList.size() <= 0) break; |
| | | |
| | | hasLeastOne = false; // 至少能简化1个图形 |
| | | for (ModelNode opNode: opNodeList) { |
| | | // 右边运算符循环 |
| | | List<ModelLine> lineToOpNodeList = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(opNode.getPicId())).collect(Collectors.toList()); |
| | | List<List<ModelNode>> listPath = new ArrayList<>(); |
| | | ModelNode lastNode = null; |
| | | boolean thisNodeSucc= true; |
| | | for (ModelLine modelLine: lineToOpNodeList) { |
| | | // 右边运算符的逐个路径循环 |
| | | List<ModelNode> result = new ArrayList<>(); |
| | | handleOneLine(modelLineList, modelNodeList, modelLine, result); |
| | | listPath.add(result); |
| | | ModelNode curLastNode = result.get(result.size()-1); |
| | | if (lastNode == null) { |
| | | lastNode = curLastNode; |
| | | } else { |
| | | if (!lastNode.getId().equals(curLastNode.getId())){ |
| | | thisNodeSucc = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (thisNodeSucc) { |
| | | //形成虚节点算法 |
| | | stepNo = replaceToVNode(modelId, modelNodeList, modelLineList, opNode, listPath, lastNode, algoList, stepNo); |
| | | hasLeastOne = true; |
| | | } |
| | | } // end for |
| | | } while (hasLeastOne); |
| | | |
| | | // if (saveFlag) saveModel(modelId, modelNodeList, modelLineList, algoList); |
| | | return root; |
| | | } |
| | | |
| | | private void handleOneLine(List<ModelLine> modelLineList, |
| | | List<ModelNode> modelNodeList, |
| | | ModelLine modelLine, |
| | | List<ModelNode> result) { |
| | | ModelNode modelNode = modelNodeList.stream().filter(item -> |
| | | item.getPicId().equals(modelLine.getBeginCell())).collect(Collectors.toList()).get(0); |
| | | result.add(modelNode); |
| | | if ("start".equals(modelNode.getNodeType())) { |
| | | return; |
| | | private void recognizeOneBranch(RbdTreeNode parent, |
| | | ModelLine lineRight, // 串联的起始线(右边) |
| | | ModelLine lineLeft, // 串联的结束线(左边) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | Map<String, Integer> vnodeCounter) { |
| | | ModelLine inLine = lineRight; |
| | | for (; ; ) { |
| | | ModelLine searchLine = inLine; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | searchLine.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getName()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setDataId(node.getDataId()); |
| | | treeNode.setObjectWidth(node.getWidth()); |
| | | treeNode.setObjectHeight(node.getHeight()); |
| | | parent.getChildren().add(treeNode); |
| | | inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | } else if ("start".equals(node.getNodeType())) { |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getNodeType()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setObjectWidth(node.getWidth()); |
| | | treeNode.setObjectHeight(node.getHeight()); |
| | | parent.getChildren().add(treeNode); |
| | | break; |
| | | } else if ("connect".equals(node.getNodeType())) { |
| | | break; |
| | | } else if ("parallel,vote,switch,bridge".contains(node.getNodeType())) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | ModelNode connect = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(connect.getId()); |
| | | treeNode.setName(connect.getNodeType()); |
| | | treeNode.setNodeType(connect.getNodeType()); |
| | | treeNode.setPicId(connect.getPicId()); |
| | | treeNode.setObjectWidth(connect.getWidth()); |
| | | treeNode.setObjectHeight(connect.getHeight()); |
| | | subNode.getChildren().add(treeNode); |
| | | RbdTreeNode subNodeOpe = new RbdTreeNode(); |
| | | subNodeOpe.setAlgorithmType(node.getNodeType()); |
| | | subNodeOpe.setId(UUIDUtil.generateId()); |
| | | counter = vnodeCounter.get("vnodeCounter"); |
| | | subNodeOpe.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNodeOpe.setNodeType("vnode"); |
| | | subNodeOpe.setVoteNum(node.getVoteNum()); |
| | | subNode.getChildren().add(subNodeOpe); |
| | | treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getNodeType()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setPairStartNodeId(node.getPairStartNodeId()); |
| | | treeNode.setObjectWidth(node.getWidth()); |
| | | treeNode.setObjectHeight(node.getHeight()); |
| | | subNode.getChildren().add(treeNode); |
| | | recognizeOpeBlock(subNodeOpe, |
| | | node, |
| | | modelNodeList, |
| | | modelLineList, |
| | | vnodeCounter); |
| | | inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(connect.getPicId())).collect(Collectors.toList()).get(0); |
| | | } |
| | | |
| | | if (null != lineLeft) { |
| | | if (inLine.getPicId().equals(lineLeft.getPicId())) break; |
| | | } |
| | | } |
| | | List<ModelLine> lines =modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(modelNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> lines2 =modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(modelNode.getPicId())).collect(Collectors.toList()); |
| | | if (lines.size()>1 || lines2.size()>1) { |
| | | return; |
| | | } else { |
| | | handleOneLine(modelLineList, modelNodeList, lines2.get(0), result); |
| | | } |
| | | if ("series".equals(parent.getAlgorithmType())) Collections.reverse(parent.getChildren()); |
| | | } |
| | | |
| | | private int replaceToVNode(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | ModelNode opNode, |
| | | List<List<ModelNode>> listPath, |
| | | ModelNode lastNode, |
| | | List<Algorithm> algoList, |
| | | int stepNo) { |
| | | String computerList = ""; |
| | | String objectList = ""; |
| | | for (List<ModelNode> path : listPath) { |
| | | path.remove(path.get(path.size()-1)); |
| | | Long id = null; |
| | | String name = ""; |
| | | if (path.size()==0) { |
| | | return stepNo; |
| | | } else if (path.size()==1) { |
| | | if ("end".equals(opNode.getNodeType()) && !"start".equals(lastNode.getNodeType())) return stepNo; |
| | | id = path.get(path.size()-1).getId(); |
| | | name = path.get(path.size()-1).getName(); |
| | | private void recognizeOpeBlock(RbdTreeNode parent, |
| | | ModelNode rightNode, // rbd中的右节点(包括end及4种运算符) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | Map<String, Integer> vnodeCounter) { |
| | | if ("parallel,vote,switch".contains(parent.getAlgorithmType())) { |
| | | ModelNode searchNode = rightNode; |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLines = sortLine(lines, modelNodeList); |
| | | for (ModelLine line : sortedLines) { |
| | | boolean isSeries = isSeriesBranch(rightNode, line, modelNodeList, modelLineList); |
| | | if (isSeries) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, line, null, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, line, null, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | } |
| | | } else if ("bridge".contains(parent.getAlgorithmType())) { |
| | | ModelNode searchNode = rightNode; |
| | | List<ModelLine> linesRight = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLinesRight = sortLine(linesRight, modelNodeList); |
| | | List<ModelLine> linesLeft = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(searchNode.getPairStartNodeId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLinesLeft = sortLine(linesLeft, modelNodeList); |
| | | ModelLine lineTop = modelLineList.stream().filter(item -> |
| | | item.getPicId().equals(searchNode.getBridgeEdgeTopId())).collect(Collectors.toList()).get(0); |
| | | ModelLine lineBottom = modelLineList.stream().filter(item -> |
| | | item.getPicId().equals(searchNode.getBridgeEdgeBottomId())).collect(Collectors.toList()).get(0); |
| | | ModelLine verticalLineUpper = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(searchNode.getBridgeEdgeTopId())).collect(Collectors.toList()).get(0); |
| | | ModelLine verticalLineLower = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getBridgeEdgeBottomId())).collect(Collectors.toList()).get(0); |
| | | // 桥联的第1个支路 |
| | | if (isSeriesBranch(lineTop, sortedLinesLeft.get(0), modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, lineTop, sortedLinesLeft.get(0), modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | id = UUIDUtil.generateId(); |
| | | name = id.toString(); |
| | | Algorithm algo = new Algorithm(); |
| | | algo.setId(id); |
| | | algo.setModelId(modelId); |
| | | algo.setComputerId(id); |
| | | algo.setModelType("series"); |
| | | algo.setAlgorithmType("series"); |
| | | algo.setComputerList(joinNodeId(path, ",")); |
| | | algo.setObjectList(joinNodeName(path, ",")); |
| | | algo.setStep(stepNo); |
| | | stepNo++; |
| | | algoList.add(algo); |
| | | name = "v"+ algo.getStep(); |
| | | recognizeOneBranch(parent, lineTop, sortedLinesLeft.get(0), modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | computerList = computerList.equals("") ? id.toString() : computerList + "," + id.toString(); |
| | | objectList = objectList.equals("") ? name : objectList + "," + name; |
| | | for (ModelNode node : path) { |
| | | List<ModelLine> lineList4 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId()) || item.getBeginCell().equals(node.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(lineList4); |
| | | modelNodeList.remove(node); |
| | | // 桥联的第2个支路 |
| | | if (isSeriesBranch(sortedLinesRight.get(0), lineTop, modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, sortedLinesRight.get(0), lineTop, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, sortedLinesRight.get(0), lineTop, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第3个支路 |
| | | if (isSeriesBranch(verticalLineLower, verticalLineUpper, modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, verticalLineLower, verticalLineUpper, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, verticalLineLower, verticalLineUpper, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第4个支路 |
| | | if (isSeriesBranch(lineBottom, sortedLinesLeft.get(1), modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, lineBottom, sortedLinesLeft.get(1), modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, lineBottom, sortedLinesLeft.get(1), modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | // 桥联的第5个支路 |
| | | if (isSeriesBranch(sortedLinesRight.get(1), lineBottom, modelNodeList, modelLineList)) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, sortedLinesRight.get(1), lineBottom, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, sortedLinesRight.get(1), lineBottom, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | } |
| | | Algorithm algo = new Algorithm(); |
| | | Long id = UUIDUtil.generateId(); |
| | | algo.setId(id); |
| | | algo.setModelId(modelId); |
| | | algo.setComputerId(id); |
| | | algo.setModelType(opNode.getNodeType()); |
| | | algo.setAlgorithmType(opNode.getNodeType()); |
| | | algo.setComputerList(computerList); |
| | | algo.setObjectList(objectList); |
| | | algo.setStep(stepNo); |
| | | stepNo++; |
| | | algoList.add(algo); |
| | | |
| | | //将原运算节点改成虚节点 |
| | | opNode.setId(id); |
| | | opNode.setNodeType("vnode"); |
| | | opNode.setName("v"+algo.getStep()); |
| | | |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long picId2 = UUIDUtil.generateId(); |
| | | modelLineNew.setId(picId2); |
| | | modelLineNew.setPicId(picId2.toString()); |
| | | modelLineNew.setModelId(modelId); |
| | | modelLineNew.setBeginCell(lastNode.getPicId()); |
| | | modelLineNew.setEndCell(opNode.getPicId()); |
| | | modelLineList.add(modelLineNew); |
| | | |
| | | return stepNo; |
| | | } |
| | | |
| | | private String joinNodeId(List<ModelNode> nodeList, String sep) { |
| | | String result = ""; |
| | | for (int i = 0; i < nodeList.size(); i++) { |
| | | if (i > 0) result = result + sep; |
| | | result = result + nodeList.get(i).getId().toString(); |
| | | /** |
| | | * 按自上而下的顺序排序 |
| | | */ |
| | | private List<ModelLine> sortLine(List<ModelLine> lines, |
| | | List<ModelNode> modelNodeList) { |
| | | for (ModelLine line : lines) { |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | line.setBeginY(node.getPositionY()); |
| | | } |
| | | lines.sort(Comparator.comparing(ModelLine::getBeginY)); |
| | | |
| | | return lines; |
| | | } |
| | | |
| | | private boolean isSeriesBranch(ModelNode rightNode, // rbd中的右节点(包括end及4种运算符) |
| | | ModelLine line, // 右节点的入口线 |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | line1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !node1.getPicId().equals(rightNode.getPairStartNodeId()); |
| | | } else { |
| | | ModelNode node2 = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node2.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node3 = modelNodeList.stream().filter(item -> |
| | | line2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !node3.getPicId().equals(rightNode.getPairStartNodeId()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private String joinNodeName(List<ModelNode> nodeList, String sep) { |
| | | String result = ""; |
| | | for (int i = 0; i < nodeList.size(); i++) { |
| | | if (i > 0) result = result + sep; |
| | | result = result + nodeList.get(i).getName(); |
| | | private boolean isSeriesBranch(ModelLine lineRight, // 串联的起始线(右边) |
| | | ModelLine lineLeft, // 串联的结束线(左边) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | lineRight.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !line1.getPicId().equals(lineLeft.getPicId()); |
| | | } else { |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node1.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !line2.getPicId().equals(lineLeft.getPicId()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | ============解析模型的第1版,已不使用============ */ |
| | | |
| | | private boolean analyzeRbd(ModelRbd modelRbd, boolean saveFlag) { |
| | | boolean result = true; |
| | | String rbdsonStr = modelRbd.getContent(); |
| | | |
| | | JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells"); |
| | | if (rbdJsonArray == null) return result; |
| | | |
| | | // 解析结果存放list |
| | | List<ModelNode> modelNodeList = new ArrayList<>(); |
| | | List<ModelLine> modelLineList = new ArrayList<>(); |
| | | List<Algorithm> algorithmList = new ArrayList<>(); |
| | | List<ProductImg> productImgList = new ArrayList<>(); // 暂不使用(而使用数据库中的可靠性参数) |
| | | List<ModelNode> modelNodeAndVnodeList = new ArrayList<>(); |
| | | |
| | | // 1. 解析出节点与边 |
| | | getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList); |
| | | // 2. 转换为树型结构 |
| | | RbdTreeNode root = recognizeRbd(modelNodeList, modelLineList); |
| | | // 3. 预处理 |
| | | deleteSeriesForAutoArrange(root); |
| | | deleteStartEnd(root); |
| | | // 3. 生成算法 |
| | | createAlgorithm(modelRbd.getId(), root, algorithmList, modelNodeAndVnodeList); |
| | | // 4. 保存模型 |
| | | if (saveFlag) saveModel(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void createAlgorithm(Long modelId, |
| | | RbdTreeNode root, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | List<RbdTreeNode> children = root.getChildren(); |
| | | if (children.size() == 0) { |
| | | ModelNode node = new ModelNode(); |
| | | node.setModelId(modelId); |
| | | node.setId(root.getId()); |
| | | node.setPicId(root.getPicId()); |
| | | node.setDataId(root.getDataId()); |
| | | node.setNodeType(root.getNodeType()); |
| | | node.setName(root.getName()); |
| | | node.setVoteNum(root.getVoteNum()); |
| | | modelNodeAndVnodeList.add(node); |
| | | } else { |
| | | Algorithm algo = new Algorithm(); |
| | | algo.setModelId(modelId); |
| | | algo.setId(root.getId()); |
| | | algo.setComputerId(algo.getId()); |
| | | algo.setAlgorithmType(root.getAlgorithmType()); |
| | | algo.setModelType(algo.getAlgorithmType()); |
| | | algo.setStep(Integer.valueOf(root.getName().substring(1))); |
| | | algo.setVoteNum(root.getVoteNum()); |
| | | algo.setObjectList(root.getChildren().stream().map(item -> |
| | | item.getName()).collect(Collectors.joining(","))); |
| | | algo.setComputerList(root.getChildren().stream().map(item -> |
| | | item.getId().toString()).collect(Collectors.joining(","))); |
| | | algorithmList.add(algo); |
| | | ModelNode node = new ModelNode(); |
| | | node.setModelId(modelId); |
| | | node.setId(root.getId()); |
| | | node.setPicId(root.getPicId()); |
| | | node.setDataId(root.getDataId()); |
| | | node.setNodeType(root.getNodeType()); |
| | | node.setName(root.getName()); |
| | | node.setVoteNum(root.getVoteNum()); |
| | | modelNodeAndVnodeList.add(node); |
| | | for (RbdTreeNode treeNode : root.getChildren()) { |
| | | createAlgorithm(modelId, treeNode, algorithmList, modelNodeAndVnodeList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 对树形结构进行预处理,包括: |
| | | * 1)将root的algorithmType替换为end,并去掉start和end节点 |
| | | * 2)start与end间只有1个逻辑运算块,则去掉最外层的series |
| | | * |
| | | * @param root |
| | | */ |
| | | private void deleteStartEnd(RbdTreeNode root) { |
| | | root.setAlgorithmType("end"); |
| | | List<RbdTreeNode> children = root.getChildren(); |
| | | children.remove(children.size() - 1); |
| | | children.remove(0); |
| | | if (children.size() > 1 || |
| | | !"vnode".equals(children.get(0).getNodeType())) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | subNode.setName("v0"); |
| | | subNode.setNodeType("vnode"); |
| | | subNode.getChildren().addAll(children); |
| | | List<RbdTreeNode> list = new ArrayList<>(); |
| | | list.add(subNode); |
| | | root.setChildren(list); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 对树形结构进行预处理: |
| | | * 去掉逻辑运算块中用于排版的外层series |
| | | * |
| | | * @param root |
| | | */ |
| | | private void deleteSeriesForAutoArrange(RbdTreeNode root) { |
| | | List<RbdTreeNode> children = root.getChildren(); |
| | | for (int i = 0; i < children.size(); i++) { |
| | | RbdTreeNode treeNode = children.get(i); |
| | | if ("vnode".equals(treeNode.getNodeType()) && |
| | | "series".equals(treeNode.getAlgorithmType()) && |
| | | "connect".equals(treeNode.getChildren().get(0).getNodeType())) { |
| | | children.set(i, treeNode.getChildren().get(1)); |
| | | } |
| | | deleteSeriesForAutoArrange(children.get(i)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 用于自动排版:将桥联转换为3支路的并联 |
| | | * @param root |
| | | * @return |
| | | */ |
| | | private void convertBridgeToThreeBranchParallel(RbdTreeNode root) { |
| | | List<RbdTreeNode> children = root.getChildren(); |
| | | for (RbdTreeNode treeNode : children) { |
| | | if ("bridge".equals(treeNode.getAlgorithmType())) { |
| | | treeNode.setAlgorithmType("parallel"); |
| | | List<RbdTreeNode> list = new ArrayList<>(); |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | subNode.setName("v10000"); |
| | | subNode.setNodeType("vnode"); |
| | | subNode.getChildren().add(treeNode.getChildren().get(0)); |
| | | subNode.getChildren().add(treeNode.getChildren().get(1)); |
| | | list.add(subNode); |
| | | list.add(treeNode.getChildren().get(2)); |
| | | subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | subNode.setName("v10001"); |
| | | subNode.setNodeType("vnode"); |
| | | subNode.getChildren().add(treeNode.getChildren().get(3)); |
| | | subNode.getChildren().add(treeNode.getChildren().get(4)); |
| | | list.add(subNode); |
| | | treeNode.setChildren(list); |
| | | } |
| | | convertBridgeToThreeBranchParallel(treeNode); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) { |
| | | if (block.getNodeType().equals("node")) { |
| | | setNodePositionXY(rbdJsonArray, block,nodeMap); |
| | | } else { |
| | | double blockWidth = block.getBlockWidthNum() * LAYOUT_CELL_SIZE_X; |
| | | double blockHeight = block.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | |
| | | Double descentWidth = block.getDescentWidth(); |
| | | if (descentWidth == null || descentWidth == 0.0) { |
| | | descentWidth = blockWidth; |
| | | } |
| | | Double descentHeight = block.getDescentHeight(); |
| | | if (descentHeight == null || descentHeight == 0.0) { |
| | | descentHeight = blockHeight; |
| | | } |
| | | |
| | | block.setBlockWidth(blockWidth); |
| | | block.setBlockHeight(blockHeight); |
| | | List<RbdTreeNode> children = block.getChildren(); |
| | | |
| | | if (OPE_TYPE_SERIES.equals(block.getAlgorithmType())) { |
| | | Double subBlockX = block.getBlockX(); |
| | | for (RbdTreeNode child : children) { |
| | | |
| | | child.setDescentWidth(blockWidth); |
| | | child.setDescentHeight(blockHeight); |
| | | |
| | | double selfWidth = child.getBlockWidthNum() * LAYOUT_CELL_SIZE_X * descentWidth / blockWidth; |
| | | child.setBlockWidth(selfWidth); |
| | | child.setBlockHeight(blockHeight); |
| | | |
| | | child.setBlockY(block.getBlockY()); |
| | | child.setBlockX(subBlockX); |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | subBlockX = subBlockX + selfWidth; |
| | | |
| | | } |
| | | } else { |
| | | |
| | | Double subBlockY = block.getBlockY() + (descentHeight - blockHeight) / 2; |
| | | Double firstSubBlockY = subBlockY; |
| | | |
| | | // 设置connect的位置 |
| | | RbdTreeNode connectBlock = new RbdTreeNode(); |
| | | connectBlock.setObjectWidth(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/width")); |
| | | connectBlock.setObjectHeight(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/height")); |
| | | connectBlock.setNodeType("connect"); |
| | | connectBlock.setPicId(block.getPairStartNodeId()); |
| | | connectBlock.setBlockX(block.getBlockX()); |
| | | connectBlock.setBlockY(firstSubBlockY); |
| | | connectBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | connectBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, connectBlock, nodeMap); |
| | | |
| | | for (RbdTreeNode child : children) { |
| | | child.setDescentWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | | child.setDescentHeight(blockHeight); |
| | | |
| | | child.setBlockWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | | child.setBlockHeight(child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y); |
| | | |
| | | child.setBlockX(block.getBlockX() + LAYOUT_CELL_SIZE_X); |
| | | child.setBlockY(subBlockY); |
| | | subBlockY = subBlockY + child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | } |
| | | |
| | | // 设置运算符的位置 |
| | | RbdTreeNode opeBlock = new RbdTreeNode(); |
| | | |
| | | opeBlock.setPicId(block.getPicId()); |
| | | opeBlock.setNodeType("parallel"); |
| | | opeBlock.setObjectWidth(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/width")); |
| | | opeBlock.setObjectHeight(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/height")); |
| | | opeBlock.setBlockX(block.getBlockX() + blockWidth - LAYOUT_CELL_SIZE_X); |
| | | opeBlock.setBlockY(firstSubBlockY); |
| | | opeBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | opeBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, opeBlock, nodeMap); |
| | | } |
| | | } |
| | | |
| | | } |
| | | */ |
| | | |
| | | } |