Made the rotation counter quieter still - it only starts reporting the rotation count...
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuenodedynamiclistremovesmart.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodedynamiclistremovesmart.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 "valuenodedynamiclistremovesmart.h"
33 #include "valuenodedynamiclistremove.h"
34 #include <synfigapp/canvasinterface.h>
35
36 #include <synfigapp/general.h>
37
38 #endif
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
45
46 /* === M A C R O S ========================================================= */
47
48 ACTION_INIT(Action::ValueNodeDynamicListRemoveSmart);
49 ACTION_SET_NAME(Action::ValueNodeDynamicListRemoveSmart,"value_node_dynamic_list_remove_smart");
50 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListRemoveSmart,N_("Remove Item (Smart)"));
51 ACTION_SET_TASK(Action::ValueNodeDynamicListRemoveSmart,"remove");
52 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListRemoveSmart,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListRemoveSmart,-19);
54 ACTION_SET_VERSION(Action::ValueNodeDynamicListRemoveSmart,"0.0");
55 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListRemoveSmart,"$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
63 Action::ValueNodeDynamicListRemoveSmart::ValueNodeDynamicListRemoveSmart()
64 {
65         index=0;
66         time=0;
67         origin=0.5f;
68         set_dirty(true);
69 }
70
71 Action::ParamVocab
72 Action::ValueNodeDynamicListRemoveSmart::get_param_vocab()
73 {
74         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75
76         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
77                 .set_local_name(_("ValueDesc"))
78         );
79         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
80                 .set_local_name(_("Time"))
81                 .set_optional()
82         );
83         ret.push_back(ParamDesc("origin",Param::TYPE_REAL)
84                 .set_local_name(_("Origin"))
85                 .set_optional()
86         );
87
88         return ret;
89 }
90
91 bool
92 Action::ValueNodeDynamicListRemoveSmart::is_candidate(const ParamList &x)
93 {
94         if(candidate_check(get_param_vocab(),x))
95         {
96                 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
97                 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
98                         return false;
99
100                 return true;
101         }
102         return false;
103 }
104
105 bool
106 Action::ValueNodeDynamicListRemoveSmart::set_param(const synfig::String& name, const Action::Param &param)
107 {
108         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
109         {
110                 ValueDesc value_desc(param.get_value_desc());
111
112                 if(!value_desc.parent_is_value_node())
113                         return false;
114
115                 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
116
117                 if(!value_node)
118                         return false;
119
120                 index=value_desc.get_index();
121
122                 return true;
123         }
124         if(name=="time" && param.get_type()==Param::TYPE_TIME)
125         {
126                 time=param.get_time();
127
128                 return true;
129         }
130         if(name=="origin" && param.get_type()==Param::TYPE_REAL)
131         {
132                 origin=param.get_real();
133
134                 return true;
135         }
136
137         return Action::CanvasSpecific::set_param(name,param);
138 }
139
140 bool
141 Action::ValueNodeDynamicListRemoveSmart::is_ready()const
142 {
143         if(!value_node)
144                 return false;
145         return Action::CanvasSpecific::is_ready();
146 }
147
148 void
149 Action::ValueNodeDynamicListRemoveSmart::prepare()
150 {
151         clear();
152
153         // If we are in animate editing mode
154         if(get_edit_mode()&MODE_ANIMATE)
155         {
156                 Action::Handle action(Action::create("activepoint_set_off"));
157
158                 if(!action)
159                         throw Error(_("Unable to find action (bug)"));
160
161                 action->set_param("canvas",get_canvas());
162                 action->set_param("canvas_interface",get_canvas_interface());
163                 action->set_param("time",time);
164                 action->set_param("origin",origin);
165                 action->set_param("value_desc",ValueDesc(value_node,index));
166
167                 if(!action->is_ready())
168                         throw Error(Error::TYPE_NOTREADY);
169
170                 add_action(action);
171         }
172         else
173         {
174                 Action::Handle action(Action::create("value_node_dynamic_list_remove"));
175
176                 if(!action)
177                         throw Error(_("Unable to find action (bug)"));
178
179                 action->set_param("canvas",get_canvas());
180                 action->set_param("canvas_interface",get_canvas_interface());
181                 action->set_param("time",time);
182                 action->set_param("origin",origin);
183                 action->set_param("value_desc",ValueDesc(value_node,index));
184
185                 if(!action->is_ready())
186                         throw Error(Error::TYPE_NOTREADY);
187
188                 add_action(action);
189         }
190 }