1 /* === S Y N F I G ========================================================= */
2 /*! \file activepointsetsmart.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 "activepointsetsmart.h"
33 #include "valuenodelinkconnect.h"
34 #include "valuenodereplace.h"
36 #include "activepointset.h"
37 #include "activepointadd.h"
39 #include "valuedescconnect.h"
40 #include <synfigapp/canvasinterface.h>
42 #include <synfigapp/general.h>
48 using namespace synfig;
49 using namespace synfigapp;
50 using namespace Action;
52 /* === M A C R O S ========================================================= */
54 ACTION_INIT(Action::ActivepointSetSmart);
55 ACTION_SET_NAME(Action::ActivepointSetSmart,"activepoint_set_smart");
56 ACTION_SET_LOCAL_NAME(Action::ActivepointSetSmart,N_("Set Activepoint (Smart)"));
57 ACTION_SET_TASK(Action::ActivepointSetSmart,"set");
58 ACTION_SET_CATEGORY(Action::ActivepointSetSmart,Action::CATEGORY_ACTIVEPOINT);
59 ACTION_SET_PRIORITY(Action::ActivepointSetSmart,0);
60 ACTION_SET_VERSION(Action::ActivepointSetSmart,"0.0");
61 ACTION_SET_CVS_ID(Action::ActivepointSetSmart,"$Id$");
63 /* === G L O B A L S ======================================================= */
65 /* === P R O C E D U R E S ================================================= */
67 /* === M E T H O D S ======================================================= */
69 Action::ActivepointSetSmart::ActivepointSetSmart()
71 activepoint.set_time(Time::begin()-1);
77 Action::ActivepointSetSmart::get_param_vocab()
79 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
81 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
82 .set_local_name(_("ValueDesc"))
85 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
86 .set_local_name(_("New Activepoint"))
87 .set_desc(_("Activepoint to be added"))
91 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
92 .set_local_name(_("Time"))
93 .set_desc(_("Time where activepoint is to be added"))
101 Action::ActivepointSetSmart::is_candidate(const ParamList &x)
103 if (!candidate_check(get_param_vocab(),x))
106 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
108 return (value_desc.parent_is_value_node() &&
109 // We need a dynamic list.
110 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()) &&
111 // We need either an activepoint or a time.
112 (x.count("activepoint") || x.count("time")));
116 Action::ActivepointSetSmart::set_param(const synfig::String& name, const Action::Param ¶m)
118 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
120 value_desc=param.get_value_desc();
122 if(!value_desc.parent_is_value_node())
125 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
130 index=value_desc.get_index();
137 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT && !time_set)
139 activepoint=param.get_activepoint();
143 if(name=="time" && param.get_type()==Param::TYPE_TIME && activepoint.get_time()==Time::begin()-1)
145 activepoint.set_time(param.get_time());
154 return Action::CanvasSpecific::set_param(name,param);
156 return Action::CanvasSpecific::set_param(name,param);
160 Action::ActivepointSetSmart::is_ready()const
163 synfig::error("Missing value_node");
165 if(activepoint.get_time()==(Time::begin()-1))
166 synfig::error("Missing activepoint");
168 if(!value_node || activepoint.get_time()==(Time::begin()-1))
170 return Action::CanvasSpecific::is_ready();
173 // This function is called if a time is specified, but not
174 // a activepoint. In this case, we need to calculate the value
175 // of the activepoint
177 Action::ActivepointSetSmart::calc_activepoint()
180 const Time time(activepoint.get_time());
181 activepoint.set_state(value_node->list[index].status_at_time(time));
182 activepoint.set_priority(0);
185 activepoint=value_node->list[index].new_activepoint_at_time(activepoint.get_time());
187 // In this case, nothing is really changing, so there will be
188 // no need to redraw the window
193 Action::ActivepointSetSmart::enclose_activepoint(const synfig::Activepoint& activepoint)
195 times.insert(activepoint.get_time());
197 if(get_edit_mode()&MODE_ANIMATE_PAST) try
199 // Try to find prev keyframe
200 Keyframe keyframe(*get_canvas()->keyframe_list().find_prev(activepoint.get_time()));
202 if(times.count(keyframe.get_time()))
205 times.insert(keyframe.get_time());
207 try { value_node->list[index].find(keyframe.get_time()); }
208 catch(synfig::Exception::NotFound)
210 Action::Handle action(ActivepointAdd::create());
212 action->set_param("canvas",get_canvas());
213 action->set_param("canvas_interface",get_canvas_interface());
214 action->set_param("value_desc",value_desc);
216 if(!value_node->list[index].timing_info.empty())
218 action->set_param("time",keyframe.get_time());
222 synfig::Activepoint tmp;
225 tmp.set_time(keyframe.get_time());
226 action->set_param("activepoint",tmp);
229 assert(action->is_ready());
230 if(!action->is_ready())
231 throw Error(Error::TYPE_NOTREADY);
233 add_action_front(action);
237 catch(synfig::Exception::NotFound) { }
239 if(get_edit_mode()&MODE_ANIMATE_FUTURE)try
241 // Try to find next keyframe
242 Keyframe keyframe(*get_canvas()->keyframe_list().find_next(activepoint.get_time()));
244 if(times.count(keyframe.get_time()))
247 times.insert(keyframe.get_time());
249 try { value_node->list[index].find(keyframe.get_time()); }
250 catch(synfig::Exception::NotFound)
252 Action::Handle action(ActivepointAdd::create());
254 action->set_param("canvas",get_canvas());
255 action->set_param("canvas_interface",get_canvas_interface());
256 action->set_param("value_desc",value_desc);
258 if(!value_node->list[index].timing_info.empty())
260 action->set_param("time",keyframe.get_time());
264 synfig::Activepoint tmp;
267 tmp.set_time(keyframe.get_time());
268 action->set_param("activepoint",tmp);
271 assert(action->is_ready());
272 if(!action->is_ready())
273 throw Error(Error::TYPE_NOTREADY);
275 add_action_front(action);
279 catch(synfig::Exception::NotFound) { }
283 Action::ActivepointSetSmart::prepare()
288 // First, we need to add any activepoints necessary to
289 // maintain the integrity of the keyframes.
290 enclose_activepoint(activepoint);
294 if(value_node->list[index].find(activepoint)==value_node->list[index].timing_info.end())
297 // Then, let's try to replace the old activepoint, if it exists
298 enclose_activepoint(*value_node->list[index].find(activepoint));
300 Action::Handle action(ActivepointSet::create());
302 action->set_param("canvas",get_canvas());
303 action->set_param("canvas_interface",get_canvas_interface());
304 action->set_param("value_desc",value_desc);
305 action->set_param("activepoint",activepoint);
307 assert(action->is_ready());
308 if(!action->is_ready())
309 throw Error(Error::TYPE_NOTREADY);
311 add_action_front(action);
316 catch(Exception::NotFound){}
320 // Check to see if a activepoint exists at this point in time
321 activepoint.mimic(*value_node->list[index].find(activepoint.get_time()));
323 enclose_activepoint(*value_node->list[index].find(activepoint.get_time()));
325 Action::Handle action(ActivepointSet::create());
327 action->set_param("canvas",get_canvas());
328 action->set_param("canvas_interface",get_canvas_interface());
329 action->set_param("value_desc",value_desc);
330 action->set_param("activepoint",activepoint);
332 assert(action->is_ready());
333 if(!action->is_ready())
334 throw Error(Error::TYPE_NOTREADY);
336 add_action_front(action);
341 catch(Exception::NotFound){}
345 // At this point we know that the old activepoint doesn't exist,
346 // so we need to create it.
347 Action::Handle action(ActivepointAdd::create());
349 action->set_param("canvas",get_canvas());
350 action->set_param("canvas_interface",get_canvas_interface());
351 action->set_param("value_desc",value_desc);
352 action->set_param("activepoint",activepoint);
354 assert(action->is_ready());
355 if(!action->is_ready())
356 throw Error(Error::TYPE_NOTREADY);
358 add_action_front(action);
363 catch(Exception::NotFound){}
365 throw Error(_("Unable to determine how to proceed. This is a bug."));