From 55693eecd98d78c3c70081866a087cc3e764b73c Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Wed, 12 Jul 2023 17:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8C=BA=E6=AE=B5=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graphics/LogicSectionInteraction.ts | 6 + .../AxleCountingSectionAssistant.ts | 90 +---------- src/graphics/logicSection/LogicSection.ts | 2 + .../logicSection/LogicSectionDrawAssistant.ts | 142 ++++++++++++++++-- src/protos/stationLayoutGraphics.ts | 23 +++ 5 files changed, 163 insertions(+), 100 deletions(-) diff --git a/src/drawApp/graphics/LogicSectionInteraction.ts b/src/drawApp/graphics/LogicSectionInteraction.ts index 628aa24..e1f72f1 100644 --- a/src/drawApp/graphics/LogicSectionInteraction.ts +++ b/src/drawApp/graphics/LogicSectionInteraction.ts @@ -51,6 +51,12 @@ export class LogicSectionData set indexNumber(v: number) { this.data.indexNumber = v; } + get turnoutId(): string { + return this.data.turnoutId; + } + set turnoutId(v: string) { + this.data.turnoutId = v; + } clone(): LogicSectionData { return new LogicSectionData(this.data.cloneMessage()); } diff --git a/src/graphics/axleCountingSection/AxleCountingSectionAssistant.ts b/src/graphics/axleCountingSection/AxleCountingSectionAssistant.ts index 0c54379..a76de3e 100644 --- a/src/graphics/axleCountingSection/AxleCountingSectionAssistant.ts +++ b/src/graphics/axleCountingSection/AxleCountingSectionAssistant.ts @@ -1,11 +1,4 @@ -import { - DisplayObject, - FederatedMouseEvent, - FederatedPointerEvent, - IHitArea, - IPointData, - Point, -} from 'pixi.js'; +import { FederatedPointerEvent, IHitArea, IPointData, Point } from 'pixi.js'; import { GraphicDrawAssistant, GraphicIdGenerator, @@ -13,7 +6,6 @@ import { JlDrawApp, JlGraphic, linePoint, - splitLineEvenly, } from 'src/jl-graphic'; import { @@ -28,11 +20,6 @@ import { Turnout } from '../turnout/Turnout'; import { createRelatedRefProto } from '../CommonGraphics'; import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; -import { Dialog } from 'quasar'; -import { LogicSection } from '../logicSection/LogicSection'; -import { LogicSectionData } from 'src/drawApp/graphics/LogicSectionInteraction'; -import { graphicData } from 'src/protos/stationLayoutGraphics'; -import SectionSplitDialog from 'src/components/draw-app/dialogs/SectionSplitDialog.vue'; function hasCommonElements(arr1: string[], arr2: string[]) { for (let i = 0; i < arr1.length; i++) { @@ -66,7 +53,7 @@ export class AxleCountingSectionDraw extends GraphicDrawAssistant< super(app, template, 'sym_o_circle', '不展示'); this.codeGraph = this.graphicTemplate.new(); this.container.addChild(this.codeGraph); - AxleCountingSectionInteraction.init(app, this); + AxleCountingSectionInteraction.init(app); } bind(): void { @@ -318,14 +305,12 @@ const SectionEditMenu: ContextMenu = ContextMenu.init({ export class AxleCountingSectionInteraction extends GraphicInteractionPlugin { static Name = 'AxleCountingSection_transform'; - drawAssistant: AxleCountingSectionDraw; - constructor(app: JlDrawApp, da: AxleCountingSectionDraw) { + constructor(app: JlDrawApp) { super(AxleCountingSectionInteraction.Name, app); - this.drawAssistant = da; app.registerMenu(SectionEditMenu); } - static init(app: JlDrawApp, da: AxleCountingSectionDraw) { - return new AxleCountingSectionInteraction(app, da); + static init(app: JlDrawApp) { + return new AxleCountingSectionInteraction(app); } filter(...grahpics: JlGraphic[]): AxleCountingSection[] | undefined { return grahpics @@ -344,7 +329,6 @@ export class AxleCountingSectionInteraction extends GraphicInteractionPlugin { - Dialog.create({ - title: '拆分逻辑区段', - message: '请选择生成数量和方向', - component: SectionSplitDialog, - cancel: true, - persistent: true, - }).onOk((data: { num: number; dir: 'ltr' | 'rtl' }) => { - const logicSections = this.app.queryStore.queryByType( - LogicSection.Type - ); - logicSections.forEach((logicSection) => { - if (logicSection.datas.axleSectionId == axleCountingSection.id) { - this.app.deleteGraphics(logicSection); - } - }); - const { num, dir } = data; - const axleCountingSectionData = axleCountingSection.datas; - const points = splitLineEvenly( - axleCountingSection.localToCanvasPoint( - axleCountingSectionData.points[0] - ), - axleCountingSection.localToCanvasPoint( - axleCountingSectionData.points[ - axleCountingSectionData.points.length - 1 - ] - ), - num - ); - if ( - (dir === 'ltr' && - axleCountingSectionData.points[0].x > - axleCountingSectionData.points[ - axleCountingSectionData.points.length - 1 - ].x) || - (dir === 'rtl' && - axleCountingSectionData.points[0].x < - axleCountingSectionData.points[ - axleCountingSectionData.points.length - 1 - ].x) - ) { - } - points.forEach((ps) => { - const data = new LogicSectionData(); - data.id = GraphicIdGenerator.next(); - data.axleSectionId = axleCountingSection.id; - // data.code = `${codeAppend.charAt(i % 26)}`; - data.points = ps.map( - (p) => new graphicData.Point({ x: p.x, y: p.y }) - ); - const g = new LogicSection(); - g.loadData(data); - this.drawAssistant.storeGraphic(g); - }); - }); - }; - SectionEditMenu.open(e.global); } } diff --git a/src/graphics/logicSection/LogicSection.ts b/src/graphics/logicSection/LogicSection.ts index 2001de4..18ccec3 100644 --- a/src/graphics/logicSection/LogicSection.ts +++ b/src/graphics/logicSection/LogicSection.ts @@ -16,6 +16,8 @@ export interface ILogicSectionData extends GraphicData { set axleSectionId(v: string); get indexNumber(): number; // 索引编号 set indexNumber(v: number); + get turnoutId(): string; // 关联岔芯的道岔id + set turnoutId(v: string); clone(): ILogicSectionData; copyFrom(data: ILogicSectionData): void; eq(other: ILogicSectionData): boolean; diff --git a/src/graphics/logicSection/LogicSectionDrawAssistant.ts b/src/graphics/logicSection/LogicSectionDrawAssistant.ts index 3b2e637..b3b5a66 100644 --- a/src/graphics/logicSection/LogicSectionDrawAssistant.ts +++ b/src/graphics/logicSection/LogicSectionDrawAssistant.ts @@ -1,4 +1,10 @@ -import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js'; +import { + DisplayObject, + FederatedMouseEvent, + FederatedPointerEvent, + IHitArea, + Point, +} from 'pixi.js'; import { GraphicDrawAssistant, GraphicIdGenerator, @@ -6,6 +12,7 @@ import { JlDrawApp, JlGraphic, linePoint, + splitLineEvenly, } from 'src/jl-graphic'; import { @@ -17,6 +24,11 @@ import { import { Turnout } from '../turnout/Turnout'; import { LogicSectionData } from 'src/drawApp/graphics/LogicSectionInteraction'; import { AxleCountingSection } from '../axleCountingSection/AxleCountingSection'; +import SectionSplitDialog from 'src/components/draw-app/dialogs/SectionSplitDialog.vue'; +import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; +import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; +import { Dialog } from 'quasar'; +import { graphicData } from 'src/protos/stationLayoutGraphics'; export interface ILogicSectionDrawOptions { newData: () => ILogicSectionData; @@ -31,7 +43,7 @@ export class LogicSectionDraw extends GraphicDrawAssistant< super(app, template, 'sym_o_circle', '不展示'); this.codeGraph = this.graphicTemplate.new(); this.container.addChild(this.codeGraph); - LogicSectionInteraction.init(app); + LogicSectionInteraction.init(app, this); } bind(): void { @@ -75,7 +87,10 @@ export class LogicSectionDraw extends GraphicDrawAssistant< logicSection.datas.axleSectionId ) as AxleCountingSection; if (ac) { - map.set(`${logicSection.datas.axleSectionId}`, 1); + map.set( + `${logicSection.datas.axleSectionId}-${logicSection.datas.turnoutId}`, + 1 + ); } else { this.app.deleteGraphics(logicSection); } @@ -85,14 +100,14 @@ export class LogicSectionDraw extends GraphicDrawAssistant< AxleCountingSection.Type ); axleCountingSections.forEach((axleCountingSection) => { - if (map.has(`${axleCountingSection.id}`)) { - return; - } - map.set(`${axleCountingSection.id}`, 1); const turnoutPosRef = axleCountingSection.datas.turnoutPosRef; if (turnoutPosRef.length > 0) { turnoutPosRef.forEach((turnout) => { - if (turnout.position == 1) { + if ( + turnout.position == 1 && + !map.has(`${axleCountingSection.id}-${turnout.id}`) + ) { + map.set(`${axleCountingSection.id}-${turnout.id}`, 1); const t = this.app.queryStore.queryById(turnout.id) as Turnout; const data = new LogicSectionData(); data.points = [ @@ -100,14 +115,18 @@ export class LogicSectionDraw extends GraphicDrawAssistant< ...t.localToCanvasPoints(...t.datas.pointC), ]; data.axleSectionId = axleCountingSection.id; + data.turnoutId = turnout.id; this.draw(data); } }); } - const data = new LogicSectionData(); - data.points = axleCountingSection.datas.points; - data.axleSectionId = axleCountingSection.id; - this.draw(data); + if (!map.has(`${axleCountingSection.id}-`)) { + map.set(`${axleCountingSection.id}-`, 1); + const data = new LogicSectionData(); + data.points = axleCountingSection.datas.points; + data.axleSectionId = axleCountingSection.id; + this.draw(data); + } }); } } @@ -128,13 +147,28 @@ class LogicSectionGraphicHitArea implements IHitArea { } } +export const splitSectionConfig: MenuItemOptions = { + name: '拆分', +}; +const SectionEditMenu: ContextMenu = ContextMenu.init({ + name: '区段编辑菜单', + groups: [ + { + items: [splitSectionConfig], + }, + ], +}); + export class LogicSectionInteraction extends GraphicInteractionPlugin { static Name = 'LogicSection_transform'; - constructor(app: JlDrawApp) { + drawAssistant: LogicSectionDraw; + constructor(app: JlDrawApp, da: LogicSectionDraw) { super(LogicSectionInteraction.Name, app); + this.drawAssistant = da; + app.registerMenu(SectionEditMenu); } - static init(app: JlDrawApp) { - return new LogicSectionInteraction(app); + static init(app: JlDrawApp, da: LogicSectionDraw) { + return new LogicSectionInteraction(app, da); } filter(...grahpics: JlGraphic[]): LogicSection[] | undefined { return grahpics @@ -153,6 +187,7 @@ export class LogicSectionInteraction extends GraphicInteractionPlugin { + Dialog.create({ + title: '拆分逻辑区段', + message: '请选择生成数量和方向', + component: SectionSplitDialog, + cancel: true, + persistent: true, + }).onOk((data: { num: number; dir: 'ltr' | 'rtl' }) => { + const axleSectionId = logicSection.datas.axleSectionId; + const turnoutId = logicSection.datas.turnoutId; + const axleCountingSection = this.app.queryStore.queryById( + axleSectionId + ) as AxleCountingSection; + const logicSections = this.app.queryStore.queryByType( + LogicSection.Type + ); + logicSections.forEach((logicSection) => { + if ( + logicSection.datas.axleSectionId == axleSectionId && + logicSection.datas.turnoutId == turnoutId + ) { + logicSection.selected = false; + this.app.deleteGraphics(logicSection); + } + }); + const { num, dir } = data; + const axleCountingSectionData = axleCountingSection.datas; + let arrP = []; + if (turnoutId) { + const t = this.app.queryStore.queryById(turnoutId) as Turnout; + arrP = [t.position, ...t.localToCanvasPoints(...t.datas.pointC)]; + } else { + arrP = [ + ...axleCountingSection.localToCanvasPoints( + ...axleCountingSectionData.points + ), + ]; + } + const points = splitLineEvenly(arrP[0], arrP[arrP.length - 1], num); + if ( + (dir === 'ltr' && + axleCountingSectionData.points[0].x > + axleCountingSectionData.points[ + axleCountingSectionData.points.length - 1 + ].x) || + (dir === 'rtl' && + axleCountingSectionData.points[0].x < + axleCountingSectionData.points[ + axleCountingSectionData.points.length - 1 + ].x) + ) { + } + points.forEach((ps) => { + const data = new LogicSectionData(); + data.id = GraphicIdGenerator.next(); + data.axleSectionId = axleCountingSection.id; + if (turnoutId) { + data.turnoutId = turnoutId; + } + // data.code = `${codeAppend.charAt(i % 26)}`; + data.points = ps.map( + (p) => new graphicData.Point({ x: p.x, y: p.y }) + ); + const g = new LogicSection(); + g.loadData(data); + this.drawAssistant.storeGraphic(g); + }); + }); + }; + SectionEditMenu.open(e.global); } } diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index 31e8f66..6ce2ec6 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -4172,6 +4172,7 @@ export namespace graphicData { points?: Point[]; axleSectionId?: string; indexNumber?: number; + turnoutId?: string; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [3], this.#one_of_decls); @@ -4191,6 +4192,9 @@ export namespace graphicData { if ("indexNumber" in data && data.indexNumber != undefined) { this.indexNumber = data.indexNumber; } + if ("turnoutId" in data && data.turnoutId != undefined) { + this.turnoutId = data.turnoutId; + } } } get common() { @@ -4226,12 +4230,19 @@ export namespace graphicData { set indexNumber(value: number) { pb_1.Message.setField(this, 5, value); } + get turnoutId() { + return pb_1.Message.getFieldWithDefault(this, 6, "") as string; + } + set turnoutId(value: string) { + pb_1.Message.setField(this, 6, value); + } static fromObject(data: { common?: ReturnType; code?: string; points?: ReturnType[]; axleSectionId?: string; indexNumber?: number; + turnoutId?: string; }): LogicSection { const message = new LogicSection({}); if (data.common != null) { @@ -4249,6 +4260,9 @@ export namespace graphicData { if (data.indexNumber != null) { message.indexNumber = data.indexNumber; } + if (data.turnoutId != null) { + message.turnoutId = data.turnoutId; + } return message; } toObject() { @@ -4258,6 +4272,7 @@ export namespace graphicData { points?: ReturnType[]; axleSectionId?: string; indexNumber?: number; + turnoutId?: string; } = {}; if (this.common != null) { data.common = this.common.toObject(); @@ -4274,6 +4289,9 @@ export namespace graphicData { if (this.indexNumber != null) { data.indexNumber = this.indexNumber; } + if (this.turnoutId != null) { + data.turnoutId = this.turnoutId; + } return data; } serialize(): Uint8Array; @@ -4290,6 +4308,8 @@ export namespace graphicData { writer.writeString(4, this.axleSectionId); if (this.indexNumber != 0) writer.writeInt32(5, this.indexNumber); + if (this.turnoutId.length) + writer.writeString(6, this.turnoutId); if (!w) return writer.getResultBuffer(); } @@ -4314,6 +4334,9 @@ export namespace graphicData { case 5: message.indexNumber = reader.readInt32(); break; + case 6: + message.turnoutId = reader.readString(); + break; default: reader.skipField(); } }