1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
37 #include "actions/layerremove.h"
38 #include "actions/layermove.h"
39 #include "actions/layerraise.h"
40 #include "actions/layerlower.h"
41 #include "actions/layeradd.h"
42 #include "actions/layeractivate.h"
43 #include "actions/layerparamset.h"
44 #include "actions/layerparamconnect.h"
45 #include "actions/layerparamdisconnect.h"
46 #include "actions/layerencapsulate.h"
47 #include "actions/layerduplicate.h"
48 #include "actions/layersetdesc.h"
50 #include "actions/valuenodeconstset.h"
51 #include "actions/valuenodeadd.h"
52 #include "actions/valuenodereplace.h"
53 #include "actions/valuenodelinkconnect.h"
54 #include "actions/valuenodelinkdisconnect.h"
55 #include "actions/valuenodedynamiclistinsert.h"
56 #include "actions/valuenodedynamiclistremove.h"
57 #include "actions/valuenodedynamiclistinsertsmart.h"
58 #include "actions/valuenodedynamiclistremovesmart.h"
59 #include "actions/valuenodedynamiclistloop.h"
60 #include "actions/valuenodedynamiclistunloop.h"
61 #include "actions/valuenodedynamiclistrotateorder.h"
62 #include "actions/valuenoderename.h"
63 #include "actions/valuenoderemove.h"
65 #include "actions/valuedescset.h"
66 #include "actions/valuedescexport.h"
67 #include "actions/valuedescconvert.h"
68 #include "actions/valuedescconnect.h"
69 #include "actions/valuedescdisconnect.h"
70 #include "actions/valuedesclink.h"
71 #include "actions/valuedescblinelink.h"
73 #include "actions/waypointadd.h"
74 #include "actions/waypointset.h"
75 #include "actions/waypointsetsmart.h"
76 #include "actions/waypointremove.h"
77 // #include "actions/waypointsimpleadd.h"
79 #include "actions/activepointadd.h"
80 #include "actions/activepointset.h"
81 #include "actions/activepointsetsmart.h"
82 #include "actions/activepointsetoff.h"
83 #include "actions/activepointseton.h"
84 #include "actions/activepointremove.h"
85 // #include "actions/activepointsimpleadd.h"
87 #include "actions/keyframeadd.h"
88 #include "actions/keyframeset.h"
89 #include "actions/keyframeremove.h"
90 #include "actions/keyframeduplicate.h"
91 #include "actions/keyframewaypointset.h"
92 #include "actions/keyframesetdelta.h"
94 #include "actions/timepointsmove.h"
95 #include "actions/timepointscopy.h"
96 #include "actions/timepointsdelete.h"
98 #include "actions/canvasdescriptionset.h"
99 #include "actions/canvasidset.h"
100 #include "actions/canvasnameset.h"
101 #include "actions/canvasrenddescset.h"
102 #include "actions/canvasadd.h"
103 #include "actions/canvasremove.h"
105 #include "actions/editmodeset.h"
107 #include "actions/blinepointtangentmerge.h"
108 #include "actions/blinepointtangentsplit.h"
110 #include "actions/gradientset.h"
111 #include "actions/colorset.h"
113 #include "actions/groupaddlayers.h"
114 #include "actions/groupremovelayers.h"
115 #include "actions/groupremove.h"
116 #include "actions/grouprename.h"
118 #include "canvasinterface.h"
126 using namespace synfig;
127 using namespace synfigapp;
128 using namespace Action;
130 /* === P R O C E D U R E S ================================================= */
132 /* === S T A T I C S ======================================================= */
134 synfigapp::Action::Book *book_;
136 /* === M E T H O D S ======================================================= */
138 #define ADD_ACTION(x) { BookEntry &be(book()[x::name__]); \
140 be.local_name=dgettext("synfigstudio",x::local_name__); \
141 be.version=x::version__; \
143 be.priority=x::priority__; \
144 be.category=x::category__; \
145 be.factory=x::create; \
146 be.get_param_vocab=x::get_param_vocab; \
147 be.is_candidate=x::is_candidate; \
153 book_=new synfigapp::Action::Book();
155 ADD_ACTION(Action::LayerRemove);
156 ADD_ACTION(Action::LayerMove);
157 ADD_ACTION(Action::LayerRaise);
158 ADD_ACTION(Action::LayerLower);
159 ADD_ACTION(Action::LayerAdd);
160 ADD_ACTION(Action::LayerActivate);
161 ADD_ACTION(Action::LayerParamSet);
162 ADD_ACTION(Action::LayerParamConnect);
163 ADD_ACTION(Action::LayerParamDisconnect);
164 ADD_ACTION(Action::LayerEncapsulate);
165 ADD_ACTION(Action::LayerDuplicate);
166 ADD_ACTION(Action::LayerSetDesc);
168 ADD_ACTION(Action::ValueNodeConstSet);
169 ADD_ACTION(Action::ValueNodeAdd);
170 ADD_ACTION(Action::ValueNodeReplace);
171 ADD_ACTION(Action::ValueNodeLinkConnect);
172 ADD_ACTION(Action::ValueNodeLinkDisconnect);
173 ADD_ACTION(Action::ValueNodeDynamicListInsert);
174 ADD_ACTION(Action::ValueNodeDynamicListRemove);
175 ADD_ACTION(Action::ValueNodeDynamicListInsertSmart);
176 ADD_ACTION(Action::ValueNodeDynamicListRemoveSmart);
177 ADD_ACTION(Action::ValueNodeDynamicListLoop);
178 ADD_ACTION(Action::ValueNodeDynamicListUnLoop);
179 ADD_ACTION(Action::ValueNodeDynamicListRotateOrder);
180 ADD_ACTION(Action::ValueNodeRename);
181 ADD_ACTION(Action::ValueNodeRemove);
183 ADD_ACTION(Action::ValueDescSet);
184 ADD_ACTION(Action::ValueDescExport);
185 ADD_ACTION(Action::ValueDescConvert);
186 ADD_ACTION(Action::ValueDescConnect);
187 ADD_ACTION(Action::ValueDescDisconnect);
188 ADD_ACTION(Action::ValueDescLink);
189 ADD_ACTION(Action::ValueDescBLineLink);
191 ADD_ACTION(Action::WaypointAdd);
192 ADD_ACTION(Action::WaypointSet);
193 ADD_ACTION(Action::WaypointSetSmart);
194 ADD_ACTION(Action::WaypointRemove);
195 // ADD_ACTION(Action::WaypointSimpleAdd);
197 ADD_ACTION(Action::ActivepointAdd);
198 ADD_ACTION(Action::ActivepointSet);
199 ADD_ACTION(Action::ActivepointSetSmart);
200 ADD_ACTION(Action::ActivepointSetOn);
201 ADD_ACTION(Action::ActivepointSetOff);
202 ADD_ACTION(Action::ActivepointRemove);
203 // ADD_ACTION(Action::ActivepointSimpleAdd);
205 ADD_ACTION(Action::KeyframeAdd);
206 ADD_ACTION(Action::KeyframeSet);
207 ADD_ACTION(Action::KeyframeRemove);
208 ADD_ACTION(Action::KeyframeDuplicate);
209 ADD_ACTION(Action::KeyframeWaypointSet);
210 ADD_ACTION(Action::KeyframeSetDelta);
212 ADD_ACTION(Action::CanvasDescriptionSet);
213 ADD_ACTION(Action::CanvasIdSet);
214 ADD_ACTION(Action::CanvasNameSet);
215 ADD_ACTION(Action::CanvasRendDescSet);
216 ADD_ACTION(Action::CanvasAdd);
217 ADD_ACTION(Action::CanvasRemove);
219 ADD_ACTION(Action::EditModeSet);
221 ADD_ACTION(Action::BLinePointTangentMerge);
222 ADD_ACTION(Action::BLinePointTangentSplit);
224 ADD_ACTION(Action::GradientSet);
225 ADD_ACTION(Action::ColorSet);
227 ADD_ACTION(Action::TimepointsMove);
228 ADD_ACTION(Action::TimepointsCopy);
229 ADD_ACTION(Action::TimepointsDelete);
231 ADD_ACTION(Action::GroupAddLayers);
232 ADD_ACTION(Action::GroupRemoveLayers);
233 ADD_ACTION(Action::GroupRemove);
234 ADD_ACTION(Action::GroupRename);
237 Action::Main::~Main()
244 Action::Book& Action::book() { return *book_; }
248 Action::create(const synfig::String &name)
250 if(!book().count(name))
251 return 0; //! \todo perhaps we should throw something instead?
252 return book()[name].factory();
256 Action::CandidateList
257 Action::compile_candidate_list(const ParamList& param_list, Category category)
259 Action::CandidateList ret;
261 Book::const_iterator iter;
263 //synfig::info("param_list.size()=%d",param_list.size());
265 for(iter=book().begin();iter!=book().end();++iter)
267 if((iter->second.category&category))
269 if(iter->second.is_candidate(param_list))
270 ret.push_back(iter->second);
273 //synfig::info("Action \"%s\" is not a candidate",iter->second.name.c_str());
281 Action::CandidateList::iterator
282 Action::CandidateList::find(const synfig::String& x)
285 for(iter=begin();iter!=end();++iter)
292 Action::Base::set_param_list(const ParamList ¶m_list)
294 ParamList::const_iterator iter;
296 for(iter=param_list.begin();iter!=param_list.end();++iter)
297 set_param(iter->first,iter->second);
301 Action::Base::get_layer_descriptions(const std::list<synfig::Layer::Handle> layers, synfig::String singular_prefix, synfig::String plural_prefix)
306 if (plural_prefix.empty())
307 plural_prefix = singular_prefix;
310 return plural_prefix;
312 if (layers.size() == 1)
313 ret = singular_prefix;
320 for(std::list<synfig::Layer::Handle>::const_iterator iter=layers.begin(); iter!=layers.end(); ++iter)
327 ret += strprintf("'%s'", (*iter)->get_non_empty_description().c_str());
334 Action::Base::get_layer_descriptions(const std::list<std::pair<synfig::Layer::Handle,int> > layers, synfig::String singular_prefix, synfig::String plural_prefix)
339 if (plural_prefix.empty())
340 plural_prefix = singular_prefix;
343 return plural_prefix;
345 if (layers.size() == 1)
346 ret = singular_prefix;
353 for(std::list<std::pair<synfig::Layer::Handle,int> >::const_iterator iter=layers.begin(); iter!=layers.end(); ++iter)
360 ret += strprintf("'%s'", iter->first->get_non_empty_description().c_str());
373 ActionList::const_iterator iter;
374 for(iter=action_list_.begin();iter!=action_list_.end();++iter)
381 CanvasSpecific* canvas_specific(dynamic_cast<CanvasSpecific*>(iter->get()));
382 if(canvas_specific && canvas_specific->is_dirty())
387 if(iter!=action_list_.begin())
389 for(--iter;iter!=action_list_.begin();--iter)
398 throw Error(x.get_type(),((*iter)->get_name()+": "+x.get_desc()).c_str());
408 ActionList::const_reverse_iterator iter;
409 for(iter=const_cast<const ActionList &>(action_list_).rbegin();iter!=const_cast<const ActionList &>(action_list_).rend();++iter)
413 CanvasSpecific* canvas_specific(dynamic_cast<CanvasSpecific*>(iter->get()));
414 if(canvas_specific && canvas_specific->is_dirty())
419 if(iter!=const_cast<const ActionList &>(action_list_).rbegin())
421 for(--iter;iter!=const_cast<const ActionList &>(action_list_).rbegin();--iter)
431 Super::add_action(etl::handle<Undoable> action)
433 action_list_.push_back(action);
434 CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get());
435 if(specific_action && !get_canvas())
436 set_canvas(specific_action->get_canvas());
440 Super::add_action_front(etl::handle<Undoable> action)
442 action_list_.push_front(action);
443 CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get());
444 if(specific_action && !get_canvas())
445 set_canvas(specific_action->get_canvas());
449 Group::Group(const synfig::String &str):
463 Action::CanvasSpecific::get_param_vocab()
467 ret.push_back(ParamDesc("canvas",Param::TYPE_CANVAS)
468 .set_local_name(_("Canvas"))
469 .set_desc(_("Selected Canvas"))
472 ret.push_back(ParamDesc("canvas_interface",Param::TYPE_CANVASINTERFACE)
473 .set_local_name(_("Canvas Interface"))
474 .set_desc(_("Canvas Interface"))
483 CanvasSpecific::set_param(const synfig::String& name, const Param ¶m)
485 if(name=="canvas" && param.get_type()==Param::TYPE_CANVAS)
487 if(!param.get_canvas())
489 set_canvas(param.get_canvas());
493 if(name=="canvas_interface" && param.get_type()==Param::TYPE_CANVASINTERFACE)
495 if(!param.get_canvas_interface())
497 set_canvas_interface(param.get_canvas_interface());
499 set_canvas(get_canvas_interface()->get_canvas());
503 if(name=="edit_mode" && param.get_type()==Param::TYPE_EDITMODE)
505 set_edit_mode(param.get_edit_mode());
514 CanvasSpecific::is_ready()const
522 CanvasSpecific::get_edit_mode()const
524 if(mode_!=MODE_UNDEFINED)
527 if(get_canvas_interface())
528 return get_canvas_interface()->get_mode();