Rename get_param_vocab to get_children_vocab and use a wrapper for the pure virtual...
[synfig.git] / synfig-core / src / synfig / valuenode_vectorangle.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_vectorangle.cpp
3 **      \brief Implementation of the "Vector Angle" 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_vectorangle.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_VectorAngle::ValueNode_VectorAngle(const ValueBase &value):
54         LinkableValueNode(value.get_type())
55 {
56         switch(value.get_type())
57         {
58         case ValueBase::TYPE_ANGLE:
59                 set_link("vector",ValueNode_Const::create(Vector(Angle::cos(value.get(Angle())).get(),
60                                                                                                                  Angle::sin(value.get(Angle())).get())));
61                 break;
62         default:
63                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
64         }
65 }
66
67 LinkableValueNode*
68 ValueNode_VectorAngle::create_new()const
69 {
70         return new ValueNode_VectorAngle(get_type());
71 }
72
73 ValueNode_VectorAngle*
74 ValueNode_VectorAngle::create(const ValueBase &x)
75 {
76         return new ValueNode_VectorAngle(x);
77 }
78
79 ValueNode_VectorAngle::~ValueNode_VectorAngle()
80 {
81         unlink_all();
82 }
83
84 ValueBase
85 ValueNode_VectorAngle::operator()(Time t)const
86 {
87         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
88                 printf("%s:%d operator()\n", __FILE__, __LINE__);
89
90         return (*vector_)(t).get(Vector()).angle();
91 }
92
93
94 bool
95 ValueNode_VectorAngle::set_link_vfunc(int i,ValueNode::Handle value)
96 {
97         assert(i>=0 && i<link_count());
98
99         switch(i)
100         {
101         case 0: CHECK_TYPE_AND_SET_VALUE(vector_, ValueBase::TYPE_VECTOR);
102         }
103         return false;
104 }
105
106 ValueNode::LooseHandle
107 ValueNode_VectorAngle::get_link_vfunc(int i)const
108 {
109         assert(i>=0 && i<link_count());
110
111         if(i==0)
112                 return vector_;
113         return 0;
114 }
115
116 int
117 ValueNode_VectorAngle::link_count()const
118 {
119         return 1;
120 }
121
122 String
123 ValueNode_VectorAngle::link_local_name(int i)const
124 {
125         assert(i>=0 && i<link_count());
126
127         if(i==0)
128                 return _("Vector");
129         return String();
130 }
131
132 String
133 ValueNode_VectorAngle::link_name(int i)const
134 {
135         assert(i>=0 && i<link_count());
136
137         if(i==0)
138                 return "vector";
139         return String();
140 }
141
142 int
143 ValueNode_VectorAngle::get_link_index_from_name(const String &name)const
144 {
145         if(name=="vector")
146                 return 0;
147
148         throw Exception::BadLinkName(name);
149 }
150
151 String
152 ValueNode_VectorAngle::get_name()const
153 {
154         return "vectorangle";
155 }
156
157 String
158 ValueNode_VectorAngle::get_local_name()const
159 {
160         return _("Vector Angle");
161 }
162
163 bool
164 ValueNode_VectorAngle::check_type(ValueBase::Type type)
165 {
166         return type==ValueBase::TYPE_ANGLE;
167 }
168
169
170 LinkableValueNode::Vocab
171 ValueNode_VectorAngle::get_children_vocab_vfunc()const
172 {
173         LinkableValueNode::Vocab ret;
174
175         ret.push_back(ParamDesc(ValueBase(),"vector")
176                 .set_local_name(_("Vector"))
177                 .set_description(_("The vector where the angle is calculated from"))
178         );
179
180         return ret;
181 }