1 /* === S Y N F I G ========================================================= */
2 /*! \file valuedescconnect.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 "layerparamconnect.h"
34 #include "waypointconnect.h"
35 #include "valuenodelinkconnect.h"
36 #include "valuenodereplace.h"
38 #include "valuedescconnect.h"
39 #include <synfigapp/canvasinterface.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_NO_GET_LOCAL_NAME(Action::ValueDescConnect);
54 ACTION_SET_NAME(Action::ValueDescConnect,"ValueDescConnect");
55 ACTION_SET_LOCAL_NAME(Action::ValueDescConnect,N_("Connect"));
56 ACTION_SET_TASK(Action::ValueDescConnect,"connect");
57 ACTION_SET_CATEGORY(Action::ValueDescConnect,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
58 ACTION_SET_PRIORITY(Action::ValueDescConnect,0);
59 ACTION_SET_VERSION(Action::ValueDescConnect,"0.0");
60 ACTION_SET_CVS_ID(Action::ValueDescConnect,"$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::ValueDescConnect::ValueDescConnect()
73 Action::ValueDescConnect::get_local_name()const
75 // TRANSLATORS: This is used in the 'history' dialog when a connection is made.
76 return strprintf(_("Connect '%s' to '%s'"),
77 value_desc.get_description(false).c_str(),
78 value_node->get_id().c_str());
82 Action::ValueDescConnect::get_param_vocab()
84 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
86 ret.push_back(ParamDesc("dest",Param::TYPE_VALUEDESC)
87 .set_local_name(_("Destination ValueDesc"))
90 ret.push_back(ParamDesc("src",Param::TYPE_VALUENODE)
91 .set_local_name(_("Source ValueNode"))
92 .set_mutual_exclusion("src_name")
95 ret.push_back(ParamDesc("src_name",Param::TYPE_STRING)
96 .set_local_name(_("Source ValueNode Name"))
97 .set_mutual_exclusion("src")
105 Action::ValueDescConnect::is_candidate(const ParamList &x)
107 if(candidate_check(get_param_vocab(),x))
109 // don't show the option of connecting to an existing Index parameter of the Duplicate layer
112 ValueDesc value_desc=x.find("dest")->second.get_value_desc();
114 if (value_desc.parent_is_layer_param() &&
115 value_desc.get_layer()->get_name() == "duplicate" &&
116 value_desc.get_param_name() == "index")
122 ValueDesc value_desc=x.find("dest")->second.get_value_desc();
123 ValueNode::Handle value_node=x.find("src")->second.get_value_node();
124 if(value_desc.get_value_type()==value_node->get_type())
133 Action::ValueDescConnect::set_param(const synfig::String& name, const Action::Param ¶m)
135 if(name=="dest" && param.get_type()==Param::TYPE_VALUEDESC)
137 value_desc=param.get_value_desc();
142 if(name=="src" && param.get_type()==Param::TYPE_VALUENODE)
144 value_node=param.get_value_node();
149 if(!value_node_name.empty() && !value_node && name=="canvas" && param.get_type()==Param::TYPE_CANVAS)
151 value_node=param.get_canvas()->find_value_node(value_node_name);
154 if(name=="src_name" && param.get_type()==Param::TYPE_STRING)
156 value_node_name=param.get_string();
160 value_node=get_canvas()->find_value_node(value_node_name);
168 return Action::CanvasSpecific::set_param(name,param);
172 Action::ValueDescConnect::is_ready()const
174 if(!value_desc || !value_node)
176 return Action::CanvasSpecific::is_ready();
180 Action::ValueDescConnect::prepare()
184 if(value_desc.parent_is_canvas())
186 ValueNode::Handle dest_value_node;
187 dest_value_node=value_desc.get_value_node();
189 Action::Handle action(ValueNodeReplace::create());
191 action->set_param("canvas",get_canvas());
192 action->set_param("canvas_interface",get_canvas_interface());
193 action->set_param("src",value_node);
194 action->set_param("dest",value_desc.get_value_node());
196 assert(action->is_ready());
197 if(!action->is_ready())
198 throw Error(Error::TYPE_NOTREADY);
200 add_action_front(action);
204 if(value_desc.parent_is_waypoint())
206 Action::Handle action(WaypointConnect::create());
208 action->set_param("canvas",get_canvas());
209 action->set_param("canvas_interface",get_canvas_interface());
210 action->set_param("parent_value_node",value_desc.get_parent_value_node());
211 action->set_param("value_node", value_node);
212 action->set_param("waypoint_time",value_desc.get_waypoint_time());
214 assert(action->is_ready());
215 if(!action->is_ready())
216 throw Error(Error::TYPE_NOTREADY);
218 add_action_front(action);
221 if(value_desc.parent_is_linkable_value_node())
223 Action::Handle action(ValueNodeLinkConnect::create());
225 action->set_param("canvas",get_canvas());
226 action->set_param("canvas_interface",get_canvas_interface());
227 action->set_param("parent_value_node",value_desc.get_parent_value_node());
228 action->set_param("value_node", value_node);
229 action->set_param("index",value_desc.get_index());
231 assert(action->is_ready());
232 if(!action->is_ready())
233 throw Error(Error::TYPE_NOTREADY);
235 add_action_front(action);
239 if(value_desc.parent_is_layer_param())
241 Action::Handle action(LayerParamConnect::create());
243 action->set_param("canvas",get_canvas());
244 action->set_param("canvas_interface",get_canvas_interface());
245 action->set_param("layer",value_desc.get_layer());
246 action->set_param("param",value_desc.get_param_name());
247 action->set_param("value_node",value_node);
249 assert(action->is_ready());
250 if(!action->is_ready())
251 throw Error(Error::TYPE_NOTREADY);
253 add_action_front(action);
257 throw Error(_("ValueDesc is not recognized or supported."));