34d66a28736d0eb664eeedb34316a132f30779fa
[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$
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_TIMEGATHER_H
26 #define __SYNFIG_TIMEGATHER_H
27
28 /* === H E A D E R S ======================================================= */
29 #include <synfig/valuenode_animated.h>
30 #include <synfig/valuenode_dynamiclist.h>
31 #include <synfig/time.h>
32 #include "value_desc.h"
33
34 /* === M A C R O S ========================================================= */
35
36 /* === T Y P E D E F S ===================================================== */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfig {
41         class Time;
42 }
43
44 namespace synfigapp {
45
46 class ValueDesc;
47
48 struct ValueBaseTimeInfo
49 {
50         synfig::ValueNode_Animated::Handle      val;
51         mutable std::set<synfig::Waypoint>      waypoints;
52
53         bool operator<(const ValueBaseTimeInfo &rhs) const
54         {
55                 return val < rhs.val;
56         }
57 };
58
59 struct ActiveTimeInfo
60 {
61         struct actcmp
62         {
63                 bool operator()(const synfig::Activepoint &lhs, const synfig::Activepoint &rhs) const
64                 {
65                         return lhs.time < rhs.time;
66                 }
67         };
68
69         synfigapp::ValueDesc                                            val;
70
71         typedef std::set<synfig::Activepoint,actcmp>    set;
72
73         mutable set activepoints;
74
75         bool operator<(const ActiveTimeInfo &rhs) const
76         {
77                 return val.get_parent_value_node() == rhs.val.get_parent_value_node() ?
78                                                 val.get_index() < rhs.val.get_index() :
79                                                 val.get_parent_value_node() < rhs.val.get_parent_value_node();
80         }
81 };
82
83 struct timepoints_ref
84 {
85         typedef std::set<ValueBaseTimeInfo>             waytracker;
86         typedef std::set<ActiveTimeInfo>        acttracker;
87
88         waytracker              waypointbiglist;
89         acttracker              actpointbiglist;
90
91         void insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w);
92         void insert(synfigapp::ValueDesc v, synfig::Activepoint a);
93 };
94
95 //assumes they're sorted... (incremental advance)
96 //checks the intersection of the two sets... might be something better in the stl
97 template < typename I1, typename I2 >
98 bool check_intersect(I1 b1, I1 end1, I2 b2, I2 end2, synfig::Time time_offset = 0)
99 {
100         if(b1 == end1 || b2 == end2)
101                 return false;
102
103         for(; b1 != end1 && b2 != end2;)
104         {
105                 if(*b1 < *b2 + time_offset) ++b1;
106                 else if(*b2 + time_offset < *b1) ++b2;
107                 else
108                 {
109                         assert(*b1 == *b2 + time_offset);
110                         return true;
111                 }
112         }
113         return false;
114 }
115
116 //gets 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, synfig::Time time = 0);
124 void recurse_layer(synfig::Layer::Handle layer, const std::set<synfig::Time> &tlist,
125                                                                 timepoints_ref &vals, synfig::Time time = 0);
126 void recurse_canvas(synfig::Canvas::Handle canvas, const std::set<synfig::Time> &tlist,
127                                                                 timepoints_ref &vals, synfig::Time time = 0);
128
129
130
131 }; // END of namespace studio
132
133 /* === E N D =============================================================== */
134
135 #endif