增加测量窗口

This commit is contained in:
yuding
2025-12-23 11:31:16 +08:00
parent 7d522afb70
commit 4b5eb78bbb
15 changed files with 3846 additions and 2832 deletions

View File

@@ -2,7 +2,7 @@ import {BimComponent} from '../core/component';
import {BimEngine} from '../bim-engine';
import {BimDialog} from "../components/dialog";
import { MeasurePanel } from '../components/measure-panel';
import type { MeasureMode, MeasureResult } from '../components/measure-panel/types';
import type { MeasureConfig, MeasureMode, MeasureResult } from '../components/measure-panel/types';
/**
* 测量弹窗管理器
@@ -11,6 +11,11 @@ export class MeasureDialogManager extends BimComponent {
private dialogId = 'measure-dialog';
private dialog: BimDialog | null = null;
private panel: MeasurePanel | null = null;
/**
* 测量配置项(单位/精度)
* 说明MeasurePanel 会自行从缓存加载默认配置Manager 这里只做“对外读取/设置”的镜像。
*/
private config: MeasureConfig | null = null;
constructor(engine: BimEngine) {
super(engine);
@@ -63,6 +68,8 @@ export class MeasureDialogManager extends BimComponent {
}
});
this.panel.init();
// 同步一次当前配置(由组件从缓存/默认加载)
this.config = this.panel.getConfig();
// 注意:你要求“组件本身不加边距”,因此在 Manager 这里用 wrapper 增加左右内边距
// 这样 MeasurePanel 可以保持通用性,避免在不同场景复用时产生多余 padding。
@@ -109,14 +116,56 @@ export class MeasureDialogManager extends BimComponent {
}
/**
* 设置测量结果(由外部注入,仅用于显示
* 设置测量结果(推荐使用的新方法名
* 说明:内部直接调用 MeasurePanel.setResult()
* @param result 测量结果;传 null 表示清空
*/
public setResult(result: MeasureResult | null): void {
if (!this.panel) return;
public setMeasureResult(result: MeasureResult | null): void {
// 按你的要求:仅当 panel 存在时才调用,不做缓存
if (!this.panel) {
return;
}
this.panel.setResult(result);
}
/**
* 获取测量配置(单位/精度)
* - 如果面板存在:返回面板当前配置
* - 否则:返回 Manager 缓存的最后一次配置(可能为 null
*/
public getConfig(): MeasureConfig | null {
if (this.panel) {
this.config = this.panel.getConfig();
}
return this.config ? { ...this.config } : null;
}
/**
* 设置测量配置(单位/精度)
* @param partial 部分更新
* @param persist 是否写入缓存(默认 true
*/
public setConfig(partial: Partial<MeasureConfig>, persist: boolean = true): void {
// 面板存在则直接设置面板;否则仅更新 Manager 缓存
if (this.panel) {
this.panel.setConfig(partial, persist);
this.config = this.panel.getConfig();
// 配置变化可能影响高度(比如设置面板显示/隐藏),安全起见做一次 fit
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;
// 注意:缓存写入由 MeasurePanel 负责(你要求默认维护在组件里)
// 这里不写 localStorage避免重复逻辑。
}
/**
* 删除全部(仅清空 UI真实测量清理逻辑后续再接
*/