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

#include "PhBInterpolatedSurface.H"
#include "xrmlP.H"

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

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

bool PhBInterpolatedSurface::assign_fraction(const SFFloat& value)
{
  // TODO: value range check!
  fraction = value;
  status |= fraction_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBInterpolatedSurface_fraction(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedSurface* PhBInterpolatedSurface_node = dynamic_cast<PhBInterpolatedSurface*>(node);
  if (!PhBInterpolatedSurface_node)
    Fatal(-1, "assign_PhBInterpolatedSurface_fraction", "called for a non-PhBInterpolatedSurface node");
  return PhBInterpolatedSurface_node->assign_fraction((const SFFloat&)value);
}

void PhBInterpolatedSurface::set_fraction(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool PhBInterpolatedSurface::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_PhBInterpolatedSurface_key(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedSurface* PhBInterpolatedSurface_node = dynamic_cast<PhBInterpolatedSurface*>(node);
  if (!PhBInterpolatedSurface_node)
    Fatal(-1, "assign_PhBInterpolatedSurface_key", "called for a non-PhBInterpolatedSurface node");
  return PhBInterpolatedSurface_node->assign_key((const MFFloat&)value);
}

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

void PhBInterpolatedSurface::synchronize_keySurfaces(void)
{
  if (_keySurfaces.size > keySurfaces.size) keySurfaces.grow(_keySurfaces.size - keySurfaces.size);
  for (int i=keySurfaces.size=0; i<_keySurfaces.size; i++)
    keySurfaces.append(dynamic_cast<PhBSurface*>(_keySurfaces[i]->firstnode()));
}

bool PhBInterpolatedSurface::assign_keySurfaces(const MFNode& value)
{
  MFNode oldval = _keySurfaces;
  _keySurfaces = value;
  if (checkValue(_keySurfaces, IsPhBSurface, "PhBInterpolatedSurface.keySurfaces", "PhBSurface")) {
    synchronize_keySurfaces();
    status |= keySurfaces_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _keySurfaces = oldval;
    return false;
  }
}

static bool assign_PhBInterpolatedSurface_keySurfaces(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedSurface* PhBInterpolatedSurface_node = dynamic_cast<PhBInterpolatedSurface*>(node);
  if (!PhBInterpolatedSurface_node)
    Fatal(-1, "assign_PhBInterpolatedSurface_keySurfaces", "called for a non-PhBInterpolatedSurface node");
  return PhBInterpolatedSurface_node->assign_keySurfaces((const MFNode&)value);
}

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

PhBInterpolatedSurface::PhBInterpolatedSurface()
{
  interfaceMember* the_interface[3] = {
    new exposedField("fraction", fieldValue(&fraction), assign_PhBInterpolatedSurface_fraction),
    new exposedField("key", fieldValue(&key), assign_PhBInterpolatedSurface_key),
    new exposedField("keySurfaces", fieldValue(&_keySurfaces), assign_PhBInterpolatedSurface_keySurfaces),
  };
  SFNode::construct(PhBInterpolatedSurfaceTypeId, 3, the_interface);

  fraction = 0;
  key = MFFloat(0);
  keySurfaces = array<PhBSurface*>(0); 	_keySurfaces = MFNode(0);
  
  PhBSurface::util_init();
  PhBInterpolatedSurface::util_init();
}

void PhBInterpolatedSurface::destruct(void)
{
  PhBInterpolatedSurface::util_destruct();
  PhBSurface::util_destruct();
  SFNode::destruct();
}

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

void PhBInterpolatedSurface::clone_here(const PhBInterpolatedSurface& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&fraction);
  interface[1]->value = fieldValue(&key);
  interface[2]->value = fieldValue(&_keySurfaces);
  
  fraction = src.fraction;
  key = src.key;
  keySurfaces = src.keySurfaces;	  _keySurfaces = src._keySurfaces;
  
  PhBSurface::util_clone(src);
  PhBInterpolatedSurface::util_clone(src);
}

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

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

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

}  // namespace xrml
