1 /* === S Y N F I G ========================================================= */
2 /*! \file activepointremove.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 "activepointremove.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::ActivepointRemove);
49 ACTION_SET_NAME(Action::ActivepointRemove,"activepoint_remove");
50 ACTION_SET_LOCAL_NAME(Action::ActivepointRemove,N_("Remove Activepoint"));
51 ACTION_SET_TASK(Action::ActivepointRemove,"remove");
52 ACTION_SET_CATEGORY(Action::ActivepointRemove,Action::CATEGORY_ACTIVEPOINT);
53 ACTION_SET_PRIORITY(Action::ActivepointRemove,0);
54 ACTION_SET_VERSION(Action::ActivepointRemove,"0.0");
55 ACTION_SET_CVS_ID(Action::ActivepointRemove,"$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::ActivepointRemove::ActivepointRemove()
65 activepoint.set_time(Time::begin()-1);
70 Action::ActivepointRemove::get_param_vocab()
72 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
75 .set_local_name(_("ValueDesc"))
78 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
79 .set_local_name(_("Activepoint"))
80 .set_desc(_("Activepoint to be changed"))
87 Action::ActivepointRemove::is_candidate(const ParamList &x)
89 if (!candidate_check(get_param_vocab(),x))
92 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
94 return (value_desc.parent_is_value_node() &&
95 // We need a dynamic list.
96 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
100 Action::ActivepointRemove::set_param(const synfig::String& name, const Action::Param ¶m)
102 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
104 ValueDesc value_desc(param.get_value_desc());
106 if(!value_desc.parent_is_value_node())
109 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
114 index=value_desc.get_index();
118 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
120 activepoint=param.get_activepoint();
125 return Action::CanvasSpecific::set_param(name,param);
129 Action::ActivepointRemove::is_ready()const
131 if(!value_node || activepoint.get_time()==(Time::begin()-1))
133 return Action::CanvasSpecific::is_ready();
137 Action::ActivepointRemove::perform()
139 ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
141 try { iter=value_node->list[index].find(activepoint); }
142 catch(synfig::Exception::NotFound)
144 throw Error(_("Unable to find activepoint"));
147 value_node->list[index].erase(activepoint);
148 value_node->changed();
151 // Signal that a layer has been inserted
152 if(get_canvas_interface())
154 get_canvas_interface()->signal_value_node_changed()(value_node);
156 else synfig::warning("CanvasInterface not set on action");
161 Action::ActivepointRemove::undo()
163 try { value_node->list[index].find(activepoint.get_time()); throw Error(_("A Activepoint already exists at this point in time"));}
164 catch(synfig::Exception::NotFound) { }
166 try { if(value_node->list[index].find(activepoint)!=value_node->list[index].timing_info.end()) throw Error(_("This activepoint is already in the ValueNode"));}
167 catch(synfig::Exception::NotFound) { }
169 value_node->list[index].add(activepoint);
170 value_node->changed();
172 // Signal that a layer has been inserted
173 if(get_canvas_interface())
175 get_canvas_interface()->signal_value_node_changed()(value_node);
177 else synfig::warning("CanvasInterface not set on action");