1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframewaypointset.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 "keyframewaypointset.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::KeyframeWaypointSet);
50 ACTION_SET_NAME(Action::KeyframeWaypointSet,"keyframe_waypoint_set");
51 ACTION_SET_LOCAL_NAME(Action::KeyframeWaypointSet,"Set Waypoints at Keyframe");
52 ACTION_SET_TASK(Action::KeyframeWaypointSet,"set");
53 ACTION_SET_CATEGORY(Action::KeyframeWaypointSet,Action::CATEGORY_KEYFRAME);
54 ACTION_SET_PRIORITY(Action::KeyframeWaypointSet,0);
55 ACTION_SET_VERSION(Action::KeyframeWaypointSet,"0.0");
56 ACTION_SET_CVS_ID(Action::KeyframeWaypointSet,"$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::KeyframeWaypointSet::KeyframeWaypointSet()
66 keyframe.set_time(Time::begin()-1);
71 Action::KeyframeWaypointSet::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"))
79 ret.push_back(ParamDesc("model",Param::TYPE_WAYPOINTMODEL)
80 .set_local_name(_("Waypoint Model"))
87 Action::KeyframeWaypointSet::is_candidate(const ParamList &x)
89 return candidate_check(get_param_vocab(),x);
93 Action::KeyframeWaypointSet::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();
101 if(name=="model" && param.get_type()==Param::TYPE_WAYPOINTMODEL)
103 waypoint_model=param.get_waypoint_model();
108 return Action::CanvasSpecific::set_param(name,param);
112 Action::KeyframeWaypointSet::is_ready()const
114 if(keyframe.get_time()==(Time::begin()-1) || waypoint_model.is_trivial())
116 return Action::CanvasSpecific::is_ready();
120 Action::KeyframeWaypointSet::prepare()
124 try { get_canvas()->keyframe_list().find(keyframe);}
125 catch(synfig::Exception::NotFound)
127 throw Error(_("Unable to find the given keyframe"));
131 std::vector<synfigapp::ValueDesc> value_desc_list;
132 get_canvas_interface()->find_important_value_descs(value_desc_list);
133 while(!value_desc_list.empty())
135 process_value_desc(value_desc_list.back());
136 value_desc_list.pop_back();
142 Action::KeyframeWaypointSet::process_value_desc(const synfigapp::ValueDesc& value_desc)
144 if(value_desc.is_value_node())
146 ValueNode_Animated::Handle value_node(ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node()));
150 Action::Handle action(WaypointSetSmart::create());
152 action->set_param("canvas",get_canvas());
153 action->set_param("canvas_interface",get_canvas_interface());
154 action->set_param("value_node",ValueNode::Handle(value_node));
159 waypoint=*value_node->find(keyframe.get_time());
163 waypoint.set_time(keyframe.get_time());
164 waypoint.set_value((*value_node)(keyframe.get_time()));
166 waypoint.apply_model(waypoint_model);
168 action->set_param("waypoint",waypoint);
170 assert(action->is_ready());
171 if(!action->is_ready())
172 throw Error(Error::TYPE_NOTREADY);
174 add_action_front(action);