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

#include "ElevationGrid.H"
#include "xrmlP.H"

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

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

static void process_ElevationGrid_set_height(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "process_ElevationGrid_set_height", "called for a non-ElevationGrid node");
  ElevationGrid_node->set_height((const MFFloat&)value);
}

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

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

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

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

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

bool ElevationGrid::assign_normal(SFNode* value)
{
  SFNode* oldval = _normal;
  _normal = value;
  if (checkValue(_normal, IsNormal, "ElevationGrid.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_ElevationGrid_normal(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_normal", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_normal((SFNode*&)value);
}

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

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

bool ElevationGrid::assign_texCoord(SFNode* value)
{
  SFNode* oldval = _texCoord;
  _texCoord = value;
  if (checkValue(_texCoord, IsTextureCoordinate, "ElevationGrid.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_ElevationGrid_texCoord(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_texCoord", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_texCoord((SFNode*&)value);
}

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

bool ElevationGrid::assign_height(const MFFloat& value)
{
  // TODO: value range check!
  height = value;
  status |= height_updated;
  timestamp = interface[4]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ElevationGrid_height(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_height", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_height((const MFFloat&)value);
}

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

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

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

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

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

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

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

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

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

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

bool ElevationGrid::assign_xDimension(const SFInt32& value)
{
  // TODO: value range check!
  xDimension = value;
  status |= xDimension_updated;
  timestamp = interface[10]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ElevationGrid_xDimension(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_xDimension", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_xDimension((const SFInt32&)value);
}

bool ElevationGrid::assign_xSpacing(const SFFloat& value)
{
  // TODO: value range check!
  xSpacing = value;
  status |= xSpacing_updated;
  timestamp = interface[11]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ElevationGrid_xSpacing(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_xSpacing", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_xSpacing((const SFFloat&)value);
}

bool ElevationGrid::assign_zDimension(const SFInt32& value)
{
  // TODO: value range check!
  zDimension = value;
  status |= zDimension_updated;
  timestamp = interface[12]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ElevationGrid_zDimension(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_zDimension", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_zDimension((const SFInt32&)value);
}

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

static bool assign_ElevationGrid_zSpacing(SFNode* node, const fieldValue& value)
{
  ElevationGrid* ElevationGrid_node = dynamic_cast<ElevationGrid*>(node);
  if (!ElevationGrid_node)
    Fatal(-1, "assign_ElevationGrid_zSpacing", "called for a non-ElevationGrid node");
  return ElevationGrid_node->assign_zSpacing((const SFFloat&)value);
}

ElevationGrid::ElevationGrid()
{
  interfaceMember* the_interface[14] = {
    new eventIn("set_height", tMFFloat, process_ElevationGrid_set_height),
    new exposedField("color", fieldValue(&_color), assign_ElevationGrid_color),
    new exposedField("normal", fieldValue(&_normal), assign_ElevationGrid_normal),
    new exposedField("texCoord", fieldValue(&_texCoord), assign_ElevationGrid_texCoord),
    new field("height", fieldValue(&height), assign_ElevationGrid_height),
    new field("ccw", fieldValue(&ccw), assign_ElevationGrid_ccw),
    new field("colorPerVertex", fieldValue(&colorPerVertex), assign_ElevationGrid_colorPerVertex),
    new field("creaseAngle", fieldValue(&creaseAngle), assign_ElevationGrid_creaseAngle),
    new field("normalPerVertex", fieldValue(&normalPerVertex), assign_ElevationGrid_normalPerVertex),
    new field("solid", fieldValue(&solid), assign_ElevationGrid_solid),
    new field("xDimension", fieldValue(&xDimension), assign_ElevationGrid_xDimension),
    new field("xSpacing", fieldValue(&xSpacing), assign_ElevationGrid_xSpacing),
    new field("zDimension", fieldValue(&zDimension), assign_ElevationGrid_zDimension),
    new field("zSpacing", fieldValue(&zSpacing), assign_ElevationGrid_zSpacing),
  };
  SFNode::construct(ElevationGridTypeId, 14, the_interface);

  color = (Color *)0; 	_color = (SFNode *)0;
  normal = (Normal *)0; 	_normal = (SFNode *)0;
  texCoord = (TextureCoordinate *)0; 	_texCoord = (SFNode *)0;
  height = MFFloat(0);
  ccw = 1;
  colorPerVertex = 1;
  creaseAngle = 0;
  normalPerVertex = 1;
  solid = 1;
  xDimension = 0;
  xSpacing = 1;
  zDimension = 0;
  zSpacing = 1;
  
  Geometry::util_init();
  ElevationGrid::util_init();
}

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

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

void ElevationGrid::clone_here(const ElevationGrid& src)
{
  SFNode::clone(src);
  
  interface[1]->value = fieldValue(&_color);
  interface[2]->value = fieldValue(&_normal);
  interface[3]->value = fieldValue(&_texCoord);
  interface[4]->value = fieldValue(&height);
  interface[5]->value = fieldValue(&ccw);
  interface[6]->value = fieldValue(&colorPerVertex);
  interface[7]->value = fieldValue(&creaseAngle);
  interface[8]->value = fieldValue(&normalPerVertex);
  interface[9]->value = fieldValue(&solid);
  interface[10]->value = fieldValue(&xDimension);
  interface[11]->value = fieldValue(&xSpacing);
  interface[12]->value = fieldValue(&zDimension);
  interface[13]->value = fieldValue(&zSpacing);
  
  color = src.color;	  _color = src._color;
  normal = src.normal;	  _normal = src._normal;
  texCoord = src.texCoord;	  _texCoord = src._texCoord;
  height = src.height;
  ccw = src.ccw;
  colorPerVertex = src.colorPerVertex;
  creaseAngle = src.creaseAngle;
  normalPerVertex = src.normalPerVertex;
  solid = src.solid;
  xDimension = src.xDimension;
  xSpacing = src.xSpacing;
  zDimension = src.zDimension;
  zSpacing = src.zSpacing;
  
  Geometry::util_clone(src);
  ElevationGrid::util_clone(src);
}

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

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

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

}  // namespace xrml
