Rearranged a bit. Use the new macro in valuenode.h introduced in the previous commit...
[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 **
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 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "timepointcollect.h"
33 #include "valuenode_animated.h"
34 #include "layer_pastecanvas.h"
35 #include "layer.h"
36 #include "canvas.h"
37 #include "value.h"
38
39 #endif
40
41 /* === U S I N G =========================================================== */
42
43 using namespace std;
44 using namespace etl;
45 using namespace synfig;
46
47 /* === M A C R O S ========================================================= */
48
49 /* === G L O B A L S ======================================================= */
50
51 /* === P R O C E D U R E S ================================================= */
52
53 /* === M E T H O D S ======================================================= */
54
55 //! \writeme
56 int
57 synfig::waypoint_collect(set<Waypoint, std::less<UniqueID> >& waypoint_set,const Time& time, const etl::handle<Node>& node)
58 {
59         const TimePointSet& timepoint_set(node->get_times());
60
61         // Check to see if there is anything in here at the given time
62         if(timepoint_set.find(time)==timepoint_set.end())
63                 return 0;
64
65         // Check if we are a linkable value node
66         LinkableValueNode::Handle linkable_value_node;
67         linkable_value_node=linkable_value_node.cast_dynamic(node);
68         if(linkable_value_node)
69         {
70                 const int link_count(linkable_value_node->link_count());
71                 int i,ret(0);
72                 for(i=0;i<link_count;i++)
73                 {
74                         ret+=waypoint_collect(waypoint_set,time,linkable_value_node->get_link(i).get());
75                 }
76                 return ret;
77         }
78
79         // Check if we are a layer
80         Layer::Handle layer;
81         layer=layer.cast_dynamic(node);
82         if(layer)
83         {
84                 const Layer::DynamicParamList& dyn_param_list(layer->dynamic_param_list());
85                 Layer::DynamicParamList::const_iterator iter;
86                 int ret(0);
87                 for(iter=dyn_param_list.begin();iter!=dyn_param_list.end();++iter)
88                 {
89                         ret+=waypoint_collect(waypoint_set,time,iter->second);
90                 }
91                 ValueBase canvas_value(layer->get_param("canvas"));
92                 if(canvas_value.get_type()==ValueBase::TYPE_CANVAS)
93                 {
94                         etl::handle<Layer_PasteCanvas> p = etl::handle<Layer_PasteCanvas>::cast_dynamic(layer);
95                         if (p)
96                                 ret+=waypoint_collect(waypoint_set, time + p->get_time_offset(),
97                                                                           Canvas::Handle(canvas_value.get(Canvas::Handle())));
98                         else
99                                 ret+=waypoint_collect(waypoint_set, time,
100                                                                           Canvas::Handle(canvas_value.get(Canvas::Handle())));
101                 }
102                 return ret;
103         }
104
105         // Check if we are a canvas
106         Canvas::Handle canvas;
107         canvas=canvas.cast_dynamic(node);
108         if(canvas)
109         {
110                 Canvas::const_iterator iter;
111                 int ret(0);
112                 for(iter=canvas->begin();iter!=canvas->end();++iter)
113                         ret+=waypoint_collect(waypoint_set,time,*iter);
114                 return ret;
115         }
116
117         // Check if we are an animated value node
118         ValueNode_Animated::Handle value_node_animated;
119         value_node_animated=value_node_animated.cast_dynamic(node);
120         if(value_node_animated)
121         {
122                 try{
123                         Waypoint waypoint=*value_node_animated->find(time);
124
125                         // If it is already in the waypoint set, then
126                         // don't bother adding it again
127                         if(waypoint_set.find(waypoint)!=waypoint_set.end())
128                         {
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 }