Use the name of each action's class is its internal name. This makes it easier to...
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layerparamset.cpp
blob74ff99aba69a10e81a848d688fa251f1f493eaf8
1 /* === S Y N F I G ========================================================= */
2 /*! \file layerparamset.cpp
3 ** \brief Template File
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
19 ** \endlegal
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #ifdef USING_PCH
26 # include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
32 #include "layerparamset.h"
33 #include <synfigapp/canvasinterface.h>
35 #include <synfigapp/general.h>
37 #endif
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::LayerParamSet);
48 ACTION_SET_NAME(Action::LayerParamSet,"LayerParamSet");
49 ACTION_SET_LOCAL_NAME(Action::LayerParamSet,N_("Set Layer Parameter"));
50 ACTION_SET_TASK(Action::LayerParamSet,"set");
51 ACTION_SET_CATEGORY(Action::LayerParamSet,Action::CATEGORY_LAYER);
52 ACTION_SET_PRIORITY(Action::LayerParamSet,0);
53 ACTION_SET_VERSION(Action::LayerParamSet,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerParamSet,"$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::LayerParamSet::LayerParamSet()
66 Action::ParamVocab
67 Action::LayerParamSet::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("new_value",Param::TYPE_VALUE)
80 .set_local_name(_("ValueBase"))
83 return ret;
86 bool
87 Action::LayerParamSet::is_candidate(const ParamList &x)
89 return candidate_check(get_param_vocab(),x);
92 bool
93 Action::LayerParamSet::set_param(const synfig::String& name, const Action::Param &param)
95 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
97 layer=param.get_layer();
99 return true;
102 if(name=="new_value" && param.get_type()==Param::TYPE_VALUE)
104 new_value=param.get_value();
106 return true;
109 if(name=="param" && param.get_type()==Param::TYPE_STRING)
111 param_name=param.get_string();
113 return true;
116 return Action::CanvasSpecific::set_param(name,param);
119 bool
120 Action::LayerParamSet::is_ready()const
122 if(!layer || !new_value.is_valid() || param_name.empty())
123 return false;
124 return Action::CanvasSpecific::is_ready();
127 void
128 Action::LayerParamSet::perform()
130 // See if the parameter is dynamic
131 if(layer->dynamic_param_list().count(param_name))
132 throw Error(_("ValueNode attached to Parameter."));
134 old_value=layer->get_param(param_name);
136 if(!layer->set_param(param_name,new_value))
137 throw Error(_("Layer did not accept parameter."));
139 /*if(layer->active())
140 set_dirty(true);
141 else
142 set_dirty(false);
144 layer->changed();
146 // Signal that a layer has been inserted
147 if(get_canvas_interface())
149 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
153 void
154 Action::LayerParamSet::undo()
156 if(!layer->set_param(param_name,old_value))
157 throw Error(_("Layer did not accept parameter."));
160 if(layer->active())
161 set_dirty(true);
162 else
163 set_dirty(false);
166 layer->changed();
168 // Signal that a layer has been inserted
169 if(get_canvas_interface())
171 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);