From fb6c01dbfdeab90fc70754c8f3f9716630e7a0d4 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 30 Oct 2024 11:45:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E8=AE=A1=E8=BD=B4=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/SelectConfigUtils.vue | 186 ++++++++++++++++++ .../properties/AxleCountingConfig.vue | 183 +++++++++++++++++ src/drawApp/index.ts | 181 +++++++++-------- .../axleCounting/AxleCountingDrawAssistant.ts | 18 +- src/layouts/DrawLayout.vue | 16 +- src/protos/stationLayoutGraphics.ts | 116 +++++++++++ xian-ncc-da-message | 2 +- 7 files changed, 614 insertions(+), 88 deletions(-) create mode 100644 src/components/common/SelectConfigUtils.vue create mode 100644 src/components/draw-app/properties/AxleCountingConfig.vue diff --git a/src/components/common/SelectConfigUtils.vue b/src/components/common/SelectConfigUtils.vue new file mode 100644 index 0000000..1c1ada4 --- /dev/null +++ b/src/components/common/SelectConfigUtils.vue @@ -0,0 +1,186 @@ + + + diff --git a/src/components/draw-app/properties/AxleCountingConfig.vue b/src/components/draw-app/properties/AxleCountingConfig.vue new file mode 100644 index 0000000..eeb6ccc --- /dev/null +++ b/src/components/draw-app/properties/AxleCountingConfig.vue @@ -0,0 +1,183 @@ + + + diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index ec8da1a..335ae57 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -289,6 +289,9 @@ export function initDrawApp(): IDrawApp { if (app.drawing) return; handleRIghtClick(e); }); + app.on('destroy', () => { + generateAxleCountingConfig = new graphicData.GenerateAxleCountingConfig(); + }); app.addKeyboardListener( new KeyListener({ value: 'KeyS', @@ -299,99 +302,99 @@ export function initDrawApp(): IDrawApp { }, }) ); - // KeyA 用于区段复制--控制生成的区段位置 - const graphicCopyPlugin = app.app.graphicCopyPlugin; - const copySectionListener = new KeyListener({ - value: 'KeyA', - global: true, - onPress: () => { - graphicCopyPlugin.updateMoveLimit('sectionPointLimit'); + // KeyA 用于区段复制--控制生成的区段位置 + const graphicCopyPlugin = app.app.graphicCopyPlugin; + const copySectionListener = new KeyListener({ + value: 'KeyA', + global: true, + onPress: () => { + graphicCopyPlugin.updateMoveLimit('sectionPointLimit'); + }, + }); + graphicCopyPlugin.addGraphicControlers([ + { + controlerList: [copySectionListener], + check: () => { + if ( + graphicCopyPlugin.copys.length == 1 && + graphicCopyPlugin.copys[0].type == Section.Type + ) + return true; + return false; }, - }); - graphicCopyPlugin.addGraphicControlers([ - { - controlerList: [copySectionListener], - check: () => { - if ( - graphicCopyPlugin.copys.length == 1 && - graphicCopyPlugin.copys[0].type == Section.Type - ) - return true; - return false; - }, - moveLimitOption: { - moveLimitName: 'sectionPointLimit', - moveLimit: (e) => { - const mousePos = app.toCanvasCoordinates(e.global); - const selectSection = app.selectedGraphics[0] as Section; - let selectSectionLeft = selectSection.localToCanvasPoint( - selectSection.getStartPoint() + moveLimitOption: { + moveLimitName: 'sectionPointLimit', + moveLimit: (e) => { + const mousePos = app.toCanvasCoordinates(e.global); + const selectSection = app.selectedGraphics[0] as Section; + let selectSectionLeft = selectSection.localToCanvasPoint( + selectSection.getStartPoint() + ); + let selectSectionRight = selectSection.localToCanvasPoint( + selectSection.getEndPoint() + ); + [selectSectionLeft, selectSectionRight] = + selectSectionLeft.x < selectSectionRight.x + ? [selectSectionLeft, selectSectionRight] + : [selectSectionRight, selectSectionLeft]; + //要移动到目标位的区段 + const sections = app.queryStore.queryByType
(Section.Type); + const minDistanceSection = sections.reduce((prev, cur) => { + const prevDistance = calculateDistanceFromPointToLine( + prev.localToCanvasPoint(prev.getStartPoint()), + prev.localToCanvasPoint(prev.getEndPoint()), + mousePos ); - let selectSectionRight = selectSection.localToCanvasPoint( - selectSection.getEndPoint() + const curDistance = calculateDistanceFromPointToLine( + cur.localToCanvasPoint(cur.getStartPoint()), + cur.localToCanvasPoint(cur.getEndPoint()), + mousePos ); - [selectSectionLeft, selectSectionRight] = - selectSectionLeft.x < selectSectionRight.x - ? [selectSectionLeft, selectSectionRight] - : [selectSectionRight, selectSectionLeft]; - //要移动到目标位的区段 - const sections = app.queryStore.queryByType
(Section.Type); - const minDistanceSection = sections.reduce((prev, cur) => { - const prevDistance = calculateDistanceFromPointToLine( - prev.localToCanvasPoint(prev.getStartPoint()), - prev.localToCanvasPoint(prev.getEndPoint()), - mousePos - ); - const curDistance = calculateDistanceFromPointToLine( - cur.localToCanvasPoint(cur.getStartPoint()), - cur.localToCanvasPoint(cur.getEndPoint()), - mousePos - ); - return prevDistance > curDistance || - (prevDistance == curDistance && - distance2( - prev.localToCanvasPoint(prev.getStartPoint()), - mousePos - ) > + return prevDistance > curDistance || + (prevDistance == curDistance && + distance2( + prev.localToCanvasPoint(prev.getStartPoint()), + mousePos + ) > distance2( cur.localToCanvasPoint(cur.getStartPoint()), mousePos )) - ? cur - : prev; - }); - const minDistanceRefSectionsPos = - minDistanceSection.localToCanvasPoint( - getRectangleCenter( - minDistanceSection.lineGraphic.getLocalBounds() - ) - ); - let minDistanceSectionLeft = minDistanceSection.localToCanvasPoint( - minDistanceSection.getStartPoint() + ? cur + : prev; + }); + const minDistanceRefSectionsPos = + minDistanceSection.localToCanvasPoint( + getRectangleCenter( + minDistanceSection.lineGraphic.getLocalBounds() + ) ); - let minDistanceSectionRight = minDistanceSection.localToCanvasPoint( - minDistanceSection.getEndPoint() - ); - [minDistanceSectionLeft, minDistanceSectionRight] = - minDistanceSectionLeft.x < minDistanceSectionRight.x - ? [minDistanceSectionLeft, minDistanceSectionRight] - : [minDistanceSectionRight, minDistanceSectionLeft]; + let minDistanceSectionLeft = minDistanceSection.localToCanvasPoint( + minDistanceSection.getStartPoint() + ); + let minDistanceSectionRight = minDistanceSection.localToCanvasPoint( + minDistanceSection.getEndPoint() + ); + [minDistanceSectionLeft, minDistanceSectionRight] = + minDistanceSectionLeft.x < minDistanceSectionRight.x + ? [minDistanceSectionLeft, minDistanceSectionRight] + : [minDistanceSectionRight, minDistanceSectionLeft]; - if (mousePos.x > minDistanceRefSectionsPos.x) { - graphicCopyPlugin.container.position.x = - minDistanceSectionRight.x - selectSectionLeft.x; - graphicCopyPlugin.container.position.y = - minDistanceSectionRight.y - selectSectionLeft.y; - } else { - graphicCopyPlugin.container.position.x = - minDistanceSectionLeft.x - selectSectionRight.x; - graphicCopyPlugin.container.position.y = - minDistanceSectionLeft.y - selectSectionRight.y; - } - }, + if (mousePos.x > minDistanceRefSectionsPos.x) { + graphicCopyPlugin.container.position.x = + minDistanceSectionRight.x - selectSectionLeft.x; + graphicCopyPlugin.container.position.y = + minDistanceSectionRight.y - selectSectionLeft.y; + } else { + graphicCopyPlugin.container.position.x = + minDistanceSectionLeft.x - selectSectionRight.x; + graphicCopyPlugin.container.position.y = + minDistanceSectionLeft.y - selectSectionRight.y; + } }, }, - ]); + }, + ]); return drawApp; } @@ -557,6 +560,7 @@ export function saveDrawDatas(app: IDrawApp) { // item.pcRef.nid = +item.pcRef.id; // } // }); + storage.generateAxleCountingConfig = generateAxleCountingConfig; const base64 = fromUint8Array(storage.serialize()); console.log('保存数据', storage); // localStorage.setItem(StorageKey, base64); @@ -579,6 +583,7 @@ export async function loadDrawDatas(): Promise { ); console.log('加载数据', storage); const datas: GraphicData[] = []; + generateAxleCountingConfig = storage.generateAxleCountingConfig; storage.links.forEach((link) => { datas.push(new LinkData(link)); }); @@ -642,3 +647,15 @@ export async function loadDrawDatas(): Promise { datas: [], }); } + +//一键生成计轴配置 +let generateAxleCountingConfig = new graphicData.GenerateAxleCountingConfig(); +export function loadGenerateAxleCountingConfig() { + return generateAxleCountingConfig; +} + +export function setGenerateAxleCountingConfig( + newScreenDoorConfig: graphicData.GenerateAxleCountingConfig +) { + generateAxleCountingConfig = newScreenDoorConfig; +} diff --git a/src/graphics/axleCounting/AxleCountingDrawAssistant.ts b/src/graphics/axleCounting/AxleCountingDrawAssistant.ts index b1dbfe7..c2d16a8 100644 --- a/src/graphics/axleCounting/AxleCountingDrawAssistant.ts +++ b/src/graphics/axleCounting/AxleCountingDrawAssistant.ts @@ -20,6 +20,7 @@ import { Turnout, TurnoutPort } from '../turnout/Turnout'; import { IRelatedRefData, createRelatedRefProto } from '../CommonGraphics'; import { Signal } from '../signal/Signal'; import { graphicData } from 'src/protos/stationLayoutGraphics'; +import { loadGenerateAxleCountingConfig } from 'src/drawApp'; export interface IAxleCountingDrawOptions { newData: () => IAxleCountingData; @@ -80,6 +81,21 @@ export class AxleCountingDraw extends GraphicDrawAssistant< refGraphic: Section | Turnout, refPort: TurnoutPort | SectionPort ) { + const generateAxleCountingConfig = loadGenerateAxleCountingConfig(); + if (generateAxleCountingConfig?.noGenerateGroup !== undefined) { + const noGenerateGroup = generateAxleCountingConfig.noGenerateGroup; + for (let i = 0; i < noGenerateGroup.length; i++) { + if ( + noGenerateGroup[i] == graphic.id && + ((i % 2 == 0 && refGraphic.id == noGenerateGroup[i + 1]) || + (i % 2 == 1 && refGraphic.id == noGenerateGroup[i - 1])) + ) { + map.set(`${graphic.id}-${port}`, 1); + map.set(`${refGraphic.id}-${refPort}`, 1); + return; + } + } + } if ( graphic.type == 'Turnout' && reftype == 'Turnout' && @@ -163,7 +179,7 @@ export class AxleCountingDraw extends GraphicDrawAssistant< } return true; }); - this.app.deleteGraphics(...needDelete); + this.app.deleteGraphics(...needDelete); const axleCountingRefs: IRelatedRefData[] = []; axleCountings.forEach((axleCounting) => { axleCountingRefs.push(...axleCounting.datas.axleCountingRef); diff --git a/src/layouts/DrawLayout.vue b/src/layouts/DrawLayout.vue index 4419146..32e0940 100644 --- a/src/layouts/DrawLayout.vue +++ b/src/layouts/DrawLayout.vue @@ -122,8 +122,11 @@ - - + + @@ -189,6 +192,7 @@ import { findContainDevice, handleCentralizedStationsData, } from 'src/graphics/concentrationDividingLine/ConcentrationDividingLineUtils'; +import AxleCountingConfig from 'src/components/draw-app/properties/AxleCountingConfig.vue'; const route = useRoute(); const router = useRouter(); @@ -358,10 +362,14 @@ function oneClickSeparator() { .getDrawAssistant(Separator.Type) as SeparatorDraw; separatorDraw.oneGenerates(); } + +const showGenerateAxleCountingConfig = ref(false); +const closeGenerateAxleCountingConfig = () => { + showGenerateAxleCountingConfig.value = false; +}; function oneClickAxleCounting() { //一键生成计轴 - drawStore.oneClickType = 'AxleCounting'; - drawStore.getDrawApp().interactionPlugin(OneClickGenerate.Type).resume(); + showGenerateAxleCountingConfig.value = true; } function oneClickTurnoutSection() { diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index fcb12d2..fa6cac0 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -28,6 +28,7 @@ export namespace graphicData { separators?: Separator[]; logicSections?: LogicSection[]; concentrationDividingLines?: ConcentrationDividingLine[]; + generateAxleCountingConfig?: GenerateAxleCountingConfig; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], this.#one_of_decls); @@ -92,6 +93,9 @@ export namespace graphicData { if ("concentrationDividingLines" in data && data.concentrationDividingLines != undefined) { this.concentrationDividingLines = data.concentrationDividingLines; } + if ("generateAxleCountingConfig" in data && data.generateAxleCountingConfig != undefined) { + this.generateAxleCountingConfig = data.generateAxleCountingConfig; + } } } get canvas() { @@ -217,6 +221,15 @@ export namespace graphicData { set concentrationDividingLines(value: ConcentrationDividingLine[]) { pb_1.Message.setRepeatedWrapperField(this, 20, value); } + get generateAxleCountingConfig() { + return pb_1.Message.getWrapperField(this, GenerateAxleCountingConfig, 21) as GenerateAxleCountingConfig; + } + set generateAxleCountingConfig(value: GenerateAxleCountingConfig) { + pb_1.Message.setWrapperField(this, 21, value); + } + get has_generateAxleCountingConfig() { + return pb_1.Message.getField(this, 21) != null; + } static fromObject(data: { canvas?: ReturnType; links?: ReturnType[]; @@ -238,6 +251,7 @@ export namespace graphicData { separators?: ReturnType[]; logicSections?: ReturnType[]; concentrationDividingLines?: ReturnType[]; + generateAxleCountingConfig?: ReturnType; }): RtssGraphicStorage { const message = new RtssGraphicStorage({}); if (data.canvas != null) { @@ -300,6 +314,9 @@ export namespace graphicData { if (data.concentrationDividingLines != null) { message.concentrationDividingLines = data.concentrationDividingLines.map(item => ConcentrationDividingLine.fromObject(item)); } + if (data.generateAxleCountingConfig != null) { + message.generateAxleCountingConfig = GenerateAxleCountingConfig.fromObject(data.generateAxleCountingConfig); + } return message; } toObject() { @@ -324,6 +341,7 @@ export namespace graphicData { separators?: ReturnType[]; logicSections?: ReturnType[]; concentrationDividingLines?: ReturnType[]; + generateAxleCountingConfig?: ReturnType; } = {}; if (this.canvas != null) { data.canvas = this.canvas.toObject(); @@ -385,6 +403,9 @@ export namespace graphicData { if (this.concentrationDividingLines != null) { data.concentrationDividingLines = this.concentrationDividingLines.map((item: ConcentrationDividingLine) => item.toObject()); } + if (this.generateAxleCountingConfig != null) { + data.generateAxleCountingConfig = this.generateAxleCountingConfig.toObject(); + } return data; } serialize(): Uint8Array; @@ -431,6 +452,8 @@ export namespace graphicData { writer.writeRepeatedMessage(19, this.logicSections, (item: LogicSection) => item.serialize(writer)); if (this.concentrationDividingLines.length) writer.writeRepeatedMessage(20, this.concentrationDividingLines, (item: ConcentrationDividingLine) => item.serialize(writer)); + if (this.has_generateAxleCountingConfig) + writer.writeMessage(21, this.generateAxleCountingConfig, () => this.generateAxleCountingConfig.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -500,6 +523,9 @@ export namespace graphicData { case 20: reader.readMessage(message.concentrationDividingLines, () => pb_1.Message.addToRepeatedWrapperField(message, 20, ConcentrationDividingLine.deserialize(reader), ConcentrationDividingLine)); break; + case 21: + reader.readMessage(message.generateAxleCountingConfig, () => message.generateAxleCountingConfig = GenerateAxleCountingConfig.deserialize(reader)); + break; default: reader.skipField(); } } @@ -5241,4 +5267,94 @@ export namespace graphicData { return Separator.deserialize(bytes); } } + export class GenerateAxleCountingConfig extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + bbConnect?: number[]; + noGenerateGroup?: number[]; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1, 2], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("bbConnect" in data && data.bbConnect != undefined) { + this.bbConnect = data.bbConnect; + } + if ("noGenerateGroup" in data && data.noGenerateGroup != undefined) { + this.noGenerateGroup = data.noGenerateGroup; + } + } + } + get bbConnect() { + return pb_1.Message.getFieldWithDefault(this, 1, []) as number[]; + } + set bbConnect(value: number[]) { + pb_1.Message.setField(this, 1, value); + } + get noGenerateGroup() { + return pb_1.Message.getFieldWithDefault(this, 2, []) as number[]; + } + set noGenerateGroup(value: number[]) { + pb_1.Message.setField(this, 2, value); + } + static fromObject(data: { + bbConnect?: number[]; + noGenerateGroup?: number[]; + }): GenerateAxleCountingConfig { + const message = new GenerateAxleCountingConfig({}); + if (data.bbConnect != null) { + message.bbConnect = data.bbConnect; + } + if (data.noGenerateGroup != null) { + message.noGenerateGroup = data.noGenerateGroup; + } + return message; + } + toObject() { + const data: { + bbConnect?: number[]; + noGenerateGroup?: number[]; + } = {}; + if (this.bbConnect != null) { + data.bbConnect = this.bbConnect; + } + if (this.noGenerateGroup != null) { + data.noGenerateGroup = this.noGenerateGroup; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.bbConnect.length) + writer.writePackedUint32(1, this.bbConnect); + if (this.noGenerateGroup.length) + writer.writePackedUint32(2, this.noGenerateGroup); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): GenerateAxleCountingConfig { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new GenerateAxleCountingConfig(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.bbConnect = reader.readPackedUint32(); + break; + case 2: + message.noGenerateGroup = reader.readPackedUint32(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): GenerateAxleCountingConfig { + return GenerateAxleCountingConfig.deserialize(bytes); + } + } } diff --git a/xian-ncc-da-message b/xian-ncc-da-message index 4f9012b..91cfbc3 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit 4f9012b0795f62bf352b078ebbc1b1fffa86849d +Subproject commit 91cfbc3ee5574419615ae177661239cdc0d7d53e