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