Fix missing back slash to do not stop all the extra dist files list
[synfig.git] / synfig-studio / src / synfigapp / actions / valuedescconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuedescconnect.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 "layerparamconnect.h"
34 #include "waypointconnect.h"
35 #include "valuenodelinkconnect.h"
36 #include "valuenodereplace.h"
37
38 #include "valuedescconnect.h"
39 #include <synfigapp/canvasinterface.h>
40
41 #include <synfigapp/general.h>
42
43 #endif
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48 using namespace synfigapp;
49 using namespace Action;
50
51 /* === M A C R O S ========================================================= */
52
53 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescConnect);
54 ACTION_SET_NAME(Action::ValueDescConnect,"ValueDescConnect");
55 ACTION_SET_LOCAL_NAME(Action::ValueDescConnect,N_("Connect"));
56 ACTION_SET_TASK(Action::ValueDescConnect,"connect");
57 ACTION_SET_CATEGORY(Action::ValueDescConnect,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
58 ACTION_SET_PRIORITY(Action::ValueDescConnect,0);
59 ACTION_SET_VERSION(Action::ValueDescConnect,"0.0");
60 ACTION_SET_CVS_ID(Action::ValueDescConnect,"$Id$");
61
62 /* === G L O B A L S ======================================================= */
63
64 /* === P R O C E D U R E S ================================================= */
65
66 /* === M E T H O D S ======================================================= */
67
68 Action::ValueDescConnect::ValueDescConnect()
69 {
70 }
71
72 synfig::String
73 Action::ValueDescConnect::get_local_name()const
74 {
75         // TRANSLATORS: This is used in the 'history' dialog when a connection is made.
76         return strprintf(_("Connect '%s' to '%s'"),
77                                          value_desc.get_description(false).c_str(),
78                                          value_node->get_id().c_str());
79 }
80
81 Action::ParamVocab
82 Action::ValueDescConnect::get_param_vocab()
83 {
84         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
85
86         ret.push_back(ParamDesc("dest",Param::TYPE_VALUEDESC)
87                 .set_local_name(_("Destination ValueDesc"))
88         );
89
90         ret.push_back(ParamDesc("src",Param::TYPE_VALUENODE)
91                 .set_local_name(_("Source ValueNode"))
92                 .set_mutual_exclusion("src_name")
93         );
94
95         ret.push_back(ParamDesc("src_name",Param::TYPE_STRING)
96                 .set_local_name(_("Source ValueNode Name"))
97                 .set_mutual_exclusion("src")
98                 .set_user_supplied()
99         );
100
101         return ret;
102 }
103
104 bool
105 Action::ValueDescConnect::is_candidate(const ParamList &x)
106 {
107         if(candidate_check(get_param_vocab(),x))
108         {
109                 // don't show the option of connecting to an existing Index parameter of the Duplicate layer
110                 if(x.count("dest"))
111                 {
112                         ValueDesc value_desc=x.find("dest")->second.get_value_desc();
113
114                         if (value_desc.parent_is_layer_param() &&
115                                 value_desc.get_layer()->get_name() == "duplicate" &&
116                                 value_desc.get_param_name() == "index")
117                                 return false;
118                 }
119
120                 if(x.count("src"))
121                 {
122                         ValueDesc value_desc=x.find("dest")->second.get_value_desc();
123                         ValueNode::Handle value_node=x.find("src")->second.get_value_node();
124                         if(value_desc.get_value_type()==value_node->get_type())
125                                 return true;
126                 }
127                 return true;
128         }
129         return false;
130 }
131
132 bool
133 Action::ValueDescConnect::set_param(const synfig::String& name, const Action::Param &param)
134 {
135         if(name=="dest" && param.get_type()==Param::TYPE_VALUEDESC)
136         {
137                 value_desc=param.get_value_desc();
138
139                 return true;
140         }
141
142         if(name=="src" && param.get_type()==Param::TYPE_VALUENODE)
143         {
144                 value_node=param.get_value_node();
145
146                 return true;
147         }
148
149         if(!value_node_name.empty() && !value_node && name=="canvas" && param.get_type()==Param::TYPE_CANVAS)
150         {
151                 value_node=param.get_canvas()->find_value_node(value_node_name);
152         }
153
154         if(name=="src_name" && param.get_type()==Param::TYPE_STRING)
155         {
156                 value_node_name=param.get_string();
157
158                 if(get_canvas())
159                 {
160                         value_node=get_canvas()->find_value_node(value_node_name);
161                         if(!value_node)
162                                 return false;
163                 }
164
165                 return true;
166         }
167
168         return Action::CanvasSpecific::set_param(name,param);
169 }
170
171 bool
172 Action::ValueDescConnect::is_ready()const
173 {
174         if(!value_desc || !value_node)
175                 return false;
176         return Action::CanvasSpecific::is_ready();
177 }
178
179 void
180 Action::ValueDescConnect::prepare()
181 {
182         clear();
183
184         if(value_desc.parent_is_canvas())
185         {
186                 ValueNode::Handle dest_value_node;
187                 dest_value_node=value_desc.get_value_node();
188
189                 Action::Handle action(ValueNodeReplace::create());
190
191                 action->set_param("canvas",get_canvas());
192                 action->set_param("canvas_interface",get_canvas_interface());
193                 action->set_param("src",value_node);
194                 action->set_param("dest",value_desc.get_value_node());
195
196                 assert(action->is_ready());
197                 if(!action->is_ready())
198                         throw Error(Error::TYPE_NOTREADY);
199
200                 add_action_front(action);
201                 return;
202         }
203         else
204         if(value_desc.parent_is_waypoint())
205         {
206                 Action::Handle action(WaypointConnect::create());
207
208                 action->set_param("canvas",get_canvas());
209                 action->set_param("canvas_interface",get_canvas_interface());
210                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
211                 action->set_param("value_node", value_node);
212                 action->set_param("waypoint_time",value_desc.get_waypoint_time());
213
214                 assert(action->is_ready());
215                 if(!action->is_ready())
216                         throw Error(Error::TYPE_NOTREADY);
217
218                 add_action_front(action);
219                 return;
220         }
221         if(value_desc.parent_is_linkable_value_node())
222         {
223                 Action::Handle action(ValueNodeLinkConnect::create());
224
225                 action->set_param("canvas",get_canvas());
226                 action->set_param("canvas_interface",get_canvas_interface());
227                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
228                 action->set_param("value_node", value_node);
229                 action->set_param("index",value_desc.get_index());
230
231                 assert(action->is_ready());
232                 if(!action->is_ready())
233                         throw Error(Error::TYPE_NOTREADY);
234
235                 add_action_front(action);
236                 return;
237         }
238         else
239         if(value_desc.parent_is_layer_param())
240         {
241                 Action::Handle action(LayerParamConnect::create());
242
243                 action->set_param("canvas",get_canvas());
244                 action->set_param("canvas_interface",get_canvas_interface());
245                 action->set_param("layer",value_desc.get_layer());
246                 action->set_param("param",value_desc.get_param_name());
247                 action->set_param("value_node",value_node);
248
249                 assert(action->is_ready());
250                 if(!action->is_ready())
251                         throw Error(Error::TYPE_NOTREADY);
252
253                 add_action_front(action);
254                 return;
255         }
256
257         throw Error(_("ValueDesc is not recognized or supported."));
258 }