more updates
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_sine.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file valuenode_sine.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenode_sine.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "valuenode_sine.h"
32 #include "valuenode_const.h"
33 #include "general.h"
34
35 #endif
36
37 /* === U S I N G =========================================================== */
38
39 using namespace std;
40 using namespace etl;
41 using namespace sinfg;
42
43 /* === M A C R O S ========================================================= */
44
45 /* === G L O B A L S ======================================================= */
46
47 /* === P R O C E D U R E S ================================================= */
48
49 /* === M E T H O D S ======================================================= */
50
51 ValueNode_Sine::ValueNode_Sine(const ValueBase::Type &x):
52         LinkableValueNode(x)
53 {
54         switch(x)
55         {
56         case ValueBase::TYPE_REAL:
57                 set_link("angle",ValueNode_Const::create(Angle::zero()));
58                 set_link("amp",ValueNode_Const::create(Real(1)));
59                 break;
60         default:
61                 throw Exception::BadType(ValueBase::type_name(x));
62         }
63
64         DCAST_HACK_ENABLE();
65 }
66
67 ValueNode_Sine*
68 ValueNode_Sine::create(const ValueBase &x)
69 {
70         return new ValueNode_Sine(x.get_type());
71 }
72
73 ValueNode_Sine::~ValueNode_Sine()
74 {
75         unlink_all();
76 }
77
78 ValueBase
79 ValueNode_Sine::operator()(Time t)const
80 {
81         return
82                 Angle::sin(
83                         (*angle_)(t).get(Angle())
84                 ).get() * (*amp_)(t).get(Real())
85         ;
86 }
87
88
89 String
90 ValueNode_Sine::get_name()const
91 {
92         return "sine";
93 }
94
95 String
96 ValueNode_Sine::get_local_name()const
97 {
98         return _("Sine");
99 }
100                 
101 bool
102 ValueNode_Sine::check_type(ValueBase::Type type)
103 {
104         return type==ValueBase::TYPE_REAL;
105 }
106
107 bool
108 ValueNode_Sine::set_link_vfunc(int i,ValueNode::Handle x)
109 {
110         assert(i==0 || i==1);
111         if(i==0)
112         {
113                 angle_=x;
114                 signal_child_changed()(i);signal_value_changed()();
115                 return true;
116         }
117         if(i==1)
118         {
119                 amp_=x;
120                 signal_child_changed()(i);signal_value_changed()();
121                 return true;
122         }
123         return false;
124 }
125
126 ValueNode::LooseHandle
127 ValueNode_Sine::get_link_vfunc(int i)const
128 {
129         assert(i==0 || i==1);
130         if(i==0)
131                 return angle_;
132         if(i==1)
133                 return amp_;
134
135         return 0;
136 }
137
138 int
139 ValueNode_Sine::link_count()const
140 {
141         return 2;
142 }
143
144 String
145 ValueNode_Sine::link_name(int i)const
146 {
147         assert(i==0 || i==1);
148         if(i==0)
149                 return "angle";
150         if(i==1)
151                 return "amp";
152         return String();
153 }
154
155 String
156 ValueNode_Sine::link_local_name(int i)const
157 {
158         assert(i==0 || i==1);
159         if(i==0)
160                 return _("Angle");
161         if(i==1)
162                 return _("Amplitude");
163         return String();
164 }
165
166 int
167 ValueNode_Sine::get_link_index_from_name(const String &name)const
168 {
169         if(name=="angle")
170                 return 0;
171         if(name=="amp")
172                 return 1;
173         
174         throw Exception::BadLinkName(name);
175 }
176
177 LinkableValueNode*
178 ValueNode_Sine::create_new()const
179 {
180         return new ValueNode_Sine(get_type());
181 }