Files
bim_engine/src/core/manager-registry.ts

129 lines
4.7 KiB
TypeScript
Raw Normal View History

/**
* 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 { 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';
import type { ComponentDetailManager } from '../managers/component-detail-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 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;
/** 构件详情管理器 */
public componentDetail: ComponentDetailManager | 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();
}
}