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