1 | /* === S Y N F I G ========================================================= */ |
---|
2 | /*! \file waypointremove.cpp |
---|
3 | ** \brief Template File |
---|
4 | ** |
---|
5 | ** $Id$ |
---|
6 | ** |
---|
7 | ** \legal |
---|
8 | ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., 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 "waypointremove.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::WaypointRemove); |
---|
48 | ACTION_SET_NAME(Action::WaypointRemove,"WaypointRemove"); |
---|
49 | ACTION_SET_LOCAL_NAME(Action::WaypointRemove,N_("Remove Waypoint")); |
---|
50 | ACTION_SET_TASK(Action::WaypointRemove,"remove"); |
---|
51 | ACTION_SET_CATEGORY(Action::WaypointRemove,Action::CATEGORY_WAYPOINT); |
---|
52 | ACTION_SET_PRIORITY(Action::WaypointRemove,0); |
---|
53 | ACTION_SET_VERSION(Action::WaypointRemove,"0.0"); |
---|
54 | ACTION_SET_CVS_ID(Action::WaypointRemove,"$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::WaypointRemove::WaypointRemove() |
---|
63 | { |
---|
64 | waypoint.set_time(Time::begin()-1); |
---|
65 | set_dirty(true); |
---|
66 | } |
---|
67 | |
---|
68 | Action::ParamVocab |
---|
69 | Action::WaypointRemove::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(_("ValueNode (Animated)")) |
---|
75 | ); |
---|
76 | |
---|
77 | ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT) |
---|
78 | .set_local_name(_("Waypoint")) |
---|
79 | .set_desc(_("Waypoint to be Removed")) |
---|
80 | ); |
---|
81 | |
---|
82 | return ret; |
---|
83 | } |
---|
84 | |
---|
85 | bool |
---|
86 | Action::WaypointRemove::is_candidate(const ParamList &x) |
---|
87 | { |
---|
88 | return candidate_check(get_param_vocab(),x); |
---|
89 | } |
---|
90 | |
---|
91 | bool |
---|
92 | Action::WaypointRemove::set_param(const synfig::String& name, const Action::Param ¶m) |
---|
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::WaypointRemove::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::WaypointRemove::perform() |
---|
120 | { |
---|
121 | WaypointList::iterator iter(value_node->find(waypoint)); |
---|
122 | |
---|
123 | if((UniqueID)*iter!=(UniqueID)waypoint) |
---|
124 | throw Error(_("UniqueID mismatch, iter=%d, waypoint=%d"),iter->get_uid(),waypoint.get_uid()); |
---|
125 | |
---|
126 | if(iter->get_time()!=waypoint.get_time()) |
---|
127 | throw Error(_("Time mismatch iter=%s, waypoint=%s"),iter->get_time().get_string().c_str(),waypoint.get_time().get_string().c_str()); |
---|
128 | |
---|
129 | waypoint=*iter; |
---|
130 | |
---|
131 | value_node->erase(waypoint); |
---|
132 | |
---|
133 | // In this case, we need to convert this to a |
---|
134 | // constant value node |
---|
135 | if(value_node->waypoint_list().size()==0) |
---|
136 | { |
---|
137 | if(!value_node_ref) |
---|
138 | { |
---|
139 | value_node_ref=waypoint.get_value_node(); |
---|
140 | if(!value_node_ref) |
---|
141 | throw Error(_("Unable to create ValueNode_Reference")); |
---|
142 | } |
---|
143 | |
---|
144 | // fix 2256600 (and 2321845) : deleting the last waypoint of an exported valuenode unexported it |
---|
145 | // if the waypoint's value isn't exported, set its id to be the id of the parent node |
---|
146 | if (value_node_ref->get_id() == "" && value_node->get_id() != "") |
---|
147 | { |
---|
148 | const String id(value_node->get_id()); |
---|
149 | Canvas::LooseHandle canvas(value_node->get_parent_canvas()); |
---|
150 | canvas->remove_value_node(value_node, false); |
---|
151 | canvas->add_value_node(value_node_ref, id); |
---|
152 | } |
---|
153 | |
---|
154 | value_node->replace(value_node_ref); |
---|
155 | value_node->editable_waypoint_list().clear(); |
---|
156 | |
---|
157 | if(get_canvas_interface()) |
---|
158 | { |
---|
159 | get_canvas_interface()->signal_value_node_replaced()(value_node,value_node_ref); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | value_node->changed(); |
---|
164 | } |
---|
165 | |
---|
166 | void |
---|
167 | Action::WaypointRemove::undo() |
---|
168 | { |
---|
169 | if(value_node_ref) |
---|
170 | { |
---|
171 | if(value_node->waypoint_list().size()!=0) |
---|
172 | throw Error(_("This animated value node should be empty, but for some reason it isn't. This is a bug. (1)")); |
---|
173 | |
---|
174 | if (value_node->get_id() == "" && value_node_ref->get_id() != "") |
---|
175 | { |
---|
176 | const String id(value_node_ref->get_id()); |
---|
177 | Canvas::LooseHandle canvas(value_node_ref->get_parent_canvas()); |
---|
178 | canvas->remove_value_node(value_node_ref, false); |
---|
179 | canvas->add_value_node(value_node, id); |
---|
180 | } |
---|
181 | |
---|
182 | value_node_ref->replace(value_node); |
---|
183 | |
---|
184 | waypoint.set_value_node(value_node_ref); |
---|
185 | |
---|
186 | if(get_canvas_interface()) |
---|
187 | get_canvas_interface()->signal_value_node_replaced()(value_node_ref,value_node); |
---|
188 | |
---|
189 | if(value_node->waypoint_list().size()!=0) |
---|
190 | throw Error(_("This animated value node should be empty, but for some reason it isn't. This is a bug. (2)")); |
---|
191 | } |
---|
192 | |
---|
193 | if(value_node->waypoint_list().size()!=0) |
---|
194 | { |
---|
195 | try { value_node->find(waypoint.get_time()); throw Error(_("A Waypoint already exists at this point in time"));} |
---|
196 | catch(synfig::Exception::NotFound) { } |
---|
197 | |
---|
198 | try { if(value_node->find(waypoint)!=value_node->waypoint_list().end()) throw Error(_("This waypoint is already in the ValueNode"));} |
---|
199 | catch(synfig::Exception::NotFound) { } |
---|
200 | } |
---|
201 | |
---|
202 | value_node->add(waypoint); |
---|
203 | |
---|
204 | /*_if(get_canvas_interface()) |
---|
205 | { |
---|
206 | get_canvas_interface()->signal_value_node_changed()(value_node); |
---|
207 | } |
---|
208 | else synfig::warning("CanvasInterface not set on action");*/ |
---|
209 | } |
---|