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>
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
43 /* === M A C R O S ========================================================= */
45 ACTION_INIT(Action::WaypointSet);
46 ACTION_SET_NAME(Action::WaypointSet,"waypoint_set");
47 ACTION_SET_LOCAL_NAME(Action::WaypointSet,"Set Waypoint");
48 ACTION_SET_TASK(Action::WaypointSet,"set");
49 ACTION_SET_CATEGORY(Action::WaypointSet,Action::CATEGORY_WAYPOINT);
50 ACTION_SET_PRIORITY(Action::WaypointSet,0);
51 ACTION_SET_VERSION(Action::WaypointSet,"0.0");
52 ACTION_SET_CVS_ID(Action::WaypointSet,"$Id$");
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 Action::WaypointSet::WaypointSet()
66 Action::WaypointSet::get_param_vocab()
68 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
71 .set_local_name(_("Destination ValueNode (Animated)"))
74 ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
75 .set_local_name(_("Waypoint"))
76 .set_desc(_("Waypoint to be changed"))
77 .set_supports_multiple()
84 Action::WaypointSet::is_candidate(const ParamList &x)
86 return candidate_check(get_param_vocab(),x);
90 Action::WaypointSet::set_param(const synfig::String& name, const Action::Param ¶m)
92 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
94 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
96 return static_cast<bool>(value_node);
98 if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
100 //NOTE: at the moment there is no error checking for multiple sets!!!
101 waypoints.push_back(param.get_waypoint());
106 return Action::CanvasSpecific::set_param(name,param);
110 Action::WaypointSet::is_ready()const
112 if(!value_node || waypoints.empty())
114 return Action::CanvasSpecific::is_ready();
118 Action::WaypointSet::perform()
120 WaypointList::iterator iter;
123 vector<WaypointList::iterator> iters;
124 vector<Waypoint>::iterator i = waypoints.begin(), end = waypoints.end();
128 try { iters.push_back(value_node->find(*i)); }
129 catch(synfig::Exception::NotFound)
131 throw Error(_("Unable to find waypoint"));
135 //check to see which valuenodes are going to override because of the time...
136 ValueNode_Animated::findresult timeiter;
138 for(i = waypoints.begin(); i != end; ++i)
140 timeiter = value_node->find_time(i->get_time());
142 bool candelete = timeiter.second;
144 //we only want to track overwrites (not waypoints that are also being modified)
147 for(vector<WaypointList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
149 if(timeiter.first == *ii)
157 //if we can still delete it after checking, record it, and then remove them all later
160 Waypoint w = *timeiter.first;
161 overwritten_waypoints.push_back(w);
165 //overwrite all the valuenodes we're supposed to set
167 i = waypoints.begin();
168 for(vector<WaypointList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
170 old_waypoints.push_back(**ii);
171 **ii = *i; //set the point to the corresponding point in the normal waypoint list
175 //remove all the points we're supposed to be overwritting
177 vector<Waypoint>::iterator oi = overwritten_waypoints.begin(),
178 oend = overwritten_waypoints.end();
179 for(; oi != oend; ++oi)
181 value_node->erase(*oi);
186 try { iter=value_node->find(waypoint); }
187 catch(synfig::Exception::NotFound)
189 throw Error(_("Unable to find waypoint"));
192 //find the value at the old time before we replace it
193 ValueNode_Animated::findresult timeiter;
194 timeiter = value_node->find_time(waypoint.get_time());
196 //we only want to track overwrites (not inplace modifications)
197 if(timeiter.second && waypoint.get_uid() == timeiter.first->get_uid())
199 timeiter.second = false;
206 //if we've found a unique one then we need to erase it, but store it first
209 time_overwrite = true;
210 overwritten_wp = *timeiter.first;
212 value_node->erase(overwritten_wp);
216 // Signal that a valuenode has been changed
217 value_node->changed();
221 Action::WaypointSet::undo()
223 WaypointList::iterator iter;
226 vector<Waypoint>::iterator i = old_waypoints.begin(), end = old_waypoints.end();
230 try { iter = value_node->find(*i); }
231 catch(synfig::Exception::NotFound)
233 throw Error(_("Unable to find waypoint"));
236 //overwrite with old one
240 //add back in all the points that we removed before...
242 vector<Waypoint>::iterator oi = overwritten_waypoints.begin(),
243 oend = overwritten_waypoints.end();
244 for(; oi != oend; ++oi)
246 value_node->add(*oi);
251 try { iter=value_node->find(old_waypoint); }
252 catch(synfig::Exception::NotFound)
254 throw Error(_("Unable to find waypoint"));
261 value_node->add(overwritten_wp);
265 // Signal that a valuenode has been changed
266 value_node->changed();