添加测试信息
This commit is contained in:
@@ -1,48 +1,46 @@
|
||||
import { BimButtonGroup } from '../components/button-group';
|
||||
import type { ButtonGroupOptions } from '../components/button-group/index.type';
|
||||
import type { ThemeConfig } from '../themes/types';
|
||||
import { BimComponent } from '../core/component';
|
||||
import type { BimEngine } from '../bim-engine';
|
||||
|
||||
/**
|
||||
* 通用按钮组管理器
|
||||
* 负责创建和管理除底部工具栏以外的其他按钮组。
|
||||
* 通用按钮组管理器 (ButtonGroupManager)
|
||||
* 负责创建和管理通用的按钮组实例。
|
||||
*/
|
||||
export class ButtonGroupManager {
|
||||
private activeGroups: BimButtonGroup[] = [];
|
||||
export class ButtonGroupManager extends BimComponent {
|
||||
private groups: Map<string, BimButtonGroup> = new Map();
|
||||
private container: HTMLElement;
|
||||
|
||||
constructor(container: HTMLElement) {
|
||||
constructor(engine: BimEngine, container: HTMLElement) {
|
||||
super(engine);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新的按钮组
|
||||
*/
|
||||
public create(options: Omit<ButtonGroupOptions, 'container'>): BimButtonGroup {
|
||||
// 自动创建一个 div 作为容器
|
||||
const groupContainer = document.createElement('div');
|
||||
this.container.appendChild(groupContainer);
|
||||
|
||||
public create(id: string, options: Omit<ButtonGroupOptions, 'container'>): BimButtonGroup {
|
||||
const group = new BimButtonGroup({
|
||||
container: groupContainer,
|
||||
container: this.container,
|
||||
...options
|
||||
});
|
||||
|
||||
// 立即初始化
|
||||
|
||||
// @ts-ignore
|
||||
group.setEngine(this.engine);
|
||||
|
||||
group.init();
|
||||
this.activeGroups.push(group);
|
||||
this.groups.set(id, group);
|
||||
return group;
|
||||
}
|
||||
|
||||
public updateTheme(theme: ThemeConfig) {
|
||||
this.activeGroups.forEach(g => g.setTheme(theme));
|
||||
public get(id: string): BimButtonGroup | undefined {
|
||||
return this.groups.get(id);
|
||||
}
|
||||
|
||||
public refresh() {
|
||||
this.activeGroups.forEach(g => g.render());
|
||||
public updateTheme(theme: ThemeConfig) {
|
||||
this.groups.forEach(group => group.setTheme(theme));
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this.activeGroups.forEach(g => g.destroy());
|
||||
this.activeGroups = [];
|
||||
this.groups.forEach(group => group.destroy());
|
||||
this.groups.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@ import { BimDialog } from '../components/dialog';
|
||||
import { BimInfoDialog } from '../components/dialog/bimInfoDialog';
|
||||
import type { DialogOptions } from '../components/dialog/index.type';
|
||||
import type { ThemeConfig } from '../themes/types';
|
||||
import { themeManager } from '../services/theme'; // 修正路径
|
||||
import { themeManager } from '../services/theme';
|
||||
import { BimComponent } from '../core/component';
|
||||
import type { BimEngine } from '../bim-engine';
|
||||
|
||||
/**
|
||||
* 弹窗管理器
|
||||
* 负责创建和管理应用中的各类弹窗。
|
||||
*/
|
||||
export class DialogManager {
|
||||
export class DialogManager extends BimComponent {
|
||||
/** 弹窗挂载的父容器 */
|
||||
private container: HTMLElement;
|
||||
/** 活跃的弹窗实例列表 */
|
||||
@@ -16,10 +18,22 @@ export class DialogManager {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param engine 引擎实例
|
||||
* @param container 弹窗挂载的目标容器
|
||||
*/
|
||||
constructor(container: HTMLElement) {
|
||||
constructor(engine: BimEngine, container: HTMLElement) {
|
||||
super(engine);
|
||||
this.container = container;
|
||||
|
||||
// 监听打开弹窗事件
|
||||
this.on('ui:open-dialog', (payload) => {
|
||||
// 这里可以根据 payload.id 做更复杂的逻辑,目前简单演示
|
||||
console.log('[DialogManager] Received open-dialog event:', payload);
|
||||
// 示例:如果 payload.id 是 'info',则打开 info dialog
|
||||
if (payload.id === 'info') {
|
||||
this.showInfoDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,4 +80,9 @@ export class DialogManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this.activeDialogs.forEach(d => d.destroy());
|
||||
this.activeDialogs = [];
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,25 @@
|
||||
import { Engine, type EngineOptions, type ModelLoadOptions } from '../components/engine';
|
||||
import { BimComponent } from '../core/component';
|
||||
import type { BimEngine } from '../bim-engine';
|
||||
|
||||
/**
|
||||
* 3D 引擎管理器
|
||||
* 负责连接 Engine 组件和 BimEngine,向外部暴露简化的 API
|
||||
* 采用延迟初始化模式,用户需主动调用 initialize() 方法
|
||||
*/
|
||||
export class EngineManager {
|
||||
export class EngineManager extends BimComponent {
|
||||
/** 3D 引擎挂载的父容器 */
|
||||
private container: HTMLElement;
|
||||
/** 3D 引擎组件实例 */
|
||||
private engine: Engine | null = null;
|
||||
private engineInstance: Engine | null = null;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param engine 引擎实例
|
||||
* @param container 3D 引擎挂载的目标容器
|
||||
*/
|
||||
constructor(container: HTMLElement) {
|
||||
constructor(engine: BimEngine, container: HTMLElement) {
|
||||
super(engine);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@@ -26,27 +30,27 @@ export class EngineManager {
|
||||
*/
|
||||
public initialize(options?: Omit<EngineOptions, 'container'>): boolean {
|
||||
// 如果已经初始化,先销毁旧的实例
|
||||
if (this.engine && this.engine.isInitialized()) {
|
||||
if (this.engineInstance && this.engineInstance.isInitialized()) {
|
||||
console.warn('[EngineManager] 3D Engine already initialized. Destroying old instance...');
|
||||
this.engine.destroy();
|
||||
this.engine = null;
|
||||
this.engineInstance.destroy();
|
||||
this.engineInstance = null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建 Engine 组件实例
|
||||
// options 中的配置会自动复制给 createEngine 使用
|
||||
this.engine = new Engine({
|
||||
this.engineInstance = new Engine({
|
||||
container: this.container,
|
||||
...options, // 合并配置选项
|
||||
});
|
||||
|
||||
// 调用组件的 init 方法初始化引擎
|
||||
this.engine.init();
|
||||
this.engineInstance.init();
|
||||
|
||||
return this.engine.isInitialized();
|
||||
return this.engineInstance.isInitialized();
|
||||
} catch (error) {
|
||||
console.error('[EngineManager] Failed to initialize 3D engine:', error);
|
||||
this.engine = null;
|
||||
this.engineInstance = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +59,7 @@ export class EngineManager {
|
||||
* 检查 3D 引擎是否已初始化
|
||||
*/
|
||||
public isInitialized(): boolean {
|
||||
return this.engine !== null && this.engine.isInitialized();
|
||||
return this.engineInstance !== null && this.engineInstance.isInitialized();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,11 +68,11 @@ export class EngineManager {
|
||||
* @param options 加载选项(位置、旋转、缩放)
|
||||
*/
|
||||
public loadModel(url: string, options?: ModelLoadOptions): void {
|
||||
if (!this.engine || !this.engine.isInitialized()) {
|
||||
if (!this.engineInstance || !this.engineInstance.isInitialized()) {
|
||||
console.error('[EngineManager] 3D Engine not initialized. Please call initialize() first.');
|
||||
return;
|
||||
}
|
||||
this.engine.loadModel(url, options);
|
||||
this.engineInstance.loadModel(url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,20 +80,20 @@ export class EngineManager {
|
||||
* 用于直接调用第三方引擎的其他 API
|
||||
*/
|
||||
public getEngine(): any {
|
||||
if (!this.engine) {
|
||||
if (!this.engineInstance) {
|
||||
console.warn('[EngineManager] 3D Engine not initialized.');
|
||||
return null;
|
||||
}
|
||||
return this.engine.getEngine();
|
||||
return this.engineInstance.getEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁 3D 引擎实例
|
||||
*/
|
||||
public destroy(): void {
|
||||
if (this.engine) {
|
||||
this.engine.destroy();
|
||||
this.engine = null;
|
||||
if (this.engineInstance) {
|
||||
this.engineInstance.destroy();
|
||||
this.engineInstance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import type { ButtonGroupColors, ButtonConfig } from '../components/button-group/index.type';
|
||||
import { Toolbar } from '../components/button-group/toolbar';
|
||||
import type { ThemeConfig } from '../themes/types';
|
||||
import { BimComponent } from '../core/component';
|
||||
import type { BimEngine } from '../bim-engine';
|
||||
|
||||
/**
|
||||
* 底部工具栏管理器 (ToolbarManager)
|
||||
* 仅负责管理底部工具栏实例。
|
||||
*/
|
||||
export class ToolbarManager {
|
||||
export class ToolbarManager extends BimComponent {
|
||||
private toolbar: Toolbar | null = null;
|
||||
private toolbarContainer: HTMLElement | null = null;
|
||||
private container: HTMLElement;
|
||||
|
||||
constructor(container: HTMLElement) {
|
||||
constructor(engine: BimEngine, container: HTMLElement) {
|
||||
super(engine);
|
||||
this.container = container;
|
||||
this.init();
|
||||
}
|
||||
@@ -32,6 +35,10 @@ export class ToolbarManager {
|
||||
expand: 'up' // 向上展开
|
||||
});
|
||||
|
||||
// 注入 engine 到 Toolbar
|
||||
// @ts-ignore - Toolbar 还没更新类型,暂时忽略
|
||||
this.toolbar.setEngine(this.engine);
|
||||
|
||||
this.toolbar.init();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user