1 /* === S Y N F I G ========================================================= */
2 /*! \file timegather.cpp
3 ** \brief Time Gather File
8 ** Copyright (c) 2004 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 "timegather.h"
33 #include "value_desc.h"
35 #include <synfig/layer_pastecanvas.h>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace synfigapp;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 /* === E N T R Y P O I N T ================================================= */
56 //! Definitions for build a list of accurate valuenode references
58 void synfigapp::timepoints_ref::insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w)
63 waytracker::iterator i = waypointbiglist.find(vt);
65 if(i != waypointbiglist.end())
67 i->waypoints.insert(w);
70 vt.waypoints.insert(w);
71 waypointbiglist.insert(vt);
75 void synfigapp::timepoints_ref::insert(synfigapp::ValueDesc v, synfig::Activepoint a)
80 acttracker::iterator i = actpointbiglist.find(vt);
82 if(i != actpointbiglist.end())
84 i->activepoints.insert(a);
86 synfig::info("!!!!For some reason it wasn't able to insert the activepoint in the list (%s,%.4lg)",
87 a.state?"true":"false", (double)a.time);
91 vt.activepoints.insert(a);
92 actpointbiglist.insert(vt);
93 //synfig::info("Insert new activept list for valdesc");
98 void synfigapp::recurse_canvas(synfig::Canvas::Handle h, const std::set<Time> &tlist,
102 //synfig::info("Canvas...\n Recurse through layers");
103 // iterate through the layers
105 synfig::Canvas::iterator i = h->begin(), end = h->end();
109 const Node::time_set &tset = (*i)->get_times();
110 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
112 recurse_layer(*i,tlist,vals);
117 void synfigapp::recurse_layer(synfig::Layer::Handle h, const std::set<Time> &tlist,
118 timepoints_ref &vals)
120 // iterate through the layers
121 //check for special case of paste canvas
122 etl::handle<synfig::Layer_PasteCanvas> p = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(h);
124 //synfig::info("Layer...");
128 //synfig::info("We are a paste canvas so go into that");
129 //recurse into the canvas
130 const synfig::Node::time_set &tset = p->get_sub_canvas()->get_times();
132 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
134 //we have to offset the times so it won't wreck havoc if the canvas is imported more than once...
135 // and so we get correct results when offsets are present
136 std::set<Time> tlistoff;
137 std::set<Time>::iterator i = tlist.begin(), end = tlist.end();
140 tlistoff.insert(*i - p->get_time_offset());
143 recurse_canvas(p->get_sub_canvas(),tlist,vals);
147 //check all the valuenodes regardless...
148 //synfig::info("Recurse all valuenodes");
149 synfig::Layer::DynamicParamList::const_iterator i = h->dynamic_param_list().begin(),
150 end = h->dynamic_param_list().end();
153 const synfig::Node::time_set &tset = i->second->get_times();
155 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
157 recurse_valuedesc(ValueDesc(h,i->first),tlist,vals);
162 template < typename IT, typename CMP >
163 static bool sorted(IT i,IT end, const CMP &cmp = CMP())
165 if(i == end) return true;
167 for(IT last = i++; i != end; last = i++)
176 void synfigapp::recurse_valuedesc(synfigapp::ValueDesc h, const std::set<Time> &tlist,
177 timepoints_ref &vals)
179 //special cases for Animated, DynamicList, and Linkable
181 //synfig::info("ValueBasenode... %p, %s", h.get_value_node().get(),typeid(*h.get_value_node()).name());
186 synfig::ValueNode_Animated::Handle p = synfig::ValueNode_Animated::Handle::cast_dynamic(h.get_value_node());
190 //loop through and determine which waypoint we will need to reference
191 const synfig::WaypointList &w = p->waypoint_list();
193 synfig::WaypointList::const_iterator i = w.begin(),
196 std::set<Time>::const_iterator j = tlist.begin(),
198 for(; i != end && j != jend;)
200 //synfig::info("tpair t(%.3f) = %.3f", (float)*j, (float)(i->get_time()));
202 if(j->is_equal(i->get_time()))
215 //parent dynamiclist case - just for active points for that object...
216 if(h.parent_is_value_node())
218 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_parent_value_node());
222 int index = h.get_index();
224 //check all the active points in each list...
225 const synfig::ActivepointList &a = p->list[index].timing_info;
227 //synfig::info("Our parent = dynamic list, searching in %d activepts",a.size());
229 std::set<Time>::const_iterator i = tlist.begin(),
232 synfig::ActivepointList::const_iterator j = a.begin(),
235 for(; j != jend && i != end;)
238 double jt = j->get_time();
239 double diff = (double)(it - jt);
241 //synfig::info("\ttpair match(%.4lg) - %.4lg (diff = %lg",it,jt,diff);
244 if(abs(diff) < (double)Time::epsilon())
246 //synfig::info("\tActivepoint to add being referenced (%x,%s,%.4lg)",
247 // (int)j->get_uid(),j->state?"true":"false", (double)j->time);
248 vals.insert(ValueDesc(p,index),*j);
253 //synfig::info("\tIncrementing time");
258 //synfig::info("\tIncrementing actpt");
264 //dynamiclist case - we must still make sure that we read from the list entries the time values
265 // because just the linked valuenodes will not do that
267 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_value_node());
271 //synfig::info("Process dynamic list valuenode");
274 std::vector<synfig::ValueNode_DynamicList::ListEntry>::const_iterator
278 for(; i != end; ++i, ++index)
280 const Node::time_set &tset = i->get_times();
282 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
284 recurse_valuedesc(ValueDesc(p,index),tlist,vals);
291 //the linkable case...
293 etl::handle<synfig::LinkableValueNode> p = etl::handle<synfig::LinkableValueNode>::cast_dynamic(h.get_value_node());
297 //synfig::info("Process Linkable ValueBasenode");
298 int i = 0, size = p->link_count();
302 ValueNode::Handle v = p->get_link(i);
303 const Node::time_set &tset = v->get_times();
305 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
307 recurse_valuedesc(ValueDesc(p,i),tlist,vals);