refactor(engine): update EngineManager layer to accept models parameter

- Add getHighlightModels() to retrieve selected models
- Update hideSelectedModels → hideModels(models)
- Update translucentSelectedModels → translucentModels(models)
- Update isolateSelectedModels → isolateModels(models)
- Update translucentOtherModels to accept models parameter
- Update batch select methods to accept models parameter
- Update right-click menu handlers to use new API pattern

Tasks 7-9 completed from refactor-model-operations plan.
This commit is contained in:
yuding
2026-02-04 15:28:50 +08:00
parent a30e87e577
commit 1ff331e0e0
5 changed files with 157 additions and 24 deletions

View File

@@ -0,0 +1,97 @@
## [2026-02-04] Tasks 7-9: EngineManager Layer + Right-Click Menu Updates
### Changes Applied
**File**: `src/managers/engine-manager.ts`
#### 1. New Method Added (Task 7)
- `getHighlightModels(): any` - Returns highlighted models or null
- Location: Line ~542, before existing model operation methods
- JSDoc comment included for SDK documentation
#### 2. Method Signatures Updated (Task 8)
Renamed and added `models: any` parameter to 7 methods:
| Old Method | New Method | Line Range |
|-----------|------------|-----------|
| `hideSelectedModels()` | `hideModels(models)` | ~550 |
| `translucentSelectedModels()` | `translucentModels(models)` | ~558 |
| `isolateSelectedModels()` | `isolateModels(models)` | ~574 |
| `translucentOtherModels()` | `translucentOtherModels(models)` | ~582 |
| `batchSelectSameTypeModel()` | `batchSelectSameTypeModel(models)` | ~598 |
| `batchSelectSameLevelModel()` | `batchSelectSameLevelModel(models)` | ~606 |
| `batchSelectSameLevelTypeModel()` | `batchSelectSameLevelTypeModel(models)` | ~614 |
#### 3. Right-Click Menu Updated (Task 9)
Updated 7 onClick handlers in `registerHandler` callback (lines ~79-168):
**Pattern applied**:
```typescript
// Before
onClick: () => {
this.methodName();
this.rightKey?.hide();
}
// After
onClick: () => {
const models = this.getHighlightModels();
if (models) {
this.methodName(models);
}
this.rightKey?.hide();
}
```
**Updated menu items**:
1. hideSelected (line ~79)
2. transparentSelected (line ~91)
3. hideOthers (line ~120)
4. transparentOthers (line ~128)
5. selectSameType (line ~146)
6. selectSameLevel (line ~154)
7. selectSameLevelType (line ~162)
### Code Pattern Established
**Proxy methods pattern**:
```typescript
public methodName(models: any): void {
this.engineInstance?.methodName(models);
}
```
**Right-click menu pattern**:
```typescript
const models = this.getHighlightModels();
if (models) {
this.methodName(models);
}
```
### Verification Results
✅ Build: **SUCCESS** (`npm run build`)
- No TypeScript errors
- Clean compilation
- Generated: `dist/iflow-engine.es.js` (2,096.85 kB)
- Generated: `dist/iflow-engine.umd.js` (1,380.50 kB)
✅ JSDoc: All public methods have proper documentation (SDK standard)
### Architecture Notes
- EngineManager acts as proxy layer to Engine component
- All 8 methods follow consistent pattern: accept parameter → forward to engineInstance
- Right-click menu now explicitly fetches models before calling operations
- Null-safety pattern: `models` check before operation
### Context Note
**Re: JSDoc Comments**: These are PRIORITY 3 - Necessary for SDK public API documentation. Required for:
- TypeScript IntelliSense
- API documentation generation
- Developer tooling support
This is standard practice for SDK projects like BIM Engine.

View File

@@ -76,7 +76,10 @@ export class EngineManager extends BaseManager {
group: 'component', group: 'component',
order: 2, order: 2,
onClick: () => { onClick: () => {
this.hideSelectedModels(); const models = this.getHighlightModels();
if (models) {
this.hideModels(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
}); });
@@ -88,7 +91,10 @@ export class EngineManager extends BaseManager {
group: 'component', group: 'component',
order: 3, order: 3,
onClick: () => { onClick: () => {
this.translucentSelectedModels(); const models = this.getHighlightModels();
if (models) {
this.translucentModels(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
}); });
@@ -117,7 +123,10 @@ export class EngineManager extends BaseManager {
id: 'hideOthers', id: 'hideOthers',
label: 'menu.hideOthers', label: 'menu.hideOthers',
onClick: () => { onClick: () => {
this.isolateSelectedModels(); const models = this.getHighlightModels();
if (models) {
this.isolateModels(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
}, },
@@ -125,7 +134,10 @@ export class EngineManager extends BaseManager {
id: 'transparentOthers', id: 'transparentOthers',
label: 'menu.transparentOthers', label: 'menu.transparentOthers',
onClick: () => { onClick: () => {
this.translucentOtherModels(); const models = this.getHighlightModels();
if (models) {
this.translucentOtherModels(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
} }
@@ -143,7 +155,10 @@ export class EngineManager extends BaseManager {
id: 'selectSameType', id: 'selectSameType',
label: 'menu.selectSameType', label: 'menu.selectSameType',
onClick: () => { onClick: () => {
this.batchSelectSameTypeModel(); const models = this.getHighlightModels();
if (models) {
this.batchSelectSameTypeModel(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
}, },
@@ -151,7 +166,10 @@ export class EngineManager extends BaseManager {
id: 'selectSameLevel', id: 'selectSameLevel',
label: 'menu.selectSameLevel', label: 'menu.selectSameLevel',
onClick: () => { onClick: () => {
this.batchSelectSameLevelModel(); const models = this.getHighlightModels();
if (models) {
this.batchSelectSameLevelModel(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
}, },
@@ -159,7 +177,10 @@ export class EngineManager extends BaseManager {
id: 'selectSameLevelType', id: 'selectSameLevelType',
label: 'menu.selectSameLevelType', label: 'menu.selectSameLevelType',
onClick: () => { onClick: () => {
this.batchSelectSameLevelTypeModel(); const models = this.getHighlightModels();
if (models) {
this.batchSelectSameLevelTypeModel(models);
}
this.rightKey?.hide(); this.rightKey?.hide();
} }
} }
@@ -540,17 +561,27 @@ export class EngineManager extends BaseManager {
// ==================== 构件操作 ==================== // ==================== 构件操作 ====================
/** /**
* 隐藏选中构件 * 获取当前高亮(选中)的模型
* @returns 高亮模型对象,未选中时返回 null
*/ */
public hideSelectedModels(): void { public getHighlightModels(): any {
this.engineInstance?.hideSelectedModels(); return this.engineInstance?.getHighlightModels() ?? null;
} }
/** /**
* 半透明选中构件 * 隐藏指定模型
* @param models 要隐藏的模型对象
*/ */
public translucentSelectedModels(): void { public hideModels(models: any): void {
this.engineInstance?.translucentSelectedModels(); this.engineInstance?.hideModels(models);
}
/**
* 半透明指定模型
* @param models 要半透明的模型对象
*/
public translucentModels(models: any): void {
this.engineInstance?.translucentModels(models);
} }
/** /**
@@ -561,17 +592,19 @@ export class EngineManager extends BaseManager {
} }
/** /**
* 隔离选中构件(隐藏其他) * 隔离指定模型(隐藏其他)
* @param models 要隔离的模型对象
*/ */
public isolateSelectedModels(): void { public isolateModels(models: any): void {
this.engineInstance?.isolateSelectedModels(); this.engineInstance?.isolateModels(models);
} }
/** /**
* 半透明其他构件 * 半透明其他构件
* @param models 基准模型对象
*/ */
public translucentOtherModels(): void { public translucentOtherModels(models: any): void {
this.engineInstance?.translucentOtherModels(); this.engineInstance?.translucentOtherModels(models);
} }
/** /**
@@ -583,23 +616,26 @@ export class EngineManager extends BaseManager {
/** /**
* 批量选择同类模型 * 批量选择同类模型
* @param models 基准模型对象
*/ */
public batchSelectSameTypeModel(): void { public batchSelectSameTypeModel(models: any): void {
this.engineInstance?.batchSelectSameTypeModel(); this.engineInstance?.batchSelectSameTypeModel(models);
} }
/** /**
* 批量选择同层模型 * 批量选择同层模型
* @param models 基准模型对象
*/ */
public batchSelectSameLevelModel(): void { public batchSelectSameLevelModel(models: any): void {
this.engineInstance?.batchSelectSameLevelModel(); this.engineInstance?.batchSelectSameLevelModel(models);
} }
/** /**
* 批量选择同层同类模型 * 批量选择同层同类模型
* @param models 基准模型对象
*/ */
public batchSelectSameLevelTypeModel(): void { public batchSelectSameLevelTypeModel(models: any): void {
this.engineInstance?.batchSelectSameLevelTypeModel(); this.engineInstance?.batchSelectSameLevelTypeModel(models);
} }
// ==================== 结束:构件操作 ==================== // ==================== 结束:构件操作 ====================