Documentation for Waypoint class
[synfig.git] / synfig-core / src / synfig / waypoint.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file waypoint.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 "waypoint.h"
33 #include "valuenode_const.h"
34
35 #endif
36
37 /* === U S I N G =========================================================== */
38
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42
43 /* === M A C R O S ========================================================= */
44
45 /* === G L O B A L S ======================================================= */
46
47 /* === P R O C E D U R E S ================================================= */
48
49 /* === M E T H O D S ======================================================= */
50
51 Waypoint::Waypoint(ValueBase value, Time time):
52         priority_(0),
53         before(INTERPOLATION_TCB),
54         after(INTERPOLATION_TCB),
55         value_node(ValueNode_Const::create(value)),
56         time(time),
57         tension(0.0),
58         continuity(0.0),
59         bias(0),
60         time_tension(0.0f)
61 {
62         //!Writeme
63         if(value.get_type()==ValueBase::TYPE_ANGLE)
64                 after=before=INTERPOLATION_LINEAR;
65 }
66
67 Waypoint::Waypoint(etl::handle<ValueNode> value_node, Time time):
68         priority_(0),
69         before(INTERPOLATION_TCB),
70         after(INTERPOLATION_TCB),
71         value_node(value_node),
72         time(time),
73         tension(0.0),
74         continuity(0),
75         bias(0),
76         time_tension(0.0f)
77 {
78         if(value_node->get_type()==ValueBase::TYPE_ANGLE)
79                 after=before=INTERPOLATION_LINEAR;
80 }
81
82 Waypoint::Waypoint():
83         priority_(0),
84         before(INTERPOLATION_TCB),
85         after(INTERPOLATION_TCB),
86         tension(0),
87         continuity(0),
88         bias(0),
89         time_tension(0.0f)
90 {
91 }
92
93 void
94 Waypoint::set_value(const ValueBase &x)
95 {
96         //! If the value node is not set and we are seting the value
97         //! of an angle, then set both interpolation to linear... why?
98         if(!value_node && x.get_type()==ValueBase::TYPE_ANGLE)
99                 after=before=INTERPOLATION_LINEAR;
100
101         value_node=ValueNode_Const::create(x);
102 }
103
104 void
105 Waypoint::set_value_node(const etl::handle<ValueNode> &x)
106 {
107         //! If the value node is not set and we are seting the value
108         //! of an angle, then set both interpolation to linear... why?
109         if(!value_node && x->get_type()==ValueBase::TYPE_ANGLE)
110                 after=before=INTERPOLATION_LINEAR;
111
112         value_node=x;
113 }
114
115 bool
116 Waypoint::is_static()const
117 {
118         return static_cast<bool>(ValueNode_Const::Handle::cast_dynamic(value_node)) && value_node && !value_node->is_exported();
119 }
120
121 void
122 Waypoint::set_time(const Time &x)
123 {
124         time=x;
125 }
126
127 void
128 Waypoint::apply_model(const Model &x)
129 {
130         if(x.priority_flag) set_priority(x.get_priority());
131         if(x.before_flag) set_before(x.get_before());
132         if(x.after_flag) set_after(x.get_after());
133         if(x.tension_flag) set_tension(x.get_tension());
134         if(x.continuity_flag) set_continuity(x.get_continuity());
135         if(x.bias_flag) set_bias(x.get_bias());
136         if(x.temporal_tension_flag) set_temporal_tension(x.get_temporal_tension());
137 }
138
139 Waypoint
140 Waypoint::clone(const GUID& deriv_guid)const
141 {
142         Waypoint ret(*this);
143         ret.make_unique();
144         if(!ret.value_node->is_exported())
145                 ret.value_node=value_node->clone(deriv_guid);
146         ret.parent_=0;
147         return ret;
148 }
149
150 ValueBase
151 Waypoint::get_value()const { return (*value_node)(0); }
152
153 ValueBase
154 Waypoint::get_value(const Time &t)const { return (*value_node)(t); }
155
156 synfig::GUID
157 Waypoint::get_guid()const
158 {
159         return GUID::hasher(get_uid());
160 }