33e9a37adc11bbf2128049569e795517cc262c3d
[synfig.git] / synfig-core / trunk / 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 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuenode_exp.h"
33 #include "valuenode_const.h"
34 #include "general.h"
35
36 #endif
37
38 /* === U S I N G =========================================================== */
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 /* === P R O C E D U R E S ================================================= */
49
50 /* === M E T H O D S ======================================================= */
51
52 ValueNode_Exp::ValueNode_Exp(const ValueBase &value):
53         LinkableValueNode(value.get_type())
54 {
55         switch(value.get_type())
56         {
57         case ValueBase::TYPE_REAL:
58                 set_link("exp",ValueNode_Const::create(Real(1)));
59                 set_link("scale",ValueNode_Const::create(value.get(Real())));
60                 break;
61         default:
62                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
63         }
64
65         DCAST_HACK_ENABLE();
66 }
67
68 LinkableValueNode*
69 ValueNode_Exp::create_new()const
70 {
71         return new ValueNode_Exp(get_type());
72 }
73
74 ValueNode_Exp*
75 ValueNode_Exp::create(const ValueBase &x)
76 {
77         return new ValueNode_Exp(x);
78 }
79
80 ValueNode_Exp::~ValueNode_Exp()
81 {
82         unlink_all();
83 }
84
85 ValueBase
86 ValueNode_Exp::operator()(Time t)const
87 {
88         return (exp((*exp_)(t).get(Real())) *
89                         (*scale_)(t).get(Real()));
90 }
91
92 String
93 ValueNode_Exp::get_name()const
94 {
95         return "exp";
96 }
97
98 String
99 ValueNode_Exp::get_local_name()const
100 {
101         return _("Exponential");
102 }
103
104 bool
105 ValueNode_Exp::set_link_vfunc(int i,ValueNode::Handle value)
106 {
107         assert(i>=0 && i<link_count());
108
109         switch(i)
110         {
111         case 0: CHECK_TYPE_AND_SET_VALUE(exp_,   ValueBase::TYPE_REAL);
112         case 1: CHECK_TYPE_AND_SET_VALUE(scale_, ValueBase::TYPE_REAL);
113         }
114         return false;
115 }
116
117 ValueNode::LooseHandle
118 ValueNode_Exp::get_link_vfunc(int i)const
119 {
120         assert(i>=0 && i<link_count());
121
122         if(i==0)
123                 return exp_;
124         if(i==1)
125                 return scale_;
126
127         return 0;
128 }
129
130 int
131 ValueNode_Exp::link_count()const
132 {
133         return 2;
134 }
135
136 String
137 ValueNode_Exp::link_name(int i)const
138 {
139         assert(i>=0 && i<link_count());
140
141         if(i==0)
142                 return "exp";
143         if(i==1)
144                 return "scale";
145         return String();
146 }
147
148 String
149 ValueNode_Exp::link_local_name(int i)const
150 {
151         assert(i>=0 && i<link_count());
152
153         if(i==0)
154                 return _("Exponent");
155         if(i==1)
156                 return _("Scale");
157         return String();
158 }
159
160 int
161 ValueNode_Exp::get_link_index_from_name(const String &name)const
162 {
163         if(name=="exp")
164                 return 0;
165         if(name=="scale")
166                 return 1;
167
168         throw Exception::BadLinkName(name);
169 }
170
171 bool
172 ValueNode_Exp::check_type(ValueBase::Type type)
173 {
174         return type==ValueBase::TYPE_REAL;
175 }