1 /* === S I N F G =========================================================== */
2 /*! \file waypointset.cpp
3 ** \brief Template File
5 ** $Id: waypointset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "waypointset.h"
32 #include <sinfgapp/canvasinterface.h>
38 using namespace sinfg;
39 using namespace sinfgapp;
40 using namespace Action;
42 /* === M A C R O S ========================================================= */
44 ACTION_INIT(Action::WaypointSet);
45 ACTION_SET_NAME(Action::WaypointSet,"waypoint_set");
46 ACTION_SET_LOCAL_NAME(Action::WaypointSet,"Set Waypoint");
47 ACTION_SET_TASK(Action::WaypointSet,"set");
48 ACTION_SET_CATEGORY(Action::WaypointSet,Action::CATEGORY_WAYPOINT);
49 ACTION_SET_PRIORITY(Action::WaypointSet,0);
50 ACTION_SET_VERSION(Action::WaypointSet,"0.0");
51 ACTION_SET_CVS_ID(Action::WaypointSet,"$Id: waypointset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 Action::WaypointSet::WaypointSet()
65 Action::WaypointSet::get_param_vocab()
67 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
70 .set_local_name(_("Destination ValueNode (Animated)"))
73 ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
74 .set_local_name(_("Waypoint"))
75 .set_desc(_("Waypoint to be changed"))
76 .set_supports_multiple()
83 Action::WaypointSet::is_canidate(const ParamList &x)
85 return canidate_check(get_param_vocab(),x);
89 Action::WaypointSet::set_param(const sinfg::String& name, const Action::Param ¶m)
91 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
93 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
95 return static_cast<bool>(value_node);
97 if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
99 //NOTE: at the moment there is no error checking for multiple sets!!!
100 waypoints.push_back(param.get_waypoint());
105 return Action::CanvasSpecific::set_param(name,param);
109 Action::WaypointSet::is_ready()const
111 if(!value_node || waypoints.empty())
113 return Action::CanvasSpecific::is_ready();
117 Action::WaypointSet::perform()
119 WaypointList::iterator iter;
122 vector<WaypointList::iterator> iters;
123 vector<Waypoint>::iterator i = waypoints.begin(), end = waypoints.end();
127 try { iters.push_back(value_node->find(*i)); }
128 catch(sinfg::Exception::NotFound)
130 throw Error(_("Unable to find waypoint"));
134 //check to see which valuenodes are going to override because of the time...
135 ValueNode_Animated::findresult timeiter;
137 for(i = waypoints.begin(); i != end; ++i)
139 timeiter = value_node->find_time(i->get_time());
141 bool candelete = timeiter.second;
143 //we only want to track overwrites (not waypoints that are also being modified)
146 for(vector<WaypointList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
148 if(timeiter.first == *ii)
156 //if we can still delete it after checking, record it, and then remove them all later
159 Waypoint w = *timeiter.first;
160 overwritten_waypoints.push_back(w);
164 //overwrite all the valuenodes we're supposed to set
166 i = waypoints.begin();
167 for(vector<WaypointList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
169 old_waypoints.push_back(**ii);
170 **ii = *i; //set the point to the corresponding point in the normal waypoint list
174 //remove all the points we're supposed to be overwritting
176 vector<Waypoint>::iterator oi = overwritten_waypoints.begin(),
177 oend = overwritten_waypoints.end();
178 for(; oi != oend; ++oi)
180 value_node->erase(*oi);
185 try { iter=value_node->find(waypoint); }
186 catch(sinfg::Exception::NotFound)
188 throw Error(_("Unable to find waypoint"));
191 //find the value at the old time before we replace it
192 ValueNode_Animated::findresult timeiter;
193 timeiter = value_node->find_time(waypoint.get_time());
195 //we only want to track overwrites (not inplace modifications)
196 if(timeiter.second && waypoint.get_uid() == timeiter.first->get_uid())
198 timeiter.second = false;
205 //if we've found a unique one then we need to erase it, but store it first
208 time_overwrite = true;
209 overwritten_wp = *timeiter.first;
211 value_node->erase(overwritten_wp);
215 // Signal that a valuenode has been changed
216 value_node->changed();
220 Action::WaypointSet::undo()
222 WaypointList::iterator iter;
225 vector<Waypoint>::iterator i = old_waypoints.begin(), end = old_waypoints.end();
229 try { iter = value_node->find(*i); }
230 catch(sinfg::Exception::NotFound)
232 throw Error(_("Unable to find waypoint"));
235 //overwrite with old one
239 //add back in all the points that we removed before...
241 vector<Waypoint>::iterator oi = overwritten_waypoints.begin(),
242 oend = overwritten_waypoints.end();
243 for(; oi != oend; ++oi)
245 value_node->add(*oi);
250 try { iter=value_node->find(old_waypoint); }
251 catch(sinfg::Exception::NotFound)
253 throw Error(_("Unable to find waypoint"));
260 value_node->add(overwritten_wp);
264 // Signal that a valuenode has been changed
265 value_node->changed();