refactor: 重构 Manager 架构,引入 ManagerRegistry 和 BaseManager 基类
- 新增 ManagerRegistry 单例注册表,统一管理所有 Manager 实例 - 新增 BaseManager 基类,自动管理事件订阅清理 - 新增 BaseDialogManager 基类,统一对话框生命周期管理 - 重构 15 个 Manager 使用新基类 - 重构 Toolbar 按钮和 Menu 按钮移除 engine 参数依赖 - 删除 BimComponent 基类(已不再使用) - 为所有 Manager 和核心模块添加中文 JSDoc 注释
This commit is contained in:
@@ -1,159 +1,144 @@
|
||||
import { BimComponent } from '../core/component';
|
||||
import { BimEngine } from '../bim-engine';
|
||||
import { BimDialog } from '../components/dialog';
|
||||
/**
|
||||
* 剖切盒对话框管理器
|
||||
* 负责管理剖切盒工具对话框的显示、隐藏和剖切盒面板的交互
|
||||
*/
|
||||
import { BaseDialogManager } from '../core/base-dialog-manager';
|
||||
import { SectionBoxPanel } from '../components/section-box-panel';
|
||||
import type { SectionBoxRange } from '../components/section-box-panel/types';
|
||||
|
||||
/**
|
||||
* 剖切盒弹窗管理器
|
||||
* 剖切盒对话框管理器
|
||||
* 继承自 BaseDialogManager,提供六面体剖切盒的对话框管理功能
|
||||
*/
|
||||
export class SectionBoxDialogManager extends BimComponent {
|
||||
private dialogId = 'section-box-dialog';
|
||||
private dialog: BimDialog | null = null;
|
||||
export class SectionBoxDialogManager extends BaseDialogManager {
|
||||
/** 剖切盒面板实例 */
|
||||
private panel: SectionBoxPanel | null = null;
|
||||
|
||||
constructor(engine: BimEngine) {
|
||||
super(engine);
|
||||
/** 对话框唯一标识 */
|
||||
protected get dialogId(): string {
|
||||
return 'section-box-dialog';
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
// 可以在这里监听事件
|
||||
/** 对话框标题(国际化 key) */
|
||||
protected get dialogTitle(): string {
|
||||
return 'sectionBox.dialogTitle';
|
||||
}
|
||||
|
||||
/** 对话框宽度 */
|
||||
protected get dialogWidth(): number {
|
||||
return 280;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示弹窗
|
||||
* 获取对话框位置
|
||||
* 定位在容器右下角
|
||||
*/
|
||||
public show(): void {
|
||||
if (!this.engine.dialog || !this.engine.container) {
|
||||
console.warn('Dialog manager or container is not initialized');
|
||||
return;
|
||||
}
|
||||
protected getDialogPosition(): { x: number; y: number } {
|
||||
const container = this.registry.container;
|
||||
if (!container) return { x: 100, y: 100 };
|
||||
|
||||
// 如果已打开,先销毁
|
||||
this.destroy();
|
||||
const containerWidth = container.clientWidth;
|
||||
const containerHeight = container.clientHeight;
|
||||
const paddingRight = 20;
|
||||
const paddingBottom = 50;
|
||||
|
||||
// 创建面板
|
||||
return {
|
||||
x: containerWidth - this.dialogWidth - paddingRight,
|
||||
y: containerHeight - paddingBottom - 300
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建对话框内容
|
||||
* 初始化剖切盒面板并设置回调
|
||||
*/
|
||||
protected createContent(): HTMLElement {
|
||||
this.panel = new SectionBoxPanel({
|
||||
defaultHidden: false,
|
||||
defaultReversed: false,
|
||||
onHideToggle: (isHidden) => {
|
||||
console.log('[SectionBoxDialogManager] 隐藏切换:', isHidden);
|
||||
// TODO: 实现隐藏/显示剖切盒的逻辑
|
||||
},
|
||||
onReverseToggle: (isReversed) => {
|
||||
console.log('[SectionBoxDialogManager] 反向切换:', isReversed);
|
||||
// TODO: 实现反向剖切的逻辑
|
||||
},
|
||||
onFitToModel: () => {
|
||||
console.log('[SectionBoxDialogManager] 适应到模型');
|
||||
// TODO: 实现自动适应模型的逻辑
|
||||
},
|
||||
onReset: () => {
|
||||
console.log('[SectionBoxDialogManager] 重置');
|
||||
// 注意:不要在这里调用 panel.reset(),会造成无限递归
|
||||
// panel 的 reset 按钮已经在内部处理了状态重置
|
||||
// TODO: 这里只需要通知 3D 引擎重置剖切盒即可
|
||||
},
|
||||
onRangeChange: (range) => {
|
||||
console.log('[SectionBoxDialogManager] 范围变化:', range);
|
||||
// TODO: 实现范围变化的逻辑
|
||||
}
|
||||
});
|
||||
this.panel.init();
|
||||
return this.panel.element;
|
||||
}
|
||||
|
||||
// 创建弹窗
|
||||
const dialogWidth = 280;
|
||||
const paddingRight = 20;
|
||||
const paddingBottom = 50;
|
||||
const container = this.engine.container;
|
||||
const containerWidth = container.clientWidth;
|
||||
const containerHeight = container.clientHeight;
|
||||
const x = containerWidth - dialogWidth - paddingRight;
|
||||
const y = containerHeight - paddingBottom - 300; // 临时y值,会被fitHeight调整
|
||||
/** 对话框创建后的回调,自适应高度 */
|
||||
protected onDialogCreated(): void {
|
||||
this.dialog?.fitHeight(false);
|
||||
}
|
||||
|
||||
this.dialog = this.engine.dialog.create({
|
||||
id: this.dialogId,
|
||||
title: 'sectionBox.dialogTitle',
|
||||
width: dialogWidth,
|
||||
height: 'auto',
|
||||
position: { x, y },
|
||||
draggable: true,
|
||||
resizable: false,
|
||||
content: this.panel.element,
|
||||
onClose: () => {
|
||||
this.engine.toolbar?.setBtnActive('section-box', false);
|
||||
this.hide();
|
||||
}
|
||||
});
|
||||
this.dialog.init();
|
||||
/** 对话框关闭时的回调,取消工具栏按钮激活状态 */
|
||||
protected onDialogClose(): void {
|
||||
this.registry.toolbar?.setBtnActive('section-box', false);
|
||||
}
|
||||
|
||||
// 自适应高度
|
||||
this.dialog.fitHeight(false);
|
||||
/** 销毁前的清理,销毁面板实例 */
|
||||
protected onBeforeDestroy(): void {
|
||||
if (this.panel) {
|
||||
this.panel.destroy();
|
||||
this.panel = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏弹窗
|
||||
*/
|
||||
public hide(): void {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取隐藏状态
|
||||
* 获取剖切盒隐藏状态
|
||||
* @returns 是否隐藏
|
||||
*/
|
||||
public getHiddenState(): boolean {
|
||||
return this.panel?.getHiddenState() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置隐藏状态
|
||||
* 设置剖切盒隐藏状态
|
||||
* @param isHidden 是否隐藏
|
||||
*/
|
||||
public setHiddenState(isHidden: boolean): void {
|
||||
this.panel?.setHiddenState(isHidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取反向状态
|
||||
* 获取剖切盒反向状态
|
||||
* @returns 是否反向(显示盒内/盒外)
|
||||
*/
|
||||
public getReversedState(): boolean {
|
||||
return this.panel?.getReversedState() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置反向状态
|
||||
* 设置剖切盒反向状态
|
||||
* @param isReversed 是否反向
|
||||
*/
|
||||
public setReversedState(isReversed: boolean): void {
|
||||
this.panel?.setReversedState(isReversed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取范围值
|
||||
* 获取剖切盒范围
|
||||
* @returns 六面体范围 { minX, maxX, minY, maxY, minZ, maxZ }
|
||||
*/
|
||||
public getRange(): SectionBoxRange | null {
|
||||
return this.panel?.getRange() ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置范围值
|
||||
* 设置剖切盒范围
|
||||
* @param range 部分或全部范围值
|
||||
*/
|
||||
public setRange(range: Partial<SectionBoxRange>): void {
|
||||
this.panel?.setRange(range);
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁弹窗和面板
|
||||
*/
|
||||
public destroy(): void {
|
||||
// 关闭弹窗
|
||||
if (this.dialog) {
|
||||
this.dialog.destroy();
|
||||
this.dialog = null;
|
||||
}
|
||||
|
||||
// 销毁面板
|
||||
if (this.panel) {
|
||||
this.panel.destroy();
|
||||
this.panel = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user