Rename get_param_vocab to get_children_vocab and use a wrapper for the pure virtual...
[synfig.git] / synfig-core / src / synfig / valuenode_cos.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_cos.cpp
3 **      \brief Implementation of the "Cos" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 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_cos.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_Cos::ValueNode_Cos(const ValueBase &value):
54         LinkableValueNode(value.get_type())
55 {
56         switch(value.get_type())
57         {
58         case ValueBase::TYPE_REAL:
59                 set_link("angle",ValueNode_Const::create(Angle::deg(0)));
60                 set_link("amp",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_Cos::create_new()const
69 {
70         return new ValueNode_Cos(get_type());
71 }
72
73 ValueNode_Cos*
74 ValueNode_Cos::create(const ValueBase &x)
75 {
76         return new ValueNode_Cos(x);
77 }
78
79 ValueNode_Cos::~ValueNode_Cos()
80 {
81         unlink_all();
82 }
83
84 ValueBase
85 ValueNode_Cos::operator()(Time t)const
86 {
87         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
88                 printf("%s:%d operator()\n", __FILE__, __LINE__);
89
90         return
91                 Angle::cos(
92                         (*angle_)(t).get(Angle())
93                 ).get() * (*amp_)(t).get(Real());
94 }
95
96
97 String
98 ValueNode_Cos::get_name()const
99 {
100         return "cos";
101 }
102
103 String
104 ValueNode_Cos::get_local_name()const
105 {
106         return _("Cos");
107 }
108
109 bool
110 ValueNode_Cos::check_type(ValueBase::Type type)
111 {
112         return type==ValueBase::TYPE_REAL;
113 }
114
115 bool
116 ValueNode_Cos::set_link_vfunc(int i,ValueNode::Handle value)
117 {
118         assert(i>=0 && i<link_count());
119
120         switch(i)
121         {
122         case 0: CHECK_TYPE_AND_SET_VALUE(angle_, ValueBase::TYPE_ANGLE);
123         case 1: CHECK_TYPE_AND_SET_VALUE(amp_,   ValueBase::TYPE_REAL);
124         }
125
126         return false;
127 }
128
129 ValueNode::LooseHandle
130 ValueNode_Cos::get_link_vfunc(int i)const
131 {
132         assert(i>=0 && i<link_count());
133
134         switch(i)
135         {
136         case 0: return angle_;
137         case 1: return amp_;
138         }
139
140         return 0;
141 }
142
143 int
144 ValueNode_Cos::link_count()const
145 {
146         return 2;
147 }
148
149 String
150 ValueNode_Cos::link_name(int i)const
151 {
152         assert(i>=0 && i<link_count());
153
154         switch(i)
155         {
156         case 0: return "angle";
157         case 1: return "amp";
158         }
159
160         return String();
161 }
162
163 String
164 ValueNode_Cos::link_local_name(int i)const
165 {
166         assert(i>=0 && i<link_count());
167
168         switch(i)
169         {
170         case 0: return _("Angle");
171         case 1: return _("Amplitude");
172         }
173
174         return String();
175 }
176
177 int
178 ValueNode_Cos::get_link_index_from_name(const String &name)const
179 {
180         if(name=="angle")       return 0;
181         if(name=="amp")         return 1;
182
183         throw Exception::BadLinkName(name);
184 }
185
186 LinkableValueNode::Vocab
187 ValueNode_Cos::get_children_vocab_vfunc()const
188 {
189         LinkableValueNode::Vocab ret;
190
191         ret.push_back(ParamDesc(ValueBase(),"angle")
192                 .set_local_name(_("Angle"))
193                 .set_description(_("Value to calculate the cosine"))
194         );
195
196         ret.push_back(ParamDesc(ValueBase(),"amp")
197                 .set_local_name(_("Amplitude"))
198                 .set_description(_("Multiplier of the resulting cosine"))
199         );
200
201         return ret;
202 }