my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / waypointremove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file waypointremove.cpp
3 **      \brief Template File
4 **
5 **      $Id: waypointremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
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 "waypointremove.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::WaypointRemove);
45 ACTION_SET_NAME(Action::WaypointRemove,"waypoint_remove");
46 ACTION_SET_LOCAL_NAME(Action::WaypointRemove,"Remove Waypoint");
47 ACTION_SET_TASK(Action::WaypointRemove,"remove");
48 ACTION_SET_CATEGORY(Action::WaypointRemove,Action::CATEGORY_WAYPOINT);
49 ACTION_SET_PRIORITY(Action::WaypointRemove,0);
50 ACTION_SET_VERSION(Action::WaypointRemove,"0.0");
51 ACTION_SET_CVS_ID(Action::WaypointRemove,"$Id: waypointremove.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::WaypointRemove::WaypointRemove()
60 {
61         waypoint.set_time(Time::begin()-1);
62         set_dirty(true);
63 }
64
65 Action::ParamVocab
66 Action::WaypointRemove::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(_("ValueNode (Animated)"))
72         );
73
74         ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
75                 .set_local_name(_("Waypoint"))
76                 .set_desc(_("Waypoint to be Removed"))
77         );
78
79         return ret;
80 }
81
82 bool
83 Action::WaypointRemove::is_canidate(const ParamList &x)
84 {
85         return canidate_check(get_param_vocab(),x);
86 }
87
88 bool
89 Action::WaypointRemove::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::WaypointRemove::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::WaypointRemove::perform()
117 {       
118         WaypointList::iterator iter(value_node->find(waypoint));
119
120         if((UniqueID)*iter!=(UniqueID)waypoint)
121                 throw Error(_("UniqueID mismatch, iter=%d, waypoint=%d"),iter->get_uid(),waypoint.get_uid());
122
123         if(iter->get_time()!=waypoint.get_time())
124                 throw Error(_("Time mismatch iter=%s, waypoint=%s"),iter->get_time().get_string().c_str(),waypoint.get_time().get_string().c_str());
125         
126         waypoint=*iter;
127         
128         value_node->erase(waypoint);
129
130         // In this case, we need to convert this to a
131         // constant value node
132         if(value_node->waypoint_list().size()==0)
133         {
134                 if(!value_node_ref)
135                 {
136                         value_node_ref=waypoint.get_value_node();
137                         if(!value_node_ref)
138                                 throw Error(_("Unable to create ValueNode_Reference"));
139                 }
140                 
141                 value_node->replace(value_node_ref);
142                 value_node->waypoint_list().clear();
143                 
144                 if(get_canvas_interface())
145                 {
146                         get_canvas_interface()->signal_value_node_replaced()(value_node,value_node_ref);
147                 }
148         }
149
150         value_node->changed();
151 }
152
153 void
154 Action::WaypointRemove::undo()
155 {
156         if(value_node_ref)
157         {
158                 if(value_node->waypoint_list().size()!=0)
159                         throw Error(_("This animated value node should be empty, but for some reason it isn't. This is a bug. (1)"));
160                 
161                 value_node_ref->replace(value_node);
162                 
163                 waypoint.set_value_node(value_node_ref);
164                 
165                 if(get_canvas_interface())
166                         get_canvas_interface()->signal_value_node_replaced()(value_node_ref,value_node);
167
168                 if(value_node->waypoint_list().size()!=0)
169                         throw Error(_("This animated value node should be empty, but for some reason it isn't. This is a bug. (2)"));
170         }
171
172         if(value_node->waypoint_list().size()!=0)
173         {
174                 try { value_node->find(waypoint.get_time()); throw Error(_("A Waypoint already exists at this point in time"));}
175                 catch(synfig::Exception::NotFound) { }  
176                 
177                 try { if(value_node->find(waypoint)!=value_node->waypoint_list().end()) throw Error(_("This waypoint is already in the ValueNode"));}
178                 catch(synfig::Exception::NotFound) { }  
179         }
180         
181         value_node->add(waypoint);
182         
183 /*_if(get_canvas_interface())
184         {
185                 get_canvas_interface()->signal_value_node_changed()(value_node);
186         }
187         else synfig::warning("CanvasInterface not set on action");*/
188 }