1 /* === S I N F 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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "keyframeremove.h"
32 #include <sinfgapp/canvasinterface.h>
33 #include <sinfg/valuenode_dynamiclist.h>
34 #include <sinfg/valuenode_animated.h>
35 #include "activepointremove.h"
36 #include "waypointremove.h"
42 using namespace sinfg;
43 using namespace sinfgapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT(Action::KeyframeRemove);
49 ACTION_SET_NAME(Action::KeyframeRemove,"keyframe_remove");
50 ACTION_SET_LOCAL_NAME(Action::KeyframeRemove,"Remove Keyframe");
51 ACTION_SET_TASK(Action::KeyframeRemove,"remove");
52 ACTION_SET_CATEGORY(Action::KeyframeRemove,Action::CATEGORY_KEYFRAME);
53 ACTION_SET_PRIORITY(Action::KeyframeRemove,0);
54 ACTION_SET_VERSION(Action::KeyframeRemove,"0.0");
55 ACTION_SET_CVS_ID(Action::KeyframeRemove,"$Id: keyframeremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Action::KeyframeRemove::KeyframeRemove()
65 keyframe.set_time(Time::begin()-1);
70 Action::KeyframeRemove::get_param_vocab()
72 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74 ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
75 .set_local_name(_("Keyframe"))
76 .set_desc(_("Keyframe to be removed"))
83 Action::KeyframeRemove::is_canidate(const ParamList &x)
85 return canidate_check(get_param_vocab(),x);
89 Action::KeyframeRemove::set_param(const sinfg::String& name, const Action::Param ¶m)
91 if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
93 keyframe=param.get_keyframe();
98 return Action::CanvasSpecific::set_param(name,param);
102 Action::KeyframeRemove::is_ready()const
104 if(keyframe.get_time()==(Time::begin()-1))
106 return Action::CanvasSpecific::is_ready();
110 Action::KeyframeRemove::prepare()
114 try { get_canvas()->keyframe_list().find(keyframe);}
115 catch(sinfg::Exception::NotFound)
117 throw Error(_("Unable to find the given keyframe"));
122 std::vector<sinfgapp::ValueDesc> value_desc_list;
123 get_canvas_interface()->find_important_value_descs(value_desc_list);
124 while(!value_desc_list.empty())
126 process_value_desc(value_desc_list.back());
127 value_desc_list.pop_back();
133 Action::KeyframeRemove::process_value_desc(const sinfgapp::ValueDesc& value_desc)
135 const sinfg::Time time(keyframe.get_time());
137 if(value_desc.is_value_node())
139 ValueNode::Handle value_node(value_desc.get_value_node());
141 // If we are a dynamic list, then we need to update the ActivePoints
142 if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
144 ValueNode_DynamicList::Handle value_node(ValueNode_DynamicList::Handle::cast_dynamic(value_node));
146 for(i=0;i<value_node->link_count();i++)
149 Activepoint activepoint;
150 activepoint=*value_node->list[i].find(time);
152 sinfgapp::ValueDesc value_desc(value_node,i);
154 Action::Handle action(ActivepointRemove::create());
156 action->set_param("canvas",get_canvas());
157 action->set_param("canvas_interface",get_canvas_interface());
158 action->set_param("value_desc",value_desc);
159 action->set_param("activepoint",activepoint);
161 assert(action->is_ready());
162 if(!action->is_ready())
163 throw Error(Error::TYPE_NOTREADY);
165 add_action_front(action);
171 else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
174 ValueNode_Animated::Handle value_node(ValueNode_Animated::Handle::cast_dynamic(value_node));
176 waypoint=*value_node->find(time);
177 assert(waypoint.get_time()==time);
179 Action::Handle action(WaypointRemove::create());
181 action->set_param("canvas",get_canvas());
182 action->set_param("canvas_interface",get_canvas_interface());
183 action->set_param("value_node",ValueNode::Handle(value_node));
184 action->set_param("waypoint",waypoint);
186 assert(action->is_ready());
187 if(!action->is_ready())
188 throw Error(Error::TYPE_NOTREADY);
190 add_action_front(action);
200 Action::KeyframeRemove::perform()
202 Action::Super::perform();
204 if(get_canvas_interface())
206 get_canvas_interface()->signal_keyframe_removed()(keyframe);
208 else sinfg::warning("CanvasInterface not set on action");
210 get_canvas()->keyframe_list().erase(keyframe);
214 Action::KeyframeRemove::undo()
216 try { get_canvas()->keyframe_list().find(keyframe.get_time()); throw Error(_("A Keyframe already exists at this point in time"));}
217 catch(sinfg::Exception::NotFound) { }
219 try { get_canvas()->keyframe_list().find(keyframe); throw Error(_("This keyframe is already in the ValueNode"));}
220 catch(sinfg::Exception::NotFound) { }
222 Action::Super::undo();
224 get_canvas()->keyframe_list().add(keyframe);
226 if(get_canvas_interface())
228 get_canvas_interface()->signal_keyframe_added()(keyframe);
230 else sinfg::warning("CanvasInterface not set on action");