Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / valuenode_sine.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_sine.cpp
3 **      \brief Implementation of the "Sine" 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_sine.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_Sine::ValueNode_Sine(const ValueBase &value):
54         LinkableValueNode(value.get_type())
55 {
56         Vocab ret(get_children_vocab());
57         set_children_vocab(ret);
58         switch(value.get_type())
59         {
60         case ValueBase::TYPE_REAL:
61                 set_link("angle",ValueNode_Const::create(Angle::deg(90)));
62                 set_link("amp",ValueNode_Const::create(value.get(Real())));
63                 break;
64         default:
65                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
66         }
67 }
68
69 LinkableValueNode*
70 ValueNode_Sine::create_new()const
71 {
72         return new ValueNode_Sine(get_type());
73 }
74
75 ValueNode_Sine*
76 ValueNode_Sine::create(const ValueBase &x)
77 {
78         return new ValueNode_Sine(x);
79 }
80
81 ValueNode_Sine::~ValueNode_Sine()
82 {
83         unlink_all();
84 }
85
86 ValueBase
87 ValueNode_Sine::operator()(Time t)const
88 {
89         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
90                 printf("%s:%d operator()\n", __FILE__, __LINE__);
91
92         return
93                 Angle::sin(
94                         (*angle_)(t).get(Angle())
95                 ).get() * (*amp_)(t).get(Real())
96         ;
97 }
98
99
100 String
101 ValueNode_Sine::get_name()const
102 {
103         return "sine";
104 }
105
106 String
107 ValueNode_Sine::get_local_name()const
108 {
109         return _("Sine");
110 }
111
112 bool
113 ValueNode_Sine::check_type(ValueBase::Type type)
114 {
115         return type==ValueBase::TYPE_REAL;
116 }
117
118 bool
119 ValueNode_Sine::set_link_vfunc(int i,ValueNode::Handle value)
120 {
121         assert(i>=0 && i<link_count());
122
123         switch(i)
124         {
125         case 0: CHECK_TYPE_AND_SET_VALUE(angle_, ValueBase::TYPE_ANGLE);
126         case 1: CHECK_TYPE_AND_SET_VALUE(amp_,   ValueBase::TYPE_REAL);
127         }
128         return false;
129 }
130
131 ValueNode::LooseHandle
132 ValueNode_Sine::get_link_vfunc(int i)const
133 {
134         assert(i>=0 && i<link_count());
135
136         if(i==0)
137                 return angle_;
138         if(i==1)
139                 return amp_;
140
141         return 0;
142 }
143
144 LinkableValueNode::Vocab
145 ValueNode_Sine::get_children_vocab_vfunc()const
146 {
147         if(children_vocab.size())
148                 return children_vocab;
149
150         LinkableValueNode::Vocab ret;
151
152         ret.push_back(ParamDesc(ValueBase(),"angle")
153                 .set_local_name(_("Angle"))
154                 .set_description(_("The angle where the sine is calculated from"))
155         );
156
157         ret.push_back(ParamDesc(ValueBase(),"amp")
158                 .set_local_name(_("Amplitude"))
159                 .set_description(_("The value that multiplies the resulting sine"))
160         );
161
162         return ret;
163 }