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

#include "PhBFresnelBSDF.H"
#include "xrmlP.H"

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

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

bool PhBFresnelBSDF::assign_intensity(const SFFloat& value)
{
  // TODO: value range check!
  intensity = value;
  status |= intensity_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBFresnelBSDF_intensity(SFNode* node, const fieldValue& value)
{
  PhBFresnelBSDF* PhBFresnelBSDF_node = dynamic_cast<PhBFresnelBSDF*>(node);
  if (!PhBFresnelBSDF_node)
    Fatal(-1, "assign_PhBFresnelBSDF_intensity", "called for a non-PhBFresnelBSDF node");
  return PhBFresnelBSDF_node->assign_intensity((const SFFloat&)value);
}

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

void PhBFresnelBSDF::synchronize_spectrum(void)
{
  spectrum = (_spectrum) ? dynamic_cast<PhBSpectrum*>(_spectrum->firstnode()) : 0;
}

bool PhBFresnelBSDF::assign_spectrum(SFNode* value)
{
  SFNode* oldval = _spectrum;
  _spectrum = value;
  if (checkValue(_spectrum, IsPhBSpectrum, "PhBFresnelBSDF.spectrum", "PhBSpectrum")) {
    synchronize_spectrum();
    status |= spectrum_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _spectrum = oldval;
    return false;
  }
}

static bool assign_PhBFresnelBSDF_spectrum(SFNode* node, const fieldValue& value)
{
  PhBFresnelBSDF* PhBFresnelBSDF_node = dynamic_cast<PhBFresnelBSDF*>(node);
  if (!PhBFresnelBSDF_node)
    Fatal(-1, "assign_PhBFresnelBSDF_spectrum", "called for a non-PhBFresnelBSDF node");
  return PhBFresnelBSDF_node->assign_spectrum((SFNode*&)value);
}

void PhBFresnelBSDF::set_spectrum(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

void PhBFresnelBSDF::synchronize_scatterer(void)
{
  scatterer = (_scatterer) ? dynamic_cast<PhBScatterer*>(_scatterer->firstnode()) : 0;
}

bool PhBFresnelBSDF::assign_scatterer(SFNode* value)
{
  SFNode* oldval = _scatterer;
  _scatterer = value;
  if (checkValue(_scatterer, IsPhBScatterer, "PhBFresnelBSDF.scatterer", "PhBScatterer")) {
    synchronize_scatterer();
    status |= scatterer_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _scatterer = oldval;
    return false;
  }
}

static bool assign_PhBFresnelBSDF_scatterer(SFNode* node, const fieldValue& value)
{
  PhBFresnelBSDF* PhBFresnelBSDF_node = dynamic_cast<PhBFresnelBSDF*>(node);
  if (!PhBFresnelBSDF_node)
    Fatal(-1, "assign_PhBFresnelBSDF_scatterer", "called for a non-PhBFresnelBSDF node");
  return PhBFresnelBSDF_node->assign_scatterer((SFNode*&)value);
}

void PhBFresnelBSDF::set_scatterer(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

PhBFresnelBSDF::PhBFresnelBSDF()
{
  interfaceMember* the_interface[3] = {
    new exposedField("intensity", fieldValue(&intensity), assign_PhBFresnelBSDF_intensity),
    new exposedField("spectrum", fieldValue(&_spectrum), assign_PhBFresnelBSDF_spectrum),
    new exposedField("scatterer", fieldValue(&_scatterer), assign_PhBFresnelBSDF_scatterer),
  };
  SFNode::construct(PhBFresnelBSDFTypeId, 3, the_interface);

  intensity = 1;
  spectrum = (PhBSpectrum *)0; 	_spectrum = (SFNode *)0;
  scatterer = (PhBScatterer *)0; 	_scatterer = (SFNode *)0;
  
  PhBSDF::util_init();
  PhBFresnelBSDF::util_init();
}

void PhBFresnelBSDF::destruct(void)
{
  PhBFresnelBSDF::util_destruct();
  PhBSDF::util_destruct();
  SFNode::destruct();
}

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

void PhBFresnelBSDF::clone_here(const PhBFresnelBSDF& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&intensity);
  interface[1]->value = fieldValue(&_spectrum);
  interface[2]->value = fieldValue(&_scatterer);
  
  intensity = src.intensity;
  spectrum = src.spectrum;	  _spectrum = src._spectrum;
  scatterer = src.scatterer;	  _scatterer = src._scatterer;
  
  PhBSDF::util_clone(src);
  PhBFresnelBSDF::util_clone(src);
}

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

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

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

}  // namespace xrml
