diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index 2159553..14978ea 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -7,11 +7,11 @@ import { Signal, SignalTemplate } from 'src/graphics/signal/Signal'; import { SignalDraw } from 'src/graphics/signal/SignalDrawAssistant'; import { CombinationKey, - IGraphicApp, GraphicData, IDrawApp, KeyListener, newDrawApp, + IGraphicStorage, } from 'src/jl-graphic'; import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; @@ -217,35 +217,18 @@ export function destroyDrawApp(): void { } } -export function initDrawApp(dom: HTMLElement): IDrawApp { - drawApp = newDrawApp(); +export function initDrawApp(): IDrawApp { + drawApp = newDrawApp({ + dataLoader: loadDrawDatas, + }); const app = drawApp; //根据草稿图类型加载绘图工具 - let drawAssistants: ( - | PlatformDraw - | StationDraw - | SignalDraw - | TurnoutDraw - | RunLineDraw - | SectionDraw - | LogicSectionDraw - | StationLineDraw - | RectDraw - | TrainLineDraw - | PathLineDraw - | TrainWindowDraw - | TrainDraw - | OneClickGenerateDraw - | AxleCountingDraw - | SeparatorDraw - )[] = []; const draftType = useDrawStore().$state.draftType; if (draftType === 'Line') { - drawAssistants = [ - new PlatformDraw( - app, - new PlatformTemplate(new PlatformData(), new PlatformState()) - ), + new PlatformDraw( + app, + new PlatformTemplate(new PlatformData(), new PlatformState()) + ), new StationDraw( app, new StationTemplate(new StationData(), new StationState()) @@ -274,11 +257,9 @@ export function initDrawApp(dom: HTMLElement): IDrawApp { new AxleCountingTemplate(new AxleCountingData()) ), new SeparatorDraw(app, new SeparatorTemplate(new SeparatorData())), - ]; - DrawSignalInteraction.init(app); + DrawSignalInteraction.init(app); } else { - drawAssistants = [ - new StationLineDraw(app, new StationLineTemplate(new StationLineData())), + new StationLineDraw(app, new StationLineTemplate(new StationLineData())), new RectDraw(app, new RectTemplate(new RectData())), new RunLineDraw(app, new RunLineTemplate(new RunLineData())), new TrainLineDraw( @@ -286,14 +267,11 @@ export function initDrawApp(dom: HTMLElement): IDrawApp { new ItrainLineTemplate(new TrainLineData(), new TrainLineState()) ), new PathLineDraw(app, new PathLineTemplate(new PathLineData())), - ]; - DrawRunLinePlugin.init(app); + DrawRunLinePlugin.init(app); } - - app.setOptions({ drawAssistants: drawAssistants }); const handleRIghtClick = constructMenu(app); app.canvas.on('_rightclick', (e) => { - if (app._drawing) return; + if (app.drawing) return; handleRIghtClick(e); }); app.addKeyboardListener( @@ -394,14 +372,14 @@ export function saveDrawDatas(app: IDrawApp) { return base64; } -export async function loadDrawDatas(app: GraphicApp) { +export async function loadDrawDatas(): Promise { // localStorage.removeItem(StorageKey); // const base64 = localStorage.getItem(StorageKey); // console.log('加载数据', base64); const drawStore = useDrawStore(); const id = drawStore.draftId; if (!id) { - return; + throw new Error('获取数据异常:未获取到草稿地图ID'); } const { proto: base64 } = await getDraft(id); if (base64) { @@ -409,7 +387,6 @@ export async function loadDrawDatas(app: GraphicApp) { toUint8Array(base64) ); console.log('加载数据', storage); - app.updateCanvas(storage.canvas); const datas: GraphicData[] = []; storage.links.forEach((link) => { datas.push(new LinkData(link)); @@ -462,8 +439,12 @@ export async function loadDrawDatas(app: GraphicApp) { storage.trainWindows.forEach((trainWindow) => { datas.push(new TrainWindowData(trainWindow)); }); - app.loadGraphic(datas); - } else { - app.loadGraphic([]); + return Promise.resolve({ + canvasProperty: storage.canvas, + datas: datas, + }); } + return Promise.resolve({ + datas: [], + }); } diff --git a/src/graphics/axleCounting/AxleCountingDrawAssistant.ts b/src/graphics/axleCounting/AxleCountingDrawAssistant.ts index b7b38b7..d2f96bd 100644 --- a/src/graphics/axleCounting/AxleCountingDrawAssistant.ts +++ b/src/graphics/axleCounting/AxleCountingDrawAssistant.ts @@ -5,7 +5,7 @@ import { GraphicDrawAssistant, GraphicIdGenerator, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, distance2, } from 'src/jl-graphic'; @@ -16,7 +16,7 @@ import { AxleCountingTemplate, AxleCountingConsts, } from './AxleCounting'; -import { Section, SectionPort, SectionType } from '../section/Section'; +import { Section, SectionPort } from '../section/Section'; import { Turnout, TurnoutPort } from '../turnout/Turnout'; import { IRelatedRefData, createRelatedRefProto } from '../CommonGraphics'; import { Signal } from '../signal/Signal'; @@ -42,7 +42,7 @@ export class AxleCountingDraw extends GraphicDrawAssistant< IAxleCountingData > { codeGraph: AxleCounting; - constructor(app: JlDrawApp, template: AxleCountingTemplate) { + constructor(app: IDrawApp, template: AxleCountingTemplate) { super(app, template, 'sym_o_circle', '不展示'); this.codeGraph = this.graphicTemplate.new(); this.container.addChild(this.codeGraph); @@ -198,12 +198,6 @@ export class AxleCountingDraw extends GraphicDrawAssistant< if (axleCountingPs.y > height.y) { direction = -1; } - if ( - section.datas.sectionType === SectionType.Logic || - section.datas.children.includes(refDevice.id) - ) { - return; - } if (refDevice.type == Section.Type || refDevice.type == Turnout.Type) this.draw( axleCountingPs, @@ -352,10 +346,10 @@ function buildAbsorbablePositions( export class AxleCountingInteraction extends GraphicInteractionPlugin { static Name = 'AxleCounting_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(AxleCountingInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new AxleCountingInteraction(app); } filter(...grahpics: JlGraphic[]): AxleCounting[] | undefined { diff --git a/src/graphics/link/LinkDrawAssistant.ts b/src/graphics/link/LinkDrawAssistant.ts index 353af5f..8b833ad 100644 --- a/src/graphics/link/LinkDrawAssistant.ts +++ b/src/graphics/link/LinkDrawAssistant.ts @@ -10,11 +10,11 @@ import { import { AbsorbablePosition, DraggablePoint, - GraphicApp, + IGraphicApp, GraphicDrawAssistant, GraphicInteractionPlugin, GraphicTransformEvent, - JlDrawApp, + IDrawApp, JlGraphic, KeyListener, calculateMirrorPoint, @@ -61,7 +61,7 @@ export class LinkDraw extends GraphicDrawAssistant { }, }); - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(app, new LinkTemplate(), 'sym_o_horizontal_rule', '轨道Link'); this.container.addChild(this.graphic); this.graphicTemplate.curve = true; @@ -268,10 +268,10 @@ function onEditPointCreate( */ export class LinkPointsEditPlugin extends GraphicInteractionPlugin { static Name = 'LinkPointsDrag'; - constructor(app: GraphicApp) { + constructor(app: IGraphicApp) { super(LinkPointsEditPlugin.Name, app); } - static init(app: GraphicApp): LinkPointsEditPlugin { + static init(app: IGraphicApp): LinkPointsEditPlugin { return new LinkPointsEditPlugin(app); } filter(...grahpics: JlGraphic[]): Link[] | undefined { diff --git a/src/graphics/logicSection/LogicSectionDrawAssistant.ts b/src/graphics/logicSection/LogicSectionDrawAssistant.ts index d0ce5e0..2a6da02 100644 --- a/src/graphics/logicSection/LogicSectionDrawAssistant.ts +++ b/src/graphics/logicSection/LogicSectionDrawAssistant.ts @@ -1,8 +1,8 @@ import { - GraphicApp, + IGraphicApp, GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, linePoint, } from 'src/jl-graphic'; @@ -17,7 +17,7 @@ export class LogicSectionDraw extends GraphicDrawAssistant< > { points: Point[] = []; graphic = new Graphics(); - constructor(app: JlDrawApp, template: LogicSectionTemplate) { + constructor(app: IDrawApp, template: LogicSectionTemplate) { super(app, template, 'sym_o_timeline', '不展示'); this.container.addChild(this.graphic); LogicSectionEditPlugin.init(app); @@ -60,10 +60,10 @@ export class LogicSectionGraphicHitArea implements IHitArea { export class LogicSectionEditPlugin extends GraphicInteractionPlugin { static Name = 'LogicSectionInteraction'; - constructor(app: GraphicApp) { + constructor(app: IGraphicApp) { super(LogicSectionEditPlugin.Name, app); } - static init(app: GraphicApp) { + static init(app: IGraphicApp) { return new LogicSectionEditPlugin(app); } filter(...grahpics: JlGraphic[]): LogicSection[] | undefined { diff --git a/src/graphics/pathLine/PathLineDrawAssistant.ts b/src/graphics/pathLine/PathLineDrawAssistant.ts index f1e000d..f441808 100644 --- a/src/graphics/pathLine/PathLineDrawAssistant.ts +++ b/src/graphics/pathLine/PathLineDrawAssistant.ts @@ -1,9 +1,9 @@ import { GraphicDrawAssistant, - JlDrawApp, + IDrawApp, linePoint, GraphicInteractionPlugin, - GraphicApp, + IGraphicApp, JlGraphic, DraggablePoint, GraphicTransformEvent, @@ -37,7 +37,7 @@ export class PathLineDraw extends GraphicDrawAssistant< code = ''; graphic: Graphics = new Graphics(); - constructor(app: JlDrawApp, template: PathLineTemplate) { + constructor(app: IDrawApp, template: PathLineTemplate) { super(app, template, 'sym_o_horizontal_rule', '不展示'); this.container.addChild(this.graphic); PathLinePointsEditPlugin.init(app); @@ -106,10 +106,10 @@ export class PathLineGraphicHitArea implements IHitArea { export class PathLinePointsEditPlugin extends GraphicInteractionPlugin { static Name = 'LinkPointsDrag'; - constructor(app: GraphicApp) { + constructor(app: IGraphicApp) { super(PathLinePointsEditPlugin.Name, app); } - static init(app: GraphicApp): PathLinePointsEditPlugin { + static init(app: IGraphicApp): PathLinePointsEditPlugin { return new PathLinePointsEditPlugin(app); } filter(...grahpics: JlGraphic[]): PathLine[] | undefined { diff --git a/src/graphics/platform/Platform.ts b/src/graphics/platform/Platform.ts index c269244..89c03bb 100644 --- a/src/graphics/platform/Platform.ts +++ b/src/graphics/platform/Platform.ts @@ -372,7 +372,7 @@ export class Platform extends JlGraphic { return this.datas.code; } doRepaint(): void { - const station = this.queryStore.queryByCodeAndType( + const station = this.getGraphicApp().queryStore.queryByCodeAndType( this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, Station.Type ); diff --git a/src/graphics/platform/PlatformDrawAssistant.ts b/src/graphics/platform/PlatformDrawAssistant.ts index ad977a0..4530997 100644 --- a/src/graphics/platform/PlatformDrawAssistant.ts +++ b/src/graphics/platform/PlatformDrawAssistant.ts @@ -4,7 +4,7 @@ import { AbsorbablePosition, GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; @@ -19,7 +19,7 @@ export class PlatformDraw extends GraphicDrawAssistant< IPlatformData > { platformGraphic: Platform; - constructor(app: JlDrawApp, template: PlatformTemplate) { + constructor(app: IDrawApp, template: PlatformTemplate) { super( app, template, @@ -76,10 +76,10 @@ function buildAbsorbablePositions(platform: Platform): AbsorbablePosition[] { export class platformInteraction extends GraphicInteractionPlugin { static Name = 'platform_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(platformInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new platformInteraction(app); } filter(...grahpics: JlGraphic[]): Platform[] | undefined { diff --git a/src/graphics/polygon/PolygonDrawAssistant.ts b/src/graphics/polygon/PolygonDrawAssistant.ts index 34b853e..b65577a 100644 --- a/src/graphics/polygon/PolygonDrawAssistant.ts +++ b/src/graphics/polygon/PolygonDrawAssistant.ts @@ -7,11 +7,11 @@ import { } from 'pixi.js'; import { DraggablePoint, - GraphicApp, + IGraphicApp, GraphicDrawAssistant, GraphicInteractionPlugin, GraphicTransformEvent, - JlDrawApp, + IDrawApp, JlGraphic, linePoint, } from 'src/jl-graphic'; @@ -37,7 +37,7 @@ export class PolygonDraw extends GraphicDrawAssistant< points: Point[] = []; polygonGraphic: Graphics = new Graphics(); - constructor(app: JlDrawApp, template: PolygonTemplate) { + constructor(app: IDrawApp, template: PolygonTemplate) { super(app, template, 'sym_o_square', '多边形Polygon'); this.container.addChild(this.polygonGraphic); PolygonPointsEditPlugin.init(app); @@ -151,10 +151,10 @@ function onEditPointCreate(g: ILineGraphic, dp: DraggablePoint): void { */ export class PolygonPointsEditPlugin extends GraphicInteractionPlugin { static Name = 'PolygonPointsDrag'; - constructor(app: GraphicApp) { + constructor(app: IGraphicApp) { super(PolygonPointsEditPlugin.Name, app); } - static init(app: GraphicApp): PolygonPointsEditPlugin { + static init(app: IGraphicApp): PolygonPointsEditPlugin { return new PolygonPointsEditPlugin(app); } filter(...grahpics: JlGraphic[]): Polygon[] | undefined { diff --git a/src/graphics/rect/RectDrawAssistant.ts b/src/graphics/rect/RectDrawAssistant.ts index a43e327..a15bc2f 100644 --- a/src/graphics/rect/RectDrawAssistant.ts +++ b/src/graphics/rect/RectDrawAssistant.ts @@ -2,7 +2,7 @@ import { FederatedPointerEvent, Graphics, Point, IHitArea } from 'pixi.js'; import { GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, pointBox, } from 'src/jl-graphic'; @@ -18,7 +18,7 @@ export class RectDraw extends GraphicDrawAssistant { point2: Point | null = null; rectGraphic: Graphics = new Graphics(); - constructor(app: JlDrawApp, template: RectTemplate) { + constructor(app: IDrawApp, template: RectTemplate) { super(app, template, 'sym_o_square', '矩形Rect'); this.container.addChild(this.rectGraphic); rectInteraction.init(app); @@ -88,10 +88,10 @@ export class RectGraphicHitArea implements IHitArea { export class rectInteraction extends GraphicInteractionPlugin { static Name = 'platform_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(rectInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new rectInteraction(app); } filter(...grahpics: JlGraphic[]): Rect[] | undefined { diff --git a/src/graphics/runLine/RunLineDrawAssistant.ts b/src/graphics/runLine/RunLineDrawAssistant.ts index 914e690..d72de84 100644 --- a/src/graphics/runLine/RunLineDrawAssistant.ts +++ b/src/graphics/runLine/RunLineDrawAssistant.ts @@ -1,10 +1,10 @@ import { GraphicDrawAssistant, - JlDrawApp, + IDrawApp, JlGraphic, GraphicInteractionPlugin, linePoint, - GraphicApp, + IGraphicApp, AbsorbablePosition, DraggablePoint, GraphicTransformEvent, @@ -40,7 +40,7 @@ export class RunLineDraw extends GraphicDrawAssistant< points: Point[] = []; graphic: Graphics = new Graphics(); - constructor(app: JlDrawApp, template: RunLineTemplate) { + constructor(app: IDrawApp, template: RunLineTemplate) { super(app, template, 'sym_o_horizontal_rule', '运行线RunLine'); this.container.addChild(this.graphic); RunLinePointsEditPlugin.init(app); @@ -162,10 +162,10 @@ function onEditPointCreate( export class RunLinePointsEditPlugin extends GraphicInteractionPlugin { static Name = 'LinkPointsDrag'; - constructor(app: GraphicApp) { + constructor(app: IGraphicApp) { super(RunLinePointsEditPlugin.Name, app); } - static init(app: GraphicApp): RunLinePointsEditPlugin { + static init(app: IGraphicApp): RunLinePointsEditPlugin { return new RunLinePointsEditPlugin(app); } filter(...grahpics: JlGraphic[]): RunLine[] | undefined { diff --git a/src/graphics/section/SectionDrawAssistant.ts b/src/graphics/section/SectionDrawAssistant.ts index 95fd899..1a82c3d 100644 --- a/src/graphics/section/SectionDrawAssistant.ts +++ b/src/graphics/section/SectionDrawAssistant.ts @@ -1,13 +1,13 @@ import { ChildTransform, DraggablePoint, - GraphicApp, + IGraphicApp, GraphicDrawAssistant, GraphicInteractionPlugin, GraphicRelation, GraphicTransform, GraphicTransformEvent, - JlDrawApp, + IDrawApp, JlGraphic, VectorText, calculateLineMidpoint, @@ -60,7 +60,7 @@ export class SectionDraw extends GraphicDrawAssistant< points: Point[] = []; graphic = new Graphics(); - constructor(app: JlDrawApp, template: SectionTemplate) { + constructor(app: IDrawApp, template: SectionTemplate) { super(app, template, 'sym_o_timeline', '区段Section'); this.container.addChild(this.graphic); @@ -400,12 +400,12 @@ export class SectionPointEditPlugin extends GraphicInteractionPlugin
{ static Name = 'SectionPointDrag'; drawAssistant: SectionDraw; - constructor(app: GraphicApp, da: SectionDraw) { + constructor(app: IGraphicApp, da: SectionDraw) { super(SectionPointEditPlugin.Name, app); this.drawAssistant = da; app.registerMenu(SectionEditMenu); } - static init(app: GraphicApp, da: SectionDraw) { + static init(app: IGraphicApp, da: SectionDraw) { return new SectionPointEditPlugin(app, da); } filter(...grahpics: JlGraphic[]): Section[] | undefined { diff --git a/src/graphics/separator/SeparatorDrawAssistant.ts b/src/graphics/separator/SeparatorDrawAssistant.ts index 6d530d9..e244ecc 100644 --- a/src/graphics/separator/SeparatorDrawAssistant.ts +++ b/src/graphics/separator/SeparatorDrawAssistant.ts @@ -4,7 +4,7 @@ import { GraphicIdGenerator, GraphicInteractionPlugin, GraphicRelationParam, - JlDrawApp, + IDrawApp, JlGraphic, linePoint, } from 'src/jl-graphic'; @@ -25,7 +25,7 @@ export class SeparatorDraw extends GraphicDrawAssistant< ISeparatorData > { SeparatorGraph: Separator; - constructor(app: JlDrawApp, template: SeparatorTemplate) { + constructor(app: IDrawApp, template: SeparatorTemplate) { super(app, template, 'sym_o_square', '不展示'); this.SeparatorGraph = this.graphicTemplate.new(); this.container.addChild(this.SeparatorGraph); @@ -258,10 +258,10 @@ export class SeparatorGraphicHitArea implements IHitArea { export class SeparatorInteraction extends GraphicInteractionPlugin { static Name = 'Separator_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(SeparatorInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new SeparatorInteraction(app); } filter(...grahpics: JlGraphic[]): Separator[] | undefined { diff --git a/src/graphics/signal/SignalDrawAssistant.ts b/src/graphics/signal/SignalDrawAssistant.ts index 7971b55..3ac1bff 100644 --- a/src/graphics/signal/SignalDrawAssistant.ts +++ b/src/graphics/signal/SignalDrawAssistant.ts @@ -5,7 +5,7 @@ import { GraphicDrawAssistant, GraphicInteractionPlugin, GraphicTransformEvent, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; @@ -21,7 +21,7 @@ export class SignalDraw extends GraphicDrawAssistant< > { _signal: Signal | null = null; - constructor(app: JlDrawApp, template: SignalTemplate) { + constructor(app: IDrawApp, template: SignalTemplate) { super( app, template, @@ -129,10 +129,10 @@ function buildCodeAbsorbablePositions(signal: Signal): AbsorbablePosition[] { export class signalInteraction extends GraphicInteractionPlugin { static Name = 'signal_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(signalInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new signalInteraction(app); } filter(...grahpics: JlGraphic[]): Signal[] | undefined { diff --git a/src/graphics/station/StationDrawAssistant.ts b/src/graphics/station/StationDrawAssistant.ts index 15266cf..111af57 100644 --- a/src/graphics/station/StationDrawAssistant.ts +++ b/src/graphics/station/StationDrawAssistant.ts @@ -4,7 +4,7 @@ import { AbsorbablePosition, GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; @@ -19,7 +19,7 @@ export class StationDraw extends GraphicDrawAssistant< IStationData > { codeGraph: Station; - constructor(app: JlDrawApp, template: StationTemplate) { + constructor(app: IDrawApp, template: StationTemplate) { super( app, template, @@ -72,10 +72,10 @@ function buildAbsorbablePositions(station: Station): AbsorbablePosition[] { export class stationInteraction extends GraphicInteractionPlugin { static Name = 'station_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(stationInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new stationInteraction(app); } filter(...grahpics: JlGraphic[]): Station[] | undefined { diff --git a/src/graphics/stationLine/StationLineDrawAssistant.ts b/src/graphics/stationLine/StationLineDrawAssistant.ts index a329cb2..16c00ea 100644 --- a/src/graphics/stationLine/StationLineDrawAssistant.ts +++ b/src/graphics/stationLine/StationLineDrawAssistant.ts @@ -4,7 +4,7 @@ import { AbsorbablePosition, GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; @@ -24,7 +24,7 @@ export class StationLineDraw extends GraphicDrawAssistant< IStationLineData > { codeGraph: StationLine; - constructor(app: JlDrawApp, template: StationLineTemplate) { + constructor(app: IDrawApp, template: StationLineTemplate) { super( app, template, @@ -86,10 +86,10 @@ function buildAbsorbablePositions(Station: StationLine): AbsorbablePosition[] { export class stationLineInteraction extends GraphicInteractionPlugin { static Name = 'stationLine_transform'; static stationLine: StationLine; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(stationLineInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new stationLineInteraction(app); } filter(...grahpics: JlGraphic[]): StationLine[] | undefined { diff --git a/src/graphics/train/TrainDrawAssistant.ts b/src/graphics/train/TrainDrawAssistant.ts index 65577e0..8ea8153 100644 --- a/src/graphics/train/TrainDrawAssistant.ts +++ b/src/graphics/train/TrainDrawAssistant.ts @@ -2,7 +2,7 @@ import { Point, FederatedPointerEvent } from 'pixi.js'; import { GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; @@ -15,7 +15,7 @@ export interface ITrainDrawOptions { export class TrainDraw extends GraphicDrawAssistant { _Train: Train | null = null; - constructor(app: JlDrawApp, template: TrainTemplate) { + constructor(app: IDrawApp, template: TrainTemplate) { super(app, template, 'directions_bus_filled', '不展示'); trainInteraction.init(app); } @@ -48,10 +48,10 @@ export class TrainDraw extends GraphicDrawAssistant { export class trainInteraction extends GraphicInteractionPlugin { static Name = 'train_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(trainInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new trainInteraction(app); } filter(...grahpics: JlGraphic[]): Train[] | undefined { diff --git a/src/graphics/trainLine/TrainLineAssistant.ts b/src/graphics/trainLine/TrainLineAssistant.ts index ce26b49..765b5b0 100644 --- a/src/graphics/trainLine/TrainLineAssistant.ts +++ b/src/graphics/trainLine/TrainLineAssistant.ts @@ -2,7 +2,7 @@ import { FederatedMouseEvent, Point } from 'pixi.js'; import { GraphicDrawAssistant, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; import { ITrainLineData, TrainLine, ItrainLineTemplate } from './TrainLine'; @@ -13,7 +13,7 @@ export class TrainLineDraw extends GraphicDrawAssistant< > { train: TrainLine | null = null; - constructor(app: JlDrawApp, template: ItrainLineTemplate) { + constructor(app: IDrawApp, template: ItrainLineTemplate) { super(app, template, 'directions_bus_filled', '列车线网'); ItrainLineInteraction.init(app); } @@ -51,10 +51,10 @@ export class TrainLineDraw extends GraphicDrawAssistant< export class ItrainLineInteraction extends GraphicInteractionPlugin { static Name = 'trainLine_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(ItrainLineInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new ItrainLineInteraction(app); } filter(...grahpics: JlGraphic[]): TrainLine[] | undefined { diff --git a/src/graphics/trainWindow/TrainWindowDrawAssistant.ts b/src/graphics/trainWindow/TrainWindowDrawAssistant.ts index 3d7029e..6a126be 100644 --- a/src/graphics/trainWindow/TrainWindowDrawAssistant.ts +++ b/src/graphics/trainWindow/TrainWindowDrawAssistant.ts @@ -5,7 +5,7 @@ import { GraphicDrawAssistant, GraphicIdGenerator, GraphicInteractionPlugin, - JlDrawApp, + IDrawApp, JlGraphic, } from 'src/jl-graphic'; @@ -69,7 +69,7 @@ export class TrainWindowDraw extends GraphicDrawAssistant< ITrainWindowData > { trainWindowGraph: TrainWindow; - constructor(app: JlDrawApp, template: TrainWindowTemplate) { + constructor(app: IDrawApp, template: TrainWindowTemplate) { super(app, template, 'sym_o_square', '不展示'); this.trainWindowGraph = this.graphicTemplate.new(); this.container.addChild(this.trainWindowGraph); @@ -243,10 +243,10 @@ function buildAbsorbablePositions( export class TrainWindowInteraction extends GraphicInteractionPlugin { static Name = 'TrainWindow_transform'; - constructor(app: JlDrawApp) { + constructor(app: IDrawApp) { super(TrainWindowInteraction.Name, app); } - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new TrainWindowInteraction(app); } filter(...grahpics: JlGraphic[]): TrainWindow[] | undefined { diff --git a/src/graphics/turnout/TurnoutDrawAssistant.ts b/src/graphics/turnout/TurnoutDrawAssistant.ts index 5441e4d..fd19ad7 100644 --- a/src/graphics/turnout/TurnoutDrawAssistant.ts +++ b/src/graphics/turnout/TurnoutDrawAssistant.ts @@ -1,12 +1,12 @@ import { AbsorbablePosition, DraggablePoint, - GraphicApp, + IGraphicApp, GraphicDrawAssistant, GraphicInteractionPlugin, GraphicRelation, GraphicTransformEvent, - JlDrawApp, + IDrawApp, JlGraphic, VectorText, linePoint, @@ -44,7 +44,7 @@ export class TurnoutDraw extends GraphicDrawAssistant< ITurnoutData > { turnout: Turnout; - constructor(app: JlDrawApp, template: TurnoutTemplate) { + constructor(app: IDrawApp, template: TurnoutTemplate) { super(app, template, 'sym_o_ramp_left', '道岔Turnout'); this.turnout = this.graphicTemplate.new(); @@ -205,11 +205,11 @@ const turnoutSectionEditMenu: ContextMenu = ContextMenu.init({ export class TurnoutPointsInteractionPlugin extends GraphicInteractionPlugin { static Name = 'TurnoutPointsDrag'; - static init(app: JlDrawApp) { + static init(app: IDrawApp) { return new TurnoutPointsInteractionPlugin(app); } - constructor(app: GraphicApp) { + constructor(app: IGraphicApp) { super(TurnoutPointsInteractionPlugin.Name, app); app.registerMenu(turnoutSectionEditMenu); } diff --git a/src/jl-graphic/app/JlGraphicApp.ts b/src/jl-graphic/app/JlGraphicApp.ts index ddeecd0..b47fab1 100644 --- a/src/jl-graphic/app/JlGraphicApp.ts +++ b/src/jl-graphic/app/JlGraphicApp.ts @@ -527,6 +527,14 @@ export interface IGraphicScene extends EventEmitter { * 销毁 */ destroy(): void; + /** + * 订阅websocket消息 + */ + subscribe(sub: AppStateSubscription): void; + /** + * 取消websocket订阅 + */ + unsubscribe(destination: string): void; } abstract class GraphicSceneBase diff --git a/src/layouts/DrawLayout.vue b/src/layouts/DrawLayout.vue index 9b64769..8b216d0 100644 --- a/src/layouts/DrawLayout.vue +++ b/src/layouts/DrawLayout.vue @@ -139,7 +139,7 @@ -
+
import DrawProperties from 'src/components/draw-app/DrawProperties.vue'; -import { - getDrawApp, - loadDrawDatas, - saveDrawDatas, - saveDrawToServer, -} from 'src/drawApp'; -import { JlDrawApp } from 'src/jl-graphic'; +import { getDrawApp, saveDrawDatas, saveDrawToServer } from 'src/drawApp'; +import { IDrawApp } from 'src/jl-graphic'; import { useDrawStore } from 'src/stores/draw-store'; import { onMounted, onUnmounted, reactive, ref, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; @@ -191,6 +186,15 @@ import { Separator } from 'src/graphics/separator/Separator'; import { SeparatorDraw } from 'src/graphics/separator/SeparatorDrawAssistant'; import { SectionDraw } from 'src/graphics/section/SectionDrawAssistant'; import { Section } from 'src/graphics/section/Section'; +import { Platform } from 'src/graphics/platform/Platform'; +import { Station } from 'src/graphics/station/Station'; +import { Signal } from 'src/graphics/signal/Signal'; +import { Turnout } from 'src/graphics/turnout/Turnout'; +import { Rect } from 'src/graphics/rect/Rect'; +import { TrainLine } from 'src/graphics/trainLine/TrainLine'; +import { StationLine } from 'src/graphics/stationLine/StationLine'; +import { RunLine } from 'src/graphics/runLine/RunLine'; +import { PathLine } from 'src/graphics/pathLine/PathLine'; const route = useRoute(); const router = useRouter(); @@ -245,26 +249,48 @@ onMounted(() => { drawStore.setDraftType(route.params.type as string); if (dom) { drawStore.setDraftId(+route.params.id as number); - const drawApp = drawStore.initDrawApp(dom); - loadDrawDatas(drawApp); + const drawApp = drawStore.initDrawApp(); + drawApp.bindDom(dom); + drawApp.reload(); onResize(); } else { drawStore.setDraftId(null); } - const drawAssistants = (getDrawApp()?._options as { drawAssistants: [] }) - .drawAssistants; - drawAssistants.forEach( - (da: { name: string; icon: string; description: string }) => { - if (da.description === '不展示') return; + let drawAssistantsTypes: string[] = []; + const draftType = useDrawStore().$state.draftType; + if (draftType === 'Line') { + drawAssistantsTypes = [ + Platform.Type, + Station.Type, + Signal.Type, + Section.Type, + Turnout.Type, + ]; + } else { + drawAssistantsTypes = [ + Rect.Type, + TrainLine.Type, + StationLine.Type, + RunLine.Type, + PathLine.Type, + ]; + } + + drawAssistantsTypes.forEach((type) => { + const drawAssistant = getDrawApp()?.getDrawAssistant(type); + if (drawAssistant) { + if (drawAssistant.description === '不展示') return; utilsOption.push( new ControlItem( - da.name, - da.icon, - da.description ? da.description : da.name + drawAssistant.name, + drawAssistant.icon, + drawAssistant.description + ? drawAssistant.description + : drawAssistant.name ) ); } - ); + }); }); const canvasWidth = ref(0); @@ -299,14 +325,10 @@ function onResize() { dom.style.width = canvasWidth.value + 'px'; dom.style.height = canvasHeight.value + 'px'; } - const drawApp = getDrawApp(); - if (drawApp) { - drawApp.onDomResize(canvasWidth.value, canvasHeight.value); - } } function saveAllDrawDatas() { const drawApp = getDrawApp(); - saveDrawToServer(drawApp as JlDrawApp); + saveDrawToServer(drawApp as IDrawApp); } function buildRelations() { @@ -351,7 +373,7 @@ const saveAsName = ref(''); async function saveAs(name: string) { try { const drawApp = getDrawApp(); - const base64 = saveDrawDatas(drawApp as JlDrawApp); + const base64 = saveDrawDatas(drawApp as IDrawApp); const record = await saveAsDraft(+route.params.id as number, { name, proto: base64, diff --git a/src/stores/draw-store.ts b/src/stores/draw-store.ts index e1a35af..3601f9e 100644 --- a/src/stores/draw-store.ts +++ b/src/stores/draw-store.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia'; import { destroyDrawApp, getDrawApp, initDrawApp } from 'src/drawApp'; -import { DrawAssistant, JlCanvas, JlDrawApp, JlGraphic } from 'src/jl-graphic'; +import { DrawAssistant, IJlCanvas, IDrawApp, JlGraphic } from 'src/jl-graphic'; export const useDrawStore = defineStore('draw', { state: () => ({ @@ -44,18 +44,18 @@ export const useDrawStore = defineStore('draw', { }, }, actions: { - getDrawApp(): JlDrawApp { + getDrawApp(): IDrawApp { const app = getDrawApp(); if (app == null) { throw new Error('未初始化app'); } return app; }, - getJlCanvas(): JlCanvas { + getJlCanvas(): IJlCanvas { return this.getDrawApp().canvas; }, - initDrawApp(dom: HTMLElement) { - const app = initDrawApp(dom); + initDrawApp() { + const app = initDrawApp(); app.on('interaction-plugin-resume', (plugin) => { if (plugin.isAppPlugin()) { if (Object.hasOwn(plugin, '__GraphicDrawAssistant')) {