1 /* === S Y N F I G ========================================================= */
2 /*! \file valuedescdisconnect.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 "layerparamdisconnect.h"
34 #include "valuenodelinkdisconnect.h"
35 #include "valuenodereplace.h"
37 #include "valuedescdisconnect.h"
38 #include <synfigapp/canvasinterface.h>
39 #include <synfig/valuenode_const.h>
40 #include <synfig/valuenode_duplicate.h>
42 #include <synfigapp/general.h>
48 using namespace synfig;
49 using namespace synfigapp;
50 using namespace Action;
52 /* === M A C R O S ========================================================= */
54 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescDisconnect);
55 ACTION_SET_NAME(Action::ValueDescDisconnect,"value_desc_disconnect");
56 ACTION_SET_LOCAL_NAME(Action::ValueDescDisconnect,N_("Disconnect"));
57 ACTION_SET_TASK(Action::ValueDescDisconnect,"disconnect");
58 ACTION_SET_CATEGORY(Action::ValueDescDisconnect,Action::CATEGORY_VALUEDESC);
59 ACTION_SET_PRIORITY(Action::ValueDescDisconnect,-100);
60 ACTION_SET_VERSION(Action::ValueDescDisconnect,"0.0");
61 ACTION_SET_CVS_ID(Action::ValueDescDisconnect,"$Id$");
63 /* === G L O B A L S ======================================================= */
65 /* === P R O C E D U R E S ================================================= */
67 /* === M E T H O D S ======================================================= */
69 Action::ValueDescDisconnect::ValueDescDisconnect():
75 Action::ValueDescDisconnect::get_local_name()const
77 // TRANSLATORS: This is used in the History dialog when a ValueNode is disconnected.
78 return strprintf(_("Disconnect %s"),
80 ? value_desc.get_description().c_str()
85 Action::ValueDescDisconnect::get_param_vocab()
87 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
89 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
90 .set_local_name(_("ValueDesc"))
93 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
94 .set_local_name(_("Time"))
102 Action::ValueDescDisconnect::is_candidate(const ParamList &x)
104 if (!candidate_check(get_param_vocab(),x))
107 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
109 // don't allow the Index parameter of the Duplicate layer to be disconnected
110 if(value_desc.parent_is_layer_param() && value_desc.get_layer()->get_name() == "duplicate" && value_desc.get_param_name() == "index")
112 if(!value_desc.parent_is_canvas() && value_desc.is_value_node() && value_desc.get_value_node()->rcount()>1)
114 if(value_desc.is_const())
116 if(value_desc.is_value_node() && ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
118 // don't allow Duplicate ValueNodes in the Children dialog to be disconnected
119 if(value_desc.is_value_node() &&
120 ValueNode_Duplicate::Handle::cast_dynamic(value_desc.get_value_node()) &&
121 !value_desc.parent_is_layer_param() &&
122 !value_desc.parent_is_value_node())
128 Action::ValueDescDisconnect::set_param(const synfig::String& name, const Action::Param ¶m)
130 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
132 value_desc=param.get_value_desc();
137 if(name=="time" && param.get_type()==Param::TYPE_TIME)
139 time=param.get_time();
144 return Action::CanvasSpecific::set_param(name,param);
148 Action::ValueDescDisconnect::is_ready()const
152 return Action::CanvasSpecific::is_ready();
156 Action::ValueDescDisconnect::prepare()
160 if(value_desc.parent_is_canvas())
162 ValueNode::Handle src_value_node;
163 src_value_node=ValueNode_Const::create((*value_desc.get_value_node())(time));
165 Action::Handle action(ValueNodeReplace::create());
167 action->set_param("canvas",get_canvas());
168 action->set_param("canvas_interface",get_canvas_interface());
169 action->set_param("src",src_value_node);
170 action->set_param("dest",value_desc.get_value_node());
172 assert(action->is_ready());
173 if(!action->is_ready())
174 throw Error(Error::TYPE_NOTREADY);
176 add_action_front(action);
180 if(value_desc.parent_is_linkable_value_node())
182 Action::Handle action(ValueNodeLinkDisconnect::create());
184 action->set_param("canvas",get_canvas());
185 action->set_param("canvas_interface",get_canvas_interface());
186 action->set_param("parent_value_node",value_desc.get_parent_value_node());
187 action->set_param("index",value_desc.get_index());
188 action->set_param("time",time);
190 assert(action->is_ready());
191 if(!action->is_ready())
192 throw Error(Error::TYPE_NOTREADY);
194 add_action_front(action);
198 if(value_desc.parent_is_layer_param())
200 Action::Handle action(LayerParamDisconnect::create());
202 action->set_param("canvas",get_canvas());
203 action->set_param("canvas_interface",get_canvas_interface());
204 action->set_param("layer",value_desc.get_layer());
205 action->set_param("param",value_desc.get_param_name());
206 action->set_param("time",time);
208 assert(action->is_ready());
209 if(!action->is_ready())
210 throw Error(Error::TYPE_NOTREADY);
212 add_action_front(action);
216 throw Error(_("ValueDesc is not recognized or supported."));