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/waypointconnect.h"
78 #include "actions/waypointdisconnect.h"
79 // #include "actions/waypointsimpleadd.h"
81 #include "actions/activepointadd.h"
82 #include "actions/activepointset.h"
83 #include "actions/activepointsetsmart.h"
84 #include "actions/activepointsetoff.h"
85 #include "actions/activepointseton.h"
86 #include "actions/activepointremove.h"
87 // #include "actions/activepointsimpleadd.h"
89 #include "actions/keyframeadd.h"
90 #include "actions/keyframeset.h"
91 #include "actions/keyframeremove.h"
92 #include "actions/keyframeduplicate.h"
93 #include "actions/keyframewaypointset.h"
94 #include "actions/keyframesetdelta.h"
96 #include "actions/timepointsmove.h"
97 #include "actions/timepointscopy.h"
98 #include "actions/timepointsdelete.h"
100 #include "actions/canvasdescriptionset.h"
101 #include "actions/canvasidset.h"
102 #include "actions/canvasnameset.h"
103 #include "actions/canvasrenddescset.h"
104 #include "actions/canvasadd.h"
105 #include "actions/canvasremove.h"
107 #include "actions/editmodeset.h"
109 #include "actions/blinepointtangentmerge.h"
110 #include "actions/blinepointtangentsplit.h"
112 #include "actions/gradientset.h"
113 #include "actions/colorset.h"
115 #include "actions/groupaddlayers.h"
116 #include "actions/groupremovelayers.h"
117 #include "actions/groupremove.h"
118 #include "actions/grouprename.h"
120 #include "canvasinterface.h"
128 using namespace synfig;
129 using namespace synfigapp;
130 using namespace Action;
132 /* === P R O C E D U R E S ================================================= */
134 /* === S T A T I C S ======================================================= */
136 synfigapp::Action::Book *book_;
138 /* === M E T H O D S ======================================================= */
140 #define ADD_ACTION(x) { BookEntry &be(book()[x::name__]); \
142 be.local_name=dgettext("synfigstudio",x::local_name__); \
143 be.version=x::version__; \
145 be.priority=x::priority__; \
146 be.category=x::category__; \
147 be.factory=x::create; \
148 be.get_param_vocab=x::get_param_vocab; \
149 be.is_candidate=x::is_candidate; \
155 book_=new synfigapp::Action::Book();
157 ADD_ACTION(Action::LayerRemove);
158 ADD_ACTION(Action::LayerMove);
159 ADD_ACTION(Action::LayerRaise);
160 ADD_ACTION(Action::LayerLower);
161 ADD_ACTION(Action::LayerAdd);
162 ADD_ACTION(Action::LayerActivate);
163 ADD_ACTION(Action::LayerParamSet);
164 ADD_ACTION(Action::LayerParamConnect);
165 ADD_ACTION(Action::LayerParamDisconnect);
166 ADD_ACTION(Action::LayerEncapsulate);
167 ADD_ACTION(Action::LayerDuplicate);
168 ADD_ACTION(Action::LayerSetDesc);
170 ADD_ACTION(Action::ValueNodeConstSet);
171 ADD_ACTION(Action::ValueNodeAdd);
172 ADD_ACTION(Action::ValueNodeReplace);
173 ADD_ACTION(Action::ValueNodeLinkConnect);
174 ADD_ACTION(Action::ValueNodeLinkDisconnect);
175 ADD_ACTION(Action::ValueNodeDynamicListInsert);
176 ADD_ACTION(Action::ValueNodeDynamicListRemove);
177 ADD_ACTION(Action::ValueNodeDynamicListInsertSmart);
178 ADD_ACTION(Action::ValueNodeDynamicListRemoveSmart);
179 ADD_ACTION(Action::ValueNodeDynamicListLoop);
180 ADD_ACTION(Action::ValueNodeDynamicListUnLoop);
181 ADD_ACTION(Action::ValueNodeDynamicListRotateOrder);
182 ADD_ACTION(Action::ValueNodeRename);
183 ADD_ACTION(Action::ValueNodeRemove);
185 ADD_ACTION(Action::ValueDescSet);
186 ADD_ACTION(Action::ValueDescExport);
187 ADD_ACTION(Action::ValueDescConvert);
188 ADD_ACTION(Action::ValueDescConnect);
189 ADD_ACTION(Action::ValueDescDisconnect);
190 ADD_ACTION(Action::ValueDescLink);
191 ADD_ACTION(Action::ValueDescBLineLink);
193 ADD_ACTION(Action::WaypointAdd);
194 ADD_ACTION(Action::WaypointSet);
195 ADD_ACTION(Action::WaypointSetSmart);
196 ADD_ACTION(Action::WaypointRemove);
197 ADD_ACTION(Action::WaypointConnect);
198 ADD_ACTION(Action::WaypointDisconnect);
199 // ADD_ACTION(Action::WaypointSimpleAdd);
201 ADD_ACTION(Action::ActivepointAdd);
202 ADD_ACTION(Action::ActivepointSet);
203 ADD_ACTION(Action::ActivepointSetSmart);
204 ADD_ACTION(Action::ActivepointSetOn);
205 ADD_ACTION(Action::ActivepointSetOff);
206 ADD_ACTION(Action::ActivepointRemove);
207 // ADD_ACTION(Action::ActivepointSimpleAdd);
209 ADD_ACTION(Action::KeyframeAdd);
210 ADD_ACTION(Action::KeyframeSet);
211 ADD_ACTION(Action::KeyframeRemove);
212 ADD_ACTION(Action::KeyframeDuplicate);
213 ADD_ACTION(Action::KeyframeWaypointSet);
214 ADD_ACTION(Action::KeyframeSetDelta);
216 ADD_ACTION(Action::CanvasDescriptionSet);
217 ADD_ACTION(Action::CanvasIdSet);
218 ADD_ACTION(Action::CanvasNameSet);
219 ADD_ACTION(Action::CanvasRendDescSet);
220 ADD_ACTION(Action::CanvasAdd);
221 ADD_ACTION(Action::CanvasRemove);
223 ADD_ACTION(Action::EditModeSet);
225 ADD_ACTION(Action::BLinePointTangentMerge);
226 ADD_ACTION(Action::BLinePointTangentSplit);
228 ADD_ACTION(Action::GradientSet);
229 ADD_ACTION(Action::ColorSetFromOC);
230 ADD_ACTION(Action::ColorSetFromFC);
232 ADD_ACTION(Action::TimepointsMove);
233 ADD_ACTION(Action::TimepointsCopy);
234 ADD_ACTION(Action::TimepointsDelete);
236 ADD_ACTION(Action::GroupAddLayers);
237 ADD_ACTION(Action::GroupRemoveLayers);
238 ADD_ACTION(Action::GroupRemove);
239 ADD_ACTION(Action::GroupRename);
242 Action::Main::~Main()
249 Action::Book& Action::book() { return *book_; }
253 Action::create(const synfig::String &name)
255 if(!book().count(name))
256 return 0; //! \todo perhaps we should throw something instead?
257 return book()[name].factory();
261 Action::CandidateList
262 Action::compile_candidate_list(const ParamList& param_list, Category category)
264 Action::CandidateList ret;
266 Book::const_iterator iter;
268 //synfig::info("param_list.size()=%d",param_list.size());
270 for(iter=book().begin();iter!=book().end();++iter)
272 if((iter->second.category&category))
274 if(iter->second.is_candidate(param_list))
276 //synfig::info("Action \"%s\" is in",iter->second.name.c_str());
277 ret.push_back(iter->second);
281 //synfig::info("Action \"%s\" is not a candidate",iter->second.name.c_str());
286 //synfig::info("Action \"%s\" has unsuitable category",iter->second.name.c_str());
293 Action::CandidateList::iterator
294 Action::CandidateList::find(const synfig::String& x)
297 for(iter=begin();iter!=end();++iter)
304 Action::Base::set_param_list(const ParamList ¶m_list)
306 ParamList::const_iterator iter;
308 for(iter=param_list.begin();iter!=param_list.end();++iter)
309 set_param(iter->first,iter->second);
313 Action::Base::get_layer_descriptions(const std::list<synfig::Layer::Handle> layers, synfig::String singular_prefix, synfig::String plural_prefix)
318 if (plural_prefix.empty())
319 plural_prefix = singular_prefix;
322 return plural_prefix;
324 if (layers.size() == 1)
325 ret = singular_prefix;
332 for(std::list<synfig::Layer::Handle>::const_iterator iter=layers.begin(); iter!=layers.end(); ++iter)
339 ret += strprintf("'%s'", (*iter)->get_non_empty_description().c_str());
346 Action::Base::get_layer_descriptions(const std::list<std::pair<synfig::Layer::Handle,int> > layers, synfig::String singular_prefix, synfig::String plural_prefix)
351 if (plural_prefix.empty())
352 plural_prefix = singular_prefix;
355 return plural_prefix;
357 if (layers.size() == 1)
358 ret = singular_prefix;
365 for(std::list<std::pair<synfig::Layer::Handle,int> >::const_iterator iter=layers.begin(); iter!=layers.end(); ++iter)
372 ret += strprintf("'%s'", iter->first->get_non_empty_description().c_str());
385 ActionList::const_iterator iter;
386 for(iter=action_list_.begin();iter!=action_list_.end();++iter)
389 // synfig::info("%s:%d action: '%s'", __FILE__, __LINE__, (*iter)->get_name().c_str());
395 CanvasSpecific* canvas_specific(dynamic_cast<CanvasSpecific*>(iter->get()));
396 if(canvas_specific && canvas_specific->is_dirty())
401 if(iter!=action_list_.begin())
403 for(--iter;iter!=action_list_.begin();--iter)
412 //synfig::info("%s:%d caught exception", __FILE__, __LINE__);
413 throw Error(x.get_type(),((*iter)->get_local_name()+": "+x.get_desc()).c_str());
415 //synfig::info("%s:%d finished action: '%s'", __FILE__, __LINE__, (*iter)->get_name().c_str());
424 ActionList::const_reverse_iterator iter;
425 for(iter=const_cast<const ActionList &>(action_list_).rbegin();iter!=const_cast<const ActionList &>(action_list_).rend();++iter)
429 CanvasSpecific* canvas_specific(dynamic_cast<CanvasSpecific*>(iter->get()));
430 if(canvas_specific && canvas_specific->is_dirty())
435 if(iter!=const_cast<const ActionList &>(action_list_).rbegin())
437 for(--iter;iter!=const_cast<const ActionList &>(action_list_).rbegin();--iter)
447 Super::add_action(etl::handle<Undoable> action)
449 action_list_.push_back(action);
450 CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get());
451 if(specific_action && !get_canvas())
452 set_canvas(specific_action->get_canvas());
456 Super::add_action_front(etl::handle<Undoable> action)
458 action_list_.push_front(action);
459 CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get());
460 if(specific_action && !get_canvas())
461 set_canvas(specific_action->get_canvas());
465 Group::Group(const synfig::String &str):
479 Action::CanvasSpecific::get_param_vocab()
483 ret.push_back(ParamDesc("canvas",Param::TYPE_CANVAS)
484 .set_local_name(_("Canvas"))
485 .set_desc(_("Selected Canvas"))
488 ret.push_back(ParamDesc("canvas_interface",Param::TYPE_CANVASINTERFACE)
489 .set_local_name(_("Canvas Interface"))
490 .set_desc(_("Canvas Interface"))
499 CanvasSpecific::set_param(const synfig::String& name, const Param ¶m)
501 if(name=="canvas" && param.get_type()==Param::TYPE_CANVAS)
503 if(!param.get_canvas())
505 set_canvas(param.get_canvas());
509 if(name=="canvas_interface" && param.get_type()==Param::TYPE_CANVASINTERFACE)
511 if(!param.get_canvas_interface())
513 set_canvas_interface(param.get_canvas_interface());
515 set_canvas(get_canvas_interface()->get_canvas());
519 if(name=="edit_mode" && param.get_type()==Param::TYPE_EDITMODE)
521 set_edit_mode(param.get_edit_mode());
530 CanvasSpecific::is_ready()const
538 CanvasSpecific::get_edit_mode()const
540 if(mode_!=MODE_UNDEFINED)
543 if(get_canvas_interface())
544 return get_canvas_interface()->get_mode();