Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc3 / 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 **
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 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_WAYPOINT_H
26 #define __SYNFIG_WAYPOINT_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "time.h"
31 #include "real.h"
32 #include "value.h"
33 //#include "valuenode.h"
34 #include "uniqueid.h"
35 #include <vector>
36 #include "guid.h"
37 #include "interpolation.h"
38
39 /* === M A C R O S ========================================================= */
40
41 /* === T Y P E D E F S ===================================================== */
42
43 /* === C L A S S E S & S T R U C T S ======================================= */
44
45 namespace synfig {
46
47 class ValueNode;
48 class GUID;
49
50
51 /*!     \class Waypoint
52 **      \brief \writeme
53 */
54 class Waypoint : public UniqueID
55 {
56         /*
57  --     ** -- T Y P E S -----------------------------------------------------------
58         */
59
60 public:
61
62         typedef synfig::Interpolation Interpolation;
63
64         class Model
65         {
66                 friend class Waypoint;
67
68                 int priority;
69                 Interpolation before;
70                 Interpolation after;
71                 Real tension;
72                 Real continuity;
73                 Real bias;
74                 Real temporal_tension;
75
76                 bool priority_flag,before_flag,after_flag,tension_flag,continuity_flag,bias_flag,temporal_tension_flag;
77
78         public:
79                 Model():
80                         priority_flag(false),
81                         before_flag(false),
82                         after_flag(false),
83                         tension_flag(false),
84                         continuity_flag(false),
85                         bias_flag(false),
86                         temporal_tension_flag(false) { }
87
88                 Interpolation get_before()const { return before; }
89                 void set_before(Interpolation x) { before=x; before_flag=true;}
90
91                 Interpolation get_after()const { return after; }
92                 void set_after(Interpolation x) { after=x; after_flag=true;}
93
94                 const Real &get_tension()const { return tension; }
95                 void set_tension(const Real &x) { tension=x; tension_flag=true;}
96
97                 const Real &get_continuity()const { return continuity; }
98                 void set_continuity(const Real &x) { continuity=x; continuity_flag=true;}
99
100                 const Real &get_bias()const { return bias; }
101                 void set_bias(const Real &x) { bias=x; bias_flag=true;}
102
103                 const Real &get_temporal_tension()const { return temporal_tension; }
104                 void set_temporal_tension(const Real &x) { temporal_tension=x; temporal_tension_flag=true;}
105
106                 int get_priority()const { return priority; }
107                 void set_priority(int x) { priority=x; priority_flag=true;}
108
109                 #define FLAG_MACRO(x) bool get_##x##_flag()const { return x##_flag; } void set_##x##_flag(bool y) { x##_flag=y; }
110                 FLAG_MACRO(priority)
111                 FLAG_MACRO(before)
112                 FLAG_MACRO(after)
113                 FLAG_MACRO(tension)
114                 FLAG_MACRO(continuity)
115                 FLAG_MACRO(bias)
116                 FLAG_MACRO(temporal_tension)
117                 #undef FLAG_MACRO
118
119                 void reset()
120                 {
121                         priority_flag=false;
122                         before_flag=false;
123                         after_flag=false;
124                         tension_flag=false;
125                         continuity_flag=false;
126                         bias_flag=false;
127                         temporal_tension_flag=false;
128                 }
129
130                 bool is_trivial()const
131                 {
132                         return !(
133                                 priority_flag||
134                                 before_flag||
135                                 after_flag||
136                                 tension_flag||
137                                 continuity_flag||
138                                 bias_flag||
139                                 temporal_tension_flag
140                         );
141                 }
142         };
143
144         /*
145  --     ** -- D A T A -------------------------------------------------------------
146         */
147
148 private:
149
150         int priority_;
151         etl::loose_handle<ValueNode> parent_;
152
153         Interpolation before, after;
154
155         etl::rhandle<ValueNode> value_node;
156
157         Time time;
158
159         // The following are for the INTERPOLATION_TCB type
160         Real tension;
161         Real continuity;
162         Real bias;
163
164         // The following are for the INTERPOLATION_MANUAL type
165         ValueBase cpoint_before,cpoint_after;
166
167
168         float time_tension;
169
170         /*
171  --     ** -- C O N S T R U C T O R S ---------------------------------------------
172         */
173
174 public:
175
176         Waypoint(ValueBase value, Time time);
177         Waypoint(etl::handle<ValueNode> value_node, Time time);
178
179         Waypoint();
180
181         /*
182  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
183         */
184
185 public:
186
187         void apply_model(const Model &x);
188
189         Interpolation get_before()const { return before; }
190         void set_before(Interpolation x) { before=x; }
191
192         Interpolation get_after()const { return after; }
193         void set_after(Interpolation x) { after=x; }
194
195         ValueBase get_value()const;
196         ValueBase get_value(const Time &t)const;
197         void set_value(const ValueBase &x);
198
199         const etl::rhandle<ValueNode> &get_value_node()const { return value_node; }
200         void set_value_node(const etl::handle<ValueNode> &x);
201
202         const Real &get_tension()const { return tension; }
203         void set_tension(const Real &x) { tension=x; }
204
205         const Real &get_continuity()const { return continuity; }
206         void set_continuity(const Real &x) { continuity=x; }
207
208         const Real &get_bias()const { return bias; }
209         void set_bias(const Real &x) { bias=x; }
210
211         const Time &get_time()const { return time; }
212         void set_time(const Time &x);
213
214         int get_priority()const { return priority_; }
215         void set_priority(int x) { priority_=x; }
216
217         const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
218         void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
219
220         bool is_static()const;
221
222         float get_time_tension()const { return time_tension; }
223         void set_time_tension(const float& x) { time_tension=x; }
224         float get_temporal_tension()const { return time_tension; }
225         void set_temporal_tension(const float& x) { time_tension=x; }
226
227         bool operator<(const Waypoint &rhs)const
228         { return time<rhs.time; }
229
230         bool operator<(const Time &rhs)const
231         { return time.is_less_than(rhs); }
232         bool operator>(const Time &rhs)const
233         { return time.is_more_than(rhs); }
234
235         bool operator==(const Time &rhs)const
236         { return time.is_equal(rhs); }
237         bool operator!=(const Time &rhs)const
238         { return !time.is_equal(rhs); }
239
240         bool operator==(const UniqueID &rhs)const
241         { return get_uid()==rhs.get_uid(); }
242         bool operator!=(const UniqueID &rhs)const
243         { return get_uid()!=rhs.get_uid(); }
244
245         Waypoint clone(const GUID& deriv_guid=GUID())const;
246
247         GUID get_guid()const;
248 }; // END of class Waypoint
249
250 typedef std::vector< Waypoint > WaypointList;
251
252 }; // END of namespace synfig
253
254 /* === E N D =============================================================== */
255
256 #endif