1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: action.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., 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 ======================================================= */
36 #include "actions/layerremove.h"
37 #include "actions/layermove.h"
38 #include "actions/layerraise.h"
39 #include "actions/layerlower.h"
40 #include "actions/layeradd.h"
41 #include "actions/layeractivate.h"
42 #include "actions/layerparamset.h"
43 #include "actions/layerparamconnect.h"
44 #include "actions/layerparamdisconnect.h"
45 #include "actions/layerencapsulate.h"
46 #include "actions/layerduplicate.h"
47 #include "actions/layersetdesc.h"
49 #include "actions/valuenodeconstset.h"
50 #include "actions/valuenodeadd.h"
51 #include "actions/valuenodereplace.h"
52 #include "actions/valuenodelinkconnect.h"
53 #include "actions/valuenodelinkdisconnect.h"
54 #include "actions/valuenodedynamiclistinsert.h"
55 #include "actions/valuenodedynamiclistremove.h"
56 #include "actions/valuenodedynamiclistinsertsmart.h"
57 #include "actions/valuenodedynamiclistremovesmart.h"
58 #include "actions/valuenodedynamiclistloop.h"
59 #include "actions/valuenodedynamiclistunloop.h"
60 #include "actions/valuenodedynamiclistrotateorder.h"
61 #include "actions/valuenoderename.h"
62 #include "actions/valuenoderemove.h"
64 #include "actions/valuedescset.h"
65 #include "actions/valuedescexport.h"
66 #include "actions/valuedescconvert.h"
67 #include "actions/valuedescconnect.h"
68 #include "actions/valuedescdisconnect.h"
69 #include "actions/valuedesclink.h"
71 #include "actions/waypointadd.h"
72 #include "actions/waypointset.h"
73 #include "actions/waypointsetsmart.h"
74 #include "actions/waypointremove.h"
76 #include "actions/activepointadd.h"
77 #include "actions/activepointset.h"
78 #include "actions/activepointsetsmart.h"
79 #include "actions/activepointsetoff.h"
80 #include "actions/activepointseton.h"
81 #include "actions/activepointremove.h"
83 #include "actions/keyframeadd.h"
84 #include "actions/keyframeset.h"
85 #include "actions/keyframeremove.h"
86 #include "actions/keyframeduplicate.h"
87 #include "actions/keyframewaypointset.h"
88 #include "actions/keyframesetdelta.h"
90 #include "actions/timepointsmove.h"
91 #include "actions/timepointscopy.h"
92 #include "actions/timepointsdelete.h"
94 #include "actions/canvasrenddescset.h"
95 #include "actions/canvasadd.h"
96 #include "actions/canvasremove.h"
98 #include "actions/editmodeset.h"
100 #include "actions/blinepointtangentmerge.h"
101 #include "actions/blinepointtangentsplit.h"
103 #include "actions/gradientset.h"
104 #include "actions/colorset.h"
106 #include "actions/groupaddlayers.h"
107 #include "actions/groupremovelayers.h"
108 #include "actions/groupremove.h"
109 #include "actions/grouprename.h"
111 #include "canvasinterface.h"
117 using namespace synfig;
118 using namespace synfigapp;
119 using namespace Action;
121 /* === P R O C E D U R E S ================================================= */
123 /* === S T A T I C S ======================================================= */
125 synfigapp::Action::Book *book_;
127 /* === M E T H O D S ======================================================= */
129 #define ADD_ACTION(x) { BookEntry &be(book()[x::name__]); \
131 be.local_name=x::local_name__; \
132 be.version=x::version__; \
134 be.priority=x::priority__; \
135 be.category=x::category__; \
136 be.factory=x::create; \
137 be.get_param_vocab=x::get_param_vocab; \
138 be.is_canidate=x::is_canidate; \
144 book_=new synfigapp::Action::Book();
146 ADD_ACTION(Action::LayerRemove);
147 ADD_ACTION(Action::LayerMove);
148 ADD_ACTION(Action::LayerRaise);
149 ADD_ACTION(Action::LayerLower);
150 ADD_ACTION(Action::LayerAdd);
151 ADD_ACTION(Action::LayerActivate);
152 ADD_ACTION(Action::LayerParamSet);
153 ADD_ACTION(Action::LayerParamConnect);
154 ADD_ACTION(Action::LayerParamDisconnect);
155 ADD_ACTION(Action::LayerEncapsulate);
156 ADD_ACTION(Action::LayerDuplicate);
157 ADD_ACTION(Action::LayerSetDesc);
159 ADD_ACTION(Action::ValueNodeConstSet);
160 ADD_ACTION(Action::ValueNodeAdd);
161 ADD_ACTION(Action::ValueNodeReplace);
162 ADD_ACTION(Action::ValueNodeLinkConnect);
163 ADD_ACTION(Action::ValueNodeLinkDisconnect);
164 ADD_ACTION(Action::ValueNodeDynamicListInsert);
165 ADD_ACTION(Action::ValueNodeDynamicListRemove);
166 ADD_ACTION(Action::ValueNodeDynamicListInsertSmart);
167 ADD_ACTION(Action::ValueNodeDynamicListRemoveSmart);
168 ADD_ACTION(Action::ValueNodeDynamicListLoop);
169 ADD_ACTION(Action::ValueNodeDynamicListUnLoop);
170 ADD_ACTION(Action::ValueNodeDynamicListRotateOrder);
171 ADD_ACTION(Action::ValueNodeRename);
172 ADD_ACTION(Action::ValueNodeRemove);
174 ADD_ACTION(Action::ValueDescSet);
175 ADD_ACTION(Action::ValueDescExport);
176 ADD_ACTION(Action::ValueDescConvert);
177 ADD_ACTION(Action::ValueDescConnect);
178 ADD_ACTION(Action::ValueDescDisconnect);
179 ADD_ACTION(Action::ValueDescLink);
181 ADD_ACTION(Action::WaypointAdd);
182 ADD_ACTION(Action::WaypointSet);
183 ADD_ACTION(Action::WaypointSetSmart);
184 ADD_ACTION(Action::WaypointRemove);
186 ADD_ACTION(Action::ActivepointAdd);
187 ADD_ACTION(Action::ActivepointSet);
188 ADD_ACTION(Action::ActivepointSetSmart);
189 ADD_ACTION(Action::ActivepointSetOn);
190 ADD_ACTION(Action::ActivepointSetOff);
191 ADD_ACTION(Action::ActivepointRemove);
193 ADD_ACTION(Action::KeyframeAdd);
194 ADD_ACTION(Action::KeyframeSet);
195 ADD_ACTION(Action::KeyframeRemove);
196 ADD_ACTION(Action::KeyframeDuplicate);
197 ADD_ACTION(Action::KeyframeWaypointSet);
198 ADD_ACTION(Action::KeyframeSetDelta);
200 ADD_ACTION(Action::CanvasRendDescSet);
201 ADD_ACTION(Action::CanvasAdd);
202 ADD_ACTION(Action::CanvasRemove);
204 ADD_ACTION(Action::EditModeSet);
206 ADD_ACTION(Action::BLinePointTangentMerge);
207 ADD_ACTION(Action::BLinePointTangentSplit);
209 ADD_ACTION(Action::GradientSet);
210 ADD_ACTION(Action::ColorSet);
212 ADD_ACTION(Action::TimepointsMove);
213 ADD_ACTION(Action::TimepointsCopy);
214 ADD_ACTION(Action::TimepointsDelete);
216 ADD_ACTION(Action::GroupAddLayers);
217 ADD_ACTION(Action::GroupRemoveLayers);
218 ADD_ACTION(Action::GroupRemove);
219 ADD_ACTION(Action::GroupRename);
222 Action::Main::~Main()
229 Action::Book& Action::book() { return *book_; }
233 Action::create(const String &name)
235 if(!book().count(name))
236 return 0; //! \todo perhaps we should throw something instead?
237 return book()[name].factory();
242 Action::compile_canidate_list(const ParamList& param_list, Category category)
244 Action::CanidateList ret;
246 Book::const_iterator iter;
248 //synfig::info("param_list.size()=%d",param_list.size());
250 for(iter=book().begin();iter!=book().end();++iter)
252 if((iter->second.category&category))
254 if(iter->second.is_canidate(param_list))
255 ret.push_back(iter->second);
258 //synfig::info("Action \"%s\" is not a canidate",iter->second.name.c_str());
266 Action::CanidateList::iterator
267 Action::CanidateList::find(const String& x)
270 for(iter=begin();iter!=end();++iter)
277 Action::Base::set_param_list(const ParamList ¶m_list)
279 ParamList::const_iterator iter;
281 for(iter=param_list.begin();iter!=param_list.end();++iter)
282 set_param(iter->first,iter->second);
292 ActionList::const_iterator iter;
293 for(iter=action_list_.begin();iter!=action_list_.end();++iter)
300 CanvasSpecific* canvas_specific(dynamic_cast<CanvasSpecific*>(iter->get()));
301 if(canvas_specific && canvas_specific->is_dirty())
306 if(iter!=action_list_.begin())
308 for(--iter;iter!=action_list_.begin();--iter)
317 throw Error(x.get_type(),((*iter)->get_name()+": "+x.get_desc()).c_str());
327 ActionList::const_reverse_iterator iter;
328 for(iter=const_cast<const ActionList &>(action_list_).rbegin();iter!=const_cast<const ActionList &>(action_list_).rend();++iter)
332 CanvasSpecific* canvas_specific(dynamic_cast<CanvasSpecific*>(iter->get()));
333 if(canvas_specific && canvas_specific->is_dirty())
338 if(iter!=const_cast<const ActionList &>(action_list_).rbegin())
340 for(--iter;iter!=const_cast<const ActionList &>(action_list_).rbegin();--iter)
350 Super::add_action(etl::handle<Undoable> action)
352 action_list_.push_back(action);
353 CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get());
354 if(specific_action && !get_canvas())
355 set_canvas(specific_action->get_canvas());
359 Super::add_action_front(etl::handle<Undoable> action)
361 action_list_.push_front(action);
362 CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get());
363 if(specific_action && !get_canvas())
364 set_canvas(specific_action->get_canvas());
368 Group::Group(const std::string &str):
382 Action::CanvasSpecific::get_param_vocab()
386 ret.push_back(ParamDesc("canvas",Param::TYPE_CANVAS)
387 .set_local_name(_("Canvas"))
388 .set_desc(_("Selected Canvas"))
391 ret.push_back(ParamDesc("canvas_interface",Param::TYPE_CANVASINTERFACE)
392 .set_local_name(_("Canvas Interface"))
393 .set_desc(_("Canvas Interface"))
402 CanvasSpecific::set_param(const synfig::String& name, const Param ¶m)
404 if(name=="canvas" && param.get_type()==Param::TYPE_CANVAS)
406 if(!param.get_canvas())
408 set_canvas(param.get_canvas());
412 if(name=="canvas_interface" && param.get_type()==Param::TYPE_CANVASINTERFACE)
414 if(!param.get_canvas_interface())
416 set_canvas_interface(param.get_canvas_interface());
418 set_canvas(get_canvas_interface()->get_canvas());
422 if(name=="edit_mode" && param.get_type()==Param::TYPE_EDITMODE)
424 set_edit_mode(param.get_edit_mode());
433 CanvasSpecific::is_ready()const
441 CanvasSpecific::get_edit_mode()const
443 if(mode_!=MODE_UNDEFINED)
446 if(get_canvas_interface())
447 return get_canvas_interface()->get_mode();