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>
48 using namespace synfig;
49 using namespace synfigapp;
50 using namespace Action;
52 /* === M A C R O S ========================================================= */
54 ACTION_INIT(Action::TimepointsDelete);
55 ACTION_SET_NAME(Action::TimepointsDelete,"timepoint_delete");
56 ACTION_SET_LOCAL_NAME(Action::TimepointsDelete,"Delete Time Points");
57 ACTION_SET_TASK(Action::TimepointsDelete,"delete");
58 ACTION_SET_CATEGORY(Action::TimepointsDelete,Action::CATEGORY_WAYPOINT|Action::CATEGORY_ACTIVEPOINT);
59 ACTION_SET_PRIORITY(Action::TimepointsDelete,0);
60 ACTION_SET_VERSION(Action::TimepointsDelete,"0.0");
61 ACTION_SET_CVS_ID(Action::TimepointsDelete,"$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::TimepointsDelete::TimepointsDelete()
75 Action::TimepointsDelete::get_param_vocab()
77 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
79 ret.push_back(ParamDesc("addlayer",Param::TYPE_VALUE)
80 .set_local_name(_("New Selected Layer"))
81 .set_desc(_("A layer to add to our selected list"))
82 .set_supports_multiple()
86 ret.push_back(ParamDesc("addcanvas",Param::TYPE_CANVAS)
87 .set_local_name(_("New Selected Canvas"))
88 .set_desc(_("A canvas to add to our selected list"))
89 .set_supports_multiple()
93 ret.push_back(ParamDesc("addvaluedesc",Param::TYPE_VALUEDESC)
94 .set_local_name(_("New Selected ValueBase"))
95 .set_desc(_("A valuenode's description to add to our selected list"))
96 .set_supports_multiple()
100 ret.push_back(ParamDesc("addtime",Param::TYPE_TIME)
101 .set_local_name(_("New Selected Time Point"))
102 .set_desc(_("A time point to add to our selected list"))
103 .set_supports_multiple()
110 Action::TimepointsDelete::is_candidate(const ParamList &x)
112 if(!candidate_check(get_param_vocab(),x))
115 if( x.find("addlayer") == x.end() &&
116 x.find("addcanvas") == x.end() &&
117 x.find("addvaluedesc") == x.end())
123 Action::TimepointsDelete::set_param(const synfig::String& name, const Action::Param ¶m)
125 if(name=="addlayer" && param.get_type()==Param::TYPE_LAYER)
127 //add a layer to the list
128 sel_layers.push_back(param.get_layer());
133 if(name=="addcanvas" && param.get_type()==Param::TYPE_CANVAS)
135 //add a layer to the list
136 sel_canvases.push_back(param.get_canvas());
141 if(name=="addvaluedesc" && param.get_type()==Param::TYPE_VALUEDESC)
143 //add a layer to the list
144 sel_values.push_back(param.get_value_desc());
149 if(name=="addtime" && param.get_type()==Param::TYPE_TIME)
151 //add a layer to the list
152 sel_times.insert(param.get_time());
157 return Action::CanvasSpecific::set_param(name,param);
161 Action::TimepointsDelete::is_ready()const
163 if((sel_layers.empty() && sel_canvases.empty() && sel_values.empty()) || sel_times.empty())
165 return Action::CanvasSpecific::is_ready();
169 Action::TimepointsDelete::prepare()
173 if(sel_times.empty()) return;
175 //all our lists should be set correctly...
177 //build our sub-action list
178 // and yes we do need to store it temporarily so we don't duplicate
179 // an operation on a specific valuenode, etc....
180 timepoints_ref match;
182 Time fps = get_canvas()->rend_desc().get_frame_rate();
184 //std::vector<synfig::Layer::Handle>
185 //synfig::info("Layers %d", sel_layers.size());
187 std::vector<synfig::Layer::Handle>::iterator i = sel_layers.begin(),
188 end = sel_layers.end();
192 //synfig::info("Recurse through a layer");
193 recurse_layer(*i,sel_times,match);
197 //std::vector<synfig::Canvas::Handle> sel_canvases;
198 //synfig::info("Canvases %d", sel_canvases.size());
200 std::vector<synfig::Canvas::Handle>::iterator i = sel_canvases.begin(),
201 end = sel_canvases.end();
205 //synfig::info("Recurse through a canvas");
206 recurse_canvas(*i,sel_times,match);
210 //std::vector<synfigapp::ValueDesc>
211 //synfig::info("ValueBasedescs %d", sel_values.size());
213 std::vector<synfigapp::ValueDesc>::iterator i = sel_values.begin(),
214 end = sel_values.end();
218 //synfig::info("Recurse through a valuedesc");
219 recurse_valuedesc(*i,sel_times,match);
223 //process the hell out of em...
225 //must build from both lists
226 timepoints_ref::waytracker::const_iterator i = match.waypointbiglist.begin(),
227 end = match.waypointbiglist.end();
230 //iterate through each waypoint for this specific valuenode
231 std::set<synfig::Waypoint>::const_iterator j = i->waypoints.begin(),
232 end = i->waypoints.end();
235 Action::Handle action(WaypointRemove::create());
237 action->set_param("canvas",get_canvas());
238 action->set_param("canvas_interface",get_canvas_interface());
239 action->set_param("value_node",ValueNode::Handle(i->val));
240 action->set_param("waypoint",*j);
242 //run the action now that we've added everything
243 assert(action->is_ready());
244 if(!action->is_ready())
245 throw Error(Error::TYPE_NOTREADY);
247 add_action_front(action);
252 //must build from both lists
253 timepoints_ref::acttracker::const_iterator i = match.actpointbiglist.begin(),
254 end = match.actpointbiglist.end();
257 //iterate through each activepoint for this specific valuenode
258 std::set<synfig::Activepoint>::const_iterator j = i->activepoints.begin(),
259 jend = i->activepoints.end();
260 for(; j != jend; ++j)
262 Action::Handle action(ActivepointRemove::create());
264 action->set_param("canvas",get_canvas());
265 action->set_param("canvas_interface",get_canvas_interface());
266 action->set_param("value_desc",i->val);
267 action->set_param("activepoint",*j);
269 //run the action now that everything should be in order
270 assert(action->is_ready());
271 if(!action->is_ready())
273 throw Error(Error::TYPE_NOTREADY);
276 add_action_front(action);
283 Action::TimepointsDelete::perform()
285 Action::Super::perform();