Typo: 'totaly' -> 'totally'.
[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 #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::ValueNodeDynamicListRemoveSmart);
47 ACTION_SET_NAME(Action::ValueNodeDynamicListRemoveSmart,"value_node_dynamic_list_remove_smart");
48 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListRemoveSmart,"Remove Item (Smart)");
49 ACTION_SET_TASK(Action::ValueNodeDynamicListRemoveSmart,"remove");
50 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListRemoveSmart,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
51 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListRemoveSmart,-19);
52 ACTION_SET_VERSION(Action::ValueNodeDynamicListRemoveSmart,"0.0");
53 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListRemoveSmart,"$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::ValueNodeDynamicListRemoveSmart::ValueNodeDynamicListRemoveSmart()
62 {
63         index=0;
64         time=0;
65         origin=0.5f;
66         set_dirty(true);
67 }
68
69 Action::ParamVocab
70 Action::ValueNodeDynamicListRemoveSmart::get_param_vocab()
71 {
72         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73
74         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
75                 .set_local_name(_("ValueDesc"))
76         );
77         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
78                 .set_local_name(_("Time"))
79                 .set_optional()
80         );
81         ret.push_back(ParamDesc("origin",Param::TYPE_REAL)
82                 .set_local_name(_("Origin"))
83                 .set_optional()
84         );
85
86         return ret;
87 }
88
89 bool
90 Action::ValueNodeDynamicListRemoveSmart::is_candidate(const ParamList &x)
91 {
92         if(candidate_check(get_param_vocab(),x))
93         {
94                 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
95                 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
96                         return false;
97
98                 return true;
99         }
100         return false;
101 }
102
103 bool
104 Action::ValueNodeDynamicListRemoveSmart::set_param(const synfig::String& name, const Action::Param &param)
105 {
106         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
107         {
108                 ValueDesc value_desc(param.get_value_desc());
109
110                 if(!value_desc.parent_is_value_node())
111                         return false;
112
113                 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
114
115                 if(!value_node)
116                         return false;
117
118                 index=value_desc.get_index();
119
120                 return true;
121         }
122         if(name=="time" && param.get_type()==Param::TYPE_TIME)
123         {
124                 time=param.get_time();
125
126                 return true;
127         }
128         if(name=="origin" && param.get_type()==Param::TYPE_REAL)
129         {
130                 origin=param.get_real();
131
132                 return true;
133         }
134
135         return Action::CanvasSpecific::set_param(name,param);
136 }
137
138 bool
139 Action::ValueNodeDynamicListRemoveSmart::is_ready()const
140 {
141         if(!value_node)
142                 return false;
143         return Action::CanvasSpecific::is_ready();
144 }
145
146 void
147 Action::ValueNodeDynamicListRemoveSmart::prepare()
148 {
149         clear();
150
151         // If we are in animate editing mode
152         if(get_edit_mode()&MODE_ANIMATE)
153         {
154                 Action::Handle action(Action::create("activepoint_set_off"));
155
156                 if(!action)
157                         throw Error(_("Unable to find action (bug)"));
158
159                 action->set_param("canvas",get_canvas());
160                 action->set_param("canvas_interface",get_canvas_interface());
161                 action->set_param("time",time);
162                 action->set_param("origin",origin);
163                 action->set_param("value_desc",ValueDesc(value_node,index));
164
165                 if(!action->is_ready())
166                         throw Error(Error::TYPE_NOTREADY);
167
168                 add_action(action);
169         }
170         else
171         {
172                 Action::Handle action(Action::create("value_node_dynamic_list_remove"));
173
174                 if(!action)
175                         throw Error(_("Unable to find action (bug)"));
176
177                 action->set_param("canvas",get_canvas());
178                 action->set_param("canvas_interface",get_canvas_interface());
179                 action->set_param("time",time);
180                 action->set_param("origin",origin);
181                 action->set_param("value_desc",ValueDesc(value_node,index));
182
183                 if(!action->is_ready())
184                         throw Error(Error::TYPE_NOTREADY);
185
186                 add_action(action);
187         }
188 }