Files
bim_engine/src/managers/section-box-dialog-manager.ts

160 lines
4.5 KiB
TypeScript
Raw Normal View History

2025-12-24 19:02:34 +08:00
import { BimComponent } from '../core/component';
import { BimEngine } from '../bim-engine';
import { BimDialog } from '../components/dialog';
import { SectionBoxPanel } from '../components/section-box-panel';
import type { SectionBoxRange } from '../components/section-box-panel/types';
/**
*
*/
export class SectionBoxDialogManager extends BimComponent {
private dialogId = 'section-box-dialog';
private dialog: BimDialog | null = null;
private panel: SectionBoxPanel | null = null;
constructor(engine: BimEngine) {
super(engine);
}
public init(): void {
// 可以在这里监听事件
}
/**
*
*/
public show(): void {
if (!this.engine.dialog || !this.engine.container) {
console.warn('Dialog manager or container is not initialized');
return;
}
// 如果已打开,先销毁
this.destroy();
// 创建面板
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();
// 创建弹窗
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调整
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();
// 自适应高度
this.dialog.fitHeight(false);
}
/**
*
*/
public hide(): void {
this.destroy();
}
/**
*
*/
public getHiddenState(): boolean {
return this.panel?.getHiddenState() ?? false;
}
/**
*
*/
public setHiddenState(isHidden: boolean): void {
this.panel?.setHiddenState(isHidden);
}
/**
*
*/
public getReversedState(): boolean {
return this.panel?.getReversedState() ?? false;
}
/**
*
*/
public setReversedState(isReversed: boolean): void {
this.panel?.setReversedState(isReversed);
}
/**
*
*/
public getRange(): SectionBoxRange | null {
return this.panel?.getRange() ?? null;
}
/**
*
*/
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;
}
}
}