1 /* === S Y N F I G ========================================================= */
2 /*! \file waypointset.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 "waypointset.h"
33 #include <synfigapp/canvasinterface.h>
35 #include <synfigapp/general.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::WaypointSet);
48 ACTION_SET_NAME(Action::WaypointSet,"WaypointSet");
49 ACTION_SET_LOCAL_NAME(Action::WaypointSet,N_("Set Waypoint"));
50 ACTION_SET_TASK(Action::WaypointSet,"set");
51 ACTION_SET_CATEGORY(Action::WaypointSet,Action::CATEGORY_WAYPOINT);
52 ACTION_SET_PRIORITY(Action::WaypointSet,0);
53 ACTION_SET_VERSION(Action::WaypointSet,"0.0");
54 ACTION_SET_CVS_ID(Action::WaypointSet,"$Id$");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::WaypointSet::WaypointSet()
68 Action::WaypointSet::get_param_vocab()
70 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
73 .set_local_name(_("Destination ValueNode (Animated)"))
76 ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
77 .set_local_name(_("Waypoint"))
78 .set_desc(_("Waypoint to be changed"))
79 .set_supports_multiple()
86 Action::WaypointSet::is_candidate(const ParamList &x)
88 return candidate_check(get_param_vocab(),x);
92 Action::WaypointSet::set_param(const synfig::String& name, const Action::Param ¶m)
94 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
96 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
98 return static_cast<bool>(value_node);
100 if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
102 //NOTE: at the moment there is no error checking for multiple sets!!!
103 waypoints.push_back(param.get_waypoint());
108 return Action::CanvasSpecific::set_param(name,param);
112 Action::WaypointSet::is_ready()const
114 if(!value_node || waypoints.empty())
116 return Action::CanvasSpecific::is_ready();
120 Action::WaypointSet::perform()
122 WaypointList::iterator iter;
125 vector<WaypointList::iterator> iters;
126 vector<Waypoint>::iterator i = waypoints.begin(), end = waypoints.end();
130 try { iters.push_back(value_node->find(*i)); }
131 catch(synfig::Exception::NotFound)
133 throw Error(_("Unable to find waypoint"));
137 //check to see which valuenodes are going to override because of the time...
138 ValueNode_Animated::findresult timeiter;
140 for(i = waypoints.begin(); i != end; ++i)
142 timeiter = value_node->find_time(i->get_time());
144 bool candelete = timeiter.second;
146 //we only want to track overwrites (not waypoints that are also being modified)
149 for(vector<WaypointList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
151 if(timeiter.first == *ii)
159 //if we can still delete it after checking, record it, and then remove them all later
162 Waypoint w = *timeiter.first;
163 overwritten_waypoints.push_back(w);
167 //overwrite all the valuenodes we're supposed to set
169 i = waypoints.begin();
170 for(vector<WaypointList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
172 old_waypoints.push_back(**ii);
173 **ii = *i; //set the point to the corresponding point in the normal waypoint list
177 //remove all the points we're supposed to be overwriting
179 vector<Waypoint>::iterator oi = overwritten_waypoints.begin(),
180 oend = overwritten_waypoints.end();
181 for(; oi != oend; ++oi)
183 value_node->erase(*oi);
188 try { iter=value_node->find(waypoint); }
189 catch(synfig::Exception::NotFound)
191 throw Error(_("Unable to find waypoint"));
194 //find the value at the old time before we replace it
195 ValueNode_Animated::findresult timeiter;
196 timeiter = value_node->find_time(waypoint.get_time());
198 //we only want to track overwrites (not inplace modifications)
199 if(timeiter.second && waypoint.get_uid() == timeiter.first->get_uid())
201 timeiter.second = false;
208 //if we've found a unique one then we need to erase it, but store it first
211 time_overwrite = true;
212 overwritten_wp = *timeiter.first;
214 value_node->erase(overwritten_wp);
218 // Signal that a valuenode has been changed
219 value_node->changed();
223 Action::WaypointSet::undo()
225 WaypointList::iterator iter;
228 vector<Waypoint>::iterator i = old_waypoints.begin(), end = old_waypoints.end();
232 try { iter = value_node->find(*i); }
233 catch(synfig::Exception::NotFound)
235 throw Error(_("Unable to find waypoint"));
238 //overwrite with old one
242 //add back in all the points that we removed before...
244 vector<Waypoint>::iterator oi = overwritten_waypoints.begin(),
245 oend = overwritten_waypoints.end();
246 for(; oi != oend; ++oi)
248 value_node->add(*oi);
253 try { iter=value_node->find(old_waypoint); }
254 catch(synfig::Exception::NotFound)
256 throw Error(_("Unable to find waypoint"));
263 value_node->add(overwritten_wp);
267 // Signal that a valuenode has been changed
268 value_node->changed();