1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_integer.cpp
3 ** \brief Implementation of the "Integer" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_integer.h"
34 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ValueNode_Integer::ValueNode_Integer(const ValueBase::Type &x):
59 ValueNode_Integer::ValueNode_Integer(const ValueBase &x):
60 LinkableValueNode(x.get_type())
62 Vocab ret(get_children_vocab());
63 set_children_vocab(ret);
66 case ValueBase::TYPE_ANGLE:
67 set_link("integer", ValueNode_Const::create(round_to_int(Angle::deg(x.get(Angle())).get())));
69 case ValueBase::TYPE_BOOL:
70 set_link("integer", ValueNode_Const::create(int(x.get(bool()))));
72 case ValueBase::TYPE_REAL:
73 set_link("integer", ValueNode_Const::create(round_to_int(x.get(Real()))));
75 case ValueBase::TYPE_TIME:
76 set_link("integer", ValueNode_Const::create(round_to_int(x.get(Time()))));
80 throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(x.get_type()));
85 ValueNode_Integer::create(const ValueBase &x)
87 return new ValueNode_Integer(x);
91 ValueNode_Integer::create_new()const
93 return new ValueNode_Integer(get_type());
96 ValueNode_Integer::~ValueNode_Integer()
102 ValueNode_Integer::set_link_vfunc(int i,ValueNode::Handle value)
104 assert(i>=0 && i<link_count());
108 case 0: CHECK_TYPE_AND_SET_VALUE(integer_, get_type());
113 ValueNode::LooseHandle
114 ValueNode_Integer::get_link_vfunc(int i)const
116 assert(i>=0 && i<link_count());
118 if(i==0) return integer_;
124 ValueNode_Integer::operator()(Time t)const
126 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
127 printf("%s:%d operator()\n", __FILE__, __LINE__);
129 int integer = (*integer_)(t).get(int());
133 case ValueBase::TYPE_ANGLE:
134 return Angle::deg(integer);
135 case ValueBase::TYPE_BOOL:
136 return bool(integer);
137 case ValueBase::TYPE_REAL:
138 return Real(integer);
139 case ValueBase::TYPE_TIME:
140 return Time(integer);
143 throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(get_type()));
148 ValueNode_Integer::get_name()const
154 ValueNode_Integer::get_local_name()const
156 return _("From Integer");
159 // don't show this to the user at the moment - maybe it's not very useful
161 ValueNode_Integer::check_type(ValueBase::Type type __attribute__ ((unused)))
165 // type==ValueBase::TYPE_ANGLE ||
166 // type==ValueBase::TYPE_BOOL ||
167 // type==ValueBase::TYPE_REAL ||
168 // type==ValueBase::TYPE_TIME;
171 LinkableValueNode::Vocab
172 ValueNode_Integer::get_children_vocab_vfunc()const
174 if(children_vocab.size())
175 return children_vocab;
177 LinkableValueNode::Vocab ret;
179 ret.push_back(ParamDesc(ValueBase(),"integer")
180 .set_local_name(_("Integer"))
181 .set_description(_("The integer value to be converted"))