my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / timegather.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file timegather.h
3 **      \brief Time Gather Header
4 **
5 **      $Id: timegather.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_TIMEGATHER_H
25 #define __SYNFIG_TIMEGATHER_H
26
27 /* === H E A D E R S ======================================================= */
28 #include <synfig/valuenode_animated.h>
29 #include <synfig/valuenode_dynamiclist.h>
30 #include <synfig/time.h>
31 #include "value_desc.h"
32
33 /* === M A C R O S ========================================================= */
34
35 /* === T Y P E D E F S ===================================================== */
36
37 /* === C L A S S E S & S T R U C T S ======================================= */
38
39 namespace synfigapp {
40
41 class ValueDesc;
42 class synfig::Time;
43
44 struct ValueBaseTimeInfo
45 {
46         synfig::ValueNode_Animated::Handle      val;
47         mutable std::set<synfig::Waypoint>      waypoints;
48         
49         bool operator<(const ValueBaseTimeInfo &rhs) const
50         {
51                 return val < rhs.val;
52         }
53 };
54
55 struct ActiveTimeInfo
56 {
57         struct actcmp
58         {
59                 bool operator()(const synfig::Activepoint &lhs, const synfig::Activepoint &rhs) const
60                 {
61                         return lhs.time < rhs.time;
62                 }               
63         };
64         
65         synfigapp::ValueDesc                                            val;
66         
67         typedef std::set<synfig::Activepoint,actcmp>    set;
68         
69         mutable set activepoints;
70         
71         bool operator<(const ActiveTimeInfo &rhs) const
72         {
73                 return val.get_parent_value_node() == rhs.val.get_parent_value_node() ? 
74                                                 val.get_index() < rhs.val.get_index() : 
75                                                 val.get_parent_value_node() < rhs.val.get_parent_value_node();
76         }
77 };
78
79 struct timepoints_ref
80 {
81         typedef std::set<ValueBaseTimeInfo>             waytracker;     
82         typedef std::set<ActiveTimeInfo>        acttracker;
83         
84         waytracker              waypointbiglist;
85         acttracker              actpointbiglist;        
86         
87         void insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w);  
88         void insert(synfigapp::ValueDesc v, synfig::Activepoint a);
89 };
90
91 //assumes they're sorted... (incremental advance)
92 //checks the intersection of the two sets... might be something better in the stl
93 template < typename I1, typename I2 >
94 bool check_intersect(I1 b1, I1 end1, I2 b2, I2 end2)
95 {
96         if(b1 == end1 || b2 == end2) 
97                 return false;
98         
99         for(; b1 != end1 && b2 != end2;)
100         {
101                 if(*b1 < *b2) ++b1;
102                 else if(*b2 < *b1) ++b2;
103                 else
104                 {
105                         assert(*b1 == *b2);
106                         return true;
107                 }
108         }
109         return false;
110 }
111
112 //pointer kind of a hack, gets the accurate times from a value desc 
113 //      (deals with dynamic list member correctly... i.e. gathers activepoints)
114 const synfig::Node::time_set *get_times_from_vdesc(const synfigapp::ValueDesc &v);
115
116 //get's the closest time inside the set
117 bool get_closest_time(const synfig::Node::time_set &tset, const synfig::Time &t, 
118                                                 const synfig::Time &range, synfig::Time &out);
119
120 //recursion functions based on time restrictions (can be expanded later)...
121 //builds a list of relevant waypoints and activepoints inside the timepoints_ref structure
122 void recurse_valuedesc(synfigapp::ValueDesc valdesc, const std::set<synfig::Time> &tlist,
123                                                                 timepoints_ref &vals);
124 void recurse_layer(synfig::Layer::Handle layer, const std::set<synfig::Time> &tlist, 
125                                                                 timepoints_ref &vals);
126 void recurse_canvas(synfig::Canvas::Handle canvas, const std::set<synfig::Time> &tlist, 
127                                                                 timepoints_ref &vals);
128
129
130
131 }; // END of namespace studio
132
133 /* === E N D =============================================================== */
134
135 #endif