1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_blinereversetangent.cpp
3 ** \brief Implementation of the "Reverse Tangent" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_blinereversetangent.h"
34 #include "valuenode_bline.h"
35 #include "valuenode_const.h"
36 #include "valuenode_composite.h"
38 #include "exception.h"
39 #include <ETL/hermite>
40 #include <ETL/calculus>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 ValueNode_BLineRevTangent::ValueNode_BLineRevTangent(const ValueBase::Type &x):
63 ValueNode_BLineRevTangent::ValueNode_BLineRevTangent(const ValueNode::Handle &x):
64 LinkableValueNode(x->get_type())
66 if(x->get_type()!=ValueBase::TYPE_BLINEPOINT)
67 throw Exception::BadType(ValueBase::type_local_name(x->get_type()));
69 set_link("reference",x);
70 set_link("reverse",ValueNode_Const::create(bool(false)));
73 ValueNode_BLineRevTangent*
74 ValueNode_BLineRevTangent::create(const ValueBase &x)
76 return new ValueNode_BLineRevTangent(ValueNode_Const::create(x));
80 ValueNode_BLineRevTangent::create_new()const
82 return new ValueNode_BLineRevTangent(get_type());
85 ValueNode_BLineRevTangent::~ValueNode_BLineRevTangent()
91 ValueNode_BLineRevTangent::operator()(Time t)const
93 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
94 printf("%s:%d operator()\n", __FILE__, __LINE__);
96 if ((*reverse_)(t).get(bool()))
98 BLinePoint reference((*reference_)(t));
99 BLinePoint ret(reference);
100 if(ret.get_split_tangent_flag())
102 ret.set_tangent1(-reference.get_tangent2());
103 ret.set_tangent2(-reference.get_tangent1());
107 // \todo what should we do here really?
108 // it seems that there's some pre-existing bug
109 // with the 'reference' convert, too - referencing
110 // a non-split blinepoint causes some problems
111 ret.set_tangent1(-reference.get_tangent1());
116 return (*reference_)(t);
120 ValueNode_BLineRevTangent::get_name()const
122 return "blinerevtangent";
126 ValueNode_BLineRevTangent::get_local_name()const
128 return _("Reverse Tangent");
132 ValueNode_BLineRevTangent::set_link_vfunc(int i,ValueNode::Handle value)
134 assert(i>=0 && i<link_count());
138 case 0: CHECK_TYPE_AND_SET_VALUE(reference_, get_type());
139 case 1: CHECK_TYPE_AND_SET_VALUE(reverse_, ValueBase::TYPE_BOOL);
144 ValueNode::LooseHandle
145 ValueNode_BLineRevTangent::get_link_vfunc(int i)const
147 assert(i>=0 && i<link_count());
151 case 0: return reference_;
152 case 1: return reverse_;
159 ValueNode_BLineRevTangent::link_count()const
165 ValueNode_BLineRevTangent::link_name(int i)const
167 assert(i>=0 && i<link_count());
171 case 0: return "reference";
172 case 1: return "reverse";
178 ValueNode_BLineRevTangent::link_local_name(int i)const
180 assert(i>=0 && i<link_count());
184 case 0: return _("Reference");
185 case 1: return _("Reverse");
191 ValueNode_BLineRevTangent::get_link_index_from_name(const String &name)const
193 if(name=="reference") return 0;
194 if(name=="reverse") return 1;
195 throw Exception::BadLinkName(name);
199 ValueNode_BLineRevTangent::check_type(ValueBase::Type type)
201 return (type==ValueBase::TYPE_BLINEPOINT);