Blame synfig-studio/src/synfigapp/actions/vectorization.cpp

Ankit Kumar Dwivedi 5c7d6a
/* === S Y N F I G ========================================================= */
Ankit Kumar Dwivedi 5c7d6a
/*!	\file vectorization.cpp
Ankit Kumar Dwivedi 5c7d6a
**	
Ankit Kumar Dwivedi 5c7d6a
**
Ankit Kumar Dwivedi 5c7d6a
**	$Id$
Ankit Kumar Dwivedi 5c7d6a
**
Ankit Kumar Dwivedi 5c7d6a
**	\legal
Ankit Kumar Dwivedi 5c7d6a
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Ankit Kumar Dwivedi 5c7d6a
**  Copyright (c) 2008 Chris Moore
Ankit Kumar Dwivedi 5c7d6a
**
Ankit Kumar Dwivedi 5c7d6a
**	This package is free software; you can redistribute it and/or
Ankit Kumar Dwivedi 5c7d6a
**	modify it under the terms of the GNU General Public License as
Ankit Kumar Dwivedi 5c7d6a
**	published by the Free Software Foundation; either version 2 of
Ankit Kumar Dwivedi 5c7d6a
**	the License, or (at your option) any later version.
Ankit Kumar Dwivedi 5c7d6a
**
Ankit Kumar Dwivedi 5c7d6a
**	This package is distributed in the hope that it will be useful,
Ankit Kumar Dwivedi 5c7d6a
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Ankit Kumar Dwivedi 5c7d6a
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Ankit Kumar Dwivedi 5c7d6a
**	General Public License for more details.
Ankit Kumar Dwivedi 5c7d6a
**	\endlegal
Ankit Kumar Dwivedi 5c7d6a
*/
Ankit Kumar Dwivedi 5c7d6a
/* ========================================================================= */
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
/* === H E A D E R S ======================================================= */
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
#ifdef USING_PCH
Ankit Kumar Dwivedi 5c7d6a
#	include "pch.h"
Ankit Kumar Dwivedi 5c7d6a
#else
Ankit Kumar Dwivedi 5c7d6a
#ifdef HAVE_CONFIG_H
Ankit Kumar Dwivedi 5c7d6a
#	include <config.h></config.h>
Ankit Kumar Dwivedi 5c7d6a
#endif
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
#include <synfig general.h=""></synfig>
Ankit Kumar Dwivedi 7799cf
#include <synfig layer.h=""></synfig>
Ankit Kumar Dwivedi 7799cf
#include <etl handle=""></etl>
Ankit Kumar Dwivedi 5c7d6a
#include "vectorization.h"
Ankit Kumar Dwivedi 5c7d6a
#include <synfigapp canvasinterface.h=""></synfigapp>
Ankit Kumar Dwivedi 5c7d6a
#include <synfigapp main.h=""></synfigapp>
Ankit Kumar Dwivedi 5c7d6a
#include <synfigapp localization.h=""></synfigapp>
Ankit Kumar Dwivedi 7d9190
#include <synfig layer_bitmap.h="" layers=""></synfig>
Ankit Kumar Dwivedi 90515f
#include <synfig layer_pastecanvas.h="" layers=""></synfig>
Ankit Kumar Dwivedi 90515f
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
#endif
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
using namespace std;
Ankit Kumar Dwivedi 5c7d6a
using namespace etl;
Ankit Kumar Dwivedi 5c7d6a
using namespace synfig;
Ankit Kumar Dwivedi 5c7d6a
using namespace synfigapp;
Ankit Kumar Dwivedi 5c7d6a
using namespace Action;
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
/* === M A C R O S ========================================================= */
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 896d3a
ACTION_INIT(Action::Vectorization);
Ankit Kumar Dwivedi 896d3a
ACTION_SET_NAME(Action::Vectorization,"Vectorization");
Ankit Kumar Dwivedi 896d3a
ACTION_SET_LOCAL_NAME(Action::Vectorization,N_("Vectorize the Image"));
Ankit Kumar Dwivedi 896d3a
ACTION_SET_TASK(Action::Vectorization,"vectorize");
Ankit Kumar Dwivedi b2346e
ACTION_SET_CATEGORY(Action::Vectorization,Action::CATEGORY_LAYER);
Ankit Kumar Dwivedi 896d3a
ACTION_SET_PRIORITY(Action::Vectorization,0);
Ankit Kumar Dwivedi 896d3a
ACTION_SET_VERSION(Action::Vectorization,"0.0");
Ankit Kumar Dwivedi 896d3a
ACTION_SET_CVS_ID(Action::Vectorization,"$Id$");
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
/* === G L O B A L S ======================================================= */
Ankit Kumar Dwivedi 5c7d6a
/* === P R O C E D U R E S ================================================= */
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 5c7d6a
/* === M E T H O D S ======================================================= */
Ankit Kumar Dwivedi 7d9190
Vectorization::Vectorization()
Ankit Kumar Dwivedi 7b3701
{
Ankit Kumar Dwivedi 7d9190
    isOutline = false;
Ankit Kumar Dwivedi 2c3f10
    new_layer = synfig::Layer::create("group");
Ankit Kumar Dwivedi 2c3f10
Ankit Kumar Dwivedi 7d9190
}
Ankit Kumar Dwivedi 7d9190
Ankit Kumar Dwivedi 8c166e
// this function return centerline configuration after setting the config using params
Ankit Kumar Dwivedi 7d9190
studio::CenterlineConfiguration Vectorization::getCenterlineConfiguration( ) const 
Ankit Kumar Dwivedi 7d9190
{
Ankit Kumar Dwivedi 7d9190
  studio::CenterlineConfiguration conf;
Ankit Kumar Dwivedi 7b3701
Ankit Kumar Dwivedi 7b3701
  conf.m_outline      = false;
Ankit Kumar Dwivedi 7b3701
  conf.m_threshold    = threshold;
Ankit Kumar Dwivedi 7b3701
  conf.m_penalty      = penalty;  // adjustment_accuracy in [1,10]
Ankit Kumar Dwivedi 7b3701
  conf.m_despeckling  = despeckling;
Ankit Kumar Dwivedi 7b3701
  conf.m_maxThickness = maxthickness;
Ankit Kumar Dwivedi 7b3701
  conf.m_thicknessRatio = 1.0;
Ankit Kumar Dwivedi 7b3701
  conf.m_leaveUnpainted = pparea;
Ankit Kumar Dwivedi 7b3701
  conf.m_makeFrame      = addborder;
Ankit Kumar Dwivedi 7b3701
  conf.m_naaSource      = false;//currently not in use
Ankit Kumar Dwivedi 7b3701
Ankit Kumar Dwivedi 7b3701
  return conf;
Ankit Kumar Dwivedi 7b3701
}
Ankit Kumar Dwivedi 7b3701
Ankit Kumar Dwivedi 8c166e
// this function return outline configuration after setting the config using params
Ankit Kumar Dwivedi 7d9190
studio::NewOutlineConfiguration Vectorization::getOutlineConfiguration() const 
Ankit Kumar Dwivedi 7d9190
{
Ankit Kumar Dwivedi 7d9190
  studio::NewOutlineConfiguration conf;
Ankit Kumar Dwivedi 7b3701
Ankit Kumar Dwivedi 7b3701
   conf.m_outline          = true;
Ankit Kumar Dwivedi 7b3701
//   conf.m_despeckling      = m_oDespeckling;
Ankit Kumar Dwivedi 7b3701
//   conf.m_adherenceTol     = m_oAdherence * 0.01;
Ankit Kumar Dwivedi 7b3701
//   conf.m_angleTol         = m_oAngle / 180.0;
Ankit Kumar Dwivedi 7b3701
//   conf.m_relativeTol      = m_oRelative * 0.01;
Ankit Kumar Dwivedi 7b3701
//   conf.m_mergeTol         = 5.0 - m_oAccuracy * 0.5;
Ankit Kumar Dwivedi 7b3701
//   conf.m_leaveUnpainted   = !m_oPaintFill;
Ankit Kumar Dwivedi 7b3701
//   conf.m_maxColors        = m_oMaxColors;
Ankit Kumar Dwivedi 7b3701
//   conf.m_transparentColor = m_oTransparentColor;
Ankit Kumar Dwivedi 7b3701
//   conf.m_toneTol          = m_oToneThreshold;
Ankit Kumar Dwivedi 7b3701
Ankit Kumar Dwivedi 7b3701
  return conf;
Ankit Kumar Dwivedi 7b3701
}
Ankit Kumar Dwivedi 5c7d6a
Ankit Kumar Dwivedi 7d9190
Action::ParamVocab
Ankit Kumar Dwivedi 7d9190
Action::Vectorization::get_param_vocab()
Ankit Kumar Dwivedi 7d9190
{
Ankit Kumar Dwivedi 7d9190
	ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
Ankit Kumar Dwivedi 7d9190
Ankit Kumar Dwivedi 7d9190
	ret.push_back(ParamDesc("image",Param::TYPE_LAYER)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Image Layer"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
Ankit Kumar Dwivedi 7d9190
	ret.push_back(ParamDesc("mode",Param::TYPE_STRING)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Vectorization mode"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("Mode for Vectorization"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
    ret.push_back(ParamDesc("threshold", Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Threshold Value"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("Mode for Vectorization"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
    ret.push_back(ParamDesc("penalty", Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Penalty"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("Penalty based on accuracy"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
    ret.push_back(ParamDesc("despeckling", Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Despeckling value"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("Despeckling Value for process"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
    ret.push_back(ParamDesc("maxthickness", Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Max thickness"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("Max thickness of outline"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
    ret.push_back(ParamDesc("pparea", Param::TYPE_BOOL)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Preserve painted area"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("To preserve painted area"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi b2346e
    ret.push_back(ParamDesc("addborder", Param::TYPE_BOOL)
Ankit Kumar Dwivedi 7d9190
		.set_local_name(_("Add border"))
Ankit Kumar Dwivedi 7d9190
		.set_desc(_("Add border in final outlines"))
Ankit Kumar Dwivedi 7d9190
	);
Ankit Kumar Dwivedi 7d9190
    
Ankit Kumar Dwivedi 7d9190
    return ret;
Ankit Kumar Dwivedi 7d9190
}
Ankit Kumar Dwivedi 7d9190
Ankit Kumar Dwivedi 7d9190
bool
Ankit Kumar Dwivedi 7d9190
Action::Vectorization::is_candidate(const ParamList &x)
Ankit Kumar Dwivedi 7d9190
{
Ankit Kumar Dwivedi 7d9190
	return (candidate_check(get_param_vocab(),x) &&
Ankit Kumar Dwivedi 7d9190
			synfig::Layer_Bitmap::Handle::cast_dynamic(x.find("image")->second.get_value_node()));
Ankit Kumar Dwivedi 7d9190
}
Ankit Kumar Dwivedi 7d9190
Ankit Kumar Dwivedi 896d3a
bool
Ankit Kumar Dwivedi f49dbb
Action::Vectorization::is_ready() const
Ankit Kumar Dwivedi f49dbb
{
Ankit Kumar Dwivedi 316c5b
    return get_param_vocab().size() >= 8 && 
Ankit Kumar Dwivedi 316c5b
        synfig::Layer_Bitmap::Handle::cast_dynamic(layer) && 
Ankit Kumar Dwivedi 316c5b
        Action::CanvasSpecific::is_ready();
Ankit Kumar Dwivedi 316c5b
 }
Ankit Kumar Dwivedi f49dbb
Ankit Kumar Dwivedi f49dbb
bool
Ankit Kumar Dwivedi 896d3a
Action::Vectorization::set_param(const synfig::String& name, const Action::Param ¶m)
Ankit Kumar Dwivedi 896d3a
{
Ankit Kumar Dwivedi 896d3a
	if(name=="image" && param.get_type()==Param::TYPE_LAYER)
Ankit Kumar Dwivedi 896d3a
	{
Ankit Kumar Dwivedi 896d3a
        layer = param.get_layer();
Ankit Kumar Dwivedi 896d3a
		return true;	
Ankit Kumar Dwivedi 896d3a
    }
Ankit Kumar Dwivedi b2346e
    if(name=="mode" && param.get_type() == Param::TYPE_STRING)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        v_mode = param.get_string();
Ankit Kumar Dwivedi 7a49bf
        if(v_mode=="outline"||v_mode == "Outline")
Ankit Kumar Dwivedi 7799cf
        isOutline=true;
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi b2346e
    if(name=="threshold" && param.get_type() == Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        threshold = param.get_integer();
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi b2346e
    if(name=="penalty" && param.get_type() == Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        penalty = param.get_integer();
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi b2346e
    if(name=="despeckling" && param.get_type() == Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        despeckling = param.get_integer();
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi b2346e
    if(name=="maxthickness" && param.get_type() == Param::TYPE_INTEGER)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        maxthickness = param.get_integer();
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi b2346e
    if(name=="pparea" && param.get_type() == Param::TYPE_BOOL)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        pparea = param.get_bool();
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi b2346e
    if(name=="addborder" && param.get_type() == Param::TYPE_BOOL)
Ankit Kumar Dwivedi 7b3701
    {
Ankit Kumar Dwivedi 7b3701
        addborder = param.get_bool();
Ankit Kumar Dwivedi 7b3701
        return true;
Ankit Kumar Dwivedi 7b3701
    }
Ankit Kumar Dwivedi 90515f
    if(name=="reference_layer" && param.get_type() == Param::TYPE_LAYER)
Ankit Kumar Dwivedi 90515f
    {
Ankit Kumar Dwivedi 90515f
        reference_layer = param.get_layer();
Ankit Kumar Dwivedi 90515f
        return true;
Ankit Kumar Dwivedi 90515f
    }
Ankit Kumar Dwivedi 896d3a
    return Action::CanvasSpecific::set_param(name,param);
Ankit Kumar Dwivedi 896d3a
}
Ankit Kumar Dwivedi 7b3701
Ankit Kumar Dwivedi 7b3701
void
Ankit Kumar Dwivedi 7b3701
Action::Vectorization::perform()
Ankit Kumar Dwivedi 7b3701
{
Ankit Kumar Dwivedi 7a49bf
    studio::CenterlineConfiguration m_cConf;
Ankit Kumar Dwivedi 7a49bf
  	studio::NewOutlineConfiguration m_oConf;
Ankit Kumar Dwivedi 8c166e
Ankit Kumar Dwivedi 8c166e
    // set the configuration to pass to vectorizer
Ankit Kumar Dwivedi 7a49bf
	studio::VectorizerConfiguration &configuration = isOutline ? static_cast<studio::vectorizerconfiguration &="">(m_oConf)</studio::vectorizerconfiguration>
Ankit Kumar Dwivedi 7a49bf
        									  : static_cast<studio::vectorizerconfiguration &="">(m_cConf);</studio::vectorizerconfiguration>
Ankit Kumar Dwivedi 7a49bf
Ankit Kumar Dwivedi 8c166e
    // set config to centerline or outline as per v_mode
Ankit Kumar Dwivedi 7a49bf
    if (v_mode=="outline"||v_mode == "Outline")
Ankit Kumar Dwivedi 7a49bf
        m_oConf = getOutlineConfiguration();
Ankit Kumar Dwivedi 7a49bf
    else if(v_mode=="centerline"||v_mode=="Centerline")
Ankit Kumar Dwivedi 7a49bf
        m_cConf = getCenterlineConfiguration();
Ankit Kumar Dwivedi 7a49bf
Ankit Kumar Dwivedi 7a49bf
    studio::VectorizerCore vCore;
Ankit Kumar Dwivedi 7a49bf
    synfig::Layer_Bitmap::Handle image_layer = synfig::Layer_Bitmap::Handle::cast_dynamic(layer);
Ankit Kumar Dwivedi 8c166e
ankit-kumar-dwivedi 2e10e1
    // result of vectorization (vector of outline layers)
ankit-kumar-dwivedi 2e10e1
    Gamma gamma = layer->get_canvas()->get_root()->rend_desc().get_gamma();
a4bbdd
	gamma.invert();
a4bbdd
ankit-kumar-dwivedi 2e10e1
    const etl::handle<uiinterface> ui_interface = get_canvas_interface()->get_ui_interface();</uiinterface>
ankit-kumar-dwivedi 2e10e1
    std::vector< etl::handle<synfig::layer> > Result = vCore.vectorize(image_layer,ui_interface, configuration, gamma);</synfig::layer>
Ankit Kumar Dwivedi 7a49bf
Ankit Kumar Dwivedi 7a49bf
    synfig::Canvas::Handle child_canvas;
Ankit Kumar Dwivedi 7a49bf
    child_canvas=synfig::Canvas::create_inline(layer->get_canvas());
Ankit Kumar Dwivedi 7a49bf
    new_layer->set_description("Vectorized "+layer->get_description());
Ankit Kumar Dwivedi 7a49bf
	new_layer->set_param("canvas",child_canvas);
Ankit Kumar Dwivedi 8c166e
    int move_depth = 0;
Ankit Kumar Dwivedi 8c166e
Ankit Kumar Dwivedi 8c166e
    // if the vectorizer option was selected for switch group
Ankit Kumar Dwivedi 512125
    if(etl::handle<synfig::layer_pastecanvas> paste = etl::handle<synfig::layer_pastecanvas>::cast_dynamic(reference_layer))</synfig::layer_pastecanvas></synfig::layer_pastecanvas>
Ankit Kumar Dwivedi 512125
    {
Ankit Kumar Dwivedi 8c166e
        // apply the transformation from switch group to result group
Ankit Kumar Dwivedi 512125
        new_layer->set_param("transformation",paste->get_param("transformation"));
Ankit Kumar Dwivedi 8c166e
        auto iter = std::find(get_canvas()->begin(), get_canvas()->end(), reference_layer);
Ankit Kumar Dwivedi 8c166e
        get_canvas()->insert(iter,new_layer);
Ankit Kumar Dwivedi 8c166e
        // how much layer is moved if there are layer above it in the layer panel
Ankit Kumar Dwivedi 8c166e
        move_depth = std::distance(get_canvas()->begin(), iter);
Ankit Kumar Dwivedi 8c166e
        
Ankit Kumar Dwivedi 512125
    }
Ankit Kumar Dwivedi 949420
    //synfig(17889) [11:06:00  IST] error: LayerTreeStore::on_layer_inserted():Unable to achieve desired depth, forced to rebuild...
Ankit Kumar Dwivedi 949420
Ankit Kumar Dwivedi 512125
    else
Ankit Kumar Dwivedi 512125
    {
Ankit Kumar Dwivedi 8c166e
        auto iter = std::find(get_canvas()->begin(), get_canvas()->end(), layer);
Ankit Kumar Dwivedi 8c166e
        get_canvas()->insert(iter,new_layer);
Ankit Kumar Dwivedi 8c166e
        move_depth = std::distance(get_canvas()->begin(), iter);
Ankit Kumar Dwivedi 512125
    }
Ankit Kumar Dwivedi e1f431
    new_layer->set_canvas(get_canvas());
Ankit Kumar Dwivedi 7a49bf
    for(int i=0;i < Result.size();i++)
Ankit Kumar Dwivedi 7a49bf
    {
Ankit Kumar Dwivedi 7a49bf
      Result[i]->set_canvas(child_canvas);
Ankit Kumar Dwivedi 7a49bf
      child_canvas->push_front(Result[i]);
Ankit Kumar Dwivedi 7a49bf
    }
Ankit Kumar Dwivedi 7a49bf
    if(get_canvas_interface()) 
Ankit Kumar Dwivedi 7a49bf
    { 
Ankit Kumar Dwivedi 7a49bf
 	    get_canvas_interface()->signal_layer_inserted()(new_layer,0); 
Ankit Kumar Dwivedi 949420
        get_canvas_interface()->signal_layer_moved()(new_layer,move_depth-1,get_canvas());
Ankit Kumar Dwivedi 7a49bf
    } 
ankit-kumar-dwivedi bf4d41
    //ui_interface->amount_complete(2,1);//just to hide the progress bar
Ankit Kumar Dwivedi 7b3701
}
Ankit Kumar Dwivedi f49dbb
Ankit Kumar Dwivedi f49dbb
void
Ankit Kumar Dwivedi f49dbb
Action::Vectorization::undo()
Ankit Kumar Dwivedi f49dbb
{
Ankit Kumar Dwivedi 2c3f10
    // Find the iterator for the layer
Ankit Kumar Dwivedi 2c3f10
	Canvas::iterator iter=find(get_canvas()->begin(),get_canvas()->end(),new_layer);
Ankit Kumar Dwivedi 2c3f10
Ankit Kumar Dwivedi 2c3f10
	if(*iter!=new_layer)
Ankit Kumar Dwivedi 2c3f10
		throw Error(_("This layer doesn't exist anymore."));
Ankit Kumar Dwivedi 2c3f10
Ankit Kumar Dwivedi 2c3f10
	// Remove the layer from the canvas
Ankit Kumar Dwivedi 2c3f10
	get_canvas()->erase(iter);
Ankit Kumar Dwivedi 2c3f10
Ankit Kumar Dwivedi 2c3f10
	// Signal that a layer has been inserted
Ankit Kumar Dwivedi 2c3f10
	if(get_canvas_interface())
Ankit Kumar Dwivedi 2c3f10
	{
Ankit Kumar Dwivedi 2c3f10
		get_canvas_interface()->signal_layer_removed()(new_layer);
Ankit Kumar Dwivedi 2c3f10
	}
Ankit Kumar Dwivedi 2c3f10
	else synfig::warning("CanvasInterface not set on action");
Ankit Kumar Dwivedi f49dbb
Ankit Kumar Dwivedi f49dbb
}