Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / valuenode_blinereversetangent.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_blinereversetangent.cpp
3 **      \brief Implementation of the "Reverse Tangent" 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_blinereversetangent.h"
34 #include "valuenode_bline.h"
35 #include "valuenode_const.h"
36 #include "valuenode_composite.h"
37 #include "general.h"
38 #include "exception.h"
39 #include <ETL/hermite>
40 #include <ETL/calculus>
41
42 #endif
43
44 /* === U S I N G =========================================================== */
45
46 using namespace std;
47 using namespace etl;
48 using namespace synfig;
49
50 /* === M A C R O S ========================================================= */
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 ValueNode_BLineRevTangent::ValueNode_BLineRevTangent(const ValueBase::Type &x):
59         LinkableValueNode(x)
60 {
61 }
62
63 ValueNode_BLineRevTangent::ValueNode_BLineRevTangent(const ValueNode::Handle &x):
64         LinkableValueNode(x->get_type())
65 {
66         Vocab ret(get_children_vocab());
67         set_children_vocab(ret);
68         if(x->get_type()!=ValueBase::TYPE_BLINEPOINT)
69                 throw Exception::BadType(ValueBase::type_local_name(x->get_type()));
70
71         set_link("reference",x);
72         set_link("reverse",ValueNode_Const::create(bool(false)));
73 }
74
75 ValueNode_BLineRevTangent*
76 ValueNode_BLineRevTangent::create(const ValueBase &x)
77 {
78         return new ValueNode_BLineRevTangent(ValueNode_Const::create(x));
79 }
80
81 LinkableValueNode*
82 ValueNode_BLineRevTangent::create_new()const
83 {
84         return new ValueNode_BLineRevTangent(get_type());
85 }
86
87 ValueNode_BLineRevTangent::~ValueNode_BLineRevTangent()
88 {
89         unlink_all();
90 }
91
92 ValueBase
93 ValueNode_BLineRevTangent::operator()(Time t)const
94 {
95         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
96                 printf("%s:%d operator()\n", __FILE__, __LINE__);
97
98         if ((*reverse_)(t).get(bool()))
99         {
100                 BLinePoint reference((*reference_)(t));
101                 BLinePoint ret(reference);
102                 if(ret.get_split_tangent_flag())
103                 {
104                         ret.set_tangent1(-reference.get_tangent2());
105                         ret.set_tangent2(-reference.get_tangent1());
106                 }
107                 else
108                 {
109                         // \todo what should we do here really?
110                         // it seems that there's some pre-existing bug
111                         // with the 'reference' convert, too - referencing
112                         // a non-split blinepoint causes some problems
113                         ret.set_tangent1(-reference.get_tangent1());
114                 }
115                 return ret;
116         }
117         else
118                 return (*reference_)(t);
119 }
120
121 String
122 ValueNode_BLineRevTangent::get_name()const
123 {
124         return "blinerevtangent";
125 }
126
127 String
128 ValueNode_BLineRevTangent::get_local_name()const
129 {
130         return _("Reverse Tangent");
131 }
132
133 bool
134 ValueNode_BLineRevTangent::set_link_vfunc(int i,ValueNode::Handle value)
135 {
136         assert(i>=0 && i<link_count());
137
138         switch(i)
139         {
140         case 0: CHECK_TYPE_AND_SET_VALUE(reference_, get_type());
141         case 1: CHECK_TYPE_AND_SET_VALUE(reverse_,   ValueBase::TYPE_BOOL);
142         }
143         return false;
144 }
145
146 ValueNode::LooseHandle
147 ValueNode_BLineRevTangent::get_link_vfunc(int i)const
148 {
149         assert(i>=0 && i<link_count());
150
151         switch(i)
152         {
153                 case 0: return reference_;
154                 case 1: return reverse_;
155         }
156
157         return 0;
158 }
159
160 bool
161 ValueNode_BLineRevTangent::check_type(ValueBase::Type type)
162 {
163         return (type==ValueBase::TYPE_BLINEPOINT);
164 }
165
166 LinkableValueNode::Vocab
167 ValueNode_BLineRevTangent::get_children_vocab_vfunc()const
168 {
169         if(children_vocab.size())
170                 return children_vocab;
171
172         LinkableValueNode::Vocab ret;
173
174         ret.push_back(ParamDesc(ValueBase(),"reference")
175                 .set_local_name(_("Reference"))
176                 .set_description(_("The referenced tangent to reverse"))
177         );
178
179         ret.push_back(ParamDesc(ValueBase(),"reverse")
180                 .set_local_name(_("Reverse"))
181                 .set_description(_("When checked, the reference is reversed"))
182         );
183
184         return ret;
185 }