While the standard model tree in HOOPS Communicator is quite feature-rich it has not been written with customization in mind. The class below implements a model tree using the above mentioned open source libraries and can be fairly easily modified and enhanced.
A few implementation notes:
JsTree is a great library (in fact we used it for the first version of HOOPS Communicator) but it does not support the concept of selection “breadcrums” natively and the way it handles mixed checkbox states does not quite work with the somewhat more complex visibility states in HOOPS Communicator. It required a bit of “wrangling” to make it function and update correctly. In hindsight writing this type of tree control from scratch might be a better option.
An attempt was made to improve on the way IFC relationship data is displayed. Not only does the relationship window display the complete hierachy of the related/relating entities but it allows for selection of those entities without updating the main tree. If you want the main tree (and the relationship window) to update as well simply hold down the “alt” key.
The Model Tree itself should be initialized in the modelStructureReady callback of your application:
var scTree = new ScTree(hwv, true, true);
Creates a new ScTree object.
The first parameter is the webviewer object. The second parameter indicates if the GoldenLayout layout manager should be used. If this is set to true all the required divs will be created automatically and the viewer itself will be included in the layout. In this case it expects the viewer div to have the id “content” which is the standard naming for our demo viewer. If you want to manage your own layout instead you need to define three divs with the following ids:
“scTreeModelTreeDiv” for Main Model Tree
“scTreeRelationshipDiv” for IFC relationship info
“scTreePropertyDiv” for Node Properties
The third parameter indicates if the relationship window should be displayed (which is currently only relevant for IFC models).
This function refreshes the model tree. You need to call it after instantiating the scTree class. It also needs to be called whenever nodes are added to the model tree (e.g. when loadSubtreeFromModel() is called)
Below is the main code for the scTree class. To use this class you need to include the following libraries (either via CDN as shown here or directly):
It is important to note that this code is not production-ready and provided “as-is”. It is really meant as a starting point for your own development and as an example for some of the functionality and concepts used in HOOPS Communicator.
ScTree.js (23.8 KB)