1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodereplace.cpp
3 ** \brief Template File
5 ** $Id: valuenodereplace.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 "valuenodereplace.h"
32 #include <synfigapp/canvasinterface.h>
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
42 /* === M A C R O S ========================================================= */
44 ACTION_INIT(Action::ValueNodeReplace);
45 ACTION_SET_NAME(Action::ValueNodeReplace,"value_node_replace");
46 ACTION_SET_LOCAL_NAME(Action::ValueNodeReplace,"Replace ValueNode");
47 ACTION_SET_TASK(Action::ValueNodeReplace,"replace");
48 ACTION_SET_CATEGORY(Action::ValueNodeReplace,Action::CATEGORY_VALUENODE|Action::CATEGORY_DRAG);
49 ACTION_SET_PRIORITY(Action::ValueNodeReplace,0);
50 ACTION_SET_VERSION(Action::ValueNodeReplace,"0.0");
51 ACTION_SET_CVS_ID(Action::ValueNodeReplace,"$Id: valuenodereplace.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 void swap_guid(const ValueNode::Handle& a,const ValueNode::Handle& b)
59 GUID old_a(a->get_guid());
62 GUID old_b(b->get_guid());
69 /* === M E T H O D S ======================================================= */
71 Action::ValueNodeReplace::ValueNodeReplace():
77 Action::ValueNodeReplace::get_param_vocab()
79 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
81 ret.push_back(ParamDesc("dest",Param::TYPE_VALUENODE)
82 .set_local_name(_("Destination ValueNode"))
83 .set_desc(_("ValueNode to replaced"))
86 ret.push_back(ParamDesc("src",Param::TYPE_VALUENODE)
87 .set_local_name(_("Source ValueNode"))
88 .set_desc(_("ValueNode that will replace the destination"))
95 Action::ValueNodeReplace::is_canidate(const ParamList &x)
97 return canidate_check(get_param_vocab(),x);
101 Action::ValueNodeReplace::set_param(const synfig::String& name, const Action::Param ¶m)
103 if(name=="dest" && param.get_type()==Param::TYPE_VALUENODE)
105 dest_value_node=param.get_value_node();
110 if(name=="src" && param.get_type()==Param::TYPE_VALUENODE)
112 src_value_node=param.get_value_node();
117 return Action::CanvasSpecific::set_param(name,param);
121 Action::ValueNodeReplace::is_ready()const
123 if(!dest_value_node || !src_value_node)
125 return Action::CanvasSpecific::is_ready();
129 Action::ValueNodeReplace::perform()
133 if(dest_value_node == src_value_node)
134 throw Error(_("Attempted to replace valuenode with itself"));
136 if(dest_value_node->get_type() != src_value_node->get_type())
137 throw Error(_("You cannot replace ValueNodes with different types!"));
141 if(!src_value_node->is_exported())
143 src_value_node->set_id(dest_value_node->get_id());
144 src_value_node->set_parent_canvas(dest_value_node->get_parent_canvas());
146 ValueNode::RHandle value_node(src_value_node);
148 if(!value_node.runique() && value_node.rcount()>1)
149 is_undoable=false; // !!!
152 is_undoable=false; // !!!
155 synfig::warning("ValueNodeReplace: Circumstances make undoing this action impossible at the current time. :(");
157 ValueNode::RHandle value_node(dest_value_node);
159 if(value_node.runique() || value_node.rcount()<=1)
160 throw Error(_("Nothing to replace."));
164 replacements=value_node->replace(src_value_node);
165 assert(replacements);
167 throw Error(_("Action Failure. This is a bug. Please report it."));
168 swap_guid(dest_value_node,src_value_node);
170 //src_value_node->parent_set.swap(dest_value_node->parent_set);
172 // Signal that a layer has been inserted
173 if(get_canvas_interface())
175 get_canvas_interface()->signal_value_node_replaced()(dest_value_node,src_value_node);
177 else synfig::warning("CanvasInterface not set on action");
182 Action::ValueNodeReplace::undo()
185 throw Error(_("This action cannot be undone under these circumstances."));
189 if(dest_value_node == src_value_node)
190 throw Error(_("Attempted to replace valuenode with itself"));
192 if(dest_value_node->get_type() != src_value_node->get_type())
193 throw Error(_("You cannot replace ValueNodes with different types!"));
195 ValueNode::RHandle value_node(src_value_node);
197 if(value_node.runique() || value_node.rcount()<=1)
198 throw Error(_("Nothing to replace."));
202 replacements=value_node->replace(dest_value_node);
203 assert(replacements);
205 throw Error(_("Action Failure. This is a bug. Please report it."));
206 swap_guid(dest_value_node,src_value_node);
208 //src_value_node->parent_set.swap(dest_value_node->parent_set);
210 synfig::info(get_name()+_(": (Undo) ")+strprintf("Replaced %d ValueNode instances",replacements));
212 src_value_node->set_id(String());
213 src_value_node->set_parent_canvas(0);
215 // Signal that a layer has been inserted
216 if(get_canvas_interface())
218 get_canvas_interface()->signal_value_node_replaced()(src_value_node,dest_value_node);
220 else synfig::warning("CanvasInterface not set on action");