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

#include "PhBTexturedSurface.H"
#include "xrmlP.H"

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

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

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

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

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

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

void PhBTexturedSurface::synchronize_surfaces(void)
{
  if (_surfaces.size > surfaces.size) surfaces.grow(_surfaces.size - surfaces.size);
  for (int i=surfaces.size=0; i<_surfaces.size; i++)
    surfaces.append(dynamic_cast<PhBSurface*>(_surfaces[i]->firstnode()));
}

bool PhBTexturedSurface::assign_surfaces(const MFNode& value)
{
  MFNode oldval = _surfaces;
  _surfaces = value;
  if (checkValue(_surfaces, IsPhBSurface, "PhBTexturedSurface.surfaces", "PhBSurface")) {
    synchronize_surfaces();
    status |= surfaces_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _surfaces = oldval;
    return false;
  }
}

static bool assign_PhBTexturedSurface_surfaces(SFNode* node, const fieldValue& value)
{
  PhBTexturedSurface* PhBTexturedSurface_node = dynamic_cast<PhBTexturedSurface*>(node);
  if (!PhBTexturedSurface_node)
    Fatal(-1, "assign_PhBTexturedSurface_surfaces", "called for a non-PhBTexturedSurface node");
  return PhBTexturedSurface_node->assign_surfaces((const MFNode&)value);
}

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

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

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

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

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

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

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

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

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

PhBTexturedSurface::PhBTexturedSurface()
{
  interfaceMember* the_interface[4] = {
    new exposedField("texture", fieldValue(&_texture), assign_PhBTexturedSurface_texture),
    new exposedField("surfaces", fieldValue(&_surfaces), assign_PhBTexturedSurface_surfaces),
    new exposedField("textureTransform", fieldValue(&_textureTransform), assign_PhBTexturedSurface_textureTransform),
    new exposedField("textureProjection", fieldValue(&_textureProjection), assign_PhBTexturedSurface_textureProjection),
  };
  SFNode::construct(PhBTexturedSurfaceTypeId, 4, the_interface);

  texture = (PhBTexture *)0; 	_texture = (SFNode *)0;
  surfaces = array<PhBSurface*>(0); 	_surfaces = MFNode(0);
  textureTransform = (TextureTransform *)0; 	_textureTransform = (SFNode *)0;
  textureProjection = (PhBTextureProjection *)0; 	_textureProjection = (SFNode *)0;
  
  PhBSurface::util_init();
  PhBTexturedSurface::util_init();
}

void PhBTexturedSurface::destruct(void)
{
  PhBTexturedSurface::util_destruct();
  PhBSurface::util_destruct();
  SFNode::destruct();
}

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

void PhBTexturedSurface::clone_here(const PhBTexturedSurface& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_texture);
  interface[1]->value = fieldValue(&_surfaces);
  interface[2]->value = fieldValue(&_textureTransform);
  interface[3]->value = fieldValue(&_textureProjection);
  
  texture = src.texture;	  _texture = src._texture;
  surfaces = src.surfaces;	  _surfaces = src._surfaces;
  textureTransform = src.textureTransform;	  _textureTransform = src._textureTransform;
  textureProjection = src.textureProjection;	  _textureProjection = src._textureProjection;
  
  PhBSurface::util_clone(src);
  PhBTexturedSurface::util_clone(src);
}

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

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

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

}  // namespace xrml
