Use translated versions of the type names everywhere other than in the .sif(z) files.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_segcalcvertex.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_segcalcvertex.cpp
3 **      \brief Implementation of the "Segment Vertex" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 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_segcalcvertex.h"
34 #include "valuenode_const.h"
35 #include "valuenode_composite.h"
36 #include "general.h"
37 #include "exception.h"
38 #include <ETL/hermite>
39 #include "segment.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48
49 /* === M A C R O S ========================================================= */
50
51 /* === G L O B A L S ======================================================= */
52
53 /* === P R O C E D U R E S ================================================= */
54
55 /* === M E T H O D S ======================================================= */
56
57 ValueNode_SegCalcVertex::ValueNode_SegCalcVertex(const ValueBase::Type &x):
58         LinkableValueNode(x)
59 {
60         if(x!=ValueBase::TYPE_VECTOR)
61                 throw Exception::BadType(ValueBase::type_local_name(x));
62
63         set_link("segment",ValueNode_Const::create(ValueBase::TYPE_SEGMENT));
64         set_link("amount",ValueNode_Const::create(Real(0.5)));
65 }
66
67 ValueNode_SegCalcVertex*
68 ValueNode_SegCalcVertex::create(const ValueBase &x)
69 {
70         return new ValueNode_SegCalcVertex(x.get_type());
71 }
72
73 ValueNode_SegCalcVertex::~ValueNode_SegCalcVertex()
74 {
75         unlink_all();
76 }
77
78 ValueBase
79 ValueNode_SegCalcVertex::operator()(Time t)const
80 {
81         Segment segment((*segment_)(t).get(Segment()));
82
83         etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
84
85         return curve((*amount_)(t).get(Real()));
86 }
87
88
89 String
90 ValueNode_SegCalcVertex::get_name()const
91 {
92         return "segcalcvertex";
93 }
94
95 String
96 ValueNode_SegCalcVertex::get_local_name()const
97 {
98         return _("Segment Vertex");
99 }
100
101 bool
102 ValueNode_SegCalcVertex::check_type(ValueBase::Type type)
103 {
104         return type==ValueBase::TYPE_VECTOR;
105 }
106
107 bool
108 ValueNode_SegCalcVertex::set_link_vfunc(int i,ValueNode::Handle x)
109 {
110         assert(i>=0 && i<link_count());
111
112         if(i==0)
113         {
114                 segment_=x;
115                 signal_child_changed()(i);signal_value_changed()();
116                 return true;
117         }
118         if(i==1)
119         {
120                 amount_=x;
121                 signal_child_changed()(i);signal_value_changed()();
122                 return true;
123         }
124         return false;
125 }
126
127 ValueNode::LooseHandle
128 ValueNode_SegCalcVertex::get_link_vfunc(int i)const
129 {
130         assert(i>=0 && i<link_count());
131
132         if(i==0)
133                 return segment_;
134         if(i==1)
135                 return amount_;
136
137         return 0;
138 }
139
140 int
141 ValueNode_SegCalcVertex::link_count()const
142 {
143         return 2;
144 }
145
146 String
147 ValueNode_SegCalcVertex::link_name(int i)const
148 {
149         assert(i>=0 && i<link_count());
150
151         if(i==0)
152                 return "segment";
153         if(i==1)
154                 return "amount";
155         return String();
156 }
157
158 String
159 ValueNode_SegCalcVertex::link_local_name(int i)const
160 {
161         assert(i>=0 && i<link_count());
162
163         if(i==0)
164                 return _("Segment");
165         if(i==1)
166                 return _("Amount");
167         return String();
168 }
169
170 int
171 ValueNode_SegCalcVertex::get_link_index_from_name(const String &name)const
172 {
173         if(name=="segment")
174                 return 0;
175         if(name=="amount")
176                 return 1;
177
178         throw Exception::BadLinkName(name);
179 }
180
181 LinkableValueNode*
182 ValueNode_SegCalcVertex::create_new()const
183 {
184         return new ValueNode_SegCalcVertex(ValueBase::TYPE_VECTOR);
185 }