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

#include "Text.H"
#include "xrmlP.H"

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

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

bool Text::assign_string(const MFString& value)
{
  // TODO: value range check!
  string = value;
  status |= string_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Text_string(SFNode* node, const fieldValue& value)
{
  Text* Text_node = dynamic_cast<Text*>(node);
  if (!Text_node)
    Fatal(-1, "assign_Text_string", "called for a non-Text node");
  return Text_node->assign_string((const MFString&)value);
}

void Text::set_string(const MFString& val)
{
  MFString tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

void Text::synchronize_fontStyle(void)
{
  fontStyle = (_fontStyle) ? dynamic_cast<FontStyle*>(_fontStyle->firstnode()) : 0;
}

bool Text::assign_fontStyle(SFNode* value)
{
  SFNode* oldval = _fontStyle;
  _fontStyle = value;
  if (checkValue(_fontStyle, IsFontStyle, "Text.fontStyle", "FontStyle")) {
    synchronize_fontStyle();
    status |= fontStyle_updated;
    timestamp = interface[1]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _fontStyle = oldval;
    return false;
  }
}

static bool assign_Text_fontStyle(SFNode* node, const fieldValue& value)
{
  Text* Text_node = dynamic_cast<Text*>(node);
  if (!Text_node)
    Fatal(-1, "assign_Text_fontStyle", "called for a non-Text node");
  return Text_node->assign_fontStyle((SFNode*&)value);
}

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

bool Text::assign_length(const MFFloat& value)
{
  // TODO: value range check!
  length = value;
  status |= length_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Text_length(SFNode* node, const fieldValue& value)
{
  Text* Text_node = dynamic_cast<Text*>(node);
  if (!Text_node)
    Fatal(-1, "assign_Text_length", "called for a non-Text node");
  return Text_node->assign_length((const MFFloat&)value);
}

void Text::set_length(const MFFloat& val)
{
  MFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

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

static bool assign_Text_maxExtent(SFNode* node, const fieldValue& value)
{
  Text* Text_node = dynamic_cast<Text*>(node);
  if (!Text_node)
    Fatal(-1, "assign_Text_maxExtent", "called for a non-Text node");
  return Text_node->assign_maxExtent((const SFFloat&)value);
}

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

Text::Text()
{
  interfaceMember* the_interface[4] = {
    new exposedField("string", fieldValue(&string), assign_Text_string),
    new exposedField("fontStyle", fieldValue(&_fontStyle), assign_Text_fontStyle),
    new exposedField("length", fieldValue(&length), assign_Text_length),
    new exposedField("maxExtent", fieldValue(&maxExtent), assign_Text_maxExtent),
  };
  SFNode::construct(TextTypeId, 4, the_interface);

  string = MFString(0);
  fontStyle = (FontStyle *)0; 	_fontStyle = (SFNode *)0;
  length = MFFloat(0);
  maxExtent = 0;
  
  Geometry::util_init();
  Text::util_init();
}

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

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

void Text::clone_here(const Text& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&string);
  interface[1]->value = fieldValue(&_fontStyle);
  interface[2]->value = fieldValue(&length);
  interface[3]->value = fieldValue(&maxExtent);
  
  string = src.string;
  fontStyle = src.fontStyle;	  _fontStyle = src._fontStyle;
  length = src.length;
  maxExtent = src.maxExtent;
  
  Geometry::util_clone(src);
  Text::util_clone(src);
}

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

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

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

}  // namespace xrml
