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