1 /* === S Y N F I G ========================================================= */
2 /*! \file timepointscopy.cpp
3 ** \brief Copy 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 "timepointscopy.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 "activepointsimpleadd.h"
39 #include "waypointsimpleadd.h"
40 #include <synfigapp/timegather.h>
44 #include <synfigapp/general.h>
50 using namespace synfig;
51 using namespace synfigapp;
52 using namespace Action;
54 /* === M A C R O S ========================================================= */
56 ACTION_INIT(Action::TimepointsCopy);
57 ACTION_SET_NAME(Action::TimepointsCopy,"TimepointsCopy");
58 ACTION_SET_LOCAL_NAME(Action::TimepointsCopy,N_("Copy Time Points"));
59 ACTION_SET_TASK(Action::TimepointsCopy,"copy");
60 ACTION_SET_CATEGORY(Action::TimepointsCopy,Action::CATEGORY_WAYPOINT|Action::CATEGORY_ACTIVEPOINT);
61 ACTION_SET_PRIORITY(Action::TimepointsCopy,0);
62 ACTION_SET_VERSION(Action::TimepointsCopy,"0.0");
63 ACTION_SET_CVS_ID(Action::TimepointsCopy,"$Id$");
65 /* === G L O B A L S ======================================================= */
67 /* === P R O C E D U R E S ================================================= */
69 /* === M E T H O D S ======================================================= */
71 Action::TimepointsCopy::TimepointsCopy()
78 Action::TimepointsCopy::get_param_vocab()
80 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
82 ret.push_back(ParamDesc("addlayer",Param::TYPE_VALUE)
83 .set_local_name(_("New Selected Layer"))
84 .set_desc(_("A layer to add to our selected list"))
85 .set_supports_multiple()
89 ret.push_back(ParamDesc("addcanvas",Param::TYPE_CANVAS)
90 .set_local_name(_("New Selected Canvas"))
91 .set_desc(_("A canvas to add to our selected list"))
92 .set_supports_multiple()
96 ret.push_back(ParamDesc("addvaluedesc",Param::TYPE_VALUEDESC)
97 .set_local_name(_("New Selected ValueBase"))
98 .set_desc(_("A valuenode's description to add to our selected list"))
99 .set_supports_multiple()
103 ret.push_back(ParamDesc("addtime",Param::TYPE_TIME)
104 .set_local_name(_("New Selected Time Point"))
105 .set_desc(_("A time point to add to our selected list"))
106 .set_supports_multiple()
109 ret.push_back(ParamDesc("deltatime",Param::TYPE_TIME)
110 .set_local_name(_("Time adjustment"))
111 .set_desc(_("The amount of time to adjust all the selected points"))
118 Action::TimepointsCopy::is_candidate(const ParamList &x)
120 if(!candidate_check(get_param_vocab(),x))
123 if( x.find("addlayer") == x.end() &&
124 x.find("addcanvas") == x.end() &&
125 x.find("addvaluedesc") == x.end())
131 Action::TimepointsCopy::set_param(const synfig::String& name, const Action::Param ¶m)
133 if(name=="addlayer" && param.get_type()==Param::TYPE_LAYER)
135 //add a layer to the list
136 sel_layers.push_back(param.get_layer());
137 //synfig::info("action got layer");
142 if(name=="addcanvas" && param.get_type()==Param::TYPE_CANVAS)
144 //add a layer to the list
145 sel_canvases.push_back(param.get_canvas());
146 //synfig::info("action got canvas");
151 if(name=="addvaluedesc" && param.get_type()==Param::TYPE_VALUEDESC)
153 //add a layer to the list
154 sel_values.push_back(param.get_value_desc());
155 //synfig::info("action got valuedesc");
160 if(name=="addtime" && param.get_type()==Param::TYPE_TIME)
162 //add a layer to the list
163 sel_times.insert(param.get_time());
164 //synfig::info("action got time");
169 if(name=="deltatime" && param.get_type()==Param::TYPE_TIME)
171 timedelta = param.get_time();
172 //synfig::info("action got time to move");
177 return Action::CanvasSpecific::set_param(name,param);
181 Action::TimepointsCopy::is_ready()const
183 if((sel_layers.empty() && sel_canvases.empty() && sel_values.empty()) || sel_times.empty())
185 return Action::CanvasSpecific::is_ready();
189 Action::TimepointsCopy::prepare()
193 //synfig::info("Preparing TimepointsCopy by %f secs",(float)timemove);
195 if(sel_times.empty()) return;
197 //all our lists should be set correctly...
199 //build our sub-action list
200 // and yes we do need to store it temporarily so we don't duplicate
201 // an operation on a specific valuenode, etc....
202 timepoints_ref match;
204 Time fps = get_canvas()->rend_desc().get_frame_rate();
206 //std::vector<synfig::Layer::Handle>
207 //synfig::info("Layers %d", sel_layers.size());
209 std::vector<synfig::Layer::Handle>::iterator i = sel_layers.begin(),
210 end = sel_layers.end();
214 //synfig::info("Recurse through a layer");
215 recurse_layer(*i,sel_times,match);
219 //std::vector<synfig::Canvas::Handle> sel_canvases;
220 //synfig::info("Canvases %d", sel_canvases.size());
222 std::vector<synfig::Canvas::Handle>::iterator i = sel_canvases.begin(),
223 end = sel_canvases.end();
227 //synfig::info("Recurse through a canvas");
228 recurse_canvas(*i,sel_times,match);
232 //std::vector<synfigapp::ValueDesc>
233 //synfig::info("ValueBasedescs %d", sel_values.size());
235 std::vector<synfigapp::ValueDesc>::iterator i = sel_values.begin(),
236 end = sel_values.end();
240 //synfig::info("Recurse through a valuedesc");
241 recurse_valuedesc(*i,sel_times,match);
245 //synfig::info("built list of waypoints/activepoints to modify");
246 //synfig::info("\t There are %d waypoint sets and %d activepointsets",
247 // match.waypointbiglist.size(), match.actpointbiglist.size());
250 //must build from both lists
251 timepoints_ref::waytracker::const_iterator i = match.waypointbiglist.begin(),
252 end = match.waypointbiglist.end();
255 //iterate through each waypoint for this specific valuenode
256 std::set<synfig::Waypoint>::const_iterator j = i->waypoints.begin(),
257 end = i->waypoints.end();
260 Action::Handle action(WaypointSimpleAdd::create());
262 action->set_param("canvas",get_canvas());
263 action->set_param("canvas_interface",get_canvas_interface());
264 action->set_param("value_node",ValueNode::Handle(i->val));
266 //synfig::info("add waypoint mod...");
267 //NOTE: We may want to store the old time for undoing the action...
270 w.set_time((w.get_time() + timedelta).round(fps));
271 w.mimic(neww); //make sure the new waypoint has a new id
273 action->set_param("waypoint",w);
275 //run the action now that we've added everything
276 assert(action->is_ready());
277 if(!action->is_ready())
278 throw Error(Error::TYPE_NOTREADY);
280 add_action_front(action);
285 //must build from both lists
286 timepoints_ref::acttracker::const_iterator i = match.actpointbiglist.begin(),
287 end = match.actpointbiglist.end();
290 //iterate through each activepoint for this specific valuenode
291 std::set<synfig::Activepoint>::const_iterator j = i->activepoints.begin(),
292 jend = i->activepoints.end();
293 for(; j != jend; ++j)
295 Action::Handle action(ActivepointSimpleAdd::create());
297 action->set_param("canvas",get_canvas());
298 action->set_param("canvas_interface",get_canvas_interface());
299 action->set_param("value_desc",i->val);
301 //NOTE: We may want to store the old time for undoing the action...
304 a.set_time((a.get_time() + timedelta).round(fps));
305 a.mimic(newa); //make sure the new activepoint has a new id
307 action->set_param("activepoint",a);
309 assert(action->is_ready());
310 if(!action->is_ready())
312 throw Error(Error::TYPE_NOTREADY);
315 add_action_front(action);
322 Action::TimepointsCopy::perform()
324 Action::Super::perform();