Visitar URL original
feat(core): adds the ability to get IfcGuids from a FragmentIdMap · ThatOpen/engine_components@dff9d2f · GitHub
Skip to content

Commit dff9d2f

Browse files
committed
feat(core): adds the ability to get IfcGuids from a FragmentIdMap
1 parent 672e377 commit dff9d2f

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎packages/core/src/core/Viewpoints/src/Viewpoint.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,10 @@ export class Viewpoint implements BCFViewpoint {
232232
*
233233
* @returns A Promise that resolves when the components have been added to the viewpoint.
234234
*/
235-
async addComponentsFromMap(fragmentIdMap: FRAGS.FragmentIdMap) {
235+
addComponentsFromMap(fragmentIdMap: FRAGS.FragmentIdMap) {
236236
const fragments = this._components.get(FragmentsManager);
237-
for (const fragmentID in fragmentIdMap) {
238-
const fragment = fragments.list.get(fragmentID);
239-
if (!(fragment && fragment.group)) continue;
240-
const model = fragment.group;
241-
const expressIDs = fragmentIdMap[fragmentID];
242-
for (const expressID of expressIDs) {
243-
const attrs = await model.getProperties(expressID);
244-
if (!attrs) continue;
245-
const globalId = attrs.GlobalId?.value;
246-
if (globalId) this.selectionComponents.add(globalId);
247-
}
248-
}
237+
const guids = fragments.fragmentIdMapToGuids(fragmentIdMap);
238+
this.selectionComponents.add(...guids);
249239
const manager = this._components.get(Viewpoints);
250240
manager.list.set(this.guid, this);
251241
}

‎packages/core/src/fragments/FragmentsManager/index.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,32 @@ export class FragmentsManager extends Component implements Disposable {
232232
return fragmentIdMap;
233233
}
234234

235+
/**
236+
* Converts a fragment ID map to a collection of IFC GUIDs.
237+
*
238+
* @param fragmentIdMap - A fragment ID map to be converted to a collection of IFC GUIDs.
239+
*
240+
* @returns An array of IFC GUIDs.
241+
*/
242+
fragmentIdMapToGuids(fragmentIdMap: FRAGS.FragmentIdMap) {
243+
const guids: string[] = [];
244+
const modelIdMap = this.getModelIdMap(fragmentIdMap);
245+
for (const modelID in modelIdMap) {
246+
const model = this.groups.get(modelID);
247+
if (!model) continue;
248+
const expressIDs = modelIdMap[modelID];
249+
for (const expressID of expressIDs) {
250+
for (const [guid, id] of model.globalToExpressIDs.entries()) {
251+
if (id === expressID) {
252+
guids.push(guid);
253+
break;
254+
}
255+
}
256+
}
257+
}
258+
return guids;
259+
}
260+
235261
/**
236262
* Applies coordinate transformation to the provided models.
237263
* If no models are provided, all groups are used.

0 commit comments

Comments
 (0)