1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodelinkdisconnect.cpp
3 ** \brief Template File
5 ** $Id: valuenodelinkdisconnect.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "valuenodelinkdisconnect.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_const.h>
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
44 /* === M A C R O S ========================================================= */
46 ACTION_INIT(Action::ValueNodeLinkDisconnect);
47 ACTION_SET_NAME(Action::ValueNodeLinkDisconnect,"value_node_link_disconnect");
48 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkDisconnect,_("Disconnect ValueNode Link"));
49 ACTION_SET_TASK(Action::ValueNodeLinkDisconnect,"disconnect");
50 ACTION_SET_CATEGORY(Action::ValueNodeLinkDisconnect,Action::CATEGORY_VALUENODE);
51 ACTION_SET_PRIORITY(Action::ValueNodeLinkDisconnect,0);
52 ACTION_SET_VERSION(Action::ValueNodeLinkDisconnect,"0.0");
53 ACTION_SET_CVS_ID(Action::ValueNodeLinkDisconnect,"$Id: valuenodelinkdisconnect.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::ValueNodeLinkDisconnect::ValueNodeLinkDisconnect():
62 index(-1), // Initially set it to negative one so that we know when it has changed
68 Action::ValueNodeLinkDisconnect::get_param_vocab()
70 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72 ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
73 .set_local_name(_("Parent ValueNode"))
76 ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
77 .set_local_name(_("Index"))
80 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
81 .set_local_name(_("Time"))
89 Action::ValueNodeLinkDisconnect::is_candidate(const ParamList &x)
91 return candidate_check(get_param_vocab(),x);
95 Action::ValueNodeLinkDisconnect::set_param(const synfig::String& name, const Action::Param ¶m)
97 if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
99 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
101 return static_cast<bool>(parent_value_node);
104 if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
106 index=param.get_integer();
111 if(name=="time" && param.get_type()==Param::TYPE_TIME)
113 time=param.get_time();
118 return Action::CanvasSpecific::set_param(name,param);
122 Action::ValueNodeLinkDisconnect::is_ready()const
124 if(!parent_value_node || index==-1)
126 return Action::CanvasSpecific::is_ready();
130 Action::ValueNodeLinkDisconnect::perform()
132 if(parent_value_node->link_count()<=index)
133 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
135 old_value_node=parent_value_node->get_link(index);
137 if(!parent_value_node->set_link(index,ValueNode_Const::create((*old_value_node)(time))))
138 throw Error(_("Parent would not accept link"));
141 if(get_canvas()->get_time()!=time)
146 if(get_canvas_interface())
148 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
154 Action::ValueNodeLinkDisconnect::undo()
156 if(parent_value_node->link_count()<=index)
157 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
159 if(!parent_value_node->set_link(index,old_value_node))
160 throw Error(_("Parent would not accept old link"));
162 /*if(get_canvas()->get_time()!=time)
167 if(get_canvas_interface())
169 get_canvas_interface()->signal_value_node_changed()(parent_value_node);