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
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
34 #include "valuenodereplace.h"
35 #include "layerparamconnect.h"
36 #include "valuenodelinkconnect.h"
39 #include "valuedescconnect.h"
41 #include "valuedescconvert.h"
43 #include <synfigapp/canvasinterface.h>
44 #include <synfig/valuenode_const.h>
46 #include <synfigapp/general.h>
52 using namespace synfig;
53 using namespace synfigapp;
54 using namespace Action;
56 /* === M A C R O S ========================================================= */
58 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescConvert);
59 ACTION_SET_NAME(Action::ValueDescConvert,"ValueDescConvert");
60 ACTION_SET_LOCAL_NAME(Action::ValueDescConvert,N_("Convert"));
61 ACTION_SET_TASK(Action::ValueDescConvert,"convert");
62 ACTION_SET_CATEGORY(Action::ValueDescConvert,Action::CATEGORY_VALUEDESC);
63 ACTION_SET_PRIORITY(Action::ValueDescConvert,0);
64 ACTION_SET_VERSION(Action::ValueDescConvert,"0.0");
65 ACTION_SET_CVS_ID(Action::ValueDescConvert,"$Id$");
67 /* === G L O B A L S ======================================================= */
69 /* === P R O C E D U R E S ================================================= */
71 /* === M E T H O D S ======================================================= */
73 Action::ValueDescConvert::ValueDescConvert()
75 time=(Time::begin()-1);
79 Action::ValueDescConvert::get_local_name()const
81 // 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.
82 return strprintf(_("Convert '%s' to ValueNode type '%s'"),
83 value_desc.get_description().c_str(),
84 LinkableValueNode::book()[type].local_name.c_str());
88 Action::ValueDescConvert::get_param_vocab()
90 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
92 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
93 .set_local_name(_("ValueDesc"))
96 ret.push_back(ParamDesc("type",Param::TYPE_STRING)
97 .set_local_name(_("Type"))
98 .set_desc(_("The type of ValueNode that you want to be converted to"))
101 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
102 .set_local_name(_("Time"))
109 Action::ValueDescConvert::is_candidate(const ParamList &x)
111 return candidate_check(get_param_vocab(),x);
115 Action::ValueDescConvert::set_param(const synfig::String& name, const Action::Param ¶m)
117 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
119 value_desc=param.get_value_desc();
124 if(name=="type" && param.get_type()==Param::TYPE_STRING)
126 type=param.get_string();
131 if(name=="time" && param.get_type()==Param::TYPE_TIME)
133 time=param.get_time();
138 return Action::CanvasSpecific::set_param(name,param);
142 Action::ValueDescConvert::is_ready()const
144 if(!value_desc || type.empty())
146 if(time==(Time::begin()-1))
148 synfig::error("Missing time");
151 return Action::CanvasSpecific::is_ready();
155 Action::ValueDescConvert::prepare()
161 if(value_desc.is_const())
162 value=value_desc.get_value();
163 else if(value_desc.is_value_node())
164 value=(*value_desc.get_value_node())(time);
166 throw Error(_("Unable to decipher ValueDesc (Bug?)"));
168 ValueNode::Handle src_value_node(LinkableValueNode::create(type,value));
171 throw Error(_("Unable to create new value node"));
174 ValueNode::Handle dest_value_node;
175 dest_value_node=value_desc.get_value_node();
177 Action::Handle action(ValueDescConnect::create());
179 action->set_param("canvas",get_canvas());
180 action->set_param("canvas_interface",get_canvas_interface());
181 action->set_param("src",src_value_node);
182 action->set_param("dest",value_desc);
184 assert(action->is_ready());
185 if(!action->is_ready())
186 throw Error(Error::TYPE_NOTREADY);
188 add_action_front(action);
194 if(value_desc.parent_is_canvas())
196 ValueNode::Handle dest_value_node;
197 dest_value_node=value_desc.get_value_node();
199 Action::Handle action(ValueNodeReplace::create());
201 action->set_param("canvas",get_canvas());
202 action->set_param("canvas_interface",get_canvas_interface());
203 action->set_param("src",src_value_node);
204 action->set_param("dest",dest_value_node);
206 assert(action->is_ready());
207 if(!action->is_ready())
208 throw Error(Error::TYPE_NOTREADY);
210 add_action_front(action);
214 if(value_desc.parent_is_linkable_value_node())
216 Action::Handle action(ValueNodeLinkConnect::create());
218 action->set_param("canvas",get_canvas());
219 action->set_param("canvas_interface",get_canvas_interface());
220 action->set_param("parent_value_node",value_desc.get_parent_value_node());
221 action->set_param("value_node", src_value_node);
222 action->set_param("index",value_desc.get_index());
224 assert(action->is_ready());
225 if(!action->is_ready())
226 throw Error(Error::TYPE_NOTREADY);
228 add_action_front(action);
232 if(value_desc.parent_is_layer_param())
234 Action::Handle action(LayerParamConnect::create());
236 action->set_param("canvas",get_canvas());
237 action->set_param("canvas_interface",get_canvas_interface());
238 action->set_param("layer",value_desc.get_layer());
239 action->set_param("param",value_desc.get_param_name());
240 action->set_param("value_node",src_value_node);
242 assert(action->is_ready());
243 if(!action->is_ready())
244 throw Error(Error::TYPE_NOTREADY);
246 add_action_front(action);
252 throw Error(_("ValueDesc is not recognized or supported."));