From 45599140917a333d46b8d0618efbef0d840bb6e9 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 28 Jun 2023 11:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E8=BD=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../properties/AxleCountingProperty.vue | 36 ++++++- .../graphics/AxleCountingInteraction.ts | 8 +- src/drawApp/index.ts | 17 ++++ src/graphics/CommonGraphics.ts | 2 + src/graphics/axleCounting/AxleCounting.ts | 97 +++++++++++++------ .../axleCounting/AxleCountingDrawAssistant.ts | 44 ++++++++- .../trainWindow/oneClickDrawAssistant.ts | 9 +- src/protos/stationLayoutGraphics.ts | 35 +++---- 8 files changed, 194 insertions(+), 54 deletions(-) diff --git a/src/components/draw-app/properties/AxleCountingProperty.vue b/src/components/draw-app/properties/AxleCountingProperty.vue index 8f6c343..a984bae 100644 --- a/src/components/draw-app/properties/AxleCountingProperty.vue +++ b/src/components/draw-app/properties/AxleCountingProperty.vue @@ -25,14 +25,33 @@ lazy-rules autogrow /> + + + + 关联的区段 +
+ + {{ item }} + +
+
+
+
diff --git a/src/drawApp/graphics/AxleCountingInteraction.ts b/src/drawApp/graphics/AxleCountingInteraction.ts index 23a188b..7498c9c 100644 --- a/src/drawApp/graphics/AxleCountingInteraction.ts +++ b/src/drawApp/graphics/AxleCountingInteraction.ts @@ -37,11 +37,11 @@ export class AxleCountingData set kilometerCode(v: string) { this.data.kilometerCode = v; } - get sectionId(): string[] { - return this.data.sectionId; + get axleCountingRef(): graphicData.RelatedRef[] { + return this.data.axleCountingRef; } - set sectionId(sectionIds: string[]) { - this.data.sectionId = sectionIds; + set axleCountingRef(points: graphicData.RelatedRef[]) { + this.data.axleCountingRef=points } clone(): AxleCountingData { return new AxleCountingData(this.data.cloneMessage()); diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index 4610efd..76733af 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -57,6 +57,12 @@ import { } from 'src/graphics/trainWindow/TrainWindow'; import { TrainWindowDraw } from 'src/graphics/trainWindow/TrainWindowDrawAssistant'; import { TrainWindowData } from './graphics/TrainWindowInteraction'; +import { + AxleCounting, + AxleCountingTemplate, +} from 'src/graphics/axleCounting/AxleCounting'; +import { AxleCountingDraw } from 'src/graphics/axleCounting/AxleCountingDrawAssistant'; +import { AxleCountingData } from './graphics/AxleCountingInteraction'; import { Turnout, TurnoutTemplate } from 'src/graphics/turnout/Turnout'; import { TurnoutDraw } from 'src/graphics/turnout/TurnoutDrawAssistant'; import { TurnoutData } from './graphics/TurnoutInteraction'; @@ -158,6 +164,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { | TrainWindowDraw | TrainDraw | OneClickGenerateDraw + | AxleCountingDraw )[] = []; if (draftType === 'Line') { drawAssistants = [ @@ -178,6 +185,10 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { new TurnoutDraw(app, new TurnoutTemplate(new TurnoutData())), new TrainWindowDraw(app, new TrainWindowTemplate(new TrainWindowData())), new OneClickGenerateDraw(app, new OneClickGenerateTemplate()), + new AxleCountingDraw( + app, + new AxleCountingTemplate(new AxleCountingData()) + ), ]; DrawSignalInteraction.init(app); } else { @@ -291,6 +302,9 @@ export function saveDrawDatas(app: JlDrawApp) { } else if (TrainWindow.Type === g.type) { const trainWindowData = (g as TrainWindow).saveData(); storage.trainWindows.push((trainWindowData as TrainWindowData).data); + } else if (AxleCounting.Type === g.type) { + const axleCountingData = (g as AxleCounting).saveData(); + storage.axleCountings.push((axleCountingData as AxleCountingData).data); } }); const base64 = fromUint8Array(storage.serialize()); @@ -358,6 +372,9 @@ export async function loadDrawDatas(app: GraphicApp) { storage.trainWindows.forEach((trainWindow) => { datas.push(new TrainWindowData(trainWindow)); }); + storage.axleCountings.forEach((axleCounting) => { + datas.push(new AxleCountingData(axleCounting)); + }); app.loadGraphic(datas); } else { app.loadGraphic([]); diff --git a/src/graphics/CommonGraphics.ts b/src/graphics/CommonGraphics.ts index aa8aece..58777ff 100644 --- a/src/graphics/CommonGraphics.ts +++ b/src/graphics/CommonGraphics.ts @@ -4,6 +4,7 @@ import { graphicData } from 'src/protos/stationLayoutGraphics'; import { Turnout, TurnoutPort } from './turnout/Turnout'; import { Section, SectionPort } from './section/Section'; import { TrainWindow } from './trainWindow/TrainWindow'; +import { AxleCounting } from './axleCounting/AxleCounting'; /** * * @param polygon @@ -83,6 +84,7 @@ export function createRelatedRefProto( [Section.Type, graphicData.RelatedRef.DeviceType.Section], [Turnout.Type, graphicData.RelatedRef.DeviceType.Turnout], [TrainWindow.Type, graphicData.RelatedRef.DeviceType.TrainWindow], + [AxleCounting.Type, graphicData.RelatedRef.DeviceType.AxleCounting], ]); const protoDeviceType = typeMap.get(type); if (protoDeviceType === undefined) throw Error(`输入的type有误: ${type}`); diff --git a/src/graphics/axleCounting/AxleCounting.ts b/src/graphics/axleCounting/AxleCounting.ts index 0e078ad..d8da59a 100644 --- a/src/graphics/axleCounting/AxleCounting.ts +++ b/src/graphics/axleCounting/AxleCounting.ts @@ -1,24 +1,32 @@ import { Color, Container, Graphics } from 'pixi.js'; import { GraphicData, + GraphicRelationParam, JlGraphic, JlGraphicTemplate, VectorText, } from 'src/jl-graphic'; +import { Section, SectionPort } from '../section/Section'; +import { + IRelatedRefData, + createRelatedRefProto, + protoPort2Data, +} from '../CommonGraphics'; +import { Turnout } from '../turnout/Turnout'; export interface IAxleCountingData extends GraphicData { get code(): string; // 编号 set code(v: string); get kilometerCode(): string; // 公里标 set kilometerCode(v: string); - get sectionId(): string[]; // 计轴两端的区段 - set sectionId(points: string[]); + get axleCountingRef(): IRelatedRefData[]; //关联的设备 + set axleCountingRef(ref: IRelatedRefData[]); clone(): IAxleCountingData; copyFrom(data: IAxleCountingData): void; eq(other: IAxleCountingData): boolean; } -const AxleCountingConsts = { +export const AxleCountingConsts = { radius: 6, borderWidth: 1, circleColorBlue: '0x08F80D', @@ -28,6 +36,7 @@ const AxleCountingConsts = { kilometerCodeColor: '0xFFFFFF', kilometerCodeFontSize: 14, kilometerCodeOffsetY: 95, + offsetSection: 50, }; class TwoCircleGraphic extends Container { circleA: Graphics = new Graphics(); @@ -68,11 +77,13 @@ export class AxleCounting extends JlGraphic { static Type = 'AxleCounting'; twoCircle: TwoCircleGraphic = new TwoCircleGraphic(); kilometerGraph: VectorText = new VectorText(''); //公里标 - constructor() { + direction: number; + constructor(direction: number) { super(AxleCounting.Type); this.addChild(this.twoCircle); this.addChild(this.kilometerGraph); this.kilometerGraph.name = 'kilometer'; + this.direction = direction; } get datas(): IAxleCountingData { @@ -80,29 +91,59 @@ export class AxleCounting extends JlGraphic { } doRepaint(): void { this.twoCircle.draw(); - const kilometerGraph = this.kilometerGraph; - const kilometerCode = this.datas?.kilometerCode || 12345.6789; - if (Math.floor(Number(kilometerCode)).toString().length > 3) { - const kiloBit = Math.floor(Number(kilometerCode) / 1000).toString(); - kilometerGraph.text = - 'K' + - kiloBit + - '+' + - kilometerCode.toString().substring(kiloBit.length); - } else { - kilometerGraph.text = kilometerCode; - } - kilometerGraph.style.fill = AxleCountingConsts.kilometerCodeColor; - kilometerGraph.setVectorFontSize(AxleCountingConsts.kilometerCodeFontSize); - kilometerGraph.anchor.set(0.5); - kilometerGraph.position.set(0, AxleCountingConsts.kilometerCodeOffsetY); - kilometerGraph.rotation = -Math.PI / 2; - if (this.datas.childTransforms?.length) { - this.datas.childTransforms.forEach((child) => { - if (child.name == 'kilometer') { - const pos = child.transform.position; - kilometerGraph.position.set(pos.x, pos.y); - } + } + buildRelation() { + this.queryStore.queryByType
(Section.Type).forEach((section) => { + const ps = section.localToCanvasPoint(section.getStartPoint()); + const pe = section.localToCanvasPoint(section.getEndPoint()); + let param = ''; + if ( + ps.x == this.x && + ps.y == this.y + AxleCountingConsts.offsetSection * this.direction + ) { + param = SectionPort.A; + } + if ( + pe.x == this.x && + pe.y == this.y + AxleCountingConsts.offsetSection * this.direction + ) { + param = SectionPort.B; + } + + if (param !== '') { + this.relationManage.addRelation( + this, + new GraphicRelationParam(section, param) + ); + } + }); + } + saveRelations() { + const sectionRelations = + this.relationManage.getRelationsOfGraphicAndOtherType(this, Section.Type); + const datas: IRelatedRefData[] = []; + sectionRelations.forEach((ref) => { + const paDevice = ref.getOtherGraphic
(this); + const data = createRelatedRefProto( + paDevice.type, + paDevice.id, + ref.getOtherRelationParam(this).param + ); + + datas.push(data); + }); + this.datas.axleCountingRef = datas; + } + loadRelations(): void { + if (this.datas.axleCountingRef.length) { + this.datas.axleCountingRef.forEach((device) => { + this.relationManage.addRelation( + this, + new GraphicRelationParam( + this.queryStore.queryById(device.id), + protoPort2Data(device.devicePort) + ) + ); }); } } @@ -115,7 +156,7 @@ export class AxleCountingTemplate extends JlGraphicTemplate { }); } new(): AxleCounting { - const axleCounting = new AxleCounting(); + const axleCounting = new AxleCounting(1); axleCounting.loadData(this.datas); return axleCounting; } diff --git a/src/graphics/axleCounting/AxleCountingDrawAssistant.ts b/src/graphics/axleCounting/AxleCountingDrawAssistant.ts index 11dd038..786fce3 100644 --- a/src/graphics/axleCounting/AxleCountingDrawAssistant.ts +++ b/src/graphics/axleCounting/AxleCountingDrawAssistant.ts @@ -1,8 +1,9 @@ -import { FederatedPointerEvent, Point } from 'pixi.js'; +import { FederatedPointerEvent, IPointData, Point } from 'pixi.js'; import { AbsorbableLine, AbsorbablePosition, GraphicDrawAssistant, + GraphicIdGenerator, GraphicInteractionPlugin, JlDrawApp, JlGraphic, @@ -12,7 +13,10 @@ import { IAxleCountingData, AxleCounting, AxleCountingTemplate, + AxleCountingConsts, } from './AxleCounting'; +import { Section } from '../section/Section'; +import { Turnout } from '../turnout/Turnout'; export interface IAxleCountingDrawOptions { newData: () => IAxleCountingData; @@ -24,7 +28,7 @@ export class AxleCountingDraw extends GraphicDrawAssistant< > { codeGraph: AxleCounting; constructor(app: JlDrawApp, template: AxleCountingTemplate) { - super(app, template, 'sym_o_circle', '计轴AxleCounting'); + super(app, template, 'sym_o_circle', '不展示'); this.codeGraph = this.graphicTemplate.new(); this.container.addChild(this.codeGraph); AxleCountingInteraction.init(app); @@ -51,6 +55,42 @@ export class AxleCountingDraw extends GraphicDrawAssistant< data.transform = this.container.saveTransform(); return true; } + oneGenerates(height: Point) { + const sections = this.app.queryStore.queryByType
(Section.Type); + const turnouts = this.app.queryStore.queryByType(Turnout.Type); + const axleCounting = this.app.queryStore.queryByType( + AxleCounting.Type + ); + this.app.deleteGraphics(...axleCounting); + sections.forEach((section) => { + const ps = section.localToCanvasPoint(section.getStartPoint()); + let direction = 1; + if (ps.y > height.y) { + direction = -1; + } + const axleCounting = new AxleCounting(direction); + axleCounting.loadData(this.graphicTemplate.datas); + axleCounting.position.set( + ps.x, + ps.y - AxleCountingConsts.offsetSection * direction + ); + axleCounting.id = GraphicIdGenerator.next(); + this.storeGraphic(axleCounting); + }); + turnouts.forEach((turnout) => { + const points = turnout.datas.pointA; + const transPos = turnout.datas.transform.position; + const ps: IPointData[] = []; + points.forEach((point: IPointData) => { + ps.push(new Point(point.x + transPos.x, point.y + transPos.y)); + }); + const axleCounting = new AxleCounting(1); + axleCounting.loadData(this.graphicTemplate.datas); + axleCounting.position.set(ps[0].x, ps[0].y); + axleCounting.id = GraphicIdGenerator.next(); + this.storeGraphic(axleCounting); + }); + } } function buildAbsorbablePositions( diff --git a/src/graphics/trainWindow/oneClickDrawAssistant.ts b/src/graphics/trainWindow/oneClickDrawAssistant.ts index 73b107a..de16338 100644 --- a/src/graphics/trainWindow/oneClickDrawAssistant.ts +++ b/src/graphics/trainWindow/oneClickDrawAssistant.ts @@ -8,6 +8,8 @@ import { } from 'src/jl-graphic'; import { TrainWindow } from './TrainWindow'; import { TrainWindowDraw } from './TrainWindowDrawAssistant'; +import { AxleCounting } from '../axleCounting/AxleCounting'; +import { AxleCountingDraw } from '../axleCounting/AxleCountingDrawAssistant'; interface IOneClickData extends GraphicData { get code(): string; // 编号 @@ -39,7 +41,7 @@ export class OneClickGenerateTemplate extends JlGraphicTemplate { lineGraph: OneClickGenerate; @@ -54,11 +56,14 @@ OneClickGenerateTemplate, this.lineGraph.doRepaint(); } onLeftDown(e: FederatedPointerEvent): void { - this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); const trainWindowDraw = this.app.getDrawAssistant( TrainWindow.Type ) as TrainWindowDraw; trainWindowDraw.oneGenerates(this.toCanvasCoordinates(e.global)); + const axleCountingDraw = this.app.getDrawAssistant( + AxleCounting.Type + ) as AxleCountingDraw; + axleCountingDraw.oneGenerates(this.toCanvasCoordinates(e.global)); this.finish(); } diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index 205bb3d..73f1d9f 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -2192,7 +2192,7 @@ export namespace graphicData { common?: CommonInfo; code?: string; kilometerCode?: string; - sectionId?: string[]; + axleCountingRef?: RelatedRef[]; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4], this.#one_of_decls); @@ -2206,8 +2206,8 @@ export namespace graphicData { if ("kilometerCode" in data && data.kilometerCode != undefined) { this.kilometerCode = data.kilometerCode; } - if ("sectionId" in data && data.sectionId != undefined) { - this.sectionId = data.sectionId; + if ("axleCountingRef" in data && data.axleCountingRef != undefined) { + this.axleCountingRef = data.axleCountingRef; } } } @@ -2232,17 +2232,17 @@ export namespace graphicData { set kilometerCode(value: string) { pb_1.Message.setField(this, 3, value); } - get sectionId() { - return pb_1.Message.getFieldWithDefault(this, 4, []) as string[]; + get axleCountingRef() { + return pb_1.Message.getRepeatedWrapperField(this, RelatedRef, 4) as RelatedRef[]; } - set sectionId(value: string[]) { - pb_1.Message.setField(this, 4, value); + set axleCountingRef(value: RelatedRef[]) { + pb_1.Message.setRepeatedWrapperField(this, 4, value); } static fromObject(data: { common?: ReturnType; code?: string; kilometerCode?: string; - sectionId?: string[]; + axleCountingRef?: ReturnType[]; }): AxleCounting { const message = new AxleCounting({}); if (data.common != null) { @@ -2254,8 +2254,8 @@ export namespace graphicData { if (data.kilometerCode != null) { message.kilometerCode = data.kilometerCode; } - if (data.sectionId != null) { - message.sectionId = data.sectionId; + if (data.axleCountingRef != null) { + message.axleCountingRef = data.axleCountingRef.map(item => RelatedRef.fromObject(item)); } return message; } @@ -2264,7 +2264,7 @@ export namespace graphicData { common?: ReturnType; code?: string; kilometerCode?: string; - sectionId?: string[]; + axleCountingRef?: ReturnType[]; } = {}; if (this.common != null) { data.common = this.common.toObject(); @@ -2275,8 +2275,8 @@ export namespace graphicData { if (this.kilometerCode != null) { data.kilometerCode = this.kilometerCode; } - if (this.sectionId != null) { - data.sectionId = this.sectionId; + if (this.axleCountingRef != null) { + data.axleCountingRef = this.axleCountingRef.map((item: RelatedRef) => item.toObject()); } return data; } @@ -2290,8 +2290,8 @@ export namespace graphicData { writer.writeString(2, this.code); if (this.kilometerCode.length) writer.writeString(3, this.kilometerCode); - if (this.sectionId.length) - writer.writeRepeatedString(4, this.sectionId); + if (this.axleCountingRef.length) + writer.writeRepeatedMessage(4, this.axleCountingRef, (item: RelatedRef) => item.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -2311,7 +2311,7 @@ export namespace graphicData { message.kilometerCode = reader.readString(); break; case 4: - pb_1.Message.addToRepeatedField(message, 4, reader.readString()); + reader.readMessage(message.axleCountingRef, () => pb_1.Message.addToRepeatedWrapperField(message, 4, RelatedRef.deserialize(reader), RelatedRef)); break; default: reader.skipField(); } @@ -3784,7 +3784,8 @@ export namespace graphicData { export enum DeviceType { Section = 0, Turnout = 1, - TrainWindow = 2 + TrainWindow = 2, + AxleCounting = 3 } export enum DevicePort { A = 0,