Преглед изворни кода

过滤条件和动态源相关逻辑优化完善

zhaoyk пре 2 година
родитељ
комит
d9f76f65f8

+ 93 - 38
adm_comp/src/lib/DiagramModel.ts

@@ -19,7 +19,7 @@ export class Template {
 	mainPipes: Array<MainPipe>;
 	
 	scatteredContainers: Array<Container>;
-	
+
 	static getContainerById(id: string, template: Template): Container {
 		return Container.getContainerById(id, template.frame);
 	}
@@ -33,7 +33,14 @@ export class Template {
 		}
 		return null;
 	}
-	
+		
+	static getElById(id: string, template: Template): any {
+		var el: any = Template.getContainerById(id, template);
+		if(el == null)
+			el = Template.getMainPipeById(id, template);
+		return el;
+	}
+
 	static getContainers(template: Template): Array<Container> {
 		const result = new Array<Container>();
 		Template.doGetContainers(template.frame, result);
@@ -50,50 +57,83 @@ export class Template {
 		}
 	}
 	
-	static findRelatedMainPipes(con: Container, template: Template): Array<MainPipe> {
-		const mps = new Array<MainPipe>();
-		while(true) {
-			if(con == null)
-				break;
-			
-			for(const mp of template.mainPipes) {
-				if(mp.bindEquipment && mp.relatedContainers && mp.relatedContainers.indexOf(con.id) >= 0){
-					if(mps.indexOf(mp) < 0) {
-						mps.push(mp);	
-					}
-				}
+	static findLeaderEls(el: any, template: Template): Array<any> {
+		const list = new Array<any>();
+		for(const con of Template.getContainers(template)) {
+			if(con != el && Container.isEquipBox(con)) {
+				if(Template.canBeLeader(el, con, template))
+					list.push(con);
+			}
+		}
+		for(const mp of template.mainPipes) {
+			if(mp != el && mp.bindEquipment) {
+				if(Template.canBeLeader(el, mp, template))
+					list.push(mp);
 			}
-			
-			con = con.parent;
 		}
-		return mps;
+		return list;
 	}
 	
-	static findDynSrcs(el: any, template: Template, ignoreEl: any, srcs: Array<string>){
-		if(el.compType == 'mainPipe') {
-			const mp = <MainPipe>el;
-			const relCons = mp.relatedContainers;
-			if(relCons && relCons.length > 0) {
-				for(const conId of relCons) {
+	private static canBeLeader(el: any, leader: any, template: Template): boolean {
+		const pdc = Template.getParentDynCon(el, template);
+		const lPdc = Template.getParentDynCon(leader, template);
+		
+		if(pdc == lPdc){
+			if(leader.dynTarget != null || el.dynTarget == null) {
+				if(el.compType != leader.compType){
+					return el.compType == 'mainPipe' ? Template.isRelatedWith(<MainPipe>el, <Container>leader, template) : Template.isRelatedWith(<MainPipe>leader, <Container>el, template);
+				} else
+					return true;	
+			}
+		} else {
+			if(el.compType == leader.compType) {
+				if(!lPdc)
+					return true;
+			}
+			if(pdc && lPdc)
+				return Container.isParentOf(lPdc, pdc);	
+		}
+		return false;
+	}
+	
+	private static getParentDynCon(el: any, template: Template): Container {
+		var p: Container;
+		if(el.compType == 'container') {
+			p = (<Container>el).parent;
+			while(p != null) {
+				if(p.dynGroup)
+					return p;
+				p = p.parent;
+			}
+		} else if(el.compType == 'mainPipe') {
+			const relConIds = (<MainPipe>el).relatedContainers;
+			if(relConIds){
+				for(const conId of relConIds) {
 					const relCon = Template.getContainerById(conId, template);
-					if(relCon)
-						Template.findDynSrcs(relCon, template, ignoreEl, srcs);	
+					if(relCon) {
+						if(relCon.dynGroup)
+							return relCon;
+						p = Template.getParentDynCon(relCon, template);
+						if(p)
+							return p;
+					}
 				}
 			}
-		} else if(el.compType == 'container') {
-			const con = <Container>el;
-			if(con.dynGroup) {
-				var srcObj;
-				if(con.dynGroup.dynSourceType == 'container')
-					srcObj = Template.getContainerById(con.dynGroup.dynSource, template);
-				else if(con.dynGroup.dynSourceType == 'mainPipe')
-					srcObj = Template.getMainPipeById(con.dynGroup.dynSource, template);
-				if(srcObj && srcObj != ignoreEl && srcs.indexOf(srcObj) < 0)
-					srcs.push(srcObj);	
+		}
+		return null;
+	}
+	
+	static isRelatedWith(mainPipe: MainPipe, con: Container, template: Template): boolean {
+		if(mainPipe.relatedContainers){
+			for(const conId of mainPipe.relatedContainers) {
+				const relCon = Template.getContainerById(conId, template);
+				if(relCon) {
+					if(relCon == con || Container.isParentOf(relCon, con))
+						return true;
+				}
 			}
-			if(con.parent)
-				Template.findDynSrcs(con.parent, template, ignoreEl, srcs);
 		}
+		return false;
 	}
 	
 	static clearParent(template: Template){
@@ -150,10 +190,25 @@ export class Container extends Comp {
 	
 	dynTarget: string;
 	
+	static isParentOf(parent: Container, comp: Comp): boolean{
+		var p = comp.parent;
+		while (p != null) {
+			if(p == parent){
+				return true;
+			}
+			p = p.parent;
+		}
+		return false;
+	}
+	
+	static isEquipBox(con: Container): boolean {
+		return con && con.equipmentTypes != null && con.equipmentTypes.length > 0;
+	}
+	
 	static getEquipBoxes(con: Container, arr?: Array<Container>){
 		if(!arr)
 			arr = new Array<Container>();
-		if(con.equipmentTypes != null && con.equipmentTypes.length > 0)
+		if(Container.isEquipBox(con))
 			arr.push(con);
 		else if(con.children && con.children.length > 0) {
 			for(const item of con.children) {

+ 0 - 29
adm_comp/src/lib/TemplateEditor.ts

@@ -344,35 +344,6 @@ export class TemplateEditor extends Editor {
 		return 1;
 	}
 	
-	getCompById(id: string): any {
-		if(!id)
-			return null;
-			
-		if(this.templateData.mainPipes) {
-			for(const mp of this.templateData.mainPipes) {
-				if(mp.id == id)
-					return mp;
-			}
-		}
-		
-		return this.getConById(id);
-	}
-	
-	getConById(id:string): Container {
-		return this.findCon(id, this.templateData.frame);
-	}
-
-	private findCon(id:string, con: Container): Container {
-		if(con.id == id)
-			return con;
-		for(const sub of con.children) {
-			const rtn = this.findCon(id, <Container>sub);
-			if(rtn != null)
-				return rtn;
-		}
-		return null;
-	}
-
 	//干管绘制时,自动调整横平竖直
 	private adjustPointForMp(point: Point) {
 		if(this.currentTmpMainPipe && this.currentTmpMainPipe.length > 0) {

+ 3 - 29
adm_comp/src/views/DiagramTemplate.vue

@@ -632,7 +632,7 @@
 		
 		//检测id是否冲突
 		checkId(id:string):boolean {
-			return this.editor.getCompById(id) == null;
+			return Template.getElById(id, this.currentTemplate) == null;
 		}
 		
 		//删除容器
@@ -775,34 +775,8 @@
 		editFilter(){
 			const sel = this.editor.getSelComp();
 			this.dataFilter = sel.dataFilter != null ? sel.dataFilter : {};//为null时赋一个新对象,触发子组件watch
-			const relObjs = [];
-			const normalCons = [];
-			if(!sel.dynTarget) {
-				if(sel.compType == 'container') {
-					relObjs.push(...Template.findRelatedMainPipes(sel, this.currentTemplate));
-					
-					const arr: any[] = Template.getContainers(this.currentTemplate);
-					arr.forEach(item => {
-						if(item.equipmentTypes != null && item.equipmentTypes.length > 0 && item.id != sel.id && item.dynTarget == null)
-							normalCons.push(item);
-					});
-				} else if(sel.compType == 'mainPipe') {
-					if(sel.relatedContainers) {
-						for(const conId of sel.relatedContainers){
-							const con = this.editor.getConById(conId);
-							if(con)
-								relObjs.push(con);
-						}
-					}
-				}
-			}
-			
-			Template.findDynSrcs(sel, this.currentTemplate, sel, relObjs);
-			
-			if(normalCons.length > 0)
-				relObjs.push(...normalCons);
 			
-			this.filterRelatedObjs = relObjs;
+			this.filterRelatedObjs = Template.findLeaderEls(sel, this.currentTemplate);
 			
 			this.dlgFilterVisible = true;
 		}
@@ -955,7 +929,7 @@
 						this.propsData = {};
 						
 						this.editor.show(this.currentTemplate);
-						this.editor.setSelComp(this.editor.getCompById(selId));
+						this.editor.setSelComp(Template.getElById(selId, this.currentTemplate));
 					}
 				})
 				.catch(err => {