// CollisionP.C: Collision nodes (private source).
// Automatically generated with nodegen 0.5a - do not edit.

#include "Collision.H"
#include "xrmlP.H"

namespace xrml {
int Collision::major_version(void) { return 0; }
int Collision::minor_version(void) { return 5; }
bool Collision::is_leaf_class(void) { return true; }

bool IsCollision(SFNode* node)
{
  return (dynamic_cast<Collision*>(node) != 0);
}

static void process_Collision_addChildren(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "process_Collision_addChildren", "called for a non-Collision node");
  Collision_node->addChildren((const MFNode&)value);
}

static void process_Collision_removeChildren(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "process_Collision_removeChildren", "called for a non-Collision node");
  Collision_node->removeChildren((const MFNode&)value);
}

bool Collision::assign_children(const MFNode& value)
{
  MFNode oldval = _children;
  _children = value;
  if (checkValue(_children, IsChildren, "Collision.children", "Children")) {
    synchronize_children();
    status |= children_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _children = oldval;
    return false;
  }
}

static bool assign_Collision_children(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "assign_Collision_children", "called for a non-Collision node");
  return Collision_node->assign_children((const MFNode&)value);
}

void Collision::set_children(const MFNode& val)
{
  MFNode tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

bool Collision::assign_collide(const SFBool& value)
{
  // TODO: value range check!
  collide = value;
  status |= collide_updated;
  timestamp = interface[3]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Collision_collide(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "assign_Collision_collide", "called for a non-Collision node");
  return Collision_node->assign_collide((const SFBool&)value);
}

void Collision::set_collide(const SFBool& val)
{
  SFBool tmpval(val);
  fieldValue v(&tmpval);
  interface[3]->assign(this, v);
}

bool Collision::assign_bboxCenter(const SFVec3f& value)
{
  // TODO: value range check!
  bboxCenter = value;
  status |= bboxCenter_updated;
  timestamp = interface[4]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Collision_bboxCenter(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "assign_Collision_bboxCenter", "called for a non-Collision node");
  return Collision_node->assign_bboxCenter((const SFVec3f&)value);
}

bool Collision::assign_bboxSize(const SFVec3f& value)
{
  // TODO: value range check!
  bboxSize = value;
  status |= bboxSize_updated;
  timestamp = interface[5]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Collision_bboxSize(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "assign_Collision_bboxSize", "called for a non-Collision node");
  return Collision_node->assign_bboxSize((const SFVec3f&)value);
}

void Collision::synchronize_proxy(void)
{
  proxy = (_proxy) ? dynamic_cast<Children*>(_proxy->firstnode()) : 0;
}

bool Collision::assign_proxy(SFNode* value)
{
  SFNode* oldval = _proxy;
  _proxy = value;
  if (checkValue(_proxy, IsChildren, "Collision.proxy", "Children")) {
    synchronize_proxy();
    status |= proxy_updated;
    timestamp = interface[6]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _proxy = oldval;
    return false;
  }
}

static bool assign_Collision_proxy(SFNode* node, const fieldValue& value)
{
  Collision* Collision_node = dynamic_cast<Collision*>(node);
  if (!Collision_node)
    Fatal(-1, "assign_Collision_proxy", "called for a non-Collision node");
  return Collision_node->assign_proxy((SFNode*&)value);
}

void Collision::post_collideTime(void)
{
  interface[7]->post(this, interface[7]->value);
}

void Collision::post_collideTime(const SFTime& val)
{
  collideTime = val;
  status |= collideTime_updated;
  post_collideTime();
}

Collision::Collision()
{
  interfaceMember* the_interface[8] = {
    new eventIn("addChildren", tMFNode, process_Collision_addChildren),
    new eventIn("removeChildren", tMFNode, process_Collision_removeChildren),
    new exposedField("children", fieldValue(&_children), assign_Collision_children),
    new exposedField("collide", fieldValue(&collide), assign_Collision_collide),
    new field("bboxCenter", fieldValue(&bboxCenter), assign_Collision_bboxCenter),
    new field("bboxSize", fieldValue(&bboxSize), assign_Collision_bboxSize),
    new field("proxy", fieldValue(&_proxy), assign_Collision_proxy),
    new eventOut("collideTime", fieldValue(&collideTime)),
  };
  SFNode::construct(CollisionTypeId, 8, the_interface);

  children = array<Children*>(0); 	_children = MFNode(0);
  collide = 1;
  bboxCenter = SFVec3f(0,0,0);
  bboxSize = SFVec3f(-1,-1,-1);
  proxy = (Children *)0; 	_proxy = (SFNode *)0;
  collideTime = 0;
  
  Sensor::util_init();
  EnvironmentalSensor::util_init();
  Grouping::util_init();
  Children::util_init();
  Collision::util_init();
}

void Collision::destruct(void)
{
  Collision::util_destruct();
  EnvironmentalSensor::util_destruct();
  Sensor::util_destruct();
  Grouping::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

Collision::~Collision()
{
  destruct();
}

void Collision::clone_here(const Collision& src)
{
  SFNode::clone(src);
  
  interface[2]->value = fieldValue(&_children);
  interface[3]->value = fieldValue(&collide);
  interface[4]->value = fieldValue(&bboxCenter);
  interface[5]->value = fieldValue(&bboxSize);
  interface[6]->value = fieldValue(&_proxy);
  interface[7]->value = fieldValue(&collideTime);
  
  children = src.children;	  _children = src._children;
  collide = src.collide;
  bboxCenter = src.bboxCenter;
  bboxSize = src.bboxSize;
  proxy = src.proxy;	  _proxy = src._proxy;
  collideTime = src.collideTime;
  
  Sensor::util_clone(src);
  EnvironmentalSensor::util_clone(src);
  Grouping::util_clone(src);
  Children::util_clone(src);
  Collision::util_clone(src);
}

Collision::Collision(const Collision& src)
{
  clone_here(src);
}

Collision& Collision::operator=(const Collision& src)
{
  if (this != &src) {
    destruct();
    clone_here(src);
  }
  return *this;
}

SFNode* Collision::instantiate(Proto *enclosing_proto)
{
  if (nameIndex>=0)
    // named node: return pointer to pre-made instance
    return enclosing_proto ? enclosing_proto->namedNodes[nameIndex] : this;
  
  Collision* instance = new Collision(*this);
  instance->instantiate_interface(enclosing_proto);
  instance->synchronize_children();
  instance->synchronize_proxy();
  return instance;
}

}  // namespace xrml
