Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add optional IfcProject root node to TreeViewPlugin "storeys" hierarchy #1759

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/plugins/TreeViewPlugin/TreeViewPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export class TreeViewPlugin extends Plugin {
* @param {Boolean} [cfg.pruneEmptyNodes=true] When true, will not contain nodes that don't have content in the {@link Scene}. These are nodes whose {@link MetaObject}s don't have {@link Entity}s.
* @param {RenderService} [cfg.renderService] Optional {@link RenderService} to use. Defaults to the {@link TreeViewPlugin}'s default {@link RenderService}.
* @param {Boolean} [cfg.showIndeterminate=false] When true, will show indeterminate state for checkboxes when some but not all child nodes are checked
* @param {Boolean} [cfg.showProjectNode=false] When true, will show top level project node when hierarchy is set to "storeys"
*/
constructor(viewer, cfg = {}) {

Expand Down Expand Up @@ -414,6 +415,7 @@ export class TreeViewPlugin extends Plugin {
this._showListItemElementId = null;
this._renderService = cfg.renderService || new RenderService();
this._showIndeterminate = cfg.showIndeterminate ?? false;
this._showProjectNode = cfg.showProjectNode ?? false;

if (!this._renderService) {
throw new Error('TreeViewPlugin: no render service set');
Expand Down Expand Up @@ -968,32 +970,53 @@ export class TreeViewPlugin extends Plugin {
_createStoreysNodes() {
const rootMetaObjects = this._viewer.metaScene.rootMetaObjects;
for (let id in rootMetaObjects) {
this._createStoreysNodes2(rootMetaObjects[id], null, null, null);
this._createStoreysNodes2(rootMetaObjects[id], null, null, null, null);
}
}

_createStoreysNodes2(metaObject, buildingNode, storeyNode, typeNodes) {
_createStoreysNodes2(metaObject, projectNode, buildingNode, storeyNode, typeNodes) {
if (this._pruneEmptyNodes && (metaObject._countEntities === 0)) {
return;
}
const metaObjectType = metaObject.type;
const metaObjectName = metaObject.name;
const children = metaObject.children;
const objectId = metaObject.id;
if (metaObjectType === "IfcBuilding") {

if (this._showProjectNode && metaObjectType === 'IfcProject') {
projectNode = {
nodeId: `${this._id}-${objectId}`,
objectId,
title: (metaObject.metaModels.length === 0) ? metaObjectName : this._rootNames[metaObject.metaModels[0].id] || ((metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType),
type: metaObjectType,
parent: null,
numEntities: 0,
numVisibleEntities: 0,
checked: false,
xrayed: false,
children: [],
};
this._rootNodes.push(projectNode);
this._objectNodes[projectNode.objectId] = projectNode;
this._nodeNodes[projectNode.nodeId] = projectNode;
} else if (metaObjectType === "IfcBuilding") {
buildingNode = {
nodeId: `${this._id}-${objectId}`,
objectId: objectId,
title: (metaObject.metaModels.length === 0) ? metaObjectName : this._rootNames[metaObject.metaModels[0].id] || ((metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType),
type: metaObjectType,
parent: null,
parent: projectNode,
numEntities: 0,
numVisibleEntities: 0,
checked: false,
xrayed: false,
children: []
};
this._rootNodes.push(buildingNode);
if (projectNode) {
projectNode.children.push(buildingNode);
} else {
this._rootNodes.push(buildingNode);
}
this._objectNodes[buildingNode.objectId] = buildingNode;
this._nodeNodes[buildingNode.nodeId] = buildingNode;
} else if (metaObjectType === "IfcBuildingStorey") {
Expand Down Expand Up @@ -1063,7 +1086,7 @@ export class TreeViewPlugin extends Plugin {
if (children) {
for (let i = 0, len = children.length; i < len; i++) {
const childMetaObject = children[i];
this._createStoreysNodes2(childMetaObject, buildingNode, storeyNode, typeNodes);
this._createStoreysNodes2(childMetaObject, projectNode, buildingNode, storeyNode, typeNodes);
}
}
}
Expand Down
Loading