Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.09 / src / synfigapp / actions / waypointsimpleadd.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file waypointsimpleadd.cpp
3 **      \brief Simple add waypoint 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 "waypointsimpleadd.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::WaypointSimpleAdd);
48 ACTION_SET_NAME(Action::WaypointSimpleAdd,"waypoint_simpleadd");
49 ACTION_SET_LOCAL_NAME(Action::WaypointSimpleAdd,N_("Simply Add Waypoint"));
50 ACTION_SET_TASK(Action::WaypointSimpleAdd,"add");
51 ACTION_SET_CATEGORY(Action::WaypointSimpleAdd,Action::CATEGORY_WAYPOINT);
52 ACTION_SET_PRIORITY(Action::WaypointSimpleAdd,0);
53 ACTION_SET_VERSION(Action::WaypointSimpleAdd,"0.0");
54 ACTION_SET_CVS_ID(Action::WaypointSimpleAdd,"$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::WaypointSimpleAdd::WaypointSimpleAdd()
63 {
64         set_dirty(true);
65         waypoint.set_time(Time::begin()-1);
66 }
67
68 Action::ParamVocab
69 Action::WaypointSimpleAdd::get_param_vocab()
70 {
71         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72
73         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
74                 .set_local_name(_("Destination ValueNode (Animated)"))
75         );
76
77         ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
78                 .set_local_name(_("Waypoint"))
79                 .set_desc(_("Waypoint to be added"))
80         );
81
82         return ret;
83 }
84
85 bool
86 Action::WaypointSimpleAdd::is_candidate(const ParamList &x)
87 {
88         return candidate_check(get_param_vocab(),x);
89 }
90
91 bool
92 Action::WaypointSimpleAdd::set_param(const synfig::String& name, const Action::Param &param)
93 {
94         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
95         {
96                 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
97
98                 return static_cast<bool>(value_node);
99         }
100         if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
101         {
102                 waypoint = param.get_waypoint();
103
104                 return true;
105         }
106
107         return Action::CanvasSpecific::set_param(name,param);
108 }
109
110 bool
111 Action::WaypointSimpleAdd::is_ready()const
112 {
113         if(!value_node && waypoint.get_time() != (Time::begin()-1))
114                 return false;
115         return Action::CanvasSpecific::is_ready();
116 }
117
118 void
119 Action::WaypointSimpleAdd::perform()
120 {
121         //remove any pretenders that lie at our destination
122         ValueNode_Animated::findresult iter = value_node->find_time(waypoint.get_time());
123
124         time_overwrite = false;
125         if(iter.second)
126         {
127                 overwritten_wp = *iter.first;
128                 time_overwrite = true;
129         }
130
131         //add the value node in since it's safe
132         value_node->add(waypoint);
133
134         // Signal that a valuenode has been changed
135         value_node->changed();
136 }
137
138 void
139 Action::WaypointSimpleAdd::undo()
140 {
141         //remove our old version...
142         ValueNode_Animated::findresult iter = value_node->find_uid(waypoint);
143
144         if(!iter.second)
145         {
146                 throw Error(_("The waypoint to remove no longer exists"));
147         }
148
149         //remove the offending value
150         value_node->erase(*iter.first); //could also just use waypoint
151
152         if(time_overwrite)
153         {
154                 value_node->add(overwritten_wp);
155         }
156
157         // Signal that a valuenode has been changed
158         value_node->changed();
159 }