How to automatically associate a selected model with a selected QtComponentTreeItem in Visualize HPS?

How to automatically associate a selected model with a selected QtComponentTreeItem in Visualize HPS?

I’m trying to traverse the QTreeWidget, comparing to HPS::ComponentPath, but it often reports an invalid memory access error directly on mouse click on the model, and I can’t locate the exception!

hps_qt_sandbox includes the QtComponentTreeItem highlighting model, but does not include the ability to select a node with the mouse, and the component tree can be linked to select it.

Using HPS::HighlightOperator to select a model does not reverse lookup to the corresponding QtComponentTreeItem.

I used the following code for the reverse lookup
void SelectTreeItemByPath(QTreeWidgetItem* treeItem, HPS::ComponentPath path, QTreeWidgetItem*& findItem)
{
size_t childNums = treeItem->childCount();
for (size_t i = 0; i < childNums; i++)
{
QTreeWidgetItem* child = treeItem->child(i);
child->setSelected(false);
QtComponentTreeItem* treeItem = child->data(0, Qt::ItemDataRole::UserRole).value<QtComponentTreeItem*>();
treeItem->getTreeItem()->setSelected(false);
if (treeItem->GetPath() == path)
{
findItem = child;
child->setSelected(true);
}
}
for (size_t i = 0; i < childNums; i++)
{
QTreeWidgetItem* child = treeItem->child(i);
SelectTreeItemByPath(child, path, findItem);
}
}

Hey Rui, thanks for sharing your code. I think this might be better answered by support, so I’ll make you a ticket and respond here when I get an answer.

I think @dave.calkins or @jamestruax might have some insight here as they are both very well versed in Visualize and maybe they have some pointers.

Here’s some information as provided by support. Hopefully it is helpful.:

As for associating a QtComponentTreeItem with HPS, you will need to call HPS::Component::.GetKeys(). This will get you the HPS KeyPath associated with the HOOPS Exchange Component.

More information can be found here:
https://docs.techsoft3d.com/hps/latest/prog_guide/0906_exchange_integration.html#introduction