Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07 / src / synfig / valuenode_exp.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_exp.cpp
3 **      \brief Template File
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_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 x)
106 {
107         assert(i==0 || i==1);
108         if(i==0)
109         {
110                 exp_=x;
111                 signal_child_changed()(i);signal_value_changed()();
112                 return true;
113         }
114         if(i==1)
115         {
116                 scale_=x;
117                 signal_child_changed()(i);signal_value_changed()();
118                 return true;
119         }
120         return false;
121 }
122
123 ValueNode::LooseHandle
124 ValueNode_Exp::get_link_vfunc(int i)const
125 {
126         assert(i==0 || i==1);
127         if(i==0)
128                 return exp_;
129         if(i==1)
130                 return scale_;
131
132         return 0;
133 }
134
135 int
136 ValueNode_Exp::link_count()const
137 {
138         return 2;
139 }
140
141 String
142 ValueNode_Exp::link_name(int i)const
143 {
144         assert(i==0 || i==1);
145         if(i==0)
146                 return "exp";
147         if(i==1)
148                 return "scale";
149         return String();
150 }
151
152 String
153 ValueNode_Exp::link_local_name(int i)const
154 {
155         assert(i==0 || i==1);
156         if(i==0)
157                 return _("Exponent");
158         if(i==1)
159                 return _("Scale");
160         return String();
161 }
162
163 int
164 ValueNode_Exp::get_link_index_from_name(const String &name)const
165 {
166         if(name=="exp")
167                 return 0;
168         if(name=="scale")
169                 return 1;
170
171         throw Exception::BadLinkName(name);
172 }
173
174 bool
175 ValueNode_Exp::check_type(ValueBase::Type type)
176 {
177         return type==ValueBase::TYPE_REAL;
178 }