// PhBHomogeneousBackgroundP.C: PhBHomogeneousBackground nodes (private source).
// Automatically generated with nodegen 0.51 - do not edit.

#include "PhBHomogeneousBackground.H"
#include "xrmlP.H"

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

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

static void process_PhBHomogeneousBackground_set_bind(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousBackground* PhBHomogeneousBackground_node = dynamic_cast<PhBHomogeneousBackground*>(node);
  if (!PhBHomogeneousBackground_node)
    Fatal(-1, "process_PhBHomogeneousBackground_set_bind", "called for a non-PhBHomogeneousBackground node");
  PhBHomogeneousBackground_node->set_bind((const SFBool&)value);
}

void PhBHomogeneousBackground::post_isBound(void)
{
  interface[1]->post(this, interface[1]->value);
}

void PhBHomogeneousBackground::post_isBound(const SFBool& val)
{
  isBound = val;
  status |= isBound_updated;
  post_isBound();
}

void PhBHomogeneousBackground::synchronize_spectralBasis(void)
{
  if (_spectralBasis.size > spectralBasis.size) spectralBasis.grow(_spectralBasis.size - spectralBasis.size);
  for (int i=spectralBasis.size=0; i<_spectralBasis.size; i++)
    spectralBasis.append(dynamic_cast<PhBSpectrum*>(_spectralBasis[i]->firstnode()));
}

bool PhBHomogeneousBackground::assign_spectralBasis(const MFNode& value)
{
  MFNode oldval = _spectralBasis;
  _spectralBasis = value;
  if (checkValue(_spectralBasis, IsPhBSpectrum, "PhBHomogeneousBackground.spectralBasis", "PhBSpectrum")) {
    synchronize_spectralBasis();
    status |= spectralBasis_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _spectralBasis = oldval;
    return false;
  }
}

static bool assign_PhBHomogeneousBackground_spectralBasis(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousBackground* PhBHomogeneousBackground_node = dynamic_cast<PhBHomogeneousBackground*>(node);
  if (!PhBHomogeneousBackground_node)
    Fatal(-1, "assign_PhBHomogeneousBackground_spectralBasis", "called for a non-PhBHomogeneousBackground node");
  return PhBHomogeneousBackground_node->assign_spectralBasis((const MFNode&)value);
}

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

bool PhBHomogeneousBackground::assign_spectralWeights(const MFFloat& value)
{
  // TODO: value range check!
  spectralWeights = value;
  status |= spectralWeights_updated;
  timestamp = interface[3]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBHomogeneousBackground_spectralWeights(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousBackground* PhBHomogeneousBackground_node = dynamic_cast<PhBHomogeneousBackground*>(node);
  if (!PhBHomogeneousBackground_node)
    Fatal(-1, "assign_PhBHomogeneousBackground_spectralWeights", "called for a non-PhBHomogeneousBackground node");
  return PhBHomogeneousBackground_node->assign_spectralWeights((const MFFloat&)value);
}

void PhBHomogeneousBackground::set_spectralWeights(const MFFloat& val)
{
  MFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[3]->assign(this, v);
}

PhBHomogeneousBackground::PhBHomogeneousBackground()
{
  interfaceMember* the_interface[4] = {
    new eventIn("set_bind", tSFBool, process_PhBHomogeneousBackground_set_bind),
    new eventOut("isBound", fieldValue(&isBound)),
    new exposedField("spectralBasis", fieldValue(&_spectralBasis), assign_PhBHomogeneousBackground_spectralBasis),
    new exposedField("spectralWeights", fieldValue(&spectralWeights), assign_PhBHomogeneousBackground_spectralWeights),
  };
  SFNode::construct(PhBHomogeneousBackgroundTypeId, 4, the_interface);

  isBound = 0;
  spectralBasis = array<PhBSpectrum*>(0); 	_spectralBasis = MFNode(0);
  spectralWeights = MFFloat(0);
  
  Bindable::util_init();
  PhBBackground::util_init();
  Children::util_init();
  PhBHomogeneousBackground::util_init();
}

void PhBHomogeneousBackground::destruct(void)
{
  PhBHomogeneousBackground::util_destruct();
  PhBBackground::util_destruct();
  Bindable::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void PhBHomogeneousBackground::clone_here(const PhBHomogeneousBackground& src)
{
  SFNode::clone(src);
  
  interface[1]->value = fieldValue(&isBound);
  interface[2]->value = fieldValue(&_spectralBasis);
  interface[3]->value = fieldValue(&spectralWeights);
  
  isBound = src.isBound;
  spectralBasis = src.spectralBasis;	  _spectralBasis = src._spectralBasis;
  spectralWeights = src.spectralWeights;
  
  Bindable::util_clone(src);
  PhBBackground::util_clone(src);
  Children::util_clone(src);
  PhBHomogeneousBackground::util_clone(src);
}

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

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

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

}  // namespace xrml
