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

#include "Anchor.H"
#include "xrmlP.H"

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

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

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

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

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

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

bool Anchor::assign_description(const SFString& value)
{
  // TODO: value range check!
  description = value;
  status |= description_updated;
  timestamp = interface[3]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Anchor_description(SFNode* node, const fieldValue& value)
{
  Anchor* Anchor_node = dynamic_cast<Anchor*>(node);
  if (!Anchor_node)
    Fatal(-1, "assign_Anchor_description", "called for a non-Anchor node");
  return Anchor_node->assign_description((const SFString&)value);
}

void Anchor::set_description(const SFString& val)
{
  SFString tmpval(val);
  fieldValue v(&tmpval);
  interface[3]->assign(this, v);
}

bool Anchor::assign_parameter(const MFString& value)
{
  // TODO: value range check!
  parameter = value;
  status |= parameter_updated;
  timestamp = interface[4]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Anchor_parameter(SFNode* node, const fieldValue& value)
{
  Anchor* Anchor_node = dynamic_cast<Anchor*>(node);
  if (!Anchor_node)
    Fatal(-1, "assign_Anchor_parameter", "called for a non-Anchor node");
  return Anchor_node->assign_parameter((const MFString&)value);
}

void Anchor::set_parameter(const MFString& val)
{
  MFString tmpval(val);
  fieldValue v(&tmpval);
  interface[4]->assign(this, v);
}

bool Anchor::assign_url(const MFString& value)
{
  // TODO: value range check!
  url = value;
  status |= url_updated;
  timestamp = interface[5]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Anchor_url(SFNode* node, const fieldValue& value)
{
  Anchor* Anchor_node = dynamic_cast<Anchor*>(node);
  if (!Anchor_node)
    Fatal(-1, "assign_Anchor_url", "called for a non-Anchor node");
  return Anchor_node->assign_url((const MFString&)value);
}

void Anchor::set_url(const MFString& val)
{
  MFString tmpval(val);
  fieldValue v(&tmpval);
  interface[5]->assign(this, v);
}

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

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

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

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

Anchor::Anchor()
{
  interfaceMember* the_interface[8] = {
    new eventIn("addChildren", tMFNode, process_Anchor_addChildren),
    new eventIn("removeChildren", tMFNode, process_Anchor_removeChildren),
    new exposedField("children", fieldValue(&_children), assign_Anchor_children),
    new exposedField("description", fieldValue(&description), assign_Anchor_description),
    new exposedField("parameter", fieldValue(&parameter), assign_Anchor_parameter),
    new exposedField("url", fieldValue(&url), assign_Anchor_url),
    new field("bboxCenter", fieldValue(&bboxCenter), assign_Anchor_bboxCenter),
    new field("bboxSize", fieldValue(&bboxSize), assign_Anchor_bboxSize),
  };
  SFNode::construct(AnchorTypeId, 8, the_interface);

  children = array<Children*>(0); 	_children = MFNode(0);
  description = "";
  parameter = MFString(0);
  url = MFString(0);
  bboxCenter = SFVec3f(0,0,0);
  bboxSize = SFVec3f(-1,-1,-1);
  
  Sensor::util_init();
  PointingDeviceSensor::util_init();
  Grouping::util_init();
  Children::util_init();
  Anchor::util_init();
}

void Anchor::destruct(void)
{
  Anchor::util_destruct();
  PointingDeviceSensor::util_destruct();
  Sensor::util_destruct();
  Grouping::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void Anchor::clone_here(const Anchor& src)
{
  SFNode::clone(src);
  
  interface[2]->value = fieldValue(&_children);
  interface[3]->value = fieldValue(&description);
  interface[4]->value = fieldValue(&parameter);
  interface[5]->value = fieldValue(&url);
  interface[6]->value = fieldValue(&bboxCenter);
  interface[7]->value = fieldValue(&bboxSize);
  
  children = src.children;	  _children = src._children;
  description = src.description;
  parameter = src.parameter;
  url = src.url;
  bboxCenter = src.bboxCenter;
  bboxSize = src.bboxSize;
  
  Sensor::util_clone(src);
  PointingDeviceSensor::util_clone(src);
  Grouping::util_clone(src);
  Children::util_clone(src);
  Anchor::util_clone(src);
}

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

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

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

}  // namespace xrml
