Merge branch 'master' of git.code.tencent.com:xian-ncc-da/xian-ncc-da-client

This commit is contained in:
Yuan 2023-09-01 14:31:45 +08:00
commit f63ec5b12c
22 changed files with 159 additions and 154 deletions

View File

@ -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<IGraphicStorage> {
// 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: [],
});
}

View File

@ -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<AxleCounting> {
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 {

View File

@ -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<LinkTemplate, ILinkData> {
},
});
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<Link> {
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 {

View File

@ -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<LogicSection> {
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 {

View File

@ -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<PathLine> {
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 {

View File

@ -372,7 +372,7 @@ export class Platform extends JlGraphic {
return this.datas.code;
}
doRepaint(): void {
const station = this.queryStore.queryByCodeAndType<Station>(
const station = this.getGraphicApp().queryStore.queryByCodeAndType<Station>(
this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId,
Station.Type
);

View File

@ -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<Platform> {
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 {

View File

@ -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<Polygon> {
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 {

View File

@ -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<RectTemplate, IRectData> {
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<Rect> {
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 {

View File

@ -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<RunLine> {
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 {

View File

@ -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<Section> {
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 {

View File

@ -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<Separator> {
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 {

View File

@ -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<Signal> {
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 {

View File

@ -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<Station> {
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 {

View File

@ -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<StationLine> {
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 {

View File

@ -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<TrainTemplate, ITrainData> {
_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<TrainTemplate, ITrainData> {
export class trainInteraction extends GraphicInteractionPlugin<Train> {
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 {

View File

@ -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<TrainLine> {
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 {

View File

@ -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<TrainWindow> {
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 {

View File

@ -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<Turnout> {
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);
}

View File

@ -527,6 +527,14 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
*
*/
destroy(): void;
/**
* websocket消息
*/
subscribe(sub: AppStateSubscription): void;
/**
* websocket订阅
*/
unsubscribe(destination: string): void;
}
abstract class GraphicSceneBase

View File

@ -139,7 +139,7 @@
</q-drawer>
<q-page-container>
<div id="draw-app-container"></div>
<div id="draw-app-container" class="overflow-hidden"></div>
</q-page-container>
<q-dialog
@ -173,13 +173,8 @@
<script setup lang="ts">
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,

View File

@ -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')) {