7b96298a06fb49be14b35c5ac7027b422e4379b3
[synfig.git] / synfig-core / src / synfig / valuenode_exp.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_exp.cpp
3 **      \brief Implementation of the "Exponential" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_exp.h"
34 #include "valuenode_const.h"
35 #include "general.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44
45 /* === M A C R O S ========================================================= */
46
47 /* === G L O B A L S ======================================================= */
48
49 /* === P R O C E D U R E S ================================================= */
50
51 /* === M E T H O D S ======================================================= */
52
53 ValueNode_Exp::ValueNode_Exp(const ValueBase &value):
54         LinkableValueNode(value.get_type())
55 {
56         switch(value.get_type())
57         {
58         case ValueBase::TYPE_REAL:
59                 set_link("exp",ValueNode_Const::create(Real(0)));
60                 set_link("scale",ValueNode_Const::create(value.get(Real())));
61                 break;
62         default:
63                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
64         }
65 }
66
67 LinkableValueNode*
68 ValueNode_Exp::create_new()const
69 {
70         return new ValueNode_Exp(get_type());
71 }
72
73 ValueNode_Exp*
74 ValueNode_Exp::create(const ValueBase &x)
75 {
76         return new ValueNode_Exp(x);
77 }
78
79 ValueNode_Exp::~ValueNode_Exp()
80 {
81         unlink_all();
82 }
83
84 ValueBase
85 ValueNode_Exp::operator()(Time t)const
86 {
87         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
88                 printf("%s:%d operator()\n", __FILE__, __LINE__);
89
90         return (exp((*exp_)(t).get(Real())) *
91                         (*scale_)(t).get(Real()));
92 }
93
94 String
95 ValueNode_Exp::get_name()const
96 {
97         return "exp";
98 }
99
100 String
101 ValueNode_Exp::get_local_name()const
102 {
103         return _("Exponential");
104 }
105
106 bool
107 ValueNode_Exp::set_link_vfunc(int i,ValueNode::Handle value)
108 {
109         assert(i>=0 && i<link_count());
110
111         switch(i)
112         {
113         case 0: CHECK_TYPE_AND_SET_VALUE(exp_,   ValueBase::TYPE_REAL);
114         case 1: CHECK_TYPE_AND_SET_VALUE(scale_, ValueBase::TYPE_REAL);
115         }
116         return false;
117 }
118
119 ValueNode::LooseHandle
120 ValueNode_Exp::get_link_vfunc(int i)const
121 {
122         assert(i>=0 && i<link_count());
123
124         if(i==0)
125                 return exp_;
126         if(i==1)
127                 return scale_;
128
129         return 0;
130 }
131
132 int
133 ValueNode_Exp::link_count()const
134 {
135         return 2;
136 }
137
138 String
139 ValueNode_Exp::link_name(int i)const
140 {
141         assert(i>=0 && i<link_count());
142
143         if(i==0)
144                 return "exp";
145         if(i==1)
146                 return "scale";
147         return String();
148 }
149
150 String
151 ValueNode_Exp::link_local_name(int i)const
152 {
153         assert(i>=0 && i<link_count());
154
155         if(i==0)
156                 return _("Exponent");
157         if(i==1)
158                 return _("Scale");
159         return String();
160 }
161
162 int
163 ValueNode_Exp::get_link_index_from_name(const String &name)const
164 {
165         if(name=="exp")
166                 return 0;
167         if(name=="scale")
168                 return 1;
169
170         throw Exception::BadLinkName(name);
171 }
172
173 bool
174 ValueNode_Exp::check_type(ValueBase::Type type)
175 {
176         return type==ValueBase::TYPE_REAL;
177 }
178
179 LinkableValueNode::Vocab
180 ValueNode_Exp::get_children_vocab_vfunc()const
181 {
182         LinkableValueNode::Vocab ret;
183
184         ret.push_back(ParamDesc(ValueBase(),"exp")
185                 .set_local_name(_("Exponent"))
186                 .set_description(_("The value to raise the constant 'e'"))
187         );
188
189         ret.push_back(ParamDesc(ValueBase(),"scale")
190                 .set_local_name(_("Scale"))
191                 .set_description(_("Multiplier of the resulting exponent"))
192         );
193
194         return ret;
195 }