| | |
| | | import com.zt.common.utils.UUIDUtil; |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.ParamDataDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.XhProductModelDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ParamData; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ProductImg; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.XhProductModel; |
| | | 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.dom4j.Element; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | // 7. 递归计算RBD的布局空间参数(x、y坐标) |
| | | root.setBlockX(0); |
| | | root.setBlockY(0); |
| | | calcPosition(rbdJsonArray, root); |
| | | |
| | | Map<String, RbdTreeNode> nodeMap = new HashMap<>(); |
| | | calcPosition(rbdJsonArray, root, nodeMap); |
| | | setEdgeRouter(rbdJsonArray, nodeMap); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("cells", rbdJsonArray); |
| | | modelRbd.setContent(jsonObject.toString()); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private void setNodePositionXY(JSONArray rbdJsonArray, RbdTreeNode block) { |
| | | 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(",")); |
| | | } |
| | | } |
| | | } |
| | | 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("")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | block.setX(x); |
| | | block.setY(y); |
| | | nodeMap.put(block.getPicId(),block); |
| | | setRbdNodePosition(rbdJsonArray, block.getPicId(), x, y); |
| | | } |
| | | |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block) { |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) { |
| | | if (block.getNodeType().equals("node")) { |
| | | setNodePositionXY(rbdJsonArray, block); |
| | | setNodePositionXY(rbdJsonArray, block,nodeMap); |
| | | } else { |
| | | double blockWidth = block.getBlockWidthNum() * LAYOUT_CELL_SIZE_X; |
| | | double blockHeight = block.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | |
| | | |
| | | child.setBlockY(block.getBlockY()); |
| | | child.setBlockX(subBlockX); |
| | | calcPosition(rbdJsonArray, child); |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | subBlockX = subBlockX + selfWidth; |
| | | |
| | | } |
| | |
| | | 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); |
| | | setNodePositionXY(rbdJsonArray, connectBlock, nodeMap); |
| | | |
| | | for (RbdTreeNode child : children) { |
| | | child.setDescentWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | |
| | | child.setBlockX(block.getBlockX() + LAYOUT_CELL_SIZE_X); |
| | | child.setBlockY(subBlockY); |
| | | subBlockY = subBlockY + child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | calcPosition(rbdJsonArray, child); |
| | | 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); |
| | | setNodePositionXY(rbdJsonArray, opeBlock, nodeMap); |
| | | } |
| | | } |
| | | |