16.10. Creating Paths to Parts

Sometimes you will need a path down to one of the node kit parts—for instance, to replace a part with a manipulator as described in Chapter 17, Draggers and Manipulators. Use the createPathToPart() method to obtain the path to the desired node for the manipulator.


C++
createPathToPart(partName, makeIfNeeded, pathToExtend);
  

.NET
CreatePathToPart(partName, makeIfNeeded, pathToExtend);
  

Java
        
      

For example, after picking a node kit, replace the transform part with a trackball manipulator:


C++
SoPath *pickPath = myPickAction->getPath();

if((pickPath != NULL) &&
   (pickPath->getTail()->isOfType(SoBaseKit::getClassTypeId()))
{
  SoTrackballManip *tb = new SoTrackballManip;
  SoBaseKit *kit = (SoBaseKit *) pickPath->getTail();
  // extends the pick path all the way down
  // to the transform node
  SoPath *attachPath = kit->createPathToPart("transform",
					                     TRUE, pickPath);
  tb->replaceNode(attachPath);
}
  

.NET
SoPath pickPath = myPickAction->GetPath();

if((pickPath != null) &&
   ((pickPath.GetTail()).GetType() == typeof(SoBaseKit)))
{
  SoTrackballManip tb = new SoTrackballManip();
  SoBaseKit kit = (SoBaseKit) pickPath.GetTail();
  // extends the pick path all the way down
  // to the transform node
  SoPath attachPath = kit.CreatePathToPart("transform",
					                     true, pickPath);
  tb.ReplaceNode(attachPath);
}
  

Java
        
      

Note that using replaceNode() does more work for you than simply calling


C++
setPart("transform", tb)
  

.NET
SetPart("transform", tb)
  

Java
setPart("transform", tb)
  

Field values are copied from the existing “transform” part into the trackball manipulator's fields.

If the pathToExtend parameter is NULL or missing, createPathToPart() simply returns the path from the top of the node kit to the specified part (see Figure 16.10, “ Obtaining the Path to a Given Part):


C++
SoPath *littlePath;
littlePath = myKit->createPathToPart("transform", TRUE);
  

.NET
SoPath littlePath = new SoPath();
littlePath = myKit.CreatePathToPart("transform", true);
  

Java
        
      

Since makeIfNeeded is TRUE, the “transform” part will be created if it does not already exist. However, if makeIfNeeded is FALSE and the part does not exist, createPathToPart returns NULL.

[Tip]

Tip: If you want to view the full path, including hidden children, be sure to cast the SoPath( C++ | Java | .NET ) to an SoFullPath.

Obtaining the Path to a Given Part

Figure 16.10.  Obtaining the Path to a Given Part


If the pathToExtend parameter is used, createPathToPart() extends the path provided all the way down to the specified part within the node kit (here, the “transform” node). (See Figure 16.11, “ Extending a Given Path to the Desired Part.) If the path provided as input (in this case, pickPath) does not include the specified node kit, bigPath equals NULL. If the path given as input extends past the specified node kit, the path will first be truncated at the node kit before extending it to reach the part.


C++
bigPath = myKit->createPathToPart("transform", TRUE, pickPath);
  

.NET
bigPath = myKit.CreatePathToPart("transform", true, pickPath);
  

Java
        
      

To create a path to a child within a list part, use the same indexing notation as you would for setPart() or getPart():


C++
pathToListElement = createPathToPart("callbackList[0]", TRUE);
  

.NET
pathToListElement = myKit.CreatePathToPart("callbackList[0]", true);
  

Java
        
      

Extending a Given Path to the Desired Part

Figure 16.11.  Extending a Given Path to the Desired Part