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

#include "PhBHeterogeneousSurface.H"
#include "xrmlP.H"

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

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

void PhBHeterogeneousSurface::synchronize_bsdf(void)
{
  if (_bsdf.size > bsdf.size) bsdf.grow(_bsdf.size - bsdf.size);
  for (int i=bsdf.size=0; i<_bsdf.size; i++)
    bsdf.append(dynamic_cast<PhBSDF*>(_bsdf[i]->firstnode()));
}

bool PhBHeterogeneousSurface::assign_bsdf(const MFNode& value)
{
  MFNode oldval = _bsdf;
  _bsdf = value;
  if (checkValue(_bsdf, IsPhBSDF, "PhBHeterogeneousSurface.bsdf", "PhBSDF")) {
    synchronize_bsdf();
    status |= bsdf_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _bsdf = oldval;
    return false;
  }
}

static bool assign_PhBHeterogeneousSurface_bsdf(SFNode* node, const fieldValue& value)
{
  PhBHeterogeneousSurface* PhBHeterogeneousSurface_node = dynamic_cast<PhBHeterogeneousSurface*>(node);
  if (!PhBHeterogeneousSurface_node)
    Fatal(-1, "assign_PhBHeterogeneousSurface_bsdf", "called for a non-PhBHeterogeneousSurface node");
  return PhBHeterogeneousSurface_node->assign_bsdf((const MFNode&)value);
}

void PhBHeterogeneousSurface::set_bsdf(const MFNode& val)
{
  MFNode tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

PhBHeterogeneousSurface::PhBHeterogeneousSurface()
{
  interfaceMember* the_interface[1] = {
    new exposedField("bsdf", fieldValue(&_bsdf), assign_PhBHeterogeneousSurface_bsdf),
  };
  SFNode::construct(PhBHeterogeneousSurfaceTypeId, 1, the_interface);

  bsdf = array<PhBSDF*>(0); 	_bsdf = MFNode(0);
  
  PhBSurface::util_init();
  PhBHeterogeneousSurface::util_init();
}

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

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

void PhBHeterogeneousSurface::clone_here(const PhBHeterogeneousSurface& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_bsdf);
  
  bsdf = src.bsdf;	  _bsdf = src._bsdf;
  
  PhBSurface::util_clone(src);
  PhBHeterogeneousSurface::util_clone(src);
}

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

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

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

}  // namespace xrml
