Index: trunk/src/lib/coord/p_node.cc
===================================================================
--- trunk/src/lib/coord/p_node.cc	(revision 6075)
+++ trunk/src/lib/coord/p_node.cc	(revision 6078)
@@ -21,4 +21,5 @@
 #include "class_list.h"
 
+#include <algorithm>
 #include "compiler.h"
 #include "debug.h"
@@ -32,17 +33,8 @@
 /**
  * @brief standard constructor
- */
-PNode::PNode (PNode* parent)
-{
-  init();
-  if (parent != NULL)
-    parent->addChild(this);
-}
-
-/**
- * @brief initializes a PNode
- * @param parent the parent for this PNode
- */
-void PNode::init()
+ * @param parent the Parent of this Node. __NULL__ if __No Parent__ requested, PNode::getNullParent(), if connected to NullParent directly (default)
+ * @param nodeFlags all flags to set. THIS_WILL_OVERWRITE Default_Values. look at creation of NullParent for more Info.
+ */
+PNode::PNode (PNode* parent, long nodeFlags)
 {
   this->setClassID(CL_PARENT_NODE, "PNode");
@@ -51,5 +43,5 @@
   this->bRelDirChanged = true;
   this->parent = NULL;
-  this->parentMode = PNODE_PARENT_MODE_DEFAULT;
+  this->parentMode = nodeFlags;
   this->bActive = true;
 
@@ -58,4 +50,7 @@
   this->toDirection = NULL;
   this->bias = 1.0;
+
+  if (parent != NULL)
+    parent->addChild(this);
 }
 
@@ -87,9 +82,9 @@
       deleteNode = tmp;
       ++tmp;
-      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
+//      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
       if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) ||
           ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
       {
-        if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)
+        if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL)
           delete (*deleteNode);
         else
@@ -102,5 +97,5 @@
   if (this->parent != NULL)
    {
-     this->parent->children.remove(this);
+     this->parent->eraseChild(this);
      this->parent = NULL;
    }
@@ -462,5 +457,5 @@
 {
   if( likely(child->parent != NULL))
-      child->parent->children.remove(child);
+      child->parent->eraseChild(child);
   if (this->checkIntegrity(child))
   {
@@ -510,8 +505,17 @@
 void PNode::reparent()
 {
-  if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
-    this->setParent(PNode::getNullParent());
+  if (this->parentMode & PNODE_REPARENT_TO_NULL)
+    this->setParent((PNode*)NULL);
   else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
     this->setParent(this->parent->getParent());
+  else
+    this->setParent(PNode::getNullParent());
+}
+
+void PNode::eraseChild(PNode* child)
+{
+  std::list<PNode*>::iterator childRemover = std::find(this->children.begin(), this->children.end(), child);
+  if(childRemover != this->children.end())
+    this->children.erase(childRemover);
 }
 
@@ -524,17 +528,19 @@
 void PNode::removeNode()
 {
-  if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE)
-  {
-    list<PNode*>::iterator child = this->children.begin();
-    list<PNode*>::iterator reparenter;
-    while (child != this->children.end())
-    {
-      reparenter = child;
-      child++;
+  list<PNode*>::iterator child = this->children.begin();
+  list<PNode*>::iterator reparenter;
+  while (child != this->children.end())
+  {
+    reparenter = child;
+    child++;
+    if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE ||
+        (*reparenter)->parentMode & PNODE_REPARENT_ON_PARENTS_REMOVE)
+    {      printf("TEST----------------%s ---- %s\n", this->getClassName(), (*reparenter)->getClassName());
       (*reparenter)->reparent();
+      printf("REPARENTED TO: %s::%s\n",(*reparenter)->getParent()->getClassName(),(*reparenter)->getParent()->getName());
     }
   }
   if (this->parent != NULL)
-    this->parent->children.remove(this);
+    this->parent->eraseChild(this);
 }
 
@@ -630,5 +636,5 @@
  * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
  */
-void PNode::addNodeModeFlags(unsigned short nodeFlags)
+void PNode::addNodeFlags(unsigned short nodeFlags)
 {
   this->parentMode |= nodeFlags;
@@ -640,7 +646,20 @@
  * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
  */
-void PNode::removeNodeModeFlags(unsigned short nodeFlags)
+void PNode::removeNodeFlags(unsigned short nodeFlags)
 {
   this->parentMode &= !nodeFlags;
+}
+
+/**
+ * @returns the NullParent (and if needed creates it)
+ */
+PNode* PNode::createNullParent()
+{
+  if (likely(PNode::nullParent == NULL))
+  {
+    PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL);
+    PNode::nullParent->setName("NullParent");
+  }
+  return PNode::nullParent;
 }
 
