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
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "activepointset.h"
33 #include <synfigapp/canvasinterface.h>
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
43 /* === M A C R O S ========================================================= */
45 ACTION_INIT(Action::ActivepointSet);
46 ACTION_SET_NAME(Action::ActivepointSet,"activepoint_set");
47 ACTION_SET_LOCAL_NAME(Action::ActivepointSet,"Set Activepoint");
48 ACTION_SET_TASK(Action::ActivepointSet,"set");
49 ACTION_SET_CATEGORY(Action::ActivepointSet,Action::CATEGORY_ACTIVEPOINT);
50 ACTION_SET_PRIORITY(Action::ActivepointSet,0);
51 ACTION_SET_VERSION(Action::ActivepointSet,"0.0");
52 ACTION_SET_CVS_ID(Action::ActivepointSet,"$Id$");
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 Action::ActivepointSet::ActivepointSet()
66 Action::ActivepointSet::get_param_vocab()
68 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
71 .set_local_name(_("ValueDesc"))
74 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
75 .set_local_name(_("Activepoint"))
76 .set_desc(_("Activepoint to be changed"))
77 .set_supports_multiple()
84 Action::ActivepointSet::is_candidate(const ParamList &x)
86 if(candidate_check(get_param_vocab(),x))
88 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
89 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
98 Action::ActivepointSet::set_param(const synfig::String& name, const Action::Param ¶m)
100 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
102 ValueDesc value_desc(param.get_value_desc());
104 if(!value_desc.parent_is_value_node())
107 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
112 index=value_desc.get_index();
116 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
118 //NOTE: there is no duplication checking at the moment
119 activepoints.push_back(param.get_activepoint());
124 return Action::CanvasSpecific::set_param(name,param);
128 Action::ActivepointSet::is_ready()const
130 if(!value_node || activepoints.empty())
132 return Action::CanvasSpecific::is_ready();
136 Action::ActivepointSet::perform()
138 typedef ValueNode_DynamicList::ListEntry::ActivepointList AList;
139 AList::iterator iter;
142 vector<AList::iterator> iters;
143 vector<Activepoint>::iterator i = activepoints.begin(), end = activepoints.end();
147 try { iters.push_back(value_node->list[index].find(*i)); }
148 catch(synfig::Exception::NotFound)
150 throw Error(_("Unable to find activepoint"));
154 //check to see which valuenodes are going to override because of the time...
155 ValueNode_DynamicList::ListEntry::findresult timeiter;
157 for(i = activepoints.begin(); i != end; ++i)
159 timeiter = value_node->list[index].find_time(i->get_time());
161 bool candelete = timeiter.second;
163 //we only want to track overwrites (not activepoints that are also being modified)
166 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
168 if(timeiter.first == *ii)
176 //if we can still delete it after checking, record it, and then remove them all later
179 Activepoint a = *timeiter.first;
180 overwritten_activepoints.push_back(a);
184 //overwrite all the valuenodes we're supposed to set
186 i = activepoints.begin();
187 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
189 old_activepoints.push_back(**ii);
190 **ii = *i; //set the point to the corresponding point in the normal waypoint list
194 //remove all the points we're supposed to be overwriting
196 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
197 oend = overwritten_activepoints.end();
198 for(; oi != oend; ++oi)
200 value_node->list[index].erase(*oi);
205 try { iter=value_node->list[index].find(activepoint); }
206 catch(synfig::Exception::NotFound)
208 throw Error(_("Unable to find activepoint"));
211 //find the value at the old time before we replace it
212 ValueNode_DynamicList::ListEntry::findresult timeiter;
213 timeiter = value_node->list[index].find_time(activepoint.get_time());
215 //we only want to track overwrites (not inplace modifications)
216 if(timeiter.second && activepoint.get_uid() == timeiter.first->get_uid())
218 timeiter.second = false;
221 old_activepoint=*iter;
226 synfig::info("Erasing the found activepoint");
227 time_overwrite = true;
228 overwritten_ap = *timeiter.first;
230 value_node->list[index].erase(overwritten_ap);
235 value_node->list[index].timing_info.sort();
237 // Signal that a valuenode has been changed
238 value_node->changed();
242 Action::ActivepointSet::undo()
244 ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
247 vector<Activepoint>::iterator i = old_activepoints.begin(), end = old_activepoints.end();
251 try { iter = value_node->list[index].find(*i); }
252 catch(synfig::Exception::NotFound)
254 throw Error(_("Unable to find activepoint"));
257 //overwrite with old one
261 //add back in all the points that we removed before...
263 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
264 oend = overwritten_activepoints.end();
265 for(; oi != oend; ++oi)
267 value_node->list[index].add(*oi);
272 try { iter=value_node->list[index].find(activepoint); }
273 catch(synfig::Exception::NotFound)
275 throw Error(_("Unable to find activepoint"));
278 *iter=old_activepoint;
282 value_node->list[index].add(overwritten_ap);
286 value_node->list[index].timing_info.sort();
288 // Signal that a valuenode has been changed
289 value_node->changed();