Added my "Copyright (c) 2007" notices, for files I edited in 2007.
[synfig.git] / synfig-core / trunk / src / synfig / timepointcollect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file timepointcollect.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., 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 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "timepointcollect.h"
34 #include "valuenode_animated.h"
35 #include "layer_pastecanvas.h"
36 #include "layer.h"
37 #include "canvas.h"
38 #include "value.h"
39
40 #endif
41
42 /* === U S I N G =========================================================== */
43
44 using namespace std;
45 using namespace etl;
46 using namespace synfig;
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 /* === P R O C E D U R E S ================================================= */
53
54 /* === M E T H O D S ======================================================= */
55
56 //! \writeme
57 int
58 synfig::waypoint_collect(set<Waypoint, std::less<UniqueID> >    &waypoint_set,
59                                                  const Time                                                             &time,
60                                                  const etl::handle<Node>                                &node)
61 {
62         const TimePointSet& timepoint_set(node->get_times());
63
64         // Check to see if there is anything in here at the given time
65         if(timepoint_set.find(time)==timepoint_set.end())
66                 return 0;
67
68         // Check if we are a linkable value node
69         LinkableValueNode::Handle linkable_value_node;
70         linkable_value_node=linkable_value_node.cast_dynamic(node);
71         if(linkable_value_node)
72         {
73                 const int link_count(linkable_value_node->link_count());
74                 int i,ret(0);
75                 for(i=0;i<link_count;i++)
76                         ret+=waypoint_collect(waypoint_set,time,linkable_value_node->get_link(i).get());
77
78                 return ret;
79         }
80
81         // Check if we are a layer
82         Layer::Handle layer;
83         layer=layer.cast_dynamic(node);
84         if(layer)
85         {
86                 const Layer::DynamicParamList& dyn_param_list(layer->dynamic_param_list());
87                 Layer::DynamicParamList::const_iterator iter;
88                 int ret(0);
89                 for(iter=dyn_param_list.begin();iter!=dyn_param_list.end();++iter)
90                         ret+=waypoint_collect(waypoint_set,time,iter->second);
91
92                 ValueBase canvas_value(layer->get_param("canvas"));
93                 if(canvas_value.get_type()==ValueBase::TYPE_CANVAS)
94                 {
95                         etl::handle<Layer_PasteCanvas> p = etl::handle<Layer_PasteCanvas>::cast_dynamic(layer);
96                         if (p)
97                                 ret+=waypoint_collect(waypoint_set, time + p->get_time_offset(),
98                                                                           Canvas::Handle(canvas_value.get(Canvas::Handle())));
99                         else
100                                 ret+=waypoint_collect(waypoint_set, time,
101                                                                           Canvas::Handle(canvas_value.get(Canvas::Handle())));
102                 }
103                 return ret;
104         }
105
106         // Check if we are a canvas
107         Canvas::Handle canvas;
108         canvas=canvas.cast_dynamic(node);
109         if(canvas)
110         {
111                 Canvas::const_iterator iter;
112                 int ret(0);
113                 for(iter=canvas->begin();iter!=canvas->end();++iter)
114                         ret+=waypoint_collect(waypoint_set,time,*iter);
115                 return ret;
116         }
117
118         // Check if we are an animated value node
119         ValueNode_Animated::Handle value_node_animated;
120         value_node_animated=value_node_animated.cast_dynamic(node);
121         if(value_node_animated)
122         {
123                 try{
124                         Waypoint waypoint=*value_node_animated->find(time);
125
126                         // If it is already in the waypoint set, then
127                         // don't bother adding it again
128                         if(waypoint_set.find(waypoint)!=waypoint_set.end())
129                                 return 0;
130
131                         waypoint_set.insert(waypoint);
132                         return 1;
133                 }catch(...)
134                 {
135                         return 0;
136                 }
137         }
138
139         return 0;
140 }
141
142 //! \writeme
143 int
144 synfig::activepoint_collect(set<Activepoint, std::less<UniqueID> >& /*activepoint_set*/,const Time& time, const etl::handle<Node>& node)
145 {
146         const TimePointSet& timepoint_set(node->get_times());
147
148         // Check to see if there is anything in here at the given time
149         if(timepoint_set.find(time)==timepoint_set.end())
150                 return 0;
151
152         return 0;
153 }