my log
[synfig.git] / synfig-studio / trunk / 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: waypointsimpleadd.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "waypointsimpleadd.h"
32 #include <synfigapp/canvasinterface.h>
33
34 #endif
35
36 using namespace std;
37 using namespace etl;
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
41
42 /* === M A C R O S ========================================================= */
43
44 ACTION_INIT(Action::WaypointSimpleAdd);
45 ACTION_SET_NAME(Action::WaypointSimpleAdd,"waypoint_simpleadd");
46 ACTION_SET_LOCAL_NAME(Action::WaypointSimpleAdd,"Simply Add Waypoint");
47 ACTION_SET_TASK(Action::WaypointSimpleAdd,"add");
48 ACTION_SET_CATEGORY(Action::WaypointSimpleAdd,Action::CATEGORY_WAYPOINT);
49 ACTION_SET_PRIORITY(Action::WaypointSimpleAdd,0);
50 ACTION_SET_VERSION(Action::WaypointSimpleAdd,"0.0");
51 ACTION_SET_CVS_ID(Action::WaypointSimpleAdd,"$Id: waypointsimpleadd.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 Action::WaypointSimpleAdd::WaypointSimpleAdd()
60 {
61         set_dirty(true);
62         waypoint.set_time(Time::begin()-1);
63 }
64
65 Action::ParamVocab
66 Action::WaypointSimpleAdd::get_param_vocab()
67 {
68         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69         
70         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
71                 .set_local_name(_("Destination ValueNode (Animated)"))
72         );
73
74         ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
75                 .set_local_name(_("Waypoint"))
76                 .set_desc(_("Waypoint to be added"))
77         );
78
79         return ret;
80 }
81
82 bool
83 Action::WaypointSimpleAdd::is_canidate(const ParamList &x)
84 {
85         return canidate_check(get_param_vocab(),x);
86 }
87
88 bool
89 Action::WaypointSimpleAdd::set_param(const synfig::String& name, const Action::Param &param)
90 {
91         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
92         {
93                 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
94                 
95                 return static_cast<bool>(value_node);
96         }
97         if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
98         {
99                 waypoint = param.get_waypoint();
100                 
101                 return true;
102         }
103
104         return Action::CanvasSpecific::set_param(name,param);
105 }
106
107 bool
108 Action::WaypointSimpleAdd::is_ready()const
109 {
110         if(!value_node && waypoint.get_time() != (Time::begin()-1))
111                 return false;
112         return Action::CanvasSpecific::is_ready();
113 }
114
115 void
116 Action::WaypointSimpleAdd::perform()
117 {       
118         //remove any pretenders that lie at our destination
119         ValueNode_Animated::findresult iter = value_node->find_time(waypoint.get_time());
120         
121         time_overwrite = false;
122         if(iter.second)
123         {
124                 overwritten_wp = *iter.first;
125                 time_overwrite = true;
126         }
127         
128         //add the value node in since it's safe
129         value_node->add(waypoint);
130         
131         // Signal that a valuenode has been changed
132         value_node->changed();
133 }
134
135 void
136 Action::WaypointSimpleAdd::undo()
137 {
138         //remove our old version...
139         ValueNode_Animated::findresult iter = value_node->find_uid(waypoint);
140         
141         if(!iter.second)
142         {
143                 throw Error(_("The waypoint to remove no longer exists"));
144         }
145         
146         //remove the offending value
147         value_node->erase(*iter.first); //could also just use waypoint
148         
149         if(time_overwrite)
150         {
151                 value_node->add(overwritten_wp);                                
152         }
153         
154         // Signal that a valuenode has been changed
155         value_node->changed();
156 }