Show the size of circles as they are drawn using the draw tool.
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuedescconvert.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuedescconvert.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 /*
33 #include "valuenodereplace.h"
34 #include "layerparamconnect.h"
35 #include "valuenodelinkconnect.h"
36 */
37
38 #include "valuedescconnect.h"
39
40 #include "valuedescconvert.h"
41
42 #include <synfigapp/canvasinterface.h>
43 #include <synfig/valuenode_const.h>
44
45 #include <synfigapp/general.h>
46
47 #endif
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace synfigapp;
53 using namespace Action;
54
55 /* === M A C R O S ========================================================= */
56
57 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescConvert);
58 ACTION_SET_NAME(Action::ValueDescConvert,"value_desc_convert");
59 ACTION_SET_LOCAL_NAME(Action::ValueDescConvert,N_("Convert"));
60 ACTION_SET_TASK(Action::ValueDescConvert,"convert");
61 ACTION_SET_CATEGORY(Action::ValueDescConvert,Action::CATEGORY_VALUEDESC);
62 ACTION_SET_PRIORITY(Action::ValueDescConvert,0);
63 ACTION_SET_VERSION(Action::ValueDescConvert,"0.0");
64 ACTION_SET_CVS_ID(Action::ValueDescConvert,"$Id$");
65
66 /* === G L O B A L S ======================================================= */
67
68 /* === P R O C E D U R E S ================================================= */
69
70 /* === M E T H O D S ======================================================= */
71
72 Action::ValueDescConvert::ValueDescConvert()
73 {
74         time=(Time::begin()-1);
75 }
76
77 synfig::String
78 Action::ValueDescConvert::get_local_name()const
79 {
80         // TRANSLATORS: This is used in the 'history' dialog when a ValueNode is converted.  The first %s is what is converted, the 2nd is the local name of the ValueNode's type.
81         return strprintf(_("Convert '%s' to ValueNode type '%s'"),
82                                          value_desc.get_description().c_str(),
83                                          LinkableValueNode::book()[type].local_name.c_str());
84 }
85
86 Action::ParamVocab
87 Action::ValueDescConvert::get_param_vocab()
88 {
89         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
90
91         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
92                 .set_local_name(_("ValueDesc"))
93         );
94
95         ret.push_back(ParamDesc("type",Param::TYPE_STRING)
96                 .set_local_name(_("Type"))
97                 .set_desc(_("The type of ValueNode that you want to be converted to"))
98         );
99
100         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
101                 .set_local_name(_("Time"))
102         );
103
104         return ret;
105 }
106
107 bool
108 Action::ValueDescConvert::is_candidate(const ParamList &x)
109 {
110         return candidate_check(get_param_vocab(),x);
111 }
112
113 bool
114 Action::ValueDescConvert::set_param(const synfig::String& name, const Action::Param &param)
115 {
116         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
117         {
118                 value_desc=param.get_value_desc();
119
120                 return true;
121         }
122
123         if(name=="type" && param.get_type()==Param::TYPE_STRING)
124         {
125                 type=param.get_string();
126
127                 return true;
128         }
129
130         if(name=="time" && param.get_type()==Param::TYPE_TIME)
131         {
132                 time=param.get_time();
133
134                 return true;
135         }
136
137         return Action::CanvasSpecific::set_param(name,param);
138 }
139
140 bool
141 Action::ValueDescConvert::is_ready()const
142 {
143         if(!value_desc || type.empty())
144                 return false;
145         if(time==(Time::begin()-1))
146         {
147                 synfig::error("Missing time");
148                 return false;
149         }
150         return Action::CanvasSpecific::is_ready();
151 }
152
153 void
154 Action::ValueDescConvert::prepare()
155 {
156         clear();
157
158         ValueBase value;
159
160         if(value_desc.is_const())
161                 value=value_desc.get_value();
162         else if(value_desc.is_value_node())
163                 value=(*value_desc.get_value_node())(time);
164         else
165                 throw Error(_("Unable to decipher ValueDesc (Bug?)"));
166
167         ValueNode::Handle src_value_node(LinkableValueNode::create(type,value));
168
169         if(!src_value_node)
170                 throw Error(_("Unable to create new value node"));
171
172
173         ValueNode::Handle dest_value_node;
174         dest_value_node=value_desc.get_value_node();
175
176         Action::Handle action(ValueDescConnect::create());
177
178         action->set_param("canvas",get_canvas());
179         action->set_param("canvas_interface",get_canvas_interface());
180         action->set_param("src",src_value_node);
181         action->set_param("dest",value_desc);
182
183         assert(action->is_ready());
184         if(!action->is_ready())
185                 throw Error(Error::TYPE_NOTREADY);
186
187         add_action_front(action);
188
189 /*
190         return;
191
192
193         if(value_desc.parent_is_canvas())
194         {
195                 ValueNode::Handle dest_value_node;
196                 dest_value_node=value_desc.get_value_node();
197
198                 Action::Handle action(ValueNodeReplace::create());
199
200                 action->set_param("canvas",get_canvas());
201                 action->set_param("canvas_interface",get_canvas_interface());
202                 action->set_param("src",src_value_node);
203                 action->set_param("dest",dest_value_node);
204
205                 assert(action->is_ready());
206                 if(!action->is_ready())
207                         throw Error(Error::TYPE_NOTREADY);
208
209                 add_action_front(action);
210                 return;
211         }
212         else
213         if(value_desc.parent_is_linkable_value_node())
214         {
215                 Action::Handle action(ValueNodeLinkConnect::create());
216
217                 action->set_param("canvas",get_canvas());
218                 action->set_param("canvas_interface",get_canvas_interface());
219                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
220                 action->set_param("value_node", src_value_node);
221                 action->set_param("index",value_desc.get_index());
222
223                 assert(action->is_ready());
224                 if(!action->is_ready())
225                         throw Error(Error::TYPE_NOTREADY);
226
227                 add_action_front(action);
228                 return;
229         }
230         else
231         if(value_desc.parent_is_layer_param())
232         {
233                 Action::Handle action(LayerParamConnect::create());
234
235                 action->set_param("canvas",get_canvas());
236                 action->set_param("canvas_interface",get_canvas_interface());
237                 action->set_param("layer",value_desc.get_layer());
238                 action->set_param("param",value_desc.get_param_name());
239                 action->set_param("value_node",src_value_node);
240
241                 assert(action->is_ready());
242                 if(!action->is_ready())
243                         throw Error(Error::TYPE_NOTREADY);
244
245                 add_action_front(action);
246                 return;
247         }
248
249
250
251         throw Error(_("ValueDesc is not recognized or supported."));
252 */
253 }