Last active
January 23, 2017 20:12
-
-
Save leefsmp/701a41104ff920e599134a7c091d53ca to your computer and use it in GitHub Desktop.
Isolate viewer node by hidding completely - no ghosting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of use: | |
// isolateFull(viewer, viewer.model, [39, 45, 61]) | |
static isolateFull (viewer, model = null, dbIds = []) { | |
return new Promise(async(resolve, reject) => { | |
try { | |
model = model || viewer.model | |
// First we call the native isolate function | |
// so hidden components will not interfere | |
// with selection | |
viewer.isolate(dbIds) | |
const targetIds = Array.isArray(dbIds) ? dbIds : [dbIds] | |
const targetLeafIds = await ViewerToolkit.getLeafNodes( | |
model, targetIds) | |
const leafIds = await ViewerToolkit.getLeafNodes (model) | |
const leafTasks = leafIds.map((dbId) => { | |
return new Promise((resolveLeaf) => { | |
const show = !targetLeafIds.length || | |
targetLeafIds.indexOf(dbId) > -1 | |
viewer.impl.visibilityManager.setNodeOff( | |
dbId, !show) | |
resolveLeaf() | |
}) | |
}) | |
return Promise.all(leafTasks) | |
} catch (ex) { | |
return reject(ex) | |
} | |
}) | |
} | |
// Helper method: returns all leaf node dbIds for | |
// given input dbIds. A leaf node is a node that | |
// doesn't have any children | |
static getLeafNodes (model, dbIds) { | |
return new Promise((resolve, reject) => { | |
try { | |
const instanceTree = model.getData().instanceTree | |
dbIds = dbIds || instanceTree.getRootId() | |
const dbIdArray = Array.isArray(dbIds) ? dbIds : [dbIds] | |
let leafIds = [] | |
const getLeafNodesRec = (id) => { | |
var childCount = 0; | |
instanceTree.enumNodeChildren(id, (childId) => { | |
getLeafNodesRec(childId) | |
++childCount | |
}) | |
if (childCount == 0) { | |
leafIds.push(id) | |
} | |
} | |
for (var i = 0; i < dbIdArray.length; ++i) { | |
getLeafNodesRec(dbIdArray[i]) | |
} | |
return resolve(leafIds) | |
} catch (ex) { | |
return reject(ex) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment