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