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

#include "ProximitySensor.H"
#include "xrmlP.H"

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

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

bool ProximitySensor::assign_center(const SFVec3f& value)
{
  // TODO: value range check!
  center = value;
  status |= center_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ProximitySensor_center(SFNode* node, const fieldValue& value)
{
  ProximitySensor* ProximitySensor_node = dynamic_cast<ProximitySensor*>(node);
  if (!ProximitySensor_node)
    Fatal(-1, "assign_ProximitySensor_center", "called for a non-ProximitySensor node");
  return ProximitySensor_node->assign_center((const SFVec3f&)value);
}

void ProximitySensor::set_center(const SFVec3f& val)
{
  SFVec3f tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool ProximitySensor::assign_size(const SFVec3f& value)
{
  // TODO: value range check!
  size = value;
  status |= size_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ProximitySensor_size(SFNode* node, const fieldValue& value)
{
  ProximitySensor* ProximitySensor_node = dynamic_cast<ProximitySensor*>(node);
  if (!ProximitySensor_node)
    Fatal(-1, "assign_ProximitySensor_size", "called for a non-ProximitySensor node");
  return ProximitySensor_node->assign_size((const SFVec3f&)value);
}

void ProximitySensor::set_size(const SFVec3f& val)
{
  SFVec3f tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

bool ProximitySensor::assign_enabled(const SFBool& value)
{
  // TODO: value range check!
  enabled = value;
  status |= enabled_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_ProximitySensor_enabled(SFNode* node, const fieldValue& value)
{
  ProximitySensor* ProximitySensor_node = dynamic_cast<ProximitySensor*>(node);
  if (!ProximitySensor_node)
    Fatal(-1, "assign_ProximitySensor_enabled", "called for a non-ProximitySensor node");
  return ProximitySensor_node->assign_enabled((const SFBool&)value);
}

void ProximitySensor::set_enabled(const SFBool& val)
{
  SFBool tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

void ProximitySensor::post_isActive(void)
{
  interface[3]->post(this, interface[3]->value);
}

void ProximitySensor::post_isActive(const SFBool& val)
{
  isActive = val;
  status |= isActive_updated;
  post_isActive();
}

void ProximitySensor::post_position_changed(void)
{
  interface[4]->post(this, interface[4]->value);
}

void ProximitySensor::post_position_changed(const SFVec3f& val)
{
  position_changed = val;
  status |= position_changed_updated;
  post_position_changed();
}

void ProximitySensor::post_orientation_changed(void)
{
  interface[5]->post(this, interface[5]->value);
}

void ProximitySensor::post_orientation_changed(const SFRotation& val)
{
  orientation_changed = val;
  status |= orientation_changed_updated;
  post_orientation_changed();
}

void ProximitySensor::post_enterTime(void)
{
  interface[6]->post(this, interface[6]->value);
}

void ProximitySensor::post_enterTime(const SFTime& val)
{
  enterTime = val;
  status |= enterTime_updated;
  post_enterTime();
}

void ProximitySensor::post_exitTime(void)
{
  interface[7]->post(this, interface[7]->value);
}

void ProximitySensor::post_exitTime(const SFTime& val)
{
  exitTime = val;
  status |= exitTime_updated;
  post_exitTime();
}

ProximitySensor::ProximitySensor()
{
  interfaceMember* the_interface[8] = {
    new exposedField("center", fieldValue(&center), assign_ProximitySensor_center),
    new exposedField("size", fieldValue(&size), assign_ProximitySensor_size),
    new exposedField("enabled", fieldValue(&enabled), assign_ProximitySensor_enabled),
    new eventOut("isActive", fieldValue(&isActive)),
    new eventOut("position_changed", fieldValue(&position_changed)),
    new eventOut("orientation_changed", fieldValue(&orientation_changed)),
    new eventOut("enterTime", fieldValue(&enterTime)),
    new eventOut("exitTime", fieldValue(&exitTime)),
  };
  SFNode::construct(ProximitySensorTypeId, 8, the_interface);

  center = SFVec3f(0,0,0);
  size = SFVec3f(0,0,0);
  enabled = 1;
  isActive = 0;
  position_changed = SFVec3f(0,0,0);
  orientation_changed = SFRotation(0,0,0,0);
  enterTime = 0;
  exitTime = 0;
  
  Sensor::util_init();
  EnvironmentalSensor::util_init();
  Children::util_init();
  ProximitySensor::util_init();
}

void ProximitySensor::destruct(void)
{
  ProximitySensor::util_destruct();
  EnvironmentalSensor::util_destruct();
  Sensor::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void ProximitySensor::clone_here(const ProximitySensor& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&center);
  interface[1]->value = fieldValue(&size);
  interface[2]->value = fieldValue(&enabled);
  interface[3]->value = fieldValue(&isActive);
  interface[4]->value = fieldValue(&position_changed);
  interface[5]->value = fieldValue(&orientation_changed);
  interface[6]->value = fieldValue(&enterTime);
  interface[7]->value = fieldValue(&exitTime);
  
  center = src.center;
  size = src.size;
  enabled = src.enabled;
  isActive = src.isActive;
  position_changed = src.position_changed;
  orientation_changed = src.orientation_changed;
  enterTime = src.enterTime;
  exitTime = src.exitTime;
  
  Sensor::util_clone(src);
  EnvironmentalSensor::util_clone(src);
  Children::util_clone(src);
  ProximitySensor::util_clone(src);
}

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

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

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

}  // namespace xrml
