1 /* === S Y N F I G ========================================================= */
2 /*!	\file activepointremove.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 <synfig/general.h>
34 
35 #include "activepointremove.h"
36 #include <synfigapp/canvasinterface.h>
37 
38 #include <synfigapp/localization.h>
39 
40 #endif
41 
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45 using namespace synfigapp;
46 using namespace Action;
47 
48 /* === M A C R O S ========================================================= */
49 
50 ACTION_INIT(Action::ActivepointRemove);
51 ACTION_SET_NAME(Action::ActivepointRemove,"ActivepointRemove");
52 ACTION_SET_LOCAL_NAME(Action::ActivepointRemove,N_("Remove Activepoint"));
53 ACTION_SET_TASK(Action::ActivepointRemove,"remove");
54 ACTION_SET_CATEGORY(Action::ActivepointRemove,Action::CATEGORY_ACTIVEPOINT);
55 ACTION_SET_PRIORITY(Action::ActivepointRemove,0);
56 ACTION_SET_VERSION(Action::ActivepointRemove,"0.0");
57 ACTION_SET_CVS_ID(Action::ActivepointRemove,"$Id$");
58 
59 /* === G L O B A L S ======================================================= */
60 
61 /* === P R O C E D U R E S ================================================= */
62 
63 /* === M E T H O D S ======================================================= */
64 
ActivepointRemove()65 Action::ActivepointRemove::ActivepointRemove():
66 	index()
67 {
68 	activepoint.set_time(Time::begin()-1);
69 	set_dirty(true);
70 }
71 
72 Action::ParamVocab
get_param_vocab()73 Action::ActivepointRemove::get_param_vocab()
74 {
75 	ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
76 
77 	ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
78 		.set_local_name(_("ValueDesc"))
79 	);
80 
81 	ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
82 		.set_local_name(_("Activepoint"))
83 		.set_desc(_("Activepoint to be changed"))
84 	);
85 
86 	return ret;
87 }
88 
89 bool
is_candidate(const ParamList & x)90 Action::ActivepointRemove::is_candidate(const ParamList &x)
91 {
92 	if (!candidate_check(get_param_vocab(),x))
93 		return false;
94 
95 	ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
96 
97 	return (value_desc.parent_is_value_node() &&
98 			// We need a dynamic list.
99 			ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
100 }
101 
102 bool
set_param(const synfig::String & name,const Action::Param & param)103 Action::ActivepointRemove::set_param(const synfig::String& name, const Action::Param &param)
104 {
105 	if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
106 	{
107 		ValueDesc value_desc(param.get_value_desc());
108 
109 		if(!value_desc.parent_is_value_node())
110 			return false;
111 
112 		value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
113 
114 		if(!value_node)
115 			return false;
116 
117 		index=value_desc.get_index();
118 
119 		return true;
120 	}
121 	if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
122 	{
123 		activepoint=param.get_activepoint();
124 
125 		return true;
126 	}
127 
128 	return Action::CanvasSpecific::set_param(name,param);
129 }
130 
131 bool
is_ready() const132 Action::ActivepointRemove::is_ready()const
133 {
134 	if(!value_node || activepoint.get_time()==(Time::begin()-1))
135 		return false;
136 	return Action::CanvasSpecific::is_ready();
137 }
138 
139 void
perform()140 Action::ActivepointRemove::perform()
141 {
142 	ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
143 
144 	try { iter=value_node->list[index].find(activepoint); }
145 	catch(synfig::Exception::NotFound)
146 	{
147 		throw Error(_("Unable to find activepoint"));
148 	}
149 
150 	value_node->list[index].erase(activepoint);
151 	value_node->changed();
152 
153 	/*
154 	// Signal that a layer has been inserted
155 	if(get_canvas_interface())
156 	{
157 		get_canvas_interface()->signal_value_node_changed()(value_node);
158 	}
159 	else synfig::warning("CanvasInterface not set on action");
160 	*/
161 }
162 
163 void
undo()164 Action::ActivepointRemove::undo()
165 {
166 	try { value_node->list[index].find(activepoint.get_time()); throw Error(_("A Activepoint already exists at this point in time"));}
167 	catch(synfig::Exception::NotFound) { }
168 
169 	try { if(value_node->list[index].find(activepoint)!=value_node->list[index].timing_info.end()) throw Error(_("This activepoint is already in the ValueNode"));}
170 	catch(synfig::Exception::NotFound) { }
171 
172 	value_node->list[index].add(activepoint);
173 	value_node->changed();
174 	/*
175 	// Signal that a layer has been inserted
176 	if(get_canvas_interface())
177 	{
178 		get_canvas_interface()->signal_value_node_changed()(value_node);
179 	}
180 	else synfig::warning("CanvasInterface not set on action");
181 	*/
182 }
183