1 /* === S Y N F I G ========================================================= */
2 /*! \file waypointremove.cpp
3 ** \brief Template File
5 ** $Id: waypointremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
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.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "waypointremove.h"
32 #include <synfigapp/canvasinterface.h>
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
42 /* === M A C R O S ========================================================= */
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 $");
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 Action::WaypointRemove::WaypointRemove()
61 waypoint.set_time(Time::begin()-1);
66 Action::WaypointRemove::get_param_vocab()
68 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
71 .set_local_name(_("ValueNode (Animated)"))
74 ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
75 .set_local_name(_("Waypoint"))
76 .set_desc(_("Waypoint to be Removed"))
83 Action::WaypointRemove::is_canidate(const ParamList &x)
85 return canidate_check(get_param_vocab(),x);
89 Action::WaypointRemove::set_param(const synfig::String& name, const Action::Param ¶m)
91 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
93 value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
95 return static_cast<bool>(value_node);
97 if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
99 waypoint=param.get_waypoint();
104 return Action::CanvasSpecific::set_param(name,param);
108 Action::WaypointRemove::is_ready()const
110 if(!value_node || waypoint.get_time()==(Time::begin()-1))
112 return Action::CanvasSpecific::is_ready();
116 Action::WaypointRemove::perform()
118 WaypointList::iterator iter(value_node->find(waypoint));
120 if((UniqueID)*iter!=(UniqueID)waypoint)
121 throw Error(_("UniqueID mismatch, iter=%d, waypoint=%d"),iter->get_uid(),waypoint.get_uid());
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());
128 value_node->erase(waypoint);
130 // In this case, we need to convert this to a
131 // constant value node
132 if(value_node->waypoint_list().size()==0)
136 value_node_ref=waypoint.get_value_node();
138 throw Error(_("Unable to create ValueNode_Reference"));
141 value_node->replace(value_node_ref);
142 value_node->waypoint_list().clear();
144 if(get_canvas_interface())
146 get_canvas_interface()->signal_value_node_replaced()(value_node,value_node_ref);
150 value_node->changed();
154 Action::WaypointRemove::undo()
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)"));
161 value_node_ref->replace(value_node);
163 waypoint.set_value_node(value_node_ref);
165 if(get_canvas_interface())
166 get_canvas_interface()->signal_value_node_replaced()(value_node_ref,value_node);
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)"));
172 if(value_node->waypoint_list().size()!=0)
174 try { value_node->find(waypoint.get_time()); throw Error(_("A Waypoint already exists at this point in time"));}
175 catch(synfig::Exception::NotFound) { }
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) { }
181 value_node->add(waypoint);
183 /*_if(get_canvas_interface())
185 get_canvas_interface()->signal_value_node_changed()(value_node);
187 else synfig::warning("CanvasInterface not set on action");*/