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"
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::KeyframeWaypointSet);
52 ACTION_SET_NAME(Action::KeyframeWaypointSet,"keyframe_waypoint_set");
53 ACTION_SET_LOCAL_NAME(Action::KeyframeWaypointSet,N_("Set Waypoints at Keyframe"));
54 ACTION_SET_TASK(Action::KeyframeWaypointSet,"set");
55 ACTION_SET_CATEGORY(Action::KeyframeWaypointSet,Action::CATEGORY_KEYFRAME);
56 ACTION_SET_PRIORITY(Action::KeyframeWaypointSet,0);
57 ACTION_SET_VERSION(Action::KeyframeWaypointSet,"0.0");
58 ACTION_SET_CVS_ID(Action::KeyframeWaypointSet,"$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::KeyframeWaypointSet::KeyframeWaypointSet()
68 keyframe.set_time(Time::begin()-1);
73 Action::KeyframeWaypointSet::get_param_vocab()
75 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
77 ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
78 .set_local_name(_("Keyframe"))
81 ret.push_back(ParamDesc("model",Param::TYPE_WAYPOINTMODEL)
82 .set_local_name(_("Waypoint Model"))
89 Action::KeyframeWaypointSet::is_candidate(const ParamList &x)
91 return candidate_check(get_param_vocab(),x);
95 Action::KeyframeWaypointSet::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();
103 if(name=="model" && param.get_type()==Param::TYPE_WAYPOINTMODEL)
105 waypoint_model=param.get_waypoint_model();
110 return Action::CanvasSpecific::set_param(name,param);
114 Action::KeyframeWaypointSet::is_ready()const
116 if(keyframe.get_time()==(Time::begin()-1) || waypoint_model.is_trivial())
118 return Action::CanvasSpecific::is_ready();
122 Action::KeyframeWaypointSet::prepare()
126 try { get_canvas()->keyframe_list().find(keyframe);}
127 catch(synfig::Exception::NotFound)
129 throw Error(_("Unable to find the given keyframe"));
133 std::vector<synfigapp::ValueDesc> value_desc_list;
134 get_canvas_interface()->find_important_value_descs(value_desc_list);
135 while(!value_desc_list.empty())
137 process_value_desc(value_desc_list.back());
138 value_desc_list.pop_back();
144 Action::KeyframeWaypointSet::process_value_desc(const synfigapp::ValueDesc& value_desc)
146 if(value_desc.is_value_node())
148 ValueNode_Animated::Handle value_node(ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node()));
152 Action::Handle action(WaypointSetSmart::create());
154 action->set_param("canvas",get_canvas());
155 action->set_param("canvas_interface",get_canvas_interface());
156 action->set_param("value_node",ValueNode::Handle(value_node));
161 waypoint=*value_node->find(keyframe.get_time());
165 waypoint.set_time(keyframe.get_time());
166 waypoint.set_value((*value_node)(keyframe.get_time()));
168 waypoint.apply_model(waypoint_model);
170 action->set_param("waypoint",waypoint);
172 assert(action->is_ready());
173 if(!action->is_ready())
174 throw Error(Error::TYPE_NOTREADY);
176 add_action_front(action);