Added copyright lines for files I've edited this year.
[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 **      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(1)));
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         DCAST_HACK_ENABLE();
67 }
68
69 LinkableValueNode*
70 ValueNode_Exp::create_new()const
71 {
72         return new ValueNode_Exp(get_type());
73 }
74
75 ValueNode_Exp*
76 ValueNode_Exp::create(const ValueBase &x)
77 {
78         return new ValueNode_Exp(x);
79 }
80
81 ValueNode_Exp::~ValueNode_Exp()
82 {
83         unlink_all();
84 }
85
86 ValueBase
87 ValueNode_Exp::operator()(Time t)const
88 {
89         return (exp((*exp_)(t).get(Real())) *
90                         (*scale_)(t).get(Real()));
91 }
92
93 String
94 ValueNode_Exp::get_name()const
95 {
96         return "exp";
97 }
98
99 String
100 ValueNode_Exp::get_local_name()const
101 {
102         return _("Exponential");
103 }
104
105 bool
106 ValueNode_Exp::set_link_vfunc(int i,ValueNode::Handle value)
107 {
108         assert(i>=0 && i<link_count());
109
110         switch(i)
111         {
112         case 0: CHECK_TYPE_AND_SET_VALUE(exp_,   ValueBase::TYPE_REAL);
113         case 1: CHECK_TYPE_AND_SET_VALUE(scale_, ValueBase::TYPE_REAL);
114         }
115         return false;
116 }
117
118 ValueNode::LooseHandle
119 ValueNode_Exp::get_link_vfunc(int i)const
120 {
121         assert(i>=0 && i<link_count());
122
123         if(i==0)
124                 return exp_;
125         if(i==1)
126                 return scale_;
127
128         return 0;
129 }
130
131 int
132 ValueNode_Exp::link_count()const
133 {
134         return 2;
135 }
136
137 String
138 ValueNode_Exp::link_name(int i)const
139 {
140         assert(i>=0 && i<link_count());
141
142         if(i==0)
143                 return "exp";
144         if(i==1)
145                 return "scale";
146         return String();
147 }
148
149 String
150 ValueNode_Exp::link_local_name(int i)const
151 {
152         assert(i>=0 && i<link_count());
153
154         if(i==0)
155                 return _("Exponent");
156         if(i==1)
157                 return _("Scale");
158         return String();
159 }
160
161 int
162 ValueNode_Exp::get_link_index_from_name(const String &name)const
163 {
164         if(name=="exp")
165                 return 0;
166         if(name=="scale")
167                 return 1;
168
169         throw Exception::BadLinkName(name);
170 }
171
172 bool
173 ValueNode_Exp::check_type(ValueBase::Type type)
174 {
175         return type==ValueBase::TYPE_REAL;
176 }