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

#include "IndexedLineSet.H"
#include "xrmlP.H"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

IndexedLineSet::IndexedLineSet()
{
  interfaceMember* the_interface[7] = {
    new eventIn("set_colorIndex", tMFInt32, process_IndexedLineSet_set_colorIndex),
    new eventIn("set_coordIndex", tMFInt32, process_IndexedLineSet_set_coordIndex),
    new exposedField("color", fieldValue(&_color), assign_IndexedLineSet_color),
    new exposedField("coord", fieldValue(&_coord), assign_IndexedLineSet_coord),
    new field("colorIndex", fieldValue(&colorIndex), assign_IndexedLineSet_colorIndex),
    new field("colorPerVertex", fieldValue(&colorPerVertex), assign_IndexedLineSet_colorPerVertex),
    new field("coordIndex", fieldValue(&coordIndex), assign_IndexedLineSet_coordIndex),
  };
  SFNode::construct(IndexedLineSetTypeId, 7, the_interface);

  color = (Color *)0; 	_color = (SFNode *)0;
  coord = (Coordinate *)0; 	_coord = (SFNode *)0;
  colorIndex = MFInt32(0);
  colorPerVertex = 1;
  coordIndex = MFInt32(0);
  
  Geometry::util_init();
  IndexedLineSet::util_init();
}

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

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

void IndexedLineSet::clone_here(const IndexedLineSet& src)
{
  SFNode::clone(src);
  
  interface[2]->value = fieldValue(&_color);
  interface[3]->value = fieldValue(&_coord);
  interface[4]->value = fieldValue(&colorIndex);
  interface[5]->value = fieldValue(&colorPerVertex);
  interface[6]->value = fieldValue(&coordIndex);
  
  color = src.color;	  _color = src._color;
  coord = src.coord;	  _coord = src._coord;
  colorIndex = src.colorIndex;
  colorPerVertex = src.colorPerVertex;
  coordIndex = src.coordIndex;
  
  Geometry::util_clone(src);
  IndexedLineSet::util_clone(src);
}

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

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

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

}  // namespace xrml
