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

#include "PhBTexturedBackground.H"
#include "xrmlP.H"

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

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

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

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

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

void PhBTexturedBackground::synchronize_texture(void)
{
  texture = (_texture) ? dynamic_cast<PhBTexture*>(_texture->firstnode()) : 0;
}

bool PhBTexturedBackground::assign_texture(SFNode* value)
{
  SFNode* oldval = _texture;
  _texture = value;
  if (checkValue(_texture, IsPhBTexture, "PhBTexturedBackground.texture", "PhBTexture")) {
    synchronize_texture();
    status |= texture_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _texture = oldval;
    return false;
  }
}

static bool assign_PhBTexturedBackground_texture(SFNode* node, const fieldValue& value)
{
  PhBTexturedBackground* PhBTexturedBackground_node = dynamic_cast<PhBTexturedBackground*>(node);
  if (!PhBTexturedBackground_node)
    Fatal(-1, "assign_PhBTexturedBackground_texture", "called for a non-PhBTexturedBackground node");
  return PhBTexturedBackground_node->assign_texture((SFNode*&)value);
}

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

void PhBTexturedBackground::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 PhBTexturedBackground::assign_spectralBasis(const MFNode& value)
{
  MFNode oldval = _spectralBasis;
  _spectralBasis = value;
  if (checkValue(_spectralBasis, IsPhBSpectrum, "PhBTexturedBackground.spectralBasis", "PhBSpectrum")) {
    synchronize_spectralBasis();
    status |= spectralBasis_updated;
    timestamp = interface[3]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _spectralBasis = oldval;
    return false;
  }
}

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

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

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

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

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

bool PhBTexturedBackground::assign_viewOrientation(const SFRotation& value)
{
  // TODO: value range check!
  viewOrientation = value;
  status |= viewOrientation_updated;
  timestamp = interface[5]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBTexturedBackground_viewOrientation(SFNode* node, const fieldValue& value)
{
  PhBTexturedBackground* PhBTexturedBackground_node = dynamic_cast<PhBTexturedBackground*>(node);
  if (!PhBTexturedBackground_node)
    Fatal(-1, "assign_PhBTexturedBackground_viewOrientation", "called for a non-PhBTexturedBackground node");
  return PhBTexturedBackground_node->assign_viewOrientation((const SFRotation&)value);
}

void PhBTexturedBackground::set_viewOrientation(const SFRotation& val)
{
  SFRotation tmpval(val);
  fieldValue v(&tmpval);
  interface[5]->assign(this, v);
}

void PhBTexturedBackground::synchronize_textureTransform(void)
{
  textureTransform = (_textureTransform) ? dynamic_cast<TextureTransform*>(_textureTransform->firstnode()) : 0;
}

bool PhBTexturedBackground::assign_textureTransform(SFNode* value)
{
  SFNode* oldval = _textureTransform;
  _textureTransform = value;
  if (checkValue(_textureTransform, IsTextureTransform, "PhBTexturedBackground.textureTransform", "TextureTransform")) {
    synchronize_textureTransform();
    status |= textureTransform_updated;
    timestamp = interface[6]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _textureTransform = oldval;
    return false;
  }
}

static bool assign_PhBTexturedBackground_textureTransform(SFNode* node, const fieldValue& value)
{
  PhBTexturedBackground* PhBTexturedBackground_node = dynamic_cast<PhBTexturedBackground*>(node);
  if (!PhBTexturedBackground_node)
    Fatal(-1, "assign_PhBTexturedBackground_textureTransform", "called for a non-PhBTexturedBackground node");
  return PhBTexturedBackground_node->assign_textureTransform((SFNode*&)value);
}

void PhBTexturedBackground::set_textureTransform(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[6]->assign(this, v);
}

void PhBTexturedBackground::synchronize_textureProjection(void)
{
  textureProjection = (_textureProjection) ? dynamic_cast<PhBBackgroundProjection*>(_textureProjection->firstnode()) : 0;
}

bool PhBTexturedBackground::assign_textureProjection(SFNode* value)
{
  SFNode* oldval = _textureProjection;
  _textureProjection = value;
  if (checkValue(_textureProjection, IsPhBBackgroundProjection, "PhBTexturedBackground.textureProjection", "PhBBackgroundProjection")) {
    synchronize_textureProjection();
    status |= textureProjection_updated;
    timestamp = interface[7]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _textureProjection = oldval;
    return false;
  }
}

static bool assign_PhBTexturedBackground_textureProjection(SFNode* node, const fieldValue& value)
{
  PhBTexturedBackground* PhBTexturedBackground_node = dynamic_cast<PhBTexturedBackground*>(node);
  if (!PhBTexturedBackground_node)
    Fatal(-1, "assign_PhBTexturedBackground_textureProjection", "called for a non-PhBTexturedBackground node");
  return PhBTexturedBackground_node->assign_textureProjection((SFNode*&)value);
}

void PhBTexturedBackground::set_textureProjection(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[7]->assign(this, v);
}

PhBTexturedBackground::PhBTexturedBackground()
{
  interfaceMember* the_interface[8] = {
    new eventIn("set_bind", tSFBool, process_PhBTexturedBackground_set_bind),
    new eventOut("isBound", fieldValue(&isBound)),
    new exposedField("texture", fieldValue(&_texture), assign_PhBTexturedBackground_texture),
    new exposedField("spectralBasis", fieldValue(&_spectralBasis), assign_PhBTexturedBackground_spectralBasis),
    new exposedField("spectralWeights", fieldValue(&spectralWeights), assign_PhBTexturedBackground_spectralWeights),
    new exposedField("viewOrientation", fieldValue(&viewOrientation), assign_PhBTexturedBackground_viewOrientation),
    new exposedField("textureTransform", fieldValue(&_textureTransform), assign_PhBTexturedBackground_textureTransform),
    new exposedField("textureProjection", fieldValue(&_textureProjection), assign_PhBTexturedBackground_textureProjection),
  };
  SFNode::construct(PhBTexturedBackgroundTypeId, 8, the_interface);

  isBound = 0;
  texture = (PhBTexture *)0; 	_texture = (SFNode *)0;
  spectralBasis = array<PhBSpectrum*>(0); 	_spectralBasis = MFNode(0);
  spectralWeights = MFFloat(0);
  viewOrientation = SFRotation(0,0,1,0);
  textureTransform = (TextureTransform *)0; 	_textureTransform = (SFNode *)0;
  textureProjection = (PhBBackgroundProjection *)0; 	_textureProjection = (SFNode *)0;
  
  Bindable::util_init();
  PhBBackground::util_init();
  Children::util_init();
  PhBTexturedBackground::util_init();
}

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

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

void PhBTexturedBackground::clone_here(const PhBTexturedBackground& src)
{
  SFNode::clone(src);
  
  interface[1]->value = fieldValue(&isBound);
  interface[2]->value = fieldValue(&_texture);
  interface[3]->value = fieldValue(&_spectralBasis);
  interface[4]->value = fieldValue(&spectralWeights);
  interface[5]->value = fieldValue(&viewOrientation);
  interface[6]->value = fieldValue(&_textureTransform);
  interface[7]->value = fieldValue(&_textureProjection);
  
  isBound = src.isBound;
  texture = src.texture;	  _texture = src._texture;
  spectralBasis = src.spectralBasis;	  _spectralBasis = src._spectralBasis;
  spectralWeights = src.spectralWeights;
  viewOrientation = src.viewOrientation;
  textureTransform = src.textureTransform;	  _textureTransform = src._textureTransform;
  textureProjection = src.textureProjection;	  _textureProjection = src._textureProjection;
  
  Bindable::util_clone(src);
  PhBBackground::util_clone(src);
  Children::util_clone(src);
  PhBTexturedBackground::util_clone(src);
}

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

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

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

}  // namespace xrml
