端到端功能 节点展开部分代码提交

This commit is contained in:
qinoy 2023-05-30 17:46:55 +08:00
parent acb645d381
commit 9ca7ae12d2
3 changed files with 122 additions and 21 deletions

View File

@ -105,44 +105,71 @@ public class GraphNodeExpandHandle {
/**
* 节点展开
* @param direction 排布方向
* @throws Exception
*/
public void handleNodeExpand() throws Exception{
public void handleNodeExpand(String direction) throws Exception{
Thread t1 = new Thread(() -> {
// 1子流程节点内部元素处理 包括范围标注框处理
handleRelationModelNodePosition();
// 1总图节点以及连线处理
handleEndToEndGraphNodeAndLinker(direction);
});
t1.start();
Thread t2 = new Thread(() -> {
// 2子流程节点外部其它节点的位置处理
handleEndToEndGraphNodeExcluedExpandNode();
// 2子流程节点内部元素处理
handleRelationModelNodePosition();
});
t2.start();
t1.join();
t2.join();
// 3构建邻接矩阵
NodeExpandAdjMatrix expandAdjMatrix = buildEndToEndGraphAdjMatrix();
expandAdjMatrix.buildAdjMatrix();
// 5根据邻接矩阵重新连线
// 6保存总图模型信息 以及 子流程模型信息备份
BaseModel baseModel = apiManager.getDefinition(repositoryId, 0);
baseModel.setDefinition(endToEndProcessDefine.toJSONString());
apiManager.storeDefinition(baseModel);
apiManager.storeChildProcessDefine(baseModel, relationFileId, childProcessDefine.toJSONString());
}
/**
* 处理子流程中所有节点的坐标
* 处理总图中的节点与连线
* 1删除待展开的节点
* 2替换为范围选择框
* 3节点x > 范围标注框x || 节点y < 范围标注框y 针对符合条件的节点 进行坐标调整
* 4根据旧有连线关系构建邻接矩阵
* 5获取当前总图中的所有节点的坐标
* 6删除旧有连线关系
* 7构建新的连线关系
*/
private void handleRelationModelNodePosition(){
// 删除当前要展开的节点
private void handleEndToEndGraphNodeAndLinker(String direction){
// 1删除当前要展开的节点
removeEndToEndGraphElements(shapeId);
// 添加到总图中
// 2添加到总图中
addEndToEndGraphElements(scopeLimitationShape);
// 3总图中符合范围选择框条件的节点 坐标更新
handleEndToEndGraphNodeExcluedExpandNode();
// 4构建邻接矩阵
NodeExpandAdjMatrix expandAdjMatrix = buildEndToEndGraphAdjMatrix();
expandAdjMatrix.buildAdjMatrix();
// 5删除节点展开前的连线
removeEndToEndGraphOldLinker();
// 6获取所有节点坐标
JSONObject elements = endToEndProcessDefine.getJSONObject("elements");
double[][] vertexPosition = expandAdjMatrix.getVertexPosition(elements);
// 7构建新的连线
NodeExpandLinkerRender linkerRender = new NodeExpandLinkerRender(vertexPosition, expandAdjMatrix);
linkerRender.toAssembleLinker(direction);
}
/**
* 处理待展开节点所代表的流程文件中的节点的坐标
*/
private void handleRelationModelNodePosition(){
// 范围标注框 坐标
JSONObject scopeShapeProps = scopeLimitationShape.getJSONObject("props");
double scopeShapeX = scopeShapeProps.getDoubleValue("x");
@ -185,6 +212,7 @@ public class GraphNodeExpandHandle {
for (String key : elements.keySet()) {
JSONObject ele = elements.getJSONObject(key);
if ("linker".equals(ele.getString("name"))) continue; // 连线先不处理
JSONObject props = ele.getJSONObject("props");
if (props.getDoubleValue("x") > scopeShapeX) { // 当前元素在待展开节点的右侧
props.put("x", props.getDoubleValue("x") + scopeShapeW);
@ -197,7 +225,6 @@ public class GraphNodeExpandHandle {
}
}
/**
* 构建节点展开前 端到端总图的邻接矩阵
* 方便后续节点展开或者闭合进行重新连线
@ -208,11 +235,9 @@ public class GraphNodeExpandHandle {
List<JSONObject> linkerList = new ArrayList<>();
JSONObject endToEndProcessElements = endToEndProcessDefine.getJSONObject("elements");
for (String key : endToEndProcessElements.keySet()) {
JSONObject ele = endToEndProcessDefine.getJSONObject(key);
JSONObject ele = endToEndProcessElements.getJSONObject(key);
if ("linker".equals(ele.getString("name"))) {
linkerList.add(ele);
// 删除旧有的连线
removeEndToEndGraphElements(key);
}else {
nodeIdList.add(key);
}
@ -221,6 +246,19 @@ public class GraphNodeExpandHandle {
return expandAdjMatrix;
}
/**
* 删除总图中节点展开前的连线
*/
private void removeEndToEndGraphOldLinker(){
JSONObject elements = endToEndProcessDefine.getJSONObject("elements");
for (String key : elements.keySet()) {
JSONObject ele = elements.getJSONObject(key);
if ("linker".equals(ele.getString("name"))){
removeEndToEndGraphElements(key);
}
}
}
/**
* 存储子流程模型信息
* 在总图存储的同一级目录下
@ -260,6 +298,9 @@ public class GraphNodeExpandHandle {
}
}
/**
* 节点展开的邻接矩阵
*/
class NodeExpandAdjMatrix{
private int[][] adjMatrix;
@ -307,6 +348,14 @@ class NodeExpandAdjMatrix{
return adjMatrix;
}
public List<String> getNodeIds() {
return nodeIds;
}
public List<JSONObject> getLinkerList() {
return linkerList;
}
/**
* 构建邻接矩阵
*/
@ -319,4 +368,56 @@ class NodeExpandAdjMatrix{
addEdge(fromIndex, toIndex);
}
}
// 输出邻接矩阵
public void printAdjMatrix() {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < nodeIds.size(); i++) {
for (int j = 0; j < nodeIds.size(); j++) {
sb.append(adjMatrix[i][j]).append(" ");
}
sb.append("\n");
}
System.out.println(sb.toString());
}
/**
* 获取总图中节点展开前的所有节点坐标
* @param elements
* @return
*/
public double[][] getVertexPosition(JSONObject elements){
double[][] position = new double[nodeIds.size()][2];
for (int i = 0; i < nodeIds.size(); i++) {
JSONObject shape = elements.getJSONObject(nodeIds.get(i));
JSONObject props = shape.getJSONObject("props");
double x = props.getDoubleValue("x");
double y = props.getDoubleValue("y");
position[i][0] = x;
position[i][1] = y;
}
return position;
}
}
/**
* 节点展开后连线重构
*/
class NodeExpandLinkerRender{
private List<String> nodeIds; // 图形节点ID集合
private double[][] vertexPosition; // 所有节点的坐标
private NodeExpandAdjMatrix expandAdjMatrix; // 节点矩阵
public NodeExpandLinkerRender(double[][] vertexPosition, NodeExpandAdjMatrix expandAdjMatrix) {
this.nodeIds = expandAdjMatrix.getNodeIds();
this.vertexPosition = vertexPosition;
this.expandAdjMatrix = expandAdjMatrix;
}
public JSONArray toAssembleLinker(String direction){
JSONArray linkers = new JSONArray();
return linkers;
}
}

View File

@ -303,7 +303,7 @@ public class SubProcessWeb extends ActionWeb {
}
public void shapeNodeExpand(String repositoryId, String shapeId){
public void shapeNodeExpand(String repositoryId, String shapeId, String direction){
/*
* 以当前节点展开涉及到动作拆分
@ -323,7 +323,7 @@ public class SubProcessWeb extends ActionWeb {
GraphNodeExpandHandle nodeExpandHandle = new GraphNodeExpandHandle(repositoryId, shapeId);
try {
nodeExpandHandle.handleNodeExpand();
nodeExpandHandle.handleNodeExpand(direction);
} catch (Exception e) {
throw new RuntimeException(e);
}