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

#include "TimeSensor.H"
#include "xrmlP.H"

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

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

static bool assign_TimeSensor_cycleInterval(SFNode* node, const fieldValue& value)
{
  TimeSensor* TimeSensor_node = dynamic_cast<TimeSensor*>(node);
  if (!TimeSensor_node)
    Fatal(-1, "assign_TimeSensor_cycleInterval", "called for a non-TimeSensor node");
  return TimeSensor_node->assign_cycleInterval((const SFTime&)value);
}

void TimeSensor::set_cycleInterval(const SFTime& val)
{
  SFTime tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

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

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

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

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

static bool assign_TimeSensor_loop(SFNode* node, const fieldValue& value)
{
  TimeSensor* TimeSensor_node = dynamic_cast<TimeSensor*>(node);
  if (!TimeSensor_node)
    Fatal(-1, "assign_TimeSensor_loop", "called for a non-TimeSensor node");
  return TimeSensor_node->assign_loop((const SFBool&)value);
}

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

static bool assign_TimeSensor_startTime(SFNode* node, const fieldValue& value)
{
  TimeSensor* TimeSensor_node = dynamic_cast<TimeSensor*>(node);
  if (!TimeSensor_node)
    Fatal(-1, "assign_TimeSensor_startTime", "called for a non-TimeSensor node");
  return TimeSensor_node->assign_startTime((const SFTime&)value);
}

void TimeSensor::set_startTime(const SFTime& val)
{
  SFTime tmpval(val);
  fieldValue v(&tmpval);
  interface[3]->assign(this, v);
}

static bool assign_TimeSensor_stopTime(SFNode* node, const fieldValue& value)
{
  TimeSensor* TimeSensor_node = dynamic_cast<TimeSensor*>(node);
  if (!TimeSensor_node)
    Fatal(-1, "assign_TimeSensor_stopTime", "called for a non-TimeSensor node");
  return TimeSensor_node->assign_stopTime((const SFTime&)value);
}

void TimeSensor::set_stopTime(const SFTime& val)
{
  SFTime tmpval(val);
  fieldValue v(&tmpval);
  interface[4]->assign(this, v);
}

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

void TimeSensor::post_cycleTime(const SFTime& val)
{
  cycleTime = val;
  status |= cycleTime_updated;
  post_cycleTime();
}

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

void TimeSensor::post_fraction_changed(const SFFloat& val)
{
  fraction_changed = val;
  status |= fraction_changed_updated;
  post_fraction_changed();
}

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

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

void TimeSensor::post_time(void)
{
  interface[8]->post(this, interface[8]->value);
}

void TimeSensor::post_time(const SFTime& val)
{
  time = val;
  status |= time_updated;
  post_time();
}

TimeSensor::TimeSensor()
{
  interfaceMember* the_interface[9] = {
    new exposedField("cycleInterval", fieldValue(&cycleInterval), assign_TimeSensor_cycleInterval),
    new exposedField("enabled", fieldValue(&enabled), assign_TimeSensor_enabled),
    new exposedField("loop", fieldValue(&loop), assign_TimeSensor_loop),
    new exposedField("startTime", fieldValue(&startTime), assign_TimeSensor_startTime),
    new exposedField("stopTime", fieldValue(&stopTime), assign_TimeSensor_stopTime),
    new eventOut("cycleTime", fieldValue(&cycleTime)),
    new eventOut("fraction_changed", fieldValue(&fraction_changed)),
    new eventOut("isActive", fieldValue(&isActive)),
    new eventOut("time", fieldValue(&time)),
  };
  SFNode::construct(TimeSensorTypeId, 9, the_interface);

  cycleInterval = 1;
  enabled = 1;
  loop = 0;
  startTime = 0;
  stopTime = 0;
  cycleTime = 0;
  fraction_changed = 0;
  isActive = 0;
  time = 0;
  
  TimeDependent::util_init();
  Sensor::util_init();
  EnvironmentalSensor::util_init();
  Children::util_init();
  TimeSensor::util_init();
}

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

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

void TimeSensor::clone_here(const TimeSensor& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&cycleInterval);
  interface[1]->value = fieldValue(&enabled);
  interface[2]->value = fieldValue(&loop);
  interface[3]->value = fieldValue(&startTime);
  interface[4]->value = fieldValue(&stopTime);
  interface[5]->value = fieldValue(&cycleTime);
  interface[6]->value = fieldValue(&fraction_changed);
  interface[7]->value = fieldValue(&isActive);
  interface[8]->value = fieldValue(&time);
  
  cycleInterval = src.cycleInterval;
  enabled = src.enabled;
  loop = src.loop;
  startTime = src.startTime;
  stopTime = src.stopTime;
  cycleTime = src.cycleTime;
  fraction_changed = src.fraction_changed;
  isActive = src.isActive;
  time = src.time;
  
  TimeDependent::util_clone(src);
  Sensor::util_clone(src);
  EnvironmentalSensor::util_clone(src);
  Children::util_clone(src);
  TimeSensor::util_clone(src);
}

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

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

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

}  // namespace xrml
