16.8. Macros for Getting Parts

Instead of using the getPart() method, you can use the macros SO_GET_PART() and SO_CHECK_PART(). If you compile with the debugging version of the Inventor library, these macros perform casting and type check the result for you. (If you link with the optimized version of Inventor, no type-checking is performed.)

The syntax for SO_GET_PART() is as follows:

SO_GET_PART(kitContainingPart, partName, partClassName);

This macro does the type-casting for you and is equivalent to

(partClassName *) kitContainingPart->getPart(partName, TRUE);

Since the makeIfNeeded argument is TRUE in this macro, the part is created if it is not already in the node kit.

For example:


C++
xf = SO_GET_PART(myKit, "transform", SoTransform);

  

The syntax for SO_CHECK_PART() is as follows:

SO_CHECK_PART(kitContainingPart, partName, partClassName);

This macro does the type-casting for you and is equivalent to

(partClassName *) kitContainingPart->getPart(partName, FALSE);

Since the makeIfNeeded argument is FALSE in this macro, the part is not created if it is not already in the node kit.

For example:


C++
xf = SO_CHECK_PART(myKit, "transform", SoTransform);
if (xf == NULL)
   printf("Transform does not exist in myKit.");
else 
   printf("Got it!");