Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_06 / 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         if(value.get_type()==ValueBase::TYPE_ANGLE)
63                 after=before=INTERPOLATION_LINEAR;
64 }
65
66 Waypoint::Waypoint(ValueNode::Handle value_node, Time time):
67         priority_(0),
68         before(INTERPOLATION_TCB),
69         after(INTERPOLATION_TCB),
70         value_node(value_node),
71         time(time),
72         tension(0.0),
73         continuity(0),
74         bias(0),
75         time_tension(0.0f)
76 {
77         if(value_node->get_type()==ValueBase::TYPE_ANGLE)
78                 after=before=INTERPOLATION_LINEAR;
79 }
80
81 Waypoint::Waypoint():
82         priority_(0),
83         before(INTERPOLATION_TCB),
84         after(INTERPOLATION_TCB),
85         tension(0),
86         continuity(0),
87         bias(0),
88         time_tension(0.0f)
89 {
90 }
91
92 void
93 Waypoint::set_value(const ValueBase &x)
94 {
95         if(!value_node && x.get_type()==ValueBase::TYPE_ANGLE)
96                 after=before=INTERPOLATION_LINEAR;
97
98         value_node=ValueNode_Const::create(x);
99 }
100
101 void
102 Waypoint::set_value_node(const ValueNode::Handle &x)
103 {
104         if(!value_node && x->get_type()==ValueBase::TYPE_ANGLE)
105                 after=before=INTERPOLATION_LINEAR;
106
107         value_node=x;
108 }
109
110 bool
111 Waypoint::is_static()const
112 {
113         return static_cast<bool>(ValueNode_Const::Handle::cast_dynamic(value_node)) && value_node && !value_node->is_exported();
114 }
115
116 void
117 Waypoint::set_time(const Time &x)
118 {
119         time=x;
120 }
121
122 void
123 Waypoint::apply_model(const Model &x)
124 {
125         if(x.priority_flag) set_priority(x.get_priority());
126         if(x.before_flag) set_before(x.get_before());
127         if(x.after_flag) set_after(x.get_after());
128         if(x.tension_flag) set_tension(x.get_tension());
129         if(x.continuity_flag) set_continuity(x.get_continuity());
130         if(x.bias_flag) set_bias(x.get_bias());
131         if(x.temporal_tension_flag) set_temporal_tension(x.get_temporal_tension());
132 }
133
134 Waypoint
135 Waypoint::clone(const GUID& deriv_guid)const
136 {
137         Waypoint ret(*this);
138         ret.make_unique();
139         if(!ret.value_node->is_exported())
140                 ret.value_node=value_node->clone(deriv_guid);
141         ret.parent_=0;
142         return ret;
143 }
144
145 ValueBase
146 Waypoint::get_value()const { return (*value_node)(0); }
147
148 ValueBase
149 Waypoint::get_value(const Time &t)const { return (*value_node)(t); }
150
151 synfig::GUID
152 Waypoint::get_guid()const
153 {
154         return GUID::hasher(get_uid());
155 }