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

#include "Appearance.H"
#include "xrmlP.H"

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

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

void Appearance::synchronize_material(void)
{
  material = (_material) ? dynamic_cast<Material*>(_material->firstnode()) : 0;
}

bool Appearance::assign_material(SFNode* value)
{
  SFNode* oldval = _material;
  _material = value;
  if (checkValue(_material, IsMaterial, "Appearance.material", "Material")) {
    synchronize_material();
    status |= material_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _material = oldval;
    return false;
  }
}

static bool assign_Appearance_material(SFNode* node, const fieldValue& value)
{
  Appearance* Appearance_node = dynamic_cast<Appearance*>(node);
  if (!Appearance_node)
    Fatal(-1, "assign_Appearance_material", "called for a non-Appearance node");
  return Appearance_node->assign_material((SFNode*&)value);
}

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

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

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

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

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

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

bool Appearance::assign_textureTransform(SFNode* value)
{
  SFNode* oldval = _textureTransform;
  _textureTransform = value;
  if (checkValue(_textureTransform, IsTextureTransform, "Appearance.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_Appearance_textureTransform(SFNode* node, const fieldValue& value)
{
  Appearance* Appearance_node = dynamic_cast<Appearance*>(node);
  if (!Appearance_node)
    Fatal(-1, "assign_Appearance_textureTransform", "called for a non-Appearance node");
  return Appearance_node->assign_textureTransform((SFNode*&)value);
}

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

Appearance::Appearance()
{
  interfaceMember* the_interface[3] = {
    new exposedField("material", fieldValue(&_material), assign_Appearance_material),
    new exposedField("texture", fieldValue(&_texture), assign_Appearance_texture),
    new exposedField("textureTransform", fieldValue(&_textureTransform), assign_Appearance_textureTransform),
  };
  SFNode::construct(AppearanceTypeId, 3, the_interface);

  material = (Material *)0; 	_material = (SFNode *)0;
  texture = (Texture *)0; 	_texture = (SFNode *)0;
  textureTransform = (TextureTransform *)0; 	_textureTransform = (SFNode *)0;
  
  AppearanceBase::util_init();
  Appearance::util_init();
}

void Appearance::destruct(void)
{
  Appearance::util_destruct();
  AppearanceBase::util_destruct();
  SFNode::destruct();
}

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

void Appearance::clone_here(const Appearance& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_material);
  interface[1]->value = fieldValue(&_texture);
  interface[2]->value = fieldValue(&_textureTransform);
  
  material = src.material;	  _material = src._material;
  texture = src.texture;	  _texture = src._texture;
  textureTransform = src.textureTransform;	  _textureTransform = src._textureTransform;
  
  AppearanceBase::util_clone(src);
  Appearance::util_clone(src);
}

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

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

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

}  // namespace xrml
