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