| 1 |
NAME SoBaseKit SoKit "" { base class for all node kits } |
| 2 |
|
| 3 |
INCLUDE nodekits/SoBaseKit.h |
| 4 |
|
| 5 |
DESC { |
| 6 |
This is the base class from which all nodekit nodes are derived. |
| 7 |
Nodekits provide a |
| 8 |
convenient mechanism for creating groups of scene graph nodes with some |
| 9 |
larger meaning. When you create a shape node such as an indexed face set, |
| 10 |
for example, you almost always precede it with a coordinate node. You |
| 11 |
may also want to add a transform node or specify properties with |
| 12 |
material, drawing style, material binding, etc. |
| 13 |
Instead of creating each of these nodes |
| 14 |
individually and then arranging them into a subgraph, |
| 15 |
you can use a nodekit of the appropriate type (in this case, \cSoShapeKit\.). |
| 16 |
\p |
| 17 |
Each class of nodekit has a \enodekit catalog\. (\cSoNodekitCatalog\.) |
| 18 |
that describes the nodes in the subgraph, referred to as \eparts\.. |
| 19 |
The catalog has an entry for each part, with information |
| 20 |
such as the \epartName\., \epartType\., and \enullByDefault\. (if FALSE |
| 21 |
the constructor creates it). |
| 22 |
The catalog also describes the arrangement of parts in the subgraph. |
| 23 |
(Other information is described below; a complete description is in the |
| 24 |
\cSoNodekitCatalog\. reference page.) |
| 25 |
\p |
| 26 |
If we regard the scene graph arrangement as a branching |
| 27 |
tree, then the top node (root) of the arrangement is always the |
| 28 |
nodekit itself. The leaf nodes are those at the bottom (containing no |
| 29 |
children). Some leaves of the tree are defined in the catalog to be |
| 30 |
\epublic\. parts, while |
| 31 |
other leaves are \eprivate\.. All non-leaf parts are considered internal to |
| 32 |
the nodekit structure and are marked private. |
| 33 |
Public parts are accessible; they may be requested, changed, or set by the |
| 34 |
programmer with member functions |
| 35 |
such as \m\+getPart()\.\-SoKitGetPart()\.\.. Private parts are not |
| 36 |
accessible, so |
| 37 |
methods such as \m\+getPart()\.\-SoKitGetPart()\.\. will have no effect on them. For example, |
| 38 |
if you call \m\+getPart()\.\-SoKitGetPart()\.\. to retrieve a private part, \kNULL\. will be returned even when the part exists. |
| 39 |
\p |
| 40 |
Every nodekit reference page has a Parts section describing |
| 41 |
the function of each public part it adds to those inherited from its parent |
| 42 |
class. |
| 43 |
Also, a Catalog Parts section has tables of often-needed |
| 44 |
information from the |
| 45 |
catalog (part type, etc.). These tables include all public parts, |
| 46 |
both new and inherited. |
| 47 |
Only the public parts of a nodekit are described in the reference pages. |
| 48 |
Nodekits take care of the rest for you; they automatically arrange the |
| 49 |
subgraph, creating and deleting the private parts when necessary. |
| 50 |
(The \cSoNodekitCatalog\. reference page has methods for finding out |
| 51 |
the part names and arrangement of all parts, both public and private.) |
| 52 |
\p |
| 53 |
The nodekit catalog is a template shared by all instances of a class. |
| 54 |
They use the shared catalog as a \eguide\. when creating parts |
| 55 |
(i.e., constructing actual nodes), |
| 56 |
but each instance stores its own parts separately. |
| 57 |
Moreover, nodekits are \enot\. \cSoGroup\. |
| 58 |
nodes, and parts are added as \ehidden children\.; |
| 59 |
you can only access parts with the methods of \cSoBaseKit\. and its |
| 60 |
derived classes. |
| 61 |
\p |
| 62 |
Any public part may be retrieved with \m\+getPart()\.\-SoKitGetPart()\.\., |
| 63 |
installed with \m\+setPart()\.\-SoKitSetPart()\.\., |
| 64 |
or removed by giving a \kNULL\. argument to \m\+setPart()\.\-SoKitSetPart()\.\.. |
| 65 |
Paths from the nodekit down to a part can be created by |
| 66 |
\m\+createPathToPart()\.\-SoKitCreatePathToPart()\.\.. |
| 67 |
\p |
| 68 |
By default, parts are not created until the user requests or sets them. |
| 69 |
This keeps the subgraph uncluttered and efficient for traversal. |
| 70 |
Additionally, removing a part (setting it to NULL) has the extra |
| 71 |
effect of removing any internal parts that are no longer needed. |
| 72 |
\p |
| 73 |
Since nodekits hide their children, any \cSoPath\. containing nodekits will |
| 74 |
end at the topmost nodekit. However, since nodekits may be nested within |
| 75 |
other nodekits, you may wish to cast an \c(SoPath *)\. into an |
| 76 |
\c(SoNodeKitPath *)\.. The methods of \cSoNodeKitPath\. allow you to view all |
| 77 |
nodekits that lie on the path (see the reference page for \cSoNodeKitPath\.). |
| 78 |
\p |
| 79 |
Public parts in the nodekit catalog fall into three categories: |
| 80 |
\p |
| 81 |
[1] \eregular nodes\. |
| 82 |
\p |
| 83 |
[2] \enodekits\., or \enested nodekits\. (which may nest recursively). |
| 84 |
Any node which is public in a nested nodekit is accessible to |
| 85 |
the higher level nodekit(s) that contains it. The description |
| 86 |
of \m\+getPart()\.\-SoKitGetPart()\.\. below shows how to refer to nested |
| 87 |
parts by name (e.g., \a"appearance.material"\.). This works for any |
| 88 |
nodekit method that takes a part name for an argument. |
| 89 |
\p |
| 90 |
[3] \elists\., or \elist parts\.. These parts group together children |
| 91 |
(\elist elements\.) of a particular type or types. As with nested nodekits, |
| 92 |
you can refer to individual elements using notation described in |
| 93 |
\m\+getPart()\.\-SoKitGetPart()\.\. |
| 94 |
(e.g., \a"childList[0]"\., or if the list elements are in turn |
| 95 |
nodekits, \a"childList[2].transform"\.). |
| 96 |
\p |
| 97 |
When the catalog denotes that a part is a list, |
| 98 |
the part itself is always a node of type \cSoNodeKitListPart\.. |
| 99 |
The catalog specifies a set of permissible \alistItemTypes\. and a |
| 100 |
\alistContainerType\. for that part. It gives this information to |
| 101 |
the \cSoNodeKitListPart\. |
| 102 |
when it creates it. From then on, the list part will enforce |
| 103 |
type checking. So even if you retrieve the \cSoNodeKitListPart\. |
| 104 |
with \m\+getPart()\.\-SoKitGetPart()\.\., you will not be able to |
| 105 |
add illegal children. (See the \cSoNodeKitListPart\. reference page for more |
| 106 |
information). As an example, the \ecallbackList\. part of \cSoBaseKit\. |
| 107 |
has an \cSoSeparator\. |
| 108 |
container and allows only \cSoCallback\. and \cSoEventCallback\. nodes |
| 109 |
in the list. |
| 110 |
Children may be added, retrieved, and removed from an \cSoNodeKitListPart\. |
| 111 |
node using |
| 112 |
methods that parallel those of \cSoGroup\.. However, type-checking is strictly |
| 113 |
enforced. |
| 114 |
\p |
| 115 |
Note that, although all public parts are leaves in the nodekit catalog, |
| 116 |
you are free to add children to them (assuming that they are groups, nodekits, |
| 117 |
or list parts). A part's status as a leaf in the catalog |
| 118 |
just means that the nodekit will not manage the part's children. |
| 119 |
For example, \cSoWrapperKit\. has a part called \econtents\. with a |
| 120 |
part type of \cSoSeparator\.. You can put whatever you want underneath the |
| 121 |
separator, as long as \econtents\. itself is an \cSoSeparator\.. |
| 122 |
\p |
| 123 |
Thus, a nodekit only controls a section of the scene graph. Above and |
| 124 |
below that section, anything goes. |
| 125 |
\p |
| 126 |
However, when nodekits are nested, they effectively create a larger |
| 127 |
`known' section of the scene graph. |
| 128 |
For example, the \eappearance\. part of the \cSoSeparatorKit\. is a leaf |
| 129 |
node in the \cSoSeparatorKit\. catalog. But \eappearance\. is in turn an |
| 130 |
\cSoAppearanceKit\., containing parts such as \ematerial\. and \edrawStyle\.. |
| 131 |
The two nodekits combine to make an even larger template, which the |
| 132 |
\cSoSeparatorKit\. can examine by looking at the catalogs for both classes. |
| 133 |
So an \cSoSeparatorKit\. can successfully return a part named \a"material"\.; |
| 134 |
first it finds (or creates) the \eappearance\. part, then it gets the |
| 135 |
\ematerial\. by calling \m\+getPart()\.\-SoKitGetPart()\.\. |
| 136 |
on the \eappearance\.. |
| 137 |
\p |
| 138 |
When the catalog defines the \alistItemTypes\. of a list part to be |
| 139 |
nodekits, the name-able space expands further. For example, |
| 140 |
\cSoSeparatorKit\. has a part \echildList\. which |
| 141 |
permits only \cSoSeparatorKits\., so each list element can |
| 142 |
be further searched. Hence the name |
| 143 |
\v"childList[0].childList[1].childList[2].material"\. is perfectly legal. |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
METHOD "" SoBaseKit() { Constructor. } |
| 149 |
|
| 150 |
METHOD getClassNkitCat static |
| 151 |
const SoNodekitCatalog *getClassNodekitCatalog() const |
| 152 |
{ Returns the \cSoNodekitCatalog\. for the class \cSoBaseKit\.. } |
| 153 |
|
| 154 |
METHOD getCat virtual const SoNodekitCatalog *getNodekitCatalog() const |
| 155 |
{ Returns the \cSoNodekitCatalog\. for this instance of \cSoBaseKit\.. |
| 156 |
While each instance of a given class creates its own distinct set |
| 157 |
of parts (which are actual nodes), all instances |
| 158 |
share the same catalog (which |
| 159 |
describes the parts but contains no actual node pointers). } |
| 160 |
|
| 161 |
METHOD "" virtual |
| 162 |
SoNode *getPart(const SbName &partName, SbBool makeIfNeeded) |
| 163 |
|
| 164 |
{ Searches the nodekit catalog (and those of all nested nodekits) for the part |
| 165 |
named \apartName\.. |
| 166 |
Returns a pointer to the part if a \ematch is found\., the part is \epublic\., |
| 167 |
and the part has \ealready been built\.. |
| 168 |
If no match is found, or if the part is \eprivate\., \kNULL\. is returned. |
| 169 |
If \apartName\. is in the catalog (or that of one of its nested nodekit parts), |
| 170 |
but the part has not been built yet, the argument \amakeIfNeeded\. |
| 171 |
determines the course of action. When \amakeIfNeeded\. is \kFALSE\., |
| 172 |
\kNULL\. is returned; when \amakeIfNeeded\. is \kTRUE\., |
| 173 |
\m\+getPart()\.\-SoKitGetPart()\.\. will create the part (as well as any |
| 174 |
necessary intermediary parts), put it in the |
| 175 |
correct place, and return a pointer to the newly created part. |
| 176 |
\p |
| 177 |
Elements of \elist parts\. and parts within nested nodekits can |
| 178 |
all be retrieved with \m\+getPart()\.\-SoKitGetPart()\.\. The full syntax for legal \apartName\. |
| 179 |
arguments is given below. |
| 180 |
\p |
| 181 |
\ePart name BNF notation\.: |
| 182 |
\p |
| 183 |
\kpartName = singleName | compoundName\. |
| 184 |
\p |
| 185 |
\kcompoundName = singleName | compoundName.singleName\. |
| 186 |
\p |
| 187 |
\ksingleName = singlePartName | singleListElementName\. |
| 188 |
\p |
| 189 |
\ksinglePartName =\. the name of any single part in the catalog (including |
| 190 |
those that are lists or nodekits), or in the recursively nested |
| 191 |
catalogs of any of its parts. |
| 192 |
\p |
| 193 |
\ksingleListElementName = singleListName[index]\. |
| 194 |
\p |
| 195 |
\ksingleListName =\. the name of any single list-type part in the |
| 196 |
catalog, or in the recursively nested catalogs of any of its parts. |
| 197 |
\p |
| 198 |
\kindex = integer\. |
| 199 |
\p |
| 200 |
Examples of valid part names are: |
| 201 |
\p |
| 202 |
"transform", "appearance.material", "childList[2].drawStyle", |
| 203 |
"foot", "bird.leftLeg.foot", "octopus.leg[4].suctionCup[2].material" |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
METHOD "" SbString getPartString(const SoBase *part) |
| 208 |
{ Given a node or a path to a node, checks if the part exists in the |
| 209 |
nodekit, in a nested nodekit, or an element of a list part. |
| 210 |
If so, returns a string describing the part name; otherwise, returns an |
| 211 |
empty string (""). |
| 212 |
} |
| 213 |
|
| 214 |
METHOD "" virtual SoNodeKitPath *createPathToPart(const SbName &partName, |
| 215 |
SbBool makeIfNeeded, const SoPath *pathToExtend = NULL) |
| 216 |
{ Returns a path that begins at this nodekit and ends at \apartName\.. |
| 217 |
Searching for the part is the same as in \m\+getPart()\.\-SoKitGetPart()\.\.. |
| 218 |
\kNULL\. is returned if \apartName\. cannot be found, |
| 219 |
or if \amakeIfNeeded\. is \kFALSE\. and the part is not yet built. |
| 220 |
If the the part is retrieved and |
| 221 |
the argument \apathToExtend\. is \kNULL\., |
| 222 |
the path returned begins at \kthis\. and ends at \apartName\.. |
| 223 |
If \apathToExtend\. is not \kNULL\., the path created is a copy of |
| 224 |
\apathToExtend\. with entries appended all the way down to \apartName\.. |
| 225 |
It is okay for \apathToExtend\. to go beyond the nodekit; extra nodes will |
| 226 |
be popped off the tail before continuing from \kthis\. down |
| 227 |
to \apartName\.. |
| 228 |
} |
| 229 |
|
| 230 |
METHOD "" virtual SbBool setPart(const SbName &partName, SoNode *newPart) |
| 231 |
{ Inserts the given node (not a copy) as the new part specified by |
| 232 |
\apartName\.. See \m\+getPart()\.\-SoKitGetPart()\.\. for the syntax of \apartName\.. |
| 233 |
This method adds any extra nodes needed to fit the part into the |
| 234 |
nodekit's catalog. For example, if you call: |
| 235 |
\b\k |
| 236 |
\+mySepKit->setPart("childList[0]", myNewChild);\.\-SoSepKitSetPart(mySepKit, "childList[0]", myNewChild);\. |
| 237 |
\.\. |
| 238 |
the kit may need to create the part |
| 239 |
\echildList\. before it can install \amyNewChild\.. |
| 240 |
Run-time type checking verifies that the node type of \anewPart\. |
| 241 |
matches the type called for by \apartName\.. For example, |
| 242 |
if \apartName\. was a \ematerial\. for an \cSoSeparatorKit\., but |
| 243 |
\anewPart\. was an \cSoTransform\. node, then the node would not be installed, |
| 244 |
and \kFALSE\. would be returned. |
| 245 |
\p |
| 246 |
If \anewPart\. is \kNULL\., then the node specified by \apartName\. is removed. |
| 247 |
If this renders any private parts useless (as occurs when you remove the last |
| 248 |
child of an \cSoGroup\. node), they will also be removed. Hence nodekits do not |
| 249 |
retain unnecessary nodes. |
| 250 |
\p |
| 251 |
\kTRUE\. is returned on success, and \kFALSE\. upon error. |
| 252 |
} |
| 253 |
|
| 254 |
METHOD "" SbBool set(char *partName, char *parameters) {} |
| 255 |
METHOD "set2" SbBool set(char *nameValuePairs) |
| 256 |
{ |
| 257 |
These functions allow field values of parts (nodes) to be set. |
| 258 |
If \apartName\. and \aparameters\. are used, then a single part is |
| 259 |
specified by \apartName\.; the field values |
| 260 |
are specified in \aparameters\.. The format of \aparamaters\. |
| 261 |
is the Inventor File Format syntax. For example, |
| 262 |
\b\k |
| 263 |
\+mySepKit->set("material", "diffuseColor 1 0 0 shininess 0.6");\.\-SoSepKitSet(mySepKit, "material", "diffuseColor 1 0 0 shininess 0.6");\. |
| 264 |
\.\. |
| 265 |
sets the part \ematerial\. to the values |
| 266 |
\k"diffuseColor 1 0 0 shininess 0.6"\.. The values |
| 267 |
used in \aparameters\. must of course be appropriate for the node-type |
| 268 |
to which \apartName\. belongs. |
| 269 |
In this case, the nodekit \cSoSeparatorKit\. has a part named \ematerial\. |
| 270 |
which is of type \cSoMaterial\.. |
| 271 |
\p |
| 272 |
The \anameValuePairs\. syntax can be used to set the field values |
| 273 |
in several different parts simultaneously. In this case, |
| 274 |
the argument string, \anameValuePairs\. contains \ename-value\. pairs: |
| 275 |
\k"partName1 { parameters1 \} ... partNameN { parametersN \}"\.. |
| 276 |
\p |
| 277 |
For example, |
| 278 |
\b\k |
| 279 |
\+mySepKit->set("material { diffuseColor 1 1 1 \} |
| 280 |
transform { translation 4 3 .6 \}"); |
| 281 |
mySepKit->set("childList[0].material { ambientColor .5 .5 .5 \}");\.\-SoSepKitSet2(mySepKit, "material { diffuseColor 1 1 1 \} |
| 282 |
transform { translation 4 3 .6 \}"); |
| 283 |
SoSepKitSet2(mySepKit, "childList[0].material { ambientColor .5 .5 .5 \}");\.\.\. |
| 284 |
} |
| 285 |
|
| 286 |
METHOD "" static SbBool isSearchingChildren() {} |
| 287 |
METHOD "" static void setSearchingChildren(SbBool newVal) |
| 288 |
{ Sets and queries if nodekit children are searched during \cSoSearchAction\. |
| 289 |
traversal. By default, they are not. } |
| 290 |
|
| 291 |
METHOD "" static SoType getClassTypeId() { |
| 292 |
Returns type identifier for this class. |
| 293 |
} |
| 294 |
|
| 295 |
PART callbackList |
| 296 |
{ This is the only part that the base class \cSoBaseKit\. creates. |
| 297 |
It is a public part that is inherited by \eall\. nodekits. |
| 298 |
It provides an easy way to add callbacks for a nodekit to use |
| 299 |
during action traversal |
| 300 |
(e.g. \cSoHandleEventAction\.). It is a list part and may contain |
| 301 |
numerous \cSoCallback\. and/or \cSoEventCallback\. nodes. } |
| 302 |
|
| 303 |
|
| 304 |
BEGIN C++ |
| 305 |
MACRO SO_GET_PART (kit, partName, partClass) |
| 306 |
{ Calls \mgetPart()\. with \amakeIfNeeded\. set to \kTRUE\., |
| 307 |
then casts the result to the type \apartClass\.. Note that in the |
| 308 |
debug library, this macro checks to see if the part is of type |
| 309 |
\apartClass\., while the regular library does no type checking. } |
| 310 |
|
| 311 |
MACRO SO_CHECK_PART (kit, partName, partClass) |
| 312 |
{ Calls \mgetPart()\., but with \amakeIfNeeded\. set to \kFALSE\., |
| 313 |
then casts the result to the type \apartClass\.. Note that in the |
| 314 |
debug library, this macro checks to see if the part is of type |
| 315 |
\apartClass\., while the regular library does no type checking. } |
| 316 |
END |
| 317 |
|
| 318 |
|
| 319 |
ALSO { |
| 320 |
SoAppearanceKit, |
| 321 |
SoCameraKit, |
| 322 |
SoLightKit, |
| 323 |
SoNodeKit, |
| 324 |
SoNodeKitDetail, |
| 325 |
SoNodeKitListPart, |
| 326 |
SoNodeKitPath, |
| 327 |
SoNodekitCatalog, |
| 328 |
SoSceneKit, |
| 329 |
SoSeparatorKit, |
| 330 |
SoShapeKit, |
| 331 |
SoWrapperKit } |
| 332 |
|
| 333 |
|
| 334 |
ACTION SoGLRenderAction, SoCallbackAction, SoGetBoundingBoxAction, |
| 335 |
SoHandleEventAction { |
| 336 |
Behaves like an \cSoGroup\.. Traverses each child in order. |
| 337 |
} |
| 338 |
|
| 339 |
ACTION SoRayPickAction { |
| 340 |
Traverses each child in order. Then, for any pick containing the kit |
| 341 |
on its path, makes an \cSoNodeKitDetail\. as follows: |
| 342 |
Sets the \k"detailNodeKit"\. (retrievable with |
| 343 |
\m\+SoNodeKitDetail::getNodeKit()\.\-SoNkDtlGetNodeKit()\.\.) |
| 344 |
to be a pointer to itself. |
| 345 |
Sets the \k"detailPart"\. (retrievable with |
| 346 |
\m\+SoNodeKitDetail::getPart()\.\-SoNkDtlGetPart()\.\.) |
| 347 |
to be a pointer to the kit's leaf-most part that lies on the pickPath. |
| 348 |
Sets the \k"detailPartName"\. (retrievable with |
| 349 |
\m\+SoNodeKitDetail::getPartName()\.\-SoNkDtlGetPartName()\.\.) |
| 350 |
to be the partName of that part, as found in the catalog. |
| 351 |
\p |
| 352 |
Does not descend into nested nodekits. Each nodekit along the path |
| 353 |
is the \k"detailPart"\. in its parent's detail. |
| 354 |
However, if the pick path goes through a list part, a pointer to the child |
| 355 |
is used for the \k"detailPart"\., and \k"detailPartName"\. is of the |
| 356 |
form \a"listName[i]"\.. |
| 357 |
} |
| 358 |
|
| 359 |
ACTION SoGetMatrixAction { |
| 360 |
Behaves like an \cSoGroup\.. |
| 361 |
Does nothing unless the kit is in the middle of the path chain the |
| 362 |
action is being applied to. If so, the children up to and including |
| 363 |
the next node in the chain are traversed. |
| 364 |
} |
| 365 |
|
| 366 |
ACTION SoSearchAction { |
| 367 |
First, searches itself like an \cSoNode\.. |
| 368 |
Then, checks the value of |
| 369 |
\m\+isSearchingChildren()\.\-SoKitIsSearchingChildren()\.\.. |
| 370 |
If TRUE, traverses the children in order. If FALSE, returns. |
| 371 |
} |
| 372 |
|
| 373 |
ACTION SoWriteAction { |
| 374 |
Begins by writing out regular fields, then writes out the parts. |
| 375 |
A nodekit does \enot\. write out its parts the way an \cSoGroup\. writes |
| 376 |
out its children. Instead, it writes each part as an \cSoSFNode\. field. |
| 377 |
First the partName is written, then the node being used for that part. |
| 378 |
\p |
| 379 |
To keep the files terse, nodekits write out as few parts as possible. |
| 380 |
However, nodekits \ealways\. write a part if another instance or a path is |
| 381 |
writing it. If this is not the case, parts are left out according to |
| 382 |
the following rules: |
| 383 |
\p |
| 384 |
[1] NULL parts only write if the catalog states they are created by default. |
| 385 |
\p |
| 386 |
[2] Empty \cSoGroup\. and \cSoSeparator\. nodes do not write. |
| 387 |
\p |
| 388 |
[3] Non-leaf parts only write if they have non-default field values. |
| 389 |
\p |
| 390 |
[4] List parts only write if they have children or if the container node has |
| 391 |
non-default field values. |
| 392 |
\p |
| 393 |
[5] Nested nodekit parts only write if they need to write one or more parts, |
| 394 |
or if they have non-default field values. |
| 395 |
} |