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

161 lines
4.9 KiB
TypeScript
Raw Normal View History

import { BaseDialogManager } from '../core/base-dialog-manager';
2025-12-24 19:02:34 +08:00
import { SectionBoxPanel } from '../components/section-box-panel';
import type { SectionBoxRange } from '../components/section-box-panel/types';
export class SectionBoxDialogManager extends BaseDialogManager {
2025-12-24 19:02:34 +08:00
private panel: SectionBoxPanel | null = null;
private unsubscribeSectionMove: (() => void) | null = null;
2025-12-24 19:02:34 +08:00
/** 对话框唯一标识 */
protected get dialogId(): string {
return 'section-box-dialog';
2025-12-24 19:02:34 +08:00
}
/** 对话框标题(国际化 key */
protected get dialogTitle(): string {
return 'sectionBox.dialogTitle';
}
/** 对话框宽度 */
protected get dialogWidth(): number {
return 280;
2025-12-24 19:02:34 +08:00
}
/**
*
*
2025-12-24 19:02:34 +08:00
*/
protected getDialogPosition(): { x: number; y: number } {
const container = this.registry.container;
if (!container) return { x: 100, y: 100 };
2025-12-24 19:02:34 +08:00
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const paddingRight = 20;
const paddingBottom = 50;
2025-12-24 19:02:34 +08:00
return {
x: containerWidth - this.dialogWidth - paddingRight,
y: containerHeight - paddingBottom - 300
};
}
/**
*
*
*/
protected createContent(): HTMLElement {
2025-12-24 19:02:34 +08:00
this.panel = new SectionBoxPanel({
defaultHidden: false,
defaultReversed: false,
onHideToggle: (isHidden) => {
console.log('[SectionBoxDialogManager] 隐藏切换:', isHidden);
if (isHidden) {
this.registry.engine3d?.hideSection();
} else {
this.registry.engine3d?.recoverSection();
}
2025-12-24 19:02:34 +08:00
},
onReverseToggle: (isReversed) => {
// 底层暂不支持反向功能
console.log('[SectionBoxDialogManager] 反向切换(底层暂不支持):', isReversed);
2025-12-24 19:02:34 +08:00
},
onFitToModel: () => {
console.log('[SectionBoxDialogManager] Fit to model not supported in new API');
2025-12-24 19:02:34 +08:00
},
onReset: () => {
console.log('[SectionBoxDialogManager] Reset not supported in new API');
2025-12-24 19:02:34 +08:00
},
onRangeChange: (range) => {
this.registry.engine3d?.setSectionBoxRange(range);
2025-12-24 19:02:34 +08:00
}
});
this.panel.init();
return this.panel.element;
}
2025-12-24 19:02:34 +08:00
protected onDialogCreated(): void {
this.registry.engine3d?.activeSection('box');
this.dialog?.fitHeight(false);
const engine = this.registry.engine3d?.getEngine();
if (engine?.events) {
const handler = (data: any) => {
if (data && this.panel) {
this.panel.setRange(data as Partial<SectionBoxRange>);
}
};
engine.events.on('section-move', handler);
this.unsubscribeSectionMove = () => engine.events.off('section-move', handler);
}
}
2025-12-24 19:02:34 +08:00
protected onDialogClose(): void {
if (this.unsubscribeSectionMove) {
this.unsubscribeSectionMove();
this.unsubscribeSectionMove = null;
}
this.registry.toolbar?.setBtnActive('section-box', false);
2025-12-24 19:02:34 +08:00
}
protected onBeforeDestroy(): void {
if (this.unsubscribeSectionMove) {
this.unsubscribeSectionMove();
this.unsubscribeSectionMove = null;
}
this.registry.engine3d?.deactivateSection();
if (this.panel) {
this.panel.destroy();
this.panel = null;
}
2025-12-24 19:02:34 +08:00
}
/**
*
* @returns
2025-12-24 19:02:34 +08:00
*/
public getHiddenState(): boolean {
return this.panel?.getHiddenState() ?? false;
}
/**
*
* @param isHidden
2025-12-24 19:02:34 +08:00
*/
public setHiddenState(isHidden: boolean): void {
this.panel?.setHiddenState(isHidden);
}
/**
*
* @returns /
2025-12-24 19:02:34 +08:00
*/
public getReversedState(): boolean {
return this.panel?.getReversedState() ?? false;
}
/**
*
* @param isReversed
2025-12-24 19:02:34 +08:00
*/
public setReversedState(isReversed: boolean): void {
this.panel?.setReversedState(isReversed);
}
/**
*
* @returns { minX, maxX, minY, maxY, minZ, maxZ }
2025-12-24 19:02:34 +08:00
*/
public getRange(): SectionBoxRange | null {
return this.panel?.getRange() ?? null;
}
/**
*
* @param range
2025-12-24 19:02:34 +08:00
*/
public setRange(range: Partial<SectionBoxRange>): void {
this.panel?.setRange(range);
}
}