Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / src / synfigapp / actions / layerparamset.cpp
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.
14 **
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
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "layerparamset.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #include <synfigapp/general.h>
36
37 #endif
38
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
44
45 /* === M A C R O S ========================================================= */
46
47 ACTION_INIT(Action::LayerParamSet);
48 ACTION_SET_NAME(Action::LayerParamSet,"layer_param_set");
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$");
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 Action::LayerParamSet::LayerParamSet()
63 {
64 }
65
66 Action::ParamVocab
67 Action::LayerParamSet::get_param_vocab()
68 {
69         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70
71         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
72                 .set_local_name(_("Layer"))
73         );
74
75         ret.push_back(ParamDesc("param",Param::TYPE_STRING)
76                 .set_local_name(_("Param"))
77         );
78
79         ret.push_back(ParamDesc("new_value",Param::TYPE_VALUE)
80                 .set_local_name(_("ValueBase"))
81         );
82
83         return ret;
84 }
85
86 bool
87 Action::LayerParamSet::is_candidate(const ParamList &x)
88 {
89         return candidate_check(get_param_vocab(),x);
90 }
91
92 bool
93 Action::LayerParamSet::set_param(const synfig::String& name, const Action::Param &param)
94 {
95         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
96         {
97                 layer=param.get_layer();
98
99                 return true;
100         }
101
102         if(name=="new_value" && param.get_type()==Param::TYPE_VALUE)
103         {
104                 new_value=param.get_value();
105
106                 return true;
107         }
108
109         if(name=="param" && param.get_type()==Param::TYPE_STRING)
110         {
111                 param_name=param.get_string();
112
113                 return true;
114         }
115
116         return Action::CanvasSpecific::set_param(name,param);
117 }
118
119 bool
120 Action::LayerParamSet::is_ready()const
121 {
122         if(!layer || !new_value.is_valid() || param_name.empty())
123                 return false;
124         return Action::CanvasSpecific::is_ready();
125 }
126
127 void
128 Action::LayerParamSet::perform()
129 {
130         // See if the parameter is dynamic
131         if(layer->dynamic_param_list().count(param_name))
132                 throw Error(_("ValueNode attached to Parameter."));
133
134         old_value=layer->get_param(param_name);
135
136         if(!layer->set_param(param_name,new_value))
137                 throw Error(_("Layer did not accept parameter."));
138
139         /*if(layer->active())
140                 set_dirty(true);
141         else
142                 set_dirty(false);
143         */
144         layer->changed();
145
146         // Signal that a layer has been inserted
147         if(get_canvas_interface())
148         {
149                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
150         }
151 }
152
153 void
154 Action::LayerParamSet::undo()
155 {
156         if(!layer->set_param(param_name,old_value))
157                 throw Error(_("Layer did not accept parameter."));
158
159         /*
160         if(layer->active())
161                 set_dirty(true);
162         else
163                 set_dirty(false);
164         */
165
166         layer->changed();
167
168         // Signal that a layer has been inserted
169         if(get_canvas_interface())
170         {
171                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
172         }
173 }