1 /* === S Y N F I G ========================================================= */
2 /*! \file activepointadd.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "activepointadd.h"
34 #include <synfigapp/canvasinterface.h>
36 #include <synfigapp/general.h>
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT(Action::ActivepointAdd);
49 ACTION_SET_NAME(Action::ActivepointAdd,"ActivepointAdd");
50 ACTION_SET_LOCAL_NAME(Action::ActivepointAdd,N_("Add Activepoint"));
51 ACTION_SET_TASK(Action::ActivepointAdd,"add");
52 ACTION_SET_CATEGORY(Action::ActivepointAdd,Action::CATEGORY_ACTIVEPOINT);
53 ACTION_SET_PRIORITY(Action::ActivepointAdd,0);
54 ACTION_SET_VERSION(Action::ActivepointAdd,"0.0");
55 ACTION_SET_CVS_ID(Action::ActivepointAdd,"$Id$");
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Action::ActivepointAdd::ActivepointAdd()
65 activepoint.set_time(Time::begin()-1);
71 Action::ActivepointAdd::get_param_vocab()
73 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
76 .set_local_name(_("ValueDesc"))
79 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
80 .set_local_name(_("New Activepoint"))
81 .set_desc(_("Activepoint to be added"))
85 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
86 .set_local_name(_("Time"))
87 .set_desc(_("Time where activepoint is to be added"))
95 Action::ActivepointAdd::is_candidate(const ParamList &x)
97 if (!candidate_check(get_param_vocab(),x))
100 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
102 return (value_desc.parent_is_value_node() &&
103 // We need a dynamic list.
104 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()) &&
105 // We need either an activepoint or a time.
106 (x.count("activepoint") || x.count("time")));
110 Action::ActivepointAdd::set_param(const synfig::String& name, const Action::Param ¶m)
112 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
114 ValueDesc value_desc(param.get_value_desc());
116 if(!value_desc.parent_is_value_node())
119 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
124 index=value_desc.get_index();
131 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT && !time_set)
133 activepoint=param.get_activepoint();
137 if(name=="time" && param.get_type()==Param::TYPE_TIME && activepoint.get_time()==Time::begin()-1)
139 activepoint.set_time(param.get_time());
148 return Action::CanvasSpecific::set_param(name,param);
152 Action::ActivepointAdd::is_ready()const
154 if(!value_node || activepoint.get_time()==(Time::begin()-1))
156 return Action::CanvasSpecific::is_ready();
159 // This function is called if a time is specified, but not
160 // a activepoint. In this case, we need to calculate the value
161 // of the activepoint
163 Action::ActivepointAdd::calc_activepoint()
165 const Time time(activepoint.get_time());
166 activepoint.set_state(value_node->list[index].status_at_time(time));
167 activepoint.set_priority(0);
169 // In this case, nothing is really changing, so there will be
170 // no need to redraw the window
175 Action::ActivepointAdd::perform()
177 try { value_node->list[index].find(activepoint.get_time()); throw Error(_("A Activepoint already exists at this point in time"));}
178 catch(synfig::Exception::NotFound) { }
180 try { if(value_node->list[index].find(activepoint)!=value_node->list[index].timing_info.end()) throw Error(_("This activepoint is already in the ValueNode"));}
181 catch(synfig::Exception::NotFound) { }
183 value_node->list[index].add(activepoint);
184 value_node->changed();
186 /*if(get_canvas_interface())
188 get_canvas_interface()->signal_value_node_changed()(value_node);
190 else synfig::warning("CanvasInterface not set on action");
195 Action::ActivepointAdd::undo()
197 value_node->list[index].erase(activepoint);
198 value_node->changed();
200 // Signal that a layer has been inserted
201 if(get_canvas_interface())
203 get_canvas_interface()->signal_value_node_changed()(value_node);
205 else synfig::warning("CanvasInterface not set on action");