1 /* === S Y N F I G ========================================================= */
2 /*! \file activepointset.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "activepointset.h"
34 #include <synfigapp/canvasinterface.h>
36 #include <synfigapp/general.h>
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT(Action::ActivepointSet);
49 ACTION_SET_NAME(Action::ActivepointSet,"activepoint_set");
50 ACTION_SET_LOCAL_NAME(Action::ActivepointSet,N_("Set Activepoint"));
51 ACTION_SET_TASK(Action::ActivepointSet,"set");
52 ACTION_SET_CATEGORY(Action::ActivepointSet,Action::CATEGORY_ACTIVEPOINT);
53 ACTION_SET_PRIORITY(Action::ActivepointSet,0);
54 ACTION_SET_VERSION(Action::ActivepointSet,"0.0");
55 ACTION_SET_CVS_ID(Action::ActivepointSet,"$Id$");
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Action::ActivepointSet::ActivepointSet()
69 Action::ActivepointSet::get_param_vocab()
71 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
74 .set_local_name(_("ValueDesc"))
77 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
78 .set_local_name(_("Activepoint"))
79 .set_desc(_("Activepoint to be changed"))
80 .set_supports_multiple()
87 Action::ActivepointSet::is_candidate(const ParamList &x)
89 if (!candidate_check(get_param_vocab(),x))
92 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
94 return (value_desc.parent_is_value_node() &&
95 // We need a dynamic list.
96 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
100 Action::ActivepointSet::set_param(const synfig::String& name, const Action::Param ¶m)
102 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
104 ValueDesc value_desc(param.get_value_desc());
106 if(!value_desc.parent_is_value_node())
109 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
114 index=value_desc.get_index();
118 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
120 //NOTE: there is no duplication checking at the moment
121 activepoints.push_back(param.get_activepoint());
126 return Action::CanvasSpecific::set_param(name,param);
130 Action::ActivepointSet::is_ready()const
132 if(!value_node || activepoints.empty())
134 return Action::CanvasSpecific::is_ready();
138 Action::ActivepointSet::perform()
140 typedef ValueNode_DynamicList::ListEntry::ActivepointList AList;
141 AList::iterator iter;
144 vector<AList::iterator> iters;
145 vector<Activepoint>::iterator i = activepoints.begin(), end = activepoints.end();
149 try { iters.push_back(value_node->list[index].find(*i)); }
150 catch(synfig::Exception::NotFound)
152 throw Error(_("Unable to find activepoint"));
156 //check to see which valuenodes are going to override because of the time...
157 ValueNode_DynamicList::ListEntry::findresult timeiter;
159 for(i = activepoints.begin(); i != end; ++i)
161 timeiter = value_node->list[index].find_time(i->get_time());
163 bool candelete = timeiter.second;
165 //we only want to track overwrites (not activepoints that are also being modified)
168 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
170 if(timeiter.first == *ii)
178 //if we can still delete it after checking, record it, and then remove them all later
181 Activepoint a = *timeiter.first;
182 overwritten_activepoints.push_back(a);
186 //overwrite all the valuenodes we're supposed to set
188 i = activepoints.begin();
189 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
191 old_activepoints.push_back(**ii);
192 **ii = *i; //set the point to the corresponding point in the normal waypoint list
196 //remove all the points we're supposed to be overwriting
198 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
199 oend = overwritten_activepoints.end();
200 for(; oi != oend; ++oi)
202 value_node->list[index].erase(*oi);
207 try { iter=value_node->list[index].find(activepoint); }
208 catch(synfig::Exception::NotFound)
210 throw Error(_("Unable to find activepoint"));
213 //find the value at the old time before we replace it
214 ValueNode_DynamicList::ListEntry::findresult timeiter;
215 timeiter = value_node->list[index].find_time(activepoint.get_time());
217 //we only want to track overwrites (not inplace modifications)
218 if(timeiter.second && activepoint.get_uid() == timeiter.first->get_uid())
220 timeiter.second = false;
223 old_activepoint=*iter;
228 synfig::info("Erasing the found activepoint");
229 time_overwrite = true;
230 overwritten_ap = *timeiter.first;
232 value_node->list[index].erase(overwritten_ap);
237 value_node->list[index].timing_info.sort();
239 // Signal that a valuenode has been changed
240 value_node->changed();
244 Action::ActivepointSet::undo()
246 ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
249 vector<Activepoint>::iterator i = old_activepoints.begin(), end = old_activepoints.end();
253 try { iter = value_node->list[index].find(*i); }
254 catch(synfig::Exception::NotFound)
256 throw Error(_("Unable to find activepoint"));
259 //overwrite with old one
263 //add back in all the points that we removed before...
265 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
266 oend = overwritten_activepoints.end();
267 for(; oi != oend; ++oi)
269 value_node->list[index].add(*oi);
274 try { iter=value_node->list[index].find(activepoint); }
275 catch(synfig::Exception::NotFound)
277 throw Error(_("Unable to find activepoint"));
280 *iter=old_activepoint;
284 value_node->list[index].add(overwritten_ap);
288 value_node->list[index].timing_info.sort();
290 // Signal that a valuenode has been changed
291 value_node->changed();