2026-01-22 15:23:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 测量对话框管理器
|
|
|
|
|
|
* 负责管理测量工具对话框的显示、隐藏和测量面板的交互
|
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
|
* 测量对话框管理器
|
|
|
|
|
|
* 继承自 BaseDialogManager,提供测量工具的对话框管理功能
|
2025-12-22 18:48:38 +08:00
|
|
|
|
*/
|
2026-01-22 15:23:57 +08:00
|
|
|
|
export class MeasureDialogManager extends BaseDialogManager {
|
|
|
|
|
|
/** 测量面板实例 */
|
2025-12-22 18:48:38 +08:00
|
|
|
|
private panel: MeasurePanel | null = null;
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 测量配置(单位、精度等) */
|
2025-12-23 11:31:16 +08:00
|
|
|
|
private config: MeasureConfig | null = null;
|
2025-12-22 18:48:38 +08:00
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 对话框唯一标识 */
|
|
|
|
|
|
protected get dialogId(): string {
|
|
|
|
|
|
return 'measure-dialog';
|
2025-12-22 18:48:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 对话框标题(国际化 key) */
|
|
|
|
|
|
protected get dialogTitle(): string {
|
|
|
|
|
|
return 'measure.dialogTitle';
|
2025-12-22 18:48:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 对话框宽度 */
|
|
|
|
|
|
protected get dialogWidth(): number {
|
|
|
|
|
|
return 250;
|
|
|
|
|
|
}
|
2025-12-22 18:48:38 +08:00
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 创建对话框内容
|
|
|
|
|
|
* 初始化测量面板并设置回调
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected createContent(): HTMLElement {
|
2025-12-22 18:48:38 +08:00
|
|
|
|
this.panel = new MeasurePanel({
|
2026-01-22 15:23:57 +08:00
|
|
|
|
defaultMode: 'distance',
|
2025-12-22 18:48:38 +08:00
|
|
|
|
defaultExpanded: false,
|
|
|
|
|
|
onModeChange: (mode) => {
|
|
|
|
|
|
console.log('[MeasureDialogManager] 当前测量方式已切换:', mode);
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.registry.engine3d?.activateMeasure(mode);
|
2025-12-22 18:48:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
onClearAll: () => {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
console.log('[MeasureDialogManager] 删除全部');
|
2025-12-22 18:48:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
onSettings: () => {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
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);
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
return panelWrapper;
|
|
|
|
|
|
}
|
2025-12-22 18:48:38 +08:00
|
|
|
|
|
2026-01-22 15:23:57 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
|
* 获取当前激活的测量模式
|
|
|
|
|
|
* @returns 当前测量模式,如 'distance'、'angle' 等
|
2025-12-22 18:48:38 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public getActiveMode(): MeasureMode | null {
|
|
|
|
|
|
return this.panel ? this.panel.getActiveMode() : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
|
* 切换测量模式
|
|
|
|
|
|
* @param mode 目标测量模式
|
2025-12-22 18:48:38 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public switchMode(mode: MeasureMode): void {
|
|
|
|
|
|
if (!this.panel) return;
|
|
|
|
|
|
this.panel.switchMode(mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
|
* 设置测量结果
|
|
|
|
|
|
* @param result 测量结果对象
|
2025-12-22 18:48:38 +08:00
|
|
|
|
*/
|
2025-12-23 11:31:16 +08:00
|
|
|
|
public setMeasureResult(result: MeasureResult | null): void {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
if (!this.panel) return;
|
2025-12-22 18:48:38 +08:00
|
|
|
|
this.panel.setResult(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 11:31:16 +08:00
|
|
|
|
/**
|
2026-01-22 15:23:57 +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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
|
* 设置测量配置
|
|
|
|
|
|
* @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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 清除所有测量结果 */
|
2025-12-22 18:48:38 +08:00
|
|
|
|
public clearAll(): void {
|
|
|
|
|
|
if (!this.panel) return;
|
|
|
|
|
|
this.panel.clearAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 打开测量设置面板 */
|
2025-12-22 18:48:38 +08:00
|
|
|
|
public openSettings(): void {
|
|
|
|
|
|
if (!this.panel) return;
|
|
|
|
|
|
this.panel.openSettings();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|