more updates
[synfig.git] / synfig-core / trunk / src / synfig / timepointcollect.cpp
1 /* === S I N F 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "timepointcollect.h"
32 #include "valuenode_animated.h"
33 #include "layer.h"
34 #include "canvas.h"
35 #include "value.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 using namespace etl;
43 using namespace sinfg;
44
45 /* === M A C R O S ========================================================= */
46
47 /* === G L O B A L S ======================================================= */
48
49 /* === P R O C E D U R E S ================================================= */
50
51 /* === M E T H O D S ======================================================= */
52
53 //! \writeme
54 int
55 sinfg::waypoint_collect(set<Waypoint, std::less<UniqueID> >& waypoint_set,const Time& time, const etl::handle<Node>& node)
56 {       
57         const TimePointSet& timepoint_set(node->get_times());
58
59         // Check to see if there is anything in here at the given time
60         if(timepoint_set.find(time)==timepoint_set.end())
61                 return 0;
62
63         // Check if we are a linkable value node
64         LinkableValueNode::Handle linkable_value_node;
65         linkable_value_node=linkable_value_node.cast_dynamic(node);
66         if(linkable_value_node)
67         {
68                 const int link_count(linkable_value_node->link_count());
69                 int i,ret(0);
70                 for(i=0;i<link_count;i++)
71                 {
72                         ret+=waypoint_collect(waypoint_set,time,linkable_value_node->get_link(i).get());
73                 }
74                 return ret;
75         }
76
77         // Check if we are a layer
78         Layer::Handle layer;
79         layer=layer.cast_dynamic(node);
80         if(layer)
81         {
82                 const Layer::DynamicParamList& dyn_param_list(layer->dynamic_param_list());
83                 Layer::DynamicParamList::const_iterator iter;
84                 int ret(0);
85                 for(iter=dyn_param_list.begin();iter!=dyn_param_list.end();++iter)
86                 {
87                         ret+=waypoint_collect(waypoint_set,time,iter->second);
88                 }
89                 ValueBase canvas_value(layer->get_param("canvas"));
90                 if(canvas_value.get_type()==ValueBase::TYPE_CANVAS)
91                 {
92                         ret+=waypoint_collect(waypoint_set,time,Canvas::Handle(canvas_value.get(Canvas::Handle())));
93                 }
94                 return ret;
95         }
96
97         // Check if we are a canvas
98         Canvas::Handle canvas;
99         canvas=canvas.cast_dynamic(node);
100         if(canvas)
101         {
102                 Canvas::const_iterator iter;
103                 int ret(0);
104                 for(iter=canvas->begin();iter!=canvas->end();++iter)
105                         ret+=waypoint_collect(waypoint_set,time,*iter);
106                 return ret;
107         }
108
109         // Check if we are an animated value node
110         ValueNode_Animated::Handle value_node_animated;
111         value_node_animated=value_node_animated.cast_dynamic(node);
112         if(value_node_animated)
113         {
114                 try{
115                         Waypoint waypoint=*value_node_animated->find(time);
116                         
117                         // If it is already in the waypoint set, then
118                         // don't bother adding it again
119                         if(waypoint_set.find(waypoint)!=waypoint_set.end())
120                         {
121                                 return 0;
122                         }
123                         waypoint_set.insert(waypoint);
124                         return 1;
125                 }catch(...)
126                 {
127                         return 0;
128                 }
129         }
130
131         return 0;
132 }
133
134 //! \writeme
135 int
136 sinfg::activepoint_collect(set<Activepoint, std::less<UniqueID> >& activepoint_set,const Time& time, const etl::handle<Node>& node)
137 {
138         const TimePointSet& timepoint_set(node->get_times());
139
140         // Check to see if there is anything in here at the given time
141         if(timepoint_set.find(time)==timepoint_set.end());
142                 return 0;
143
144         return 0;
145 }