Added copyright lines for files I've edited this year.
[synfig.git] / synfig-core / trunk / src / synfig / waypoint.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file waypoint.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_WAYPOINT_H
27 #define __SYNFIG_WAYPOINT_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "time.h"
32 #include "real.h"
33 #include "value.h"
34 //#include "valuenode.h"
35 #include "uniqueid.h"
36 #include <vector>
37 #include "guid.h"
38 #include "interpolation.h"
39
40 /* === M A C R O S ========================================================= */
41
42 /* === T Y P E D E F S ===================================================== */
43
44 /* === C L A S S E S & S T R U C T S ======================================= */
45
46 namespace synfig {
47
48 class ValueNode;
49 class GUID;
50
51
52 /*!     \class Waypoint
53 **      \brief \writeme
54 */
55 class Waypoint : public UniqueID
56 {
57         /*
58  --     ** -- T Y P E S -----------------------------------------------------------
59         */
60
61 public:
62
63         typedef synfig::Interpolation Interpolation;
64
65         class Model
66         {
67                 friend class Waypoint;
68
69                 int priority;
70                 Interpolation before;
71                 Interpolation after;
72                 Real tension;
73                 Real continuity;
74                 Real bias;
75                 Real temporal_tension;
76
77                 bool priority_flag,before_flag,after_flag,tension_flag,continuity_flag,bias_flag,temporal_tension_flag;
78
79         public:
80                 Model():
81                         // we don't need to initialise these 5, but the compiler thinks they're used uninitialised if we don't
82                         // and this constructor isn't called often, so it's ok
83                         priority(0), tension(0), continuity(0), bias(0), temporal_tension(0),
84
85                         priority_flag(false),
86                         before_flag(false),
87                         after_flag(false),
88                         tension_flag(false),
89                         continuity_flag(false),
90                         bias_flag(false),
91                         temporal_tension_flag(false) { }
92
93                 Interpolation get_before()const { return before; }
94                 void set_before(Interpolation x) { before=x; before_flag=true;}
95
96                 Interpolation get_after()const { return after; }
97                 void set_after(Interpolation x) { after=x; after_flag=true;}
98
99                 const Real &get_tension()const { return tension; }
100                 void set_tension(const Real &x) { tension=x; tension_flag=true;}
101
102                 const Real &get_continuity()const { return continuity; }
103                 void set_continuity(const Real &x) { continuity=x; continuity_flag=true;}
104
105                 const Real &get_bias()const { return bias; }
106                 void set_bias(const Real &x) { bias=x; bias_flag=true;}
107
108                 const Real &get_temporal_tension()const { return temporal_tension; }
109                 void set_temporal_tension(const Real &x) { temporal_tension=x; temporal_tension_flag=true;}
110
111                 int get_priority()const { return priority; }
112                 void set_priority(int x) { priority=x; priority_flag=true;}
113
114                 #define FLAG_MACRO(x) bool get_##x##_flag()const { return x##_flag; } void set_##x##_flag(bool y) { x##_flag=y; }
115                 FLAG_MACRO(priority)
116                 FLAG_MACRO(before)
117                 FLAG_MACRO(after)
118                 FLAG_MACRO(tension)
119                 FLAG_MACRO(continuity)
120                 FLAG_MACRO(bias)
121                 FLAG_MACRO(temporal_tension)
122                 #undef FLAG_MACRO
123
124                 void reset()
125                 {
126                         priority_flag=false;
127                         before_flag=false;
128                         after_flag=false;
129                         tension_flag=false;
130                         continuity_flag=false;
131                         bias_flag=false;
132                         temporal_tension_flag=false;
133                 }
134
135                 bool is_trivial()const
136                 {
137                         return !(
138                                 priority_flag||
139                                 before_flag||
140                                 after_flag||
141                                 tension_flag||
142                                 continuity_flag||
143                                 bias_flag||
144                                 temporal_tension_flag
145                         );
146                 }
147         };
148
149         enum Side
150         {
151                 SIDE_UNSPECIFIED, SIDE_LEFT, SIDE_RIGHT,
152
153             SIDE_END=2                          //!< \internal
154         };
155
156         /*
157  --     ** -- D A T A -------------------------------------------------------------
158         */
159
160 private:
161
162         int priority_;
163         etl::loose_handle<ValueNode> parent_;
164
165         Interpolation before, after;
166
167         etl::rhandle<ValueNode> value_node;
168
169         Time time;
170
171         // The following are for the INTERPOLATION_TCB type
172         Real tension;
173         Real continuity;
174         Real bias;
175
176         // The following are for the INTERPOLATION_MANUAL type
177         ValueBase cpoint_before,cpoint_after;
178
179
180         float time_tension;
181
182         /*
183  --     ** -- C O N S T R U C T O R S ---------------------------------------------
184         */
185
186 public:
187
188         Waypoint(ValueBase value, Time time);
189         Waypoint(etl::handle<ValueNode> value_node, Time time);
190
191         Waypoint();
192
193         /*
194  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
195         */
196
197 public:
198
199         void apply_model(const Model &x);
200
201         Interpolation get_before()const { return before; }
202         void set_before(Interpolation x) { before=x; }
203
204         Interpolation get_after()const { return after; }
205         void set_after(Interpolation x) { after=x; }
206
207         ValueBase get_value()const;
208         ValueBase get_value(const Time &t)const;
209         void set_value(const ValueBase &x);
210
211         const etl::rhandle<ValueNode> &get_value_node()const { return value_node; }
212         void set_value_node(const etl::handle<ValueNode> &x);
213
214         const Real &get_tension()const { return tension; }
215         void set_tension(const Real &x) { tension=x; }
216
217         const Real &get_continuity()const { return continuity; }
218         void set_continuity(const Real &x) { continuity=x; }
219
220         const Real &get_bias()const { return bias; }
221         void set_bias(const Real &x) { bias=x; }
222
223         const Time &get_time()const { return time; }
224         void set_time(const Time &x);
225
226         int get_priority()const { return priority_; }
227         void set_priority(int x) { priority_=x; }
228
229         const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
230         void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
231
232         bool is_static()const;
233
234         float get_time_tension()const { return time_tension; }
235         void set_time_tension(const float& x) { time_tension=x; }
236         float get_temporal_tension()const { return time_tension; }
237         void set_temporal_tension(const float& x) { time_tension=x; }
238
239         bool operator<(const Waypoint &rhs)const
240         { return time<rhs.time; }
241
242         bool operator<(const Time &rhs)const
243         { return time.is_less_than(rhs); }
244         bool operator>(const Time &rhs)const
245         { return time.is_more_than(rhs); }
246
247         bool operator==(const Time &rhs)const
248         { return time.is_equal(rhs); }
249         bool operator!=(const Time &rhs)const
250         { return !time.is_equal(rhs); }
251
252         bool operator==(const UniqueID &rhs)const
253         { return get_uid()==rhs.get_uid(); }
254         bool operator!=(const UniqueID &rhs)const
255         { return get_uid()!=rhs.get_uid(); }
256
257         Waypoint clone(const GUID& deriv_guid=GUID())const;
258
259         GUID get_guid()const;
260 }; // END of class Waypoint
261
262 typedef std::vector< Waypoint > WaypointList;
263
264 }; // END of namespace synfig
265
266 /* === E N D =============================================================== */
267
268 #endif