/** * 剖切盒对话框管理器 * 负责管理剖切盒工具对话框的显示、隐藏和剖切盒面板的交互 */ 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 BaseDialogManager { /** 剖切盒面板实例 */ private panel: SectionBoxPanel | null = null; /** 对话框唯一标识 */ protected get dialogId(): string { return 'section-box-dialog'; } /** 对话框标题(国际化 key) */ protected get dialogTitle(): string { return 'sectionBox.dialogTitle'; } /** 对话框宽度 */ protected get dialogWidth(): number { return 280; } /** * 获取对话框位置 * 定位在容器右下角 */ protected getDialogPosition(): { x: number; y: number } { const container = this.registry.container; if (!container) return { x: 100, y: 100 }; 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); }, onReverseToggle: (isReversed) => { // 底层暂不支持反向功能 console.log('[SectionBoxDialogManager] 反向切换(底层暂不支持):', isReversed); }, onFitToModel: () => { console.log('[SectionBoxDialogManager] Fit to model not supported in new API'); }, onReset: () => { console.log('[SectionBoxDialogManager] Reset not supported in new API'); }, onRangeChange: (range) => { this.registry.engine3d?.setSectionBoxRange(range); } }); this.panel.init(); return this.panel.element; } /** 对话框创建后的回调,激活剖切盒并自适应高度 */ protected onDialogCreated(): void { this.registry.engine3d?.activeSection('box'); this.dialog?.fitHeight(false); } /** 对话框关闭时的回调,取消工具栏按钮激活状态 */ protected onDialogClose(): void { this.registry.toolbar?.setBtnActive('section-box', false); } /** 销毁前的清理,停用剖切盒并销毁面板实例 */ protected onBeforeDestroy(): void { this.registry.engine3d?.deactivateSection(); if (this.panel) { this.panel.destroy(); this.panel = null; } } /** * 获取剖切盒隐藏状态 * @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): void { this.panel?.setRange(range); } }