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.
createPathToPart(partName, makeIfNeeded, pathToExtend);
CreatePathToPart(partName, makeIfNeeded, pathToExtend);
For example, after picking a node kit, replace the transform part with a trackball manipulator:
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); }
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); }
Note that using replaceNode() does more work for you than simply calling
setPart("transform", tb)
SetPart("transform", tb)
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 ”):
SoPath *littlePath; littlePath = myKit->createPathToPart("transform", TRUE);
SoPath littlePath = new SoPath(); littlePath = myKit.CreatePathToPart("transform", true);
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: If you want to view the full path, including hidden children, be sure to cast the SoPath SoPath SoPath to an SoFullPath. |
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.
bigPath = myKit->createPathToPart("transform", TRUE, pickPath);
bigPath = myKit.CreatePathToPart("transform", true, pickPath);
To create a path to a child within a list part, use the same indexing notation as you would for setPart() or getPart():
pathToListElement = createPathToPart("callbackList[0]", TRUE);
pathToListElement = myKit.CreatePathToPart("callbackList[0]", true);