View Full Version : getByName() API.....
aman.sonu
01-21-2009, 03:36 AM
Hey,
I m facing some problem in the API getByName(SbName)
If I m trying to get Some Node from the SceneGraph, it is searching in the whole SoDB.
E.g.
I have two Separator (Sep1, Sep2) Node under the SceneNode (SoSeparator). Both having SoDataRange Node, having SameName like “DATARANGE” (set by setName() API)
When I use the API getByName()
Sep1->getByName(“DATARANGE”); ………………(1)
Sep2->getByName(“DATARANGE”); ……………….(2)
In both the case ( 1 & 2 ), it gets the DATARANGE Node from the Sep2,
I need both the Node Separately
How can I achieve this.
Please help…
Regards,
Aman
mikeheck
01-21-2009, 07:29 AM
I have two Separator (Sep1, Sep2) Node under the SceneNode (SoSeparator). Both having SoDataRange Node, having SameName like “DATARANGE” (set by setName() API). When I use the API getByName()
Sep1->getByName(“DATARANGE”); ………………(1)
Sep2->getByName(“DATARANGE”); ……………….(2)
In both the case ( 1 & 2 ), it gets the DATARANGE Node from the Sep2. I need both the Node Separately.
That's not a problem, it's the defined behavior of getByName. :)
Note that getByName is a class static method in SoNode. The compiler should really issue a warning for calling this method through an instance pointer, to avoid exactly this confusion. The correct call is:
SoNode *p = SoNode::getByName("DATARANGE");
This makes it clearer that this method applies to the whole scene graph and, as noted in the help file, if there are multiple nodes with the same name, it returns the most recently named.
You have multiple options.
A simple one is to append something to the names to make them unique. For example, use DATARANGE1 and DATARANGE2. This doesn't directly address finding the DataRange node that lives under a specific Separator.
You can build the scene graph according to strict rules (that you define), so for example you would know that under these Separators, the DataRange node is always child index 2 (or whatever). Then just use sep1->getChild(2) to get the node.
The most general solution is to apply an SoSearchAction to the Separator, with type set to SoDataRange. This will return a path and the DataRange node will be the last node in the path (call path->getTail).
Regards,
Mike
pbarthel
02-10-2009, 06:56 PM
You should also have a look at
static int getByName (const SbName &name, SoNodeList &list)
for the SoNode class. I found it quite convenient to give an attribute as a name to a bunch of different nodes and then be able to get all of the nodes with this given attribute at the same time through this call.
JulietteKlonk
01-06-2010, 11:08 AM
Very nice post with a ton of informative information.
Thanks.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.