1 /* === S Y N F I G ========================================================= */
2 /*! \file timepointsdelete.cpp
3 ** \brief Delete 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 "timepointsdelete.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 "activepointremove.h"
39 #include "waypointremove.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::TimepointsDelete);
57 ACTION_SET_NAME(Action::TimepointsDelete,"timepoint_delete");
58 ACTION_SET_LOCAL_NAME(Action::TimepointsDelete,N_("Delete Time Points"));
59 ACTION_SET_TASK(Action::TimepointsDelete,"delete");
60 ACTION_SET_CATEGORY(Action::TimepointsDelete,Action::CATEGORY_WAYPOINT|Action::CATEGORY_ACTIVEPOINT);
61 ACTION_SET_PRIORITY(Action::TimepointsDelete,0);
62 ACTION_SET_VERSION(Action::TimepointsDelete,"0.0");
63 ACTION_SET_CVS_ID(Action::TimepointsDelete,"$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::TimepointsDelete::TimepointsDelete()
77 Action::TimepointsDelete::get_param_vocab()
79 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
81 ret.push_back(ParamDesc("addlayer",Param::TYPE_VALUE)
82 .set_local_name(_("New Selected Layer"))
83 .set_desc(_("A layer to add to our selected list"))
84 .set_supports_multiple()
88 ret.push_back(ParamDesc("addcanvas",Param::TYPE_CANVAS)
89 .set_local_name(_("New Selected Canvas"))
90 .set_desc(_("A canvas to add to our selected list"))
91 .set_supports_multiple()
95 ret.push_back(ParamDesc("addvaluedesc",Param::TYPE_VALUEDESC)
96 .set_local_name(_("New Selected ValueBase"))
97 .set_desc(_("A valuenode's description to add to our selected list"))
98 .set_supports_multiple()
102 ret.push_back(ParamDesc("addtime",Param::TYPE_TIME)
103 .set_local_name(_("New Selected Time Point"))
104 .set_desc(_("A time point to add to our selected list"))
105 .set_supports_multiple()
112 Action::TimepointsDelete::is_candidate(const ParamList &x)
114 if(!candidate_check(get_param_vocab(),x))
117 if( x.find("addlayer") == x.end() &&
118 x.find("addcanvas") == x.end() &&
119 x.find("addvaluedesc") == x.end())
125 Action::TimepointsDelete::set_param(const synfig::String& name, const Action::Param ¶m)
127 if(name=="addlayer" && param.get_type()==Param::TYPE_LAYER)
129 //add a layer to the list
130 sel_layers.push_back(param.get_layer());
135 if(name=="addcanvas" && param.get_type()==Param::TYPE_CANVAS)
137 //add a layer to the list
138 sel_canvases.push_back(param.get_canvas());
143 if(name=="addvaluedesc" && param.get_type()==Param::TYPE_VALUEDESC)
145 //add a layer to the list
146 sel_values.push_back(param.get_value_desc());
151 if(name=="addtime" && param.get_type()==Param::TYPE_TIME)
153 //add a layer to the list
154 sel_times.insert(param.get_time());
159 return Action::CanvasSpecific::set_param(name,param);
163 Action::TimepointsDelete::is_ready()const
165 if((sel_layers.empty() && sel_canvases.empty() && sel_values.empty()) || sel_times.empty())
167 return Action::CanvasSpecific::is_ready();
171 Action::TimepointsDelete::prepare()
175 if(sel_times.empty()) return;
177 //all our lists should be set correctly...
179 //build our sub-action list
180 // and yes we do need to store it temporarily so we don't duplicate
181 // an operation on a specific valuenode, etc....
182 timepoints_ref match;
184 Time fps = get_canvas()->rend_desc().get_frame_rate();
186 //std::vector<synfig::Layer::Handle>
187 //synfig::info("Layers %d", sel_layers.size());
189 std::vector<synfig::Layer::Handle>::iterator i = sel_layers.begin(),
190 end = sel_layers.end();
194 //synfig::info("Recurse through a layer");
195 recurse_layer(*i,sel_times,match);
199 //std::vector<synfig::Canvas::Handle> sel_canvases;
200 //synfig::info("Canvases %d", sel_canvases.size());
202 std::vector<synfig::Canvas::Handle>::iterator i = sel_canvases.begin(),
203 end = sel_canvases.end();
207 //synfig::info("Recurse through a canvas");
208 recurse_canvas(*i,sel_times,match);
212 //std::vector<synfigapp::ValueDesc>
213 //synfig::info("ValueBasedescs %d", sel_values.size());
215 std::vector<synfigapp::ValueDesc>::iterator i = sel_values.begin(),
216 end = sel_values.end();
220 //synfig::info("Recurse through a valuedesc");
221 recurse_valuedesc(*i,sel_times,match);
225 //process the hell out of em...
227 //must build from both lists
228 timepoints_ref::waytracker::const_iterator i = match.waypointbiglist.begin(),
229 end = match.waypointbiglist.end();
232 //iterate through each waypoint for this specific valuenode
233 std::set<synfig::Waypoint>::const_iterator j = i->waypoints.begin(),
234 end = i->waypoints.end();
237 Action::Handle action(WaypointRemove::create());
239 action->set_param("canvas",get_canvas());
240 action->set_param("canvas_interface",get_canvas_interface());
241 action->set_param("value_node",ValueNode::Handle(i->val));
242 action->set_param("waypoint",*j);
244 //run the action now that we've added everything
245 assert(action->is_ready());
246 if(!action->is_ready())
247 throw Error(Error::TYPE_NOTREADY);
249 add_action_front(action);
254 //must build from both lists
255 timepoints_ref::acttracker::const_iterator i = match.actpointbiglist.begin(),
256 end = match.actpointbiglist.end();
259 //iterate through each activepoint for this specific valuenode
260 std::set<synfig::Activepoint>::const_iterator j = i->activepoints.begin(),
261 jend = i->activepoints.end();
262 for(; j != jend; ++j)
264 Action::Handle action(ActivepointRemove::create());
266 action->set_param("canvas",get_canvas());
267 action->set_param("canvas_interface",get_canvas_interface());
268 action->set_param("value_desc",i->val);
269 action->set_param("activepoint",*j);
271 //run the action now that everything should be in order
272 assert(action->is_ready());
273 if(!action->is_ready())
275 throw Error(Error::TYPE_NOTREADY);
278 add_action_front(action);
285 Action::TimepointsDelete::perform()
287 Action::Super::perform();