Added my "Copyright (c) 2007" notices, for files I edited in 2007.
[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 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_TIMEGATHER_H
27 #define __SYNFIG_TIMEGATHER_H
28
29 /* === H E A D E R S ======================================================= */
30 #include <synfig/valuenode_animated.h>
31 #include <synfig/valuenode_dynamiclist.h>
32 #include <synfig/time.h>
33 #include "value_desc.h"
34
35 /* === M A C R O S ========================================================= */
36
37 /* === T Y P E D E F S ===================================================== */
38
39 /* === C L A S S E S & S T R U C T S ======================================= */
40
41 namespace synfig {
42         class Time;
43 }
44
45 namespace synfigapp {
46
47 class ValueDesc;
48
49 struct ValueBaseTimeInfo
50 {
51         synfig::ValueNode_Animated::Handle      val;
52         mutable std::set<synfig::Waypoint>      waypoints;
53
54         bool operator<(const ValueBaseTimeInfo &rhs) const
55         {
56                 return val < rhs.val;
57         }
58 };
59
60 struct ActiveTimeInfo
61 {
62         struct actcmp
63         {
64                 bool operator()(const synfig::Activepoint &lhs, const synfig::Activepoint &rhs) const
65                 {
66                         return lhs.time < rhs.time;
67                 }
68         };
69
70         synfigapp::ValueDesc                                            val;
71
72         typedef std::set<synfig::Activepoint,actcmp>    set;
73
74         mutable set activepoints;
75
76         bool operator<(const ActiveTimeInfo &rhs) const
77         {
78                 return val.get_parent_value_node() == rhs.val.get_parent_value_node() ?
79                                                 val.get_index() < rhs.val.get_index() :
80                                                 val.get_parent_value_node() < rhs.val.get_parent_value_node();
81         }
82 };
83
84 struct timepoints_ref
85 {
86         typedef std::set<ValueBaseTimeInfo>             waytracker;
87         typedef std::set<ActiveTimeInfo>        acttracker;
88
89         waytracker              waypointbiglist;
90         acttracker              actpointbiglist;
91
92         void insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w);
93         void insert(synfigapp::ValueDesc v, synfig::Activepoint a);
94 };
95
96 //assumes they're sorted... (incremental advance)
97 //checks the intersection of the two sets... might be something better in the stl
98 template < typename I1, typename I2 >
99 bool check_intersect(I1 b1, I1 end1, I2 b2, I2 end2, synfig::Time time_offset = 0)
100 {
101         if(b1 == end1 || b2 == end2)
102                 return false;
103
104         for(; b1 != end1 && b2 != end2;)
105         {
106                 if(*b1 < *b2 + time_offset) ++b1;
107                 else if(*b2 + time_offset < *b1) ++b2;
108                 else
109                 {
110                         assert(*b1 == *b2 + time_offset);
111                         return true;
112                 }
113         }
114         return false;
115 }
116
117 //gets the closest time inside the set
118 bool get_closest_time(const synfig::Node::time_set &tset, const synfig::Time &t,
119                                                 const synfig::Time &range, synfig::Time &out);
120
121 //recursion functions based on time restrictions (can be expanded later)...
122 //builds a list of relevant waypoints and activepoints inside the timepoints_ref structure
123 void recurse_valuedesc(synfigapp::ValueDesc valdesc, const std::set<synfig::Time> &tlist,
124                                                                 timepoints_ref &vals, synfig::Time time = 0);
125 void recurse_layer(synfig::Layer::Handle layer, const std::set<synfig::Time> &tlist,
126                                                                 timepoints_ref &vals, synfig::Time time = 0);
127 void recurse_canvas(synfig::Canvas::Handle canvas, const std::set<synfig::Time> &tlist,
128                                                                 timepoints_ref &vals, synfig::Time time = 0);
129
130
131
132 }; // END of namespace studio
133
134 /* === E N D =============================================================== */
135
136 #endif