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