diff --git a/src/graphics/sectionLink/SectionLink.ts b/src/graphics/sectionLink/SectionLink.ts index 587308b..b25baeb 100644 --- a/src/graphics/sectionLink/SectionLink.ts +++ b/src/graphics/sectionLink/SectionLink.ts @@ -7,9 +7,14 @@ import { IChildTransform, getNormalVector, movePointAlongNormal, + GraphicRelationParam, } from 'src/jl-graphic'; import { ILineGraphic } from 'src/jl-graphic/plugins/GraphicEditPlugin'; -import { IRelatedRefData, ISimpleRefData } from '../CommonGraphics'; +import { + IRelatedRefData, + ISimpleRefData, + protoPort2Data, +} from '../CommonGraphics'; export interface ISectionLinkData extends GraphicData { get code(): string; // 编号 @@ -139,6 +144,43 @@ export class SectionLink extends JlGraphic implements ILineGraphic { old.points = points; this.updateData(old); } + + loadRelations(): void { + if (this.datas.aSimRef) { + this.relationManage.addRelation( + new GraphicRelationParam(this, 'A'), + new GraphicRelationParam( + this.queryStore.queryById(this.datas.aSimRef.id) + ) + ); + } + if (this.datas.bSimRef) { + this.relationManage.addRelation( + new GraphicRelationParam(this, 'B'), + new GraphicRelationParam( + this.queryStore.queryById(this.datas.bSimRef.id) + ) + ); + } + if (this.datas.aRef) { + this.relationManage.addRelation( + new GraphicRelationParam(this, 'A'), + new GraphicRelationParam( + this.queryStore.queryById(this.datas.aRef.id), + protoPort2Data(this.datas.aRef.devicePort) + ) + ); + } + if (this.datas.bRef) { + this.relationManage.addRelation( + new GraphicRelationParam(this, 'B'), + new GraphicRelationParam( + this.queryStore.queryById(this.datas.bRef.id), + protoPort2Data(this.datas.bRef.devicePort) + ) + ); + } + } } export class SectionLinkTemplate extends JlGraphicTemplate { diff --git a/src/graphics/sectionLink/SectionLinkDrawAssistant.ts b/src/graphics/sectionLink/SectionLinkDrawAssistant.ts index 53cc609..b5671e3 100644 --- a/src/graphics/sectionLink/SectionLinkDrawAssistant.ts +++ b/src/graphics/sectionLink/SectionLinkDrawAssistant.ts @@ -107,7 +107,6 @@ export class SectionLinkDraw extends GraphicDrawAssistant< } else { throw new Error('无法判断linkAB端'); } - this.storeGraphic(sectionLink); return sectionLink; } generateByTurnoutAxle( @@ -152,7 +151,6 @@ export class SectionLinkDraw extends GraphicDrawAssistant< throw new Error('无法判断linkAB端'); } sectionLink.datas.points = points; - this.storeGraphic(sectionLink); return sectionLink; } generateByTurnout( @@ -219,7 +217,7 @@ export class SectionLinkDraw extends GraphicDrawAssistant< } points.push(forkP2); sectionLink.datas.points = points; - this.storeGraphic(sectionLink); + return sectionLink; } /** * 缓存计轴和link关系,为生成link关联关系提供数据依据 @@ -338,6 +336,33 @@ export class SectionLinkDraw extends GraphicDrawAssistant< map.set(deviceId, [devicePort]); } } + /** + * 构建现有link识别list + */ + buildLinkRecognize(): string[] { + const sectionLinkList = this.app.queryStore.queryByType( + SectionLink.Type + ); + const curLinks: string[] = []; + sectionLinkList.forEach((link) => { + const id1 = link.datas.aSimRef?.id; + const id2 = link.datas.bSimRef?.id; + curLinks.push(id1 + '_' + id2); + }); + return curLinks; + } + /** + * 识别是否已有相同link,如没有则创建 + * @param curLinks + * @param sectionLink + */ + recognizeAndCreateLink(curLinks: string[], sectionLink: SectionLink) { + const id1 = sectionLink.datas.aSimRef?.id; + const id2 = sectionLink.datas.bSimRef?.id; + if (!curLinks.includes(id1 + '_' + id2)) { + this.storeGraphic(sectionLink); + } + } /** * 一键生成link */ @@ -352,6 +377,7 @@ export class SectionLinkDraw extends GraphicDrawAssistant< const tpMap: Map = new Map(); // 已生成link的section数据(两计轴之间的区段) const gSectionList: string[] = []; + const curLinks = this.buildLinkRecognize(); axleCountingList.forEach((axleCounting) => { axleCounting.datas.axleCountingRef.forEach((device) => { const g = this.app.queryStore.queryById(device.id); @@ -371,6 +397,7 @@ export class SectionLinkDraw extends GraphicDrawAssistant< axle1 ); gSectionList.push(g.id); + this.recognizeAndCreateLink(curLinks, link); this.cacheAxleLinkRelation(axleRefLink, axleCounting.id, link.id); this.cacheAxleLinkRelation(axleRefLink, axle1.id, link.id); } @@ -380,6 +407,7 @@ export class SectionLinkDraw extends GraphicDrawAssistant< device.devicePort, axleCounting ); + this.recognizeAndCreateLink(curLinks, link); this.cacheAxleLinkRelation(axleRefLink, axleCounting.id, link.id); this.cacheTurnoutPort(tpMap, g.id, device.devicePort); } @@ -397,7 +425,8 @@ export class SectionLinkDraw extends GraphicDrawAssistant< turnout.datas.paRef.deviceType === rrDeviceType.Turnout ) { pRef = turnout.datas.paRef; - this.generateByTurnout(turnout, rrDevicePort.A, pRef); + const link = this.generateByTurnout(turnout, rrDevicePort.A, pRef); + this.recognizeAndCreateLink(curLinks, link); } if ( !pList.includes(rrDevicePort.B) && @@ -405,7 +434,8 @@ export class SectionLinkDraw extends GraphicDrawAssistant< turnout.datas.pbRef.deviceType === rrDeviceType.Turnout ) { pRef = turnout.datas.pbRef; - this.generateByTurnout(turnout, rrDevicePort.B, pRef); + const link = this.generateByTurnout(turnout, rrDevicePort.B, pRef); + this.recognizeAndCreateLink(curLinks, link); } if ( !pList.includes(rrDevicePort.C) && @@ -413,7 +443,8 @@ export class SectionLinkDraw extends GraphicDrawAssistant< turnout.datas.pcRef.deviceType === rrDeviceType.Turnout ) { pRef = turnout.datas.pcRef; - this.generateByTurnout(turnout, rrDevicePort.C, pRef); + const link = this.generateByTurnout(turnout, rrDevicePort.C, pRef); + this.recognizeAndCreateLink(curLinks, link); } tpMap.set(turnout.id, [rrDevicePort.A, rrDevicePort.B, rrDevicePort.C]); if (pRef) { diff --git a/src/layouts/DrawLayout.vue b/src/layouts/DrawLayout.vue index 5f4c132..38d293e 100644 --- a/src/layouts/DrawLayout.vue +++ b/src/layouts/DrawLayout.vue @@ -369,10 +369,6 @@ function oneClickLogicSection() { } function oneClickLink() { drawStore.oneClickType = 'SectionLink'; - const linkList = drawStore - .getDrawApp() - .queryStore.queryByType(SectionLink.Type); - drawStore.getDrawApp().deleteGraphics(...linkList); const draw = drawStore .getDrawApp() .getDrawAssistant(SectionLink.Type);