Quote the "Working Draft, Standard for Programming Language C++" on a point I wasn...
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuedescconvert.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuedescconvert.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 /*
33 #include "valuenodereplace.h"
34 #include "layerparamconnect.h"
35 #include "valuenodelinkconnect.h"
36 */
37
38 #include "valuedescconnect.h"
39
40 #include "valuedescconvert.h"
41
42 #include <synfigapp/canvasinterface.h>
43 #include <synfig/valuenode_const.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(Action::ValueDescConvert);
56 ACTION_SET_NAME(Action::ValueDescConvert,"value_desc_convert");
57 ACTION_SET_LOCAL_NAME(Action::ValueDescConvert,"Convert");
58 ACTION_SET_TASK(Action::ValueDescConvert,"convert");
59 ACTION_SET_CATEGORY(Action::ValueDescConvert,Action::CATEGORY_VALUEDESC);
60 ACTION_SET_PRIORITY(Action::ValueDescConvert,0);
61 ACTION_SET_VERSION(Action::ValueDescConvert,"0.0");
62 ACTION_SET_CVS_ID(Action::ValueDescConvert,"$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::ValueDescConvert::ValueDescConvert()
71 {
72 }
73
74 Action::ParamVocab
75 Action::ValueDescConvert::get_param_vocab()
76 {
77         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
78
79         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
80                 .set_local_name(_("ValueDesc"))
81         );
82
83         ret.push_back(ParamDesc("type",Param::TYPE_STRING)
84                 .set_local_name(_("Type"))
85                 .set_desc(_("The type of ValueNode that you want to be converted to"))
86         );
87
88         return ret;
89 }
90
91 bool
92 Action::ValueDescConvert::is_candidate(const ParamList &x)
93 {
94         return candidate_check(get_param_vocab(),x);
95 }
96
97 bool
98 Action::ValueDescConvert::set_param(const synfig::String& name, const Action::Param &param)
99 {
100         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
101         {
102                 value_desc=param.get_value_desc();
103
104                 return true;
105         }
106
107         if(name=="type" && param.get_type()==Param::TYPE_STRING)
108         {
109                 type=param.get_string();
110
111                 return true;
112         }
113
114         return Action::CanvasSpecific::set_param(name,param);
115 }
116
117 bool
118 Action::ValueDescConvert::is_ready()const
119 {
120         if(!value_desc || type.empty())
121                 return false;
122         return Action::CanvasSpecific::is_ready();
123 }
124
125 void
126 Action::ValueDescConvert::prepare()
127 {
128         clear();
129
130         ValueBase value;
131
132         if(value_desc.is_const())
133                 value=value_desc.get_value();
134         else if(value_desc.is_value_node())
135                 value=(*value_desc.get_value_node())(0);
136         else
137                 throw Error(_("Unable to decipher ValueDesc (Bug?)"));
138
139         ValueNode::Handle src_value_node(LinkableValueNode::create(type,value));
140
141         if(!src_value_node)
142                 throw Error(_("Unable to create new value node"));
143
144
145         ValueNode::Handle dest_value_node;
146         dest_value_node=value_desc.get_value_node();
147
148         Action::Handle action(ValueDescConnect::create());
149
150         action->set_param("canvas",get_canvas());
151         action->set_param("canvas_interface",get_canvas_interface());
152         action->set_param("src",src_value_node);
153         action->set_param("dest",value_desc);
154
155         assert(action->is_ready());
156         if(!action->is_ready())
157                 throw Error(Error::TYPE_NOTREADY);
158
159         add_action_front(action);
160
161 /*
162         return;
163
164
165         if(value_desc.parent_is_canvas())
166         {
167                 ValueNode::Handle dest_value_node;
168                 dest_value_node=value_desc.get_value_node();
169
170                 Action::Handle action(ValueNodeReplace::create());
171
172                 action->set_param("canvas",get_canvas());
173                 action->set_param("canvas_interface",get_canvas_interface());
174                 action->set_param("src",src_value_node);
175                 action->set_param("dest",dest_value_node);
176
177                 assert(action->is_ready());
178                 if(!action->is_ready())
179                         throw Error(Error::TYPE_NOTREADY);
180
181                 add_action_front(action);
182                 return;
183         }
184         else
185         if(value_desc.parent_is_linkable_value_node())
186         {
187                 Action::Handle action(ValueNodeLinkConnect::create());
188
189                 action->set_param("canvas",get_canvas());
190                 action->set_param("canvas_interface",get_canvas_interface());
191                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
192                 action->set_param("value_node", src_value_node);
193                 action->set_param("index",value_desc.get_index());
194
195                 assert(action->is_ready());
196                 if(!action->is_ready())
197                         throw Error(Error::TYPE_NOTREADY);
198
199                 add_action_front(action);
200                 return;
201         }
202         else
203         if(value_desc.parent_is_layer_param())
204         {
205                 Action::Handle action(LayerParamConnect::create());
206
207                 action->set_param("canvas",get_canvas());
208                 action->set_param("canvas_interface",get_canvas_interface());
209                 action->set_param("layer",value_desc.get_layer());
210                 action->set_param("param",value_desc.get_param_name());
211                 action->set_param("value_node",src_value_node);
212
213                 assert(action->is_ready());
214                 if(!action->is_ready())
215                         throw Error(Error::TYPE_NOTREADY);
216
217                 add_action_front(action);
218                 return;
219         }
220
221
222
223         throw Error(_("ValueDesc is not recognized or supported."));
224 */
225 }