| 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.3 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoV1NodekitCatalog |
| 47 |
| |
| 48 |
| Author(s) : Paul Isaacs and Thad Beier |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
|
| 54 |
#include <machine.h> |
| 55 |
#include <Inventor/misc/upgraders/SoV1NodekitCatalog.h> |
| 56 |
#include <Inventor/SoDB.h> |
| 57 |
#include <Inventor/misc/upgraders/SoV1BaseKit.h> |
| 58 |
#include <Inventor/nodes/SoSeparator.h> |
| 59 |
#include <Inventor/nodes/SoSwitch.h> |
| 60 |
#include <Inventor/errors/SoDebugError.h> |
| 61 |
|
| 62 |
// Static variables for the nodekit catalog class... |
| 63 |
|
| 64 |
const SbName *SoV1NodekitCatalog::emptyName = NULL; |
| 65 |
const SbPList *SoV1NodekitCatalog::emptyList = NULL; |
| 66 |
SoType *SoV1NodekitCatalog::badType = NULL; |
| 67 |
|
| 68 |
//////////////////////////////////////////////////////////////////////// |
| 69 |
// |
| 70 |
// Class: |
| 71 |
// SoV1NodekitCatalogEntry |
| 72 |
// |
| 73 |
//////////////////////////////////////////////////////////////////////// |
| 74 |
|
| 75 |
//////////////////////////////////////////////////////////////////////// |
| 76 |
// |
| 77 |
// Description: |
| 78 |
// Constructor |
| 79 |
// |
| 80 |
// Use: internal |
| 81 |
|
| 82 |
SoV1NodekitCatalogEntry::SoV1NodekitCatalogEntry( const SbName &theName, |
| 83 |
const SoType &theType , const SoType &theDefaultType, |
| 84 |
const SbName &theParentName, |
| 85 |
const SbName &theRightSiblingName, SbBool theListPart, |
| 86 |
const SbPList &theListItemTypes, |
| 87 |
SbBool thePublicPart ) |
| 88 |
// |
| 89 |
//////////////////////////////////////////////////////////////////////// |
| 90 |
{ |
| 91 |
name = theName; |
| 92 |
type = theType; |
| 93 |
defaultType = theDefaultType; |
| 94 |
leafPart = TRUE; // everything is a leaf 'til given a child |
| 95 |
parentName = theParentName; |
| 96 |
rightSiblingName = theRightSiblingName; |
| 97 |
listPart = theListPart; |
| 98 |
listItemTypes.copy( theListItemTypes ); |
| 99 |
publicPart = thePublicPart; |
| 100 |
} |
| 101 |
|
| 102 |
//////////////////////////////////////////////////////////////////////// |
| 103 |
// |
| 104 |
// Description: |
| 105 |
// Print contents for debugging purposes |
| 106 |
// |
| 107 |
// Use: internal |
| 108 |
|
| 109 |
void |
| 110 |
SoV1NodekitCatalogEntry::printCheck() const |
| 111 |
// |
| 112 |
//////////////////////////////////////////////////////////////////////// |
| 113 |
{ |
| 114 |
fprintf( stdout," name = %s, type = %s, defaultType = %s\n", |
| 115 |
name.getString(), type.getName().getString(), defaultType.getName().getString() ); |
| 116 |
fprintf( stdout," parentName = %s\n", parentName.getString() ); |
| 117 |
fprintf( stdout," sibling = %s, listPart = %d\n", |
| 118 |
rightSiblingName.getString(), listPart ); |
| 119 |
if ( listPart ) { |
| 120 |
fprintf( stdout, "listItemTypes = " ); |
| 121 |
for ( int i = 0; i < listItemTypes.getLength(); i++ ) { |
| 122 |
fprintf( stdout," %s ", |
| 123 |
((SoType *) listItemTypes[i])->getName().getString() ); |
| 124 |
} |
| 125 |
fprintf( stdout, "\n" ); |
| 126 |
} |
| 127 |
fprintf( stdout," publicPart = %d\n", publicPart ); |
| 128 |
} |
| 129 |
|
| 130 |
//////////////////////////////////////////////////////////////////////// |
| 131 |
// |
| 132 |
// Description: |
| 133 |
// Creates a new copy of this catalog |
| 134 |
// |
| 135 |
// Use: private |
| 136 |
|
| 137 |
SoV1NodekitCatalogEntry * |
| 138 |
SoV1NodekitCatalogEntry::clone() const |
| 139 |
// |
| 140 |
//////////////////////////////////////////////////////////////////////// |
| 141 |
{ |
| 142 |
// make a clone with the current type and defaultType... |
| 143 |
return clone( type, defaultType ); |
| 144 |
} |
| 145 |
|
| 146 |
//////////////////////////////////////////////////////////////////////// |
| 147 |
// |
| 148 |
// Description: |
| 149 |
// Creates a new copy of this catalog, but sets the type to newType |
| 150 |
// |
| 151 |
// Use: private |
| 152 |
|
| 153 |
SoV1NodekitCatalogEntry * |
| 154 |
SoV1NodekitCatalogEntry::clone( const SoType &newType, |
| 155 |
const SoType &newDefaultType ) const |
| 156 |
// |
| 157 |
//////////////////////////////////////////////////////////////////////// |
| 158 |
{ |
| 159 |
SoV1NodekitCatalogEntry *theClone; |
| 160 |
|
| 161 |
theClone = new SoV1NodekitCatalogEntry( name, newType, newDefaultType, |
| 162 |
parentName, rightSiblingName, listPart, listItemTypes, publicPart ); |
| 163 |
theClone->leafPart = leafPart; |
| 164 |
|
| 165 |
return theClone; |
| 166 |
} |
| 167 |
|
| 168 |
//////////////////////////////////////////////////////////////////////// |
| 169 |
// |
| 170 |
// Description: |
| 171 |
// Creates a new copy of this catalog |
| 172 |
// |
| 173 |
// Use: public |
| 174 |
|
| 175 |
void |
| 176 |
SoV1NodekitCatalogEntry::addListItemType( const SoType &typeToAdd ) |
| 177 |
// |
| 178 |
//////////////////////////////////////////////////////////////////////// |
| 179 |
{ |
| 180 |
SoType *typePtr = new SoType(); |
| 181 |
*typePtr = typeToAdd; |
| 182 |
listItemTypes.append( typePtr ); |
| 183 |
} |
| 184 |
|
| 185 |
//////////////////////////////////////////////////////////////////////// |
| 186 |
// |
| 187 |
// Description: |
| 188 |
// Looks for the given part. |
| 189 |
// Checks this part, then recursively checks all entries in the |
| 190 |
// catalog of this part (it gets its own catalog by looking |
| 191 |
// at the catalog for the 'dummy' for this type, which is accessed |
| 192 |
// through: type.createInstance()->getNodekitCatalog() |
| 193 |
// or, if type is an abstract type, |
| 194 |
// uses defaultType.createInstance()->getNodekitCatalog() |
| 195 |
// |
| 196 |
// Use: public |
| 197 |
|
| 198 |
SbBool |
| 199 |
SoV1NodekitCatalogEntry::recursiveSearch( const SbName &nameToFind, |
| 200 |
SbPList *typesChecked ) const |
| 201 |
// |
| 202 |
//////////////////////////////////////////////////////////////////////// |
| 203 |
{ |
| 204 |
const SoV1NodekitCatalog *subCat; |
| 205 |
|
| 206 |
// is this the part of my dreams? |
| 207 |
if ( name == nameToFind ) |
| 208 |
return TRUE; |
| 209 |
|
| 210 |
// make sure the part isn't a list |
| 211 |
if ( listPart == TRUE ) |
| 212 |
return FALSE; |
| 213 |
// make sure the part is subclassed off of SoV1BaseKit |
| 214 |
if ( !type.isDerivedFrom( SoV1BaseKit::getClassTypeId() )) |
| 215 |
return FALSE; |
| 216 |
|
| 217 |
// avoid an infinite search loop by seeing if this type has already been |
| 218 |
// checked... |
| 219 |
if ( typesChecked->find( (void *) type.getName().getString()) != -1 ) |
| 220 |
return FALSE; |
| 221 |
|
| 222 |
// if it's still ok, then search within the catalog of this part |
| 223 |
// first check each name: |
| 224 |
const SoV1BaseKit *inst = (const SoV1BaseKit *) type.createInstance(); |
| 225 |
if ( inst == NULL ) |
| 226 |
inst = (const SoV1BaseKit *) defaultType.createInstance(); |
| 227 |
#ifdef DEBUG |
| 228 |
if ( inst == NULL ) { |
| 229 |
SoDebugError::post("SoV1NodekitCatalogEntry::recursiveSearch", |
| 230 |
"part type and defaultType are both abstract classes"); |
| 231 |
abort(); |
| 232 |
} |
| 233 |
#endif |
| 234 |
|
| 235 |
subCat = inst->getNodekitCatalog(); |
| 236 |
int i; |
| 237 |
for( i = 0; i < subCat->getNumEntries(); i++ ) { |
| 238 |
if ( subCat->getName( i ) == nameToFind ) |
| 239 |
return TRUE; |
| 240 |
} |
| 241 |
// at these point, we've checked all the names in this class, so |
| 242 |
// we can add it to typesChecked |
| 243 |
typesChecked->append( (void *) type.getName().getString() ); |
| 244 |
|
| 245 |
// then, recursively check each part |
| 246 |
for( i = 0; i < subCat->getNumEntries(); i++ ) { |
| 247 |
if ( subCat->recursiveSearch( i, nameToFind, typesChecked ) ) |
| 248 |
return TRUE; |
| 249 |
} |
| 250 |
|
| 251 |
return FALSE; // couldn't find it ANYwhere! |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
//////////////////////////////////////////////////////////////////////// |
| 256 |
// |
| 257 |
// Class: |
| 258 |
// SoV1NodekitCatalog |
| 259 |
// |
| 260 |
//////////////////////////////////////////////////////////////////////// |
| 261 |
|
| 262 |
|
| 263 |
//////////////////////////////////////////////////////////////////////// |
| 264 |
// |
| 265 |
// Description: |
| 266 |
// Constructor |
| 267 |
// |
| 268 |
// Use: internal |
| 269 |
|
| 270 |
SoV1NodekitCatalog::SoV1NodekitCatalog() |
| 271 |
// |
| 272 |
//////////////////////////////////////////////////////////////////////// |
| 273 |
{ |
| 274 |
numEntries = 0; |
| 275 |
entries = NULL; |
| 276 |
} |
| 277 |
|
| 278 |
//////////////////////////////////////////////////////////////////////// |
| 279 |
// |
| 280 |
// Description: |
| 281 |
// Destructor |
| 282 |
// |
| 283 |
// Use: internal |
| 284 |
|
| 285 |
SoV1NodekitCatalog::~SoV1NodekitCatalog() |
| 286 |
// |
| 287 |
//////////////////////////////////////////////////////////////////////// |
| 288 |
{ |
| 289 |
// delete all the members of the entries array |
| 290 |
for ( int i = 0; i < numEntries; i++ ) |
| 291 |
delete entries[i]; |
| 292 |
|
| 293 |
// delete the entries array itself |
| 294 |
if (entries != NULL) |
| 295 |
delete entries; |
| 296 |
|
| 297 |
} |
| 298 |
|
| 299 |
//////////////////////////////////////////////////////////////////////// |
| 300 |
// |
| 301 |
// Description: |
| 302 |
// Prints out contents of the catalog for debuggin purposes |
| 303 |
// |
| 304 |
// Use: internal |
| 305 |
|
| 306 |
void |
| 307 |
SoV1NodekitCatalog::printCheck() const |
| 308 |
// |
| 309 |
//////////////////////////////////////////////////////////////////////// |
| 310 |
{ |
| 311 |
fprintf(stdout,"catalog printout: number of entries = %d\n", numEntries ); |
| 312 |
for( int i = 0; i < numEntries; i++ ) { |
| 313 |
fprintf(stdout,"#%d\n", i ); |
| 314 |
entries[i]->printCheck(); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
//////////////////////////////////////////////////////////////////////// |
| 319 |
// |
| 320 |
// Description: |
| 321 |
// For finding the partNumber of an entry given its reference name. |
| 322 |
// |
| 323 |
// Use: internal |
| 324 |
|
| 325 |
int |
| 326 |
SoV1NodekitCatalog::getPartNumber( const SbName &theName ) const |
| 327 |
// |
| 328 |
//////////////////////////////////////////////////////////////////////// |
| 329 |
{ |
| 330 |
void *castPNum; |
| 331 |
|
| 332 |
if ( partNameDict.find( (uintptr_t) theName.getString(), castPNum ) ) |
| 333 |
return ( (intptr_t) castPNum ); |
| 334 |
else |
| 335 |
return SO_V1_CATALOG_NAME_NOT_FOUND; |
| 336 |
} |
| 337 |
|
| 338 |
//////////////////////////////////////////////////////////////////////// |
| 339 |
// |
| 340 |
// Description: |
| 341 |
// For finding the name of an entry given its partNumber. |
| 342 |
// |
| 343 |
// Use: internal |
| 344 |
|
| 345 |
const SbName & |
| 346 |
SoV1NodekitCatalog::getName( int thePartNumber ) const |
| 347 |
// |
| 348 |
//////////////////////////////////////////////////////////////////////// |
| 349 |
{ |
| 350 |
// return the name of the entry, if you can find it. |
| 351 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 352 |
return entries[thePartNumber]->getName(); |
| 353 |
else |
| 354 |
return *emptyName; |
| 355 |
} |
| 356 |
|
| 357 |
//////////////////////////////////////////////////////////////////////// |
| 358 |
// |
| 359 |
// Description: |
| 360 |
// For finding the type of an entry. |
| 361 |
// |
| 362 |
// Use: internal |
| 363 |
|
| 364 |
const SoType & |
| 365 |
SoV1NodekitCatalog::getType( int thePartNumber ) const |
| 366 |
// |
| 367 |
//////////////////////////////////////////////////////////////////////// |
| 368 |
{ |
| 369 |
// return the type of the entry, if you can find it. |
| 370 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 371 |
return entries[thePartNumber]->getType(); |
| 372 |
else |
| 373 |
return *badType; |
| 374 |
} |
| 375 |
|
| 376 |
//////////////////////////////////////////////////////////////////////// |
| 377 |
// |
| 378 |
// Description: |
| 379 |
// For finding the type of an entry. |
| 380 |
// |
| 381 |
// Use: internal |
| 382 |
|
| 383 |
const SoType & |
| 384 |
SoV1NodekitCatalog::getType( const SbName &theName ) const |
| 385 |
// |
| 386 |
//////////////////////////////////////////////////////////////////////// |
| 387 |
{ |
| 388 |
return( getType( getPartNumber( theName ) )); |
| 389 |
} |
| 390 |
|
| 391 |
//////////////////////////////////////////////////////////////////////// |
| 392 |
// |
| 393 |
// Description: |
| 394 |
// For finding the default type of an entry. |
| 395 |
// |
| 396 |
// Use: internal |
| 397 |
|
| 398 |
const SoType & |
| 399 |
SoV1NodekitCatalog::getDefaultType( int thePartNumber ) const |
| 400 |
// |
| 401 |
//////////////////////////////////////////////////////////////////////// |
| 402 |
{ |
| 403 |
// return the defaultType of the entry, if you can find it. |
| 404 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 405 |
return entries[thePartNumber]->getDefaultType(); |
| 406 |
else |
| 407 |
return *badType; |
| 408 |
} |
| 409 |
|
| 410 |
//////////////////////////////////////////////////////////////////////// |
| 411 |
// |
| 412 |
// Description: |
| 413 |
// For finding the defaultType of an entry. |
| 414 |
// |
| 415 |
// Use: internal |
| 416 |
|
| 417 |
const SoType & |
| 418 |
SoV1NodekitCatalog::getDefaultType( const SbName &theName ) const |
| 419 |
// |
| 420 |
//////////////////////////////////////////////////////////////////////// |
| 421 |
{ |
| 422 |
return( getDefaultType( getPartNumber( theName ) )); |
| 423 |
} |
| 424 |
|
| 425 |
//////////////////////////////////////////////////////////////////////// |
| 426 |
// |
| 427 |
// Description: |
| 428 |
// For finding 'leafPart' of an entry. |
| 429 |
// |
| 430 |
// Use: internal |
| 431 |
|
| 432 |
SbBool |
| 433 |
SoV1NodekitCatalog::isLeaf( int thePartNumber ) const |
| 434 |
// |
| 435 |
//////////////////////////////////////////////////////////////////////// |
| 436 |
{ |
| 437 |
// return the type of the entry, if you can find it. |
| 438 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 439 |
return entries[thePartNumber]->isLeaf(); |
| 440 |
else |
| 441 |
return TRUE; |
| 442 |
} |
| 443 |
|
| 444 |
//////////////////////////////////////////////////////////////////////// |
| 445 |
// |
| 446 |
// Description: |
| 447 |
// For finding 'leafPart' of an entry. |
| 448 |
// |
| 449 |
// Use: internal |
| 450 |
|
| 451 |
SbBool |
| 452 |
SoV1NodekitCatalog::isLeaf( const SbName &theName ) const |
| 453 |
// |
| 454 |
//////////////////////////////////////////////////////////////////////// |
| 455 |
{ |
| 456 |
return( isLeaf( getPartNumber( theName ) )); |
| 457 |
} |
| 458 |
|
| 459 |
//////////////////////////////////////////////////////////////////////// |
| 460 |
// |
| 461 |
// Description: |
| 462 |
// For finding the name of the parent of an entry. |
| 463 |
// |
| 464 |
// Use: internal |
| 465 |
|
| 466 |
const SbName & |
| 467 |
SoV1NodekitCatalog::getParentName( int thePartNumber ) const |
| 468 |
// |
| 469 |
//////////////////////////////////////////////////////////////////////// |
| 470 |
{ |
| 471 |
// return the entry, if you can find it. |
| 472 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 473 |
return entries[thePartNumber]->getParentName(); |
| 474 |
else |
| 475 |
return *emptyName; |
| 476 |
} |
| 477 |
|
| 478 |
//////////////////////////////////////////////////////////////////////// |
| 479 |
// |
| 480 |
// Description: |
| 481 |
// For finding the name of the parent of an entry. |
| 482 |
// |
| 483 |
// Use: internal |
| 484 |
|
| 485 |
const SbName & |
| 486 |
SoV1NodekitCatalog::getParentName( const SbName &theName ) const |
| 487 |
// |
| 488 |
//////////////////////////////////////////////////////////////////////// |
| 489 |
{ |
| 490 |
return( getParentName( getPartNumber( theName ) )); |
| 491 |
} |
| 492 |
|
| 493 |
//////////////////////////////////////////////////////////////////////// |
| 494 |
// |
| 495 |
// Description: |
| 496 |
// For finding the name of the parent of an entry. |
| 497 |
// |
| 498 |
// Use: internal |
| 499 |
|
| 500 |
int |
| 501 |
SoV1NodekitCatalog::getParentPartNumber( int thePartNumber ) const |
| 502 |
// |
| 503 |
//////////////////////////////////////////////////////////////////////// |
| 504 |
{ |
| 505 |
const SbName pName = getParentName( thePartNumber ); |
| 506 |
return( getPartNumber( pName ) ); |
| 507 |
} |
| 508 |
|
| 509 |
//////////////////////////////////////////////////////////////////////// |
| 510 |
// |
| 511 |
// Description: |
| 512 |
// For finding the name of the parent of an entry. |
| 513 |
// |
| 514 |
// Use: internal |
| 515 |
|
| 516 |
int |
| 517 |
SoV1NodekitCatalog::getParentPartNumber( const SbName &theName ) const |
| 518 |
// |
| 519 |
//////////////////////////////////////////////////////////////////////// |
| 520 |
{ |
| 521 |
const SbName pName = getParentName( theName ); |
| 522 |
return( getPartNumber( pName ) ); |
| 523 |
} |
| 524 |
|
| 525 |
//////////////////////////////////////////////////////////////////////// |
| 526 |
// |
| 527 |
// Description: |
| 528 |
// For finding the name of the right sibling of an entry. |
| 529 |
// |
| 530 |
// Use: internal |
| 531 |
|
| 532 |
const SbName & |
| 533 |
SoV1NodekitCatalog::getRightSiblingName( int thePartNumber ) const |
| 534 |
// |
| 535 |
//////////////////////////////////////////////////////////////////////// |
| 536 |
{ |
| 537 |
// return the entry, if you can find it. |
| 538 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 539 |
return entries[thePartNumber]->getRightSiblingName(); |
| 540 |
else |
| 541 |
return *emptyName; |
| 542 |
} |
| 543 |
|
| 544 |
//////////////////////////////////////////////////////////////////////// |
| 545 |
// |
| 546 |
// Description: |
| 547 |
// For finding the name of the RightSiblingName of an entry. |
| 548 |
// |
| 549 |
// Use: internal |
| 550 |
|
| 551 |
const SbName & |
| 552 |
SoV1NodekitCatalog::getRightSiblingName( const SbName &theName ) const |
| 553 |
// |
| 554 |
//////////////////////////////////////////////////////////////////////// |
| 555 |
{ |
| 556 |
return( getRightSiblingName( getPartNumber( theName ) )); |
| 557 |
} |
| 558 |
|
| 559 |
//////////////////////////////////////////////////////////////////////// |
| 560 |
// |
| 561 |
// Description: |
| 562 |
// For finding the name of the rightSibling of an entry. |
| 563 |
// |
| 564 |
// Use: internal |
| 565 |
|
| 566 |
int |
| 567 |
SoV1NodekitCatalog::getRightSiblingPartNumber( int thePartNumber ) const |
| 568 |
// |
| 569 |
//////////////////////////////////////////////////////////////////////// |
| 570 |
{ |
| 571 |
const SbName sName = getRightSiblingName( thePartNumber ); |
| 572 |
return( getPartNumber( sName ) ); |
| 573 |
} |
| 574 |
|
| 575 |
//////////////////////////////////////////////////////////////////////// |
| 576 |
// |
| 577 |
// Description: |
| 578 |
// For finding the name of the rightSibling of an entry. |
| 579 |
// |
| 580 |
// Use: internal |
| 581 |
|
| 582 |
int |
| 583 |
SoV1NodekitCatalog::getRightSiblingPartNumber( const SbName &theName ) const |
| 584 |
// |
| 585 |
//////////////////////////////////////////////////////////////////////// |
| 586 |
{ |
| 587 |
const SbName sName = getRightSiblingName( theName ); |
| 588 |
return( getPartNumber( sName ) ); |
| 589 |
} |
| 590 |
|
| 591 |
//////////////////////////////////////////////////////////////////////// |
| 592 |
// |
| 593 |
// Description: |
| 594 |
// For finding 'listPart' of an entry. |
| 595 |
// |
| 596 |
// Use: internal |
| 597 |
|
| 598 |
SbBool |
| 599 |
SoV1NodekitCatalog::isList( int thePartNumber ) const |
| 600 |
// |
| 601 |
//////////////////////////////////////////////////////////////////////// |
| 602 |
{ |
| 603 |
// return the type of the entry, if you can find it. |
| 604 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 605 |
return entries[thePartNumber]->isList(); |
| 606 |
else |
| 607 |
return FALSE; |
| 608 |
} |
| 609 |
|
| 610 |
//////////////////////////////////////////////////////////////////////// |
| 611 |
// |
| 612 |
// Description: |
| 613 |
// For finding 'listPart' of an entry. |
| 614 |
// |
| 615 |
// Use: internal |
| 616 |
|
| 617 |
SbBool |
| 618 |
SoV1NodekitCatalog::isList( const SbName &theName ) const |
| 619 |
// |
| 620 |
//////////////////////////////////////////////////////////////////////// |
| 621 |
{ |
| 622 |
return( isList( getPartNumber( theName ) )); |
| 623 |
} |
| 624 |
|
| 625 |
//////////////////////////////////////////////////////////////////////// |
| 626 |
// |
| 627 |
// Description: |
| 628 |
// For finding the list item type of an entry. |
| 629 |
// |
| 630 |
// Use: internal |
| 631 |
|
| 632 |
const SbPList & |
| 633 |
SoV1NodekitCatalog::getListItemTypes( int thePartNumber ) const |
| 634 |
// |
| 635 |
//////////////////////////////////////////////////////////////////////// |
| 636 |
{ |
| 637 |
// return the type of the entry, if you can find it. |
| 638 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 639 |
return entries[thePartNumber]->getListItemTypes(); |
| 640 |
else |
| 641 |
return ( *emptyList ); |
| 642 |
} |
| 643 |
|
| 644 |
//////////////////////////////////////////////////////////////////////// |
| 645 |
// |
| 646 |
// Description: |
| 647 |
// For finding the list item type of an entry. |
| 648 |
// |
| 649 |
// Use: internal |
| 650 |
|
| 651 |
const SbPList & |
| 652 |
SoV1NodekitCatalog::getListItemTypes( const SbName &theName ) const |
| 653 |
// |
| 654 |
//////////////////////////////////////////////////////////////////////// |
| 655 |
{ |
| 656 |
return( getListItemTypes( getPartNumber( theName ) )); |
| 657 |
} |
| 658 |
|
| 659 |
//////////////////////////////////////////////////////////////////////// |
| 660 |
// |
| 661 |
// Description: |
| 662 |
// For finding 'publicPart' of an entry. |
| 663 |
// |
| 664 |
// Use: internal |
| 665 |
|
| 666 |
SbBool |
| 667 |
SoV1NodekitCatalog::isPublic( int thePartNumber ) const |
| 668 |
// |
| 669 |
//////////////////////////////////////////////////////////////////////// |
| 670 |
{ |
| 671 |
// return whether the part is public, if you can find it. |
| 672 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 673 |
return entries[thePartNumber]->isPublic(); |
| 674 |
else |
| 675 |
return TRUE; |
| 676 |
} |
| 677 |
|
| 678 |
//////////////////////////////////////////////////////////////////////// |
| 679 |
// |
| 680 |
// Description: |
| 681 |
// For finding 'publicPart' of an entry. |
| 682 |
// |
| 683 |
// Use: internal |
| 684 |
|
| 685 |
SbBool |
| 686 |
SoV1NodekitCatalog::isPublic( const SbName &theName ) const |
| 687 |
// |
| 688 |
//////////////////////////////////////////////////////////////////////// |
| 689 |
{ |
| 690 |
return( isPublic( getPartNumber( theName ) )); |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
//////////////////////////////////////////////////////////////////////// |
| 695 |
// |
| 696 |
// Description: |
| 697 |
// For adding an allowable child-type to an entry. |
| 698 |
// This will only make a difference if the entry has listPart set to TRUE |
| 699 |
// |
| 700 |
// Use: public |
| 701 |
|
| 702 |
void |
| 703 |
SoV1NodekitCatalog::addListItemType( int thePartNumber, |
| 704 |
const SoType &typeToAdd ) |
| 705 |
// |
| 706 |
//////////////////////////////////////////////////////////////////////// |
| 707 |
{ |
| 708 |
// add typeToAdd to the entry's listItemTypes, if you can find |
| 709 |
// the entry... |
| 710 |
if ( thePartNumber >= 0 && thePartNumber < numEntries ) |
| 711 |
entries[thePartNumber]->addListItemType( typeToAdd ); |
| 712 |
} |
| 713 |
|
| 714 |
//////////////////////////////////////////////////////////////////////// |
| 715 |
// |
| 716 |
// Description: |
| 717 |
// For adding an allowable child-type to an entry. |
| 718 |
// This will only make a difference if the entry has listPart set to TRUE |
| 719 |
// |
| 720 |
// Use: public |
| 721 |
|
| 722 |
void |
| 723 |
SoV1NodekitCatalog::addListItemType( const SbName &theName, |
| 724 |
const SoType &typeToAdd ) |
| 725 |
// |
| 726 |
//////////////////////////////////////////////////////////////////////// |
| 727 |
{ |
| 728 |
addListItemType( getPartNumber( theName ), typeToAdd ); |
| 729 |
} |
| 730 |
|
| 731 |
//////////////////////////////////////////////////////////////////////// |
| 732 |
// |
| 733 |
// Description: |
| 734 |
// |
| 735 |
// For changing the type and defaultType of an entry. |
| 736 |
// The new types must be subclasses of the types already existing in the |
| 737 |
// entry. |
| 738 |
// For example, in SoV1ShapeKit, the part "shape" has type SoShape and |
| 739 |
// default type SoSphere. Any shape node is acceptable, but be default a |
| 740 |
// sphere will be built. |
| 741 |
// Well, when creating the SoV1VertexShapeKit class, a call of: |
| 742 |
// narrowTypes( "shape", SoVertexShape::getClassTypeId(), |
| 743 |
// SoFaceSet::getClassTypeId()) |
| 744 |
// might be used. This would reflect the fact that: |
| 745 |
// Only vertext shapes may be put in the "shape" part, not just any shape. |
| 746 |
// And also, by default, a faceSet will be built, not a sphere. |
| 747 |
// |
| 748 |
// Use: public |
| 749 |
|
| 750 |
void |
| 751 |
SoV1NodekitCatalog::narrowTypes( const SbName &theName, |
| 752 |
const SoType &newType, const SoType &newDefaultType ) |
| 753 |
// |
| 754 |
//////////////////////////////////////////////////////////////////////// |
| 755 |
{ |
| 756 |
int thePartNumber = getPartNumber( theName ); |
| 757 |
|
| 758 |
if ( thePartNumber < 0 || thePartNumber >= numEntries ) |
| 759 |
return; |
| 760 |
|
| 761 |
SoV1NodekitCatalogEntry *theEntry = entries[thePartNumber]; |
| 762 |
|
| 763 |
// Checks that [1] newDefaultType is not an abstract type, and |
| 764 |
// [2] newDefaultType is a subclass of newType |
| 765 |
if ( !checkNewTypes( newType, newDefaultType ) ) |
| 766 |
return; |
| 767 |
|
| 768 |
const SoType oldType = theEntry->getType(); |
| 769 |
const SoType oldDefaultType = theEntry->getDefaultType(); |
| 770 |
|
| 771 |
// Make sure that the new types is derived from the old type. |
| 772 |
// Parts in derived classes must be subclasses of the types they |
| 773 |
// belong to when cast to the parent classes. |
| 774 |
if ( !newType.isDerivedFrom( oldType ) ) { |
| 775 |
#ifdef DEBUG |
| 776 |
const char *newName = newType.getName().getString(); |
| 777 |
const char *oldName = oldType.getName().getString(); |
| 778 |
SoDebugError::post("SoV1NodekitCatalogEntry::narrowTypes", |
| 779 |
"The newType %s is not a subclass of the oldType " |
| 780 |
"%s. Cannot narrow the type from %s to %s", |
| 781 |
newName, oldName, oldName, newName); |
| 782 |
#endif |
| 783 |
return; |
| 784 |
} |
| 785 |
|
| 786 |
// passed all the tests! |
| 787 |
theEntry->setTypes( newType, newDefaultType ); |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
//////////////////////////////////////////////////////////////////////// |
| 793 |
// |
| 794 |
// Description: |
| 795 |
// Creates a new copy of this catalog |
| 796 |
// |
| 797 |
// Use: public |
| 798 |
|
| 799 |
SoV1NodekitCatalog * |
| 800 |
SoV1NodekitCatalog::clone( const SoType &typeOfThis ) const |
| 801 |
// |
| 802 |
//////////////////////////////////////////////////////////////////////// |
| 803 |
{ |
| 804 |
SoV1NodekitCatalog *theClone; |
| 805 |
|
| 806 |
theClone = new SoV1NodekitCatalog; |
| 807 |
theClone->numEntries = numEntries; |
| 808 |
if (numEntries == 0) |
| 809 |
theClone->entries = NULL; |
| 810 |
else { |
| 811 |
theClone->entries = new SoV1NodekitCatalogEntry* [numEntries]; |
| 812 |
for (int i = 0; i < numEntries; i++) { |
| 813 |
if ( entries[i]->getName() == "this" ) |
| 814 |
theClone->entries[i] = entries[i]->clone( typeOfThis, |
| 815 |
typeOfThis ); |
| 816 |
else |
| 817 |
theClone->entries[i] = entries[i]->clone(); |
| 818 |
theClone->partNameDict.enter( (unsigned long) |
| 819 |
entries[i]->getName().getString(), |
| 820 |
(void *) (unsigned long) i ); |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
return theClone; |
| 825 |
} |
| 826 |
|
| 827 |
//////////////////////////////////////////////////////////////////////// |
| 828 |
// |
| 829 |
// Description: |
| 830 |
// Used as a check when adding a new entry to a catalog. |
| 831 |
// Checks that the name is not NULL and not empty. |
| 832 |
// |
| 833 |
// Use: private |
| 834 |
|
| 835 |
SbBool |
| 836 |
SoV1NodekitCatalog::checkName( const SbName &theName ) // proposed name |
| 837 |
// |
| 838 |
//////////////////////////////////////////////////////////////////////// |
| 839 |
{ |
| 840 |
// CHECK IF IT'S NULL |
| 841 |
if ( theName.getString() == NULL ) { |
| 842 |
#ifdef DEBUG |
| 843 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkName", |
| 844 |
"given name is NULL" ); |
| 845 |
#endif |
| 846 |
return FALSE; |
| 847 |
} |
| 848 |
|
| 849 |
// CHECK IF IT'S EMPTY |
| 850 |
if ( theName == "" ) { |
| 851 |
#ifdef DEBUG |
| 852 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkName", |
| 853 |
"given name is the empty string" ); |
| 854 |
#endif |
| 855 |
return FALSE; |
| 856 |
} |
| 857 |
|
| 858 |
return TRUE; |
| 859 |
} |
| 860 |
|
| 861 |
//////////////////////////////////////////////////////////////////////// |
| 862 |
// |
| 863 |
// Description: |
| 864 |
// Used as a check when adding a new entry to a catalog. |
| 865 |
// Checks that the name is OK to use for the new entry. |
| 866 |
// |
| 867 |
// Use: private |
| 868 |
|
| 869 |
SbBool |
| 870 |
SoV1NodekitCatalog::checkNewName( const SbName &theName ) // proposed name |
| 871 |
// |
| 872 |
//////////////////////////////////////////////////////////////////////// |
| 873 |
{ |
| 874 |
if ( !checkName( theName ) ) |
| 875 |
return FALSE; |
| 876 |
|
| 877 |
// CHECK IF IT'S UNIQUE FOR THIS CATALOG |
| 878 |
if ( getPartNumber( theName ) == SO_V1_CATALOG_NAME_NOT_FOUND ) { |
| 879 |
return TRUE; |
| 880 |
} |
| 881 |
else { |
| 882 |
#ifdef DEBUG |
| 883 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkNewName", |
| 884 |
"the name %s is already in this catalog", |
| 885 |
theName.getString() ); |
| 886 |
#endif |
| 887 |
return FALSE; |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
//////////////////////////////////////////////////////////////////////// |
| 892 |
// |
| 893 |
// Description: |
| 894 |
// Used as a check when adding a new entry to a catalog. |
| 895 |
// Checks that the type is not for an abstract node type. |
| 896 |
// |
| 897 |
// Use: private |
| 898 |
|
| 899 |
SbBool |
| 900 |
SoV1NodekitCatalog::checkNewTypes( const SoType &theType, // proposed type |
| 901 |
const SoType &theDefaultType ) // and default |
| 902 |
// |
| 903 |
//////////////////////////////////////////////////////////////////////// |
| 904 |
{ |
| 905 |
if ( !theDefaultType.canCreateInstance()) { |
| 906 |
#ifdef DEBUG |
| 907 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkNewTypes", |
| 908 |
" the defaultType %s is an abstract class, and cannot be part of a nodekits structure", theDefaultType.getName().getString() ); |
| 909 |
#endif |
| 910 |
return FALSE; |
| 911 |
} |
| 912 |
|
| 913 |
if ( !theDefaultType.isDerivedFrom( theType ) ) { |
| 914 |
#ifdef DEBUG |
| 915 |
const char *defName = theDefaultType.getName().getString(); |
| 916 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkNewTypes", |
| 917 |
"the defaultType %s is not a subclass of the type " |
| 918 |
"%s. It can not be part of a nodekits structure", |
| 919 |
defName, theType.getName().getString() ); |
| 920 |
#endif |
| 921 |
return FALSE; |
| 922 |
} |
| 923 |
else |
| 924 |
return TRUE; |
| 925 |
} |
| 926 |
|
| 927 |
//////////////////////////////////////////////////////////////////////// |
| 928 |
// |
| 929 |
// Description: |
| 930 |
// Used as a check when adding a new entry to a catalog. |
| 931 |
// Checks that the name is OK to use the parent for a new entry. |
| 932 |
// |
| 933 |
// Use: private |
| 934 |
|
| 935 |
SbBool |
| 936 |
SoV1NodekitCatalog::checkAndGetParent( |
| 937 |
const SbName &theName, // the child's name |
| 938 |
const SbName &theParentName, // proposed parent name |
| 939 |
SoV1NodekitCatalogEntry *& parentEntry ) // corresponding entry filled |
| 940 |
// in this method |
| 941 |
// |
| 942 |
//////////////////////////////////////////////////////////////////////// |
| 943 |
{ |
| 944 |
// CHECK FOR "THIS" |
| 945 |
// The string "this" means that a node is to be the nodekit node itself |
| 946 |
// In this case, return NULL as the parentEntry, and a status of TRUE! |
| 947 |
if ( theName == "this" ) { |
| 948 |
// 'this' has no parent |
| 949 |
parentEntry = NULL; |
| 950 |
return TRUE; |
| 951 |
} |
| 952 |
else { |
| 953 |
// only 'this' can have no parent |
| 954 |
if ( !checkName( theParentName ) ) |
| 955 |
return FALSE; |
| 956 |
} |
| 957 |
|
| 958 |
// CHECK THAT THE PARENT IS IN THE CATALOG |
| 959 |
int parentPartNumber = getPartNumber( theParentName ); |
| 960 |
if ( parentPartNumber == SO_V1_CATALOG_NAME_NOT_FOUND ) { |
| 961 |
#ifdef DEBUG |
| 962 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkAndGetParent", |
| 963 |
"requested parent >> %s << is not in this catalog", |
| 964 |
theParentName.getString() ); |
| 965 |
#endif |
| 966 |
return FALSE; |
| 967 |
} |
| 968 |
parentEntry = entries[ parentPartNumber ]; |
| 969 |
|
| 970 |
// CHECK THE NODE TYPE OF THE PARENT |
| 971 |
// [1] it must be a subclass of SoGroup, or you can't add children to it. |
| 972 |
if ( !parentEntry->getType().isDerivedFrom( SoGroup::getClassTypeId() ) ) { |
| 973 |
#ifdef DEBUG |
| 974 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkAndGetParent", |
| 975 |
"requested parent >> %s << is a node that is not subclassed from SoGroup, so it can't have children", |
| 976 |
theParentName.getString() ); |
| 977 |
#endif |
| 978 |
return FALSE; |
| 979 |
} |
| 980 |
// [2] Unless it is 'this', the parent can NOT be subclass of SoV1BaseKit. |
| 981 |
// This is because you can only add child nodes to an nodekit through |
| 982 |
// its own class's nodekitCatalog |
| 983 |
if ( theParentName != "this" && |
| 984 |
parentEntry->getType().isDerivedFrom( SoV1BaseKit::getClassTypeId()) ) { |
| 985 |
#ifdef DEBUG |
| 986 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkAndGetParent", |
| 987 |
" requested parent >> %s << is a node that is subclassed from SoV1BaseKit, so it can't children except through its own class's nodekitCatalog", |
| 988 |
theParentName.getString()); |
| 989 |
#endif |
| 990 |
return FALSE; |
| 991 |
} |
| 992 |
|
| 993 |
// MAKE SURE THAT THE NODE HAS NOT BEEN DESIGNATED AS A LIST |
| 994 |
if ( parentEntry->isList() == TRUE ) { |
| 995 |
#ifdef DEBUG |
| 996 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkAndGetParent", |
| 997 |
"Requested parent >> %s << is a node that has been designated as a list. It can not have explicit children in the catalog, although nodes can be added to the list for a given instance by using the special list editting methods on the nodekit node.", theParentName.getString() ); |
| 998 |
#endif |
| 999 |
return FALSE; |
| 1000 |
} |
| 1001 |
|
| 1002 |
return TRUE; |
| 1003 |
} |
| 1004 |
|
| 1005 |
//////////////////////////////////////////////////////////////////////// |
| 1006 |
// |
| 1007 |
// Description: |
| 1008 |
// Used as a check when adding a new entry to a catalog. |
| 1009 |
// Finds the left and right siblings for the new entry. |
| 1010 |
// Also, checks that the right sibling exists in the catalog (unless |
| 1011 |
// the name is "", in which case the new entry is to be the rightmost child |
| 1012 |
// |
| 1013 |
// Use: private |
| 1014 |
|
| 1015 |
SbBool |
| 1016 |
SoV1NodekitCatalog::checkAndGetSiblings( |
| 1017 |
const SbName &theParentName, // parent name |
| 1018 |
const SbName &theRightSiblingName, // proposed sibling name |
| 1019 |
SoV1NodekitCatalogEntry *& leftEntry, // new left (to be filled in) |
| 1020 |
SoV1NodekitCatalogEntry *& rightEntry ) // new right (to be filled ) |
| 1021 |
// |
| 1022 |
//////////////////////////////////////////////////////////////////////// |
| 1023 |
{ |
| 1024 |
leftEntry = NULL; |
| 1025 |
rightEntry = NULL; |
| 1026 |
|
| 1027 |
for ( int i = 0; i < numEntries; i++ ) { |
| 1028 |
// is it left? |
| 1029 |
if ( entries[i]->getParentName() == theParentName && |
| 1030 |
entries[i]->getRightSiblingName() == theRightSiblingName ) |
| 1031 |
leftEntry = entries[i]; |
| 1032 |
// is it right? |
| 1033 |
else if ( entries[i]->getParentName() == theParentName && |
| 1034 |
theRightSiblingName == entries[i]->getName() ) |
| 1035 |
rightEntry = entries[i]; |
| 1036 |
} |
| 1037 |
if ( ( rightEntry == NULL ) && ( theRightSiblingName != "" ) ) { |
| 1038 |
#ifdef DEBUG |
| 1039 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkAndGetSiblings", |
| 1040 |
" Requested right sibling >> %s << can not be found in the nodekitCatalog", theRightSiblingName.getString() ); |
| 1041 |
#endif |
| 1042 |
return FALSE; |
| 1043 |
} |
| 1044 |
|
| 1045 |
return TRUE; |
| 1046 |
} |
| 1047 |
|
| 1048 |
//////////////////////////////////////////////////////////////////////// |
| 1049 |
// |
| 1050 |
// Description: |
| 1051 |
// Used as a check when adding a new entry to a catalog. |
| 1052 |
// Called if the new node is to be a list of other nodes. |
| 1053 |
// Checks that the given type is OK as a list. |
| 1054 |
// |
| 1055 |
// Use: private |
| 1056 |
|
| 1057 |
SbBool |
| 1058 |
SoV1NodekitCatalog::checkCanTypesBeList( const SoType &theType, |
| 1059 |
const SoType &theDefaultType ) |
| 1060 |
// |
| 1061 |
//////////////////////////////////////////////////////////////////////// |
| 1062 |
{ |
| 1063 |
// CHECK IF IT'S A GROUP OR SEPARATOR |
| 1064 |
if ( !(theType == SoGroup::getClassTypeId() || |
| 1065 |
theType == SoSeparator::getClassTypeId() || |
| 1066 |
theType == SoSwitch::getClassTypeId() )) { |
| 1067 |
#ifdef DEBUG |
| 1068 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkCanTypesBeList", |
| 1069 |
" requested node type can not be a list since it is neither an SoGroup, an SoSeparator, or an SoSwitch"); |
| 1070 |
#endif |
| 1071 |
return FALSE; |
| 1072 |
} |
| 1073 |
if ( !(theDefaultType == SoGroup::getClassTypeId() || |
| 1074 |
theDefaultType == SoSeparator::getClassTypeId() || |
| 1075 |
theDefaultType == SoSwitch::getClassTypeId() )) { |
| 1076 |
#ifdef DEBUG |
| 1077 |
SoDebugError::post("SoV1NodekitCatalogEntry::checkCanTypesBeList", |
| 1078 |
" requested node type can not be a list since it is neither an SoGroup, an SoSeparator, or an SoSwitch"); |
| 1079 |
#endif |
| 1080 |
return FALSE; |
| 1081 |
} |
| 1082 |
return TRUE; |
| 1083 |
} |
| 1084 |
|
| 1085 |
//////////////////////////////////////////////////////////////////////// |
| 1086 |
// |
| 1087 |
// Description: |
| 1088 |
// For adding a new entry into the nodekitCatalog |
| 1089 |
// |
| 1090 |
// Use: internal |
| 1091 |
|
| 1092 |
SbBool |
| 1093 |
SoV1NodekitCatalog::addEntry( const SbName &theName, |
| 1094 |
const SoType &theType, |
| 1095 |
const SoType &theDefaultType, |
| 1096 |
const SbName &theParentName, |
| 1097 |
const SbName &theRightSiblingName, |
| 1098 |
SbBool theListPart, |
| 1099 |
const SoType &theListItemType, |
| 1100 |
SbBool thePublicPart ) |
| 1101 |
// |
| 1102 |
//////////////////////////////////////////////////////////////////////// |
| 1103 |
{ |
| 1104 |
SoV1NodekitCatalogEntry *parentEntry, *rightEntry, *leftEntry; |
| 1105 |
SoV1NodekitCatalogEntry *newEntry; |
| 1106 |
SoV1NodekitCatalogEntry **newArray; |
| 1107 |
|
| 1108 |
// CHECK IF THE NEW ENTRY IS OK |
| 1109 |
|
| 1110 |
if ( !checkNewName( theName ) ) |
| 1111 |
return FALSE; |
| 1112 |
|
| 1113 |
if ( !checkNewTypes( theType, theDefaultType ) ) { |
| 1114 |
#ifdef DEBUG |
| 1115 |
SoDebugError::post("SoV1NodekitCatalogEntry::addEntry", |
| 1116 |
"error creating catalog entry %s", theName.getString()); |
| 1117 |
#endif |
| 1118 |
return FALSE; |
| 1119 |
} |
| 1120 |
|
| 1121 |
if ( !checkAndGetParent( theName, theParentName, parentEntry ) ) |
| 1122 |
return FALSE; |
| 1123 |
|
| 1124 |
if ( !checkAndGetSiblings( theParentName, theRightSiblingName, |
| 1125 |
leftEntry, rightEntry ) ) |
| 1126 |
return FALSE; |
| 1127 |
|
| 1128 |
if ( theListPart && !checkCanTypesBeList( theType, theDefaultType ) ) |
| 1129 |
return FALSE; |
| 1130 |
|
| 1131 |
// IF ALL TESTS WERE PASSED... |
| 1132 |
|
| 1133 |
// expand the list by one slot |
| 1134 |
newArray = new SoV1NodekitCatalogEntry* [numEntries + 1]; |
| 1135 |
if ( entries != NULL ) { |
| 1136 |
for (int i = 0; i < numEntries; i++ ) |
| 1137 |
newArray[i] = entries[i]; |
| 1138 |
delete entries; |
| 1139 |
} |
| 1140 |
entries = newArray; |
| 1141 |
numEntries++; |
| 1142 |
|
| 1143 |
// make a list containing only the given list item type. |
| 1144 |
SbPList *listItemTypeList = new SbPList( 0 ); |
| 1145 |
SoType *typePtr = new SoType; |
| 1146 |
*typePtr = theListItemType; |
| 1147 |
listItemTypeList->append( (void *) typePtr ); |
| 1148 |
|
| 1149 |
// create the new entry |
| 1150 |
newEntry = new SoV1NodekitCatalogEntry( theName, theType, theDefaultType, |
| 1151 |
theParentName, theRightSiblingName,theListPart,*listItemTypeList, |
| 1152 |
thePublicPart); |
| 1153 |
// enter the new entry in the array |
| 1154 |
entries[numEntries - 1] = newEntry; |
| 1155 |
|
| 1156 |
// add the new name to the quick-reference part name dictionary |
| 1157 |
partNameDict.enter( (unsigned long) theName.getString(), |
| 1158 |
(void *) (unsigned long) (numEntries - 1)); |
| 1159 |
|
| 1160 |
// parent is no longer a leaf node in the nodekit structure |
| 1161 |
if ( parentEntry != NULL ) |
| 1162 |
parentEntry->setLeaf( FALSE ); |
| 1163 |
|
| 1164 |
// stitch up sibling names. |
| 1165 |
if ( leftEntry != NULL ) |
| 1166 |
leftEntry->setRightSiblingName( theName ); |
| 1167 |
return TRUE; |
| 1168 |
} |
| 1169 |
|
| 1170 |
//////////////////////////////////////////////////////////////////////// |
| 1171 |
// |
| 1172 |
// Description: |
| 1173 |
// Looks for part with the given name within the template. |
| 1174 |
// Recursively Checks 'partNumber' only. |
| 1175 |
// |
| 1176 |
// See SoV1NodekitCatalogEntry::recursiveSearch for more info... |
| 1177 |
// |
| 1178 |
// Use: public |
| 1179 |
SbBool |
| 1180 |
SoV1NodekitCatalog::recursiveSearch( int partNumber, |
| 1181 |
const SbName &nameToFind, |
| 1182 |
SbPList *typesChecked ) const |
| 1183 |
// |
| 1184 |
//////////////////////////////////////////////////////////////////////// |
| 1185 |
{ |
| 1186 |
// just call the recursive search method on the given entry... |
| 1187 |
return( entries[partNumber]->recursiveSearch( nameToFind, typesChecked )); |
| 1188 |
} |