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

#include "PointSet.H"
#include "xrmlP.H"

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

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

void PointSet::synchronize_color(void)
{
  color = (_color) ? dynamic_cast<Color*>(_color->firstnode()) : 0;
}

bool PointSet::assign_color(SFNode* value)
{
  SFNode* oldval = _color;
  _color = value;
  if (checkValue(_color, IsColor, "PointSet.color", "Color")) {
    synchronize_color();
    status |= color_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _color = oldval;
    return false;
  }
}

static bool assign_PointSet_color(SFNode* node, const fieldValue& value)
{
  PointSet* PointSet_node = dynamic_cast<PointSet*>(node);
  if (!PointSet_node)
    Fatal(-1, "assign_PointSet_color", "called for a non-PointSet node");
  return PointSet_node->assign_color((SFNode*&)value);
}

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

void PointSet::synchronize_coord(void)
{
  coord = (_coord) ? dynamic_cast<Coordinate*>(_coord->firstnode()) : 0;
}

bool PointSet::assign_coord(SFNode* value)
{
  SFNode* oldval = _coord;
  _coord = value;
  if (checkValue(_coord, IsCoordinate, "PointSet.coord", "Coordinate")) {
    synchronize_coord();
    status |= coord_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _coord = oldval;
    return false;
  }
}

static bool assign_PointSet_coord(SFNode* node, const fieldValue& value)
{
  PointSet* PointSet_node = dynamic_cast<PointSet*>(node);
  if (!PointSet_node)
    Fatal(-1, "assign_PointSet_coord", "called for a non-PointSet node");
  return PointSet_node->assign_coord((SFNode*&)value);
}

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

void PointSet::synchronize_normal(void)
{
  normal = (_normal) ? dynamic_cast<Normal*>(_normal->firstnode()) : 0;
}

bool PointSet::assign_normal(SFNode* value)
{
  SFNode* oldval = _normal;
  _normal = value;
  if (checkValue(_normal, IsNormal, "PointSet.normal", "Normal")) {
    synchronize_normal();
    status |= normal_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _normal = oldval;
    return false;
  }
}

static bool assign_PointSet_normal(SFNode* node, const fieldValue& value)
{
  PointSet* PointSet_node = dynamic_cast<PointSet*>(node);
  if (!PointSet_node)
    Fatal(-1, "assign_PointSet_normal", "called for a non-PointSet node");
  return PointSet_node->assign_normal((SFNode*&)value);
}

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

void PointSet::synchronize_texCoord(void)
{
  texCoord = (_texCoord) ? dynamic_cast<TextureCoordinate*>(_texCoord->firstnode()) : 0;
}

bool PointSet::assign_texCoord(SFNode* value)
{
  SFNode* oldval = _texCoord;
  _texCoord = value;
  if (checkValue(_texCoord, IsTextureCoordinate, "PointSet.texCoord", "TextureCoordinate")) {
    synchronize_texCoord();
    status |= texCoord_updated;
    timestamp = interface[3]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _texCoord = oldval;
    return false;
  }
}

static bool assign_PointSet_texCoord(SFNode* node, const fieldValue& value)
{
  PointSet* PointSet_node = dynamic_cast<PointSet*>(node);
  if (!PointSet_node)
    Fatal(-1, "assign_PointSet_texCoord", "called for a non-PointSet node");
  return PointSet_node->assign_texCoord((SFNode*&)value);
}

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

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

static bool assign_PointSet_pointsize(SFNode* node, const fieldValue& value)
{
  PointSet* PointSet_node = dynamic_cast<PointSet*>(node);
  if (!PointSet_node)
    Fatal(-1, "assign_PointSet_pointsize", "called for a non-PointSet node");
  return PointSet_node->assign_pointsize((const SFFloat&)value);
}

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

PointSet::PointSet()
{
  interfaceMember* the_interface[5] = {
    new exposedField("color", fieldValue(&_color), assign_PointSet_color),
    new exposedField("coord", fieldValue(&_coord), assign_PointSet_coord),
    new exposedField("normal", fieldValue(&_normal), assign_PointSet_normal),
    new exposedField("texCoord", fieldValue(&_texCoord), assign_PointSet_texCoord),
    new exposedField("pointsize", fieldValue(&pointsize), assign_PointSet_pointsize),
  };
  SFNode::construct(PointSetTypeId, 5, the_interface);

  color = (Color *)0; 	_color = (SFNode *)0;
  coord = (Coordinate *)0; 	_coord = (SFNode *)0;
  normal = (Normal *)0; 	_normal = (SFNode *)0;
  texCoord = (TextureCoordinate *)0; 	_texCoord = (SFNode *)0;
  pointsize = 1;
  
  Geometry::util_init();
  PointSet::util_init();
}

void PointSet::destruct(void)
{
  PointSet::util_destruct();
  Geometry::util_destruct();
  SFNode::destruct();
}

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

void PointSet::clone_here(const PointSet& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_color);
  interface[1]->value = fieldValue(&_coord);
  interface[2]->value = fieldValue(&_normal);
  interface[3]->value = fieldValue(&_texCoord);
  interface[4]->value = fieldValue(&pointsize);
  
  color = src.color;	  _color = src._color;
  coord = src.coord;	  _coord = src._coord;
  normal = src.normal;	  _normal = src._normal;
  texCoord = src.texCoord;	  _texCoord = src._texCoord;
  pointsize = src.pointsize;
  
  Geometry::util_clone(src);
  PointSet::util_clone(src);
}

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

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

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

}  // namespace xrml
