Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / 0.61.09 / 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         if(x->get_type()!=ValueBase::TYPE_BLINEPOINT)
67                 throw Exception::BadType(ValueBase::type_local_name(x->get_type()));
68
69         set_link("reference",x);
70         set_link("reverse",ValueNode_Const::create(bool(false)));
71 }
72
73 ValueNode_BLineRevTangent*
74 ValueNode_BLineRevTangent::create(const ValueBase &x)
75 {
76         return new ValueNode_BLineRevTangent(ValueNode_Const::create(x));
77 }
78
79 LinkableValueNode*
80 ValueNode_BLineRevTangent::create_new()const
81 {
82         return new ValueNode_BLineRevTangent(get_type());
83 }
84
85 ValueNode_BLineRevTangent::~ValueNode_BLineRevTangent()
86 {
87         unlink_all();
88 }
89
90 ValueBase
91 ValueNode_BLineRevTangent::operator()(Time t)const
92 {
93         if ((*reverse_)(t).get(bool()))
94         {
95                 BLinePoint reference((*reference_)(t));
96                 BLinePoint ret(reference);
97                 if(ret.get_split_tangent_flag())
98                 {
99                         ret.set_tangent1(-reference.get_tangent2());
100                         ret.set_tangent2(-reference.get_tangent1());
101                 }
102                 else
103                 {
104                         // \todo what should we do here really?
105                         // it seems that there's some pre-existing bug
106                         // with the 'reference' convert, too - referencing
107                         // a non-split blinepoint causes some problems
108                         ret.set_tangent1(-reference.get_tangent1());
109                 }
110                 return ret;
111         }
112         else
113                 return (*reference_)(t);
114 }
115
116 String
117 ValueNode_BLineRevTangent::get_name()const
118 {
119         return "blinerevtangent";
120 }
121
122 String
123 ValueNode_BLineRevTangent::get_local_name()const
124 {
125         return _("Reverse Tangent");
126 }
127
128 bool
129 ValueNode_BLineRevTangent::set_link_vfunc(int i,ValueNode::Handle value)
130 {
131         assert(i>=0 && i<link_count());
132
133         switch(i)
134         {
135         case 0: CHECK_TYPE_AND_SET_VALUE(reference_, get_type());
136         case 1: CHECK_TYPE_AND_SET_VALUE(reverse_,   ValueBase::TYPE_BOOL);
137         }
138         return false;
139 }
140
141 ValueNode::LooseHandle
142 ValueNode_BLineRevTangent::get_link_vfunc(int i)const
143 {
144         assert(i>=0 && i<link_count());
145
146         switch(i)
147         {
148                 case 0: return reference_;
149                 case 1: return reverse_;
150         }
151
152         return 0;
153 }
154
155 int
156 ValueNode_BLineRevTangent::link_count()const
157 {
158         return 2;
159 }
160
161 String
162 ValueNode_BLineRevTangent::link_name(int i)const
163 {
164         assert(i>=0 && i<link_count());
165
166         switch(i)
167         {
168                 case 0: return "reference";
169                 case 1: return "reverse";
170         }
171         return String();
172 }
173
174 String
175 ValueNode_BLineRevTangent::link_local_name(int i)const
176 {
177         assert(i>=0 && i<link_count());
178
179         switch(i)
180         {
181                 case 0: return _("Reference");
182                 case 1: return _("Reverse");
183         }
184         return String();
185 }
186
187 int
188 ValueNode_BLineRevTangent::get_link_index_from_name(const String &name)const
189 {
190         if(name=="reference")   return 0;
191         if(name=="reverse")             return 1;
192         throw Exception::BadLinkName(name);
193 }
194
195 bool
196 ValueNode_BLineRevTangent::check_type(ValueBase::Type type)
197 {
198         return (type==ValueBase::TYPE_BLINEPOINT);
199 }