Remove ancient trunk folder from svn repository
[synfig.git] / synfig-studio / src / synfigapp / actions / waypointdisconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file waypointdisconnect.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "waypointdisconnect.h"
34 #include <synfigapp/canvasinterface.h>
35 #include <synfig/valuenode_const.h>
36
37 #include <synfigapp/general.h>
38
39 #endif
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44 using namespace synfigapp;
45 using namespace Action;
46
47 /* === M A C R O S ========================================================= */
48
49 ACTION_INIT(Action::WaypointDisconnect);
50 ACTION_SET_NAME(Action::WaypointDisconnect,"WaypointDisconnect");
51 ACTION_SET_LOCAL_NAME(Action::WaypointDisconnect,N_("Disconnect Waypoint"));
52 ACTION_SET_TASK(Action::WaypointDisconnect,"disconnect");
53 ACTION_SET_CATEGORY(Action::WaypointDisconnect,Action::CATEGORY_WAYPOINT);
54 ACTION_SET_PRIORITY(Action::WaypointDisconnect,0);
55 ACTION_SET_VERSION(Action::WaypointDisconnect,"0.0");
56 ACTION_SET_CVS_ID(Action::WaypointDisconnect,"$Id$");
57
58 /* === G L O B A L S ======================================================= */
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
64 Action::WaypointDisconnect::WaypointDisconnect():
65         waypoint_time_set(false),
66         time_set(false)
67 {
68 }
69
70 Action::ParamVocab
71 Action::WaypointDisconnect::get_param_vocab()
72 {
73         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74
75         ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
76                 .set_local_name(_("Parent ValueNode"))
77         );
78
79         ret.push_back(ParamDesc("waypoint_time",Param::TYPE_TIME)
80                 .set_local_name(_("Waypoint Time"))
81         );
82
83         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
84                 .set_local_name(_("Time"))
85                 .set_optional()
86         );
87
88         return ret;
89 }
90
91 bool
92 Action::WaypointDisconnect::is_candidate(const ParamList &x)
93 {
94         return candidate_check(get_param_vocab(),x);
95 }
96
97 bool
98 Action::WaypointDisconnect::set_param(const synfig::String& name, const Action::Param &param)
99 {
100         if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
101         {
102                 parent_value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
103
104                 return static_cast<bool>(parent_value_node);
105         }
106
107         if(name=="waypoint_time" && param.get_type()==Param::TYPE_TIME)
108         {
109                 waypoint_time=param.get_time();
110                 waypoint_time_set=true;
111
112                 return true;
113         }
114
115         if(name=="time" && param.get_type()==Param::TYPE_TIME)
116         {
117                 time=param.get_time();
118                 time_set=true;
119
120                 return true;
121         }
122
123         return Action::CanvasSpecific::set_param(name,param);
124 }
125
126 bool
127 Action::WaypointDisconnect::is_ready()const
128 {
129         if(!parent_value_node || !waypoint_time_set)
130                 return false;
131         return Action::CanvasSpecific::is_ready();
132 }
133
134 void
135 Action::WaypointDisconnect::perform()
136 {
137         ValueNode_Animated::WaypointList::iterator iter(parent_value_node->find(waypoint_time));
138
139         old_value_node=iter->get_value_node();
140
141         iter->set_value_node(ValueNode_Const::create((*old_value_node)(time_set ? time : waypoint_time)));
142
143         /*
144         if(get_canvas()->get_time()!=time)
145                 set_dirty(true);
146         else
147                 set_dirty(false);
148
149         if(get_canvas_interface())
150         {
151                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
152         }
153         */
154 }
155
156 void
157 Action::WaypointDisconnect::undo()
158 {
159         ValueNode_Animated::WaypointList::iterator iter(parent_value_node->find(waypoint_time));
160
161         iter->set_value_node(old_value_node);
162
163         /*if(get_canvas()->get_time()!=time)
164                 set_dirty(true);
165         else
166                 set_dirty(false);
167
168         if(get_canvas_interface())
169         {
170                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
171         }*/
172 }