1 /* === S Y N F I G ========================================================= */
2 /*! \file timegather.cpp
3 ** \brief Time Gather File
5 ** $Id: timegather.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2004 Adrian Bentley
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 "timegather.h"
32 #include "value_desc.h"
34 #include <synfig/layer_pastecanvas.h>
38 /* === U S I N G =========================================================== */
42 using namespace synfig;
43 using namespace synfigapp;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 /* === E N T R Y P O I N T ================================================= */
55 //! Definitions for build a list of accurate valuenode references
57 void synfigapp::timepoints_ref::insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w)
62 waytracker::iterator i = waypointbiglist.find(vt);
64 if(i != waypointbiglist.end())
66 i->waypoints.insert(w);
69 vt.waypoints.insert(w);
70 waypointbiglist.insert(vt);
74 void synfigapp::timepoints_ref::insert(synfigapp::ValueDesc v, synfig::Activepoint a)
79 acttracker::iterator i = actpointbiglist.find(vt);
81 if(i != actpointbiglist.end())
83 i->activepoints.insert(a);
85 synfig::info("!!!!For some reason it wasn't able to insert the activepoint in the list (%s,%.4lg)",
86 a.state?"true":"false", (double)a.time);
90 vt.activepoints.insert(a);
91 actpointbiglist.insert(vt);
92 //synfig::info("Insert new activept list for valdesc");
97 void synfigapp::recurse_canvas(synfig::Canvas::Handle h, const std::set<Time> &tlist,
101 //synfig::info("Canvas...\n Recurse through layers");
102 // iterate through the layers
104 synfig::Canvas::iterator i = h->begin(), end = h->end();
108 const Node::time_set &tset = (*i)->get_times();
109 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
111 recurse_layer(*i,tlist,vals);
116 void synfigapp::recurse_layer(synfig::Layer::Handle h, const std::set<Time> &tlist,
117 timepoints_ref &vals)
119 // iterate through the layers
120 //check for special case of paste canvas
121 etl::handle<synfig::Layer_PasteCanvas> p = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(h);
123 //synfig::info("Layer...");
127 //synfig::info("We are a paste canvas so go into that");
128 //recurse into the canvas
129 const synfig::Node::time_set &tset = p->get_sub_canvas()->get_times();
131 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
133 //we have to offset the times so it won't wreck havoc if the canvas is imported more than once...
134 // and so we get correct results when offsets are present
135 std::set<Time> tlistoff;
136 std::set<Time>::iterator i = tlist.begin(), end = tlist.end();
139 tlistoff.insert(*i - p->get_time_offset());
142 recurse_canvas(p->get_sub_canvas(),tlist,vals);
146 //check all the valuenodes regardless...
147 //synfig::info("Recurse all valuenodes");
148 synfig::Layer::DynamicParamList::const_iterator i = h->dynamic_param_list().begin(),
149 end = h->dynamic_param_list().end();
152 const synfig::Node::time_set &tset = i->second->get_times();
154 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
156 recurse_valuedesc(ValueDesc(h,i->first),tlist,vals);
161 template < typename IT, typename CMP >
162 static bool sorted(IT i,IT end, const CMP &cmp = CMP())
164 if(i == end) return true;
166 for(IT last = i++; i != end; last = i++)
175 void synfigapp::recurse_valuedesc(synfigapp::ValueDesc h, const std::set<Time> &tlist,
176 timepoints_ref &vals)
178 //special cases for Animated, DynamicList, and Linkable
180 //synfig::info("ValueBasenode... %p, %s", h.get_value_node().get(),typeid(*h.get_value_node()).name());
185 synfig::ValueNode_Animated::Handle p = synfig::ValueNode_Animated::Handle::cast_dynamic(h.get_value_node());
189 //loop through and determine which waypoint we will need to reference
190 const synfig::WaypointList &w = p->waypoint_list();
192 synfig::WaypointList::const_iterator i = w.begin(),
195 std::set<Time>::const_iterator j = tlist.begin(),
197 for(; i != end && j != jend;)
199 //synfig::info("tpair t(%.3f) = %.3f", (float)*j, (float)(i->get_time()));
201 if(j->is_equal(i->get_time()))
214 //parent dynamiclist case - just for active points for that object...
215 if(h.parent_is_value_node())
217 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_parent_value_node());
221 int index = h.get_index();
223 //check all the active points in each list...
224 const synfig::ActivepointList &a = p->list[index].timing_info;
226 //synfig::info("Our parent = dynamic list, searching in %d activepts",a.size());
228 std::set<Time>::const_iterator i = tlist.begin(),
231 synfig::ActivepointList::const_iterator j = a.begin(),
234 for(; j != jend && i != end;)
237 double jt = j->get_time();
238 double diff = (double)(it - jt);
240 //synfig::info("\ttpair match(%.4lg) - %.4lg (diff = %lg",it,jt,diff);
243 if(abs(diff) < (double)Time::epsilon())
245 //synfig::info("\tActivepoint to add being referenced (%x,%s,%.4lg)",
246 // (int)j->get_uid(),j->state?"true":"false", (double)j->time);
247 vals.insert(ValueDesc(p,index),*j);
252 //synfig::info("\tIncrementing time");
257 //synfig::info("\tIncrementing actpt");
263 //dynamiclist case - we must still make sure that we read from the list entries the time values
264 // because just the linked valuenodes will not do that
266 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_value_node());
270 //synfig::info("Process dynamic list valuenode");
273 std::vector<synfig::ValueNode_DynamicList::ListEntry>::const_iterator
277 for(; i != end; ++i, ++index)
279 const Node::time_set &tset = i->get_times();
281 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
283 recurse_valuedesc(ValueDesc(p,index),tlist,vals);
290 //the linkable case...
292 etl::handle<synfig::LinkableValueNode> p = etl::handle<synfig::LinkableValueNode>::cast_dynamic(h.get_value_node());
296 //synfig::info("Process Linkable ValueBasenode");
297 int i = 0, size = p->link_count();
301 ValueNode::Handle v = p->get_link(i);
302 const Node::time_set &tset = v->get_times();
304 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end()))
306 recurse_valuedesc(ValueDesc(p,i),tlist,vals);