1 /* === S Y N F I G ========================================================= */
2 /*! \file valuedesclink.cpp
3 ** \brief Template File
5 ** $Id: valuedesclink.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "valuedesclink.h"
34 #include <synfigapp/canvasinterface.h>
35 #include <synfig/valuenode_const.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::ValueDescLink);
48 ACTION_SET_NAME(Action::ValueDescLink,"value_desc_link");
49 ACTION_SET_LOCAL_NAME(Action::ValueDescLink,"Link");
50 ACTION_SET_TASK(Action::ValueDescLink,"connect");
51 ACTION_SET_CATEGORY(Action::ValueDescLink,Action::CATEGORY_VALUEDESC);
52 ACTION_SET_PRIORITY(Action::ValueDescLink,0);
53 ACTION_SET_VERSION(Action::ValueDescLink,"0.0");
54 ACTION_SET_CVS_ID(Action::ValueDescLink,"$Id: valuedesclink.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::ValueDescLink::ValueDescLink()
68 Action::ValueDescLink::get_param_vocab()
70 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
73 .set_local_name(_("ValueDesc to link"))
74 .set_requires_multiple()
81 Action::ValueDescLink::is_canidate(const ParamList &x)
83 return canidate_check(get_param_vocab(),x);
87 Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param ¶m)
89 if(name=="time" && param.get_type()==Param::TYPE_TIME)
91 time=param.get_time();
95 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
97 ValueDesc value_desc(param.get_value_desc());
99 if(value_desc.is_value_node() && value_desc.get_value_node()->is_exported())
101 if(link_value_node==value_desc.get_value_node())
104 if(link_value_node && link_value_node->is_exported())
110 link_value_node=value_desc.get_value_node();
112 else if(value_desc.is_value_node())
116 link_value_node=value_desc.get_value_node();
119 // Use the one that is referenced more
120 else if(link_value_node->rcount()<value_desc.get_value_node()->rcount())
122 link_value_node=value_desc.get_value_node();
125 // If the current link value node is a constant and
126 // this one isn't, then give preference to the exotic
127 else if(ValueNode_Const::Handle::cast_dynamic(link_value_node) && !ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
129 link_value_node=value_desc.get_value_node();
132 // If both are animated, and this one has more waypoints,
133 // then use the one with more waypoints
135 ValueNode_Animated::Handle::cast_dynamic(link_value_node)
136 && ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())
138 ValueNode_Animated::Handle::cast_dynamic(link_value_node)->waypoint_list().size()
139 < ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node())->waypoint_list().size()
143 link_value_node=value_desc.get_value_node();
147 // Use the one that was most recently changed
148 else if(link_value_node->get_time_last_changed()<value_desc.get_value_node()->get_time_last_changed())
150 link_value_node=value_desc.get_value_node();
156 if(value_desc_list.size() && value_desc.get_value_type()!=value_desc_list.front().get_value_type())
158 // Everything must be of the same type
162 value_desc_list.push_back(value_desc);
167 return Action::CanvasSpecific::set_param(name,param);
171 Action::ValueDescLink::is_ready()const
173 if(poison || value_desc_list.size()<=1)
175 return Action::CanvasSpecific::is_ready();
179 Action::ValueDescLink::prepare()
181 if(poison || value_desc_list.empty())
182 throw Error(Error::TYPE_NOTREADY);
188 ValueDesc& value_desc(value_desc_list.front());
190 link_value_node=ValueNode_Const::create(value_desc.get_value(time));
192 Action::Handle action(Action::create("value_desc_connect"));
194 action->set_param("canvas",get_canvas());
195 action->set_param("canvas_interface",get_canvas_interface());
196 action->set_param("src",link_value_node);
197 action->set_param("dest",value_desc);
199 assert(action->is_ready());
200 if(!action->is_ready())
201 throw Error(Error::TYPE_NOTREADY);
203 add_action_front(action);
207 if(!link_value_node->is_exported())
209 Action::Handle action(Action::create("value_node_add"));
211 action->set_param("canvas",get_canvas());
212 action->set_param("canvas_interface",get_canvas_interface());
213 action->set_param("new",link_value_node);
214 action->set_param("name",strprintf(_("Unnamed%08d"),synfig::UniqueID().get_uid()));
216 assert(action->is_ready());
217 if(!action->is_ready())
218 throw Error(Error::TYPE_NOTREADY);
220 add_action_front(action);
224 std::list<ValueDesc>::iterator iter;
225 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
227 ValueDesc& value_desc(*iter);
229 if(value_desc.is_value_node() && value_desc.get_value_node()==link_value_node)
232 Action::Handle action(Action::create("value_desc_connect"));
234 action->set_param("canvas",get_canvas());
235 action->set_param("canvas_interface",get_canvas_interface());
236 action->set_param("src",link_value_node);
237 action->set_param("dest",value_desc);
239 assert(action->is_ready());
240 if(!action->is_ready())
241 throw Error(Error::TYPE_NOTREADY);
243 add_action_front(action);