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

#include "Shape.H"
#include "xrmlP.H"

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

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

void Shape::synchronize_appearance(void)
{
  appearance = (_appearance) ? dynamic_cast<AppearanceBase*>(_appearance->firstnode()) : 0;
}

bool Shape::assign_appearance(SFNode* value)
{
  SFNode* oldval = _appearance;
  _appearance = value;
  if (checkValue(_appearance, IsAppearanceBase, "Shape.appearance", "AppearanceBase")) {
    synchronize_appearance();
    status |= appearance_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _appearance = oldval;
    return false;
  }
}

static bool assign_Shape_appearance(SFNode* node, const fieldValue& value)
{
  Shape* Shape_node = dynamic_cast<Shape*>(node);
  if (!Shape_node)
    Fatal(-1, "assign_Shape_appearance", "called for a non-Shape node");
  return Shape_node->assign_appearance((SFNode*&)value);
}

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

void Shape::synchronize_geometry(void)
{
  geometry = (_geometry) ? dynamic_cast<Geometry*>(_geometry->firstnode()) : 0;
}

bool Shape::assign_geometry(SFNode* value)
{
  SFNode* oldval = _geometry;
  _geometry = value;
  if (checkValue(_geometry, IsGeometry, "Shape.geometry", "Geometry")) {
    synchronize_geometry();
    status |= geometry_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _geometry = oldval;
    return false;
  }
}

static bool assign_Shape_geometry(SFNode* node, const fieldValue& value)
{
  Shape* Shape_node = dynamic_cast<Shape*>(node);
  if (!Shape_node)
    Fatal(-1, "assign_Shape_geometry", "called for a non-Shape node");
  return Shape_node->assign_geometry((SFNode*&)value);
}

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

Shape::Shape()
{
  interfaceMember* the_interface[2] = {
    new exposedField("appearance", fieldValue(&_appearance), assign_Shape_appearance),
    new exposedField("geometry", fieldValue(&_geometry), assign_Shape_geometry),
  };
  SFNode::construct(ShapeTypeId, 2, the_interface);

  appearance = (AppearanceBase *)0; 	_appearance = (SFNode *)0;
  geometry = (Geometry *)0; 	_geometry = (SFNode *)0;
  
  Children::util_init();
  Shape::util_init();
}

void Shape::destruct(void)
{
  Shape::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void Shape::clone_here(const Shape& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_appearance);
  interface[1]->value = fieldValue(&_geometry);
  
  appearance = src.appearance;	  _appearance = src._appearance;
  geometry = src.geometry;	  _geometry = src._geometry;
  
  Children::util_clone(src);
  Shape::util_clone(src);
}

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

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

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

}  // namespace xrml
