From 25d80c79eac3f75fe9f737acca006a34c0547ba7 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Mon, 7 Aug 2023 13:35:25 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E5=88=86=E9=9A=94=E7=AC=A6=E5=92=8C?= =?UTF-8?q?=E5=BA=94=E7=AD=94=E5=99=A8=E7=A2=B0=E6=92=9E=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../separator/SeparatorDrawAssistant.ts | 29 ++--------------- src/graphics/transponder/Transponder.ts | 2 ++ .../transponder/TransponderDrawAssistant.ts | 31 +------------------ 3 files changed, 6 insertions(+), 56 deletions(-) diff --git a/src/graphics/separator/SeparatorDrawAssistant.ts b/src/graphics/separator/SeparatorDrawAssistant.ts index 54482cd..83b5b10 100644 --- a/src/graphics/separator/SeparatorDrawAssistant.ts +++ b/src/graphics/separator/SeparatorDrawAssistant.ts @@ -7,6 +7,7 @@ import { JlDrawApp, JlGraphic, linePoint, + pointBox, } from 'src/jl-graphic'; import { Section, SectionType } from '../section/Section'; import { @@ -208,32 +209,8 @@ export class SeparatorGraphicHitArea implements IHitArea { contains(x: number, y: number): boolean { let contains = false; const p = new Point(x, y); - const typeArr = ['section', 'turnout']; - const endTypeArr = ['endA', 'endB']; - let d = SeparatorConsts.radius; - if (typeArr.includes(this.separator.datas.separatorType)) { - const tolerance = SeparatorConsts.lineWidth; - const p1 = new Point(0, -SeparatorConsts.height / 2); - const p2 = new Point(0, SeparatorConsts.height / 2); - contains = contains || linePoint(p1, p2, p, tolerance); - return contains; - } else if (endTypeArr.includes(this.separator.datas.separatorType)) { - if (this.separator.datas.separatorType == 'endB') { - d = -d; - } - const tolerance = SeparatorConsts.lineWidth; - const p1 = new Point(0, 0); - const p2 = new Point(-d, 0); - const p3 = new Point(-d, -d); - const p4 = new Point(-d * 3, -d); - const p5 = new Point(-d, d); - const p6 = new Point(-d * 3, d); - contains = contains || linePoint(p1, p2, p, tolerance); - contains = contains || linePoint(p2, p3, p, tolerance); - contains = contains || linePoint(p3, p4, p, tolerance); - contains = contains || linePoint(p2, p5, p, tolerance); - contains = contains || linePoint(p5, p6, p, tolerance); - } + const r = this.separator.getLocalBounds(); + contains = pointBox(p, r); return contains; } } diff --git a/src/graphics/transponder/Transponder.ts b/src/graphics/transponder/Transponder.ts index b723262..ff5e875 100644 --- a/src/graphics/transponder/Transponder.ts +++ b/src/graphics/transponder/Transponder.ts @@ -136,6 +136,7 @@ export class Transponder extends JlGraphic { ? TransponderConsts.wblineColor : TransponderConsts.lineColor; polygonGraphic.lineStyle(TransponderConsts.lineWidth, lineColor); + polygonGraphic.beginFill(TransponderConsts.lineColor, 0.00001); // 填充透明色(用于碰撞检测) const indexArr = [0, 5, 7]; ps.forEach((item, index) => { if (indexArr.includes(index)) { @@ -144,6 +145,7 @@ export class Transponder extends JlGraphic { polygonGraphic.lineTo(item[0], item[1]); } }); + polygonGraphic.endFill; this.labelGraphic.paint(this.datas); const style = { fill: lineColor, diff --git a/src/graphics/transponder/TransponderDrawAssistant.ts b/src/graphics/transponder/TransponderDrawAssistant.ts index 07ce9ab..698cd7b 100644 --- a/src/graphics/transponder/TransponderDrawAssistant.ts +++ b/src/graphics/transponder/TransponderDrawAssistant.ts @@ -1,4 +1,4 @@ -import { DisplayObject, FederatedPointerEvent, IHitArea, Point } from 'pixi.js'; +import { DisplayObject, FederatedPointerEvent, Point } from 'pixi.js'; import { AbsorbableLine, AbsorbablePosition, @@ -7,15 +7,11 @@ import { GraphicTransformEvent, JlDrawApp, JlGraphic, - linePoint, } from 'src/jl-graphic'; import { ITransponderData, Transponder, - TransponderConsts, TransponderTemplate, - transponderTypeEnum, - transponderTypePoints, } from './Transponder'; export class TransponderDraw extends GraphicDrawAssistant< @@ -51,30 +47,6 @@ export class TransponderDraw extends GraphicDrawAssistant< } } -//碰撞检测 -export class TransponderGraphicHitArea implements IHitArea { - transponder: Transponder; - constructor(transponder: Transponder) { - this.transponder = transponder; - } - contains(x: number, y: number): boolean { - let contains = false; - const p = new Point(x, y); - const type = transponderTypeEnum[this.transponder.datas.transponderType]; - const ps = transponderTypePoints[type]; - const tolerance = TransponderConsts.lineWidth; - const indexArr = [0, 5, 7]; - ps.forEach((item, index) => { - if (!indexArr.includes(index)) { - const p1 = new Point(ps[index - 1][0], ps[index - 1][1]); - const p2 = new Point(item[0], item[1]); - contains = contains || linePoint(p1, p2, p, tolerance); - } - }); - return contains; - } -} - export class TransponderInteraction extends GraphicInteractionPlugin { static Name = 'Transponder_transform'; constructor(app: JlDrawApp) { @@ -92,7 +64,6 @@ export class TransponderInteraction extends GraphicInteractionPlugin Date: Mon, 7 Aug 2023 13:52:32 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E5=9D=A1=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/slope/Slope.ts | 13 ++++++- src/graphics/slope/SlopeAssistant.ts | 58 ++++++++++++++++------------ 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/graphics/slope/Slope.ts b/src/graphics/slope/Slope.ts index 3cbf485..3d22e23 100644 --- a/src/graphics/slope/Slope.ts +++ b/src/graphics/slope/Slope.ts @@ -6,6 +6,7 @@ import { VectorText, calculateLineMidpoint, } from 'src/jl-graphic'; +import { SlopeKiloMarker } from '../slopeKiloMarker/SlopeKiloMarker'; export interface ISlopeData extends GraphicData { get points(): IPointData[]; // 线坐标点 set points(points: IPointData[]); @@ -21,7 +22,7 @@ export interface ISlopeData extends GraphicData { export const SlopeConsts = { lineColor: '0xffffff', lineWidth: 2, - height: 40, + height: 100, }; export class Slope extends JlGraphic { @@ -90,7 +91,15 @@ export class Slope extends JlGraphic { this.slopeNumber.position.set(centerPos.x, centerPos.y - 15); } //坡度长度 - this.slopeLong.text = this.datas.refDeviceId[1]; + const slopeKiloMarkerL = this.queryStore.queryById( + this.datas.refDeviceId[0] + ) as SlopeKiloMarker; + const slopeKiloMarkerR = this.queryStore.queryById( + this.datas.refDeviceId[1] + ) as SlopeKiloMarker; + this.slopeLong.text = + slopeKiloMarkerR.datas.kilometerSystem.kilometer - + slopeKiloMarkerL.datas.kilometerSystem.kilometer; const slopeLongPosition = this.datas.childTransforms?.find( (t) => t.name === this.slopeLong.name )?.transform.position; diff --git a/src/graphics/slope/SlopeAssistant.ts b/src/graphics/slope/SlopeAssistant.ts index 6c46148..93e7891 100644 --- a/src/graphics/slope/SlopeAssistant.ts +++ b/src/graphics/slope/SlopeAssistant.ts @@ -9,7 +9,7 @@ import { } from 'src/jl-graphic'; import { ISlopeData, Slope, SlopeTemplate, SlopeConsts } from './Slope'; -import { AxleCounting } from '../axleCounting/AxleCounting'; +import { SlopeKiloMarker } from '../slopeKiloMarker/SlopeKiloMarker'; export interface ISlopeDrawOptions { newData: () => ISlopeData; @@ -44,7 +44,7 @@ export class SlopeDraw extends GraphicDrawAssistant { data.transform = this.container.saveTransform(); return true; } - draw(graphics: AxleCounting[], map: Map) { + draw(graphics: SlopeKiloMarker[], map: Map) { if ( map.has(`${graphics[0].id}+${graphics[1].id}`) || map.has(`${graphics[1].id}+${graphics[0].id}`) @@ -61,29 +61,38 @@ export class SlopeDraw extends GraphicDrawAssistant { } oneGenerates() { const map = new Map(); - const slopes = this.app.queryStore.queryByType(Slope.Type); - const axleCountings = this.app.queryStore.queryByType( - AxleCounting.Type - ); - axleCountings.sort((a, b) => a.position.x - b.position.x); - const axleCountingsPos = axleCountings.map((g) => g.position.x); - //检验坡度有效性--是否有增加和删除 - slopes.forEach((slope) => { - const pS = slope.datas.points[0].x; - const mapS = axleCountingsPos.findIndex((x) => x == pS); - const pE = slope.datas.points[1].x; - const mapE = axleCountingsPos.findIndex((x) => x == pE); - if (mapS !== -1 && mapE !== -1 && mapE - mapS == 1) { - map.set( - `${slope.datas.refDeviceId[0]}+${slope.datas.refDeviceId[1]}`, - 1 - ); - } else { - this.app.deleteGraphics(slope); + for (let dirSlop = 0; dirSlop < 2; dirSlop++) { + const slopes = this.app.queryStore + .queryByType(Slope.Type) + .filter((g) => { + const refSlopeKiloMarker = this.app.queryStore.queryById( + g.datas.refDeviceId[0] + ) as SlopeKiloMarker; + return refSlopeKiloMarker.datas.direction == dirSlop; + }); + const slopeKiloMarkers = this.app.queryStore + .queryByType(SlopeKiloMarker.Type) + .filter((g) => g.datas.direction == dirSlop); + slopeKiloMarkers.sort((a, b) => a.position.x - b.position.x); + const slopeKiloMarkersPos = slopeKiloMarkers.map((g) => g.position.x); + //检验坡度有效性--是否有增加和删除 + slopes.forEach((slope) => { + const pS = slope.datas.points[0].x; + const mapS = slopeKiloMarkersPos.findIndex((x) => x == pS); + const pE = slope.datas.points[1].x; + const mapE = slopeKiloMarkersPos.findIndex((x) => x == pE); + if (mapS !== -1 && mapE !== -1 && mapE - mapS == 1) { + map.set( + `${slope.datas.refDeviceId[0]}+${slope.datas.refDeviceId[1]}`, + 1 + ); + } else { + this.app.deleteGraphics(slope); + } + }); + for (let i = 0; i < slopeKiloMarkers.length - 1; i++) { + this.draw([slopeKiloMarkers[i], slopeKiloMarkers[i + 1]], map); } - }); - for (let i = 0; i < axleCountings.length - 1; i++) { - this.draw([axleCountings[i], axleCountings[i + 1]], map); } } } @@ -119,6 +128,7 @@ export class SlopeInteraction extends GraphicInteractionPlugin { g.eventMode = 'static'; g.cursor = 'pointer'; g.scalable = true; + g.draggable = false; g.transformSave = true; g.lineGraphic.eventMode = 'static'; g.lineGraphic.cursor = 'pointer'; From c175ef86a7dd2e80728a9ba739c1f3c4efb75738 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Mon, 7 Aug 2023 14:03:05 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/separator/SeparatorDrawAssistant.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/graphics/separator/SeparatorDrawAssistant.ts b/src/graphics/separator/SeparatorDrawAssistant.ts index 83b5b10..3413514 100644 --- a/src/graphics/separator/SeparatorDrawAssistant.ts +++ b/src/graphics/separator/SeparatorDrawAssistant.ts @@ -6,14 +6,12 @@ import { GraphicRelationParam, JlDrawApp, JlGraphic, - linePoint, pointBox, } from 'src/jl-graphic'; import { Section, SectionType } from '../section/Section'; import { ISeparatorData, Separator, - SeparatorConsts, SeparatorTemplate, separatorTypeEnum, } from './Separator'; From 961683116c908a9ac7a601312f8a612e19cc2c67 Mon Sep 17 00:00:00 2001 From: Yuan Date: Mon, 7 Aug 2023 15:06:03 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E5=9D=A1=E5=BA=A6=E5=85=AC=E9=87=8C?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bj-rtss-message | 2 +- .../properties/KiloMarkerProperty.vue | 58 +++++- .../draw-app/properties/SignalProperty.vue | 9 +- .../draw-app/properties/TurnoutProperty.vue | 6 +- .../graphics/SlopeKiloMarkerInteraction.ts | 15 +- src/drawApp/index.ts | 1 + src/drawApp/lineApp.ts | 3 + .../kilometerMarker/KilometerMarker.ts | 1 + src/graphics/signal/Signal.ts | 8 + .../slopeKiloMarker/SlopeKiloMarker.ts | 25 ++- .../SlopeKiloMarkerDrawAssistant.ts | 24 ++- src/protos/stationLayoutGraphics.ts | 185 +++++++----------- 12 files changed, 195 insertions(+), 142 deletions(-) diff --git a/bj-rtss-message b/bj-rtss-message index 86bf1f0..b62e9b1 160000 --- a/bj-rtss-message +++ b/bj-rtss-message @@ -1 +1 @@ -Subproject commit 86bf1f0c76ade5866afd8063e8f263ca9eda55a5 +Subproject commit b62e9b13e4b667b8f5aa47cae3a4cb7181a4f40c diff --git a/src/components/draw-app/properties/KiloMarkerProperty.vue b/src/components/draw-app/properties/KiloMarkerProperty.vue index e36730f..d78ef86 100644 --- a/src/components/draw-app/properties/KiloMarkerProperty.vue +++ b/src/components/draw-app/properties/KiloMarkerProperty.vue @@ -6,7 +6,18 @@ import { reactive, shallowRef, watchEffect } from 'vue'; const drawStore = useDrawStore(); const kiloMarkerModel = shallowRef(new SlopeKiloMarkerData()); -const kilometerSystem = reactive({ coordinateSystem: '', kilometer: 0 }); +const kilometerSystem = reactive([ + { + coordinateSystem: '', + kilometer: 0, + direction: 0, + }, + { + coordinateSystem: '', + kilometer: 0, + direction: 0, + }, +]); const CoordinateSystemOptions = [ { label: '车辆段', value: 'DEPOT' }, @@ -22,11 +33,24 @@ watchEffect(() => { const kiloMarker = drawStore.selectedGraphic; if (kiloMarker && kiloMarker instanceof SlopeKiloMarker) { kiloMarkerModel.value = kiloMarker.saveData(); + if (kiloMarkerModel.value.kilometerSystem.length > 0) { + kilometerSystem.forEach((ks, i) => { + ks.coordinateSystem = + kiloMarkerModel.value.kilometerSystem[i].coordinateSystem; + ks.kilometer = kiloMarkerModel.value.kilometerSystem[i].kilometer; + ks.direction = kiloMarkerModel.value.kilometerSystem[i].direction; + }); + } } }); const onUpdate = () => { const kiloMarker = drawStore.selectedGraphic as SlopeKiloMarker; + kiloMarkerModel.value.kilometerSystem = kilometerSystem.map((ks) => ({ + coordinateSystem: ks.coordinateSystem, + kilometer: ks.kilometer, + direction: ks.direction, + })); if (kiloMarker) { drawStore .getDrawApp() @@ -55,7 +79,7 @@ const onUpdate = () => { /> --> { > + + + import { SignalData } from 'src/drawApp/graphics/SignalInteraction'; import { Section } from 'src/graphics/section/Section'; -import { Signal } from 'src/graphics/signal/Signal'; +import { Direction, Signal } from 'src/graphics/signal/Signal'; import { Turnout } from 'src/graphics/turnout/Turnout'; import { graphicData } from 'src/protos/stationLayoutGraphics'; import { useDrawStore } from 'src/stores/draw-store'; @@ -89,7 +89,11 @@ import { onMounted, reactive, watch } from 'vue'; const drawStore = useDrawStore(); const signalModel = reactive(new SignalData()); -const kilometerSystem = reactive({ coordinateSystem: '', kilometer: 0 }); +const kilometerSystem = reactive({ + coordinateSystem: '', + kilometer: 0, + direction: Direction.LEFT, +}); const sectionList: { label: string; value: string }[] = reactive([]); const turnoutList: { label: string; value: string }[] = reactive([]); const refDevData = reactive({ @@ -168,6 +172,7 @@ function onUpdate() { signalModel.kilometerSystem = { coordinateSystem: kilometerSystem.coordinateSystem, kilometer: kilometerSystem.kilometer, + direction: kilometerSystem.direction, }; if (refDevData.id) { signalModel.refDev = new graphicData.RelatedRef({ diff --git a/src/components/draw-app/properties/TurnoutProperty.vue b/src/components/draw-app/properties/TurnoutProperty.vue index 71ca4bc..65d64b5 100644 --- a/src/components/draw-app/properties/TurnoutProperty.vue +++ b/src/components/draw-app/properties/TurnoutProperty.vue @@ -80,6 +80,7 @@ diff --git a/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue b/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue new file mode 100644 index 0000000..e0c038d --- /dev/null +++ b/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue @@ -0,0 +1,134 @@ + + + + + diff --git a/src/components/draw-app/properties/KiloMarkerProperty.vue b/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue similarity index 100% rename from src/components/draw-app/properties/KiloMarkerProperty.vue rename to src/components/draw-app/properties/SlopeKiloMarkerProperty.vue diff --git a/src/drawApp/graphics/CurvatureKiloMarkerInteraction.ts b/src/drawApp/graphics/CurvatureKiloMarkerInteraction.ts new file mode 100644 index 0000000..12f43db --- /dev/null +++ b/src/drawApp/graphics/CurvatureKiloMarkerInteraction.ts @@ -0,0 +1,52 @@ +import * as pb_1 from 'google-protobuf'; +import { GraphicDataBase } from './GraphicDataBase'; +import { graphicData } from 'src/protos/stationLayoutGraphics'; +import { KilometerSystem } from 'src/graphics/signal/Signal'; +import { IKiloMarkerData } from 'src/graphics/kilometerMarker/KilometerMarker'; +import { CurvatureKiloMarker } from 'src/graphics/curvatureKiloMarker/CurvatureKiloMarker'; + +export class CurvatureKiloMarkerData + extends GraphicDataBase + implements IKiloMarkerData +{ + constructor(data?: graphicData.CurvatureKiloMarker) { + let platform; + if (!data) { + platform = new graphicData.CurvatureKiloMarker({ + common: GraphicDataBase.defaultCommonInfo(CurvatureKiloMarker.Type), + }); + } else { + platform = data; + } + super(platform); + } + + public get data(): graphicData.CurvatureKiloMarker { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + get kilometerSystem(): KilometerSystem[] { + return this.data.kilometerSystem; + } + set kilometerSystem(value: KilometerSystem[]) { + this.data.kilometerSystem = value.map( + (v) => new graphicData.KilometerSystem(v) + ); + } + + clone(): CurvatureKiloMarkerData { + return new CurvatureKiloMarkerData(this.data.cloneMessage()); + } + copyFrom(data: CurvatureKiloMarkerData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: CurvatureKiloMarkerData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/graphics/SlopeKiloMarkerInteraction.ts b/src/drawApp/graphics/SlopeKiloMarkerInteraction.ts index 0ea33e4..76f0aca 100644 --- a/src/drawApp/graphics/SlopeKiloMarkerInteraction.ts +++ b/src/drawApp/graphics/SlopeKiloMarkerInteraction.ts @@ -1,15 +1,13 @@ import * as pb_1 from 'google-protobuf'; -import { - ISlopeKiloMarkerData, - SlopeKiloMarker, -} from 'src/graphics/slopeKiloMarker/SlopeKiloMarker'; +import { SlopeKiloMarker } from 'src/graphics/slopeKiloMarker/SlopeKiloMarker'; import { GraphicDataBase } from './GraphicDataBase'; import { graphicData } from 'src/protos/stationLayoutGraphics'; import { KilometerSystem } from 'src/graphics/signal/Signal'; +import { IKiloMarkerData } from 'src/graphics/kilometerMarker/KilometerMarker'; export class SlopeKiloMarkerData extends GraphicDataBase - implements ISlopeKiloMarkerData + implements IKiloMarkerData { constructor(data?: graphicData.SlopeKiloMarker) { let platform; diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index 20871a1..72376ca 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -121,6 +121,12 @@ import { SlopeDraw } from 'src/graphics/slope/SlopeAssistant'; import { SlopeData } from './graphics/SlopeInteraction'; import { Slope, SlopeTemplate } from 'src/graphics/slope/Slope'; import { useLineStore } from 'src/stores/line-store'; +import { + CurvatureKiloMarker, + CurvatureKiloMarkerTemplate, +} from 'src/graphics/curvatureKiloMarker/CurvatureKiloMarker'; +import { CurvatureKiloMarkerDrawAssistant } from 'src/graphics/curvatureKiloMarker/CurvatureKiloMarkerDrawAssistant'; +import { CurvatureKiloMarkerData } from './graphics/CurvatureKiloMarkerInteraction'; // export function fromStoragePoint(p: graphicData.Point): Point { // return new Point(p.x, p.y); @@ -210,6 +216,7 @@ const showType = [ TrainWindow.Type, SlopeKiloMarker.Type, Slope.Type, + CurvatureKiloMarker.Type, ]; export const drawLayerList = [ // 图层列表 @@ -257,6 +264,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { | TransponderDraw | SlopeKiloMarkerDrawAssistant | SlopeDraw + | CurvatureKiloMarkerDrawAssistant )[] = []; if (draftType === 'Line') { drawAssistants = [ @@ -307,6 +315,10 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { new SlopeKiloMarkerTemplate(new SlopeKiloMarkerData()) ), new SlopeDraw(app, new SlopeTemplate(new SlopeData())), + new CurvatureKiloMarkerDrawAssistant( + app, + new CurvatureKiloMarkerTemplate(new CurvatureKiloMarkerData()) + ), ]; DrawSignalInteraction.init(app); DrawStopPositionInteraction.init(app); @@ -475,6 +487,11 @@ export function saveDrawDatas(app: JlDrawApp) { } else if (Slope.Type === g.type) { const slopeData = (g as Slope).saveData(); storage.slopes.push((slopeData as SlopeData).data); + } else if (CurvatureKiloMarker.Type === g.type) { + const curvatureKiloMarkerData = (g as CurvatureKiloMarker).saveData(); + storage.curvatureKiloMarker.push( + (curvatureKiloMarkerData as CurvatureKiloMarkerData).data + ); } }); const base64 = fromUint8Array(storage.serialize()); @@ -561,6 +578,9 @@ export async function loadDrawDatas(app: GraphicApp) { storage.slopeKiloMarker.forEach((slopeKiloMarker) => { datas.push(new SlopeKiloMarkerData(slopeKiloMarker)); }); + storage.curvatureKiloMarker.forEach((curvatureKiloMarker) => { + datas.push(new CurvatureKiloMarkerData(curvatureKiloMarker)); + }); storage.slopes.forEach((slope) => { datas.push(new SlopeData(slope)); }); diff --git a/src/graphics/curvatureKiloMarker/CurvatureKiloMarker.ts b/src/graphics/curvatureKiloMarker/CurvatureKiloMarker.ts new file mode 100644 index 0000000..3835f84 --- /dev/null +++ b/src/graphics/curvatureKiloMarker/CurvatureKiloMarker.ts @@ -0,0 +1,50 @@ +import { JlGraphic, JlGraphicTemplate } from 'src/jl-graphic'; +import { + IKiloMarkerData, + KiloMarkerConsts, + KilometerMarker, +} from '../kilometerMarker/KilometerMarker'; + +export class CurvatureKiloMarker extends JlGraphic { + static Type = 'CurvatureKiloMarker'; + graphic: KilometerMarker; + size = KiloMarkerConsts.size; + + constructor() { + super(CurvatureKiloMarker.Type); + this.graphic = new KilometerMarker(); + this.addChild(this.graphic); + } + get datas(): IKiloMarkerData { + return this.getDatas(); + } + doRepaint(): void { + this.graphic.paint(); + } + + getPoint(position: 'up' | 'down' | 'mid') { + const p = this.transform.position.clone(); + if (position === 'up') { + p.y -= this.size; + return p; + } else if (position === 'down') { + p.y += this.size; + return p; + } else if (position === 'mid') { + return p; + } + } +} + +export class CurvatureKiloMarkerTemplate extends JlGraphicTemplate { + constructor(dataTemplate: IKiloMarkerData) { + super(CurvatureKiloMarker.Type, { + dataTemplate, + }); + } + new(): CurvatureKiloMarker { + const curvatureKiloMarker = new CurvatureKiloMarker(); + curvatureKiloMarker.loadData(this.datas); + return curvatureKiloMarker; + } +} diff --git a/src/graphics/curvatureKiloMarker/CurvatureKiloMarkerDrawAssistant.ts b/src/graphics/curvatureKiloMarker/CurvatureKiloMarkerDrawAssistant.ts new file mode 100644 index 0000000..79416f4 --- /dev/null +++ b/src/graphics/curvatureKiloMarker/CurvatureKiloMarkerDrawAssistant.ts @@ -0,0 +1,102 @@ +import { + GraphicApp, + GraphicDrawAssistant, + GraphicInteractionPlugin, + JlDrawApp, + JlGraphic, + linePoint, +} from 'src/jl-graphic'; +import { FederatedMouseEvent, IHitArea, Point } from 'pixi.js'; +import { IKiloMarkerData } from '../kilometerMarker/KilometerMarker'; +import { + CurvatureKiloMarker, + CurvatureKiloMarkerTemplate, +} from './CurvatureKiloMarker'; + +export class KilometerMarkerHitArea implements IHitArea { + kiloMarker: CurvatureKiloMarker; + constructor(kiloMarker: CurvatureKiloMarker) { + this.kiloMarker = kiloMarker; + } + contains(x: number, y: number): boolean { + const { position } = this.kiloMarker.transform; + return linePoint( + this.kiloMarker.canvasToLocalPoint({ x: position.x, y: position.y - 50 }), + this.kiloMarker.canvasToLocalPoint({ x: position.x, y: position.y + 50 }), + { x, y }, + 2 + ); + } +} + +export class CurvatureKiloMarkerDrawAssistant extends GraphicDrawAssistant< + CurvatureKiloMarkerTemplate, + IKiloMarkerData +> { + curvatureKiloMarker: CurvatureKiloMarker; + + constructor(app: JlDrawApp, template: CurvatureKiloMarkerTemplate) { + super(app, template, 'sym_o_golf_course', '曲度公里标'); + this.curvatureKiloMarker = this.graphicTemplate.new(); + this.container.addChild(this.curvatureKiloMarker); + CurvatureKiloMarkerInteractionPlugin.init(app); + } + + onLeftDown(e: FederatedMouseEvent): void { + this.createAndStore(true); + } + + redraw(cp: Point): void { + const list = this.app.queryStore.queryByType( + CurvatureKiloMarker.Type + ); + const ys = list.reduce((prev, curr, i) => { + const currentY = curr.datas.transform.position.y; + if (!prev.includes(currentY)) { + return [currentY, ...prev]; + } else { + return prev; + } + }, []); + if (list.length) { + const matchY = ys.find( + (y) => Math.abs(cp.y - y) <= this.curvatureKiloMarker.size + ); + if (matchY) { + this.container.position.set(cp.x, matchY); + return; + } + } + this.container.position.set(cp.x, cp.y); + } + prepareData(data: IKiloMarkerData): boolean { + data.transform = this.container.saveTransform(); + return true; + } +} + +export class CurvatureKiloMarkerInteractionPlugin extends GraphicInteractionPlugin { + static Name = 'CurvatureKiloMarkerInteraction'; + + constructor(app: GraphicApp) { + super(CurvatureKiloMarkerInteractionPlugin.Name, app); + } + static init(app: GraphicApp) { + return new CurvatureKiloMarkerInteractionPlugin(app); + } + filter(...grahpics: JlGraphic[]): CurvatureKiloMarker[] | undefined { + return grahpics.filter( + (g): g is CurvatureKiloMarker => g instanceof CurvatureKiloMarker + ); + } + bind(g: CurvatureKiloMarker): void { + g.graphic.eventMode = 'static'; + g.graphic.cursor = 'pointer'; + g.graphic.selectable = true; + g.graphic.draggable = false; + g.graphic.hitArea = new KilometerMarkerHitArea(g); + } + unbind(g: CurvatureKiloMarker): void { + console.log(g); + } +} diff --git a/src/graphics/kilometerMarker/KilometerMarker.ts b/src/graphics/kilometerMarker/KilometerMarker.ts index 8693ac1..7475229 100644 --- a/src/graphics/kilometerMarker/KilometerMarker.ts +++ b/src/graphics/kilometerMarker/KilometerMarker.ts @@ -1,4 +1,20 @@ import { Graphics } from 'pixi.js'; +import { KilometerSystem } from '../signal/Signal'; +import { GraphicData } from 'src/jl-graphic'; + +export const KiloMarkerConsts = { + size: 50, +}; + +export interface IKiloMarkerData extends GraphicData { + get code(): string; // 编号 + set code(v: string); + get kilometerSystem(): KilometerSystem[]; + set kilometerSystem(v: KilometerSystem[]); + clone(): IKiloMarkerData; + copyFrom(data: IKiloMarkerData): void; + eq(other: IKiloMarkerData): boolean; +} export class KilometerMarker extends Graphics { constructor() { diff --git a/src/graphics/slopeKiloMarker/SlopeKiloMarker.ts b/src/graphics/slopeKiloMarker/SlopeKiloMarker.ts index 60ad388..3aa5e86 100644 --- a/src/graphics/slopeKiloMarker/SlopeKiloMarker.ts +++ b/src/graphics/slopeKiloMarker/SlopeKiloMarker.ts @@ -1,20 +1,9 @@ -import { GraphicData, JlGraphic, JlGraphicTemplate } from 'src/jl-graphic'; -import { KilometerMarker } from '../kilometerMarker/KilometerMarker'; -import { KilometerSystem } from '../signal/Signal'; - -export const KiloMarkerConsts = { - size: 50, -}; - -export interface ISlopeKiloMarkerData extends GraphicData { - get code(): string; // 编号 - set code(v: string); - get kilometerSystem(): KilometerSystem[]; - set kilometerSystem(v: KilometerSystem[]); - clone(): ISlopeKiloMarkerData; - copyFrom(data: ISlopeKiloMarkerData): void; - eq(other: ISlopeKiloMarkerData): boolean; -} +import { JlGraphic, JlGraphicTemplate } from 'src/jl-graphic'; +import { + IKiloMarkerData, + KiloMarkerConsts, + KilometerMarker, +} from '../kilometerMarker/KilometerMarker'; export class SlopeKiloMarker extends JlGraphic { static Type = 'SlopeKiloMarker'; @@ -26,8 +15,8 @@ export class SlopeKiloMarker extends JlGraphic { this.graphic = new KilometerMarker(); this.addChild(this.graphic); } - get datas(): ISlopeKiloMarkerData { - return this.getDatas(); + get datas(): IKiloMarkerData { + return this.getDatas(); } doRepaint(): void { this.graphic.paint(); @@ -48,7 +37,7 @@ export class SlopeKiloMarker extends JlGraphic { } export class SlopeKiloMarkerTemplate extends JlGraphicTemplate { - constructor(dataTemplate: ISlopeKiloMarkerData) { + constructor(dataTemplate: IKiloMarkerData) { super(SlopeKiloMarker.Type, { dataTemplate, }); diff --git a/src/graphics/slopeKiloMarker/SlopeKiloMarkerDrawAssistant.ts b/src/graphics/slopeKiloMarker/SlopeKiloMarkerDrawAssistant.ts index d007a49..d66c192 100644 --- a/src/graphics/slopeKiloMarker/SlopeKiloMarkerDrawAssistant.ts +++ b/src/graphics/slopeKiloMarker/SlopeKiloMarkerDrawAssistant.ts @@ -6,12 +6,9 @@ import { JlGraphic, linePoint, } from 'src/jl-graphic'; -import { - ISlopeKiloMarkerData, - SlopeKiloMarker, - SlopeKiloMarkerTemplate, -} from './SlopeKiloMarker'; +import { SlopeKiloMarker, SlopeKiloMarkerTemplate } from './SlopeKiloMarker'; import { FederatedMouseEvent, IHitArea, Point } from 'pixi.js'; +import { IKiloMarkerData } from '../kilometerMarker/KilometerMarker'; export class KilometerMarkerHitArea implements IHitArea { kiloMarker: SlopeKiloMarker; @@ -31,7 +28,7 @@ export class KilometerMarkerHitArea implements IHitArea { export class SlopeKiloMarkerDrawAssistant extends GraphicDrawAssistant< SlopeKiloMarkerTemplate, - ISlopeKiloMarkerData + IKiloMarkerData > { slopeKiloMarker: SlopeKiloMarker; @@ -69,7 +66,7 @@ export class SlopeKiloMarkerDrawAssistant extends GraphicDrawAssistant< } this.container.position.set(cp.x, cp.y); } - prepareData(data: ISlopeKiloMarkerData): boolean { + prepareData(data: IKiloMarkerData): boolean { data.transform = this.container.saveTransform(); return true; } diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index c78ab15..4c5e906 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -32,9 +32,10 @@ export namespace graphicData { slopes?: Slope[]; CalculateLink?: CalculateLink[]; slopeKiloMarker?: SlopeKiloMarker[]; + curvatureKiloMarker?: CurvatureKiloMarker[]; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4, 5, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4, 5, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26], this.#one_of_decls); if (!Array.isArray(data) && typeof data == "object") { if ("canvas" in data && data.canvas != undefined) { this.canvas = data.canvas; @@ -96,6 +97,9 @@ export namespace graphicData { if ("slopeKiloMarker" in data && data.slopeKiloMarker != undefined) { this.slopeKiloMarker = data.slopeKiloMarker; } + if ("curvatureKiloMarker" in data && data.curvatureKiloMarker != undefined) { + this.curvatureKiloMarker = data.curvatureKiloMarker; + } } } get canvas() { @@ -221,6 +225,12 @@ export namespace graphicData { set slopeKiloMarker(value: SlopeKiloMarker[]) { pb_1.Message.setRepeatedWrapperField(this, 25, value); } + get curvatureKiloMarker() { + return pb_1.Message.getRepeatedWrapperField(this, CurvatureKiloMarker, 26) as CurvatureKiloMarker[]; + } + set curvatureKiloMarker(value: CurvatureKiloMarker[]) { + pb_1.Message.setRepeatedWrapperField(this, 26, value); + } static fromObject(data: { canvas?: ReturnType; Platforms?: ReturnType[]; @@ -242,6 +252,7 @@ export namespace graphicData { slopes?: ReturnType[]; CalculateLink?: ReturnType[]; slopeKiloMarker?: ReturnType[]; + curvatureKiloMarker?: ReturnType[]; }): RtssGraphicStorage { const message = new RtssGraphicStorage({}); if (data.canvas != null) { @@ -304,6 +315,9 @@ export namespace graphicData { if (data.slopeKiloMarker != null) { message.slopeKiloMarker = data.slopeKiloMarker.map(item => SlopeKiloMarker.fromObject(item)); } + if (data.curvatureKiloMarker != null) { + message.curvatureKiloMarker = data.curvatureKiloMarker.map(item => CurvatureKiloMarker.fromObject(item)); + } return message; } toObject() { @@ -328,6 +342,7 @@ export namespace graphicData { slopes?: ReturnType[]; CalculateLink?: ReturnType[]; slopeKiloMarker?: ReturnType[]; + curvatureKiloMarker?: ReturnType[]; } = {}; if (this.canvas != null) { data.canvas = this.canvas.toObject(); @@ -389,6 +404,9 @@ export namespace graphicData { if (this.slopeKiloMarker != null) { data.slopeKiloMarker = this.slopeKiloMarker.map((item: SlopeKiloMarker) => item.toObject()); } + if (this.curvatureKiloMarker != null) { + data.curvatureKiloMarker = this.curvatureKiloMarker.map((item: CurvatureKiloMarker) => item.toObject()); + } return data; } serialize(): Uint8Array; @@ -435,6 +453,8 @@ export namespace graphicData { writer.writeRepeatedMessage(24, this.CalculateLink, (item: CalculateLink) => item.serialize(writer)); if (this.slopeKiloMarker.length) writer.writeRepeatedMessage(25, this.slopeKiloMarker, (item: SlopeKiloMarker) => item.serialize(writer)); + if (this.curvatureKiloMarker.length) + writer.writeRepeatedMessage(26, this.curvatureKiloMarker, (item: CurvatureKiloMarker) => item.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -504,6 +524,9 @@ export namespace graphicData { case 25: reader.readMessage(message.slopeKiloMarker, () => pb_1.Message.addToRepeatedWrapperField(message, 25, SlopeKiloMarker.deserialize(reader), SlopeKiloMarker)); break; + case 26: + reader.readMessage(message.curvatureKiloMarker, () => pb_1.Message.addToRepeatedWrapperField(message, 26, CurvatureKiloMarker.deserialize(reader), CurvatureKiloMarker)); + break; default: reader.skipField(); } } @@ -4716,7 +4739,7 @@ export namespace graphicData { return SlopeKiloMarker.deserialize(bytes); } } - export class TurningRadiusKiloMarker extends pb_1.Message { + export class CurvatureKiloMarker extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { common?: CommonInfo; @@ -4762,8 +4785,8 @@ export namespace graphicData { common?: ReturnType; code?: string; kilometerSystem?: ReturnType[]; - }): TurningRadiusKiloMarker { - const message = new TurningRadiusKiloMarker({}); + }): CurvatureKiloMarker { + const message = new CurvatureKiloMarker({}); if (data.common != null) { message.common = CommonInfo.fromObject(data.common); } @@ -4805,8 +4828,8 @@ export namespace graphicData { if (!w) return writer.getResultBuffer(); } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): TurningRadiusKiloMarker { - const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new TurningRadiusKiloMarker(); + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): CurvatureKiloMarker { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new CurvatureKiloMarker(); while (reader.nextField()) { if (reader.isEndGroup()) break; @@ -4828,8 +4851,8 @@ export namespace graphicData { serializeBinary(): Uint8Array { return this.serialize(); } - static deserializeBinary(bytes: Uint8Array): TurningRadiusKiloMarker { - return TurningRadiusKiloMarker.deserialize(bytes); + static deserializeBinary(bytes: Uint8Array): CurvatureKiloMarker { + return CurvatureKiloMarker.deserialize(bytes); } } export class Slope extends pb_1.Message { @@ -4980,6 +5003,7 @@ export namespace graphicData { aRelatedRef?: RelatedRef; bRelatedRef?: RelatedRef; devicePositions?: CalculateLink.DevicePosition[]; + index?: number; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 6], this.#one_of_decls); @@ -5002,6 +5026,9 @@ export namespace graphicData { if ("devicePositions" in data && data.devicePositions != undefined) { this.devicePositions = data.devicePositions; } + if ("index" in data && data.index != undefined) { + this.index = data.index; + } } } get common() { @@ -5049,6 +5076,12 @@ export namespace graphicData { set devicePositions(value: CalculateLink.DevicePosition[]) { pb_1.Message.setRepeatedWrapperField(this, 6, value); } + get index() { + return pb_1.Message.getFieldWithDefault(this, 7, 0) as number; + } + set index(value: number) { + pb_1.Message.setField(this, 7, value); + } static fromObject(data: { common?: ReturnType; points?: ReturnType[]; @@ -5056,6 +5089,7 @@ export namespace graphicData { aRelatedRef?: ReturnType; bRelatedRef?: ReturnType; devicePositions?: ReturnType[]; + index?: number; }): CalculateLink { const message = new CalculateLink({}); if (data.common != null) { @@ -5076,6 +5110,9 @@ export namespace graphicData { if (data.devicePositions != null) { message.devicePositions = data.devicePositions.map(item => CalculateLink.DevicePosition.fromObject(item)); } + if (data.index != null) { + message.index = data.index; + } return message; } toObject() { @@ -5086,6 +5123,7 @@ export namespace graphicData { aRelatedRef?: ReturnType; bRelatedRef?: ReturnType; devicePositions?: ReturnType[]; + index?: number; } = {}; if (this.common != null) { data.common = this.common.toObject(); @@ -5105,6 +5143,9 @@ export namespace graphicData { if (this.devicePositions != null) { data.devicePositions = this.devicePositions.map((item: CalculateLink.DevicePosition) => item.toObject()); } + if (this.index != null) { + data.index = this.index; + } return data; } serialize(): Uint8Array; @@ -5123,6 +5164,8 @@ export namespace graphicData { writer.writeMessage(5, this.bRelatedRef, () => this.bRelatedRef.serialize(writer)); if (this.devicePositions.length) writer.writeRepeatedMessage(6, this.devicePositions, (item: CalculateLink.DevicePosition) => item.serialize(writer)); + if (this.index != 0) + writer.writeInt32(7, this.index); if (!w) return writer.getResultBuffer(); } @@ -5150,6 +5193,9 @@ export namespace graphicData { case 6: reader.readMessage(message.devicePositions, () => pb_1.Message.addToRepeatedWrapperField(message, 6, CalculateLink.DevicePosition.deserialize(reader), CalculateLink.DevicePosition)); break; + case 7: + message.index = reader.readInt32(); + break; default: reader.skipField(); } } From 344443ca516fde9f47c657cb6dbfc335d96d7866 Mon Sep 17 00:00:00 2001 From: Yuan Date: Mon, 7 Aug 2023 16:23:53 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E5=B8=B8=E9=87=8F=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/slope/Slope.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/graphics/slope/Slope.ts b/src/graphics/slope/Slope.ts index 617000c..8c0589c 100644 --- a/src/graphics/slope/Slope.ts +++ b/src/graphics/slope/Slope.ts @@ -6,10 +6,8 @@ import { VectorText, calculateLineMidpoint, } from 'src/jl-graphic'; -import { - SlopeKiloMarker, - KiloMarkerConsts, -} from '../slopeKiloMarker/SlopeKiloMarker'; +import { SlopeKiloMarker } from '../slopeKiloMarker/SlopeKiloMarker'; +import { KiloMarkerConsts } from '../kilometerMarker/KilometerMarker'; export interface ISlopeData extends GraphicData { get points(): IPointData[]; // 线坐标点 set points(points: IPointData[]); From 4fe25787048f7eff5754743032aea7a994c80aa6 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Mon, 7 Aug 2023 17:06:50 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E5=9D=A1=E5=BA=A6=E5=88=A0=E9=99=A4bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/slope/SlopeAssistant.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/graphics/slope/SlopeAssistant.ts b/src/graphics/slope/SlopeAssistant.ts index 95427f6..98b220e 100644 --- a/src/graphics/slope/SlopeAssistant.ts +++ b/src/graphics/slope/SlopeAssistant.ts @@ -65,11 +65,17 @@ export class SlopeDraw extends GraphicDrawAssistant { const slopes = this.app.queryStore .queryByType(Slope.Type) .filter((g) => { - const refSlopeKiloMarker = this.app.queryStore.queryById( - g.datas.refDeviceId[0] - ) as SlopeKiloMarker; + let refSlopeKiloMarker; + try { + refSlopeKiloMarker = this.app.queryStore.queryById( + g.datas.refDeviceId[0] + ) as SlopeKiloMarker; + } catch (error) { + this.app.deleteGraphics(g); + } + return ( - refSlopeKiloMarker.datas.kilometerSystem[0].direction == dirSlop + refSlopeKiloMarker?.datas.kilometerSystem[0].direction == dirSlop ); }); const slopeKiloMarkers = this.app.queryStore From 75990f65af8fa7da971aaf9a74c2957a9e0b1a2c Mon Sep 17 00:00:00 2001 From: Yuan Date: Mon, 7 Aug 2023 17:38:12 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../draw-app/properties/CurvatureKiloMarkerProperty.vue | 4 ++-- .../draw-app/properties/SlopeKiloMarkerProperty.vue | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue b/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue index e0c038d..5674d06 100644 --- a/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue +++ b/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue @@ -26,8 +26,8 @@ const CoordinateSystemOptions = [ { label: '换线', value: 'TRANSFER' }, ]; const directionOptions = [ - { label: '上行', value: 0 }, - { label: '下行', value: 1 }, + { label: '左行', value: 0 }, + { label: '右行', value: 1 }, ]; watchEffect(() => { const kiloMarker = drawStore.selectedGraphic; diff --git a/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue b/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue index d78ef86..350a0c6 100644 --- a/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue +++ b/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue @@ -26,8 +26,8 @@ const CoordinateSystemOptions = [ { label: '换线', value: 'TRANSFER' }, ]; const directionOptions = [ - { label: '上行', value: 0 }, - { label: '下行', value: 1 }, + { label: '左行', value: 0 }, + { label: '右行', value: 1 }, ]; watchEffect(() => { const kiloMarker = drawStore.selectedGraphic; From 4a96f250efe5a88d52c698f1ec077f539009bc46 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Mon, 7 Aug 2023 17:53:48 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=9B=B2=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/draw-app/DrawProperties.vue | 5 + .../draw-app/properties/CurvatureProperty.vue | 97 ++++++++++ .../draw-app/properties/SlopeProperty.vue | 2 +- src/drawApp/graphics/CurvatureInteraction.ts | 52 ++++++ src/drawApp/index.ts | 12 ++ src/graphics/curvature/Curvature.ts | 115 ++++++++++++ src/graphics/curvature/CurvatureAssistant.ts | 165 ++++++++++++++++++ src/graphics/slope/Slope.ts | 4 +- src/layouts/DrawLayout.vue | 12 ++ src/protos/stationLayoutGraphics.ts | 164 ++++++++++++++++- 10 files changed, 625 insertions(+), 3 deletions(-) create mode 100644 src/components/draw-app/properties/CurvatureProperty.vue create mode 100644 src/drawApp/graphics/CurvatureInteraction.ts create mode 100644 src/graphics/curvature/Curvature.ts create mode 100644 src/graphics/curvature/CurvatureAssistant.ts diff --git a/src/components/draw-app/DrawProperties.vue b/src/components/draw-app/DrawProperties.vue index 0bfa597..86e1d31 100644 --- a/src/components/draw-app/DrawProperties.vue +++ b/src/components/draw-app/DrawProperties.vue @@ -107,6 +107,9 @@ + @@ -159,6 +162,8 @@ import CurvatureKiloMarkerProperty from './properties/CurvatureKiloMarkerPropert import { SlopeKiloMarker } from 'src/graphics/slopeKiloMarker/SlopeKiloMarker'; import { Slope } from 'src/graphics/slope/Slope'; import SlopeProperty from './properties/SlopeProperty.vue'; +import { Curvature } from 'src/graphics/curvature/Curvature'; +import CurvatureProperty from './properties/CurvatureProperty.vue'; import { CurvatureKiloMarker } from 'src/graphics/curvatureKiloMarker/CurvatureKiloMarker'; const drawStore = useDrawStore(); diff --git a/src/components/draw-app/properties/CurvatureProperty.vue b/src/components/draw-app/properties/CurvatureProperty.vue new file mode 100644 index 0000000..57bd7bc --- /dev/null +++ b/src/components/draw-app/properties/CurvatureProperty.vue @@ -0,0 +1,97 @@ + + + diff --git a/src/components/draw-app/properties/SlopeProperty.vue b/src/components/draw-app/properties/SlopeProperty.vue index 11e3e11..a71de29 100644 --- a/src/components/draw-app/properties/SlopeProperty.vue +++ b/src/components/draw-app/properties/SlopeProperty.vue @@ -33,7 +33,7 @@ - 关联的设备 + 关联的坡度公里标
(); + } + get points(): IPointData[] { + return this.data.points; + } + set points(points: IPointData[]) { + this.data.points = points.map( + (p) => new graphicData.Point({ x: p.x, y: p.y }) + ); + } + get curvatureNumber(): number { + return this.data.curvatureNumber; + } + set curvatureNumber(v: number) { + this.data.curvatureNumber = v; + } + get refDeviceId(): string[] { + return this.data.refDeviceId; + } + set refDeviceId(v: string[]) { + this.data.refDeviceId = v; + } + + clone(): CurvatureData { + return new CurvatureData(this.data.cloneMessage()); + } + copyFrom(data: CurvatureData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: CurvatureData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index 72376ca..0566a57 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -127,6 +127,9 @@ import { } from 'src/graphics/curvatureKiloMarker/CurvatureKiloMarker'; import { CurvatureKiloMarkerDrawAssistant } from 'src/graphics/curvatureKiloMarker/CurvatureKiloMarkerDrawAssistant'; import { CurvatureKiloMarkerData } from './graphics/CurvatureKiloMarkerInteraction'; +import { Curvature, CurvatureTemplate } from 'src/graphics/curvature/Curvature'; +import { CurvatureData } from './graphics/CurvatureInteraction'; +import { CurvatureDraw } from 'src/graphics/curvature/CurvatureAssistant'; // export function fromStoragePoint(p: graphicData.Point): Point { // return new Point(p.x, p.y); @@ -217,6 +220,7 @@ const showType = [ SlopeKiloMarker.Type, Slope.Type, CurvatureKiloMarker.Type, + Curvature.Type, ]; export const drawLayerList = [ // 图层列表 @@ -265,6 +269,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { | SlopeKiloMarkerDrawAssistant | SlopeDraw | CurvatureKiloMarkerDrawAssistant + | CurvatureDraw )[] = []; if (draftType === 'Line') { drawAssistants = [ @@ -319,6 +324,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { app, new CurvatureKiloMarkerTemplate(new CurvatureKiloMarkerData()) ), + new CurvatureDraw(app, new CurvatureTemplate(new CurvatureData())), ]; DrawSignalInteraction.init(app); DrawStopPositionInteraction.init(app); @@ -492,6 +498,9 @@ export function saveDrawDatas(app: JlDrawApp) { storage.curvatureKiloMarker.push( (curvatureKiloMarkerData as CurvatureKiloMarkerData).data ); + } else if (Curvature.Type === g.type) { + const curvatureData = (g as Curvature).saveData(); + storage.curvatures.push((curvatureData as CurvatureData).data); } }); const base64 = fromUint8Array(storage.serialize()); @@ -584,6 +593,9 @@ export async function loadDrawDatas(app: GraphicApp) { storage.slopes.forEach((slope) => { datas.push(new SlopeData(slope)); }); + storage.curvatures.forEach((curvature) => { + datas.push(new CurvatureData(curvature)); + }); await app.loadGraphic(datas); } else { app.loadGraphic([]); diff --git a/src/graphics/curvature/Curvature.ts b/src/graphics/curvature/Curvature.ts new file mode 100644 index 0000000..386dc98 --- /dev/null +++ b/src/graphics/curvature/Curvature.ts @@ -0,0 +1,115 @@ +import { Graphics, IPointData } from 'pixi.js'; +import { + GraphicData, + JlGraphic, + JlGraphicTemplate, + VectorText, + calculateLineMidpoint, +} from 'src/jl-graphic'; +import { KiloMarkerConsts } from '../kilometerMarker/KilometerMarker'; +export interface ICurvatureData extends GraphicData { + get points(): IPointData[]; // 线坐标点 + set points(points: IPointData[]); + get curvatureNumber(): number; // 曲度的值 + set curvatureNumber(v: number); + get refDeviceId(): string[]; // 曲度关联的设备id + set refDeviceId(v: string[]); + clone(): ICurvatureData; + copyFrom(data: ICurvatureData): void; + eq(other: ICurvatureData): boolean; +} + +export const CurvatureConsts = { + lineColor: '0xffffff', + lineWidth: 2, +}; + +export class Curvature extends JlGraphic { + static Type = 'Curvature'; + lineGraphic: Graphics; + curvatureNumber: VectorText; + constructor() { + super(Curvature.Type); + this.lineGraphic = new Graphics(); + this.curvatureNumber = new VectorText(); + this.curvatureNumber.name = 'curvatureNumber'; + const vectorTexts = [this.curvatureNumber]; + vectorTexts.forEach((vectorText) => { + vectorText.setVectorFontSize(14); + vectorText.anchor.set(0.5); + vectorText.style.fill = '0xffffff'; + vectorText.transformSave = true; + }); + this.transformSave = true; + this.addChild(this.lineGraphic); + this.addChild(this.curvatureNumber); + } + + get datas(): ICurvatureData { + return this.getDatas(); + } + doRepaint(): void { + if (this.datas.points.length < 2) { + throw new Error('Curvature坐标数据异常'); + } + this.lineGraphic.clear(); + this.lineGraphic.lineStyle( + CurvatureConsts.lineWidth, + CurvatureConsts.lineColor + ); + let distanceY = 0; + if (this.datas.curvatureNumber !== 0) { + distanceY = + this.datas.curvatureNumber > 0 + ? -KiloMarkerConsts.size / 2 + : KiloMarkerConsts.size / 2; + } + this.datas.points.forEach((p, i) => { + if (i !== 0) { + this.lineGraphic.lineTo(p.x, p.y + distanceY); + } else { + this.lineGraphic.moveTo(p.x, p.y + distanceY); + } + }); + //曲度值 + const text = Math.abs(this.datas.curvatureNumber); + this.curvatureNumber.text = text ? `R-${text}` : ''; + const centerPos = calculateLineMidpoint( + this.datas.points[0], + this.datas.points[this.datas.points.length - 1] + ); + this.curvatureNumber.position.set( + centerPos.x, + centerPos.y + distanceY - 15 + ); + } + get linePoints(): IPointData[] { + return this.datas.points; + } + set linePoints(points: IPointData[]) { + const old = this.datas.clone(); + old.points = points; + this.updateData(old); + } + loadRelations() { + if (this.datas.refDeviceId.length) { + this.datas.refDeviceId.forEach((id) => { + const curvatureKiloMarker = this.queryStore.queryById(id); + this.relationManage.addRelation(this, curvatureKiloMarker); + }); + } + } +} + +export class CurvatureTemplate extends JlGraphicTemplate { + constructor(dataTemplate: ICurvatureData) { + super(Curvature.Type, { + dataTemplate, + }); + } + new(): Curvature { + const curvature = new Curvature(); + curvature.loadData(this.datas); + return curvature; + } +} diff --git a/src/graphics/curvature/CurvatureAssistant.ts b/src/graphics/curvature/CurvatureAssistant.ts new file mode 100644 index 0000000..5330b89 --- /dev/null +++ b/src/graphics/curvature/CurvatureAssistant.ts @@ -0,0 +1,165 @@ +import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js'; +import { + GraphicDrawAssistant, + GraphicIdGenerator, + GraphicInteractionPlugin, + JlDrawApp, + JlGraphic, + linePoint, +} from 'src/jl-graphic'; + +import { + ICurvatureData, + Curvature, + CurvatureTemplate, + CurvatureConsts, +} from './Curvature'; +import { CurvatureKiloMarker } from '../curvatureKiloMarker/CurvatureKiloMarker'; + +export interface ICurvatureDrawOptions { + newData: () => ICurvatureData; +} +export class CurvatureDraw extends GraphicDrawAssistant< + CurvatureTemplate, + ICurvatureData +> { + codeGraph: Curvature; + constructor(app: JlDrawApp, template: CurvatureTemplate) { + super(app, template, 'sym_o_circle', '不展示'); + this.codeGraph = this.graphicTemplate.new(); + this.container.addChild(this.codeGraph); + CurvatureInteraction.init(app); + } + + bind(): void { + super.bind(); + this.codeGraph.loadData(this.graphicTemplate.datas); + this.codeGraph.doRepaint(); + } + + clearCache(): void { + //this.codeGraph.destroy(); + } + onLeftDown(e: FederatedPointerEvent): void { + this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + + redraw(p: Point): void { + this.container.position.copyFrom(p); + } + prepareData(data: ICurvatureData): boolean { + data.transform = this.container.saveTransform(); + return true; + } + draw(graphics: CurvatureKiloMarker[], map: Map) { + if ( + map.has(`${graphics[0].id}+${graphics[1].id}`) || + map.has(`${graphics[1].id}+${graphics[0].id}`) + ) + return; + map.set(`${graphics[0].id}+${graphics[1].id}`, 1); + const curvature = new Curvature(); + curvature.loadData(this.graphicTemplate.datas); + curvature.datas.points = [graphics[0].position, graphics[1].position]; + curvature.id = GraphicIdGenerator.next(); + curvature.datas.refDeviceId = [graphics[0].id, graphics[1].id]; + this.storeGraphic(curvature); + curvature.loadRelations(); + } + oneGenerates() { + const map = new Map(); + for (let dirSlop = 0; dirSlop < 2; dirSlop++) { + const curvatures = this.app.queryStore + .queryByType(Curvature.Type) + .filter((g) => { + let refCurvatureKiloMarker; + try { + refCurvatureKiloMarker = this.app.queryStore.queryById( + g.datas.refDeviceId[0] + ) as CurvatureKiloMarker; + } catch (error) { + this.app.deleteGraphics(g); + } + + return ( + refCurvatureKiloMarker?.datas.kilometerSystem[0].direction == + dirSlop + ); + }); + const curvatureKiloMarkers = this.app.queryStore + .queryByType(CurvatureKiloMarker.Type) + .filter((g) => g.datas.kilometerSystem[0].direction == dirSlop); + curvatureKiloMarkers.sort((a, b) => a.position.x - b.position.x); + const curvatureKiloMarkersPos = curvatureKiloMarkers.map( + (g) => g.position.x + ); + //检验曲度有效性--是否有增加和删除 + curvatures.forEach((curvature) => { + const pS = curvature.datas.points[0].x; + const mapS = curvatureKiloMarkersPos.findIndex((x) => x == pS); + const pE = curvature.datas.points[1].x; + const mapE = curvatureKiloMarkersPos.findIndex((x) => x == pE); + if (mapS !== -1 && mapE !== -1 && mapE - mapS == 1) { + map.set( + `${curvature.datas.refDeviceId[0]}+${curvature.datas.refDeviceId[1]}`, + 1 + ); + } else { + this.app.deleteGraphics(curvature); + } + }); + for (let i = 0; i < curvatureKiloMarkers.length - 1; i++) { + this.draw([curvatureKiloMarkers[i], curvatureKiloMarkers[i + 1]], map); + } + } + } +} +class CurvatureGraphicHitArea implements IHitArea { + curvature: Curvature; + constructor(curvature: Curvature) { + this.curvature = curvature; + } + contains(x: number, y: number): boolean { + for (let i = 1; i < this.curvature.datas.points.length; i++) { + const p1 = this.curvature.datas.points[i - 1]; + const p2 = this.curvature.datas.points[i]; + if (linePoint(p1, p2, { x, y }, CurvatureConsts.lineWidth)) { + return true; + } + } + return false; + } +} + +export class CurvatureInteraction extends GraphicInteractionPlugin { + static Name = 'Curvature_transform'; + constructor(app: JlDrawApp) { + super(CurvatureInteraction.Name, app); + } + static init(app: JlDrawApp) { + return new CurvatureInteraction(app); + } + filter(...grahpics: JlGraphic[]): Curvature[] | undefined { + return grahpics + .filter((g) => g.type === Curvature.Type) + .map((g) => g as Curvature); + } + bind(g: Curvature): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.scalable = true; + g.draggable = false; + g.transformSave = true; + g.lineGraphic.eventMode = 'static'; + g.lineGraphic.cursor = 'pointer'; + g.lineGraphic.hitArea = new CurvatureGraphicHitArea(g); + } + unbind(g: Curvature): void { + g.eventMode = 'none'; + g.lineGraphic.eventMode = 'none'; + g.lineGraphic.draggable = false; + g.lineGraphic.selectable = false; + g.lineGraphic.transformSave = false; + } +} diff --git a/src/graphics/slope/Slope.ts b/src/graphics/slope/Slope.ts index 8c0589c..8baad98 100644 --- a/src/graphics/slope/Slope.ts +++ b/src/graphics/slope/Slope.ts @@ -74,7 +74,9 @@ export class Slope extends JlGraphic { } }); //坡度值 - this.slopeNumber.text = parseFloat(this.datas.slopeNumber / 1000 + ''); + this.slopeNumber.text = Math.abs( + parseFloat(this.datas.slopeNumber / 1000 + '') + ); const slopeNumberPosition = this.datas.childTransforms?.find( (t) => t.name === this.slopeNumber.name )?.transform.position; diff --git a/src/layouts/DrawLayout.vue b/src/layouts/DrawLayout.vue index 166cedc..391f5d6 100644 --- a/src/layouts/DrawLayout.vue +++ b/src/layouts/DrawLayout.vue @@ -46,6 +46,9 @@ 一键生成坡度 + + 一键生成曲度 + @@ -252,6 +255,8 @@ import { useQuasar } from 'quasar'; import LayerControlDialog from 'src/components/draw-app/dialogs/LayerControlDialog.vue'; import { drawLayerList } from 'src/drawApp/index'; import { useLineStore } from 'src/stores/line-store'; +import { Curvature } from 'src/graphics/curvature/Curvature'; +import { CurvatureDraw } from 'src/graphics/curvature/CurvatureAssistant'; const $q = useQuasar(); const route = useRoute(); @@ -442,6 +447,13 @@ function oneClickSlope() { .getDrawAssistant(Slope.Type) as SlopeDraw; slopeDraw.oneGenerates(); } +function oneClickCurvature() { + //一键生成曲度 + const curvatureDraw = drawStore + .getDrawApp() + .getDrawAssistant(Curvature.Type) as CurvatureDraw; + curvatureDraw.oneGenerates(); +} function oneClickLink() { drawStore.oneClickType = 'SectionLink'; const draw = drawStore diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index 4c5e906..ecdb4c0 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -33,9 +33,10 @@ export namespace graphicData { CalculateLink?: CalculateLink[]; slopeKiloMarker?: SlopeKiloMarker[]; curvatureKiloMarker?: CurvatureKiloMarker[]; + curvatures?: Curvature[]; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4, 5, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4, 5, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], this.#one_of_decls); if (!Array.isArray(data) && typeof data == "object") { if ("canvas" in data && data.canvas != undefined) { this.canvas = data.canvas; @@ -100,6 +101,9 @@ export namespace graphicData { if ("curvatureKiloMarker" in data && data.curvatureKiloMarker != undefined) { this.curvatureKiloMarker = data.curvatureKiloMarker; } + if ("curvatures" in data && data.curvatures != undefined) { + this.curvatures = data.curvatures; + } } } get canvas() { @@ -231,6 +235,12 @@ export namespace graphicData { set curvatureKiloMarker(value: CurvatureKiloMarker[]) { pb_1.Message.setRepeatedWrapperField(this, 26, value); } + get curvatures() { + return pb_1.Message.getRepeatedWrapperField(this, Curvature, 27) as Curvature[]; + } + set curvatures(value: Curvature[]) { + pb_1.Message.setRepeatedWrapperField(this, 27, value); + } static fromObject(data: { canvas?: ReturnType; Platforms?: ReturnType[]; @@ -253,6 +263,7 @@ export namespace graphicData { CalculateLink?: ReturnType[]; slopeKiloMarker?: ReturnType[]; curvatureKiloMarker?: ReturnType[]; + curvatures?: ReturnType[]; }): RtssGraphicStorage { const message = new RtssGraphicStorage({}); if (data.canvas != null) { @@ -318,6 +329,9 @@ export namespace graphicData { if (data.curvatureKiloMarker != null) { message.curvatureKiloMarker = data.curvatureKiloMarker.map(item => CurvatureKiloMarker.fromObject(item)); } + if (data.curvatures != null) { + message.curvatures = data.curvatures.map(item => Curvature.fromObject(item)); + } return message; } toObject() { @@ -343,6 +357,7 @@ export namespace graphicData { CalculateLink?: ReturnType[]; slopeKiloMarker?: ReturnType[]; curvatureKiloMarker?: ReturnType[]; + curvatures?: ReturnType[]; } = {}; if (this.canvas != null) { data.canvas = this.canvas.toObject(); @@ -407,6 +422,9 @@ export namespace graphicData { if (this.curvatureKiloMarker != null) { data.curvatureKiloMarker = this.curvatureKiloMarker.map((item: CurvatureKiloMarker) => item.toObject()); } + if (this.curvatures != null) { + data.curvatures = this.curvatures.map((item: Curvature) => item.toObject()); + } return data; } serialize(): Uint8Array; @@ -455,6 +473,8 @@ export namespace graphicData { writer.writeRepeatedMessage(25, this.slopeKiloMarker, (item: SlopeKiloMarker) => item.serialize(writer)); if (this.curvatureKiloMarker.length) writer.writeRepeatedMessage(26, this.curvatureKiloMarker, (item: CurvatureKiloMarker) => item.serialize(writer)); + if (this.curvatures.length) + writer.writeRepeatedMessage(27, this.curvatures, (item: Curvature) => item.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -527,6 +547,9 @@ export namespace graphicData { case 26: reader.readMessage(message.curvatureKiloMarker, () => pb_1.Message.addToRepeatedWrapperField(message, 26, CurvatureKiloMarker.deserialize(reader), CurvatureKiloMarker)); break; + case 27: + reader.readMessage(message.curvatures, () => pb_1.Message.addToRepeatedWrapperField(message, 27, Curvature.deserialize(reader), Curvature)); + break; default: reader.skipField(); } } @@ -4994,6 +5017,145 @@ export namespace graphicData { return Slope.deserialize(bytes); } } + export class Curvature extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + common?: CommonInfo; + points?: Point[]; + curvatureNumber?: number; + refDeviceId?: string[]; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 4], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("points" in data && data.points != undefined) { + this.points = data.points; + } + if ("curvatureNumber" in data && data.curvatureNumber != undefined) { + this.curvatureNumber = data.curvatureNumber; + } + if ("refDeviceId" in data && data.refDeviceId != undefined) { + this.refDeviceId = data.refDeviceId; + } + } + } + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; + } + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_common() { + return pb_1.Message.getField(this, 1) != null; + } + get points() { + return pb_1.Message.getRepeatedWrapperField(this, Point, 2) as Point[]; + } + set points(value: Point[]) { + pb_1.Message.setRepeatedWrapperField(this, 2, value); + } + get curvatureNumber() { + return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; + } + set curvatureNumber(value: number) { + pb_1.Message.setField(this, 3, value); + } + get refDeviceId() { + return pb_1.Message.getFieldWithDefault(this, 4, []) as string[]; + } + set refDeviceId(value: string[]) { + pb_1.Message.setField(this, 4, value); + } + static fromObject(data: { + common?: ReturnType; + points?: ReturnType[]; + curvatureNumber?: number; + refDeviceId?: string[]; + }): Curvature { + const message = new Curvature({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.points != null) { + message.points = data.points.map(item => Point.fromObject(item)); + } + if (data.curvatureNumber != null) { + message.curvatureNumber = data.curvatureNumber; + } + if (data.refDeviceId != null) { + message.refDeviceId = data.refDeviceId; + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + points?: ReturnType[]; + curvatureNumber?: number; + refDeviceId?: string[]; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.points != null) { + data.points = this.points.map((item: Point) => item.toObject()); + } + if (this.curvatureNumber != null) { + data.curvatureNumber = this.curvatureNumber; + } + if (this.refDeviceId != null) { + data.refDeviceId = this.refDeviceId; + } + 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.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.points.length) + writer.writeRepeatedMessage(2, this.points, (item: Point) => item.serialize(writer)); + if (this.curvatureNumber != 0) + writer.writeSint32(3, this.curvatureNumber); + if (this.refDeviceId.length) + writer.writeRepeatedString(4, this.refDeviceId); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Curvature { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Curvature(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + reader.readMessage(message.points, () => pb_1.Message.addToRepeatedWrapperField(message, 2, Point.deserialize(reader), Point)); + break; + case 3: + message.curvatureNumber = reader.readSint32(); + break; + case 4: + pb_1.Message.addToRepeatedField(message, 4, reader.readString()); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Curvature { + return Curvature.deserialize(bytes); + } + } export class CalculateLink extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { From ebe95a45e30ce0740010355b534c97a168799ed6 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Tue, 8 Aug 2023 10:21:30 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9D=A1=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E6=9B=B2=E5=BA=A6=E6=9C=AA=E5=A1=AB=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=97=B6=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/curvature/CurvatureAssistant.ts | 2 +- src/graphics/slope/SlopeAssistant.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/curvature/CurvatureAssistant.ts b/src/graphics/curvature/CurvatureAssistant.ts index 5330b89..48ae0b2 100644 --- a/src/graphics/curvature/CurvatureAssistant.ts +++ b/src/graphics/curvature/CurvatureAssistant.ts @@ -89,7 +89,7 @@ export class CurvatureDraw extends GraphicDrawAssistant< }); const curvatureKiloMarkers = this.app.queryStore .queryByType(CurvatureKiloMarker.Type) - .filter((g) => g.datas.kilometerSystem[0].direction == dirSlop); + .filter((g) => g.datas.kilometerSystem[0]?.direction == dirSlop); curvatureKiloMarkers.sort((a, b) => a.position.x - b.position.x); const curvatureKiloMarkersPos = curvatureKiloMarkers.map( (g) => g.position.x diff --git a/src/graphics/slope/SlopeAssistant.ts b/src/graphics/slope/SlopeAssistant.ts index 98b220e..a2199aa 100644 --- a/src/graphics/slope/SlopeAssistant.ts +++ b/src/graphics/slope/SlopeAssistant.ts @@ -80,7 +80,7 @@ export class SlopeDraw extends GraphicDrawAssistant { }); const slopeKiloMarkers = this.app.queryStore .queryByType(SlopeKiloMarker.Type) - .filter((g) => g.datas.kilometerSystem[0].direction == dirSlop); + .filter((g) => g.datas.kilometerSystem[0]?.direction == dirSlop); slopeKiloMarkers.sort((a, b) => a.position.x - b.position.x); const slopeKiloMarkersPos = slopeKiloMarkers.map((g) => g.position.x); //检验坡度有效性--是否有增加和删除 From da6a73998181f8d19e8dc144a6bb76c4310be4ac Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Tue, 8 Aug 2023 10:31:16 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9D=A1=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E6=9B=B2=E5=BA=A6=E5=85=AC=E9=87=8C=E6=A0=87=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E9=BB=98=E8=AE=A4=E5=80=BC=E6=9C=AA=E8=BF=98=E5=8E=9F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../draw-app/properties/CurvatureKiloMarkerProperty.vue | 6 ++++++ .../draw-app/properties/SlopeKiloMarkerProperty.vue | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue b/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue index 5674d06..1c4e491 100644 --- a/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue +++ b/src/components/draw-app/properties/CurvatureKiloMarkerProperty.vue @@ -40,6 +40,12 @@ watchEffect(() => { ks.kilometer = kiloMarkerModel.value.kilometerSystem[i].kilometer; ks.direction = kiloMarkerModel.value.kilometerSystem[i].direction; }); + } else { + kilometerSystem.forEach((ks) => { + ks.coordinateSystem = ''; + ks.kilometer = 0; + ks.direction = 0; + }); } } }); diff --git a/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue b/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue index 350a0c6..6c99ad5 100644 --- a/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue +++ b/src/components/draw-app/properties/SlopeKiloMarkerProperty.vue @@ -40,6 +40,12 @@ watchEffect(() => { ks.kilometer = kiloMarkerModel.value.kilometerSystem[i].kilometer; ks.direction = kiloMarkerModel.value.kilometerSystem[i].direction; }); + } else { + kilometerSystem.forEach((ks) => { + ks.coordinateSystem = ''; + ks.kilometer = 0; + ks.direction = 0; + }); } } }); From dfb98794deadc0725eb624e826beea08dc3b4bfc Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Tue, 8 Aug 2023 11:07:40 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/curvature/Curvature.ts | 8 ------- src/graphics/curvature/CurvatureAssistant.ts | 22 +++++++------------- src/graphics/slope/Slope.ts | 8 ------- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/graphics/curvature/Curvature.ts b/src/graphics/curvature/Curvature.ts index 386dc98..866e677 100644 --- a/src/graphics/curvature/Curvature.ts +++ b/src/graphics/curvature/Curvature.ts @@ -83,14 +83,6 @@ export class Curvature extends JlGraphic { centerPos.y + distanceY - 15 ); } - get linePoints(): IPointData[] { - return this.datas.points; - } - set linePoints(points: IPointData[]) { - const old = this.datas.clone(); - old.points = points; - this.updateData(old); - } loadRelations() { if (this.datas.refDeviceId.length) { this.datas.refDeviceId.forEach((id) => { diff --git a/src/graphics/curvature/CurvatureAssistant.ts b/src/graphics/curvature/CurvatureAssistant.ts index 48ae0b2..e4995f8 100644 --- a/src/graphics/curvature/CurvatureAssistant.ts +++ b/src/graphics/curvature/CurvatureAssistant.ts @@ -5,15 +5,10 @@ import { GraphicInteractionPlugin, JlDrawApp, JlGraphic, - linePoint, + pointBox, } from 'src/jl-graphic'; -import { - ICurvatureData, - Curvature, - CurvatureTemplate, - CurvatureConsts, -} from './Curvature'; +import { ICurvatureData, Curvature, CurvatureTemplate } from './Curvature'; import { CurvatureKiloMarker } from '../curvatureKiloMarker/CurvatureKiloMarker'; export interface ICurvatureDrawOptions { @@ -121,14 +116,11 @@ class CurvatureGraphicHitArea implements IHitArea { this.curvature = curvature; } contains(x: number, y: number): boolean { - for (let i = 1; i < this.curvature.datas.points.length; i++) { - const p1 = this.curvature.datas.points[i - 1]; - const p2 = this.curvature.datas.points[i]; - if (linePoint(p1, p2, { x, y }, CurvatureConsts.lineWidth)) { - return true; - } - } - return false; + let contains = false; + const p = new Point(x, y); + const r = this.curvature.getLocalBounds(); + contains = pointBox(p, r); + return contains; } } diff --git a/src/graphics/slope/Slope.ts b/src/graphics/slope/Slope.ts index 8baad98..624106e 100644 --- a/src/graphics/slope/Slope.ts +++ b/src/graphics/slope/Slope.ts @@ -115,14 +115,6 @@ export class Slope extends JlGraphic { this.slopeLong.position.set(centerPos.x, centerPos.y + 15); } } - get linePoints(): IPointData[] { - return this.datas.points; - } - set linePoints(points: IPointData[]) { - const old = this.datas.clone(); - old.points = points; - this.updateData(old); - } loadRelations() { if (this.datas.refDeviceId.length) { this.datas.refDeviceId.forEach((id) => {