Skip to content

Commit

Permalink
feat(obc): Groups entities with the same name in RelationsTree. #40 (#41
Browse files Browse the repository at this point in the history
)
  • Loading branch information
HoyosJuan authored Jul 31, 2024
1 parent 576eab3 commit 4ef9848
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
6 changes: 2 additions & 4 deletions packages/obc/src/components/tables/RelationsTree/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ const panel = BUI.Component.create(() => {
};

return BUI.html`
<bim-panel label="Classifications Tree">
<bim-panel-section label="Importing">
<bim-panel label="Relations Tree">
<bim-panel-section label="Model Tree">
${loadIfcBtn}
</bim-panel-section>
<bim-panel-section label="Classifications">
<bim-text-input @input=${onSearch} placeholder="Search..." debounce="200"></bim-text-input>
${relationsTree}
</bim-panel-section>
Expand Down
45 changes: 37 additions & 8 deletions packages/obc/src/components/tables/RelationsTree/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,54 @@ 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,
model,
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);
}
}

Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 4ef9848

Please sign in to comment.