1 /* === S Y N F I G ========================================================= */
2 /*! \file timepointsmove.cpp
3 ** \brief Move the Time Points File
8 ** Copyright (c) 2004 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 "timepointsmove.h"
33 #include <synfig/layer_pastecanvas.h>
34 #include <synfigapp/canvasinterface.h>
35 #include <synfig/valuenode_dynamiclist.h>
36 #include <synfig/valuenode_animated.h>
38 #include "activepointset.h"
39 #include "waypointset.h"
40 #include <synfigapp/timegather.h>
48 using namespace synfig;
49 using namespace synfigapp;
50 using namespace Action;
52 /* === M A C R O S ========================================================= */
54 ACTION_INIT(Action::TimepointsMove);
55 ACTION_SET_NAME(Action::TimepointsMove,"timepoint_move");
56 ACTION_SET_LOCAL_NAME(Action::TimepointsMove,"Move Time Points");
57 ACTION_SET_TASK(Action::TimepointsMove,"move");
58 ACTION_SET_CATEGORY(Action::TimepointsMove,Action::CATEGORY_WAYPOINT|Action::CATEGORY_ACTIVEPOINT);
59 ACTION_SET_PRIORITY(Action::TimepointsMove,0);
60 ACTION_SET_VERSION(Action::TimepointsMove,"0.0");
61 ACTION_SET_CVS_ID(Action::TimepointsMove,"$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::TimepointsMove::TimepointsMove()
76 Action::TimepointsMove::get_param_vocab()
78 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80 ret.push_back(ParamDesc("addlayer",Param::TYPE_VALUE)
81 .set_local_name(_("New Selected Layer"))
82 .set_desc(_("A layer to add to our selected list"))
83 .set_supports_multiple()
87 ret.push_back(ParamDesc("addcanvas",Param::TYPE_CANVAS)
88 .set_local_name(_("New Selected Canvas"))
89 .set_desc(_("A canvas to add to our selected list"))
90 .set_supports_multiple()
94 ret.push_back(ParamDesc("addvaluedesc",Param::TYPE_VALUEDESC)
95 .set_local_name(_("New Selected ValueBase"))
96 .set_desc(_("A valuenode's description to add to our selected list"))
97 .set_supports_multiple()
101 ret.push_back(ParamDesc("addtime",Param::TYPE_TIME)
102 .set_local_name(_("New Selected Time Point"))
103 .set_desc(_("A time point to add to our selected list"))
104 .set_supports_multiple()
107 ret.push_back(ParamDesc("deltatime",Param::TYPE_TIME)
108 .set_local_name(_("Time adjustment"))
109 .set_desc(_("The amount of time to adjust all the selected points"))
116 Action::TimepointsMove::is_candidate(const ParamList &x)
118 if(!candidate_check(get_param_vocab(),x))
121 if( x.find("addlayer") == x.end() &&
122 x.find("addcanvas") == x.end() &&
123 x.find("addvaluedesc") == x.end())
129 Action::TimepointsMove::set_param(const synfig::String& name, const Action::Param ¶m)
131 if(name=="addlayer" && param.get_type()==Param::TYPE_LAYER)
133 //add a layer to the list
134 sel_layers.push_back(param.get_layer());
135 //synfig::info("action got layer");
140 if(name=="addcanvas" && param.get_type()==Param::TYPE_CANVAS)
142 //add a layer to the list
143 sel_canvases.push_back(param.get_canvas());
144 //synfig::info("action got canvas");
149 if(name=="addvaluedesc" && param.get_type()==Param::TYPE_VALUEDESC)
151 //add a layer to the list
152 sel_values.push_back(param.get_value_desc());
153 //synfig::info("action got valuedesc");
158 if(name=="addtime" && param.get_type()==Param::TYPE_TIME)
160 //add a layer to the list
161 sel_times.insert(param.get_time());
162 //synfig::info("action got time");
167 if(name=="deltatime" && param.get_type()==Param::TYPE_TIME)
169 timemove = param.get_time();
170 //synfig::info("action got time to move");
175 return Action::CanvasSpecific::set_param(name,param);
179 Action::TimepointsMove::is_ready()const
181 if((sel_layers.empty() && sel_canvases.empty() && sel_values.empty()) || sel_times.empty())
183 return Action::CanvasSpecific::is_ready();
187 Action::TimepointsMove::prepare()
191 //synfig::info("Preparing TimepointsMove by %f secs",(float)timemove);
193 if(sel_times.empty()) return;
195 //all our lists should be set correctly...
198 std::set<synfig::Time>::iterator i = sel_times.begin(), end = sel_times.end();
202 synfig::info("Time %f", (float)*i);
206 //build our sub-action list
207 // and yes we do need to store it temporarily so we don't duplicate
208 // an operation on a specific valuenode, etc....
209 timepoints_ref match;
211 Time fps = get_canvas()->rend_desc().get_frame_rate();
213 //std::vector<synfig::Layer::Handle>
214 //synfig::info("Layers %d", sel_layers.size());
216 std::vector<synfig::Layer::Handle>::iterator i = sel_layers.begin(),
217 end = sel_layers.end();
221 //synfig::info("Recurse through a layer");
222 recurse_layer(*i,sel_times,match);
226 //std::vector<synfig::Canvas::Handle> sel_canvases;
227 //synfig::info("Canvases %d", sel_canvases.size());
229 std::vector<synfig::Canvas::Handle>::iterator i = sel_canvases.begin(),
230 end = sel_canvases.end();
234 //synfig::info("Recurse through a canvas");
235 recurse_canvas(*i,sel_times,match);
239 //std::vector<synfigapp::ValueDesc>
240 //synfig::info("ValueBasedescs %d", sel_values.size());
242 std::vector<synfigapp::ValueDesc>::iterator i = sel_values.begin(),
243 end = sel_values.end();
247 //synfig::info("Recurse through a valuedesc");
248 recurse_valuedesc(*i,sel_times,match);
252 //synfig::info("built list of waypoints/activepoints to modify");
253 //synfig::info("\t There are %d waypoint sets and %d activepointsets",
254 // match.waypointbiglist.size(), match.actpointbiglist.size());
255 //process the hell out of em...
257 //must build from both lists
258 timepoints_ref::waytracker::const_iterator i = match.waypointbiglist.begin(),
259 end = match.waypointbiglist.end();
262 Action::Handle action(WaypointSet::create());
264 action->set_param("canvas",get_canvas());
265 action->set_param("canvas_interface",get_canvas_interface());
266 action->set_param("value_node",ValueNode::Handle(i->val));
268 //iterate through each waypoint for this specific valuenode
269 std::set<synfig::Waypoint>::const_iterator j = i->waypoints.begin(),
270 end = i->waypoints.end();
273 //synfig::info("add waypoint mod...");
274 //NOTE: We may want to store the old time for undoing the action...
276 w.set_time((w.get_time() + timemove).round(fps));
277 action->set_param("waypoint",w);
280 //run the action now that we've added everything
281 assert(action->is_ready());
282 if(!action->is_ready())
283 throw Error(Error::TYPE_NOTREADY);
285 add_action_front(action);
289 //must build from both lists
290 timepoints_ref::acttracker::const_iterator i = match.actpointbiglist.begin(),
291 end = match.actpointbiglist.end();
294 Action::Handle action(ActivepointSet::create());
296 action->set_param("canvas",get_canvas());
297 action->set_param("canvas_interface",get_canvas_interface());
298 action->set_param("value_desc",i->val);
300 //iterate through each activepoint for this specific valuenode
301 std::set<synfig::Activepoint>::const_iterator j = i->activepoints.begin(),
302 jend = i->activepoints.end();
303 for(; j != jend; ++j)
305 //synfig::info("add activepoint mod...");
307 //NOTE: We may want to store the old time for undoing the action...
309 a.set_time((a.get_time() + timemove).round(fps));
310 action->set_param("activepoint",a);
313 assert(action->is_ready());
314 if(!action->is_ready())
316 throw Error(Error::TYPE_NOTREADY);
319 add_action_front(action);
325 Action::TimepointsMove::perform()
327 Action::Super::perform();