Commit 3d8fa339 authored by finetjul's avatar finetjul
Browse files

BUG: Observe node ID even if the scene is null or node doesn't exist

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15630 3bd1e089-480b-0410-8dfb-8563597acbee
parent 412b4922
......@@ -114,30 +114,29 @@ int vtkMRMLDisplayableHierarchyNodeTest1(int , char * [] )
if (displayableNode == NULL)
{
std::cerr << "Could not instantiate a displayable node\n";
return EXIT_FAILURE;
}
else
scene->AddNode(displayableNode);
node1->SetDisplayableNodeIDReference(displayableNode->GetID());
node1->GetChildrenDisplayableNodes(col);
numChildren = col->GetNumberOfItems();
std::cout << "Number of children displayble nodes = " << numChildren << std::endl;
if (numChildren != expectedChildren)
{
scene->AddNode(displayableNode);
node1->SetDisplayableNodeIDReference(displayableNode->GetID());
node1->GetChildrenDisplayableNodes(col);
numChildren = col->GetNumberOfItems();
std::cout << "Number of children displayble nodes = " << numChildren << std::endl;
if (numChildren != expectedChildren)
{
std::cerr << "Expected " << expectedChildren << " children, got " << numChildren << std::endl;
return EXIT_FAILURE;
}
expectedChildren++;
std::cerr << "Expected " << expectedChildren << " children, got " << numChildren << std::endl;
return EXIT_FAILURE;
}
// add another hierarchy node below this one
vtkSmartPointer< vtkMRMLDisplayableHierarchyNode > node2 = vtkSmartPointer< vtkMRMLDisplayableHierarchyNode >::New();
scene->AddNode(node2);
node2->SetParentNodeID(node1->GetID());
expectedChildren++;
vtkSmartPointer<vtkMRMLModelNode> modelNode = vtkSmartPointer<vtkMRMLModelNode>::New();
scene->AddNode(modelNode);
node2->SetDisplayableNodeIDReference(modelNode->GetID());
expectedChildren++;
node1->GetChildrenDisplayableNodes(col);
numChildren = col->GetNumberOfItems();
std::cout << "Number of children displayble nodes after adding a model one = " << numChildren << std::endl;
......@@ -147,8 +146,6 @@ int vtkMRMLDisplayableHierarchyNodeTest1(int , char * [] )
return EXIT_FAILURE;
}
vtkSmartPointer<vtkMRMLDisplayableHierarchyNode> hnode3 = node1->GetDisplayableHierarchyNode(scene, "myid");
std::cout << "Displayable hierarchy node from id myid = " << (hnode3 == NULL ? "NULL" : hnode3->GetID()) << std::endl;
hnode3 = node1->GetDisplayableHierarchyNode(scene,modelNode->GetID());
......
......@@ -55,25 +55,17 @@ vtkMRMLDiffusionTensorVolumeNode::vtkMRMLDiffusionTensorVolumeNode()
{
this->Order = 2; //Second order Tensor
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void vtkMRMLDiffusionTensorVolumeNode::SetAndObserveDisplayNodeID(const char *displayNodeID)
{
if (displayNodeID == NULL)
{
vtkDebugMacro("SetAndObserveDisplayNodeID: null display node id");
return;
}
if (this->GetScene() == NULL)
{
vtkDebugMacro("SetAndObserveDisplayNodeID: null scene");
return;
}
if (vtkMRMLDiffusionTensorVolumeDisplayNode::SafeDownCast(this->GetScene()->GetNodeByID(displayNodeID))==NULL)
this->Superclass::SetAndObserveDisplayNodeID(displayNodeID);
// Make sure the node added is a DiffusionTensorVolumeDisplayNode
vtkMRMLNode* displayNode = this->GetDisplayNode();
if (displayNode && vtkMRMLDiffusionTensorVolumeDisplayNode::SafeDownCast(displayNode))
{
vtkWarningMacro("SetAndObserveDisplayNodeID: The node to display " << displayNodeID << " can not display diffusion tensors");
}
Superclass::SetAndObserveDisplayNodeID(displayNodeID);
}
//----------------------------------------------------------------------------
......
......@@ -318,14 +318,10 @@ void vtkMRMLDisplayableNode::SetAndObserveNthDisplayNodeID(int n, const char *di
//----------------------------------------------------------------------------
void vtkMRMLDisplayableNode::AddAndObserveDisplayNodeID(const char *displayNodeID)
{
if (!this->GetScene())
{
vtkWarningMacro(<<"Scene is NULL when observing " << (displayNodeID ? displayNodeID : ""));
return;
}
this->AddDisplayNodeID(displayNodeID);
vtkMRMLDisplayNode *dnode = vtkMRMLDisplayNode::SafeDownCast(this->GetScene()->GetNodeByID(displayNodeID));
vtkMRMLDisplayNode *dnode = vtkMRMLDisplayNode::SafeDownCast(
this->GetScene() != 0 ? this->GetScene()->GetNodeByID(displayNodeID) : 0);
this->AddAndObserveDisplayNode(dnode);
this->Modified();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment