feat(engine-manager): 添加构件选中方法和动态右键菜单
This commit is contained in:
@@ -9,6 +9,8 @@ import { infoMenuButton } from '../components/menu/buttons/info';
|
||||
import { homeMenuButton } from '../components/menu/buttons/home';
|
||||
import type { MeasureMode } from '../types/measure';
|
||||
import type { SectionBoxRange } from '../components/section-box-panel/types';
|
||||
import type { MenuItemConfig } from '../components/menu/item';
|
||||
import { ManagerRegistry } from '../core/manager-registry';
|
||||
|
||||
/**
|
||||
* 3D 引擎管理器
|
||||
@@ -50,10 +52,37 @@ export class EngineManager extends BaseManager {
|
||||
this.rightKey = new RightKeyManager(this.container);
|
||||
|
||||
this.rightKey.registerHandler((_e) => {
|
||||
return [
|
||||
infoMenuButton(),
|
||||
homeMenuButton()
|
||||
];
|
||||
const selected = this.getSelectedComponent();
|
||||
const items: MenuItemConfig[] = [];
|
||||
|
||||
if (selected) {
|
||||
items.push({
|
||||
id: 'componentDetail',
|
||||
label: 'menu.componentDetail',
|
||||
group: 'component',
|
||||
onClick: () => {
|
||||
const registry = ManagerRegistry.getInstance();
|
||||
// @ts-expect-error - componentDetail will be added in Task 4
|
||||
registry.componentDetail?.show(selected.url, selected.id);
|
||||
this.rightKey?.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
id: 'showAll',
|
||||
label: 'menu.showAll',
|
||||
group: 'component',
|
||||
onClick: () => {
|
||||
console.log('[Menu] 显示全部 - 功能开发中');
|
||||
this.rightKey?.hide();
|
||||
}
|
||||
});
|
||||
|
||||
items.push(infoMenuButton());
|
||||
items.push(homeMenuButton());
|
||||
|
||||
return items;
|
||||
});
|
||||
|
||||
return this.engineInstance.isInitialized();
|
||||
@@ -316,6 +345,32 @@ export class EngineManager extends BaseManager {
|
||||
|
||||
// ==================== 结束:漫游功能 ====================
|
||||
|
||||
// ==================== 构件选中 ====================
|
||||
|
||||
/**
|
||||
* 获取当前选中的构件
|
||||
* @returns 选中构件的 URL 和 ID,未选中时返回 null
|
||||
*/
|
||||
public getSelectedComponent(): { url: string; id: string } | null {
|
||||
return this.engineInstance?.getSelectedComponent() ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取构件属性
|
||||
* @param url 模型 URL
|
||||
* @param id 构件 ID
|
||||
* @param callback 回调函数,接收属性数据
|
||||
*/
|
||||
public getComponentProperties(
|
||||
url: string,
|
||||
id: string,
|
||||
callback: (data: any) => void
|
||||
): void {
|
||||
this.engineInstance?.getComponentProperties(url, id, callback);
|
||||
}
|
||||
|
||||
// ==================== 结束:构件选中 ====================
|
||||
|
||||
/** 销毁引擎管理器 */
|
||||
public destroy(): void {
|
||||
if (this.engineInstance) {
|
||||
|
||||
Reference in New Issue
Block a user