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 "valuenodelinkconnect.h"
35 #include "valuenodereplace.h"
37 #include "valuedescconnect.h"
38 #include <synfigapp/canvasinterface.h>
40 #include <synfigapp/general.h>
46 using namespace synfig;
47 using namespace synfigapp;
48 using namespace Action;
50 /* === M A C R O S ========================================================= */
52 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescConnect);
53 ACTION_SET_NAME(Action::ValueDescConnect,"value_desc_connect");
54 ACTION_SET_LOCAL_NAME(Action::ValueDescConnect,N_("Connect"));
55 ACTION_SET_TASK(Action::ValueDescConnect,"connect");
56 ACTION_SET_CATEGORY(Action::ValueDescConnect,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
57 ACTION_SET_PRIORITY(Action::ValueDescConnect,0);
58 ACTION_SET_VERSION(Action::ValueDescConnect,"0.0");
59 ACTION_SET_CVS_ID(Action::ValueDescConnect,"$Id$");
61 /* === G L O B A L S ======================================================= */
63 /* === P R O C E D U R E S ================================================= */
65 /* === M E T H O D S ======================================================= */
67 Action::ValueDescConnect::ValueDescConnect()
72 Action::ValueDescConnect::get_local_name()const
74 // TRANSLATORS: This is used in the 'history' dialog when a connection is made.
75 return strprintf(_("Connect '%s' to '%s'"),
76 value_desc.get_description(false).c_str(),
77 value_node->get_id().c_str());
81 Action::ValueDescConnect::get_param_vocab()
83 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
85 ret.push_back(ParamDesc("dest",Param::TYPE_VALUEDESC)
86 .set_local_name(_("Destination ValueDesc"))
89 ret.push_back(ParamDesc("src",Param::TYPE_VALUENODE)
90 .set_local_name(_("Source ValueNode"))
91 .set_mutual_exclusion("src_name")
94 ret.push_back(ParamDesc("src_name",Param::TYPE_STRING)
95 .set_local_name(_("Source ValueNode Name"))
96 .set_mutual_exclusion("src")
104 Action::ValueDescConnect::is_candidate(const ParamList &x)
106 if(candidate_check(get_param_vocab(),x))
108 // don't show the option of connecting to an existing Index parameter of the Duplicate layer
111 ValueDesc value_desc=x.find("dest")->second.get_value_desc();
113 if (value_desc.parent_is_layer_param() &&
114 value_desc.get_layer()->get_name() == "duplicate" &&
115 value_desc.get_param_name() == "index")
121 ValueDesc value_desc=x.find("dest")->second.get_value_desc();
122 ValueNode::Handle value_node=x.find("src")->second.get_value_node();
123 if(value_desc.get_value_type()==value_node->get_type())
132 Action::ValueDescConnect::set_param(const synfig::String& name, const Action::Param ¶m)
134 if(name=="dest" && param.get_type()==Param::TYPE_VALUEDESC)
136 value_desc=param.get_value_desc();
141 if(name=="src" && param.get_type()==Param::TYPE_VALUENODE)
143 value_node=param.get_value_node();
148 if(!value_node_name.empty() && !value_node && name=="canvas" && param.get_type()==Param::TYPE_CANVAS)
150 value_node=param.get_canvas()->find_value_node(value_node_name);
153 if(name=="src_name" && param.get_type()==Param::TYPE_STRING)
155 value_node_name=param.get_string();
159 value_node=get_canvas()->find_value_node(value_node_name);
167 return Action::CanvasSpecific::set_param(name,param);
171 Action::ValueDescConnect::is_ready()const
173 if(!value_desc || !value_node)
175 return Action::CanvasSpecific::is_ready();
179 Action::ValueDescConnect::prepare()
183 if(value_desc.parent_is_canvas())
185 ValueNode::Handle dest_value_node;
186 dest_value_node=value_desc.get_value_node();
188 Action::Handle action(ValueNodeReplace::create());
190 action->set_param("canvas",get_canvas());
191 action->set_param("canvas_interface",get_canvas_interface());
192 action->set_param("src",value_node);
193 action->set_param("dest",value_desc.get_value_node());
195 assert(action->is_ready());
196 if(!action->is_ready())
197 throw Error(Error::TYPE_NOTREADY);
199 add_action_front(action);
203 if(value_desc.parent_is_linkable_value_node())
205 Action::Handle action(ValueNodeLinkConnect::create());
207 action->set_param("canvas",get_canvas());
208 action->set_param("canvas_interface",get_canvas_interface());
209 action->set_param("parent_value_node",value_desc.get_parent_value_node());
210 action->set_param("value_node", value_node);
211 action->set_param("index",value_desc.get_index());
213 assert(action->is_ready());
214 if(!action->is_ready())
215 throw Error(Error::TYPE_NOTREADY);
217 add_action_front(action);
221 if(value_desc.parent_is_layer_param())
223 Action::Handle action(LayerParamConnect::create());
225 action->set_param("canvas",get_canvas());
226 action->set_param("canvas_interface",get_canvas_interface());
227 action->set_param("layer",value_desc.get_layer());
228 action->set_param("param",value_desc.get_param_name());
229 action->set_param("value_node",value_node);
231 assert(action->is_ready());
232 if(!action->is_ready())
233 throw Error(Error::TYPE_NOTREADY);
235 add_action_front(action);
239 throw Error(_("ValueDesc is not recognized or supported."));