1 /* === S I N F G =========================================================== */
2 /*! \file valuenodelinkconnect.cpp
3 ** \brief Template File
5 ** $Id: valuenodelinkconnect.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 "valuenodelinkconnect.h"
32 #include <sinfgapp/canvasinterface.h>
38 using namespace sinfg;
39 using namespace sinfgapp;
40 using namespace Action;
42 /* === M A C R O S ========================================================= */
44 ACTION_INIT(Action::ValueNodeLinkConnect);
45 ACTION_SET_NAME(Action::ValueNodeLinkConnect,"value_node_link_connect");
46 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkConnect,_("Connect ValueNode Link"));
47 ACTION_SET_TASK(Action::ValueNodeLinkConnect,"connect");
48 ACTION_SET_CATEGORY(Action::ValueNodeLinkConnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
49 ACTION_SET_PRIORITY(Action::ValueNodeLinkConnect,0);
50 ACTION_SET_VERSION(Action::ValueNodeLinkConnect,"0.0");
51 ACTION_SET_CVS_ID(Action::ValueNodeLinkConnect,"$Id: valuenodelinkconnect.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 /* === M E T H O D S ======================================================= */
59 Action::ValueNodeLinkConnect::ValueNodeLinkConnect():
60 index(-1) // Initially set it to negative one so that we know when it has changed
65 Action::ValueNodeLinkConnect::get_param_vocab()
67 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69 ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
70 .set_local_name(_("Parent ValueNode"))
73 ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
74 .set_local_name(_("Index"))
77 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
78 .set_local_name(_("ValueNode to be connected"))
85 Action::ValueNodeLinkConnect::is_canidate(const ParamList &x)
87 return canidate_check(get_param_vocab(),x);
91 Action::ValueNodeLinkConnect::set_param(const sinfg::String& name, const Action::Param ¶m)
93 if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
95 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
97 return static_cast<bool>(parent_value_node);
100 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
102 new_value_node=param.get_value_node();
107 if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
109 index=param.get_integer();
114 return Action::CanvasSpecific::set_param(name,param);
118 Action::ValueNodeLinkConnect::is_ready()const
120 if(!new_value_node || !parent_value_node || index==-1)
122 return Action::CanvasSpecific::is_ready();
126 Action::ValueNodeLinkConnect::perform()
128 if(parent_value_node->link_count()<=index)
129 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
131 old_value_node=parent_value_node->get_link(index);
133 if(!parent_value_node->set_link(index,new_value_node))
134 throw Error(_("Parent would not accept link"));
138 if(get_canvas_interface())
140 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
145 Action::ValueNodeLinkConnect::undo()
147 if(parent_value_node->link_count()<=index)
148 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
150 if(!parent_value_node->set_link(index,old_value_node))
151 throw Error(_("Parent would not accept old link"));
155 if(get_canvas_interface())
157 get_canvas_interface()->signal_value_node_changed()(parent_value_node);