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