1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframeduplicate.cpp
3 ** \brief Template File
5 ** $Id: keyframeduplicate.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 "keyframeduplicate.h"
32 #include <synfigapp/canvasinterface.h>
33 #include <synfig/valuenode_dynamiclist.h>
34 #include <synfig/valuenode_animated.h>
35 #include "activepointsetsmart.h"
36 #include "waypointsetsmart.h"
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT(Action::KeyframeDuplicate);
49 ACTION_SET_NAME(Action::KeyframeDuplicate,"keyframe_duplicate");
50 ACTION_SET_LOCAL_NAME(Action::KeyframeDuplicate,"Duplicate Keyframe");
51 ACTION_SET_TASK(Action::KeyframeDuplicate,"duplicate");
52 ACTION_SET_CATEGORY(Action::KeyframeDuplicate,Action::CATEGORY_KEYFRAME);
53 ACTION_SET_PRIORITY(Action::KeyframeDuplicate,0);
54 ACTION_SET_VERSION(Action::KeyframeDuplicate,"0.0");
55 ACTION_SET_CVS_ID(Action::KeyframeDuplicate,"$Id: keyframeduplicate.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::KeyframeDuplicate::KeyframeDuplicate()
65 new_keyframe.set_time(Time::begin()-1);
66 keyframe.set_time(Time::begin()-1);
71 Action::KeyframeDuplicate::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 duplicated"))
80 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
81 .set_local_name(_("Time"))
88 Action::KeyframeDuplicate::is_canidate(const ParamList &x)
90 return canidate_check(get_param_vocab(),x);
94 Action::KeyframeDuplicate::set_param(const synfig::String& name, const Action::Param ¶m)
96 if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
98 keyframe=param.get_keyframe();
99 new_keyframe.set_description(keyframe.get_description()+_(" (Duplicate)"));
103 if(name=="time" && param.get_type()==Param::TYPE_TIME)
105 new_keyframe.set_time(param.get_time());
110 return Action::CanvasSpecific::set_param(name,param);
114 Action::KeyframeDuplicate::is_ready()const
116 if(keyframe.get_time()==(Time::begin()-1) || new_keyframe.get_time()==(Time::begin()-1))
118 return Action::CanvasSpecific::is_ready();
122 Action::KeyframeDuplicate::prepare()
126 const synfig::Time old_time=keyframe.get_time();
127 const synfig::Time new_time=new_keyframe.get_time();
129 try { get_canvas()->keyframe_list().find(keyframe);}
130 catch(synfig::Exception::NotFound)
132 throw Error(_("Unable to find the given keyframe"));
135 try { if(get_canvas()->keyframe_list().find(new_time)!=get_canvas()->keyframe_list().end()) throw Error(_("A Keyframe already exists at this point in time"));}
138 // If the times are different, then we
139 // will need to romp through the valuenodes
140 // and add actions to update their values.
141 if(new_time!=old_time)
143 std::vector<synfigapp::ValueDesc> value_desc_list;
144 get_canvas_interface()->find_important_value_descs(value_desc_list);
145 while(!value_desc_list.empty())
147 process_value_desc(value_desc_list.back());
148 value_desc_list.pop_back();
154 Action::KeyframeDuplicate::process_value_desc(const synfigapp::ValueDesc& value_desc)
156 const synfig::Time old_time=keyframe.get_time();
157 const synfig::Time new_time=new_keyframe.get_time();
159 if(value_desc.is_value_node())
161 ValueNode::Handle value_node(value_desc.get_value_node());
163 // If we are a dynamic list, then we need to update the ActivePoints
164 if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
166 ValueNode_DynamicList::Handle value_node(ValueNode_DynamicList::Handle::cast_dynamic(value_node));
169 for(i=0;i<value_node->link_count();i++)
171 synfigapp::ValueDesc value_desc(value_node,i);
172 Activepoint activepoint(value_node->list[i].new_activepoint_at_time(old_time));
173 activepoint.set_time(new_time);
175 Action::Handle action(ActivepointSetSmart::create());
177 action->set_param("canvas",get_canvas());
178 action->set_param("canvas_interface",get_canvas_interface());
179 action->set_param("value_desc",value_desc);
180 action->set_param("activepoint",activepoint);
182 assert(action->is_ready());
183 if(!action->is_ready())
184 throw Error(Error::TYPE_NOTREADY);
186 add_action_front(action);
189 else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
191 ValueNode_Animated::Handle value_node(ValueNode_Animated::Handle::cast_dynamic(value_node));
192 Waypoint waypoint(value_node->new_waypoint_at_time(old_time));
193 waypoint.set_time(new_time);
195 Action::Handle action(WaypointSetSmart::create());
197 action->set_param("canvas",get_canvas());
198 action->set_param("canvas_interface",get_canvas_interface());
199 action->set_param("value_node",ValueNode::Handle(value_node));
200 action->set_param("waypoint",waypoint);
202 assert(action->is_ready());
203 if(!action->is_ready())
204 throw Error(Error::TYPE_NOTREADY);
206 add_action_front(action);
212 Action::KeyframeDuplicate::perform()
214 try { get_canvas()->keyframe_list().find(new_keyframe.get_time()); throw Error(_("A Keyframe already exists at this point in time"));}
215 catch(synfig::Exception::NotFound) { }
217 try { get_canvas()->keyframe_list().find(new_keyframe); throw Error(_("This keyframe is already in the ValueNode"));}
218 catch(synfig::Exception::NotFound) { }
220 Action::Super::perform();
222 get_canvas()->keyframe_list().add(new_keyframe);
224 if(get_canvas_interface())
226 get_canvas_interface()->signal_keyframe_added()(new_keyframe);
228 else synfig::warning("CanvasInterface not set on action");
232 Action::KeyframeDuplicate::undo()
234 Action::Super::undo();
236 if(get_canvas_interface())
238 get_canvas_interface()->signal_keyframe_removed()(new_keyframe);
240 else synfig::warning("CanvasInterface not set on action");
242 get_canvas()->keyframe_list().erase(new_keyframe);