1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframeremove.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
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"
39 #include <synfigapp/general.h>
45 using namespace synfig;
46 using namespace synfigapp;
47 using namespace Action;
49 /* === M A C R O S ========================================================= */
51 ACTION_INIT(Action::KeyframeRemove);
52 ACTION_SET_NAME(Action::KeyframeRemove,"keyframe_remove");
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$");
60 /* === G L O B A L S ======================================================= */
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 Action::KeyframeRemove::KeyframeRemove()
68 keyframe.set_time(Time::begin()-1);
73 Action::KeyframeRemove::get_param_vocab()
75 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
77 ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
78 .set_local_name(_("Keyframe"))
79 .set_desc(_("Keyframe to be removed"))
86 Action::KeyframeRemove::is_candidate(const ParamList &x)
88 return candidate_check(get_param_vocab(),x);
92 Action::KeyframeRemove::set_param(const synfig::String& name, const Action::Param ¶m)
94 if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
96 keyframe=param.get_keyframe();
101 return Action::CanvasSpecific::set_param(name,param);
105 Action::KeyframeRemove::is_ready()const
107 if(keyframe.get_time()==(Time::begin()-1))
109 return Action::CanvasSpecific::is_ready();
113 Action::KeyframeRemove::prepare()
117 try { get_canvas()->keyframe_list().find(keyframe);}
118 catch(synfig::Exception::NotFound)
120 throw Error(_("Unable to find the given keyframe"));
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())
129 process_value_desc(value_desc_list.back());
130 value_desc_list.pop_back();
136 Action::KeyframeRemove::process_value_desc(const synfigapp::ValueDesc& value_desc)
138 const synfig::Time time(keyframe.get_time());
140 if(value_desc.is_value_node())
142 ValueNode::Handle value_node(value_desc.get_value_node());
144 // If we are a dynamic list, then we need to update the ActivePoints
145 if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
147 ValueNode_DynamicList::Handle value_node_dynamic(ValueNode_DynamicList::Handle::cast_dynamic(value_node));
149 for(i=0;i<value_node_dynamic->link_count();i++)
152 Activepoint activepoint;
153 activepoint=*value_node_dynamic->list[i].find(time);
155 synfigapp::ValueDesc value_desc(value_node_dynamic,i);
157 Action::Handle action(ActivepointRemove::create());
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);
164 assert(action->is_ready());
165 if(!action->is_ready())
166 throw Error(Error::TYPE_NOTREADY);
168 add_action_front(action);
174 else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
177 ValueNode_Animated::Handle value_node_animated(ValueNode_Animated::Handle::cast_dynamic(value_node));
179 waypoint=*value_node_animated->find(time);
180 assert(waypoint.get_time()==time);
182 Action::Handle action(WaypointRemove::create());
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);
189 assert(action->is_ready());
190 if(!action->is_ready())
191 throw Error(Error::TYPE_NOTREADY);
193 add_action_front(action);
203 Action::KeyframeRemove::perform()
205 Action::Super::perform();
207 if(get_canvas_interface())
209 get_canvas_interface()->signal_keyframe_removed()(keyframe);
211 else synfig::warning("CanvasInterface not set on action");
213 get_canvas()->keyframe_list().erase(keyframe);
217 Action::KeyframeRemove::undo()
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) { }
222 try { get_canvas()->keyframe_list().find(keyframe); throw Error(_("This keyframe is already in the ValueNode"));}
223 catch(synfig::Exception::NotFound) { }
225 Action::Super::undo();
227 get_canvas()->keyframe_list().add(keyframe);
229 if(get_canvas_interface())
231 get_canvas_interface()->signal_keyframe_added()(keyframe);
233 else synfig::warning("CanvasInterface not set on action");