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

#include "PhBTexturedMedium.H"
#include "xrmlP.H"

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

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

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

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

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

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

void PhBTexturedMedium::synchronize_media(void)
{
  if (_media.size > media.size) media.grow(_media.size - media.size);
  for (int i=media.size=0; i<_media.size; i++)
    media.append(dynamic_cast<PhBMedium*>(_media[i]->firstnode()));
}

bool PhBTexturedMedium::assign_media(const MFNode& value)
{
  MFNode oldval = _media;
  _media = value;
  if (checkValue(_media, IsPhBMedium, "PhBTexturedMedium.media", "PhBMedium")) {
    synchronize_media();
    status |= media_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _media = oldval;
    return false;
  }
}

static bool assign_PhBTexturedMedium_media(SFNode* node, const fieldValue& value)
{
  PhBTexturedMedium* PhBTexturedMedium_node = dynamic_cast<PhBTexturedMedium*>(node);
  if (!PhBTexturedMedium_node)
    Fatal(-1, "assign_PhBTexturedMedium_media", "called for a non-PhBTexturedMedium node");
  return PhBTexturedMedium_node->assign_media((const MFNode&)value);
}

void PhBTexturedMedium::set_media(const MFNode& val)
{
  MFNode tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

void PhBTexturedMedium::synchronize_textureTransform3D(void)
{
  textureTransform3D = (_textureTransform3D) ? dynamic_cast<PhB3DTextureTransform*>(_textureTransform3D->firstnode()) : 0;
}

bool PhBTexturedMedium::assign_textureTransform3D(SFNode* value)
{
  SFNode* oldval = _textureTransform3D;
  _textureTransform3D = value;
  if (checkValue(_textureTransform3D, IsPhB3DTextureTransform, "PhBTexturedMedium.textureTransform3D", "PhB3DTextureTransform")) {
    synchronize_textureTransform3D();
    status |= textureTransform3D_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _textureTransform3D = oldval;
    return false;
  }
}

static bool assign_PhBTexturedMedium_textureTransform3D(SFNode* node, const fieldValue& value)
{
  PhBTexturedMedium* PhBTexturedMedium_node = dynamic_cast<PhBTexturedMedium*>(node);
  if (!PhBTexturedMedium_node)
    Fatal(-1, "assign_PhBTexturedMedium_textureTransform3D", "called for a non-PhBTexturedMedium node");
  return PhBTexturedMedium_node->assign_textureTransform3D((SFNode*&)value);
}

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

PhBTexturedMedium::PhBTexturedMedium()
{
  interfaceMember* the_interface[3] = {
    new exposedField("texture", fieldValue(&_texture), assign_PhBTexturedMedium_texture),
    new exposedField("media", fieldValue(&_media), assign_PhBTexturedMedium_media),
    new exposedField("textureTransform3D", fieldValue(&_textureTransform3D), assign_PhBTexturedMedium_textureTransform3D),
  };
  SFNode::construct(PhBTexturedMediumTypeId, 3, the_interface);

  texture = (PhB3DTexture *)0; 	_texture = (SFNode *)0;
  media = array<PhBMedium*>(0); 	_media = MFNode(0);
  textureTransform3D = (PhB3DTextureTransform *)0; 	_textureTransform3D = (SFNode *)0;
  
  PhBMedium::util_init();
  PhBTexturedMedium::util_init();
}

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

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

void PhBTexturedMedium::clone_here(const PhBTexturedMedium& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_texture);
  interface[1]->value = fieldValue(&_media);
  interface[2]->value = fieldValue(&_textureTransform3D);
  
  texture = src.texture;	  _texture = src._texture;
  media = src.media;	  _media = src._media;
  textureTransform3D = src.textureTransform3D;	  _textureTransform3D = src._textureTransform3D;
  
  PhBMedium::util_clone(src);
  PhBTexturedMedium::util_clone(src);
}

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

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

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

}  // namespace xrml
