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

#include "PhBPhF.H"
#include "xrmlP.H"

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

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

bool PhBPhF::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_PhBPhF_intensity(SFNode* node, const fieldValue& value)
{
  PhBPhF* PhBPhF_node = dynamic_cast<PhBPhF*>(node);
  if (!PhBPhF_node)
    Fatal(-1, "assign_PhBPhF_intensity", "called for a non-PhBPhF node");
  return PhBPhF_node->assign_intensity((const SFFloat&)value);
}

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

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

bool PhBPhF::assign_spectrum(SFNode* value)
{
  SFNode* oldval = _spectrum;
  _spectrum = value;
  if (checkValue(_spectrum, IsPhBSpectrum, "PhBPhF.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_PhBPhF_spectrum(SFNode* node, const fieldValue& value)
{
  PhBPhF* PhBPhF_node = dynamic_cast<PhBPhF*>(node);
  if (!PhBPhF_node)
    Fatal(-1, "assign_PhBPhF_spectrum", "called for a non-PhBPhF node");
  return PhBPhF_node->assign_spectrum((SFNode*&)value);
}

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

void PhBPhF::synchronize_phaseFunction(void)
{
  phaseFunction = (_phaseFunction) ? dynamic_cast<PhBPhaseFunction*>(_phaseFunction->firstnode()) : 0;
}

bool PhBPhF::assign_phaseFunction(SFNode* value)
{
  SFNode* oldval = _phaseFunction;
  _phaseFunction = value;
  if (checkValue(_phaseFunction, IsPhBPhaseFunction, "PhBPhF.phaseFunction", "PhBPhaseFunction")) {
    synchronize_phaseFunction();
    status |= phaseFunction_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _phaseFunction = oldval;
    return false;
  }
}

static bool assign_PhBPhF_phaseFunction(SFNode* node, const fieldValue& value)
{
  PhBPhF* PhBPhF_node = dynamic_cast<PhBPhF*>(node);
  if (!PhBPhF_node)
    Fatal(-1, "assign_PhBPhF_phaseFunction", "called for a non-PhBPhF node");
  return PhBPhF_node->assign_phaseFunction((SFNode*&)value);
}

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

PhBPhF::PhBPhF()
{
  interfaceMember* the_interface[3] = {
    new exposedField("intensity", fieldValue(&intensity), assign_PhBPhF_intensity),
    new exposedField("spectrum", fieldValue(&_spectrum), assign_PhBPhF_spectrum),
    new exposedField("phaseFunction", fieldValue(&_phaseFunction), assign_PhBPhF_phaseFunction),
  };
  SFNode::construct(PhBPhFTypeId, 3, the_interface);

  intensity = 1;
  spectrum = (PhBSpectrum *)0; 	_spectrum = (SFNode *)0;
  phaseFunction = (PhBPhaseFunction *)0; 	_phaseFunction = (SFNode *)0;
  
  PhBPhF::util_init();
}

void PhBPhF::destruct(void)
{
  PhBPhF::util_destruct();
  SFNode::destruct();
}

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

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

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

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

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

}  // namespace xrml
