SelectionBasket Class

This class offers the ability to organize and manage selections in HOOPS Communicator via a “selection basket” approach. This makes it easy to stash and retrieve multiple lists of selected entities. A single selection basket manages multiple groups of selected entities and ensures that no entity appears in more than one group. It is also possible to create multiple selection baskets, each containing their own independent list of selection groups.


Usage:

mySelectionBasket = new SelectionBasket(hwv);
Creates a new SelectionBasket object. The constructor should be called after the model is initialized (e.g. after the modelstructureready callback has fired).

mySelectionBasket.initializeUI("selectionbasketcontainer", true);
Initializes the UI for the selection basket. The first parameter is the id of the div that the selection basket will be using (in the above screenshot GoldenLayout is used to place the SelectionBasket UI to the right of the viewer).
The second parameter indicates if the default buttons should be shown. If this parameter is set to false you need to provide your own UI for the class on top of the selection table.

mySelectionBasket.toJson()
Generates a JSON object of all selection baskets meant for serialization.

mySelectionBasket.fromJson(content)
Populates the selection baskets from the provided JSON object.

mySelectionBasket.setRestrictToNode(nodeid)
Restricts selections to a particular node in the hierarchy.

mySelectionBasket unsetRestrictToNode()
Unsets the selection restriction.

mySelectionBasket.setDisallowBodyNodes(true)
If set, selection will automatically pick the parent of a body node.

If you provide your own UI the following functions will also be relevant:

let newbasketid = mySelectionBasket.addBasket()
Adds a new selection basket and switches to it.

mySelectionBasket.switchBasket(basketid)
Switches to a different selection basket based on its id.

let activeBasketId = mySelectionBasket.deleteCurrentBasket()
Deletes the currently active selection basket.

mySelectionBasket.selectAll()
Selects all elements in the active selection basket in the viewer.

mySelectionBasket.addNodesFromSelection()
Adds all nodes currently selected in the viewer to the currently active selection basket.

mySelectionBasket.addNodes(nodeids)
Adds a list of nodeids to the currently active selection basket.

mySelectionBasket.removeSelectedNodes()
Removes all nodes currently selected in the viewer from the currently active selection basket.

mySelectionBasket.removeNodes(nodeids)
Removes a list of nodeids from the currently active selection basket.


Below is the code for the SelectionBasket class. Besides the standard HOOPS Communicator libraries and jQuery it uses tabulator to display the selection table. To include tabulator from a CDN add the following to your html:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/5.0.7/js/tabulator.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/5.0.7/css/tabulator.min.css" rel="stylesheet">

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.

If you have any questions or comments, please don’t hesitate to post them here in the forum.

SelectionBasket.js (16.2 KB)