1 /* === S Y N F I G ========================================================= */
2 /*! \file valuedescexport.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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 ======================================================= */
33 #include "valuenodeadd.h"
35 #include "canvasadd.h"
36 #include "valuedescexport.h"
37 #include "layerparamconnect.h"
39 #include <synfigapp/canvasinterface.h>
40 #include <synfig/valuenode_const.h>
42 #include <synfigapp/general.h>
48 using namespace synfig;
49 using namespace synfigapp;
50 using namespace Action;
52 /* === M A C R O S ========================================================= */
54 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescExport);
55 ACTION_SET_NAME(Action::ValueDescExport,"value_desc_export");
56 ACTION_SET_LOCAL_NAME(Action::ValueDescExport,N_("Export"));
57 ACTION_SET_TASK(Action::ValueDescExport,"export");
58 ACTION_SET_CATEGORY(Action::ValueDescExport,Action::CATEGORY_VALUEDESC);
59 ACTION_SET_PRIORITY(Action::ValueDescExport,0);
60 ACTION_SET_VERSION(Action::ValueDescExport,"0.0");
61 ACTION_SET_CVS_ID(Action::ValueDescExport,"$Id$");
63 /* === G L O B A L S ======================================================= */
65 /* === P R O C E D U R E S ================================================= */
67 /* === M E T H O D S ======================================================= */
69 Action::ValueDescExport::ValueDescExport()
74 Action::ValueDescExport::get_local_name()const
76 // TRANSLATORS: This is used in the 'history' dialog when a ValueNode is exported. The first %s is what is exported, the 2nd is the name it is given.
77 return strprintf(_("Export '%s' as '%s'"),
78 value_desc.get_description(false).c_str(),
83 Action::ValueDescExport::get_param_vocab()
85 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
87 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
88 .set_local_name(_("ValueDesc"))
91 ret.push_back(ParamDesc("name",Param::TYPE_STRING)
92 .set_local_name(_("Name"))
93 .set_desc(_("The name that you want this value to be exported as"))
101 Action::ValueDescExport::is_candidate(const ParamList &x)
103 if(candidate_check(get_param_vocab(),x))
105 ValueDesc value_desc=x.find("value_desc")->second.get_value_desc();
106 if(!value_desc || value_desc.parent_is_canvas() || (value_desc.is_value_node() && value_desc.get_value_node()->is_exported()))
114 Action::ValueDescExport::set_param(const synfig::String& param_name, const Action::Param ¶m)
116 if(param_name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
118 value_desc=param.get_value_desc();
123 if(param_name=="name" && param.get_type()==Param::TYPE_STRING)
125 name=param.get_string();
130 return Action::CanvasSpecific::set_param(param_name,param);
134 Action::ValueDescExport::is_ready()const
136 if(!value_desc || name.empty())
138 return Action::CanvasSpecific::is_ready();
142 Action::ValueDescExport::prepare()
146 ValueNode::Handle value_node;
148 if(value_desc.get_value_type()==ValueBase::TYPE_CANVAS)
150 if(!value_desc.is_const())
151 throw Error(_("Can only export Canvas when used as constant parameter"));
152 Canvas::Handle canvas(value_desc.get_value().get(Canvas::Handle()));
154 Action::Handle action(CanvasAdd::create());
156 action->set_param("canvas",get_canvas());
157 action->set_param("canvas_interface",get_canvas_interface());
158 action->set_param("src",canvas);
159 action->set_param("id",name);
161 assert(action->is_ready());
162 if(!action->is_ready())
163 throw Error(Error::TYPE_NOTREADY);
165 add_action_front(action);
171 if(value_desc.is_value_node())
173 if(value_desc.get_value_node()->is_exported())
174 throw Error(_("ValueBase is already exported"));
176 value_node=value_desc.get_value_node();
180 if(!value_desc.parent_is_layer_param())
181 throw Error(_("Unable to export parameter. (Bug?)"));
183 value_node=ValueNode_Const::create(value_desc.get_value());
185 Action::Handle action(LayerParamConnect::create());
187 action->set_param("canvas",get_canvas());
188 action->set_param("canvas_interface",get_canvas_interface());
189 action->set_param("layer",value_desc.get_layer());
190 action->set_param("param",value_desc.get_param_name());
191 action->set_param("value_node",value_node);
193 assert(action->is_ready());
194 if(!action->is_ready())
195 throw Error(Error::TYPE_NOTREADY);
197 add_action_front(action);
200 Action::Handle action(ValueNodeAdd::create());
202 action->set_param("canvas",get_canvas());
203 action->set_param("canvas_interface",get_canvas_interface());
204 action->set_param("new",value_node);
205 action->set_param("name",name);
207 assert(action->is_ready());
208 if(!action->is_ready())
209 throw Error(Error::TYPE_NOTREADY);
211 add_action_front(action);