source: synfigstudio/trunk/fuentes/src/synfigapp/actions/layerparamsetstatic.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 5.1 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file layerparamsetstatic.cpp
3**      \brief Template File
4**
5**      $Id$
6**
7**      \legal
8**      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9**      Copyright (c) 2010 Carlos López
10**
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.
15**
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.
20**      \endlegal
21*/
22/* ========================================================================= */
23
24/* === H E A D E R S ======================================================= */
25
26#ifdef USING_PCH
27#       include "pch.h"
28#else
29#ifdef HAVE_CONFIG_H
30#       include <config.h>
31#endif
32
33#include "layerparamsetstatic.h"
34#include <synfigapp/canvasinterface.h>
35
36#include <synfigapp/general.h>
37
38#endif
39
40using namespace std;
41using namespace etl;
42using namespace synfig;
43using namespace synfigapp;
44using namespace Action;
45
46/* === M A C R O S ========================================================= */
47
48ACTION_INIT(Action::LayerParamSetStatic);
49ACTION_SET_NAME(Action::LayerParamSetStatic,"LayerParamSetStatic");
50ACTION_SET_LOCAL_NAME(Action::LayerParamSetStatic,N_("Forbid Animation"));
51ACTION_SET_TASK(Action::LayerParamSetStatic,"setstatic");
52ACTION_SET_CATEGORY(Action::LayerParamSetStatic,Action::CATEGORY_VALUEDESC);
53ACTION_SET_PRIORITY(Action::LayerParamSetStatic,0);
54ACTION_SET_VERSION(Action::LayerParamSetStatic,"0.0");
55ACTION_SET_CVS_ID(Action::LayerParamSetStatic,"$Id$");
56
57/* === G L O B A L S ======================================================= */
58
59/* === P R O C E D U R E S ================================================= */
60
61/* === M E T H O D S ======================================================= */
62
63Action::LayerParamSetStatic::LayerParamSetStatic():
64        old_static_value()
65{ }
66
67Action::ParamVocab
68Action::LayerParamSetStatic::get_param_vocab()
69{
70        ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71
72        ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
73                .set_local_name(_("Value Desc"))
74        );
75
76        return ret;
77}
78
79bool
80Action::LayerParamSetStatic::is_candidate(const ParamList &x)
81{
82        if(!candidate_check(get_param_vocab(),x))
83                return false;
84
85        ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
86
87        if(!value_desc.parent_is_layer())
88                return false;
89
90        synfig::ValueBase parameter;
91        synfig::Layer::Handle _layer;
92        synfig::String _param_name;
93        _layer = value_desc.get_layer();
94        _param_name = value_desc.get_param_name();
95
96        if(!_layer || _param_name.empty())
97                return false;
98
99        //!Check that the parameter is not Value Node (Const, Animated or Linkable)
100        if(_layer->dynamic_param_list().count(_param_name))
101                return false;
102        //! Retrieves the current parameter
103        parameter = _layer->get_param(_param_name);
104        //! Check that the parameter is not a inline canvas
105        if(parameter.get_type()==type_canvas && parameter.get(Canvas::Handle()))
106                if(parameter.get(Canvas::Handle())->is_inline())
107                        return false;
108        //! Check if it is already static
109        if(parameter.get_static())
110                return false;
111
112        return true;
113
114}
115
116bool
117Action::LayerParamSetStatic::set_param(const synfig::String& name, const Action::Param &param)
118{
119
120        if(!layer && name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
121        {
122                ValueDesc value_desc(param.get_value_desc());
123                if(!value_desc.parent_is_layer())
124                        return false;
125
126                layer=Layer::Handle::cast_dynamic(value_desc.get_layer());
127
128                if(!layer)
129                        return false;
130        }
131
132
133        if(param_name.empty() && name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
134        {
135                ValueDesc value_desc(param.get_value_desc());
136                if(!value_desc.parent_is_layer())
137                        return false;
138
139                param_name=value_desc.get_param_name();
140
141                if(param_name.empty())
142                        return false;
143        }
144
145        return Action::CanvasSpecific::set_param(name,param);
146}
147
148bool
149Action::LayerParamSetStatic::is_ready()const
150{
151        if(!layer || param_name.empty())
152                return false;
153
154        return Action::CanvasSpecific::is_ready();
155}
156
157void
158Action::LayerParamSetStatic::perform()
159{
160        //! See if the parameter is dynamic
161        if(layer->dynamic_param_list().count(param_name))
162                throw Error(_("This action is not for Value Nodes!"));
163
164        old_static_value=false;
165
166        ValueBase v=layer->get_param(param_name);
167        v.set_static(true);
168        if(!layer->set_param(param_name,v))
169                throw Error(_("Layer did not accept static value."));
170
171        //! Signal layer changed
172        layer->changed();
173        //! Signal that a layer parameter changed
174        if(get_canvas_interface())
175                get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
176}
177
178void
179Action::LayerParamSetStatic::undo()
180{
181        ValueBase v=layer->get_param(param_name);
182        v.set_static(old_static_value);
183        if(!layer->set_param(param_name,v))
184           throw Error(_("Layer did not accept static value."));
185
186        //! Signal layer changed
187        layer->changed();
188        //! Signal that a layer parameter changed
189        if(get_canvas_interface())
190                get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
191}
Note: See TracBrowser for help on using the repository browser.