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"
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::KeyframeSetDelta);
52 ACTION_SET_NAME(Action::KeyframeSetDelta,"KeyframeSetDelta");
53 ACTION_SET_LOCAL_NAME(Action::KeyframeSetDelta,N_("Set Keyframe Delta"));
54 ACTION_SET_TASK(Action::KeyframeSetDelta,"set");
55 ACTION_SET_CATEGORY(Action::KeyframeSetDelta,Action::CATEGORY_KEYFRAME|Action::CATEGORY_HIDDEN);
56 ACTION_SET_PRIORITY(Action::KeyframeSetDelta,0);
57 ACTION_SET_VERSION(Action::KeyframeSetDelta,"0.0");
58 ACTION_SET_CVS_ID(Action::KeyframeSetDelta,"$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::KeyframeSetDelta::KeyframeSetDelta():
69 keyframe.set_time(Time::end());
74 Action::KeyframeSetDelta::get_param_vocab()
76 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
78 ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
79 .set_local_name(_("Keyframe"))
81 ret.push_back(ParamDesc("delta",Param::TYPE_KEYFRAME)
82 .set_local_name(_("Delta"))
89 Action::KeyframeSetDelta::is_candidate(const ParamList &x)
91 return candidate_check(get_param_vocab(),x);
95 Action::KeyframeSetDelta::set_param(const synfig::String& name, const Action::Param ¶m)
97 if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
99 keyframe=param.get_keyframe();
102 if(name=="delta" && param.get_type()==Param::TYPE_TIME)
104 delta=param.get_time();
108 return Action::CanvasSpecific::set_param(name,param);
112 Action::KeyframeSetDelta::is_ready()const
114 if(keyframe.get_time()==Time::end())
116 return Action::CanvasSpecific::is_ready();
120 Action::KeyframeSetDelta::prepare()
123 value_desc_list.clear();
124 get_canvas_interface()->find_important_value_descs(value_desc_list);
127 Time time(get_canvas()->keyframe_list().find(keyframe)->get_time());
129 std::vector<synfigapp::ValueDesc>::iterator iter;
130 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
132 ValueDesc& value_desc(*iter);
133 ValueNode_Animated::Handle value_node(
134 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
141 value_node->find(time);
142 // if we got to this point, then we know that
143 // a waypoint already exists here and we don't
144 // need to add a new one.
148 // Make sure there is something previous
150 value_node->find_prev(time);
156 Action::Handle action(Action::create("WaypointSetSmart"));
158 action->set_param("canvas",get_canvas());
159 action->set_param("canvas_interface",get_canvas_interface());
160 action->set_param("value_node",ValueNode::Handle::cast_static(value_node));
162 action->set_param("time",time);
164 assert(action->is_ready());
165 if(!action->is_ready())
166 throw Error(Error::TYPE_NOTREADY);
173 Action::KeyframeSetDelta::perform()
177 Action::Super::perform();
179 // Time location(keyframe.get_time());
180 Time location(get_canvas()->keyframe_list().find(keyframe)->get_time());
183 get_canvas()->keyframe_list().insert_time(location,delta);
185 std::vector<synfigapp::ValueDesc>::iterator iter;
186 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
188 ValueDesc& value_desc(*iter);
189 if(!value_desc.is_value_node())
191 ValueNode_Animated::Handle animated(
192 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
196 animated->insert_time(location,delta);
199 ValueNode_DynamicList::Handle dyn_list(
200 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node())
204 dyn_list->insert_time(location,delta);
209 // Signal that something has changed
210 if(get_canvas_interface())
212 get_canvas_interface()->signal_keyframe_changed()(keyframe);
214 else synfig::warning("CanvasInterface not set on action");
218 Action::KeyframeSetDelta::undo()
223 // Time location(keyframe.get_time());
224 Time location(get_canvas()->keyframe_list().find(keyframe)->get_time());
227 get_canvas()->keyframe_list().insert_time(location,delta);
229 std::vector<synfigapp::ValueDesc>::iterator iter;
230 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
232 ValueDesc& value_desc(*iter);
233 if(!value_desc.is_value_node())
235 ValueNode_Animated::Handle animated(
236 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
240 animated->insert_time(location,delta);
243 ValueNode_DynamicList::Handle dyn_list(
244 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node())
248 dyn_list->insert_time(location,delta);
253 Action::Super::undo();
255 // Signal that something has changed
256 if(get_canvas_interface())
258 get_canvas_interface()->signal_keyframe_changed()(keyframe);
260 else synfig::warning("CanvasInterface not set on action");