1 /* === S I N F G =========================================================== */
2 /*! \file activepointsetsmart.cpp
3 ** \brief Template File
5 ** $Id: activepointsetsmart.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 "activepointsetsmart.h"
32 #include "valuenodelinkconnect.h"
33 #include "valuenodereplace.h"
35 #include "activepointset.h"
36 #include "activepointadd.h"
38 #include "valuedescconnect.h"
39 #include <sinfgapp/canvasinterface.h>
45 using namespace sinfg;
46 using namespace sinfgapp;
47 using namespace Action;
49 /* === M A C R O S ========================================================= */
51 ACTION_INIT(Action::ActivepointSetSmart);
52 ACTION_SET_NAME(Action::ActivepointSetSmart,"activepoint_set_smart");
53 ACTION_SET_LOCAL_NAME(Action::ActivepointSetSmart,_("Set Activepoint (Smart)"));
54 ACTION_SET_TASK(Action::ActivepointSetSmart,"set");
55 ACTION_SET_CATEGORY(Action::ActivepointSetSmart,Action::CATEGORY_ACTIVEPOINT);
56 ACTION_SET_PRIORITY(Action::ActivepointSetSmart,0);
57 ACTION_SET_VERSION(Action::ActivepointSetSmart,"0.0");
58 ACTION_SET_CVS_ID(Action::ActivepointSetSmart,"$Id: activepointsetsmart.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
60 /* === G L O B A L S ======================================================= */
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 Action::ActivepointSetSmart::ActivepointSetSmart()
68 activepoint.set_time(Time::begin()-1);
74 Action::ActivepointSetSmart::get_param_vocab()
76 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
78 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
79 .set_local_name(_("ValueDesc"))
82 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
83 .set_local_name(_("New Activepoint"))
84 .set_desc(_("Activepoint to be added"))
88 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
89 .set_local_name(_("Time"))
90 .set_desc(_("Time where activepoint is to be added"))
98 Action::ActivepointSetSmart::is_canidate(const ParamList &x)
100 if(canidate_check(get_param_vocab(),x))
102 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
103 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
106 // We need either a activepoint or a time.
107 if(x.count("activepoint") || x.count("time"))
114 Action::ActivepointSetSmart::set_param(const sinfg::String& name, const Action::Param ¶m)
116 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
118 value_desc=param.get_value_desc();
120 if(!value_desc.parent_is_value_node())
123 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
128 index=value_desc.get_index();
135 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT && !time_set)
137 activepoint=param.get_activepoint();
141 if(name=="time" && param.get_type()==Param::TYPE_TIME && activepoint.get_time()==Time::begin()-1)
143 activepoint.set_time(param.get_time());
152 return Action::CanvasSpecific::set_param(name,param);
154 return Action::CanvasSpecific::set_param(name,param);
158 Action::ActivepointSetSmart::is_ready()const
161 sinfg::error("Missing value_node");
163 if(activepoint.get_time()==(Time::begin()-1))
164 sinfg::error("Missing activepoint");
166 if(!value_node || activepoint.get_time()==(Time::begin()-1))
168 return Action::CanvasSpecific::is_ready();
171 // This function is called if a time is specified, but not
172 // a activepoint. In this case, we need to calculate the value
173 // of the activepoint
175 Action::ActivepointSetSmart::calc_activepoint()
178 const Time time(activepoint.get_time());
179 activepoint.set_state(value_node->list[index].status_at_time(time));
180 activepoint.set_priority(0);
183 activepoint=value_node->list[index].new_activepoint_at_time(activepoint.get_time());
185 // In this case, nothing is really changing, so there will be
186 // no need to redraw the window
191 Action::ActivepointSetSmart::enclose_activepoint(const sinfg::Activepoint& activepoint)
193 times.insert(activepoint.get_time());
195 if(get_edit_mode()&MODE_ANIMATE_PAST) try
197 // Try to find prev keyframe
198 Keyframe keyframe(*get_canvas()->keyframe_list().find_prev(activepoint.get_time()));
200 if(times.count(keyframe.get_time()))
203 times.insert(keyframe.get_time());
205 try { value_node->list[index].find(keyframe.get_time()); }
206 catch(sinfg::Exception::NotFound)
208 Action::Handle action(ActivepointAdd::create());
210 action->set_param("canvas",get_canvas());
211 action->set_param("canvas_interface",get_canvas_interface());
212 action->set_param("value_desc",value_desc);
214 if(!value_node->list[index].timing_info.empty())
216 action->set_param("time",keyframe.get_time());
220 sinfg::Activepoint tmp;
223 tmp.set_time(keyframe.get_time());
224 action->set_param("activepoint",tmp);
227 assert(action->is_ready());
228 if(!action->is_ready())
229 throw Error(Error::TYPE_NOTREADY);
231 add_action_front(action);
235 catch(sinfg::Exception::NotFound) { }
237 if(get_edit_mode()&MODE_ANIMATE_FUTURE)try
239 // Try to find next keyframe
240 Keyframe keyframe(*get_canvas()->keyframe_list().find_next(activepoint.get_time()));
242 if(times.count(keyframe.get_time()))
245 times.insert(keyframe.get_time());
247 try { value_node->list[index].find(keyframe.get_time()); }
248 catch(sinfg::Exception::NotFound)
250 Action::Handle action(ActivepointAdd::create());
252 action->set_param("canvas",get_canvas());
253 action->set_param("canvas_interface",get_canvas_interface());
254 action->set_param("value_desc",value_desc);
256 if(!value_node->list[index].timing_info.empty())
258 action->set_param("time",keyframe.get_time());
262 sinfg::Activepoint tmp;
265 tmp.set_time(keyframe.get_time());
266 action->set_param("activepoint",tmp);
269 assert(action->is_ready());
270 if(!action->is_ready())
271 throw Error(Error::TYPE_NOTREADY);
273 add_action_front(action);
277 catch(sinfg::Exception::NotFound) { }
281 Action::ActivepointSetSmart::prepare()
286 // First, we need to to add any activepoints necessary to
287 // maintain the integrity of the keyframes.
288 enclose_activepoint(activepoint);
292 if(value_node->list[index].find(activepoint)==value_node->list[index].timing_info.end())
295 // Then, lets try to replace the old activepoint, if it exists
296 enclose_activepoint(*value_node->list[index].find(activepoint));
298 Action::Handle action(ActivepointSet::create());
300 action->set_param("canvas",get_canvas());
301 action->set_param("canvas_interface",get_canvas_interface());
302 action->set_param("value_desc",value_desc);
303 action->set_param("activepoint",activepoint);
305 assert(action->is_ready());
306 if(!action->is_ready())
307 throw Error(Error::TYPE_NOTREADY);
309 add_action_front(action);
314 catch(Exception::NotFound){}
318 // Check to see if a activepoint exists at this point in time
319 activepoint.mimic(*value_node->list[index].find(activepoint.get_time()));
321 enclose_activepoint(*value_node->list[index].find(activepoint.get_time()));
323 Action::Handle action(ActivepointSet::create());
325 action->set_param("canvas",get_canvas());
326 action->set_param("canvas_interface",get_canvas_interface());
327 action->set_param("value_desc",value_desc);
328 action->set_param("activepoint",activepoint);
330 assert(action->is_ready());
331 if(!action->is_ready())
332 throw Error(Error::TYPE_NOTREADY);
334 add_action_front(action);
339 catch(Exception::NotFound){}
343 // At this point we know that the old activepoint doesn't exist,
344 // so we need to create it.
345 Action::Handle action(ActivepointAdd::create());
347 action->set_param("canvas",get_canvas());
348 action->set_param("canvas_interface",get_canvas_interface());
349 action->set_param("value_desc",value_desc);
350 action->set_param("activepoint",activepoint);
352 assert(action->is_ready());
353 if(!action->is_ready())
354 throw Error(Error::TYPE_NOTREADY);
356 add_action_front(action);
361 catch(Exception::NotFound){}
363 throw Error(_("Unable to determine how to procede. This is a bug."));