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

#include "Group.H"
#include "xrmlP.H"

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

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

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

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

bool Group::assign_children(const MFNode& value)
{
  MFNode oldval = _children;
  _children = value;
  if (checkValue(_children, IsChildren, "Group.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_Group_children(SFNode* node, const fieldValue& value)
{
  Group* Group_node = dynamic_cast<Group*>(node);
  if (!Group_node)
    Fatal(-1, "assign_Group_children", "called for a non-Group node");
  return Group_node->assign_children((const MFNode&)value);
}

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

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

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

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

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

Group::Group()
{
  interfaceMember* the_interface[5] = {
    new eventIn("addChildren", tMFNode, process_Group_addChildren),
    new eventIn("removeChildren", tMFNode, process_Group_removeChildren),
    new exposedField("children", fieldValue(&_children), assign_Group_children),
    new field("bboxCenter", fieldValue(&bboxCenter), assign_Group_bboxCenter),
    new field("bboxSize", fieldValue(&bboxSize), assign_Group_bboxSize),
  };
  SFNode::construct(GroupTypeId, 5, the_interface);

  children = array<Children*>(0); 	_children = MFNode(0);
  bboxCenter = SFVec3f(0,0,0);
  bboxSize = SFVec3f(-1,-1,-1);
  
  Grouping::util_init();
  Children::util_init();
  Group::util_init();
}

void Group::destruct(void)
{
  Group::util_destruct();
  Grouping::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void Group::clone_here(const Group& src)
{
  SFNode::clone(src);
  
  interface[2]->value = fieldValue(&_children);
  interface[3]->value = fieldValue(&bboxCenter);
  interface[4]->value = fieldValue(&bboxSize);
  
  children = src.children;	  _children = src._children;
  bboxCenter = src.bboxCenter;
  bboxSize = src.bboxSize;
  
  Grouping::util_clone(src);
  Children::util_clone(src);
  Group::util_clone(src);
}

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

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

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

}  // namespace xrml
