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
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 ======================================================= */
32 #include "valuenodeadd.h"
34 #include "canvasadd.h"
35 #include "valuedescexport.h"
36 #include "layerparamconnect.h"
38 #include <synfigapp/canvasinterface.h>
39 #include <synfig/valuenode_const.h>
41 #include <synfigapp/general.h>
47 using namespace synfig;
48 using namespace synfigapp;
49 using namespace Action;
51 /* === M A C R O S ========================================================= */
53 ACTION_INIT(Action::ValueDescExport);
54 ACTION_SET_NAME(Action::ValueDescExport,"value_desc_export");
55 ACTION_SET_LOCAL_NAME(Action::ValueDescExport,N_("Export"));
56 ACTION_SET_TASK(Action::ValueDescExport,"export");
57 ACTION_SET_CATEGORY(Action::ValueDescExport,Action::CATEGORY_VALUEDESC);
58 ACTION_SET_PRIORITY(Action::ValueDescExport,0);
59 ACTION_SET_VERSION(Action::ValueDescExport,"0.0");
60 ACTION_SET_CVS_ID(Action::ValueDescExport,"$Id$");
62 /* === G L O B A L S ======================================================= */
64 /* === P R O C E D U R E S ================================================= */
66 /* === M E T H O D S ======================================================= */
68 Action::ValueDescExport::ValueDescExport()
73 Action::ValueDescExport::get_param_vocab()
75 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
77 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
78 .set_local_name(_("ValueDesc"))
81 ret.push_back(ParamDesc("name",Param::TYPE_STRING)
82 .set_local_name(_("Name"))
83 .set_desc(_("The name that you want this value to be exported as"))
91 Action::ValueDescExport::is_candidate(const ParamList &x)
93 if(candidate_check(get_param_vocab(),x))
95 ValueDesc value_desc=x.find("value_desc")->second.get_value_desc();
96 if(!value_desc || value_desc.parent_is_canvas() || (value_desc.is_value_node() && value_desc.get_value_node()->is_exported()))
104 Action::ValueDescExport::set_param(const synfig::String& param_name, const Action::Param ¶m)
106 if(param_name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
108 value_desc=param.get_value_desc();
113 if(param_name=="name" && param.get_type()==Param::TYPE_STRING)
115 name=param.get_string();
120 return Action::CanvasSpecific::set_param(param_name,param);
124 Action::ValueDescExport::is_ready()const
126 if(!value_desc || name.empty())
128 return Action::CanvasSpecific::is_ready();
132 Action::ValueDescExport::prepare()
136 ValueNode::Handle value_node;
138 if(value_desc.get_value_type()==ValueBase::TYPE_CANVAS)
140 if(!value_desc.is_const())
141 throw Error(_("Can only export Canvas when used as constant parameter"));
142 Canvas::Handle canvas(value_desc.get_value().get(Canvas::Handle()));
144 Action::Handle action(CanvasAdd::create());
146 action->set_param("canvas",get_canvas());
147 action->set_param("canvas_interface",get_canvas_interface());
148 action->set_param("src",canvas);
149 action->set_param("id",name);
151 assert(action->is_ready());
152 if(!action->is_ready())
153 throw Error(Error::TYPE_NOTREADY);
155 add_action_front(action);
161 if(value_desc.is_value_node())
163 if(value_desc.get_value_node()->is_exported())
164 throw Error(_("ValueBase is already exported"));
166 value_node=value_desc.get_value_node();
170 if(!value_desc.parent_is_layer_param())
171 throw Error(_("Unable to export parameter. (Bug?)"));
173 value_node=ValueNode_Const::create(value_desc.get_value());
175 Action::Handle action(LayerParamConnect::create());
177 action->set_param("canvas",get_canvas());
178 action->set_param("canvas_interface",get_canvas_interface());
179 action->set_param("layer",value_desc.get_layer());
180 action->set_param("param",value_desc.get_param_name());
181 action->set_param("value_node",value_node);
183 assert(action->is_ready());
184 if(!action->is_ready())
185 throw Error(Error::TYPE_NOTREADY);
187 add_action_front(action);
190 Action::Handle action(ValueNodeAdd::create());
192 action->set_param("canvas",get_canvas());
193 action->set_param("canvas_interface",get_canvas_interface());
194 action->set_param("new",value_node);
195 action->set_param("name",name);
197 assert(action->is_ready());
198 if(!action->is_ready())
199 throw Error(Error::TYPE_NOTREADY);
201 add_action_front(action);