Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / stable / src / synfig / valuenode_anglestring.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_anglestring.cpp
3 **      \brief Implementation of the "AngleString" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 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_anglestring.h"
34 #include "valuenode_const.h"
35 #include "canvas.h"
36 #include "general.h"
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_AngleString::ValueNode_AngleString(const ValueBase &value):
55         LinkableValueNode(value.get_type())
56 {
57         switch(value.get_type())
58         {
59         case ValueBase::TYPE_STRING:
60                 set_link("angle",ValueNode_Const::create(Angle::deg(0)));
61                 set_link("width",ValueNode_Const::create(int(0)));
62                 set_link("precision",ValueNode_Const::create(int(3)));
63                 set_link("zero_pad",ValueNode_Const::create(bool(false)));
64                 break;
65         default:
66                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
67         }
68
69         DCAST_HACK_ENABLE();
70 }
71
72 LinkableValueNode*
73 ValueNode_AngleString::create_new()const
74 {
75         return new ValueNode_AngleString(get_type());
76 }
77
78 ValueNode_AngleString*
79 ValueNode_AngleString::create(const ValueBase &x)
80 {
81         return new ValueNode_AngleString(x);
82 }
83
84 ValueNode_AngleString::~ValueNode_AngleString()
85 {
86         unlink_all();
87 }
88
89 ValueBase
90 ValueNode_AngleString::operator()(Time t)const
91 {
92         Real angle(Angle::deg((*angle_)(t).get(Angle())).get());
93         int width((*width_)(t).get(int()));
94         int precision((*precision_)(t).get(int()));
95         int zero_pad((*zero_pad_)(t).get(bool()));
96
97         switch (get_type())
98         {
99         case ValueBase::TYPE_STRING:
100                 return strprintf(strprintf("%%%s%d.%df",
101                                                                    zero_pad ? "0" : "",
102                                                                    width,
103                                                                    precision).c_str(), angle);
104         default:
105                 break;
106         }
107
108         assert(0);
109         return ValueBase();
110 }
111
112 String
113 ValueNode_AngleString::get_name()const
114 {
115         return "anglestring";
116 }
117
118 String
119 ValueNode_AngleString::get_local_name()const
120 {
121         return _("Angle String");
122 }
123
124 bool
125 ValueNode_AngleString::set_link_vfunc(int i,ValueNode::Handle value)
126 {
127         assert(i>=0 && i<link_count());
128
129         switch(i)
130         {
131         case 0: CHECK_TYPE_AND_SET_VALUE(angle_, ValueBase::TYPE_ANGLE);
132         case 1: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_INTEGER);
133         case 2: CHECK_TYPE_AND_SET_VALUE(precision_, ValueBase::TYPE_INTEGER);
134         case 3: CHECK_TYPE_AND_SET_VALUE(zero_pad_, ValueBase::TYPE_BOOL);
135         }
136         return false;
137 }
138
139 ValueNode::LooseHandle
140 ValueNode_AngleString::get_link_vfunc(int i)const
141 {
142         assert(i>=0 && i<link_count());
143
144         switch(i)
145         {
146         case 0: return angle_;
147         case 1: return width_;
148         case 2: return precision_;
149         case 3: return zero_pad_;
150         }
151
152         return 0;
153 }
154
155 int
156 ValueNode_AngleString::link_count()const
157 {
158         return 4;
159 }
160
161 String
162 ValueNode_AngleString::link_name(int i)const
163 {
164         assert(i>=0 && i<link_count());
165
166         switch(i)
167         {
168                 case 0: return "angle";
169                 case 1: return "width";
170                 case 2: return "precision";
171                 case 3: return "zero_pad";
172         }
173         return String();
174 }
175
176 String
177 ValueNode_AngleString::link_local_name(int i)const
178 {
179         assert(i>=0 && i<link_count());
180
181         switch(i)
182         {
183                 case 0: return _("Angle");
184                 case 1: return _("Width");
185                 case 2: return _("Precision");
186                 case 3: return _("Zero Padded");
187         }
188         return String();
189 }
190
191 int
192 ValueNode_AngleString::get_link_index_from_name(const String &name)const
193 {
194         if (name=="angle") return 0;
195         if (name=="width") return 1;
196         if (name=="precision") return 2;
197         if (name=="zero_pad") return 3;
198
199         throw Exception::BadLinkName(name);
200 }
201
202 bool
203 ValueNode_AngleString::check_type(ValueBase::Type type)
204 {
205         return
206                 type==ValueBase::TYPE_STRING;
207 }