diff --git a/packages/obc/src/components/tables/RelationsTree/example.ts b/packages/obc/src/components/tables/RelationsTree/example.ts index 5002bd55..0c0e9566 100644 --- a/packages/obc/src/components/tables/RelationsTree/example.ts +++ b/packages/obc/src/components/tables/RelationsTree/example.ts @@ -92,11 +92,9 @@ const panel = BUI.Component.create(() => { }; return BUI.html` - - + + ${loadIfcBtn} - - ${relationsTree} diff --git a/packages/obc/src/components/tables/RelationsTree/src/template.ts b/packages/obc/src/components/tables/RelationsTree/src/template.ts index 1725cb47..e7fa811b 100644 --- a/packages/obc/src/components/tables/RelationsTree/src/template.ts +++ b/packages/obc/src/components/tables/RelationsTree/src/template.ts @@ -31,14 +31,16 @@ const getDecompositionTree = async ( Entity: OBC.IfcCategoryMap[type], Name: entityAttrs.Name?.value, modelID: model.uuid, + expressID, }, }; for (const attrName of inverseAttributes) { const relations = indexer.getEntityRelations(model, expressID, attrName); - entityRow.data.expressID = expressID; if (!relations) continue; + if (!entityRow.children) entityRow.children = []; entityRow.data.relations = JSON.stringify(relations); + const entityGroups: any = {}; for (const id of relations) { const decompositionRow = await getDecompositionTree( components, @@ -46,8 +48,37 @@ const getDecompositionTree = async ( id, inverseAttributes, ); - if (!entityRow.children) entityRow.children = []; - entityRow.children.push(...decompositionRow); + for (const row of decompositionRow) { + if (row.data.relations) { + entityRow.children.push(row); + } else { + const data = model.data.get(id); + if (!data) { + entityRow.children.push(row); + continue; + } + const type = data[1][1]; + const entity = OBC.IfcCategoryMap[type]; + if (!(entity in entityGroups)) entityGroups[entity] = []; + row.data.Entity = row.data.Name; + delete row.data.Name; + entityGroups[entity].push(row); + } + } + } + + for (const entity in entityGroups) { + const children = entityGroups[entity]; + const relations = children.map((child: any) => child.data.expressID); + const row: BUI.TableGroupData = { + data: { + Entity: entity, + modelID: model.uuid, + relations: JSON.stringify(relations), + }, + children, + }; + entityRow.children.push(row); } } @@ -111,7 +142,7 @@ const getRowFragmentIdMap = (components: OBC.Components, row: BUI.TableRow) => { expressID: number; relations: string; }; - if (!(modelID && expressID)) return null; + if (!modelID) return null; const model = fragments.groups.get(modelID); if (!model) return null; const fragmentIDMap = model.getFragmentMap([ @@ -145,10 +176,10 @@ export const relationsTreeTemplate = (state: RelationsTreeUIState) => { e.stopImmediatePropagation(); const { row } = e.detail; const highlighter = components.get(OBF.Highlighter); + const fragmentIDMap = getRowFragmentIdMap(components, row); + if (!(fragmentIDMap && Object.keys(fragmentIDMap).length !== 0)) return; row.onmouseover = () => { if (!hoverHighlighterName) return; - const fragmentIDMap = getRowFragmentIdMap(components, row); - if (!(fragmentIDMap && Object.keys(fragmentIDMap).length !== 0)) return; row.style.backgroundColor = "var(--bim-ui_bg-contrast-20)"; highlighter.highlightByID( hoverHighlighterName, @@ -166,8 +197,6 @@ export const relationsTreeTemplate = (state: RelationsTreeUIState) => { row.onclick = () => { if (!selectHighlighterName) return; - const fragmentIDMap = getRowFragmentIdMap(components, row); - if (!(fragmentIDMap && Object.keys(fragmentIDMap).length !== 0)) return; highlighter.highlightByID( selectHighlighterName, fragmentIDMap,