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,"keyframe_set_delta");
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;
131 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
133 ValueDesc& value_desc(*iter);
134 ValueNode_Animated::Handle value_node(
135 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
142 value_node->find(time);
143 // if we got to this point, then we know that
144 // a waypoint already exists here and we don't
145 // need to add a new one.
149 // Make sure there is something previous
151 value_node->find_prev(time);
157 Action::Handle action(Action::create("waypoint_set_smart"));
159 action->set_param("canvas",get_canvas());
160 action->set_param("canvas_interface",get_canvas_interface());
161 action->set_param("value_node",ValueNode::Handle::cast_static(value_node));
163 action->set_param("time",time);
165 assert(action->is_ready());
166 if(!action->is_ready())
167 throw Error(Error::TYPE_NOTREADY);
174 Action::KeyframeSetDelta::perform()
178 Action::Super::perform();
180 // Time location(keyframe.get_time());
181 Time location(get_canvas()->keyframe_list().find(keyframe)->get_time());
184 get_canvas()->keyframe_list().insert_time(location,delta);
186 std::vector<synfigapp::ValueDesc>::iterator iter;
187 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
189 ValueDesc& value_desc(*iter);
190 if(!value_desc.is_value_node())
192 ValueNode_Animated::Handle animated(
193 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
197 animated->insert_time(location,delta);
200 ValueNode_DynamicList::Handle dyn_list(
201 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node())
205 dyn_list->insert_time(location,delta);
210 // Signal that something has changed
211 if(get_canvas_interface())
213 get_canvas_interface()->signal_keyframe_changed()(keyframe);
215 else synfig::warning("CanvasInterface not set on action");
219 Action::KeyframeSetDelta::undo()
224 // Time location(keyframe.get_time());
225 Time location(get_canvas()->keyframe_list().find(keyframe)->get_time());
228 get_canvas()->keyframe_list().insert_time(location,delta);
230 std::vector<synfigapp::ValueDesc>::iterator iter;
231 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
233 ValueDesc& value_desc(*iter);
234 if(!value_desc.is_value_node())
236 ValueNode_Animated::Handle animated(
237 ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
241 animated->insert_time(location,delta);
244 ValueNode_DynamicList::Handle dyn_list(
245 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_value_node())
249 dyn_list->insert_time(location,delta);
254 Action::Super::undo();
256 // Signal that something has changed
257 if(get_canvas_interface())
259 get_canvas_interface()->signal_keyframe_changed()(keyframe);
261 else synfig::warning("CanvasInterface not set on action");