void SceneGraphTreeModel::removeNode(NodeUnrecPtr nodeToBeRemoved) { NodeRefPtr parent = nodeToBeRemoved->getParent(); TreePath pathOfNode = createPath(nodeToBeRemoved); if(parent!=NULL) { UInt32 ChildIndex(parent->findChild(nodeToBeRemoved)); produceTreeNodesWillBeRemoved(pathOfNode.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeRemoved)); parent->subChild(nodeToBeRemoved); produceTreeNodesRemoved(pathOfNode.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeRemoved)); if(parent->getNChildren() == 0) { if(parent->getParent() != NULL) { std::vector<UInt32> childIndices; childIndices.push_back(parent->getParent()->findChild(parent)); std::vector<boost::any> ChildUserObjects; for(UInt32 i(0) ; i< childIndices.size() ; ++i) { ChildUserObjects.push_back(boost::any(NodeUnrecPtr(parent->getParent()->getChild(childIndices[i])))); } produceTreeNodesChanged(createPath(parent->getParent()), childIndices, ChildUserObjects); } } } }
void SceneGraphTreeModel::addNode(NodeUnrecPtr parent,NodeUnrecPtr nodeToBeAdded) { UInt32 ChildIndex(parent->getNChildren()); NodeRefPtr(parent)->addChild(nodeToBeAdded); produceTreeNodesInserted(createPath(parent),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeAdded)); if(parent->getNChildren() == 1) { if(parent->getParent() != NULL) { std::vector<UInt32> childIndices; childIndices.push_back(parent->getParent()->findChild(parent)); std::vector<boost::any> ChildUserObjects; for(UInt32 i(0) ; i< childIndices.size() ; ++i) { ChildUserObjects.push_back(boost::any(NodeUnrecPtr(parent->getParent()->getChild(childIndices[i])))); } produceTreeNodesChanged(createPath(NodeUnrecPtr(parent->getParent())), childIndices, ChildUserObjects); } } }
void SceneGraphTreeModel::valueForPathChanged(TreePath path, const boost::any& newValue) { try { NodeUnrecPtr NewNode = boost::any_cast<NodeUnrecPtr>(newValue); NodeUnrecPtr OldNode = boost::any_cast<NodeUnrecPtr>(path.getLastPathComponent()); if(NewNode != NULL && OldNode != NULL && NewNode != OldNode && OldNode->getParent() != NULL) { NodeUnrecPtr ParentNode(OldNode->getParent()); if(ParentNode->replaceChildBy(OldNode, NewNode)) { UInt32 ChildIndex(ParentNode->findChild(NewNode)); produceTreeStructureChanged(path.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, newValue)); } } } catch(boost::bad_any_cast &ex) { SWARNING << "Bad any cast: " << ex.what() << std::endl; } }