1 /* === S Y N F I G ========================================================= */
2 /*! \file valuedescconvert.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include "valuenodereplace.h"
34 #include "layerparamconnect.h"
35 #include "valuenodelinkconnect.h"
38 #include "valuedescconnect.h"
40 #include "valuedescconvert.h"
42 #include <synfigapp/canvasinterface.h>
43 #include <synfig/valuenode_const.h>
45 #include <synfigapp/general.h>
51 using namespace synfig;
52 using namespace synfigapp;
53 using namespace Action;
55 /* === M A C R O S ========================================================= */
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$");
66 /* === G L O B A L S ======================================================= */
68 /* === P R O C E D U R E S ================================================= */
70 /* === M E T H O D S ======================================================= */
72 Action::ValueDescConvert::ValueDescConvert()
74 time=(Time::begin()-1);
78 Action::ValueDescConvert::get_local_name()const
80 // TRANSLATORS: This is used in the 'history' dialog when a ValueNode is converted. %s is the local name of the valuenode's type.
81 return strprintf(_("Convert to '%s'"), LinkableValueNode::book()[type].local_name.c_str());
85 Action::ValueDescConvert::get_param_vocab()
87 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
89 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
90 .set_local_name(_("ValueDesc"))
93 ret.push_back(ParamDesc("type",Param::TYPE_STRING)
94 .set_local_name(_("Type"))
95 .set_desc(_("The type of ValueNode that you want to be converted to"))
98 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
99 .set_local_name(_("Time"))
106 Action::ValueDescConvert::is_candidate(const ParamList &x)
108 return candidate_check(get_param_vocab(),x);
112 Action::ValueDescConvert::set_param(const synfig::String& name, const Action::Param ¶m)
114 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
116 value_desc=param.get_value_desc();
121 if(name=="type" && param.get_type()==Param::TYPE_STRING)
123 type=param.get_string();
128 if(name=="time" && param.get_type()==Param::TYPE_TIME)
130 time=param.get_time();
135 return Action::CanvasSpecific::set_param(name,param);
139 Action::ValueDescConvert::is_ready()const
141 if(!value_desc || type.empty())
143 if(time==(Time::begin()-1))
145 synfig::error("Missing time");
148 return Action::CanvasSpecific::is_ready();
152 Action::ValueDescConvert::prepare()
158 if(value_desc.is_const())
159 value=value_desc.get_value();
160 else if(value_desc.is_value_node())
161 value=(*value_desc.get_value_node())(time);
163 throw Error(_("Unable to decipher ValueDesc (Bug?)"));
165 ValueNode::Handle src_value_node(LinkableValueNode::create(type,value));
168 throw Error(_("Unable to create new value node"));
171 ValueNode::Handle dest_value_node;
172 dest_value_node=value_desc.get_value_node();
174 Action::Handle action(ValueDescConnect::create());
176 action->set_param("canvas",get_canvas());
177 action->set_param("canvas_interface",get_canvas_interface());
178 action->set_param("src",src_value_node);
179 action->set_param("dest",value_desc);
181 assert(action->is_ready());
182 if(!action->is_ready())
183 throw Error(Error::TYPE_NOTREADY);
185 add_action_front(action);
191 if(value_desc.parent_is_canvas())
193 ValueNode::Handle dest_value_node;
194 dest_value_node=value_desc.get_value_node();
196 Action::Handle action(ValueNodeReplace::create());
198 action->set_param("canvas",get_canvas());
199 action->set_param("canvas_interface",get_canvas_interface());
200 action->set_param("src",src_value_node);
201 action->set_param("dest",dest_value_node);
203 assert(action->is_ready());
204 if(!action->is_ready())
205 throw Error(Error::TYPE_NOTREADY);
207 add_action_front(action);
211 if(value_desc.parent_is_linkable_value_node())
213 Action::Handle action(ValueNodeLinkConnect::create());
215 action->set_param("canvas",get_canvas());
216 action->set_param("canvas_interface",get_canvas_interface());
217 action->set_param("parent_value_node",value_desc.get_parent_value_node());
218 action->set_param("value_node", src_value_node);
219 action->set_param("index",value_desc.get_index());
221 assert(action->is_ready());
222 if(!action->is_ready())
223 throw Error(Error::TYPE_NOTREADY);
225 add_action_front(action);
229 if(value_desc.parent_is_layer_param())
231 Action::Handle action(LayerParamConnect::create());
233 action->set_param("canvas",get_canvas());
234 action->set_param("canvas_interface",get_canvas_interface());
235 action->set_param("layer",value_desc.get_layer());
236 action->set_param("param",value_desc.get_param_name());
237 action->set_param("value_node",src_value_node);
239 assert(action->is_ready());
240 if(!action->is_ready())
241 throw Error(Error::TYPE_NOTREADY);
243 add_action_front(action);
249 throw Error(_("ValueDesc is not recognized or supported."));