my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuenodelinkconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodelinkconnect.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenodelinkconnect.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "valuenodelinkconnect.h"
32 #include <synfigapp/canvasinterface.h>
33
34 #endif
35
36 using namespace std;
37 using namespace etl;
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
41
42 /* === M A C R O S ========================================================= */
43
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 $");
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 Action::ValueNodeLinkConnect::ValueNodeLinkConnect():
60         index(-1)       // Initially set it to negative one so that we know when it has changed
61 {
62 }
63
64 Action::ParamVocab
65 Action::ValueNodeLinkConnect::get_param_vocab()
66 {
67         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
68         
69         ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
70                 .set_local_name(_("Parent ValueNode"))
71         );
72
73         ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
74                 .set_local_name(_("Index"))
75         );
76
77         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
78                 .set_local_name(_("ValueNode to be connected"))
79         );
80
81         return ret;
82 }
83
84 bool
85 Action::ValueNodeLinkConnect::is_canidate(const ParamList &x)
86 {
87         return canidate_check(get_param_vocab(),x);
88 }
89
90 bool
91 Action::ValueNodeLinkConnect::set_param(const synfig::String& name, const Action::Param &param)
92 {
93         if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
94         {
95                 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
96                 
97                 return static_cast<bool>(parent_value_node);
98         }
99
100         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
101         {
102                 new_value_node=param.get_value_node();
103                 
104                 return true;
105         }
106
107         if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
108         {
109                 index=param.get_integer();
110                 
111                 return true;
112         }
113
114         return Action::CanvasSpecific::set_param(name,param);
115 }
116
117 bool
118 Action::ValueNodeLinkConnect::is_ready()const
119 {
120         if(!new_value_node || !parent_value_node || index==-1)
121                 return false;
122         return Action::CanvasSpecific::is_ready();
123 }
124
125 void
126 Action::ValueNodeLinkConnect::perform()
127 {
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);             
130                 
131         old_value_node=parent_value_node->get_link(index);
132
133         if(!parent_value_node->set_link(index,new_value_node))
134                 throw Error(_("Parent would not accept link"));
135         
136         /*set_dirty(true);
137         
138         if(get_canvas_interface())
139         {
140                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
141         }*/
142 }
143
144 void
145 Action::ValueNodeLinkConnect::undo()
146 {
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);             
149                 
150         if(!parent_value_node->set_link(index,old_value_node))
151                 throw Error(_("Parent would not accept old link"));
152         
153         /*set_dirty(true);
154         
155         if(get_canvas_interface())
156         {
157                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
158         }*/
159 }