一键创建link不再删除原有link

This commit is contained in:
fan 2023-07-12 17:25:39 +08:00
parent 1619eb05b6
commit c8b15ae0d9
3 changed files with 80 additions and 11 deletions

View File

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

View File

@ -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>(
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<string, graphicData.RelatedRef.DevicePort[]> = 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) {

View File

@ -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<SectionLinkDraw>(SectionLink.Type);