1 /* === S Y N F I G ========================================================= */
2 /*! \file activepointsimpleadd.cpp
3 ** \brief Simple add activepoint File
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2004 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 #include <synfig/general.h>
33
34 #include "activepointsimpleadd.h"
35 #include <synfigapp/canvasinterface.h>
36
37 #include <synfigapp/localization.h>
38
39 #endif
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44 using namespace synfigapp;
45 using namespace Action;
46
47 /* === M A C R O S ========================================================= */
48
49 ACTION_INIT(Action::ActivepointSimpleAdd);
50 ACTION_SET_NAME(Action::ActivepointSimpleAdd,"ActivepointSimpleAdd");
51 ACTION_SET_LOCAL_NAME(Action::ActivepointSimpleAdd,N_("Simply Add Waypoint"));
52 ACTION_SET_TASK(Action::ActivepointSimpleAdd,"add");
53 ACTION_SET_CATEGORY(Action::ActivepointSimpleAdd,Action::CATEGORY_WAYPOINT);
54 ACTION_SET_PRIORITY(Action::ActivepointSimpleAdd,0);
55 ACTION_SET_VERSION(Action::ActivepointSimpleAdd,"0.0");
56 ACTION_SET_CVS_ID(Action::ActivepointSimpleAdd,"$Id$");
57
58 /* === G L O B A L S ======================================================= */
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
ActivepointSimpleAdd()64 Action::ActivepointSimpleAdd::ActivepointSimpleAdd():
65 index(),
66 time_overwrite()
67 {
68 set_dirty(true);
69 activepoint.set_time(Time::begin()-1);
70 }
71
72 Action::ParamVocab
get_param_vocab()73 Action::ActivepointSimpleAdd::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(_("Destination ValueNode (Animated)"))
79 );
80
81 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
82 .set_local_name(_("Activepoint"))
83 .set_desc(_("Activepoint to be added"))
84 );
85
86 return ret;
87 }
88
89 bool
is_candidate(const ParamList & x)90 Action::ActivepointSimpleAdd::is_candidate(const ParamList &x)
91 {
92 if(candidate_check(get_param_vocab(),x))
93 {
94 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
95 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
96 return false;
97
98 return true;
99 }
100 return candidate_check(get_param_vocab(),x);
101 }
102
103 bool
set_param(const synfig::String & name,const Action::Param & param)104 Action::ActivepointSimpleAdd::set_param(const synfig::String& name, const Action::Param ¶m)
105 {
106 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
107 {
108 ValueDesc value_desc(param.get_value_desc());
109
110 if(!value_desc.parent_is_value_node())
111 return false;
112
113 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
114
115 if(!value_node)
116 return false;
117
118 index=value_desc.get_index();
119
120 return true;
121 }
122 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
123 {
124 activepoint = param.get_activepoint();
125
126 return true;
127 }
128
129 return Action::CanvasSpecific::set_param(name,param);
130 }
131
132 bool
is_ready() const133 Action::ActivepointSimpleAdd::is_ready()const
134 {
135 if(!value_node && activepoint.get_time() != (Time::begin()-1))
136 return false;
137 return Action::CanvasSpecific::is_ready();
138 }
139
140 void
perform()141 Action::ActivepointSimpleAdd::perform()
142 {
143 //remove any pretenders that lie at our destination
144 ValueNode_DynamicList::ListEntry::findresult iter = value_node->list[index]
145 .find_time(activepoint.get_time());
146
147 time_overwrite = false;
148 if(iter.second)
149 {
150 overwritten_ap = *iter.first;
151 time_overwrite = true;
152 value_node->list[index].erase(overwritten_ap);
153 }
154
155 //add the value node in since it's safe
156 value_node->list[index].add(activepoint);
157
158 //sort them...
159 value_node->list[index].timing_info.sort();
160
161 // Signal that a valuenode has been changed
162 value_node->changed();
163 }
164
165 void
undo()166 Action::ActivepointSimpleAdd::undo()
167 {
168 //remove our old version...
169 ValueNode_DynamicList::ListEntry::findresult iter = value_node->list[index].find_uid(activepoint);
170
171 if(!iter.second)
172 {
173 throw Error(_("The activepoint to remove no longer exists"));
174 }
175
176 //remove the offending value
177 value_node->list[index].erase(*iter.first); //could also just use waypoint
178
179 if(time_overwrite)
180 {
181 value_node->list[index].add(overwritten_ap);
182 }
183
184 //sort them...
185 value_node->list[index].timing_info.sort();
186
187 // Signal that a valuenode has been changed
188 value_node->changed();
189 }
190