1 /* === S Y N F I G ========================================================= */
2 /*! \file layerraise.cpp
3 ** \brief Template File
5 ** $Id: layerencapsulate.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "layerencapsulate.h"
33 #include "layerremove.h"
34 #include <synfigapp/canvasinterface.h>
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
44 /* === M A C R O S ========================================================= */
46 ACTION_INIT(Action::LayerEncapsulate);
47 ACTION_SET_NAME(Action::LayerEncapsulate,"layer_encapsulate");
48 ACTION_SET_LOCAL_NAME(Action::LayerEncapsulate,"Encapsulate");
49 ACTION_SET_TASK(Action::LayerEncapsulate,"encapsulate");
50 ACTION_SET_CATEGORY(Action::LayerEncapsulate,Action::CATEGORY_LAYER);
51 ACTION_SET_PRIORITY(Action::LayerEncapsulate,0);
52 ACTION_SET_VERSION(Action::LayerEncapsulate,"0.0");
53 ACTION_SET_CVS_ID(Action::LayerEncapsulate,"$Id: layerencapsulate.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Action::LayerEncapsulate::LayerEncapsulate()
66 Action::LayerEncapsulate::get_param_vocab()
68 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
71 .set_local_name(_("Layer"))
72 .set_desc(_("Layer to be encapsulated"))
73 .set_supports_multiple()
80 Action::LayerEncapsulate::is_canidate(const ParamList &x)
82 return canidate_check(get_param_vocab(),x);
86 Action::LayerEncapsulate::set_param(const synfig::String& name, const Action::Param ¶m)
88 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
90 layers.push_back(param.get_layer());
95 return Action::CanvasSpecific::set_param(name,param);
99 Action::LayerEncapsulate::is_ready()const
103 return Action::CanvasSpecific::is_ready();
107 Action::LayerEncapsulate::lowest_depth()const
109 std::list<synfig::Layer::Handle>::const_iterator iter;
110 int lowest_depth(0x7fffffff);
112 for(iter=layers.begin();iter!=layers.end();++iter)
114 int depth((*iter)->get_depth());
115 if(depth<lowest_depth)
118 if(lowest_depth==0x7fffffff)
124 Action::LayerEncapsulate::prepare()
131 throw Error("No layers to encapsulate");
133 // First create the new canvas and layer
135 child_canvas=Canvas::create_inline(get_canvas());
137 Layer::Handle new_layer(Layer::create("PasteCanvas"));
139 new_layer->set_param("canvas",child_canvas);
141 int target_depth(lowest_depth());
145 Action::Handle action(LayerAdd::create());
147 action->set_param("canvas",get_canvas());
148 action->set_param("canvas_interface",get_canvas_interface());
149 action->set_param("new",new_layer);
156 Action::Handle action(Action::create("layer_move"));
160 action->set_param("canvas",get_canvas());
161 action->set_param("canvas_interface",get_canvas_interface());
162 action->set_param("layer",new_layer);
163 action->set_param("new_index",target_depth);
168 std::list<synfig::Layer::Handle>::reverse_iterator iter;
170 for(iter=layers.rbegin();iter!=layers.rend();++iter)
172 Layer::Handle layer(*iter);
174 Canvas::Handle subcanvas(layer->get_canvas());
176 // Find the iterator for the layer
177 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
179 // If we couldn't find the layer in the canvas, then bail
181 throw Error(_("This layer doesn't exist anymore."));
184 throw Error(_("This layer doesn't have a parent canvas"));
186 // If the subcanvas isn't the same as the canvas,
187 // then it had better be an inline canvas. If not,
189 if(get_canvas()!=subcanvas && !subcanvas->is_inline())
190 throw Error(_("This layer doesn't belong to this canvas anymore"));
192 if(get_canvas()!=subcanvas)
193 throw Error(_("get_canvas()!=subcanvas"));
195 // Remove the layer from the old canvas
197 Action::Handle action(LayerRemove::create());
199 action->set_param("canvas",subcanvas);
200 action->set_param("canvas_interface",get_canvas_interface());
201 action->set_param("layer",layer);
205 // Add the layer to the new canvas
207 Action::Handle action(LayerAdd::create());
209 action->set_param("canvas",child_canvas);
210 action->set_param("canvas_interface",get_canvas_interface());
211 action->set_param("new",layer);