Made all the assert() lines which check the valuenode sub-parameter index range the...
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_atan2.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_atan2.cpp
3 **      \brief Implementation of the "aTan2" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 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_atan2.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_Atan2::ValueNode_Atan2(const ValueBase &value):
54         LinkableValueNode(value.get_type())
55 {
56         switch(value.get_type())
57         {
58         case ValueBase::TYPE_ANGLE:
59                 set_link("x",ValueNode_Const::create(Angle::cos(value.get(Angle())).get()));
60                 set_link("y",ValueNode_Const::create(Angle::sin(value.get(Angle())).get()));
61                 break;
62         default:
63                 throw Exception::BadType(ValueBase::type_name(value.get_type()));
64         }
65
66         DCAST_HACK_ENABLE();
67 }
68
69 LinkableValueNode*
70 ValueNode_Atan2::create_new()const
71 {
72         return new ValueNode_Atan2(get_type());
73 }
74
75 ValueNode_Atan2*
76 ValueNode_Atan2::create(const ValueBase &x)
77 {
78         return new ValueNode_Atan2(x);
79 }
80
81 ValueNode_Atan2::~ValueNode_Atan2()
82 {
83         unlink_all();
84 }
85
86 ValueBase
87 ValueNode_Atan2::operator()(Time t)const
88 {
89         return Angle::tan((*y_)(t).get(Real()),
90                                           (*x_)(t).get(Real()));
91 }
92
93
94 String
95 ValueNode_Atan2::get_name()const
96 {
97         return "atan2";
98 }
99
100 String
101 ValueNode_Atan2::get_local_name()const
102 {
103         return _("aTan2");
104 }
105
106 bool
107 ValueNode_Atan2::check_type(ValueBase::Type type)
108 {
109         return type==ValueBase::TYPE_ANGLE;
110 }
111
112 bool
113 ValueNode_Atan2::set_link_vfunc(int i,ValueNode::Handle x)
114 {
115         assert(i>=0 && i<link_count());
116
117         if(i==0)
118         {
119                 x_=x;
120                 signal_child_changed()(i);signal_value_changed()();
121                 return true;
122         }
123         if(i==1)
124         {
125                 y_=x;
126                 signal_child_changed()(i);signal_value_changed()();
127                 return true;
128         }
129         return false;
130 }
131
132 ValueNode::LooseHandle
133 ValueNode_Atan2::get_link_vfunc(int i)const
134 {
135         assert(i>=0 && i<link_count());
136
137         if(i==0)
138                 return x_;
139         if(i==1)
140                 return y_;
141
142         return 0;
143 }
144
145 int
146 ValueNode_Atan2::link_count()const
147 {
148         return 2;
149 }
150
151 String
152 ValueNode_Atan2::link_name(int i)const
153 {
154         assert(i>=0 && i<link_count());
155
156         if(i==0)
157                 return "x";
158         if(i==1)
159                 return "y";
160         return String();
161 }
162
163 String
164 ValueNode_Atan2::link_local_name(int i)const
165 {
166         assert(i>=0 && i<link_count());
167
168         if(i==0)
169                 return _("X");
170         if(i==1)
171                 return _("Y");
172         return String();
173 }
174
175 int
176 ValueNode_Atan2::get_link_index_from_name(const String &name)const
177 {
178         if(name=="x")
179                 return 0;
180         if(name=="y")
181                 return 1;
182
183         throw Exception::BadLinkName(name);
184 }