From b965bd7c77a17da6cb398191d5febbaecbc226d0 Mon Sep 17 00:00:00 2001 From: fan Date: Fri, 22 Sep 2023 11:05:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphic-pixi | 2 +- src/jl-graphic/app/JlDrawApp.ts | 8 ++++++-- src/jl-graphic/app/JlGraphicApp.ts | 21 +++++++++++++++------ src/jl-graphic/message/MessageBroker.ts | 13 +++++++++++-- src/jl-graphic/plugins/InteractionPlugin.ts | 10 +++------- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/graphic-pixi b/graphic-pixi index 3e1bbc9..023c84c 160000 --- a/graphic-pixi +++ b/graphic-pixi @@ -1 +1 @@ -Subproject commit 3e1bbc92bf3e1604ec54db0e9188a1677ac20388 +Subproject commit 023c84c4ccf7f38e477253e1b49856bfb50aca18 diff --git a/src/jl-graphic/app/JlDrawApp.ts b/src/jl-graphic/app/JlDrawApp.ts index 25ef784..78040c7 100644 --- a/src/jl-graphic/app/JlDrawApp.ts +++ b/src/jl-graphic/app/JlDrawApp.ts @@ -523,8 +523,12 @@ export class JlDrawApp extends GraphicApp implements IDrawApp { */ bindFormData(form: GraphicData): void { this.formData = form; - if (this.selectedGraphics.length == 1) { - this.formData.copyFrom(this.selectedGraphics[0].saveData()); + if (this.formData && this.selectedGraphics.length == 1) { + if (this.formData.graphicType == this.selectedGraphics[0].type) { + this.formData.copyFrom(this.selectedGraphics[0].saveData()); + } else { + this.formData = undefined; + } } } diff --git a/src/jl-graphic/app/JlGraphicApp.ts b/src/jl-graphic/app/JlGraphicApp.ts index afc67d5..3510b75 100644 --- a/src/jl-graphic/app/JlGraphicApp.ts +++ b/src/jl-graphic/app/JlGraphicApp.ts @@ -24,6 +24,7 @@ import { WsMsgCli, type AppStateSubscription, type MessageCliOption, + GraphicQuery, } from '../message'; import { OperationRecord } from '../operation/JlOperation'; import { @@ -472,7 +473,10 @@ export interface IGraphicScene extends EventEmitter { * 处理图形状态 * @param graphicStates */ - handleGraphicStates(graphicStates: GraphicState[]): void; + handleGraphicStates( + graphicStates: GraphicState[], + queryer?: GraphicQuery + ): void; /** * 根据类型获取图形模板 * @param type @@ -1083,12 +1087,17 @@ abstract class GraphicSceneBase * 处理图形状态 * @param graphicStates */ - handleGraphicStates(graphicStates: GraphicState[]): void { + handleGraphicStates( + graphicStates: GraphicState[], + queryer?: GraphicQuery + ): void { graphicStates.forEach((state) => { - const g = this.queryStore.queryByCodeAndType( - state.code, - state.graphicType - ); + let g: JlGraphic | undefined; + if (queryer) { + g = queryer(state, this.queryStore); + } else { + g = this.queryStore.queryByCodeAndType(state.code, state.graphicType); + } try { if (!g) { const template = this.getGraphicTemplatesByType(state.graphicType); diff --git a/src/jl-graphic/message/MessageBroker.ts b/src/jl-graphic/message/MessageBroker.ts index cec650b..0d2c2b1 100644 --- a/src/jl-graphic/message/MessageBroker.ts +++ b/src/jl-graphic/message/MessageBroker.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import EventEmitter from 'eventemitter3'; import { IGraphicScene } from '../app'; -import { GraphicState } from '../core'; +import { GraphicQueryStore, GraphicState, JlGraphic } from '../core'; import { IMessageHandler, IUnsubscriptor, @@ -146,6 +146,11 @@ export type GraphicStateMessageConvert = ( message: Uint8Array ) => GraphicState[]; +export type GraphicQuery = ( + state: GraphicState, + store: GraphicQueryStore +) => JlGraphic | undefined; + // 订阅消息处理器 export type SubscriptionMessageHandle = (message: Uint8Array) => void; @@ -159,6 +164,10 @@ export interface AppStateSubscription { * 图形状态消息转换 */ messageConverter?: GraphicStateMessageConvert; + /** + * 根据状态查询图形对象,默认为根据code和type查询图形对象 + */ + graphicQueryer?: GraphicQuery; /** * 订阅消息处理 */ @@ -187,7 +196,7 @@ class AppMessageHandler implements IMessageHandler { const sub = this.sub; if (sub.messageConverter) { const graphicStates = sub.messageConverter(data); - this.app.handleGraphicStates(graphicStates); + this.app.handleGraphicStates(graphicStates, sub.graphicQueryer); } else if (sub.messageHandle) { sub.messageHandle(data); } diff --git a/src/jl-graphic/plugins/InteractionPlugin.ts b/src/jl-graphic/plugins/InteractionPlugin.ts index 080f879..23e2210 100644 --- a/src/jl-graphic/plugins/InteractionPlugin.ts +++ b/src/jl-graphic/plugins/InteractionPlugin.ts @@ -4,11 +4,7 @@ import { FederatedPointerEvent, Point, } from 'pixi.js'; -import { - IGraphicApp, - IGraphicAppConfig, - IGraphicScene, -} from '../app/JlGraphicApp'; +import { IGraphicAppConfig, IGraphicScene } from '../app/JlGraphicApp'; import { JlGraphic } from '../core/JlGraphic'; export enum InteractionPluginType { @@ -417,10 +413,10 @@ export abstract class GraphicInteractionPlugin implements InteractionPlugin { readonly _type = InteractionPluginType.Graphic; - app: IGraphicApp; + app: IGraphicScene; name: string; // 唯一标识 _pause: boolean; - constructor(name: string, app: IGraphicApp) { + constructor(name: string, app: IGraphicScene) { this.app = app; this.name = name; this._pause = true;