Better translation for 'Metaballs'
[synfig.git] / synfig-studio / src / synfigapp / actions / keyframeremove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file keyframeremove.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 "keyframeremove.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_dynamiclist.h>
35 #include <synfig/valuenode_animated.h>
36 #include "activepointremove.h"
37 #include "waypointremove.h"
38
39 #include <synfigapp/general.h>
40
41 #endif
42
43 using namespace std;
44 using namespace etl;
45 using namespace synfig;
46 using namespace synfigapp;
47 using namespace Action;
48
49 /* === M A C R O S ========================================================= */
50
51 ACTION_INIT(Action::KeyframeRemove);
52 ACTION_SET_NAME(Action::KeyframeRemove,"KeyframeRemove");
53 ACTION_SET_LOCAL_NAME(Action::KeyframeRemove,N_("Remove Keyframe"));
54 ACTION_SET_TASK(Action::KeyframeRemove,"remove");
55 ACTION_SET_CATEGORY(Action::KeyframeRemove,Action::CATEGORY_KEYFRAME);
56 ACTION_SET_PRIORITY(Action::KeyframeRemove,0);
57 ACTION_SET_VERSION(Action::KeyframeRemove,"0.0");
58 ACTION_SET_CVS_ID(Action::KeyframeRemove,"$Id$");
59
60 /* === G L O B A L S ======================================================= */
61
62 /* === P R O C E D U R E S ================================================= */
63
64 /* === M E T H O D S ======================================================= */
65
66 Action::KeyframeRemove::KeyframeRemove()
67 {
68         keyframe.set_time(Time::begin()-1);
69         set_dirty(true);
70 }
71
72 Action::ParamVocab
73 Action::KeyframeRemove::get_param_vocab()
74 {
75         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
76
77         ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
78                 .set_local_name(_("Keyframe"))
79                 .set_desc(_("Keyframe to be removed"))
80         );
81
82         return ret;
83 }
84
85 bool
86 Action::KeyframeRemove::is_candidate(const ParamList &x)
87 {
88         return candidate_check(get_param_vocab(),x);
89 }
90
91 bool
92 Action::KeyframeRemove::set_param(const synfig::String& name, const Action::Param &param)
93 {
94         if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
95         {
96                 keyframe=param.get_keyframe();
97
98                 return true;
99         }
100
101         return Action::CanvasSpecific::set_param(name,param);
102 }
103
104 bool
105 Action::KeyframeRemove::is_ready()const
106 {
107         if(keyframe.get_time()==(Time::begin()-1))
108                 return false;
109         return Action::CanvasSpecific::is_ready();
110 }
111
112 void
113 Action::KeyframeRemove::prepare()
114 {
115         clear();
116
117         try { get_canvas()->keyframe_list().find(keyframe);}
118         catch(synfig::Exception::NotFound)
119         {
120                 throw Error(_("Unable to find the given keyframe"));
121         }
122
123
124         {
125                 std::vector<synfigapp::ValueDesc> value_desc_list;
126                 get_canvas_interface()->find_important_value_descs(value_desc_list);
127                 while(!value_desc_list.empty())
128                 {
129                         process_value_desc(value_desc_list.back());
130                         value_desc_list.pop_back();
131                 }
132         }
133 }
134
135 void
136 Action::KeyframeRemove::process_value_desc(const synfigapp::ValueDesc& value_desc)
137 {
138         const synfig::Time time(keyframe.get_time());
139
140         if(value_desc.is_value_node())
141         {
142                 ValueNode::Handle value_node(value_desc.get_value_node());
143
144                 // If we are a dynamic list, then we need to update the ActivePoints
145                 if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
146                 {
147                         ValueNode_DynamicList::Handle value_node_dynamic(ValueNode_DynamicList::Handle::cast_dynamic(value_node));
148                         int i;
149                         for(i=0;i<value_node_dynamic->link_count();i++)
150                         try
151                         {
152                                 Activepoint activepoint;
153                                 activepoint=*value_node_dynamic->list[i].find(time);
154
155                                 synfigapp::ValueDesc value_desc(value_node_dynamic,i);
156
157                                 Action::Handle action(ActivepointRemove::create());
158
159                                 action->set_param("canvas",get_canvas());
160                                 action->set_param("canvas_interface",get_canvas_interface());
161                                 action->set_param("value_desc",value_desc);
162                                 action->set_param("activepoint",activepoint);
163
164                                 assert(action->is_ready());
165                                 if(!action->is_ready())
166                                         throw Error(Error::TYPE_NOTREADY);
167
168                                 add_action_front(action);
169                         }
170                         catch(...)
171                         {
172                         }
173                 }
174                 else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
175                 try
176                 {
177                         ValueNode_Animated::Handle value_node_animated(ValueNode_Animated::Handle::cast_dynamic(value_node));
178                         Waypoint waypoint;
179                         waypoint=*value_node_animated->find(time);
180                         assert(waypoint.get_time()==time);
181
182                         Action::Handle action(WaypointRemove::create());
183
184                         action->set_param("canvas",get_canvas());
185                         action->set_param("canvas_interface",get_canvas_interface());
186                         action->set_param("value_node",ValueNode::Handle(value_node_animated));
187                         action->set_param("waypoint",waypoint);
188
189                         assert(action->is_ready());
190                         if(!action->is_ready())
191                                 throw Error(Error::TYPE_NOTREADY);
192
193                         add_action_front(action);
194                 }
195                 catch(...)
196                 {
197                 }
198         }
199 }
200
201
202 void
203 Action::KeyframeRemove::perform()
204 {
205         Action::Super::perform();
206
207         if(get_canvas_interface())
208         {
209                 get_canvas_interface()->signal_keyframe_removed()(keyframe);
210         }
211         else synfig::warning("CanvasInterface not set on action");
212
213         get_canvas()->keyframe_list().erase(keyframe);
214 }
215
216 void
217 Action::KeyframeRemove::undo()
218 {
219         try { get_canvas()->keyframe_list().find(keyframe.get_time()); throw Error(_("A Keyframe already exists at this point in time"));}
220         catch(synfig::Exception::NotFound) { }
221
222         try { get_canvas()->keyframe_list().find(keyframe); throw Error(_("This keyframe is already in the ValueNode"));}
223         catch(synfig::Exception::NotFound) { }
224
225         Action::Super::undo();
226
227         get_canvas()->keyframe_list().add(keyframe);
228
229         if(get_canvas_interface())
230         {
231                 get_canvas_interface()->signal_keyframe_added()(keyframe);
232         }
233         else synfig::warning("CanvasInterface not set on action");
234 }