Use translated versions of the type names everywhere other than in the .sif(z) files.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_integer.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_integer.cpp
3 **      \brief Implementation of the "Integer" 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_integer.h"
34 #include "valuenode_const.h"
35 #include "general.h"
36 #include <ETL/misc>
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 ValueNode_Integer::ValueNode_Integer(const ValueBase::Type &x):
55         LinkableValueNode(x)
56 {
57 }
58
59 ValueNode_Integer::ValueNode_Integer(const ValueBase &x):
60         LinkableValueNode(x.get_type())
61 {
62         switch(x.get_type())
63         {
64         case ValueBase::TYPE_ANGLE:
65                 set_link("integer", ValueNode_Const::create(round_to_int(Angle::deg(x.get(Angle())).get())));
66                 break;
67         case ValueBase::TYPE_BOOL:
68                 set_link("integer", ValueNode_Const::create(int(x.get(bool()))));
69                 break;
70         case ValueBase::TYPE_REAL:
71                 set_link("integer", ValueNode_Const::create(round_to_int(x.get(Real()))));
72                 break;
73         case ValueBase::TYPE_TIME:
74                 set_link("integer", ValueNode_Const::create(round_to_int(x.get(Time()))));
75                 break;
76         default:
77                 assert(0);
78                 throw runtime_error(_("synfig::ValueNode_Integer:Bad type ")+ValueBase::type_local_name(x.get_type()));
79         }
80 }
81
82 ValueNode_Integer*
83 ValueNode_Integer::create(const ValueBase &x)
84 {
85         return new ValueNode_Integer(x);
86 }
87
88 LinkableValueNode*
89 ValueNode_Integer::create_new()const
90 {
91         return new ValueNode_Integer(get_type());
92 }
93
94 ValueNode_Integer::~ValueNode_Integer()
95 {
96         unlink_all();
97 }
98
99 bool
100 ValueNode_Integer::set_link_vfunc(int i,ValueNode::Handle x)
101 {
102         assert(i>=0 && i<link_count());
103
104         switch(i)
105         {
106         case 0:  integer_ = x; break;
107         default: return false;
108         }
109
110         signal_child_changed()(i);
111         signal_value_changed()();
112         return true;
113 }
114
115 ValueNode::LooseHandle
116 ValueNode_Integer::get_link_vfunc(int i)const
117 {
118         assert(i>=0 && i<link_count());
119
120         if(i==0) return integer_;
121
122         return 0;
123 }
124
125 int
126 ValueNode_Integer::link_count()const
127 {
128         return 1;
129 }
130
131 String
132 ValueNode_Integer::link_local_name(int i)const
133 {
134         assert(i>=0 && i<link_count());
135
136         if(i==0) return _("Integer");
137         return String();
138 }
139
140 String
141 ValueNode_Integer::link_name(int i)const
142 {
143         assert(i>=0 && i<link_count());
144
145         if(i==0) return "integer";
146         return String();
147 }
148
149 int
150 ValueNode_Integer::get_link_index_from_name(const String &name)const
151 {
152         if(name=="integer") return 0;
153
154         throw Exception::BadLinkName(name);
155 }
156
157 ValueBase
158 ValueNode_Integer::operator()(Time t)const
159 {
160         int integer = (*integer_)(t).get(int());
161
162         switch (get_type())
163         {
164         case ValueBase::TYPE_ANGLE:
165                 return Angle::deg(integer);
166         case ValueBase::TYPE_BOOL:
167                 return bool(integer);
168         case ValueBase::TYPE_REAL:
169                 return Real(integer);
170         case ValueBase::TYPE_TIME:
171                 return Time(integer);
172         default:
173                 assert(0);
174                 throw runtime_error(_("synfig::ValueNode_Integer:Bad type ")+ValueBase::type_local_name(get_type()));
175         }
176 }
177
178 String
179 ValueNode_Integer::get_name()const
180 {
181         return "fromint";
182 }
183
184 String
185 ValueNode_Integer::get_local_name()const
186 {
187         return _("From Integer");
188 }
189
190 // don't show this to the user at the moment - maybe it's not very useful
191 bool
192 ValueNode_Integer::check_type(ValueBase::Type type)
193 {
194         return false;
195 //      return
196 //              type==ValueBase::TYPE_ANGLE ||
197 //              type==ValueBase::TYPE_BOOL  ||
198 //              type==ValueBase::TYPE_REAL  ||
199 //              type==ValueBase::TYPE_TIME;
200 }