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 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 set_link("from", ValueNode_Const::create(Real(1.0)));
62 set_link("to", ValueNode_Const::create(x.get(Real())));
63 set_link("step", ValueNode_Const::create(Real(1.0)));
68 ValueNode_Duplicate::create(const ValueBase &x)
70 return new ValueNode_Duplicate(x);
74 ValueNode_Duplicate::create_new()const
76 return new ValueNode_Duplicate(get_type());
79 ValueNode_Duplicate::~ValueNode_Duplicate()
85 ValueNode_Duplicate::set_link_vfunc(int i,ValueNode::Handle x)
87 assert(i>=0 && i<link_count());
91 case 0: from_ = x; break;
92 case 1: to_ = x; break;
93 case 2: step_ = x; break;
94 default: return false;
97 signal_child_changed()(i);
98 signal_value_changed()();
102 ValueNode::LooseHandle
103 ValueNode_Duplicate::get_link_vfunc(int i)const
105 assert(i>=0 && i<link_count());
107 if(i==0) return from_;
109 if(i==2) return step_;
115 ValueNode_Duplicate::link_count()const
121 ValueNode_Duplicate::link_local_name(int i)const
123 assert(i>=0 && i<link_count());
125 if(i==0) return _("From");
126 if(i==1) return _("To");
127 if(i==2) return _("Step");
132 ValueNode_Duplicate::link_name(int i)const
134 assert(i>=0 && i<link_count());
136 if(i==0) return "from";
137 if(i==1) return "to";
138 if(i==2) return "step";
143 ValueNode_Duplicate::get_link_index_from_name(const String &name)const
145 if(name=="from") return 0;
146 if(name=="to") return 1;
147 if(name=="step") return 2;
149 throw Exception::BadLinkName(name);
153 ValueNode_Duplicate::reset_index(Time t)const
155 Real from = (*from_)(t).get(Real());
160 ValueNode_Duplicate::step(Time t)const
162 Real from = (*from_)(t).get(Real());
163 Real to = (*to_ )(t).get(Real());
164 Real step = (*step_)(t).get(Real());
166 if (step == 0) return false;
183 ValueNode_Duplicate::count_steps(Time t)const
185 Real from = (*from_)(t).get(Real());
186 Real to = (*to_ )(t).get(Real());
187 Real step = (*step_)(t).get(Real());
189 if (step == 0) return 1;
191 return abs((from - to) / step) + 1;
195 ValueNode_Duplicate::operator()(Time t)const
201 ValueNode_Duplicate::get_name()const
207 ValueNode_Duplicate::get_local_name()const
209 return _("Duplicate");
213 ValueNode_Duplicate::check_type(ValueBase::Type type)
215 // never offer this as a choice. it's used automatically by the 'Duplicate' layer.