Quote the "Working Draft, Standard for Programming Language C++" on a point I wasn...
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layerparamdisconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layerparamdisconnect.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 "layerparamdisconnect.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_dynamiclist.h>
35
36 #endif
37
38 using namespace std;
39 using namespace etl;
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
43
44 /* === M A C R O S ========================================================= */
45
46 ACTION_INIT(Action::LayerParamDisconnect);
47 ACTION_SET_NAME(Action::LayerParamDisconnect,"layer_param_disconnect");
48 ACTION_SET_LOCAL_NAME(Action::LayerParamDisconnect,_("Disconnect Layer Parameter"));
49 ACTION_SET_TASK(Action::LayerParamDisconnect,"disconnect");
50 ACTION_SET_CATEGORY(Action::LayerParamDisconnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
51 ACTION_SET_PRIORITY(Action::LayerParamDisconnect,0);
52 ACTION_SET_VERSION(Action::LayerParamDisconnect,"0.0");
53 ACTION_SET_CVS_ID(Action::LayerParamDisconnect,"$Id$");
54
55 /* === G L O B A L S ======================================================= */
56
57 /* === P R O C E D U R E S ================================================= */
58
59 /* === M E T H O D S ======================================================= */
60
61 Action::LayerParamDisconnect::LayerParamDisconnect():
62         time(0)
63 {
64
65 }
66
67 Action::ParamVocab
68 Action::LayerParamDisconnect::get_param_vocab()
69 {
70         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71
72         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
73                 .set_local_name(_("Layer"))
74         );
75
76         ret.push_back(ParamDesc("param",Param::TYPE_STRING)
77                 .set_local_name(_("Param"))
78         );
79
80         ret.push_back(ParamDesc("time",Param::TYPE_STRING)
81                 .set_local_name(_("Time"))
82                 .set_optional()
83         );
84
85         return ret;
86 }
87
88 bool
89 Action::LayerParamDisconnect::is_candidate(const ParamList &x)
90 {
91         return candidate_check(get_param_vocab(),x);
92 }
93
94 bool
95 Action::LayerParamDisconnect::set_param(const synfig::String& name, const Action::Param &param)
96 {
97         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
98         {
99                 layer=param.get_layer();
100
101                 return true;
102         }
103
104         if(name=="param" && param.get_type()==Param::TYPE_STRING)
105         {
106                 param_name=param.get_string();
107
108                 return true;
109         }
110
111         if(name=="time" && param.get_type()==Param::TYPE_TIME)
112         {
113                 time=param.get_time();
114
115                 return true;
116         }
117
118         return Action::CanvasSpecific::set_param(name,param);
119 }
120
121 bool
122 Action::LayerParamDisconnect::is_ready()const
123 {
124         if(!layer || param_name.empty())
125                 return false;
126         return Action::CanvasSpecific::is_ready();
127 }
128
129 void
130 Action::LayerParamDisconnect::perform()
131 {
132         if(!layer->dynamic_param_list().count(param_name))
133                 throw Error(_("Layer Parameter is not connected to anything"));
134
135         old_value_node=layer->dynamic_param_list().find(param_name)->second;
136         layer->disconnect_dynamic_param(param_name);
137
138         if(new_value_node || ValueNode_DynamicList::Handle::cast_dynamic(old_value_node))
139         {
140                 if(!new_value_node)
141                         new_value_node=old_value_node.clone();
142                 layer->connect_dynamic_param(param_name,new_value_node);
143         }
144         else
145                 layer->set_param(param_name,(*old_value_node)(time));
146
147         layer->changed();
148         old_value_node->changed();
149
150         set_dirty(false);
151
152         if(get_canvas_interface())
153         {
154                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
155         }
156 }
157
158 void
159 Action::LayerParamDisconnect::undo()
160 {
161         layer->connect_dynamic_param(param_name,old_value_node);
162
163 /*      if(layer->active() && get_canvas()->get_time()!=time)
164                 set_dirty(true);
165         else
166                 set_dirty(false);
167 */
168         layer->changed();
169         old_value_node->changed();
170
171         set_dirty(false);
172
173         if(get_canvas_interface())
174         {
175                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
176         }
177 }