Files
bim_engine/src/managers/measure-dialog-manager.ts

158 lines
4.6 KiB
TypeScript
Raw Normal View History

/**
*
*
*/
import { BaseDialogManager } from '../core/base-dialog-manager';
2025-12-22 18:48:38 +08:00
import { MeasurePanel } from '../components/measure-panel';
2025-12-23 11:31:16 +08:00
import type { MeasureConfig, MeasureMode, MeasureResult } from '../components/measure-panel/types';
2025-12-22 18:48:38 +08:00
/**
*
* BaseDialogManager
2025-12-22 18:48:38 +08:00
*/
export class MeasureDialogManager extends BaseDialogManager {
/** 测量面板实例 */
2025-12-22 18:48:38 +08:00
private panel: MeasurePanel | null = null;
/** 测量配置(单位、精度等) */
2025-12-23 11:31:16 +08:00
private config: MeasureConfig | null = null;
2025-12-22 18:48:38 +08:00
/** 对话框唯一标识 */
protected get dialogId(): string {
return 'measure-dialog';
2025-12-22 18:48:38 +08:00
}
/** 对话框标题(国际化 key */
protected get dialogTitle(): string {
return 'measure.dialogTitle';
2025-12-22 18:48:38 +08:00
}
/** 对话框宽度 */
protected get dialogWidth(): number {
return 250;
}
2025-12-22 18:48:38 +08:00
/**
*
*
*/
protected createContent(): HTMLElement {
2025-12-22 18:48:38 +08:00
this.panel = new MeasurePanel({
defaultMode: 'distance',
2025-12-22 18:48:38 +08:00
defaultExpanded: false,
onModeChange: (mode) => {
console.log('[MeasureDialogManager] 当前测量方式已切换:', mode);
this.registry.engine3d?.activateMeasure(mode);
2025-12-22 18:48:38 +08:00
},
onClearAll: () => {
console.log('[MeasureDialogManager] 删除全部');
this.registry.engine3d?.clearAllMeasures();
2025-12-22 18:48:38 +08:00
},
onSettings: () => {
console.log('[MeasureDialogManager] 打开设置');
2025-12-22 18:48:38 +08:00
},
onExpandedChange: () => {
this.dialog?.fitHeight(false);
}
});
this.panel.init();
2025-12-23 11:31:16 +08:00
this.config = this.panel.getConfig();
2025-12-22 18:48:38 +08:00
const panelWrapper = document.createElement('div');
panelWrapper.style.padding = '12px';
panelWrapper.appendChild(this.panel.element);
return panelWrapper;
}
2025-12-22 18:48:38 +08:00
/** 对话框创建后的回调,自适应高度 */
protected onDialogCreated(): void {
this.dialog?.fitHeight(false);
}
/** 对话框关闭时的回调,取消工具栏按钮激活状态 */
protected onDialogClose(): void {
this.registry.toolbar?.setBtnActive('measure', false);
}
/** 销毁前的清理,停用测量功能并销毁面板 */
protected onBeforeDestroy(): void {
if (this.registry.engine3d) {
this.registry.engine3d.deactivateMeasure();
}
if (this.panel) {
this.panel.destroy();
this.panel = null;
}
2025-12-22 18:48:38 +08:00
}
/**
*
* @returns 'distance''angle'
2025-12-22 18:48:38 +08:00
*/
public getActiveMode(): MeasureMode | null {
return this.panel ? this.panel.getActiveMode() : null;
}
/**
*
* @param mode
2025-12-22 18:48:38 +08:00
*/
public switchMode(mode: MeasureMode): void {
if (!this.panel) return;
this.panel.switchMode(mode);
}
/**
*
* @param result
2025-12-22 18:48:38 +08:00
*/
2025-12-23 11:31:16 +08:00
public setMeasureResult(result: MeasureResult | null): void {
if (!this.panel) return;
2025-12-22 18:48:38 +08:00
this.panel.setResult(result);
}
2025-12-23 11:31:16 +08:00
/**
*
* @returns
2025-12-23 11:31:16 +08:00
*/
public getConfig(): MeasureConfig | null {
if (this.panel) {
this.config = this.panel.getConfig();
}
return this.config ? { ...this.config } : null;
}
/**
*
* @param partial
* @param persist
2025-12-23 11:31:16 +08:00
*/
public setConfig(partial: Partial<MeasureConfig>, persist: boolean = true): void {
if (this.panel) {
this.panel.setConfig(partial, persist);
this.config = this.panel.getConfig();
this.dialog?.fitHeight(false);
return;
}
const prev = this.config;
const next: MeasureConfig = {
unit: partial.unit ?? prev?.unit ?? 'mm',
precision: partial.precision ?? prev?.precision ?? 2
};
this.config = next;
}
/** 清除所有测量结果 */
2025-12-22 18:48:38 +08:00
public clearAll(): void {
if (!this.panel) return;
this.panel.clearAll();
}
/** 打开测量设置面板 */
2025-12-22 18:48:38 +08:00
public openSettings(): void {
if (!this.panel) return;
this.panel.openSettings();
}
}