Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
Other Methods: getPart() and setPart()

Two other useful methods of SoBaseKit() are getPart() and setPart().

The getPart() Method

The getPart() method returns the requested node (part):

getPart(partName, makeIfNeeded);

If makeIfNeeded is TRUE and no node is present, the node is created. In addition, if any extra nodes are needed to connect the node to the top node (“this”) of the node kit, those nodes are created as well.

For example:

C++ :

xf = ( SoTransform* )myKit->getPart( "transform", TRUE );

C# :

xf = ( SoTransform )myKit.GetPart( "transform", true );

Java :

xf = ( SoTransform )myKit.getPart( "transform", true );

looks for “transform” and either returns it (if found) or makes it (if not found). It then assigns this node to xf. If you specify FALSE for makeIfNeeded and the node kit has no “transform” yet, the method returns NULL without creating the node. If the catalog for the type of node kit you are using does not have an entry for a part named “transform,” the getPart() method returns NULL.

The setPart() Method

The setPart() method inserts the given node as a new part in the node kit:

setPart(partName, node);

If extra nodes are required to connect the part into the node-kit structure, those nodes are created as well. For example, suppose you want another node kit to share the transform node (xf) created in the previous example:

C++ :

myOtherKit->setPart( "transform", xf );

C# :

myOtherKit.SetPart( "transform", xf );

Java :

myOtherKit.setPart( "transform", xf );

If the given node is not derived from the type of that part, as described in the node-kit catalog, the part will not be set. If you have linked with the debugging library, an error message will print.

To delete the transform node entirely, use a NULL argument for the node pointer:

C++ :

myOtherKit->setPart( "transform", NULL );

C# :

myOtherKit.SetPart( "transform", null );

Java :

myOtherKit.setPart( "transform", null );

To change the “shape” in SoShapeKit from the default cube to a cone:

C++ :

myShape->setPart( "shape", new SoCone );

C# :

myShape.SetPart( "shape", new SoCone() );

Java :

myShape.setPart( "shape", new SoCone() );

And, of course, setPart() will do nothing if there is no part with the specified name in the catalog.