5f7912a85ca454bd9980b2f58358ea77925f060c
[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,
58                                                  const Time                                                             &time,
59                                                  const etl::handle<Node>                                &node)
60 {
61         const TimePointSet& timepoint_set(node->get_times());
62
63         // Check to see if there is anything in here at the given time
64         if(timepoint_set.find(time)==timepoint_set.end())
65                 return 0;
66
67         // Check if we are a linkable value node
68         LinkableValueNode::Handle linkable_value_node;
69         linkable_value_node=linkable_value_node.cast_dynamic(node);
70         if(linkable_value_node)
71         {
72                 const int link_count(linkable_value_node->link_count());
73                 int i,ret(0);
74                 for(i=0;i<link_count;i++)
75                         ret+=waypoint_collect(waypoint_set,time,linkable_value_node->get_link(i).get());
76
77                 return ret;
78         }
79
80         // Check if we are a layer
81         Layer::Handle layer;
82         layer=layer.cast_dynamic(node);
83         if(layer)
84         {
85                 const Layer::DynamicParamList& dyn_param_list(layer->dynamic_param_list());
86                 Layer::DynamicParamList::const_iterator iter;
87                 int ret(0);
88                 for(iter=dyn_param_list.begin();iter!=dyn_param_list.end();++iter)
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                                 return 0;
129
130                         waypoint_set.insert(waypoint);
131                         return 1;
132                 }catch(...)
133                 {
134                         return 0;
135                 }
136         }
137
138         return 0;
139 }
140
141 //! \writeme
142 int
143 synfig::activepoint_collect(set<Activepoint, std::less<UniqueID> >& /*activepoint_set*/,const Time& time, const etl::handle<Node>& node)
144 {
145         const TimePointSet& timepoint_set(node->get_times());
146
147         // Check to see if there is anything in here at the given time
148         if(timepoint_set.find(time)==timepoint_set.end())
149                 return 0;
150
151         return 0;
152 }