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>
35 #include <synfigapp/general.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::ActivepointSet);
48 ACTION_SET_NAME(Action::ActivepointSet,"activepoint_set");
49 ACTION_SET_LOCAL_NAME(Action::ActivepointSet,N_("Set Activepoint"));
50 ACTION_SET_TASK(Action::ActivepointSet,"set");
51 ACTION_SET_CATEGORY(Action::ActivepointSet,Action::CATEGORY_ACTIVEPOINT);
52 ACTION_SET_PRIORITY(Action::ActivepointSet,0);
53 ACTION_SET_VERSION(Action::ActivepointSet,"0.0");
54 ACTION_SET_CVS_ID(Action::ActivepointSet,"$Id$");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::ActivepointSet::ActivepointSet()
68 Action::ActivepointSet::get_param_vocab()
70 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
73 .set_local_name(_("ValueDesc"))
76 ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
77 .set_local_name(_("Activepoint"))
78 .set_desc(_("Activepoint to be changed"))
79 .set_supports_multiple()
86 Action::ActivepointSet::is_candidate(const ParamList &x)
88 if (!candidate_check(get_param_vocab(),x))
91 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
93 return (value_desc.parent_is_value_node() &&
94 // We need a dynamic list.
95 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
99 Action::ActivepointSet::set_param(const synfig::String& name, const Action::Param ¶m)
101 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
103 ValueDesc value_desc(param.get_value_desc());
105 if(!value_desc.parent_is_value_node())
108 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
113 index=value_desc.get_index();
117 if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
119 //NOTE: there is no duplication checking at the moment
120 activepoints.push_back(param.get_activepoint());
125 return Action::CanvasSpecific::set_param(name,param);
129 Action::ActivepointSet::is_ready()const
131 if(!value_node || activepoints.empty())
133 return Action::CanvasSpecific::is_ready();
137 Action::ActivepointSet::perform()
139 typedef ValueNode_DynamicList::ListEntry::ActivepointList AList;
140 AList::iterator iter;
143 vector<AList::iterator> iters;
144 vector<Activepoint>::iterator i = activepoints.begin(), end = activepoints.end();
148 try { iters.push_back(value_node->list[index].find(*i)); }
149 catch(synfig::Exception::NotFound)
151 throw Error(_("Unable to find activepoint"));
155 //check to see which valuenodes are going to override because of the time...
156 ValueNode_DynamicList::ListEntry::findresult timeiter;
158 for(i = activepoints.begin(); i != end; ++i)
160 timeiter = value_node->list[index].find_time(i->get_time());
162 bool candelete = timeiter.second;
164 //we only want to track overwrites (not activepoints that are also being modified)
167 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end(); ++ii)
169 if(timeiter.first == *ii)
177 //if we can still delete it after checking, record it, and then remove them all later
180 Activepoint a = *timeiter.first;
181 overwritten_activepoints.push_back(a);
185 //overwrite all the valuenodes we're supposed to set
187 i = activepoints.begin();
188 for(vector<AList::iterator>::iterator ii = iters.begin(); ii != iters.end() && i != end; ++ii, ++i)
190 old_activepoints.push_back(**ii);
191 **ii = *i; //set the point to the corresponding point in the normal waypoint list
195 //remove all the points we're supposed to be overwriting
197 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
198 oend = overwritten_activepoints.end();
199 for(; oi != oend; ++oi)
201 value_node->list[index].erase(*oi);
206 try { iter=value_node->list[index].find(activepoint); }
207 catch(synfig::Exception::NotFound)
209 throw Error(_("Unable to find activepoint"));
212 //find the value at the old time before we replace it
213 ValueNode_DynamicList::ListEntry::findresult timeiter;
214 timeiter = value_node->list[index].find_time(activepoint.get_time());
216 //we only want to track overwrites (not inplace modifications)
217 if(timeiter.second && activepoint.get_uid() == timeiter.first->get_uid())
219 timeiter.second = false;
222 old_activepoint=*iter;
227 synfig::info("Erasing the found activepoint");
228 time_overwrite = true;
229 overwritten_ap = *timeiter.first;
231 value_node->list[index].erase(overwritten_ap);
236 value_node->list[index].timing_info.sort();
238 // Signal that a valuenode has been changed
239 value_node->changed();
243 Action::ActivepointSet::undo()
245 ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
248 vector<Activepoint>::iterator i = old_activepoints.begin(), end = old_activepoints.end();
252 try { iter = value_node->list[index].find(*i); }
253 catch(synfig::Exception::NotFound)
255 throw Error(_("Unable to find activepoint"));
258 //overwrite with old one
262 //add back in all the points that we removed before...
264 vector<Activepoint>::iterator oi = overwritten_activepoints.begin(),
265 oend = overwritten_activepoints.end();
266 for(; oi != oend; ++oi)
268 value_node->list[index].add(*oi);
273 try { iter=value_node->list[index].find(activepoint); }
274 catch(synfig::Exception::NotFound)
276 throw Error(_("Unable to find activepoint"));
279 *iter=old_activepoint;
283 value_node->list[index].add(overwritten_ap);
287 value_node->list[index].timing_info.sort();
289 // Signal that a valuenode has been changed
290 value_node->changed();