127 lines
4.7 KiB
TypeScript
127 lines
4.7 KiB
TypeScript
|
|
/**
|
|||
|
|
* Manager 注册表
|
|||
|
|
* 全局单例,提供所有 Manager 的集中访问点
|
|||
|
|
*/
|
|||
|
|
import { EventEmitter } from './event-emitter';
|
|||
|
|
import type { EngineEvents } from '../types/events';
|
|||
|
|
|
|||
|
|
import type { ToolbarManager } from '../managers/toolbar-manager';
|
|||
|
|
import type { DialogManager } from '../managers/dialog-manager';
|
|||
|
|
import type { EngineManager } from '../managers/engine-manager';
|
|||
|
|
import type { ButtonGroupManager } from '../managers/button-group-manager';
|
|||
|
|
import type { RightKeyManager } from '../managers/right-key-manager';
|
|||
|
|
import type { ConstructTreeManagerBtn } from '../managers/construct-tree-manager-btn';
|
|||
|
|
import type { PropertyPanelManager } from '../managers/property-panel-manager';
|
|||
|
|
import type { MeasureDialogManager } from '../managers/measure-dialog-manager';
|
|||
|
|
import type { WalkControlManager } from '../managers/walk-control-manager';
|
|||
|
|
import type { MapDialogManager } from '../managers/map-dialog-manager';
|
|||
|
|
import type { SectionPlaneDialogManager } from '../managers/section-plane-dialog-manager';
|
|||
|
|
import type { SectionAxisDialogManager } from '../managers/section-axis-dialog-manager';
|
|||
|
|
import type { SectionBoxDialogManager } from '../managers/section-box-dialog-manager';
|
|||
|
|
import type { WalkPathDialogManager } from '../managers/walk-path-dialog-manager';
|
|||
|
|
import type { WalkPlanViewDialogManager } from '../managers/walk-plan-view-dialog-manager';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Manager 注册表 - 单例模式
|
|||
|
|
* 提供所有 Manager 的全局访问点,替代 engine 层层传递
|
|||
|
|
*/
|
|||
|
|
export class ManagerRegistry {
|
|||
|
|
/** 单例实例 */
|
|||
|
|
private static instance: ManagerRegistry | null = null;
|
|||
|
|
/** 事件发射器 */
|
|||
|
|
private eventEmitter: EventEmitter = new EventEmitter();
|
|||
|
|
|
|||
|
|
/** 主容器元素 */
|
|||
|
|
public container: HTMLElement | null = null;
|
|||
|
|
/** 包装容器元素 */
|
|||
|
|
public wrapper: HTMLElement | null = null;
|
|||
|
|
|
|||
|
|
/** 工具栏管理器 */
|
|||
|
|
public toolbar: ToolbarManager | null = null;
|
|||
|
|
/** 对话框管理器 */
|
|||
|
|
public dialog: DialogManager | null = null;
|
|||
|
|
/** 3D 引擎管理器 */
|
|||
|
|
public engine3d: EngineManager | null = null;
|
|||
|
|
/** 按钮组管理器 */
|
|||
|
|
public buttonGroup: ButtonGroupManager | null = null;
|
|||
|
|
/** 右键菜单管理器 */
|
|||
|
|
public rightKey: RightKeyManager | null = null;
|
|||
|
|
/** 构件树管理器 */
|
|||
|
|
public constructTree: ConstructTreeManagerBtn | null = null;
|
|||
|
|
/** 属性面板管理器 */
|
|||
|
|
public propertyPanel: PropertyPanelManager | null = null;
|
|||
|
|
/** 测量对话框管理器 */
|
|||
|
|
public measure: MeasureDialogManager | null = null;
|
|||
|
|
/** 漫游控制管理器 */
|
|||
|
|
public walkControl: WalkControlManager | null = null;
|
|||
|
|
/** 地图对话框管理器 */
|
|||
|
|
public map: MapDialogManager | null = null;
|
|||
|
|
/** 拾取面剖切对话框管理器 */
|
|||
|
|
public sectionPlane: SectionPlaneDialogManager | null = null;
|
|||
|
|
/** 轴向剖切对话框管理器 */
|
|||
|
|
public sectionAxis: SectionAxisDialogManager | null = null;
|
|||
|
|
/** 剖切盒对话框管理器 */
|
|||
|
|
public sectionBox: SectionBoxDialogManager | null = null;
|
|||
|
|
/** 漫游路径对话框管理器 */
|
|||
|
|
public walkPath: WalkPathDialogManager | null = null;
|
|||
|
|
/** 漫游平面图对话框管理器 */
|
|||
|
|
public walkPlanView: WalkPlanViewDialogManager | null = null;
|
|||
|
|
|
|||
|
|
private constructor() {}
|
|||
|
|
|
|||
|
|
/** 获取单例实例 */
|
|||
|
|
public static getInstance(): ManagerRegistry {
|
|||
|
|
if (!ManagerRegistry.instance) {
|
|||
|
|
ManagerRegistry.instance = new ManagerRegistry();
|
|||
|
|
}
|
|||
|
|
return ManagerRegistry.instance;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 重置单例(用于测试或重新初始化) */
|
|||
|
|
public static reset(): void {
|
|||
|
|
if (ManagerRegistry.instance) {
|
|||
|
|
ManagerRegistry.instance.eventEmitter.clear();
|
|||
|
|
ManagerRegistry.instance = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 发送事件
|
|||
|
|
* @param event 事件名称
|
|||
|
|
* @param payload 事件数据
|
|||
|
|
*/
|
|||
|
|
public emit<K extends keyof EngineEvents>(event: K, payload: EngineEvents[K]): void {
|
|||
|
|
this.eventEmitter.emit(event, payload);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 订阅事件
|
|||
|
|
* @param event 事件名称
|
|||
|
|
* @param listener 事件处理函数
|
|||
|
|
* @returns 取消订阅的函数
|
|||
|
|
*/
|
|||
|
|
public on<K extends keyof EngineEvents>(
|
|||
|
|
event: K,
|
|||
|
|
listener: (payload: EngineEvents[K]) => void
|
|||
|
|
): () => void {
|
|||
|
|
return this.eventEmitter.on(event, listener);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 取消订阅事件
|
|||
|
|
* @param event 事件名称
|
|||
|
|
* @param listener 事件处理函数
|
|||
|
|
*/
|
|||
|
|
public off<K extends keyof EngineEvents>(
|
|||
|
|
event: K,
|
|||
|
|
listener: (payload: EngineEvents[K]) => void
|
|||
|
|
): void {
|
|||
|
|
this.eventEmitter.off(event, listener);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 清除所有事件监听器 */
|
|||
|
|
public clearEvents(): void {
|
|||
|
|
this.eventEmitter.clear();
|
|||
|
|
}
|
|||
|
|
}
|