16.9. Specifying Part Names

Suppose you have created the three node-kit classes shown in Figure 16.9, “ Three Node-Kit Classes for Making “Goons” (see The Inventor Toolmaker, Chapter 7, for information on how to subclass node kits):

After creating an instance of SoGoonKit (myGoon), you can be very specific when asking for the parts. For example:

myCube = SO_GET_PART(myGoon, "toe1", SoCube);
  
myCube = (SoCube)myGoon.GetPart("toe1", true);
  
myCube = (SoCube)myGoon.getPart("toe1", true);
  

first looks in the catalog of myGoon for toe1. If it doesn't find toe1 and some children in the catalog are node kits, it looks inside the leaf node kits for toe1 and uses the first match it finds. Here, the match would be found in the foot of leg1. But what if you really want toe1 in leg2? In that case, you may specify:

myCube = SO_GET_PART(myGoon, "leg2.toe1", SoCube);
  
myCube = (SoCube)myGoon.GetPart("leg2.toe1", true);
  
myCube = (SoCube)myGoon.getPart("leg2.toe1", true);
  

which returns toe1 in leg2. This is equivalent to leg2.foot.toe1.

You can also refer to parts by indexing into any part that is defined as a list in the catalog—for example, “childList[0]” or “callbackList[2].”

The following excerpts illustrate three different ways to create node-kit parts and set their values. These excerpts assume you have subclassed to create your own class, derived from SoBaseKit SoBaseKit SoBaseKit , an SoGoonKit (see The Inventor Toolmaker, Chapter 7). This goon has a body, legs, and feet, as described earlier.

This fragment shows setting each part individually:

SoGoonKit *myGoon = new SoGoonKit();
myGoon->set("body.material", "diffuseColor [1 0 0 ]");
// makes body red
myGoon->set("leg2.toe1", "width 2 height 3 depth 1");
// creates toe with proper dimensions
  
SoGoonKit myGoon = new SoGoonKit();
myGoon.Set("body.material", "diffuseColor [1 0 0 ]");
// makes body red
myGoon.Set("leg2.toe1", "width 2 height 3 depth 1");
// creates toe with proper dimensions
  
SoGoonKit myGoon = new SoGoonKit();
myGoon.set("body.material", "diffuseColor [1 0 0 ]");
// makes body red
myGoon.set("leg2.toe1", "width 2 height 3 depth 1");
// creates toe with proper dimensions
  

Three Node-Kit Classes for Making “Goons”

Figure 16.9.  Three Node-Kit Classes for Making “Goons”



This fragment shows getting parts and editing them:

SoGoonKit *myGoon = new SoGoonKit();
SoMaterial *bodyMtl;
SoCube     *toe;
bodyMtl = SO_GET_PART(myGoon, "body.material", SoMaterial);
bodyMtl->diffuseColor.setValue(1, 0, 0);
toe = SO_GET_PART(myGoon, "leg2.toe1", SoCube);
toe->width.setValue(2);
toe->height.setValue(3);
toe->depth.setValue(1);
  
SoGoonKit myGoon = new SoGoonKit();
SoMaterial bodyMtl = new SoMaterial();
SoCube toe = new SoCube();
bodyMtl = (SoMaterial)myGoon.GetPart("body.material", true);
bodyMtl.diffuseColor.SetValue(1f, 0f, 0f);
toe = (SoCube)myGoon.GetPart("leg2.toe1", true);
toe.width.alue = 2f;
toe.height.Value = 3f;
toe.depth.Value = 1f;
  
SoGoonKit myGoon = new SoGoonKit();
SoMaterial bodyMtl = new SoMaterial();
SoCube toe = new SoCube();
bodyMtl = (SoMaterial)myGoon.getPart("body.material", true);
bodyMtl.diffuseColor.setValue(1f, 0f, 0f);
toe = (SoCube)myGoon.getPart("leg2.toe1", true);
toe.width.setValue(2f);
toe.height.setValue(3f);
toe.depth.setValue(1f);
  

This fragment shows setting both parts in one command:

SoGoonKit *myGoon = new SoGoonKit();
myGoon->set("body.material { diffuseColor [ 1 0 0 ] }
			     leg2.toe1  { width 2
				                 height 3
				                 depth 1 }");
  
SoGoonKit myGoon = new SoGoonKit();
myGoon.Set("body.material { diffuseColor [ 1 0 0 ] }" +
		   "leg2.toe1 #160{ width 2" +
				           "height 3" +
				           "depth 1 }");
SoGoonKit myGoon = new SoGoonKit();
myGoon.set("body.material { diffuseColor [ 1 0 0 ] }" +
           "leg2.toe1 #160{ width 2" +
                           "height 3" +
                           "depth 1 }");