Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_04 / synfig-studio / src / synfigapp / actions / layerparamset.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layerparamset.cpp
3 **      \brief Template File
4 **
5 **      $Id: layerparamset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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 #endif
36
37 using namespace std;
38 using namespace etl;
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
42
43 /* === M A C R O S ========================================================= */
44
45 ACTION_INIT(Action::LayerParamSet);
46 ACTION_SET_NAME(Action::LayerParamSet,"layer_param_set");
47 ACTION_SET_LOCAL_NAME(Action::LayerParamSet,_("Set Layer Parameter"));
48 ACTION_SET_TASK(Action::LayerParamSet,"set");
49 ACTION_SET_CATEGORY(Action::LayerParamSet,Action::CATEGORY_LAYER);
50 ACTION_SET_PRIORITY(Action::LayerParamSet,0);
51 ACTION_SET_VERSION(Action::LayerParamSet,"0.0");
52 ACTION_SET_CVS_ID(Action::LayerParamSet,"$Id: layerparamset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 Action::LayerParamSet::LayerParamSet()
61 {
62 }
63
64 Action::ParamVocab
65 Action::LayerParamSet::get_param_vocab()
66 {
67         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
68         
69         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
70                 .set_local_name(_("Layer"))
71         );
72
73         ret.push_back(ParamDesc("param",Param::TYPE_STRING)
74                 .set_local_name(_("Param"))
75         );
76
77         ret.push_back(ParamDesc("new_value",Param::TYPE_VALUE)
78                 .set_local_name(_("ValueBase"))
79         );
80         
81         return ret;
82 }
83
84 bool
85 Action::LayerParamSet::is_canidate(const ParamList &x)
86 {
87         return canidate_check(get_param_vocab(),x);
88 }
89
90 bool
91 Action::LayerParamSet::set_param(const synfig::String& name, const Action::Param &param)
92 {
93         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
94         {
95                 layer=param.get_layer();
96                 
97                 return true;
98         }
99
100         if(name=="new_value" && param.get_type()==Param::TYPE_VALUE)
101         {
102                 new_value=param.get_value();
103                 
104                 return true;
105         }
106
107         if(name=="param" && param.get_type()==Param::TYPE_STRING)
108         {
109                 param_name=param.get_string();
110                 
111                 return true;
112         }
113
114         return Action::CanvasSpecific::set_param(name,param);
115 }
116
117 bool
118 Action::LayerParamSet::is_ready()const
119 {
120         if(!layer || !new_value.is_valid() || param_name.empty())
121                 return false;
122         return Action::CanvasSpecific::is_ready();
123 }
124
125 void
126 Action::LayerParamSet::perform()
127 {
128         // See if the parameter is dynamic
129         if(layer->dynamic_param_list().count(param_name))
130                 throw Error(_("ValueNode attached to Parameter."));
131
132         old_value=layer->get_param(param_name);
133         
134         if(!layer->set_param(param_name,new_value))
135                 throw Error(_("Layer did not accept parameter."));
136
137         /*if(layer->active())
138                 set_dirty(true);
139         else
140                 set_dirty(false);
141         */
142         layer->changed();
143         
144         // Signal that a layer has been inserted
145         if(get_canvas_interface())
146         {
147                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
148         }
149 }
150
151 void
152 Action::LayerParamSet::undo()
153 {
154         if(!layer->set_param(param_name,old_value))
155                 throw Error(_("Layer did not accept parameter."));
156
157         /*
158         if(layer->active())
159                 set_dirty(true);
160         else
161                 set_dirty(false);
162         */
163         
164         layer->changed();
165         
166         // Signal that a layer has been inserted
167         if(get_canvas_interface())
168         {
169                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
170         }
171 }