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

#include "PhBHomogeneousMedium.H"
#include "xrmlP.H"

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

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

bool PhBHomogeneousMedium::assign_indexOfRefraction(const SFVec2f& value)
{
  // TODO: value range check!
  indexOfRefraction = value;
  status |= indexOfRefraction_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBHomogeneousMedium_indexOfRefraction(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousMedium* PhBHomogeneousMedium_node = dynamic_cast<PhBHomogeneousMedium*>(node);
  if (!PhBHomogeneousMedium_node)
    Fatal(-1, "assign_PhBHomogeneousMedium_indexOfRefraction", "called for a non-PhBHomogeneousMedium node");
  return PhBHomogeneousMedium_node->assign_indexOfRefraction((const SFVec2f&)value);
}

void PhBHomogeneousMedium::set_indexOfRefraction(const SFVec2f& val)
{
  SFVec2f tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool PhBHomogeneousMedium::assign_scatteringCrossSection(const SFFloat& value)
{
  // TODO: value range check!
  scatteringCrossSection = value;
  status |= scatteringCrossSection_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBHomogeneousMedium_scatteringCrossSection(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousMedium* PhBHomogeneousMedium_node = dynamic_cast<PhBHomogeneousMedium*>(node);
  if (!PhBHomogeneousMedium_node)
    Fatal(-1, "assign_PhBHomogeneousMedium_scatteringCrossSection", "called for a non-PhBHomogeneousMedium node");
  return PhBHomogeneousMedium_node->assign_scatteringCrossSection((const SFFloat&)value);
}

void PhBHomogeneousMedium::set_scatteringCrossSection(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

bool PhBHomogeneousMedium::assign_absorptionCrossSection(const SFFloat& value)
{
  // TODO: value range check!
  absorptionCrossSection = value;
  status |= absorptionCrossSection_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBHomogeneousMedium_absorptionCrossSection(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousMedium* PhBHomogeneousMedium_node = dynamic_cast<PhBHomogeneousMedium*>(node);
  if (!PhBHomogeneousMedium_node)
    Fatal(-1, "assign_PhBHomogeneousMedium_absorptionCrossSection", "called for a non-PhBHomogeneousMedium node");
  return PhBHomogeneousMedium_node->assign_absorptionCrossSection((const SFFloat&)value);
}

void PhBHomogeneousMedium::set_absorptionCrossSection(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

void PhBHomogeneousMedium::synchronize_phaseFunction(void)
{
  if (_phaseFunction.size > phaseFunction.size) phaseFunction.grow(_phaseFunction.size - phaseFunction.size);
  for (int i=phaseFunction.size=0; i<_phaseFunction.size; i++)
    phaseFunction.append(dynamic_cast<PhBPhF*>(_phaseFunction[i]->firstnode()));
}

bool PhBHomogeneousMedium::assign_phaseFunction(const MFNode& value)
{
  MFNode oldval = _phaseFunction;
  _phaseFunction = value;
  if (checkValue(_phaseFunction, IsPhBPhF, "PhBHomogeneousMedium.phaseFunction", "PhBPhF")) {
    synchronize_phaseFunction();
    status |= phaseFunction_updated;
    timestamp = interface[3]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _phaseFunction = oldval;
    return false;
  }
}

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

void PhBHomogeneousMedium::set_phaseFunction(const MFNode& val)
{
  MFNode tmpval(val);
  fieldValue v(&tmpval);
  interface[3]->assign(this, v);
}

void PhBHomogeneousMedium::synchronize_selfEmittedFluxDensity(void)
{
  selfEmittedFluxDensity = (_selfEmittedFluxDensity) ? dynamic_cast<PhBSpectrum*>(_selfEmittedFluxDensity->firstnode()) : 0;
}

bool PhBHomogeneousMedium::assign_selfEmittedFluxDensity(SFNode* value)
{
  SFNode* oldval = _selfEmittedFluxDensity;
  _selfEmittedFluxDensity = value;
  if (checkValue(_selfEmittedFluxDensity, IsPhBSpectrum, "PhBHomogeneousMedium.selfEmittedFluxDensity", "PhBSpectrum")) {
    synchronize_selfEmittedFluxDensity();
    status |= selfEmittedFluxDensity_updated;
    timestamp = interface[4]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _selfEmittedFluxDensity = oldval;
    return false;
  }
}

static bool assign_PhBHomogeneousMedium_selfEmittedFluxDensity(SFNode* node, const fieldValue& value)
{
  PhBHomogeneousMedium* PhBHomogeneousMedium_node = dynamic_cast<PhBHomogeneousMedium*>(node);
  if (!PhBHomogeneousMedium_node)
    Fatal(-1, "assign_PhBHomogeneousMedium_selfEmittedFluxDensity", "called for a non-PhBHomogeneousMedium node");
  return PhBHomogeneousMedium_node->assign_selfEmittedFluxDensity((SFNode*&)value);
}

void PhBHomogeneousMedium::set_selfEmittedFluxDensity(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[4]->assign(this, v);
}

PhBHomogeneousMedium::PhBHomogeneousMedium()
{
  interfaceMember* the_interface[5] = {
    new exposedField("indexOfRefraction", fieldValue(&indexOfRefraction), assign_PhBHomogeneousMedium_indexOfRefraction),
    new exposedField("scatteringCrossSection", fieldValue(&scatteringCrossSection), assign_PhBHomogeneousMedium_scatteringCrossSection),
    new exposedField("absorptionCrossSection", fieldValue(&absorptionCrossSection), assign_PhBHomogeneousMedium_absorptionCrossSection),
    new exposedField("phaseFunction", fieldValue(&_phaseFunction), assign_PhBHomogeneousMedium_phaseFunction),
    new exposedField("selfEmittedFluxDensity", fieldValue(&_selfEmittedFluxDensity), assign_PhBHomogeneousMedium_selfEmittedFluxDensity),
  };
  SFNode::construct(PhBHomogeneousMediumTypeId, 5, the_interface);

  indexOfRefraction = SFVec2f(1,0);
  scatteringCrossSection = 0;
  absorptionCrossSection = 0;
  phaseFunction = array<PhBPhF*>(0); 	_phaseFunction = MFNode(0);
  selfEmittedFluxDensity = (PhBSpectrum *)0; 	_selfEmittedFluxDensity = (SFNode *)0;
  
  PhBMedium::util_init();
  PhBHomogeneousMedium::util_init();
}

void PhBHomogeneousMedium::destruct(void)
{
  PhBHomogeneousMedium::util_destruct();
  PhBMedium::util_destruct();
  SFNode::destruct();
}

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

void PhBHomogeneousMedium::clone_here(const PhBHomogeneousMedium& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&indexOfRefraction);
  interface[1]->value = fieldValue(&scatteringCrossSection);
  interface[2]->value = fieldValue(&absorptionCrossSection);
  interface[3]->value = fieldValue(&_phaseFunction);
  interface[4]->value = fieldValue(&_selfEmittedFluxDensity);
  
  indexOfRefraction = src.indexOfRefraction;
  scatteringCrossSection = src.scatteringCrossSection;
  absorptionCrossSection = src.absorptionCrossSection;
  phaseFunction = src.phaseFunction;	  _phaseFunction = src._phaseFunction;
  selfEmittedFluxDensity = src.selfEmittedFluxDensity;	  _selfEmittedFluxDensity = src._selfEmittedFluxDensity;
  
  PhBMedium::util_clone(src);
  PhBHomogeneousMedium::util_clone(src);
}

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

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

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

}  // namespace xrml
