1 /* === S Y N F I G ========================================================= */
2 /*! \file layerduplicate.cpp
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 ======================================================= */
33 #include "layerduplicate.h"
35 #include <synfig/context.h>
36 #include <synfigapp/canvasinterface.h>
38 #include <synfigapp/general.h>
44 using namespace synfig;
45 using namespace synfigapp;
46 using namespace Action;
48 /* === M A C R O S ========================================================= */
50 ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerDuplicate);
51 ACTION_SET_NAME(Action::LayerDuplicate,"layer_duplicate");
52 ACTION_SET_LOCAL_NAME(Action::LayerDuplicate,N_("Duplicate Layer"));
53 ACTION_SET_TASK(Action::LayerDuplicate,"duplicate");
54 ACTION_SET_CATEGORY(Action::LayerDuplicate,Action::CATEGORY_LAYER);
55 ACTION_SET_PRIORITY(Action::LayerDuplicate,0);
56 ACTION_SET_VERSION(Action::LayerDuplicate,"0.0");
57 ACTION_SET_CVS_ID(Action::LayerDuplicate,"$Id$");
59 /* === G L O B A L S ======================================================= */
61 /* === P R O C E D U R E S ================================================= */
63 /* === M E T H O D S ======================================================= */
65 Action::LayerDuplicate::LayerDuplicate()
70 Action::LayerDuplicate::get_local_name()const
72 return get_layer_descriptions(layers, _("Duplicate Layer"), _("Duplicate Layers"));
76 Action::LayerDuplicate::get_param_vocab()
78 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
81 .set_local_name(_("Layer"))
82 .set_desc(_("Layer to be duplicated"))
83 .set_supports_multiple()
90 Action::LayerDuplicate::is_candidate(const ParamList &x)
92 return candidate_check(get_param_vocab(),x);
96 Action::LayerDuplicate::set_param(const synfig::String& name, const Action::Param ¶m)
98 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
100 layers.push_back(param.get_layer());
105 return Action::CanvasSpecific::set_param(name,param);
109 Action::LayerDuplicate::is_ready()const
113 return Action::CanvasSpecific::is_ready();
117 Action::LayerDuplicate::prepare()
122 std::list<synfig::Layer::Handle>::const_iterator iter;
124 for(iter=layers.begin();iter!=layers.end();++iter)
126 Layer::Handle layer(*iter);
128 Canvas::Handle subcanvas(layer->get_canvas());
130 // Find the iterator for the layer
131 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
133 // If we couldn't find the layer in the canvas, then bail
135 throw Error(_("This layer doesn't exist anymore."));
137 // If the subcanvas isn't the same as the canvas,
138 // then it had better be an inline canvas. If not,
140 if(get_canvas()!=subcanvas && !subcanvas->is_inline())
141 throw Error(_("This layer doesn't belong to this canvas anymore"));
143 Layer::Handle new_layer(layer->clone(guid));
146 Action::Handle action(Action::create("layer_move"));
148 action->set_param("canvas",subcanvas);
149 action->set_param("canvas_interface",get_canvas_interface());
150 action->set_param("layer",new_layer);
151 action->set_param("new_index",layers.front()->get_depth());
153 add_action_front(action);
156 Action::Handle action(Action::create("layer_add"));
158 action->set_param("canvas",subcanvas);
159 action->set_param("canvas_interface",get_canvas_interface());
160 action->set_param("new",new_layer);
162 add_action_front(action);
165 // automatically export the Index parameter of Duplicate layers when duplicating
167 export_dup_nodes(new_layer, subcanvas, index);
172 Action::LayerDuplicate::export_dup_nodes(synfig::Layer::Handle layer, Canvas::Handle canvas, int &index)
174 // automatically export the Index parameter of Duplicate layers when duplicating
175 if (layer->get_name() == "duplicate")
178 String name = strprintf(_("Index %d"), index++);
181 canvas->find_value_node(name);
183 catch (Exception::IDNotFound x)
185 Action::Handle action(Action::create("value_node_add"));
187 action->set_param("canvas",canvas);
188 action->set_param("canvas_interface",get_canvas_interface());
189 action->set_param("new",layer->dynamic_param_list().find("index")->second);
190 action->set_param("name",name);
192 add_action_front(action);
199 Layer::ParamList param_list(layer->get_param_list());
200 for (Layer::ParamList::const_iterator iter(param_list.begin())
201 ; iter != param_list.end()
203 if (layer->dynamic_param_list().count(iter->first)==0 && iter->second.get_type()==ValueBase::TYPE_CANVAS)
205 Canvas::Handle subcanvas(iter->second.get(Canvas::Handle()));
206 if (subcanvas && subcanvas->is_inline())
207 for (Context iter = subcanvas->get_context(); iter != subcanvas->end(); iter++)
208 export_dup_nodes(*iter, canvas, index);
211 for (Layer::DynamicParamList::const_iterator iter(layer->dynamic_param_list().begin())
212 ; iter != layer->dynamic_param_list().end()
214 if (iter->second->get_type()==ValueBase::TYPE_CANVAS)
216 Canvas::Handle canvas((*iter->second)(0).get(Canvas::Handle()));
217 if (canvas->is_inline())
218 //! \todo do we need to implement this? and if so, shouldn't we check all canvases, not just the one at t=0s?
219 warning("%s:%d not yet implemented - do we need to export duplicate valuenodes in dynamic canvas parameters?", __FILE__, __LINE__);