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

#include "PhBAppearance.H"
#include "xrmlP.H"

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

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

void PhBAppearance::synchronize_surface(void)
{
  surface = (_surface) ? dynamic_cast<PhBSurface*>(_surface->firstnode()) : 0;
}

bool PhBAppearance::assign_surface(SFNode* value)
{
  SFNode* oldval = _surface;
  _surface = value;
  if (checkValue(_surface, IsPhBSurface, "PhBAppearance.surface", "PhBSurface")) {
    synchronize_surface();
    status |= surface_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _surface = oldval;
    return false;
  }
}

static bool assign_PhBAppearance_surface(SFNode* node, const fieldValue& value)
{
  PhBAppearance* PhBAppearance_node = dynamic_cast<PhBAppearance*>(node);
  if (!PhBAppearance_node)
    Fatal(-1, "assign_PhBAppearance_surface", "called for a non-PhBAppearance node");
  return PhBAppearance_node->assign_surface((SFNode*&)value);
}

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

void PhBAppearance::synchronize_medium(void)
{
  medium = (_medium) ? dynamic_cast<PhBMedium*>(_medium->firstnode()) : 0;
}

bool PhBAppearance::assign_medium(SFNode* value)
{
  SFNode* oldval = _medium;
  _medium = value;
  if (checkValue(_medium, IsPhBMedium, "PhBAppearance.medium", "PhBMedium")) {
    synchronize_medium();
    status |= medium_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _medium = oldval;
    return false;
  }
}

static bool assign_PhBAppearance_medium(SFNode* node, const fieldValue& value)
{
  PhBAppearance* PhBAppearance_node = dynamic_cast<PhBAppearance*>(node);
  if (!PhBAppearance_node)
    Fatal(-1, "assign_PhBAppearance_medium", "called for a non-PhBAppearance node");
  return PhBAppearance_node->assign_medium((SFNode*&)value);
}

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

void PhBAppearance::synchronize_bumpMap(void)
{
  bumpMap = (_bumpMap) ? dynamic_cast<PhBDistortion*>(_bumpMap->firstnode()) : 0;
}

bool PhBAppearance::assign_bumpMap(SFNode* value)
{
  SFNode* oldval = _bumpMap;
  _bumpMap = value;
  if (checkValue(_bumpMap, IsPhBDistortion, "PhBAppearance.bumpMap", "PhBDistortion")) {
    synchronize_bumpMap();
    status |= bumpMap_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _bumpMap = oldval;
    return false;
  }
}

static bool assign_PhBAppearance_bumpMap(SFNode* node, const fieldValue& value)
{
  PhBAppearance* PhBAppearance_node = dynamic_cast<PhBAppearance*>(node);
  if (!PhBAppearance_node)
    Fatal(-1, "assign_PhBAppearance_bumpMap", "called for a non-PhBAppearance node");
  return PhBAppearance_node->assign_bumpMap((SFNode*&)value);
}

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

void PhBAppearance::synchronize_displacementMap(void)
{
  displacementMap = (_displacementMap) ? dynamic_cast<PhBDistortion*>(_displacementMap->firstnode()) : 0;
}

bool PhBAppearance::assign_displacementMap(SFNode* value)
{
  SFNode* oldval = _displacementMap;
  _displacementMap = value;
  if (checkValue(_displacementMap, IsPhBDistortion, "PhBAppearance.displacementMap", "PhBDistortion")) {
    synchronize_displacementMap();
    status |= displacementMap_updated;
    timestamp = interface[3]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _displacementMap = oldval;
    return false;
  }
}

static bool assign_PhBAppearance_displacementMap(SFNode* node, const fieldValue& value)
{
  PhBAppearance* PhBAppearance_node = dynamic_cast<PhBAppearance*>(node);
  if (!PhBAppearance_node)
    Fatal(-1, "assign_PhBAppearance_displacementMap", "called for a non-PhBAppearance node");
  return PhBAppearance_node->assign_displacementMap((SFNode*&)value);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

PhBAppearance::PhBAppearance()
{
  interfaceMember* the_interface[7] = {
    new exposedField("surface", fieldValue(&_surface), assign_PhBAppearance_surface),
    new exposedField("medium", fieldValue(&_medium), assign_PhBAppearance_medium),
    new exposedField("bumpMap", fieldValue(&_bumpMap), assign_PhBAppearance_bumpMap),
    new exposedField("displacementMap", fieldValue(&_displacementMap), assign_PhBAppearance_displacementMap),
    new exposedField("textureProjection", fieldValue(&_textureProjection), assign_PhBAppearance_textureProjection),
    new exposedField("textureTransform", fieldValue(&_textureTransform), assign_PhBAppearance_textureTransform),
    new exposedField("textureTransform3D", fieldValue(&_textureTransform3D), assign_PhBAppearance_textureTransform3D),
  };
  SFNode::construct(PhBAppearanceTypeId, 7, the_interface);

  surface = (PhBSurface *)0; 	_surface = (SFNode *)0;
  medium = (PhBMedium *)0; 	_medium = (SFNode *)0;
  bumpMap = (PhBDistortion *)0; 	_bumpMap = (SFNode *)0;
  displacementMap = (PhBDistortion *)0; 	_displacementMap = (SFNode *)0;
  textureProjection = (PhBTextureProjection *)0; 	_textureProjection = (SFNode *)0;
  textureTransform = (TextureTransform *)0; 	_textureTransform = (SFNode *)0;
  textureTransform3D = (PhB3DTextureTransform *)0; 	_textureTransform3D = (SFNode *)0;
  
  AppearanceBase::util_init();
  PhBAppearance::util_init();
}

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

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

void PhBAppearance::clone_here(const PhBAppearance& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_surface);
  interface[1]->value = fieldValue(&_medium);
  interface[2]->value = fieldValue(&_bumpMap);
  interface[3]->value = fieldValue(&_displacementMap);
  interface[4]->value = fieldValue(&_textureProjection);
  interface[5]->value = fieldValue(&_textureTransform);
  interface[6]->value = fieldValue(&_textureTransform3D);
  
  surface = src.surface;	  _surface = src._surface;
  medium = src.medium;	  _medium = src._medium;
  bumpMap = src.bumpMap;	  _bumpMap = src._bumpMap;
  displacementMap = src.displacementMap;	  _displacementMap = src._displacementMap;
  textureProjection = src.textureProjection;	  _textureProjection = src._textureProjection;
  textureTransform = src.textureTransform;	  _textureTransform = src._textureTransform;
  textureTransform3D = src.textureTransform3D;	  _textureTransform3D = src._textureTransform3D;
  
  AppearanceBase::util_clone(src);
  PhBAppearance::util_clone(src);
}

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

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

SFNode* PhBAppearance::instantiate(Proto *enclosing_proto)
{
  if (nameIndex>=0)
    // named node: return pointer to pre-made instance
    return enclosing_proto ? enclosing_proto->namedNodes[nameIndex] : this;
  
  PhBAppearance* instance = new PhBAppearance(*this);
  instance->instantiate_interface(enclosing_proto);
  instance->synchronize_surface();
  instance->synchronize_medium();
  instance->synchronize_bumpMap();
  instance->synchronize_displacementMap();
  instance->synchronize_textureProjection();
  instance->synchronize_textureTransform();
  instance->synchronize_textureTransform3D();
  return instance;
}

}  // namespace xrml
