diff --git a/src/components/draw-app/properties/TransponderProperty.vue b/src/components/draw-app/properties/TransponderProperty.vue index cac2d44..616d910 100644 --- a/src/components/draw-app/properties/TransponderProperty.vue +++ b/src/components/draw-app/properties/TransponderProperty.vue @@ -49,17 +49,43 @@ @update:model-value="onUpdate" label="应答器类型" > + + + + + + diff --git a/src/drawApp/graphics/TransponderInteraction.ts b/src/drawApp/graphics/TransponderInteraction.ts index 0ea7f03..e0f3c3f 100644 --- a/src/drawApp/graphics/TransponderInteraction.ts +++ b/src/drawApp/graphics/TransponderInteraction.ts @@ -50,6 +50,12 @@ export class TransponderData set kilometerSystem(v: KilometerSystem) { this.data.kilometerSystem = new graphicData.KilometerSystem(v); } + get TransponderRef(): graphicData.RelatedRef { + return this.data.TransponderRef; + } + set TransponderRef(v: graphicData.RelatedRef) { + this.data.TransponderRef = v; + } clone(): TransponderData { return new TransponderData(this.data.cloneMessage()); } diff --git a/src/graphics/transponder/Transponder.ts b/src/graphics/transponder/Transponder.ts index aa4a710..b723262 100644 --- a/src/graphics/transponder/Transponder.ts +++ b/src/graphics/transponder/Transponder.ts @@ -1,11 +1,20 @@ -import { Container, Graphics } from 'pixi.js'; +import { Container, Graphics, Point } from 'pixi.js'; import { GraphicData, + GraphicRelationParam, JlGraphic, JlGraphicTemplate, VectorText, + linePoint, } from 'src/jl-graphic'; import { KilometerSystem } from '../signal/Signal'; +import { + IRelatedRefData, + createRelatedRefProto, + protoPort2Data, +} from '../CommonGraphics'; +import { Section, SectionConsts, SectionPort } from '../section/Section'; +import { Turnout, TurnoutConsts, TurnoutPort } from '../turnout/Turnout'; export interface ITransponderData extends GraphicData { get code(): string; // 编号 @@ -16,6 +25,8 @@ export interface ITransponderData extends GraphicData { set index(v: number); get kilometerSystem(): KilometerSystem; set kilometerSystem(v: KilometerSystem); + get TransponderRef(): IRelatedRefData; + set TransponderRef(v: IRelatedRefData); clone(): ITransponderData; copyFrom(data: ITransponderData): void; eq(other: ITransponderData): boolean; @@ -156,6 +167,102 @@ export class Transponder extends JlGraphic { ); } } + buildRelation() { + this.relationManage.deleteRelationOfGraphic(this); + const { x, y } = this.position; + const sections = this.queryStore.queryByType
(Section.Type); + const findSection = sections.find((section) => { + let s = false; + for (let i = 1; i < section.datas.points.length; i++) { + const p1 = section.datas.points[i - 1]; + const p2 = section.datas.points[i]; + if ( + linePoint( + section.localToCanvasPoint(p1), + section.localToCanvasPoint(p2), + { x, y }, + SectionConsts.lineWidth + ) + ) { + s = true; + break; + } + } + return s; + }); + if (findSection) { + this.relationManage.addRelation( + new GraphicRelationParam(this), + new GraphicRelationParam(findSection, SectionPort.A) + ); + return; + } + let tPort: TurnoutPort | null = null; + const portList = [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C]; + const turnouts = this.queryStore.queryByType(Turnout.Type); + const findTurnout = turnouts.find((turnout) => { + let s = false; + const aPs = turnout.getPortPoints(); + aPs.some((item, index) => { + const Ps = [new Point(0, 0), ...item]; + for (let i = 1; i < Ps.length; i++) { + const p1 = Ps[i - 1]; + const p2 = Ps[i]; + if ( + linePoint( + turnout.localToCanvasPoint(p1), + turnout.localToCanvasPoint(p2), + { x, y }, + TurnoutConsts.lineWidth + ) + ) { + s = true; + tPort = portList[index]; + break; + } + } + return s; + }); + return s; + }); + if (findTurnout) { + this.relationManage.addRelation( + new GraphicRelationParam(this), + new GraphicRelationParam(findTurnout, tPort) + ); + return; + } + } + + saveRelations() { + const relationM = this.relationManage + .getRelationsOfGraphic(this) + .find( + (relation) => + relation.getOtherGraphic(this) instanceof Section || + relation.getOtherGraphic(this) instanceof Turnout + ); + const device = relationM?.getOtherGraphic
(this); + if (device) { + this.datas.TransponderRef = createRelatedRefProto( + device.type, + device.id, + relationM?.getOtherRelationParam(this).param + ); + } + } + + loadRelations() { + if (this.datas?.TransponderRef?.id) { + this.relationManage.addRelation( + new GraphicRelationParam(this), + new GraphicRelationParam( + this.queryStore.queryById(this.datas.TransponderRef.id), + protoPort2Data(this.datas.TransponderRef.devicePort) + ) + ); + } + } } export class TransponderTemplate extends JlGraphicTemplate { diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index 88746bc..8a231ea 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -2950,6 +2950,7 @@ export namespace graphicData { transponderType?: number; index?: number; kilometerSystem?: KilometerSystem; + TransponderRef?: RelatedRef; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); @@ -2969,6 +2970,9 @@ export namespace graphicData { if ("kilometerSystem" in data && data.kilometerSystem != undefined) { this.kilometerSystem = data.kilometerSystem; } + if ("TransponderRef" in data && data.TransponderRef != undefined) { + this.TransponderRef = data.TransponderRef; + } } } get common() { @@ -3007,12 +3011,22 @@ export namespace graphicData { get has_kilometerSystem() { return pb_1.Message.getField(this, 5) != null; } + get TransponderRef() { + return pb_1.Message.getWrapperField(this, RelatedRef, 6) as RelatedRef; + } + set TransponderRef(value: RelatedRef) { + pb_1.Message.setWrapperField(this, 6, value); + } + get has_TransponderRef() { + return pb_1.Message.getField(this, 6) != null; + } static fromObject(data: { common?: ReturnType; code?: string; transponderType?: number; index?: number; kilometerSystem?: ReturnType; + TransponderRef?: ReturnType; }): Transponder { const message = new Transponder({}); if (data.common != null) { @@ -3030,6 +3044,9 @@ export namespace graphicData { if (data.kilometerSystem != null) { message.kilometerSystem = KilometerSystem.fromObject(data.kilometerSystem); } + if (data.TransponderRef != null) { + message.TransponderRef = RelatedRef.fromObject(data.TransponderRef); + } return message; } toObject() { @@ -3039,6 +3056,7 @@ export namespace graphicData { transponderType?: number; index?: number; kilometerSystem?: ReturnType; + TransponderRef?: ReturnType; } = {}; if (this.common != null) { data.common = this.common.toObject(); @@ -3055,6 +3073,9 @@ export namespace graphicData { if (this.kilometerSystem != null) { data.kilometerSystem = this.kilometerSystem.toObject(); } + if (this.TransponderRef != null) { + data.TransponderRef = this.TransponderRef.toObject(); + } return data; } serialize(): Uint8Array; @@ -3071,6 +3092,8 @@ export namespace graphicData { writer.writeInt32(4, this.index); if (this.has_kilometerSystem) writer.writeMessage(5, this.kilometerSystem, () => this.kilometerSystem.serialize(writer)); + if (this.has_TransponderRef) + writer.writeMessage(6, this.TransponderRef, () => this.TransponderRef.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -3095,6 +3118,9 @@ export namespace graphicData { case 5: reader.readMessage(message.kilometerSystem, () => message.kilometerSystem = KilometerSystem.deserialize(reader)); break; + case 6: + reader.readMessage(message.TransponderRef, () => message.TransponderRef = RelatedRef.deserialize(reader)); + break; default: reader.skipField(); } }