Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / valuenode_timestring.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_timestring.cpp
3 **      \brief Implementation of the "TimeString" 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_timestring.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_TimeString::ValueNode_TimeString(const ValueBase &value):
55         LinkableValueNode(value.get_type())
56 {
57         Vocab ret(get_children_vocab());
58         set_children_vocab(ret);
59         switch(value.get_type())
60         {
61         case ValueBase::TYPE_STRING:
62                 set_link("time",ValueNode_Const::create(Time(0)));
63                 break;
64         default:
65                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
66         }
67 }
68
69 LinkableValueNode*
70 ValueNode_TimeString::create_new()const
71 {
72         return new ValueNode_TimeString(get_type());
73 }
74
75 ValueNode_TimeString*
76 ValueNode_TimeString::create(const ValueBase &x)
77 {
78         return new ValueNode_TimeString(x);
79 }
80
81 ValueNode_TimeString::~ValueNode_TimeString()
82 {
83         unlink_all();
84 }
85
86 ValueBase
87 ValueNode_TimeString::operator()(Time t)const
88 {
89         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
90                 printf("%s:%d operator()\n", __FILE__, __LINE__);
91
92         Time time((*time_)(t).get(Time()));
93
94         switch (get_type())
95         {
96         case ValueBase::TYPE_STRING:
97                 if (get_root_canvas())
98                         return time.get_string(get_root_canvas()->rend_desc().get_frame_rate());
99                 else
100                         return time.get_string();
101         default:
102                 break;
103         }
104
105         assert(0);
106         return ValueBase();
107 }
108
109 String
110 ValueNode_TimeString::get_name()const
111 {
112         return "timestring";
113 }
114
115 String
116 ValueNode_TimeString::get_local_name()const
117 {
118         return _("Time String");
119 }
120
121 bool
122 ValueNode_TimeString::set_link_vfunc(int i,ValueNode::Handle value)
123 {
124         assert(i>=0 && i<link_count());
125
126         switch(i)
127         {
128         case 0: CHECK_TYPE_AND_SET_VALUE(time_, ValueBase::TYPE_TIME);
129         }
130         return false;
131 }
132
133 ValueNode::LooseHandle
134 ValueNode_TimeString::get_link_vfunc(int i)const
135 {
136         assert(i>=0 && i<link_count());
137
138         switch(i)
139         {
140         case 0: return time_;
141         }
142
143         return 0;
144 }
145
146 bool
147 ValueNode_TimeString::check_type(ValueBase::Type type)
148 {
149         return
150                 type==ValueBase::TYPE_STRING;
151 }
152
153 LinkableValueNode::Vocab
154 ValueNode_TimeString::get_children_vocab_vfunc()const
155 {
156         if(children_vocab.size())
157                 return children_vocab;
158
159         LinkableValueNode::Vocab ret;
160
161         ret.push_back(ParamDesc(ValueBase(),"time")
162                 .set_local_name(_("Time"))
163                 .set_description(_("The time that is converted to string"))
164         );
165
166         return ret;
167 }