1 /* === S Y N F I G ========================================================= */
2 /*! \file waypointadd.cpp
3 ** \brief Template File
5 ** $Id: waypointadd.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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 "waypointadd.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfigapp/main.h>
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
44 /* === M A C R O S ========================================================= */
46 ACTION_INIT(Action::WaypointAdd);
47 ACTION_SET_NAME(Action::WaypointAdd,"waypoint_add");
48 ACTION_SET_LOCAL_NAME(Action::WaypointAdd,"Add Waypoint");
49 ACTION_SET_TASK(Action::WaypointAdd,"add");
50 ACTION_SET_CATEGORY(Action::WaypointAdd,Action::CATEGORY_WAYPOINT);
51 ACTION_SET_PRIORITY(Action::WaypointAdd,0);
52 ACTION_SET_VERSION(Action::WaypointAdd,"0.0");
53 ACTION_SET_CVS_ID(Action::WaypointAdd,"$Id: waypointadd.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Action::WaypointAdd::WaypointAdd()
63 waypoint.set_time(Time::begin()-1);
69 Action::WaypointAdd::get_param_vocab()
71 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
74 .set_local_name(_("Destination ValueNode (Animated)"))
77 ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
78 .set_local_name(_("New Waypoint"))
79 .set_desc(_("Waypoint to be added"))
83 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
84 .set_local_name(_("Time"))
85 .set_desc(_("Time where waypoint is to be added"))
93 Action::WaypointAdd::is_candidate(const ParamList &x)
95 if(candidate_check(get_param_vocab(),x))
97 if(!ValueNode_Animated::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()))
100 // We need either a waypoint or a time.
101 if(x.count("waypoint") || x.count("time"))
108 Action::WaypointAdd::set_param(const synfig::String& name, const Action::Param ¶m)
110 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
112 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
116 return static_cast<bool>(value_node);
118 if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT && !time_set)
120 waypoint=param.get_waypoint();
124 if(name=="time" && param.get_type()==Param::TYPE_TIME && waypoint.get_time()==Time::begin()-1)
126 waypoint.set_time(param.get_time());
135 return Action::CanvasSpecific::set_param(name,param);
139 Action::WaypointAdd::is_ready()const
141 if(!value_node || waypoint.get_time()==(Time::begin()-1))
143 return Action::CanvasSpecific::is_ready();
146 // This function is called if a time is specified, but not
147 // a waypoint. In this case, we need to calculate the value
150 Action::WaypointAdd::calc_waypoint()
152 Time time=waypoint.get_time();
153 Waypoint original(waypoint);
154 waypoint=value_node->new_waypoint_at_time(time);
155 waypoint.mimic(original);
156 waypoint.set_before(synfigapp::Main::get_interpolation());
157 waypoint.set_after(synfigapp::Main::get_interpolation());
160 ValueNode_Animated::WaypointList &waypoint_list(value_node->waypoint_list());
161 ValueNode_Animated::WaypointList::iterator iter;
163 if(waypoint_list.empty())
165 waypoint.set_value((*value_node)(time));
169 ValueNode_Animated::WaypointList::iterator closest=waypoint_list.begin();
171 for(iter=waypoint_list.begin();iter!=waypoint_list.end();++iter)
173 const Real dist(abs(iter->get_time()-time));
174 if(dist<abs(closest->get_time()-time))
177 if(!closest->is_static())
178 waypoint.set_value_node(closest->get_value_node());
180 waypoint.set_value((*value_node)(time));
185 Action::WaypointAdd::perform()
187 try { value_node->find(waypoint.get_time()); throw Error(_("A Waypoint already exists at this point in time (%s)"),waypoint.get_time().get_string().c_str());}
188 catch(synfig::Exception::NotFound) { }
190 try { if(value_node->find(waypoint)!=value_node->waypoint_list().end()) throw Error(_("This waypoint is already in the ValueNode"));}
191 catch(synfig::Exception::NotFound) { }
193 value_node->add(waypoint);
195 value_node->changed();
196 /*_if(get_canvas_interface())
198 get_canvas_interface()->signal_value_node_changed()(value_node);
200 else synfig::warning("CanvasInterface not set on action");*/
204 Action::WaypointAdd::undo()
206 value_node->erase(waypoint);
208 value_node->changed();
209 /*_if(get_canvas_interface())
211 get_canvas_interface()->signal_value_node_changed()(value_node);
213 else synfig::warning("CanvasInterface not set on action");*/