Changeset 6078 in orxonox.OLD for trunk/src/lib/coord/p_node.cc
- Timestamp:
- Dec 13, 2005, 2:55:08 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r6075 r6078 21 21 #include "class_list.h" 22 22 23 #include <algorithm> 23 24 #include "compiler.h" 24 25 #include "debug.h" … … 32 33 /** 33 34 * @brief standard constructor 34 */ 35 PNode::PNode (PNode* parent) 36 { 37 init(); 38 if (parent != NULL) 39 parent->addChild(this); 40 } 41 42 /** 43 * @brief initializes a PNode 44 * @param parent the parent for this PNode 45 */ 46 void PNode::init() 35 * @param parent the Parent of this Node. __NULL__ if __No Parent__ requested, PNode::getNullParent(), if connected to NullParent directly (default) 36 * @param nodeFlags all flags to set. THIS_WILL_OVERWRITE Default_Values. look at creation of NullParent for more Info. 37 */ 38 PNode::PNode (PNode* parent, long nodeFlags) 47 39 { 48 40 this->setClassID(CL_PARENT_NODE, "PNode"); … … 51 43 this->bRelDirChanged = true; 52 44 this->parent = NULL; 53 this->parentMode = PNODE_PARENT_MODE_DEFAULT;45 this->parentMode = nodeFlags; 54 46 this->bActive = true; 55 47 … … 58 50 this->toDirection = NULL; 59 51 this->bias = 1.0; 52 53 if (parent != NULL) 54 parent->addChild(this); 60 55 } 61 56 … … 87 82 deleteNode = tmp; 88 83 ++tmp; 89 printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());84 // printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName()); 90 85 if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || 91 86 ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT)) 92 87 { 93 if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL PARENT)88 if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL) 94 89 delete (*deleteNode); 95 90 else … … 102 97 if (this->parent != NULL) 103 98 { 104 this->parent-> children.remove(this);99 this->parent->eraseChild(this); 105 100 this->parent = NULL; 106 101 } … … 462 457 { 463 458 if( likely(child->parent != NULL)) 464 child->parent-> children.remove(child);459 child->parent->eraseChild(child); 465 460 if (this->checkIntegrity(child)) 466 461 { … … 510 505 void PNode::reparent() 511 506 { 512 if (this->parentMode & PNODE_REPARENT_TO_NULL PARENT)513 this->setParent( PNode::getNullParent());507 if (this->parentMode & PNODE_REPARENT_TO_NULL) 508 this->setParent((PNode*)NULL); 514 509 else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL) 515 510 this->setParent(this->parent->getParent()); 511 else 512 this->setParent(PNode::getNullParent()); 513 } 514 515 void PNode::eraseChild(PNode* child) 516 { 517 std::list<PNode*>::iterator childRemover = std::find(this->children.begin(), this->children.end(), child); 518 if(childRemover != this->children.end()) 519 this->children.erase(childRemover); 516 520 } 517 521 … … 524 528 void PNode::removeNode() 525 529 { 526 if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE) 527 { 528 list<PNode*>::iterator child = this->children.begin(); 529 list<PNode*>::iterator reparenter; 530 while (child != this->children.end()) 531 { 532 reparenter = child; 533 child++; 530 list<PNode*>::iterator child = this->children.begin(); 531 list<PNode*>::iterator reparenter; 532 while (child != this->children.end()) 533 { 534 reparenter = child; 535 child++; 536 if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE || 537 (*reparenter)->parentMode & PNODE_REPARENT_ON_PARENTS_REMOVE) 538 { printf("TEST----------------%s ---- %s\n", this->getClassName(), (*reparenter)->getClassName()); 534 539 (*reparenter)->reparent(); 540 printf("REPARENTED TO: %s::%s\n",(*reparenter)->getParent()->getClassName(),(*reparenter)->getParent()->getName()); 535 541 } 536 542 } 537 543 if (this->parent != NULL) 538 this->parent-> children.remove(this);544 this->parent->eraseChild(this); 539 545 } 540 546 … … 630 636 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator. 631 637 */ 632 void PNode::addNode ModeFlags(unsigned short nodeFlags)638 void PNode::addNodeFlags(unsigned short nodeFlags) 633 639 { 634 640 this->parentMode |= nodeFlags; … … 640 646 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator. 641 647 */ 642 void PNode::removeNode ModeFlags(unsigned short nodeFlags)648 void PNode::removeNodeFlags(unsigned short nodeFlags) 643 649 { 644 650 this->parentMode &= !nodeFlags; 651 } 652 653 /** 654 * @returns the NullParent (and if needed creates it) 655 */ 656 PNode* PNode::createNullParent() 657 { 658 if (likely(PNode::nullParent == NULL)) 659 { 660 PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL); 661 PNode::nullParent->setName("NullParent"); 662 } 663 return PNode::nullParent; 645 664 } 646 665
Note: See TracChangeset
for help on using the changeset viewer.