|
@@ -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) {
|