diff --git a/src/api/Simulation.ts b/src/api/Simulation.ts index 930a215..ba139f8 100644 --- a/src/api/Simulation.ts +++ b/src/api/Simulation.ts @@ -49,6 +49,15 @@ export async function removeTrain(data: { return response.data; } +export async function setSwitchPosition(data: { + simulationId: string; + switchIndex: number; + turnNormal: boolean; + turnReverse: boolean; +}) { + return await api.post(`${UriBase}/switch/operation`, data); +} + export function checkMapData(data: { mapProto: string }) { return api.post(`${UriBase}/check/data`, data); } diff --git a/src/configs/UrlManage.ts b/src/configs/UrlManage.ts index 590df49..07c5344 100644 --- a/src/configs/UrlManage.ts +++ b/src/configs/UrlManage.ts @@ -4,16 +4,16 @@ function getHost(): string { // return '192.168.3.37:9091'; // return '192.168.3.15:9091'; // return '192.168.3.5:9091'; - // return '192.168.3.233:9091'; - return 'test.joylink.club/bjrtss-server'; + return '192.168.3.233:9091'; + // return 'test.joylink.club/bjrtss-server'; } export function getHttpBase() { - // return `http://${getHost()}`; - return `https://${getHost()}`; + return `http://${getHost()}`; + // return `https://${getHost()}`; } export function getWebsocketUrl() { - // return `ws://${getHost()}/ws-bj`; - return `wss://${getHost()}/ws-bj`; + return `ws://${getHost()}/ws-bj`; + // return `wss://${getHost()}/ws-bj`; } diff --git a/src/drawApp/graphics/TurnoutInteraction.ts b/src/drawApp/graphics/TurnoutInteraction.ts index fed9413..55eb4dc 100644 --- a/src/drawApp/graphics/TurnoutInteraction.ts +++ b/src/drawApp/graphics/TurnoutInteraction.ts @@ -6,9 +6,22 @@ import { import * as pb_1 from 'google-protobuf'; import { GraphicDataBase, GraphicStateBase } from './GraphicDataBase'; import { graphicData } from 'src/protos/stationLayoutGraphics'; -import { IPointData } from 'pixi.js'; +import { DisplayObject, FederatedMouseEvent, IPointData } from 'pixi.js'; import { KilometerSystem } from 'src/graphics/signal/Signal'; import { state } from 'src/protos/device_state'; +import { + GraphicApp, + GraphicInteractionPlugin, + JlGraphic, +} from 'src/jl-graphic'; +import { + ForkHitArea, + TurnoutSectionHitArea, +} from 'src/graphics/turnout/TurnoutDrawAssistant'; +import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; +import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; +import { useLineStore } from 'src/stores/line-store'; +import { setSwitchPosition } from 'src/api/Simulation'; function getDefaultEndPoint() { return { @@ -18,6 +31,68 @@ function getDefaultEndPoint() { }; } +const setNormalPosition: MenuItemOptions = { name: '设置定位' }; +const setReversePosition: MenuItemOptions = { name: '设置反位' }; + +const TurnoutOperationMenu: ContextMenu = ContextMenu.init({ + name: 'Turnout操作', + groups: [{ items: [setNormalPosition, setReversePosition] }], +}); + +export class TurnoutOperationPlugin extends GraphicInteractionPlugin { + static Name = 'turnout_operate_menu'; + constructor(app: GraphicApp) { + super(TurnoutOperationPlugin.Name, app); + app.registerMenu(TurnoutOperationMenu); + } + static init(app: GraphicApp) { + return new TurnoutOperationPlugin(app); + } + filter(...grahpics: JlGraphic[]): Turnout[] | undefined { + return grahpics.filter((g): g is Turnout => g instanceof Turnout); + } + bind(g: Turnout): void { + g.graphics.fork.eventMode = 'static'; + g.graphics.fork.cursor = 'pointer'; + g.graphics.fork.hitArea = new ForkHitArea(g); + g.graphics.sections.forEach((sectionGraphic) => { + sectionGraphic.eventMode = 'static'; + sectionGraphic.cursor = 'pointer'; + sectionGraphic.hitArea = new TurnoutSectionHitArea(sectionGraphic); + }); + g.on('rightclick', this.onContextMenu, this); + } + unbind(g: Turnout): void { + g.graphics.fork.eventMode = 'none'; + g.graphics.sections.forEach((sectionGraphic) => { + sectionGraphic.eventMode = 'none'; + }); + g.off('rightclick', this.onContextMenu); + } + onContextMenu(e: FederatedMouseEvent) { + const target = e.target as DisplayObject; + const turnout = target.getGraphic(); + if (!turnout) return; + this.app.updateSelected(turnout); + const simulationId = useLineStore().simulationId || ''; + const setPosition = async (normal: boolean) => { + setSwitchPosition({ + simulationId, + switchIndex: turnout.datas.index, + turnNormal: normal, + turnReverse: !normal, + }); + }; + setNormalPosition.handler = async () => { + await setPosition(true); + }; + setReversePosition.handler = async () => { + await setPosition(false); + }; + TurnoutOperationMenu.open(e.global); + } +} + export class TurnoutData extends GraphicDataBase implements ITurnoutData { constructor(data?: graphicData.Turnout) { let turnout = new graphicData.Turnout(); diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 947665e..6305aca 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -26,7 +26,11 @@ import { StationState, } from './graphics/StationInteraction'; import { Station, StationTemplate } from 'src/graphics/station/Station'; -import { TurnoutData, TurnoutStates } from './graphics/TurnoutInteraction'; +import { + TurnoutData, + TurnoutOperationPlugin, + TurnoutStates, +} from './graphics/TurnoutInteraction'; import { Turnout, TurnoutTemplate } from 'src/graphics/turnout/Turnout'; import { SectionData } from './graphics/SectionInteraction'; import { Section, SectionTemplate } from 'src/graphics/section/Section'; @@ -145,6 +149,7 @@ export function initLineApp(dom: HTMLElement): GraphicApp { Station.Type, SectionLink.Type, Train.Type, + Turnout.Type, ], }, }); @@ -153,6 +158,7 @@ export function initLineApp(dom: HTMLElement): GraphicApp { StationOperateInteraction.init(lineApp); SectionLinkOperateInteraction.init(lineApp); TrainOperateInteraction.init(lineApp); + TurnoutOperationPlugin.init(lineApp); // 画布右键菜单 lineApp.registerMenu(DefaultCanvasMenu); lineApp.canvas.on('_rightclick', (e) => { @@ -258,7 +264,7 @@ export async function loadLineDatas(app: GraphicApp) { messageConverter: (message: Uint8Array) => { const states: GraphicState[] = []; const storage = state.PushedDevicesStatus.deserialize(message); - console.log(storage, 'storage'); + // console.log(storage, 'storage'); if (storage.all) { storage.allStatus.sectionState.forEach((item) => { if (state.SectionType[item.type] == 'Axle') { diff --git a/src/graphics/platform/Platform.ts b/src/graphics/platform/Platform.ts index aca975b..1a6dedc 100644 --- a/src/graphics/platform/Platform.ts +++ b/src/graphics/platform/Platform.ts @@ -100,7 +100,6 @@ export class rectGraphic extends Container { this.addChild(this.rectGraphic); } draw(state: IPlatformState): void { - console.info(state); const rectGraphic = this.rectGraphic; rectGraphic.clear(); const fillColor = PlatformColorEnum.white; @@ -139,7 +138,6 @@ export class doorGraphic extends Container { this.addChild(this.doorCloseGraphic); } draw(stateData: IPlatformState): void { - console.info(stateData); const doorGraphic = this.doorGraphic; const doorCloseGraphic = this.doorCloseGraphic; doorGraphic.clear(); diff --git a/src/graphics/turnout/Turnout.ts b/src/graphics/turnout/Turnout.ts index bbefad9..55812f8 100644 --- a/src/graphics/turnout/Turnout.ts +++ b/src/graphics/turnout/Turnout.ts @@ -177,7 +177,7 @@ export class Turnout extends JlGraphic { } doRepaint(): void { - console.log(this.states); + // console.log(this.states); const { pointB, pointC } = this.datas; if (this.states.normal) { this.graphics.fork.paint(pointB[0]); diff --git a/src/graphics/turnout/TurnoutDrawAssistant.ts b/src/graphics/turnout/TurnoutDrawAssistant.ts index 4c1ae50..b3ede0c 100644 --- a/src/graphics/turnout/TurnoutDrawAssistant.ts +++ b/src/graphics/turnout/TurnoutDrawAssistant.ts @@ -69,34 +69,7 @@ export class TurnoutDraw extends GraphicDrawAssistant< } } -export class TurnoutHitArea implements IHitArea { - turnout: Turnout; - constructor(turnout: Turnout) { - this.turnout = turnout; - } - contains(x: number, y: number): boolean { - const { pointA, pointB, pointC } = this.turnout.datas; - return ( - polylinePoint( - [...pointA, { x: 0, y: 0 }], - { x, y }, - TurnoutConsts.lineWidth - ) || - polylinePoint( - [...pointB, { x: 0, y: 0 }], - { x, y }, - TurnoutConsts.lineWidth - ) || - polylinePoint( - [...pointC, { x: 0, y: 0 }], - { x, y }, - TurnoutConsts.lineWidth - ) - ); - } -} - -class ForkHitArea implements IHitArea { +export class ForkHitArea implements IHitArea { turnout: Turnout; constructor(turnout: Turnout) { this.turnout = turnout; @@ -128,7 +101,7 @@ class ForkHitArea implements IHitArea { } } -class TurnoutSectionHitArea implements IHitArea { +export class TurnoutSectionHitArea implements IHitArea { section: TurnoutSection; constructor(section: TurnoutSection) { this.section = section;