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

#include "CoordinateInterpolator.H"
#include "xrmlP.H"

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

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

static void process_CoordinateInterpolator_set_fraction(SFNode* node, const fieldValue& value)
{
  CoordinateInterpolator* CoordinateInterpolator_node = dynamic_cast<CoordinateInterpolator*>(node);
  if (!CoordinateInterpolator_node)
    Fatal(-1, "process_CoordinateInterpolator_set_fraction", "called for a non-CoordinateInterpolator node");
  CoordinateInterpolator_node->set_fraction((const SFFloat&)value);
}

bool CoordinateInterpolator::assign_key(const MFFloat& value)
{
  // TODO: value range check!
  key = value;
  status |= key_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_CoordinateInterpolator_key(SFNode* node, const fieldValue& value)
{
  CoordinateInterpolator* CoordinateInterpolator_node = dynamic_cast<CoordinateInterpolator*>(node);
  if (!CoordinateInterpolator_node)
    Fatal(-1, "assign_CoordinateInterpolator_key", "called for a non-CoordinateInterpolator node");
  return CoordinateInterpolator_node->assign_key((const MFFloat&)value);
}

void CoordinateInterpolator::set_key(const MFFloat& val)
{
  MFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

bool CoordinateInterpolator::assign_keyValue(const MFVec3f& value)
{
  // TODO: value range check!
  keyValue = value;
  status |= keyValue_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_CoordinateInterpolator_keyValue(SFNode* node, const fieldValue& value)
{
  CoordinateInterpolator* CoordinateInterpolator_node = dynamic_cast<CoordinateInterpolator*>(node);
  if (!CoordinateInterpolator_node)
    Fatal(-1, "assign_CoordinateInterpolator_keyValue", "called for a non-CoordinateInterpolator node");
  return CoordinateInterpolator_node->assign_keyValue((const MFVec3f&)value);
}

void CoordinateInterpolator::set_keyValue(const MFVec3f& val)
{
  MFVec3f tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

void CoordinateInterpolator::post_value_changed(void)
{
  interface[3]->post(this, interface[3]->value);
}

void CoordinateInterpolator::post_value_changed(const MFVec3f& val)
{
  value_changed = val;
  status |= value_changed_updated;
  post_value_changed();
}

CoordinateInterpolator::CoordinateInterpolator()
{
  interfaceMember* the_interface[4] = {
    new eventIn("set_fraction", tSFFloat, process_CoordinateInterpolator_set_fraction),
    new exposedField("key", fieldValue(&key), assign_CoordinateInterpolator_key),
    new exposedField("keyValue", fieldValue(&keyValue), assign_CoordinateInterpolator_keyValue),
    new eventOut("value_changed", fieldValue(&value_changed)),
  };
  SFNode::construct(CoordinateInterpolatorTypeId, 4, the_interface);

  key = MFFloat(0);
  keyValue = MFVec3f(0);
  value_changed = MFVec3f(0);
  
  Interpolator::util_init();
  Children::util_init();
  CoordinateInterpolator::util_init();
}

void CoordinateInterpolator::destruct(void)
{
  CoordinateInterpolator::util_destruct();
  Interpolator::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void CoordinateInterpolator::clone_here(const CoordinateInterpolator& src)
{
  SFNode::clone(src);
  
  interface[1]->value = fieldValue(&key);
  interface[2]->value = fieldValue(&keyValue);
  interface[3]->value = fieldValue(&value_changed);
  
  key = src.key;
  keyValue = src.keyValue;
  value_changed = src.value_changed;
  
  Interpolator::util_clone(src);
  Children::util_clone(src);
  CoordinateInterpolator::util_clone(src);
}

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

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

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

}  // namespace xrml
