1 /* === S I N F G =========================================================== */
2 /*! \file activepointset.cpp
3 ** \brief Template File
5 ** $Id: activepointset.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 "activepointset.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::ActivepointSet);
45 ACTION_SET_NAME(Action::ActivepointSet,"activepoint_set");
46 ACTION_SET_LOCAL_NAME(Action::ActivepointSet,"Set Activepoint");
47 ACTION_SET_TASK(Action::ActivepointSet,"set");
48 ACTION_SET_CATEGORY(Action::ActivepointSet,Action::CATEGORY_ACTIVEPOINT);
49 ACTION_SET_PRIORITY(Action::ActivepointSet,0);
50 ACTION_SET_VERSION(Action::ActivepointSet,"0.0");
51 ACTION_SET_CVS_ID(Action::ActivepointSet,"$Id: activepointset.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::ActivepointSet::ActivepointSet()
65 Action::ActivepointSet::get_param_vocab()
67 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
70 .set_local_name(_("ValueDesc"))
73 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
74 .set_local_name(_("Activepoint"))
75 .set_desc(_("Activepoint to be changed"))
76 .set_supports_multiple()
83 Action::ActivepointSet::is_canidate(const ParamList &x)
85 if(canidate_check(get_param_vocab(),x))
87 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
88 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
97 Action::ActivepointSet::set_param(const sinfg::String& name, const Action::Param ¶m)
99 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
101 ValueDesc value_desc(param.get_value_desc());
103 if(!value_desc.parent_is_value_node())
106 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
111 index=value_desc.get_index();
115 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
117 //NOTE: there is no duplication checking at the moment
118 activepoints.push_back(param.get_activepoint());
123 return Action::CanvasSpecific::set_param(name,param);
127 Action::ActivepointSet::is_ready()const
129 if(!value_node || activepoints.empty())
131 return Action::CanvasSpecific::is_ready();
135 Action::ActivepointSet::perform()
137 typedef ValueNode_DynamicList::ListEntry::ActivepointList AList;
138 AList::iterator iter;
141 vector<AList::iterator> iters;
142 vector<Activepoint>::iterator i = activepoints.begin(), end = activepoints.end();
146 try { iters.push_back(value_node->list[index].find(*i)); }
147 catch(sinfg::Exception::NotFound)
149 throw Error(_("Unable to find activepoint"));
153 //check to see which valuenodes are going to override because of the time...
154 ValueNode_DynamicList::ListEntry::findresult timeiter;
156 for(i = activepoints.begin(); i != end; ++i)
158 timeiter = value_node->list[index].find_time(i->get_time());
160 bool candelete = timeiter.second;
162 //we only want to track overwrites (not activepoints that are also being modified)
165 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
167 if(timeiter.first == *ii)
175 //if we can still delete it after checking, record it, and then remove them all later
178 Activepoint a = *timeiter.first;
179 overwritten_activepoints.push_back(a);
183 //overwrite all the valuenodes we're supposed to set
185 i = activepoints.begin();
186 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
188 old_activepoints.push_back(**ii);
189 **ii = *i; //set the point to the corresponding point in the normal waypoint list
193 //remove all the points we're supposed to be overwritting
195 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
196 oend = overwritten_activepoints.end();
197 for(; oi != oend; ++oi)
199 value_node->list[index].erase(*oi);
204 try { iter=value_node->list[index].find(activepoint); }
205 catch(sinfg::Exception::NotFound)
207 throw Error(_("Unable to find activepoint"));
210 //find the value at the old time before we replace it
211 ValueNode_DynamicList::ListEntry::findresult timeiter;
212 timeiter = value_node->list[index].find_time(activepoint.get_time());
214 //we only want to track overwrites (not inplace modifications)
215 if(timeiter.second && activepoint.get_uid() == timeiter.first->get_uid())
217 timeiter.second = false;
220 old_activepoint=*iter;
225 sinfg::info("Erasing the found activepoint");
226 time_overwrite = true;
227 overwritten_ap = *timeiter.first;
229 value_node->list[index].erase(overwritten_ap);
234 value_node->list[index].timing_info.sort();
236 // Signal that a valuenode has been changed
237 value_node->changed();
241 Action::ActivepointSet::undo()
243 ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
246 vector<Activepoint>::iterator i = old_activepoints.begin(), end = old_activepoints.end();
250 try { iter = value_node->list[index].find(*i); }
251 catch(sinfg::Exception::NotFound)
253 throw Error(_("Unable to find activepoint"));
256 //overwrite with old one
260 //add back in all the points that we removed before...
262 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
263 oend = overwritten_activepoints.end();
264 for(; oi != oend; ++oi)
266 value_node->list[index].add(*oi);
271 try { iter=value_node->list[index].find(activepoint); }
272 catch(sinfg::Exception::NotFound)
274 throw Error(_("Unable to find activepoint"));
277 *iter=old_activepoint;
281 value_node->list[index].add(overwritten_ap);
285 value_node->list[index].timing_info.sort();
287 // Signal that a valuenode has been changed
288 value_node->changed();