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

#include "IndexedFaceSet.H"
#include "xrmlP.H"

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

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

static void process_IndexedFaceSet_set_colorIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "process_IndexedFaceSet_set_colorIndex", "called for a non-IndexedFaceSet node");
  IndexedFaceSet_node->set_colorIndex((const MFInt32&)value);
}

static void process_IndexedFaceSet_set_coordIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "process_IndexedFaceSet_set_coordIndex", "called for a non-IndexedFaceSet node");
  IndexedFaceSet_node->set_coordIndex((const MFInt32&)value);
}

static void process_IndexedFaceSet_set_normalIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "process_IndexedFaceSet_set_normalIndex", "called for a non-IndexedFaceSet node");
  IndexedFaceSet_node->set_normalIndex((const MFInt32&)value);
}

static void process_IndexedFaceSet_set_texCoordIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "process_IndexedFaceSet_set_texCoordIndex", "called for a non-IndexedFaceSet node");
  IndexedFaceSet_node->set_texCoordIndex((const MFInt32&)value);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

bool IndexedFaceSet::assign_ccw(const SFBool& value)
{
  // TODO: value range check!
  ccw = value;
  status |= ccw_updated;
  timestamp = interface[8]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_ccw(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_ccw", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_ccw((const SFBool&)value);
}

bool IndexedFaceSet::assign_colorIndex(const MFInt32& value)
{
  // TODO: value range check!
  colorIndex = value;
  status |= colorIndex_updated;
  timestamp = interface[9]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_colorIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_colorIndex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_colorIndex((const MFInt32&)value);
}

bool IndexedFaceSet::assign_colorPerVertex(const SFBool& value)
{
  // TODO: value range check!
  colorPerVertex = value;
  status |= colorPerVertex_updated;
  timestamp = interface[10]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_colorPerVertex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_colorPerVertex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_colorPerVertex((const SFBool&)value);
}

bool IndexedFaceSet::assign_convex(const SFBool& value)
{
  // TODO: value range check!
  convex = value;
  status |= convex_updated;
  timestamp = interface[11]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_convex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_convex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_convex((const SFBool&)value);
}

bool IndexedFaceSet::assign_coordIndex(const MFInt32& value)
{
  // TODO: value range check!
  coordIndex = value;
  status |= coordIndex_updated;
  timestamp = interface[12]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_coordIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_coordIndex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_coordIndex((const MFInt32&)value);
}

bool IndexedFaceSet::assign_creaseAngle(const SFFloat& value)
{
  // TODO: value range check!
  creaseAngle = value;
  status |= creaseAngle_updated;
  timestamp = interface[13]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_creaseAngle(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_creaseAngle", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_creaseAngle((const SFFloat&)value);
}

bool IndexedFaceSet::assign_normalIndex(const MFInt32& value)
{
  // TODO: value range check!
  normalIndex = value;
  status |= normalIndex_updated;
  timestamp = interface[14]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_normalIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_normalIndex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_normalIndex((const MFInt32&)value);
}

bool IndexedFaceSet::assign_normalPerVertex(const SFBool& value)
{
  // TODO: value range check!
  normalPerVertex = value;
  status |= normalPerVertex_updated;
  timestamp = interface[15]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_normalPerVertex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_normalPerVertex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_normalPerVertex((const SFBool&)value);
}

bool IndexedFaceSet::assign_solid(const SFBool& value)
{
  // TODO: value range check!
  solid = value;
  status |= solid_updated;
  timestamp = interface[16]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_solid(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_solid", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_solid((const SFBool&)value);
}

bool IndexedFaceSet::assign_texCoordIndex(const MFInt32& value)
{
  // TODO: value range check!
  texCoordIndex = value;
  status |= texCoordIndex_updated;
  timestamp = interface[17]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_IndexedFaceSet_texCoordIndex(SFNode* node, const fieldValue& value)
{
  IndexedFaceSet* IndexedFaceSet_node = dynamic_cast<IndexedFaceSet*>(node);
  if (!IndexedFaceSet_node)
    Fatal(-1, "assign_IndexedFaceSet_texCoordIndex", "called for a non-IndexedFaceSet node");
  return IndexedFaceSet_node->assign_texCoordIndex((const MFInt32&)value);
}

IndexedFaceSet::IndexedFaceSet()
{
  interfaceMember* the_interface[18] = {
    new eventIn("set_colorIndex", tMFInt32, process_IndexedFaceSet_set_colorIndex),
    new eventIn("set_coordIndex", tMFInt32, process_IndexedFaceSet_set_coordIndex),
    new eventIn("set_normalIndex", tMFInt32, process_IndexedFaceSet_set_normalIndex),
    new eventIn("set_texCoordIndex", tMFInt32, process_IndexedFaceSet_set_texCoordIndex),
    new exposedField("color", fieldValue(&_color), assign_IndexedFaceSet_color),
    new exposedField("coord", fieldValue(&_coord), assign_IndexedFaceSet_coord),
    new exposedField("normal", fieldValue(&_normal), assign_IndexedFaceSet_normal),
    new exposedField("texCoord", fieldValue(&_texCoord), assign_IndexedFaceSet_texCoord),
    new field("ccw", fieldValue(&ccw), assign_IndexedFaceSet_ccw),
    new field("colorIndex", fieldValue(&colorIndex), assign_IndexedFaceSet_colorIndex),
    new field("colorPerVertex", fieldValue(&colorPerVertex), assign_IndexedFaceSet_colorPerVertex),
    new field("convex", fieldValue(&convex), assign_IndexedFaceSet_convex),
    new field("coordIndex", fieldValue(&coordIndex), assign_IndexedFaceSet_coordIndex),
    new field("creaseAngle", fieldValue(&creaseAngle), assign_IndexedFaceSet_creaseAngle),
    new field("normalIndex", fieldValue(&normalIndex), assign_IndexedFaceSet_normalIndex),
    new field("normalPerVertex", fieldValue(&normalPerVertex), assign_IndexedFaceSet_normalPerVertex),
    new field("solid", fieldValue(&solid), assign_IndexedFaceSet_solid),
    new field("texCoordIndex", fieldValue(&texCoordIndex), assign_IndexedFaceSet_texCoordIndex),
  };
  SFNode::construct(IndexedFaceSetTypeId, 18, 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;
  ccw = 1;
  colorIndex = MFInt32(0);
  colorPerVertex = 1;
  convex = 1;
  coordIndex = MFInt32(0);
  creaseAngle = 0;
  normalIndex = MFInt32(0);
  normalPerVertex = 1;
  solid = 1;
  texCoordIndex = MFInt32(0);
  
  Geometry::util_init();
  IndexedFaceSet::util_init();
}

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

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

void IndexedFaceSet::clone_here(const IndexedFaceSet& src)
{
  SFNode::clone(src);
  
  interface[4]->value = fieldValue(&_color);
  interface[5]->value = fieldValue(&_coord);
  interface[6]->value = fieldValue(&_normal);
  interface[7]->value = fieldValue(&_texCoord);
  interface[8]->value = fieldValue(&ccw);
  interface[9]->value = fieldValue(&colorIndex);
  interface[10]->value = fieldValue(&colorPerVertex);
  interface[11]->value = fieldValue(&convex);
  interface[12]->value = fieldValue(&coordIndex);
  interface[13]->value = fieldValue(&creaseAngle);
  interface[14]->value = fieldValue(&normalIndex);
  interface[15]->value = fieldValue(&normalPerVertex);
  interface[16]->value = fieldValue(&solid);
  interface[17]->value = fieldValue(&texCoordIndex);
  
  color = src.color;	  _color = src._color;
  coord = src.coord;	  _coord = src._coord;
  normal = src.normal;	  _normal = src._normal;
  texCoord = src.texCoord;	  _texCoord = src._texCoord;
  ccw = src.ccw;
  colorIndex = src.colorIndex;
  colorPerVertex = src.colorPerVertex;
  convex = src.convex;
  coordIndex = src.coordIndex;
  creaseAngle = src.creaseAngle;
  normalIndex = src.normalIndex;
  normalPerVertex = src.normalPerVertex;
  solid = src.solid;
  texCoordIndex = src.texCoordIndex;
  
  Geometry::util_clone(src);
  IndexedFaceSet::util_clone(src);
}

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

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

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

}  // namespace xrml
