1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframeremove.cpp
3 ** \brief Template File
5 ** $Id: keyframeremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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"
43 using namespace synfig;
44 using namespace synfigapp;
45 using namespace Action;
47 /* === M A C R O S ========================================================= */
49 ACTION_INIT(Action::KeyframeRemove);
50 ACTION_SET_NAME(Action::KeyframeRemove,"keyframe_remove");
51 ACTION_SET_LOCAL_NAME(Action::KeyframeRemove,"Remove Keyframe");
52 ACTION_SET_TASK(Action::KeyframeRemove,"remove");
53 ACTION_SET_CATEGORY(Action::KeyframeRemove,Action::CATEGORY_KEYFRAME);
54 ACTION_SET_PRIORITY(Action::KeyframeRemove,0);
55 ACTION_SET_VERSION(Action::KeyframeRemove,"0.0");
56 ACTION_SET_CVS_ID(Action::KeyframeRemove,"$Id: keyframeremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
58 /* === G L O B A L S ======================================================= */
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 Action::KeyframeRemove::KeyframeRemove()
66 keyframe.set_time(Time::begin()-1);
71 Action::KeyframeRemove::get_param_vocab()
73 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75 ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
76 .set_local_name(_("Keyframe"))
77 .set_desc(_("Keyframe to be removed"))
84 Action::KeyframeRemove::is_candidate(const ParamList &x)
86 return candidate_check(get_param_vocab(),x);
90 Action::KeyframeRemove::set_param(const synfig::String& name, const Action::Param ¶m)
92 if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
94 keyframe=param.get_keyframe();
99 return Action::CanvasSpecific::set_param(name,param);
103 Action::KeyframeRemove::is_ready()const
105 if(keyframe.get_time()==(Time::begin()-1))
107 return Action::CanvasSpecific::is_ready();
111 Action::KeyframeRemove::prepare()
115 try { get_canvas()->keyframe_list().find(keyframe);}
116 catch(synfig::Exception::NotFound)
118 throw Error(_("Unable to find the given keyframe"));
123 std::vector<synfigapp::ValueDesc> value_desc_list;
124 get_canvas_interface()->find_important_value_descs(value_desc_list);
125 while(!value_desc_list.empty())
127 process_value_desc(value_desc_list.back());
128 value_desc_list.pop_back();
134 Action::KeyframeRemove::process_value_desc(const synfigapp::ValueDesc& value_desc)
136 const synfig::Time time(keyframe.get_time());
138 if(value_desc.is_value_node())
140 ValueNode::Handle value_node(value_desc.get_value_node());
142 // If we are a dynamic list, then we need to update the ActivePoints
143 if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
145 ValueNode_DynamicList::Handle value_node_dynamic(ValueNode_DynamicList::Handle::cast_dynamic(value_node));
147 for(i=0;i<value_node_dynamic->link_count();i++)
150 Activepoint activepoint;
151 activepoint=*value_node_dynamic->list[i].find(time);
153 synfigapp::ValueDesc value_desc(value_node_dynamic,i);
155 Action::Handle action(ActivepointRemove::create());
157 action->set_param("canvas",get_canvas());
158 action->set_param("canvas_interface",get_canvas_interface());
159 action->set_param("value_desc",value_desc);
160 action->set_param("activepoint",activepoint);
162 assert(action->is_ready());
163 if(!action->is_ready())
164 throw Error(Error::TYPE_NOTREADY);
166 add_action_front(action);
172 else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
175 ValueNode_Animated::Handle value_node_animated(ValueNode_Animated::Handle::cast_dynamic(value_node));
177 waypoint=*value_node_animated->find(time);
178 assert(waypoint.get_time()==time);
180 Action::Handle action(WaypointRemove::create());
182 action->set_param("canvas",get_canvas());
183 action->set_param("canvas_interface",get_canvas_interface());
184 action->set_param("value_node",ValueNode::Handle(value_node_animated));
185 action->set_param("waypoint",waypoint);
187 assert(action->is_ready());
188 if(!action->is_ready())
189 throw Error(Error::TYPE_NOTREADY);
191 add_action_front(action);
201 Action::KeyframeRemove::perform()
203 Action::Super::perform();
205 if(get_canvas_interface())
207 get_canvas_interface()->signal_keyframe_removed()(keyframe);
209 else synfig::warning("CanvasInterface not set on action");
211 get_canvas()->keyframe_list().erase(keyframe);
215 Action::KeyframeRemove::undo()
217 try { get_canvas()->keyframe_list().find(keyframe.get_time()); throw Error(_("A Keyframe already exists at this point in time"));}
218 catch(synfig::Exception::NotFound) { }
220 try { get_canvas()->keyframe_list().find(keyframe); throw Error(_("This keyframe is already in the ValueNode"));}
221 catch(synfig::Exception::NotFound) { }
223 Action::Super::undo();
225 get_canvas()->keyframe_list().add(keyframe);
227 if(get_canvas_interface())
229 get_canvas_interface()->signal_keyframe_added()(keyframe);
231 else synfig::warning("CanvasInterface not set on action");