فهرست منبع

修改diagram保存机制

zhaoyk 3 سال پیش
والد
کامیت
30d150db1b

+ 3 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramDataLoader.java

@@ -68,6 +68,9 @@ public class DiagramDataLoader {
 				} else {
 					en.setLegend(DiagramBuilder.emptyLegend());
 				}
+
+				//设置anchorLocations
+				en.getAnchorLocations();
 			}
 
 			if(obj != null) {

+ 2 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/line/LineLayoutManager.java

@@ -44,8 +44,8 @@ public class LineLayoutManager {
 		ConnectPoint p1 = line.getFrom();
 		ConnectPoint p2 = line.getTo();
 
-		p1.layout();
-		p2.layout();
+		p1.layout(context);
+		p2.layout(context);
 
 		boolean exchange = false;
 		//先计算点模型的终点

+ 7 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/ConnectPoint.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.google.gson.annotations.Expose;
 import com.persagy.adm.diagram.core.model.base.XY;
 import com.persagy.adm.diagram.core.model.legend.Anchor;
+import com.persagy.adm.diagram.core.model.logic.CalcContext;
 import com.persagy.adm.diagram.core.model.template.MainPipe;
 
 import java.util.Objects;
@@ -74,8 +75,13 @@ public class ConnectPoint {
 		return null;
 	}
 
-	public void layout() {
+	public void layout(CalcContext context) {
 		if(!layoutFlag) {
+			//重新执行layout时,需要初始化hostObj
+			if(hostObj == null) {
+				hostObj = context.getComp(hostId, hostType);
+			}
+
 			if(hostObj instanceof EquipmentNode) {
 				EquipmentNode en = (EquipmentNode)hostObj;
 				location = en.locationToRoot();

+ 22 - 23
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java

@@ -91,37 +91,36 @@ public class Diagram {
 	/**
 	 * 节点列表,运行时&显示态数据结构
 	 */
-	@Expose //TODO 删掉
 	private List<DiagramNode> nodes = new ArrayList<>();
 
 	public void init(){
 		if (template != null) {
 			template.init();
 
-//			List<Container> containers = template.getContainers();
-//			for(Container con : containers) {
-//				if(con.isEquipmentBox()) {
-//					for(IComponent comp : con.getChildren()) {
-//						if(comp instanceof DiagramNode){
-//							nodes.add((DiagramNode) comp);
-//						}
-//					}
-//				}
-//			}
-		}
-
-		nodes.sort(new Comparator<DiagramNode>() {
-			@Override
-			public int compare(DiagramNode o1, DiagramNode o2) {
-				return o1.getLayoutIndex() - o2.getLayoutIndex();
-			}
-		});
-		for (DiagramNode node : nodes) {
-			Container con = template.getContainerById(node.getContainerId());
-			if (con != null) {
-				con.addComp(node);
+			List<Container> containers = template.getContainers();
+			for(Container con : containers) {
+				if(con.isEquipmentBox()) {
+					for(IComponent comp : con.getChildren()) {
+						if(comp instanceof DiagramNode){
+							nodes.add((DiagramNode) comp);
+						}
+					}
+				}
 			}
 		}
+
+//		nodes.sort(new Comparator<DiagramNode>() {
+//			@Override
+//			public int compare(DiagramNode o1, DiagramNode o2) {
+//				return o1.getLayoutIndex() - o2.getLayoutIndex();
+//			}
+//		});
+//		for (DiagramNode node : nodes) {
+//			Container con = template.getContainerById(node.getContainerId());
+//			if (con != null) {
+//				con.addComp(node);
+//			}
+//		}
 	}
 
 	public void layout(CalcContext context){

+ 4 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/XY.java

@@ -14,6 +14,10 @@ public class XY {
 	@Expose
 	public int y;
 
+	public XY() {
+
+	}
+
 	public XY(int x, int y) {
 		this.x = x;
 		this.y = y;

+ 7 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/CalcContext.java

@@ -3,6 +3,7 @@ package com.persagy.adm.diagram.core.model.logic;
 import cn.hutool.core.util.StrUtil;
 import com.persagy.adm.diagram.core.DataStrategy;
 import com.persagy.adm.diagram.core.model.Diagram;
+import com.persagy.adm.diagram.core.model.DiagramNode;
 import com.persagy.adm.diagram.core.model.EquipmentNode;
 import com.persagy.adm.diagram.core.model.Line;
 import com.persagy.adm.diagram.core.model.base.Container;
@@ -73,6 +74,12 @@ public class CalcContext {
 		//TODO 按动态组获取
 		if(MainPipe.TYPE.equals(type)) {
 			return (T)template.getMainPipeById(id);
+		} else if(EquipmentNode.TYPE.equals(type)) {
+			for(DiagramNode node : diagram.getNodes()) {
+				if(node.getId().equals(id)){
+					return (T)node;
+				}
+			}
 		} else if(Container.TYPE.equals(type)) {
 			return (T)template.getContainerById(id);
 		} else {