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 SceneTreeModel::handleViewportFieldsChanged(FieldContainer *fc, ConstFieldMaskArg whichField)
{
    if(whichField & Viewport::ForegroundsFieldMask)
    {
        //Send the Foregrounds nodes changed
        //produceTreeNodesChanged(TreePath Parent, const std::vector<UInt32>& ChildIndices, const std::vector<boost::any>& Children);
    }
    else if(whichField & Viewport::BackgroundFieldMask)
    {
        //Send the Background node changed
        TreePath Root(getRootPath());

        std::vector<UInt32> ChildIndices;
        ChildIndices.push_back(getIndexOfChild(getRoot(), boost::any(BackgroundComponent)));
        
        std::vector<boost::any> Children;
        Children.push_back(getChild(getRoot(), ChildIndices.front()));
        
        produceTreeNodesChanged(Root, ChildIndices, Children);
    }
    else if(whichField & Viewport::CameraFieldMask)
    {
        //Send the Camera node changed
    }
    else if(whichField & Viewport::RootFieldMask)
    {
    }
}
void DefaultTreeModel::nodesChanged(ModelTreeNodeRefPtr node, std::vector<UInt32> childIndices)
{
    std::vector<boost::any> ChildUserObjects;

    for(UInt32 i(0) ; i< childIndices.size() ; ++i)
    {
        ChildUserObjects.push_back(dynamic_pointer_cast<ModelTreeNode>(node->getChildAt(childIndices[i])));
    }

    produceTreeNodesChanged(getPath(boost::any(node)), 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);
        }
    }
}