框架同步

This commit is contained in:
Yuan 2023-11-01 15:05:30 +08:00
parent 9bb34e73b4
commit cdd14016ac
5 changed files with 77 additions and 16 deletions

@ -1 +1 @@
Subproject commit 460a6237e3095df4f7f666d4415f84abddc416e3 Subproject commit 6ac8af13ebb029b428cc45e5ca70f5da01f50029

View File

@ -475,7 +475,8 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
*/ */
handleGraphicStates( handleGraphicStates(
graphicStates: GraphicState[], graphicStates: GraphicState[],
queryer?: GraphicQuery queryer?: GraphicQuery,
createOnNotFound?: boolean
): void; ): void;
/** /**
* *
@ -1092,7 +1093,8 @@ abstract class GraphicSceneBase
*/ */
handleGraphicStates( handleGraphicStates(
graphicStates: GraphicState[], graphicStates: GraphicState[],
queryer?: GraphicQuery queryer?: GraphicQuery,
createOnNotFound?: boolean
): void { ): void {
graphicStates.forEach((state) => { graphicStates.forEach((state) => {
let g: JlGraphic | undefined; let g: JlGraphic | undefined;
@ -1103,12 +1105,21 @@ abstract class GraphicSceneBase
} }
try { try {
if (!g) { if (!g) {
const template = this.getGraphicTemplatesByType(state.graphicType); // 未找到图形对象
const g = template.new(); if (createOnNotFound) {
g.loadState(state); const template = this.getGraphicTemplatesByType(state.graphicType);
this.addGraphics(g); const g = template.new();
} else if (g.updateStates(state)) { g.loadState(state);
g.repaint(); this.addGraphics(g);
}
} else {
// 找到
if (state.remove) {
this.deleteGraphics(g);
g.destroy({ children: true });
} else if (g.updateStates(state)) {
g.repaint();
}
} }
} catch (err) { } catch (err) {
console.error('图形状态处理异常', g, state, err); console.error('图形状态处理异常', g, state, err);

View File

@ -502,6 +502,7 @@ export interface GraphicData {
export interface GraphicState { export interface GraphicState {
get code(): string; // 业务标识 get code(): string; // 业务标识
get graphicType(): string; // 图形类型 get graphicType(): string; // 图形类型
remove?: boolean; // 是否移除图形
/** /**
* *
*/ */

View File

@ -146,6 +146,7 @@ export type GraphicStateMessageConvert = (
message: Uint8Array message: Uint8Array
) => GraphicState[]; ) => GraphicState[];
// 根据状态查询图形对象查询器
export type GraphicQuery = ( export type GraphicQuery = (
state: GraphicState, state: GraphicState,
store: GraphicQueryStore store: GraphicQueryStore
@ -168,6 +169,10 @@ export interface AppStateSubscription {
* ,code和type查询图形对象 * ,code和type查询图形对象
*/ */
graphicQueryer?: GraphicQuery; graphicQueryer?: GraphicQuery;
/**
*
*/
createOnNotFound?: boolean;
/** /**
* *
*/ */
@ -196,7 +201,11 @@ class AppMessageHandler implements IMessageHandler {
const sub = this.sub; const sub = this.sub;
if (sub.messageConverter) { if (sub.messageConverter) {
const graphicStates = sub.messageConverter(data); const graphicStates = sub.messageConverter(data);
this.app.handleGraphicStates(graphicStates, sub.graphicQueryer); this.app.handleGraphicStates(
graphicStates,
sub.graphicQueryer,
sub.createOnNotFound
);
} else if (sub.messageHandle) { } else if (sub.messageHandle) {
sub.messageHandle(data); sub.messageHandle(data);
} }

View File

@ -24,6 +24,10 @@ export interface IMouseToolOptions {
* (), * (),
*/ */
viewportDrag?: boolean; viewportDrag?: boolean;
/**
*
*/
viewportDragLeft?: boolean;
/** /**
* , * ,
*/ */
@ -37,12 +41,14 @@ export interface IMouseToolOptions {
class CompleteMouseToolOptions implements IMouseToolOptions { class CompleteMouseToolOptions implements IMouseToolOptions {
boxSelect: boolean; boxSelect: boolean;
viewportDrag: boolean; viewportDrag: boolean;
viewportDragLeft: boolean;
wheelZoom: boolean; wheelZoom: boolean;
selectFilter?: GraphicSelectFilter | undefined; selectFilter?: GraphicSelectFilter | undefined;
constructor() { constructor() {
this.boxSelect = true; this.boxSelect = true;
this.viewportDrag = true; this.viewportDrag = true;
this.wheelZoom = true; this.wheelZoom = true;
this.viewportDragLeft = false;
} }
update(options: IMouseToolOptions) { update(options: IMouseToolOptions) {
if (options.boxSelect != undefined) { if (options.boxSelect != undefined) {
@ -51,6 +57,9 @@ class CompleteMouseToolOptions implements IMouseToolOptions {
if (options.viewportDrag != undefined) { if (options.viewportDrag != undefined) {
this.viewportDrag = options.viewportDrag; this.viewportDrag = options.viewportDrag;
} }
if (options.viewportDragLeft != undefined) {
this.viewportDragLeft = options.viewportDragLeft;
}
if (options.wheelZoom != undefined) { if (options.wheelZoom != undefined) {
this.wheelZoom = options.wheelZoom; this.wheelZoom = options.wheelZoom;
} }
@ -132,12 +141,21 @@ export class CommonMouseTool extends AppInteractionPlugin {
this.app.on('drag_op_move', this.onDragMove, this); this.app.on('drag_op_move', this.onDragMove, this);
this.app.on('drag_op_end', this.onDragEnd, this); this.app.on('drag_op_end', this.onDragEnd, this);
if (this.options.viewportDrag) { if (this.options.viewportDrag) {
this.app.viewport.drag({ if (this.options.viewportDragLeft) {
mouseButtons: 'right', this.app.viewport.drag({
}); mouseButtons: 'left',
canvas.on('rightdown', this.setCursor, this); });
canvas.on('rightup', this.resumeCursor, this); canvas.on('mousedown', this.setLeftCursor, this);
canvas.on('rightupoutside', this.resumeCursor, this); canvas.on('mouseup', this.resumeLeftCursor, this);
canvas.on('mouseupoutside', this.resumeLeftCursor, this);
} else {
this.app.viewport.drag({
mouseButtons: 'right',
});
canvas.on('rightdown', this.setCursor, this);
canvas.on('rightup', this.resumeCursor, this);
canvas.on('rightupoutside', this.resumeCursor, this);
}
} }
if (this.options.wheelZoom) { if (this.options.wheelZoom) {
this.app.viewport.wheel({ this.app.viewport.wheel({
@ -156,6 +174,9 @@ export class CommonMouseTool extends AppInteractionPlugin {
this.app.off('drag_op_end', this.onDragEnd, this); this.app.off('drag_op_end', this.onDragEnd, this);
this.app.viewport.plugins.remove('drag'); this.app.viewport.plugins.remove('drag');
canvas.off('mousedown', this.setLeftCursor, this);
canvas.off('mouseup', this.resumeLeftCursor, this);
canvas.off('mouseupoutside', this.resumeLeftCursor, this);
canvas.off('rightdown', this.setCursor, this); canvas.off('rightdown', this.setCursor, this);
canvas.off('rightup', this.resumeCursor, this); canvas.off('rightup', this.resumeCursor, this);
canvas.off('rightupoutside', this.resumeCursor, this); canvas.off('rightupoutside', this.resumeCursor, this);
@ -199,6 +220,25 @@ export class CommonMouseTool extends AppInteractionPlugin {
} }
} }
setLeftCursor(e: FederatedMouseEvent) {
const target = e.target as DisplayObject;
this.leftDownTarget = target;
if (target.isCanvas() && this.app.pixi.view.style) {
this.app.pixi.view.style.cursor = 'grab';
}
}
resumeLeftCursor() {
if (
this.leftDownTarget &&
this.leftDownTarget.isCanvas() &&
this.app.pixi.view.style
) {
this.app.pixi.view.style.cursor = 'inherit';
}
this.leftDownTarget = null;
}
setCursor(e: FederatedMouseEvent) { setCursor(e: FederatedMouseEvent) {
const target = e.target as DisplayObject; const target = e.target as DisplayObject;
this.rightTarget = target; this.rightTarget = target;