| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Copyright (C) 1990,91 Silicon Graphics, Inc. |
| 39 | * |
| 40 | _______________________________________________________________________ |
| 41 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 | | |
| 43 | | $Revision: 1.2 $ |
| 44 | | |
| 45 | | Classes: |
| 46 | | SoSwitch |
| 47 | | |
| 48 | | Author(s) : Paul S. Strauss, Nick Thompson |
| 49 | | |
| 50 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 | _______________________________________________________________________ |
| 52 | */ |
| 53 | |
| 54 | |
| 55 | #include <Inventor/actions/SoCallbackAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoCallbackAction.h`/ |
| 56 | #include <Inventor/actions/SoGLRenderAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoGLRenderAction.h`/ |
| 57 | #include <Inventor/actions/SoGetBoundingBoxAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoGetBoundingBoxAction.h`/ |
| 58 | #include <Inventor/actions/SoGetMatrixAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoGetMatrixAction.h`/ |
| 59 | #include <Inventor/actions/SoHandleEventAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoHandleEventAction.h`/ |
| 60 | #include <Inventor/actions/SoPickAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoPickAction.h`/ |
| 61 | #include <Inventor/actions/SoSearchAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoSearchAction.h`/ |
| 62 | #include <Inventor/actions/SoWriteAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoWriteAction.h`/ |
| 63 | #include <Inventor/elements/SoSwitchElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoSwitchElement.h`/ |
| 64 | #include <Inventor/errors/SoDebugError.h>cxx . . $ `<file>/lib/database/include/Inventor/errors/SoDebugError.h`/ |
| 65 | #include <Inventor/misc/SoChildList.h>cxx . . $ `<file>/lib/database/include/Inventor/misc/SoChildList.h`/ |
| 66 | #include <Inventor/misc/SoState.h>cxx . . $ `<file>/lib/database/include/Inventor/misc/SoState.h`/ |
| 67 | #include <Inventor/nodes/SoSwitch.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoSwitch.h`/ |
| 68 | |
| 69 | SO_NODE_SOURCEcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:241:9`!(SoSwitch); |
| 70 | |
| 71 | //////////////////////////////////////////////////////////////////////// |
| 72 | // |
| 73 | // Description: |
| 74 | // Constructor |
| 75 | // |
| 76 | // Use: public |
| 77 | |
| 78 | SoSwitchcxx . . $ SoSwitch#::SoSwitchcxx . . $ SoSwitch#SoSwitch(49f6e7a06ebc5aa8).() |
| 79 | // |
| 80 | //////////////////////////////////////////////////////////////////////// |
| 81 | { |
| 82 | SO_NODE_CONSTRUCTORcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:309:9`!(SoSwitch); |
| 83 | SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(whichChild, (SO_SWITCH_NONEcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:75:9`!)); |
| 84 | isBuiltIncxx . . $ SoFieldContainer#isBuiltIn. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 85 | } |
| 86 | |
| 87 | //////////////////////////////////////////////////////////////////////// |
| 88 | // |
| 89 | // Description: |
| 90 | // Constructor that takes approximate number of children. |
| 91 | // |
| 92 | // Use: public |
| 93 | |
| 94 | SoSwitchcxx . . $ SoSwitch#::SoSwitchcxx . . $ SoSwitch#SoSwitch(d4f767463ce0a6b3).(int nChildren) : SoGroupcxx . . $ SoGroup#(nChildren) |
| 95 | // |
| 96 | //////////////////////////////////////////////////////////////////////// |
| 97 | { |
| 98 | SO_NODE_CONSTRUCTORcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:309:9`!(SoSwitch); |
| 99 | SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(whichChild, (SO_SWITCH_NONEcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:75:9`!)); |
| 100 | isBuiltIncxx . . $ SoFieldContainer#isBuiltIn. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 101 | } |
| 102 | |
| 103 | //////////////////////////////////////////////////////////////////////// |
| 104 | // |
| 105 | // Description: |
| 106 | // Destructor |
| 107 | // |
| 108 | // Use: private |
| 109 | |
| 110 | SoSwitchcxx . . $ SoSwitch#::~cxx . . $ SoSwitch#`~SoSwitch`(49f6e7a06ebc5aa8).SoSwitchcxx . . $ SoSwitch#() |
| 111 | // |
| 112 | //////////////////////////////////////////////////////////////////////// |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | //////////////////////////////////////////////////////////////////////// |
| 117 | // |
| 118 | // Description: |
| 119 | // Overrides method in SoNode to return FALSE if there is no |
| 120 | // selected child or the selected child does not affect the state. |
| 121 | // |
| 122 | // Use: public |
| 123 | |
| 124 | SbBoolcxx . . $ SbBool# |
| 125 | SoSwitchcxx . . $ SoSwitch#::affectsStatecxx . . $ SoSwitch#affectsState(455f465bc33b4cdf).() const |
| 126 | // |
| 127 | //////////////////////////////////////////////////////////////////////// |
| 128 | { |
| 129 | int which; |
| 130 | if (whichChildcxx . . $ SoSwitch#whichChild..isIgnoredcxx . . $ SoField#isIgnored(455f465bc33b4cdf).()) |
| 131 | which = SO_SWITCH_NONEcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:75:9`!; |
| 132 | else |
| 133 | which = whichChildcxx . . $ SoSwitch#whichChild..getValuecxx . . $ SoSFInt32#getValue(455f465bc33b4cdf).(); |
| 134 | |
| 135 | // Special case-- if called during application of an |
| 136 | // SoSearchAction that is searching all: |
| 137 | if (SoSearchActioncxx . . $ SoSearchAction#::duringSearchAllcxx . . $ SoSearchAction#duringSearchAll.) |
| 138 | which = SO_SWITCH_ALLcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:77:9`!; |
| 139 | |
| 140 | if (whichChildcxx . . $ SoSwitch#whichChild..isIgnoredcxx . . $ SoField#isIgnored(455f465bc33b4cdf).() || which == SO_SWITCH_NONEcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:75:9`!) |
| 141 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 142 | |
| 143 | if (which == SO_SWITCH_ALLcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:77:9`! || |
| 144 | which == SO_SWITCH_INHERITcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:76:9`!) |
| 145 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 146 | |
| 147 | if (getChildcxx . . $ SoGroup#getChild(fd675789997d09c2).(which)->affectsStatecxx . . $ SoNode#affectsState(455f465bc33b4cdf).()) |
| 148 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 149 | |
| 150 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 151 | } |
| 152 | |
| 153 | //////////////////////////////////////////////////////////////////////// |
| 154 | // |
| 155 | // Description: |
| 156 | // Typical action traversal. |
| 157 | // |
| 158 | // Use: extender |
| 159 | |
| 160 | void |
| 161 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(SoActioncxx . . $ SoAction# *action) |
| 162 | // |
| 163 | //////////////////////////////////////////////////////////////////////// |
| 164 | { |
| 165 | int numIndices; |
| 166 | const int *indices; |
| 167 | |
| 168 | if (action->getPathCodecxx . . $ SoAction#getPathCode(8bed7858e06375c9).(numIndices, indices) == SoActioncxx . . $ SoAction#::IN_PATHcxx . . $ SoAction#IN_PATH.) { |
| 169 | int i; |
| 170 | for (i = 0; i < numIndices; i++) |
| 171 | doChildcxx . . $ SoSwitch#doChild(26b22d80ec04e930).(action, indices[i]); |
| 172 | } |
| 173 | |
| 174 | else |
| 175 | doChildcxx . . $ SoSwitch#doChild(26b22d80ec04e930).(action); |
| 176 | } |
| 177 | |
| 178 | //////////////////////////////////////////////////////////////////////// |
| 179 | // |
| 180 | // Description: |
| 181 | // Traversal for callback action. |
| 182 | // |
| 183 | // Use: extender |
| 184 | |
| 185 | void |
| 186 | SoSwitchcxx . . $ SoSwitch#::callbackcxx . . $ SoSwitch#callback(425635c2081b81c8).(SoCallbackActioncxx . . $ SoCallbackAction# *action) |
| 187 | // |
| 188 | //////////////////////////////////////////////////////////////////////// |
| 189 | { |
| 190 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 191 | } |
| 192 | |
| 193 | //////////////////////////////////////////////////////////////////////// |
| 194 | // |
| 195 | // Description: |
| 196 | // Traversal for GL rendering |
| 197 | // |
| 198 | // Use: extender |
| 199 | |
| 200 | void |
| 201 | SoSwitchcxx . . $ SoSwitch#::GLRendercxx . . $ SoSwitch#GLRender(5c806c737f468e18).(SoGLRenderActioncxx . . $ SoGLRenderAction# *action) |
| 202 | // |
| 203 | //////////////////////////////////////////////////////////////////////// |
| 204 | { |
| 205 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 206 | } |
| 207 | |
| 208 | //////////////////////////////////////////////////////////////////////// |
| 209 | // |
| 210 | // Description: |
| 211 | // Traversal for picking |
| 212 | // |
| 213 | // Use: extender |
| 214 | |
| 215 | void |
| 216 | SoSwitchcxx . . $ SoSwitch#::pickcxx . . $ SoSwitch#pick(7b4c6871cb3411ea).(SoPickActioncxx . . $ SoPickAction# *action) |
| 217 | // |
| 218 | //////////////////////////////////////////////////////////////////////// |
| 219 | { |
| 220 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 221 | } |
| 222 | |
| 223 | //////////////////////////////////////////////////////////////////////// |
| 224 | // |
| 225 | // Description: |
| 226 | // Traversal for get bounding box |
| 227 | // |
| 228 | // Use: extender |
| 229 | |
| 230 | void |
| 231 | SoSwitchcxx . . $ SoSwitch#::getBoundingBoxcxx . . $ SoSwitch#getBoundingBox(dd7d7d7c2dd56aae).(SoGetBoundingBoxActioncxx . . $ SoGetBoundingBoxAction# *action) |
| 232 | // |
| 233 | //////////////////////////////////////////////////////////////////////// |
| 234 | { |
| 235 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 236 | } |
| 237 | |
| 238 | //////////////////////////////////////////////////////////////////////// |
| 239 | // |
| 240 | // Description: |
| 241 | // Traversal for handle event |
| 242 | // |
| 243 | // Use: extender |
| 244 | |
| 245 | void |
| 246 | SoSwitchcxx . . $ SoSwitch#::handleEventcxx . . $ SoSwitch#handleEvent(89f4d17049d836a3).(SoHandleEventActioncxx . . $ SoHandleEventAction# *action) |
| 247 | // |
| 248 | //////////////////////////////////////////////////////////////////////// |
| 249 | { |
| 250 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 251 | } |
| 252 | |
| 253 | //////////////////////////////////////////////////////////////////////// |
| 254 | // |
| 255 | // Description: |
| 256 | // Implements getMatrix action. |
| 257 | // |
| 258 | // Use: extender |
| 259 | |
| 260 | void |
| 261 | SoSwitchcxx . . $ SoSwitch#::getMatrixcxx . . $ SoSwitch#getMatrix(b69d845234b7e6ee).(SoGetMatrixActioncxx . . $ SoGetMatrixAction# *action) |
| 262 | // |
| 263 | //////////////////////////////////////////////////////////////////////// |
| 264 | { |
| 265 | int numIndices; |
| 266 | const int *indices; |
| 267 | |
| 268 | // Only need to compute matrix if switch is a node in middle of |
| 269 | // current path chain or is off path chain (since the only way |
| 270 | // this could be called if it is off the chain is if the switch is |
| 271 | // under a group that affects the chain). |
| 272 | |
| 273 | switch (action->getPathCodecxx . . $ SoAction#getPathCode(8bed7858e06375c9).(numIndices, indices)) { |
| 274 | |
| 275 | case SoActioncxx . . $ SoAction#::NO_PATHcxx . . $ SoAction#NO_PATH.: |
| 276 | case SoActioncxx . . $ SoAction#::BELOW_PATHcxx . . $ SoAction#BELOW_PATH.: |
| 277 | break; |
| 278 | |
| 279 | case SoActioncxx . . $ SoAction#::OFF_PATHcxx . . $ SoAction#OFF_PATH.: |
| 280 | case SoActioncxx . . $ SoAction#::IN_PATHcxx . . $ SoAction#IN_PATH.: |
| 281 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | //////////////////////////////////////////////////////////////////////// |
| 287 | // |
| 288 | // Description: |
| 289 | // Implements search action. |
| 290 | // |
| 291 | // Use: extender |
| 292 | // |
| 293 | //////////////////////////////////////////////////////////////////////// |
| 294 | |
| 295 | void |
| 296 | SoSwitchcxx . . $ SoSwitch#::searchcxx . . $ SoSwitch#search(ecd330ee9b1f803b).(SoSearchActioncxx . . $ SoSearchAction# *action) |
| 297 | { |
| 298 | // if the action is searching everything, then do so... |
| 299 | if (action->isSearchingAllcxx . . $ SoSearchAction#isSearchingAll(455f465bc33b4cdf).()) |
| 300 | SoGroupcxx . . $ SoGroup#::searchcxx . . $ SoGroup#search(ecd330ee9b1f803b).(action); |
| 301 | |
| 302 | // Otherwise, traverse according to the regular switch node rules |
| 303 | else { |
| 304 | // First, make sure this node is found if we are searching for |
| 305 | // switches |
| 306 | SoNodecxx . . $ SoNode#::searchcxx . . $ SoNode#search(ecd330ee9b1f803b).(action); |
| 307 | |
| 308 | // Recurse |
| 309 | if (! action->isFoundcxx . . $ SoSearchAction#isFound(455f465bc33b4cdf).()) |
| 310 | SoSwitchcxx . . $ SoSwitch#::doActioncxx . . $ SoSwitch#doAction(967167263c8a77b7).(action); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | //////////////////////////////////////////////////////////////////////// |
| 315 | // |
| 316 | // Description: |
| 317 | // Traverses correct child based on value of whichChild field. If |
| 318 | // matchIndex is non-negative, the indicated child must match it |
| 319 | // for it to be traversed. Sets switch element in state unless we |
| 320 | // are inheriting the value. |
| 321 | // |
| 322 | // Use: private |
| 323 | |
| 324 | void |
| 325 | SoSwitchcxx . . $ SoSwitch#::doChildcxx . . $ SoSwitch#doChild(26b22d80ec04e930).(SoActioncxx . . $ SoAction# *action, int matchIndex) |
| 326 | // |
| 327 | //////////////////////////////////////////////////////////////////////// |
| 328 | { |
| 329 | int32_tcxx . . $ int32_t# which; |
| 330 | |
| 331 | if (whichChildcxx . . $ SoSwitch#whichChild..isIgnoredcxx . . $ SoField#isIgnored(455f465bc33b4cdf).()) |
| 332 | which = SO_SWITCH_NONEcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:75:9`!; |
| 333 | |
| 334 | else |
| 335 | which = whichChildcxx . . $ SoSwitch#whichChild..getValuecxx . . $ SoSFInt32#getValue(455f465bc33b4cdf).(); |
| 336 | |
| 337 | // If index is inherited from state, get value from there |
| 338 | if (which == SO_SWITCH_INHERITcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:76:9`!) { |
| 339 | |
| 340 | which = SoSwitchElementcxx . . $ SoSwitchElement#::getcxx . . $ SoSwitchElement#get(fec557bbb5044c9b).(action->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).()); |
| 341 | |
| 342 | // Make sure it is in range |
| 343 | if (which >= getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).()) |
| 344 | which %= getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).(); |
| 345 | } |
| 346 | |
| 347 | // Store resulting index in state if not already inherited from there |
| 348 | else |
| 349 | SoSwitchElementcxx . . $ SoSwitchElement#::setcxx . . $ SoSwitchElement#set(47a371b7b9daa722).(action->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).(), which); |
| 350 | |
| 351 | // Now we have the real value to deal with |
| 352 | |
| 353 | switch (which) { |
| 354 | |
| 355 | case SO_SWITCH_NONEcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:75:9`!: |
| 356 | break; |
| 357 | |
| 358 | case SO_SWITCH_ALLcxx . . $ `lib/database/include/Inventor/nodes/SoSwitch.h:77:9`!: |
| 359 | // If traversing to compute bounding box, we have to do some |
| 360 | // work in between children |
| 361 | if (action->isOfTypecxx . . $ SoAction#isOfType(1fd66475a268b64e).(SoGetBoundingBoxActioncxx . . $ SoGetBoundingBoxAction#::getClassTypeIdcxx . . $ SoGetBoundingBoxAction#getClassTypeId(c00c150378d2b968).())) { |
| 362 | SoGetBoundingBoxActioncxx . . $ SoGetBoundingBoxAction# *bba = (SoGetBoundingBoxActioncxx . . $ SoGetBoundingBoxAction# *) action; |
| 363 | SbVec3fcxx . . $ SbVec3f# totalCentercxx . . $ SbVec3f#SbVec3f(bd1040fe176e0786).(0.0, 0.0, 0.0); |
| 364 | int numCenters = 0; |
| 365 | int lastChild = (matchIndex >= 0 ? matchIndex : |
| 366 | getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).() - 1); |
| 367 | |
| 368 | for (int i = 0; i <= lastChild; i++) { |
| 369 | childrencxx . . $ SoGroup#children.->traversecxx . . $ SoChildList#traverse(8167277d18ca88ca).(bba, i, i); |
| 370 | if (bba->isCenterSetcxx . . $ SoGetBoundingBoxAction#isCenterSet(455f465bc33b4cdf).()) { |
| 371 | totalCenter +=cxx . . $ SbVec3f#`operator+=`(13422326b1abca17). bba->getCentercxx . . $ SoGetBoundingBoxAction#getCenter(b5c384c15c94bb12).(); |
| 372 | numCenters++; |
| 373 | bba->resetCentercxx . . $ SoGetBoundingBoxAction#resetCenter(49f6e7a06ebc5aa8).(); |
| 374 | } |
| 375 | } |
| 376 | // Now, set the center to be the average: |
| 377 | if (numCenters != 0) |
| 378 | bba->setCentercxx . . $ SoGetBoundingBoxAction#setCenter(53e9a146b1159747).(totalCenter /cxx . . $ `operator/`(8301011090c64e0f). numCenters, FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!); |
| 379 | } |
| 380 | else { |
| 381 | if (matchIndex >= 0) |
| 382 | childrencxx . . $ SoGroup#children.->traversecxx . . $ SoChildList#traverse(8167277d18ca88ca).(action, 0, matchIndex); |
| 383 | else |
| 384 | childrencxx . . $ SoGroup#children.->traversecxx . . $ SoChildList#traverse(967167263c8a77b7).(action); |
| 385 | } |
| 386 | break; |
| 387 | |
| 388 | default: |
| 389 | |
| 390 | // Make sure index is reasonable |
| 391 | if (which < 0 || which >= getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).()) { |
| 392 | #ifdef DEBUG |
| 393 | SoDebugError::post("SoSwitch::doChild", |
| 394 | "Child index %d is out of range %d - %d " |
| 395 | "(applying %s)", |
| 396 | which, 0, getNumChildren() - 1, |
| 397 | action->getTypeId().getName().getString()); |
| 398 | #endif /* DEBUG */ |
| 399 | break; |
| 400 | } |
| 401 | |
| 402 | // Traverse indicated child |
| 403 | if (matchIndex < 0 || matchIndex == which) |
| 404 | childrencxx . . $ SoGroup#children.->traversecxx . . $ SoChildList#traverse(26b22d80ec04e930).(action, (int) which); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | //////////////////////////////////////////////////////////////////////// |
| 409 | // |
| 410 | // Description: |
| 411 | // Implements write action. |
| 412 | // |
| 413 | // Use: extender |
| 414 | |
| 415 | void |
| 416 | SoSwitchcxx . . $ SoSwitch#::writecxx . . $ SoSwitch#write(a375a81bffae2638).(SoWriteActioncxx . . $ SoWriteAction# *action) |
| 417 | // |
| 418 | //////////////////////////////////////////////////////////////////////// |
| 419 | { |
| 420 | SoOutputcxx . . $ SoOutput# *out = action->getOutputcxx . . $ SoWriteAction#getOutput(daf9692406936d14).(); |
| 421 | |
| 422 | // When writing out a switch that is in a path, we always want to |
| 423 | // write out ALL children of the switch. If we did the default |
| 424 | // thing of writing out just those children that affect the nodes |
| 425 | // in the path, we could screw up. Consider a switch that has two |
| 426 | // child separators and whichChild set to 1. If a path goes |
| 427 | // through the switch to the second child, the first child, being |
| 428 | // a separator, does not affect the path. But if we don't write |
| 429 | // out the separator, the whichChild will reference a |
| 430 | // nonexistent child. So we always write out all children. |
| 431 | |
| 432 | // NOTE: SoChildList::traverse() checks the current path code and |
| 433 | // skips children off the path that do not affect the |
| 434 | // state. Because of this we have to avoid calling it. Instead, we |
| 435 | // do its work here. |
| 436 | |
| 437 | // This code is stolen and modified from SoGroup::write() and |
| 438 | // SoChildList::traverse() |
| 439 | |
| 440 | int lastChild = getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).() - 1; |
| 441 | SoActioncxx . . $ SoAction#::PathCodecxx . . $ SoAction#PathCode# pc = action->getCurPathCodecxx . . $ SoAction#getCurPathCode(642470b03220c9ca).(); |
| 442 | |
| 443 | // In write-reference counting phase |
| 444 | if (out->getStagecxx . . $ SoOutput#getStage(951fc68f69ba3c5a).() == SoOutputcxx . . $ SoOutput#::COUNT_REFScxx . . $ SoOutput#COUNT_REFS.) { |
| 445 | |
| 446 | // Increment our write reference count |
| 447 | addWriteReferencecxx . . $ SoFieldContainer#addWriteReference(ef4b98cc8eef533a).(out); |
| 448 | |
| 449 | // If this is the first reference (i.e., we don't now have |
| 450 | // multiple references), also count all appropriate children |
| 451 | if (! hasMultipleWriteRefscxx . . $ SoBase#hasMultipleWriteRefs(455f465bc33b4cdf).()) { |
| 452 | for (int i = 0; i <= lastChild; i++) { |
| 453 | action->pushCurPathcxx . . $ SoAction#pushCurPath(d4f767463ce0a6b3).(i); |
| 454 | action->traversecxx . . $ SoAction#traverse(da6c7544ccee32bd).(getChildcxx . . $ SoGroup#getChild(fd675789997d09c2).(i)); |
| 455 | action->popCurPathcxx . . $ SoAction#popCurPath(bd6e9aa4a69af45e).(pc); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // In writing phase, we have to do some more work |
| 461 | else if (! writeHeadercxx . . $ SoBase#writeHeader(9b3bdbd0ec77c6f4).(out, TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!, FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!)) { |
| 462 | |
| 463 | // Write fields |
| 464 | const SoFieldDatacxx . . $ SoFieldData# *fieldData = getFieldDatacxx . . $ SoSwitch#getFieldData(56e90abbfb485471).(); |
| 465 | fieldData->writecxx . . $ SoFieldData#write(3c9bfc134c31f96e).(out, this); |
| 466 | |
| 467 | // We KNOW that all children should be written, so don't |
| 468 | // bother calling shouldWrite() |
| 469 | |
| 470 | // If writing binary format, write out number of children |
| 471 | // that are going to be written |
| 472 | if (out->isBinarycxx . . $ SoOutput#isBinary(455f465bc33b4cdf).()) |
| 473 | out->writecxx . . $ SoOutput#write(d4f767463ce0a6b3).(getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).()); |
| 474 | |
| 475 | for (int i = 0; i <= lastChild; i++) { |
| 476 | action->pushCurPathcxx . . $ SoAction#pushCurPath(d4f767463ce0a6b3).(i); |
| 477 | action->traversecxx . . $ SoAction#traverse(da6c7544ccee32bd).(getChildcxx . . $ SoGroup#getChild(fd675789997d09c2).(i)); |
| 478 | action->popCurPathcxx . . $ SoAction#popCurPath(bd6e9aa4a69af45e).(pc); |
| 479 | } |
| 480 | |
| 481 | // Write post-children stuff |
| 482 | writeFootercxx . . $ SoBase#writeFooter(58762e0f79576b7c).(out); |
| 483 | } |
| 484 | } |