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

#include "Material.H"
#include "xrmlP.H"

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

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

bool Material::assign_ambientIntensity(const SFFloat& value)
{
  // TODO: value range check!
  ambientIntensity = value;
  status |= ambientIntensity_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Material_ambientIntensity(SFNode* node, const fieldValue& value)
{
  Material* Material_node = dynamic_cast<Material*>(node);
  if (!Material_node)
    Fatal(-1, "assign_Material_ambientIntensity", "called for a non-Material node");
  return Material_node->assign_ambientIntensity((const SFFloat&)value);
}

void Material::set_ambientIntensity(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool Material::assign_diffuseColor(const SFColor& value)
{
  // TODO: value range check!
  diffuseColor = value;
  status |= diffuseColor_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Material_diffuseColor(SFNode* node, const fieldValue& value)
{
  Material* Material_node = dynamic_cast<Material*>(node);
  if (!Material_node)
    Fatal(-1, "assign_Material_diffuseColor", "called for a non-Material node");
  return Material_node->assign_diffuseColor((const SFColor&)value);
}

void Material::set_diffuseColor(const SFColor& val)
{
  SFColor tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

bool Material::assign_emissiveColor(const SFColor& value)
{
  // TODO: value range check!
  emissiveColor = value;
  status |= emissiveColor_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Material_emissiveColor(SFNode* node, const fieldValue& value)
{
  Material* Material_node = dynamic_cast<Material*>(node);
  if (!Material_node)
    Fatal(-1, "assign_Material_emissiveColor", "called for a non-Material node");
  return Material_node->assign_emissiveColor((const SFColor&)value);
}

void Material::set_emissiveColor(const SFColor& val)
{
  SFColor tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

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

static bool assign_Material_shininess(SFNode* node, const fieldValue& value)
{
  Material* Material_node = dynamic_cast<Material*>(node);
  if (!Material_node)
    Fatal(-1, "assign_Material_shininess", "called for a non-Material node");
  return Material_node->assign_shininess((const SFFloat&)value);
}

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

bool Material::assign_specularColor(const SFColor& value)
{
  // TODO: value range check!
  specularColor = value;
  status |= specularColor_updated;
  timestamp = interface[4]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Material_specularColor(SFNode* node, const fieldValue& value)
{
  Material* Material_node = dynamic_cast<Material*>(node);
  if (!Material_node)
    Fatal(-1, "assign_Material_specularColor", "called for a non-Material node");
  return Material_node->assign_specularColor((const SFColor&)value);
}

void Material::set_specularColor(const SFColor& val)
{
  SFColor tmpval(val);
  fieldValue v(&tmpval);
  interface[4]->assign(this, v);
}

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

static bool assign_Material_transparency(SFNode* node, const fieldValue& value)
{
  Material* Material_node = dynamic_cast<Material*>(node);
  if (!Material_node)
    Fatal(-1, "assign_Material_transparency", "called for a non-Material node");
  return Material_node->assign_transparency((const SFFloat&)value);
}

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

Material::Material()
{
  interfaceMember* the_interface[6] = {
    new exposedField("ambientIntensity", fieldValue(&ambientIntensity), assign_Material_ambientIntensity),
    new exposedField("diffuseColor", fieldValue(&diffuseColor), assign_Material_diffuseColor),
    new exposedField("emissiveColor", fieldValue(&emissiveColor), assign_Material_emissiveColor),
    new exposedField("shininess", fieldValue(&shininess), assign_Material_shininess),
    new exposedField("specularColor", fieldValue(&specularColor), assign_Material_specularColor),
    new exposedField("transparency", fieldValue(&transparency), assign_Material_transparency),
  };
  SFNode::construct(MaterialTypeId, 6, the_interface);

  ambientIntensity = 0.2;
  diffuseColor = SFColor(0.8,0.8,0.8);
  emissiveColor = SFColor(0,0,0);
  shininess = 0.2;
  specularColor = SFColor(0,0,0);
  transparency = 0;
  
  Material::util_init();
}

void Material::destruct(void)
{
  Material::util_destruct();
  SFNode::destruct();
}

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

void Material::clone_here(const Material& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&ambientIntensity);
  interface[1]->value = fieldValue(&diffuseColor);
  interface[2]->value = fieldValue(&emissiveColor);
  interface[3]->value = fieldValue(&shininess);
  interface[4]->value = fieldValue(&specularColor);
  interface[5]->value = fieldValue(&transparency);
  
  ambientIntensity = src.ambientIntensity;
  diffuseColor = src.diffuseColor;
  emissiveColor = src.emissiveColor;
  shininess = src.shininess;
  specularColor = src.specularColor;
  transparency = src.transparency;
  
  Material::util_clone(src);
}

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

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

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

}  // namespace xrml
