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

#include "Sound.H"
#include "xrmlP.H"

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

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

bool Sound::assign_direction(const SFVec3f& value)
{
  // TODO: value range check!
  direction = value;
  status |= direction_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_direction(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_direction", "called for a non-Sound node");
  return Sound_node->assign_direction((const SFVec3f&)value);
}

void Sound::set_direction(const SFVec3f& val)
{
  SFVec3f tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool Sound::assign_intensity(const SFFloat& value)
{
  // TODO: value range check!
  intensity = value;
  status |= intensity_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_intensity(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_intensity", "called for a non-Sound node");
  return Sound_node->assign_intensity((const SFFloat&)value);
}

void Sound::set_intensity(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

bool Sound::assign_location(const SFVec3f& value)
{
  // TODO: value range check!
  location = value;
  status |= location_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_location(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_location", "called for a non-Sound node");
  return Sound_node->assign_location((const SFVec3f&)value);
}

void Sound::set_location(const SFVec3f& val)
{
  SFVec3f tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

bool Sound::assign_maxBack(const SFFloat& value)
{
  // TODO: value range check!
  maxBack = value;
  status |= maxBack_updated;
  timestamp = interface[3]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_maxBack(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_maxBack", "called for a non-Sound node");
  return Sound_node->assign_maxBack((const SFFloat&)value);
}

void Sound::set_maxBack(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[3]->assign(this, v);
}

bool Sound::assign_maxFront(const SFFloat& value)
{
  // TODO: value range check!
  maxFront = value;
  status |= maxFront_updated;
  timestamp = interface[4]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_maxFront(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_maxFront", "called for a non-Sound node");
  return Sound_node->assign_maxFront((const SFFloat&)value);
}

void Sound::set_maxFront(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[4]->assign(this, v);
}

bool Sound::assign_minBack(const SFFloat& value)
{
  // TODO: value range check!
  minBack = value;
  status |= minBack_updated;
  timestamp = interface[5]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_minBack(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_minBack", "called for a non-Sound node");
  return Sound_node->assign_minBack((const SFFloat&)value);
}

void Sound::set_minBack(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[5]->assign(this, v);
}

bool Sound::assign_minFront(const SFFloat& value)
{
  // TODO: value range check!
  minFront = value;
  status |= minFront_updated;
  timestamp = interface[6]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_minFront(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_minFront", "called for a non-Sound node");
  return Sound_node->assign_minFront((const SFFloat&)value);
}

void Sound::set_minFront(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[6]->assign(this, v);
}

bool Sound::assign_priority(const SFFloat& value)
{
  // TODO: value range check!
  priority = value;
  status |= priority_updated;
  timestamp = interface[7]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_priority(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_priority", "called for a non-Sound node");
  return Sound_node->assign_priority((const SFFloat&)value);
}

void Sound::set_priority(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[7]->assign(this, v);
}

void Sound::synchronize_source(void)
{
  source = (_source) ? dynamic_cast<SoundSource*>(_source->firstnode()) : 0;
}

bool Sound::assign_source(SFNode* value)
{
  SFNode* oldval = _source;
  _source = value;
  if (checkValue(_source, IsSoundSource, "Sound.source", "SoundSource")) {
    synchronize_source();
    status |= source_updated;
    timestamp = interface[8]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _source = oldval;
    return false;
  }
}

static bool assign_Sound_source(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_source", "called for a non-Sound node");
  return Sound_node->assign_source((SFNode*&)value);
}

void Sound::set_source(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[8]->assign(this, v);
}

bool Sound::assign_spatialize(const SFBool& value)
{
  // TODO: value range check!
  spatialize = value;
  status |= spatialize_updated;
  timestamp = interface[9]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Sound_spatialize(SFNode* node, const fieldValue& value)
{
  Sound* Sound_node = dynamic_cast<Sound*>(node);
  if (!Sound_node)
    Fatal(-1, "assign_Sound_spatialize", "called for a non-Sound node");
  return Sound_node->assign_spatialize((const SFBool&)value);
}

Sound::Sound()
{
  interfaceMember* the_interface[10] = {
    new exposedField("direction", fieldValue(&direction), assign_Sound_direction),
    new exposedField("intensity", fieldValue(&intensity), assign_Sound_intensity),
    new exposedField("location", fieldValue(&location), assign_Sound_location),
    new exposedField("maxBack", fieldValue(&maxBack), assign_Sound_maxBack),
    new exposedField("maxFront", fieldValue(&maxFront), assign_Sound_maxFront),
    new exposedField("minBack", fieldValue(&minBack), assign_Sound_minBack),
    new exposedField("minFront", fieldValue(&minFront), assign_Sound_minFront),
    new exposedField("priority", fieldValue(&priority), assign_Sound_priority),
    new exposedField("source", fieldValue(&_source), assign_Sound_source),
    new field("spatialize", fieldValue(&spatialize), assign_Sound_spatialize),
  };
  SFNode::construct(SoundTypeId, 10, the_interface);

  direction = SFVec3f(0,0,1);
  intensity = 1;
  location = SFVec3f(0,0,0);
  maxBack = 10;
  maxFront = 10;
  minBack = 1;
  minFront = 1;
  priority = 0;
  source = (SoundSource *)0; 	_source = (SFNode *)0;
  spatialize = 1;
  
  Children::util_init();
  Sound::util_init();
}

void Sound::destruct(void)
{
  Sound::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void Sound::clone_here(const Sound& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&direction);
  interface[1]->value = fieldValue(&intensity);
  interface[2]->value = fieldValue(&location);
  interface[3]->value = fieldValue(&maxBack);
  interface[4]->value = fieldValue(&maxFront);
  interface[5]->value = fieldValue(&minBack);
  interface[6]->value = fieldValue(&minFront);
  interface[7]->value = fieldValue(&priority);
  interface[8]->value = fieldValue(&_source);
  interface[9]->value = fieldValue(&spatialize);
  
  direction = src.direction;
  intensity = src.intensity;
  location = src.location;
  maxBack = src.maxBack;
  maxFront = src.maxFront;
  minBack = src.minBack;
  minFront = src.minFront;
  priority = src.priority;
  source = src.source;	  _source = src._source;
  spatialize = src.spatialize;
  
  Children::util_clone(src);
  Sound::util_clone(src);
}

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

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

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

}  // namespace xrml
