Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.08 / src / synfigapp / actions / timepointsdelete.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file timepointsdelete.cpp
3 **      \brief Delete the Time Points File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
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>
37
38 #include "activepointremove.h"
39 #include "waypointremove.h"
40 #include <synfigapp/timegather.h>
41
42 #include <typeinfo>
43
44 #include <synfigapp/general.h>
45
46 #endif
47
48 using namespace std;
49 using namespace etl;
50 using namespace synfig;
51 using namespace synfigapp;
52 using namespace Action;
53
54 /* === M A C R O S ========================================================= */
55
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$");
64
65 /* === G L O B A L S ======================================================= */
66
67 /* === P R O C E D U R E S ================================================= */
68
69 /* === M E T H O D S ======================================================= */
70
71 Action::TimepointsDelete::TimepointsDelete()
72 {
73         set_dirty(false);
74 }
75
76 Action::ParamVocab
77 Action::TimepointsDelete::get_param_vocab()
78 {
79         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80
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()
85                 .set_optional()
86         );
87
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()
92                 .set_optional()
93         );
94
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()
99                 .set_optional()
100         );
101
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()
106         );
107
108         return ret;
109 }
110
111 bool
112 Action::TimepointsDelete::is_candidate(const ParamList &x)
113 {
114         if(!candidate_check(get_param_vocab(),x))
115                 return false;
116
117         if(     x.find("addlayer") == x.end() &&
118                 x.find("addcanvas") == x.end() &&
119                 x.find("addvaluedesc") == x.end())
120                 return false;
121         return true;
122 }
123
124 bool
125 Action::TimepointsDelete::set_param(const synfig::String& name, const Action::Param &param)
126 {
127         if(name=="addlayer" && param.get_type()==Param::TYPE_LAYER)
128         {
129                 //add a layer to the list
130                 sel_layers.push_back(param.get_layer());
131
132                 return true;
133         }
134
135         if(name=="addcanvas" && param.get_type()==Param::TYPE_CANVAS)
136         {
137                 //add a layer to the list
138                 sel_canvases.push_back(param.get_canvas());
139
140                 return true;
141         }
142
143         if(name=="addvaluedesc" && param.get_type()==Param::TYPE_VALUEDESC)
144         {
145                 //add a layer to the list
146                 sel_values.push_back(param.get_value_desc());
147
148                 return true;
149         }
150
151         if(name=="addtime" && param.get_type()==Param::TYPE_TIME)
152         {
153                 //add a layer to the list
154                 sel_times.insert(param.get_time());
155
156                 return true;
157         }
158
159         return Action::CanvasSpecific::set_param(name,param);
160 }
161
162 bool
163 Action::TimepointsDelete::is_ready()const
164 {
165         if((sel_layers.empty() && sel_canvases.empty() && sel_values.empty()) || sel_times.empty())
166                 return false;
167         return Action::CanvasSpecific::is_ready();
168 }
169
170 void
171 Action::TimepointsDelete::prepare()
172 {
173         clear();
174
175         if(sel_times.empty()) return;
176
177         //all our lists should be set correctly...
178
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;
183
184         Time fps = get_canvas()->rend_desc().get_frame_rate();
185
186         //std::vector<synfig::Layer::Handle>
187         //synfig::info("Layers %d", sel_layers.size());
188         {
189                 std::vector<synfig::Layer::Handle>::iterator i = sel_layers.begin(),
190                                                                                                         end = sel_layers.end();
191
192                 for(; i != end; ++i)
193                 {
194                         //synfig::info("Recurse through a layer");
195                         recurse_layer(*i,sel_times,match);
196                 }
197         }
198
199         //std::vector<synfig::Canvas::Handle>   sel_canvases;
200         //synfig::info("Canvases %d", sel_canvases.size());
201         {
202                 std::vector<synfig::Canvas::Handle>::iterator   i = sel_canvases.begin(),
203                                                                                                                 end = sel_canvases.end();
204
205                 for(; i != end; ++i)
206                 {
207                         //synfig::info("Recurse through a canvas");
208                         recurse_canvas(*i,sel_times,match);
209                 }
210         }
211
212         //std::vector<synfigapp::ValueDesc>
213         //synfig::info("ValueBasedescs %d", sel_values.size());
214         {
215                 std::vector<synfigapp::ValueDesc>::iterator     i = sel_values.begin(),
216                                                                                                         end = sel_values.end();
217
218                 for(; i != end; ++i)
219                 {
220                         //synfig::info("Recurse through a valuedesc");
221                         recurse_valuedesc(*i,sel_times,match);
222                 }
223         }
224
225         //process the hell out of em...
226         {
227                 //must build from both lists
228                 timepoints_ref::waytracker::const_iterator      i = match.waypointbiglist.begin(),
229                                                                                                         end = match.waypointbiglist.end();
230                 for(; i != end; ++i)
231                 {
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();
235                         for(; j != end; ++j)
236                         {
237                                 Action::Handle action(WaypointRemove::create());
238
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);
243
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);
248
249                                 add_action_front(action);
250                         }
251                 }
252         }
253         {
254                 //must build from both lists
255                 timepoints_ref::acttracker::const_iterator      i = match.actpointbiglist.begin(),
256                                                                                                         end = match.actpointbiglist.end();
257                 for(; i != end; ++i)
258                 {
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)
263                         {
264                                 Action::Handle action(ActivepointRemove::create());
265
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);
270
271                                 //run the action now that everything should be in order
272                                 assert(action->is_ready());
273                                 if(!action->is_ready())
274                                 {
275                                         throw Error(Error::TYPE_NOTREADY);
276                                 }
277
278                                 add_action_front(action);
279                         }
280                 }
281         }
282 }
283
284 void
285 Action::TimepointsDelete::perform()
286 {
287         Action::Super::perform();
288 }