1 /* === S Y N F I G ========================================================= */
2 /*! \file layerparamconnect.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 "layerparamconnect.h"
33 #include <synfigapp/canvasinterface.h>
35 #include <synfigapp/general.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::LayerParamConnect);
48 ACTION_SET_NAME(Action::LayerParamConnect,"LayerParamConnect");
49 ACTION_SET_LOCAL_NAME(Action::LayerParamConnect,N_("Connect Layer Parameter"));
50 ACTION_SET_TASK(Action::LayerParamConnect,"connect");
51 ACTION_SET_CATEGORY(Action::LayerParamConnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
52 ACTION_SET_PRIORITY(Action::LayerParamConnect,0);
53 ACTION_SET_VERSION(Action::LayerParamConnect,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerParamConnect,"$Id$");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::LayerParamConnect::LayerParamConnect()
67 Action::LayerParamConnect::get_param_vocab()
69 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
72 .set_local_name(_("Layer"))
75 ret.push_back(ParamDesc("param",Param::TYPE_STRING)
76 .set_local_name(_("Param"))
79 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
80 .set_local_name(_("ValueNode"))
87 Action::LayerParamConnect::is_candidate(const ParamList &x)
89 return candidate_check(get_param_vocab(),x);
93 Action::LayerParamConnect::set_param(const synfig::String& name, const Action::Param ¶m)
95 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
97 layer=param.get_layer();
102 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
104 value_node=param.get_value_node();
109 if(name=="param" && param.get_type()==Param::TYPE_STRING)
111 param_name=param.get_string();
116 return Action::CanvasSpecific::set_param(name,param);
120 Action::LayerParamConnect::is_ready()const
123 synfig::warning("Action::LayerParamConnect: Missing \"layer\"");
125 synfig::warning("Action::LayerParamConnect: Missing \"value_node\"");
126 if(param_name.empty())
127 synfig::warning("Action::LayerParamConnect: Missing \"param\"");
129 if(!layer || !value_node || param_name.empty())
131 return Action::CanvasSpecific::is_ready();
135 Action::LayerParamConnect::perform()
137 // See if the parameter is dynamic
138 if(layer->dynamic_param_list().count(param_name))
139 old_value_node=layer->dynamic_param_list().find(param_name)->second;
145 old_value=layer->get_param(param_name);
146 if(!old_value.is_valid())
147 throw Error(_("Layer did not recognize parameter name"));
149 if(!layer->set_param(param_name,(*value_node)(0)))
150 throw Error(_("Bad connection"));
152 layer->connect_dynamic_param(param_name,value_node);
155 value_node->changed();
156 /* if(get_canvas_interface())
158 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
159 //get_canvas_interface()->signal_value_node_changed()(value_node);
165 Action::LayerParamConnect::undo()
168 layer->connect_dynamic_param(param_name,old_value_node);
171 layer->disconnect_dynamic_param(param_name);
172 layer->set_param(param_name,old_value);
177 old_value_node->changed();
185 if(get_canvas_interface())
187 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
188 //if(old_value_node)get_canvas_interface()->signal_value_node_changed()(old_value_node);