From db143530c153fe223e7c7673ce67da52144c374a Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Mon, 26 Jun 2023 10:05:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E6=AC=A1=E7=AA=97=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=BE=85=E5=8A=A9=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/index.ts | 6 ++ src/graphics/trainWindow/TrainWindow.ts | 2 +- .../trainWindow/TrainWindowDrawAssistant.ts | 22 ++---- .../trainWindow/oneClickDrawAssistant.ts | 71 +++++++++++++++++++ src/layouts/DrawLayout.vue | 8 +-- 5 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 src/graphics/trainWindow/oneClickDrawAssistant.ts diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index b1def62..4610efd 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -47,6 +47,10 @@ import { } from 'src/graphics/trainLine/TrainLine'; import { TrainLineDraw } from 'src/graphics/trainLine/TrainLineAssistant'; import { TrainLineData } from './graphics/TrainLineInteraction'; +import { + OneClickGenerateDraw, + OneClickGenerateTemplate, +} from 'src/graphics/trainWindow/oneClickDrawAssistant'; import { TrainWindow, TrainWindowTemplate, @@ -153,6 +157,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { | PathLineDraw | TrainWindowDraw | TrainDraw + | OneClickGenerateDraw )[] = []; if (draftType === 'Line') { drawAssistants = [ @@ -172,6 +177,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { new SectionDraw(app, new SectionTemplate(new SectionData())), new TurnoutDraw(app, new TurnoutTemplate(new TurnoutData())), new TrainWindowDraw(app, new TrainWindowTemplate(new TrainWindowData())), + new OneClickGenerateDraw(app, new OneClickGenerateTemplate()), ]; DrawSignalInteraction.init(app); } else { diff --git a/src/graphics/trainWindow/TrainWindow.ts b/src/graphics/trainWindow/TrainWindow.ts index 29e9128..af2ed1d 100644 --- a/src/graphics/trainWindow/TrainWindow.ts +++ b/src/graphics/trainWindow/TrainWindow.ts @@ -23,7 +23,7 @@ export const TrainWindowConsts = { height: 15, lineWidth: 2, lineColor: '0x0fe81f', - offsetSection: 60, + offsetSection: 120, }; export class TrainWindow extends JlGraphic { diff --git a/src/graphics/trainWindow/TrainWindowDrawAssistant.ts b/src/graphics/trainWindow/TrainWindowDrawAssistant.ts index 0c8fec2..73a7007 100644 --- a/src/graphics/trainWindow/TrainWindowDrawAssistant.ts +++ b/src/graphics/trainWindow/TrainWindowDrawAssistant.ts @@ -94,20 +94,8 @@ export class TrainWindowDraw extends GraphicDrawAssistant< } this.storeGraphic(...trainWindows); } - oneGenerates() { + oneGenerates(height: Point) { const sections = this.app.queryStore.queryByType
(Section.Type); - const sectionSelect = this.app.selectedGraphics[0] as Section; - let height = 0; - if (sections.length && sectionSelect !== undefined) { - if (sectionSelect.datas.transform.position.y == 0) { - height = sectionSelect.datas.points[0].y + 5; - } else { - height = - sectionSelect.datas.points[0].y + - sectionSelect.datas.transform.position.y + - 5; - } - } const trainWindowAll = this.app.queryStore.queryByType( TrainWindow.Type ); @@ -120,7 +108,7 @@ export class TrainWindowDraw extends GraphicDrawAssistant< ps.push(new Point(point.x + transPos.x, point.y + transPos.y)); }); let direction = 1; - if (ps[0].y > height) { + if (ps[0].y > height.y) { direction = -1; } for (let i = 0; i < ps.length - 1; i++) { @@ -206,15 +194,15 @@ export class TrainWindowInteraction extends GraphicInteractionPlugin { + constructor() { + super(OneClickGenerate.Type, {}); + } + new(): OneClickGenerate { + return new OneClickGenerate(); + } +} + +export class OneClickGenerateDraw extends GraphicDrawAssistant< +OneClickGenerateTemplate, + IOneClickData +> { + lineGraph: OneClickGenerate; + constructor(app: JlDrawApp, template: OneClickGenerateTemplate) { + super(app, template, 'sym_o_square', '不展示'); + this.lineGraph = this.graphicTemplate.new(); + this.container.addChild(this.lineGraph); + } + + bind(): void { + super.bind(); + this.lineGraph.doRepaint(); + } + onLeftDown(e: FederatedPointerEvent): void { + this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); + const trainWindowDraw = this.app.getDrawAssistant( + TrainWindow.Type + ) as TrainWindowDraw; + trainWindowDraw.oneGenerates(this.toCanvasCoordinates(e.global)); + this.finish(); + } + + redraw(p: Point): void { + this.container.position.copyFrom(p); + } + prepareData(): boolean { + return true; + } +} diff --git a/src/layouts/DrawLayout.vue b/src/layouts/DrawLayout.vue index d41d59c..16ee051 100644 --- a/src/layouts/DrawLayout.vue +++ b/src/layouts/DrawLayout.vue @@ -177,8 +177,7 @@ import { useRoute, useRouter } from 'vue-router'; import { errorNotify, successNotify } from 'src/utils/CommonNotify'; import { saveAsDraft } from 'src/api/DraftApi'; import { ApiError } from 'src/boot/axios'; -import { TrainWindowDraw } from 'src/graphics/trainWindow/TrainWindowDrawAssistant'; -import { TrainWindow } from 'src/graphics/trainWindow/TrainWindow'; +import { OneClickGenerate } from 'src/graphics/trainWindow/oneClickDrawAssistant'; const route = useRoute(); const router = useRouter(); @@ -304,10 +303,7 @@ function buildRelations() { } function oneClickGeneration() { - const trainWindowDraw = drawStore - .getDrawApp() - .getDrawAssistant(TrainWindow.Type) as TrainWindowDraw; - trainWindowDraw.oneGenerates(); + drawStore.getDrawApp().interactionPlugin(OneClickGenerate.Type).resume(); } function backConfirm() {