1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_duplicate.cpp
3 ** \brief Implementation of the "Duplicate" 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_duplicate.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_Duplicate::ValueNode_Duplicate(const ValueBase::Type &x):
58 ValueNode_Duplicate::ValueNode_Duplicate(const ValueBase &x):
59 LinkableValueNode(x.get_type())
61 Vocab ret(get_children_vocab());
62 set_children_vocab(ret);
63 set_link("from", ValueNode_Const::create(Real(1.0)));
64 set_link("to", ValueNode_Const::create(x.get(Real())));
65 set_link("step", ValueNode_Const::create(Real(1.0)));
70 ValueNode_Duplicate::create(const ValueBase &x)
72 return new ValueNode_Duplicate(x);
76 ValueNode_Duplicate::create_new()const
78 return new ValueNode_Duplicate(get_type());
81 ValueNode_Duplicate::~ValueNode_Duplicate()
87 ValueNode_Duplicate::set_link_vfunc(int i,ValueNode::Handle value)
89 assert(i>=0 && i<link_count());
93 case 0: CHECK_TYPE_AND_SET_VALUE(from_, ValueBase::TYPE_REAL);
94 case 1: CHECK_TYPE_AND_SET_VALUE(to_, ValueBase::TYPE_REAL);
95 case 2: CHECK_TYPE_AND_SET_VALUE(step_, ValueBase::TYPE_REAL);
100 ValueNode::LooseHandle
101 ValueNode_Duplicate::get_link_vfunc(int i)const
103 assert(i>=0 && i<link_count());
105 if(i==0) return from_;
107 if(i==2) return step_;
113 ValueNode_Duplicate::reset_index(Time t)const
115 Real from = (*from_)(t).get(Real());
120 ValueNode_Duplicate::step(Time t)const
122 Real from = (*from_)(t).get(Real());
123 Real to = (*to_ )(t).get(Real());
124 Real step = (*step_)(t).get(Real());
127 if (step == 0) return false;
133 if ((index += step) <= to) return true;
136 if ((index -= step) >= to) return true;
138 // at the end of the loop, leave the index at the last value that was used
144 ValueNode_Duplicate::count_steps(Time t)const
146 Real from = (*from_)(t).get(Real());
147 Real to = (*to_ )(t).get(Real());
148 Real step = (*step_)(t).get(Real());
150 if (step == 0) return 1;
152 return abs((from - to) / step) + 1;
156 ValueNode_Duplicate::operator()(Time t __attribute__ ((unused)))const
158 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
159 printf("%s:%d operator()\n", __FILE__, __LINE__);
165 ValueNode_Duplicate::get_name()const
171 ValueNode_Duplicate::get_local_name()const
173 return _("Duplicate");
177 ValueNode_Duplicate::check_type(ValueBase::Type type __attribute__ ((unused)))
179 // never offer this as a choice. it's used automatically by the 'Duplicate' layer.
183 LinkableValueNode::Vocab
184 ValueNode_Duplicate::get_children_vocab_vfunc()const
186 if(children_vocab.size())
187 return children_vocab;
189 LinkableValueNode::Vocab ret;
191 ret.push_back(ParamDesc(ValueBase(),"from")
192 .set_local_name(_("From"))
193 .set_description(_("Initial value of the index "))
196 ret.push_back(ParamDesc(ValueBase(),"to")
197 .set_local_name(_("To"))
198 .set_description(_("Final value of the index"))
201 ret.push_back(ParamDesc(ValueBase(),"step")
202 .set_local_name(_("Step"))
203 .set_description(_("Amount increment of the index"))