my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuenodelinkdisconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodelinkdisconnect.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenodelinkdisconnect.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 "valuenodelinkdisconnect.h"
32 #include <synfigapp/canvasinterface.h>
33 #include <synfig/valuenode_const.h>
34
35 #endif
36
37 using namespace std;
38 using namespace etl;
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
42
43 /* === M A C R O S ========================================================= */
44
45 ACTION_INIT(Action::ValueNodeLinkDisconnect);
46 ACTION_SET_NAME(Action::ValueNodeLinkDisconnect,"value_node_link_disconnect");
47 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkDisconnect,_("Disconnect ValueNode Link"));
48 ACTION_SET_TASK(Action::ValueNodeLinkDisconnect,"disconnect");
49 ACTION_SET_CATEGORY(Action::ValueNodeLinkDisconnect,Action::CATEGORY_VALUENODE);
50 ACTION_SET_PRIORITY(Action::ValueNodeLinkDisconnect,0);
51 ACTION_SET_VERSION(Action::ValueNodeLinkDisconnect,"0.0");
52 ACTION_SET_CVS_ID(Action::ValueNodeLinkDisconnect,"$Id: valuenodelinkdisconnect.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 Action::ValueNodeLinkDisconnect::ValueNodeLinkDisconnect():
61         index(-1),      // Initially set it to negative one so that we know when it has changed
62         time(0)
63 {
64 }
65
66 Action::ParamVocab
67 Action::ValueNodeLinkDisconnect::get_param_vocab()
68 {
69         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70         
71         ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
72                 .set_local_name(_("Parent ValueNode"))
73         );
74
75         ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
76                 .set_local_name(_("Index"))
77         );
78
79         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
80                 .set_local_name(_("Time"))
81                 .set_optional()
82         );
83
84         return ret;
85 }
86
87 bool
88 Action::ValueNodeLinkDisconnect::is_canidate(const ParamList &x)
89 {
90         return canidate_check(get_param_vocab(),x);
91 }
92
93 bool
94 Action::ValueNodeLinkDisconnect::set_param(const synfig::String& name, const Action::Param &param)
95 {
96         if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
97         {
98                 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
99                 
100                 return static_cast<bool>(parent_value_node);
101         }
102
103         if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
104         {
105                 index=param.get_integer();
106                 
107                 return true;
108         }
109
110         if(name=="time" && param.get_type()==Param::TYPE_TIME)
111         {
112                 time=param.get_time();
113                 
114                 return true;
115         }
116
117         return Action::CanvasSpecific::set_param(name,param);
118 }
119
120 bool
121 Action::ValueNodeLinkDisconnect::is_ready()const
122 {
123         if(!parent_value_node || index==-1)
124                 return false;
125         return Action::CanvasSpecific::is_ready();
126 }
127
128 void
129 Action::ValueNodeLinkDisconnect::perform()
130 {
131         if(parent_value_node->link_count()<=index)
132                 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);             
133                 
134         old_value_node=parent_value_node->get_link(index);
135
136         if(!parent_value_node->set_link(index,ValueNode_Const::create((*old_value_node)(time))))
137                 throw Error(_("Parent would not accept link"));
138         
139         /*
140         if(get_canvas()->get_time()!=time)
141                 set_dirty(true);
142         else
143                 set_dirty(false);
144         
145         if(get_canvas_interface())
146         {
147                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
148         }
149         */
150 }
151
152 void
153 Action::ValueNodeLinkDisconnect::undo()
154 {
155         if(parent_value_node->link_count()<=index)
156                 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);             
157                 
158         if(!parent_value_node->set_link(index,old_value_node))
159                 throw Error(_("Parent would not accept old link"));
160         
161         /*if(get_canvas()->get_time()!=time)
162                 set_dirty(true);
163         else
164                 set_dirty(false);
165         
166         if(get_canvas_interface())
167         {
168                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
169         }*/
170 }