Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuedescdisconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuedescdisconnect.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "layerparamdisconnect.h"
34 #include "waypointdisconnect.h"
35 #include "valuenodelinkdisconnect.h"
36 #include "valuenodereplace.h"
37
38 #include "valuedescdisconnect.h"
39 #include <synfigapp/canvasinterface.h>
40 #include <synfig/valuenode_const.h>
41 #include <synfig/valuenode_duplicate.h>
42
43 #include <synfigapp/general.h>
44
45 #endif
46
47 using namespace std;
48 using namespace etl;
49 using namespace synfig;
50 using namespace synfigapp;
51 using namespace Action;
52
53 /* === M A C R O S ========================================================= */
54
55 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescDisconnect);
56 ACTION_SET_NAME(Action::ValueDescDisconnect,"ValueDescDisconnect");
57 ACTION_SET_LOCAL_NAME(Action::ValueDescDisconnect,N_("Disconnect"));
58 ACTION_SET_TASK(Action::ValueDescDisconnect,"disconnect");
59 ACTION_SET_CATEGORY(Action::ValueDescDisconnect,Action::CATEGORY_VALUEDESC);
60 ACTION_SET_PRIORITY(Action::ValueDescDisconnect,-100);
61 ACTION_SET_VERSION(Action::ValueDescDisconnect,"0.0");
62 ACTION_SET_CVS_ID(Action::ValueDescDisconnect,"$Id$");
63
64 /* === G L O B A L S ======================================================= */
65
66 /* === P R O C E D U R E S ================================================= */
67
68 /* === M E T H O D S ======================================================= */
69
70 Action::ValueDescDisconnect::ValueDescDisconnect():
71         time(0)
72 {
73 }
74
75 synfig::String
76 Action::ValueDescDisconnect::get_local_name()const
77 {
78   // TRANSLATORS: This is used in the History dialog when a ValueNode is disconnected.
79   return strprintf(_("Disconnect %s"),
80                    value_desc
81                    ? value_desc.get_description().c_str()
82                    : _("ValueDesc"));
83 }
84
85 Action::ParamVocab
86 Action::ValueDescDisconnect::get_param_vocab()
87 {
88         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
89
90         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
91                 .set_local_name(_("ValueDesc"))
92         );
93
94         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
95                 .set_local_name(_("Time"))
96                 .set_optional()
97         );
98
99         return ret;
100 }
101
102 bool
103 Action::ValueDescDisconnect::is_candidate(const ParamList &x)
104 {
105         if (!candidate_check(get_param_vocab(),x))
106                 return false;
107
108         ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
109
110         // don't allow the Index parameter of the Duplicate layer to be disconnected
111         if(value_desc.parent_is_layer_param() && value_desc.get_layer()->get_name() == "duplicate" && value_desc.get_param_name() == "index")
112                 return false;
113         if(!value_desc.parent_is_canvas() && value_desc.is_value_node() && value_desc.get_value_node()->rcount()>1)
114                 return true;
115         if(value_desc.is_const())
116                 return false;
117         if(value_desc.is_value_node() && ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
118                 return false;
119         // don't allow Duplicate ValueNodes in the Children dialog to be disconnected
120         if(value_desc.is_value_node() &&
121            ValueNode_Duplicate::Handle::cast_dynamic(value_desc.get_value_node()) &&
122            !value_desc.parent_is_layer_param() &&
123            !value_desc.parent_is_value_node())
124                 return false;
125         return true;
126 }
127
128 bool
129 Action::ValueDescDisconnect::set_param(const synfig::String& name, const Action::Param &param)
130 {
131         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
132         {
133                 value_desc=param.get_value_desc();
134
135                 return true;
136         }
137
138         if(name=="time" && param.get_type()==Param::TYPE_TIME)
139         {
140                 time=param.get_time();
141
142                 return true;
143         }
144
145         return Action::CanvasSpecific::set_param(name,param);
146 }
147
148 bool
149 Action::ValueDescDisconnect::is_ready()const
150 {
151         if(!value_desc)
152                 return false;
153         return Action::CanvasSpecific::is_ready();
154 }
155
156 void
157 Action::ValueDescDisconnect::prepare()
158 {
159         clear();
160
161         if(value_desc.parent_is_canvas())
162         {
163                 ValueNode::Handle src_value_node;
164                 src_value_node=ValueNode_Const::create((*value_desc.get_value_node())(time));
165
166                 Action::Handle action(ValueNodeReplace::create());
167
168                 action->set_param("canvas",get_canvas());
169                 action->set_param("canvas_interface",get_canvas_interface());
170                 action->set_param("src",src_value_node);
171                 action->set_param("dest",value_desc.get_value_node());
172
173                 assert(action->is_ready());
174                 if(!action->is_ready())
175                         throw Error(Error::TYPE_NOTREADY);
176
177                 add_action_front(action);
178                 return;
179         }
180         else
181         if(value_desc.parent_is_waypoint())
182         {
183                 Action::Handle action(WaypointDisconnect::create());
184
185                 action->set_param("canvas",get_canvas());
186                 action->set_param("canvas_interface",get_canvas_interface());
187                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
188                 action->set_param("waypoint_time",value_desc.get_waypoint_time());
189                 action->set_param("time",time);
190
191                 assert(action->is_ready());
192                 if(!action->is_ready())
193                         throw Error(Error::TYPE_NOTREADY);
194
195                 add_action_front(action);
196                 return;
197         }
198         else
199         if(value_desc.parent_is_linkable_value_node())
200         {
201                 Action::Handle action(ValueNodeLinkDisconnect::create());
202
203                 action->set_param("canvas",get_canvas());
204                 action->set_param("canvas_interface",get_canvas_interface());
205                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
206                 action->set_param("index",value_desc.get_index());
207                 action->set_param("time",time);
208
209                 assert(action->is_ready());
210                 if(!action->is_ready())
211                         throw Error(Error::TYPE_NOTREADY);
212
213                 add_action_front(action);
214                 return;
215         }
216         else
217         if(value_desc.parent_is_layer_param())
218         {
219                 Action::Handle action(LayerParamDisconnect::create());
220
221                 action->set_param("canvas",get_canvas());
222                 action->set_param("canvas_interface",get_canvas_interface());
223                 action->set_param("layer",value_desc.get_layer());
224                 action->set_param("param",value_desc.get_param_name());
225                 action->set_param("time",time);
226
227                 assert(action->is_ready());
228                 if(!action->is_ready())
229                         throw Error(Error::TYPE_NOTREADY);
230
231                 add_action_front(action);
232                 return;
233         }
234
235         throw Error(_("ValueDesc is not recognized or supported."));
236 }