1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframesetdelta.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 "keyframesetdelta.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_dynamiclist.h>
35 #include <synfig/valuenode_animated.h>
36 #include "activepointsetsmart.h"
37 #include "waypointsetsmart.h"
43 using namespace synfig;
44 using namespace synfigapp;
45 using namespace Action;
47 /* === M A C R O S ========================================================= */
49 ACTION_INIT(Action::KeyframeSetDelta);
50 ACTION_SET_NAME(Action::KeyframeSetDelta,"keyframe_set_delta");
51 ACTION_SET_LOCAL_NAME(Action::KeyframeSetDelta,"Set Keyframe Delta");
52 ACTION_SET_TASK(Action::KeyframeSetDelta,"set");
53 ACTION_SET_CATEGORY(Action::KeyframeSetDelta,Action::CATEGORY_KEYFRAME|Action::CATEGORY_HIDDEN);
54 ACTION_SET_PRIORITY(Action::KeyframeSetDelta,0);
55 ACTION_SET_VERSION(Action::KeyframeSetDelta,"0.0");
56 ACTION_SET_CVS_ID(Action::KeyframeSetDelta,"$Id$");
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::KeyframeSetDelta::KeyframeSetDelta():
67 keyframe.set_time(Time::end());
72 Action::KeyframeSetDelta::get_param_vocab()
74 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
76 ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
77 .set_local_name(_("Keyframe"))
79 ret.push_back(ParamDesc("delta",Param::TYPE_KEYFRAME)
80 .set_local_name(_("Delta"))
87 Action::KeyframeSetDelta::is_candidate(const ParamList &x)
89 return candidate_check(get_param_vocab(),x);
93 Action::KeyframeSetDelta::set_param(const synfig::String& name, const Action::Param ¶m)
95 if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
97 keyframe=param.get_keyframe();
100 if(name=="delta" && param.get_type()==Param::TYPE_TIME)
102 delta=param.get_time();
106 return Action::CanvasSpecific::set_param(name,param);
110 Action::KeyframeSetDelta::is_ready()const
112 if(keyframe.get_time()==Time::end())
114 return Action::CanvasSpecific::is_ready();
118 Action::KeyframeSetDelta::prepare()
121 value_desc_list.clear();
122 get_canvas_interface()->find_important_value_descs(value_desc_list);
125 Time time(get_canvas()->keyframe_list().find(keyframe)->get_time());
127 std::vector<synfigapp::ValueDesc>::iterator iter;
129 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
131 ValueDesc& value_desc(*iter);
132 ValueNode_Animated::Handle value_node(
133 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
140 value_node->find(time);
141 // if we got to this point, then we know that
142 // a waypoint already exists here and we don't
143 // need to add a new one.
147 // Make sure there is something previous
149 value_node->find_prev(time);
155 Action::Handle action(Action::create("waypoint_set_smart"));
157 action->set_param("canvas",get_canvas());
158 action->set_param("canvas_interface",get_canvas_interface());
159 action->set_param("value_node",ValueNode::Handle::cast_static(value_node));
161 action->set_param("time",time);
163 assert(action->is_ready());
164 if(!action->is_ready())
165 throw Error(Error::TYPE_NOTREADY);
172 Action::KeyframeSetDelta::perform()
176 Action::Super::perform();
178 // Time location(keyframe.get_time());
179 Time location(get_canvas()->keyframe_list().find(keyframe)->get_time());
182 get_canvas()->keyframe_list().insert_time(location,delta);
184 std::vector<synfigapp::ValueDesc>::iterator iter;
185 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
187 ValueDesc& value_desc(*iter);
188 if(!value_desc.is_value_node())
190 ValueNode_Animated::Handle animated(
191 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
195 animated->insert_time(location,delta);
198 ValueNode_DynamicList::Handle dyn_list(
199 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node())
203 dyn_list->insert_time(location,delta);
208 // Signal that something has changed
209 if(get_canvas_interface())
211 get_canvas_interface()->signal_keyframe_changed()(keyframe);
213 else synfig::warning("CanvasInterface not set on action");
217 Action::KeyframeSetDelta::undo()
222 // Time location(keyframe.get_time());
223 Time location(get_canvas()->keyframe_list().find(keyframe)->get_time());
226 get_canvas()->keyframe_list().insert_time(location,delta);
228 std::vector<synfigapp::ValueDesc>::iterator iter;
229 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
231 ValueDesc& value_desc(*iter);
232 if(!value_desc.is_value_node())
234 ValueNode_Animated::Handle animated(
235 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
239 animated->insert_time(location,delta);
242 ValueNode_DynamicList::Handle dyn_list(
243 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node())
247 dyn_list->insert_time(location,delta);
252 Action::Super::undo();
254 // Signal that something has changed
255 if(get_canvas_interface())
257 get_canvas_interface()->signal_keyframe_changed()(keyframe);
259 else synfig::warning("CanvasInterface not set on action");