4420f48998f9f32db60cd71e386ce67cd5421574
[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 **
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                         // we don't need to initialise these 5, but the compiler thinks they're used uninitialised if we don't
81                         // and this constructor isn't called often, so it's ok
82                         priority(0), tension(0), continuity(0), bias(0), temporal_tension(0),
83
84                         priority_flag(false),
85                         before_flag(false),
86                         after_flag(false),
87                         tension_flag(false),
88                         continuity_flag(false),
89                         bias_flag(false),
90                         temporal_tension_flag(false) { }
91
92                 Interpolation get_before()const { return before; }
93                 void set_before(Interpolation x) { before=x; before_flag=true;}
94
95                 Interpolation get_after()const { return after; }
96                 void set_after(Interpolation x) { after=x; after_flag=true;}
97
98                 const Real &get_tension()const { return tension; }
99                 void set_tension(const Real &x) { tension=x; tension_flag=true;}
100
101                 const Real &get_continuity()const { return continuity; }
102                 void set_continuity(const Real &x) { continuity=x; continuity_flag=true;}
103
104                 const Real &get_bias()const { return bias; }
105                 void set_bias(const Real &x) { bias=x; bias_flag=true;}
106
107                 const Real &get_temporal_tension()const { return temporal_tension; }
108                 void set_temporal_tension(const Real &x) { temporal_tension=x; temporal_tension_flag=true;}
109
110                 int get_priority()const { return priority; }
111                 void set_priority(int x) { priority=x; priority_flag=true;}
112
113                 #define FLAG_MACRO(x) bool get_##x##_flag()const { return x##_flag; } void set_##x##_flag(bool y) { x##_flag=y; }
114                 FLAG_MACRO(priority)
115                 FLAG_MACRO(before)
116                 FLAG_MACRO(after)
117                 FLAG_MACRO(tension)
118                 FLAG_MACRO(continuity)
119                 FLAG_MACRO(bias)
120                 FLAG_MACRO(temporal_tension)
121                 #undef FLAG_MACRO
122
123                 void reset()
124                 {
125                         priority_flag=false;
126                         before_flag=false;
127                         after_flag=false;
128                         tension_flag=false;
129                         continuity_flag=false;
130                         bias_flag=false;
131                         temporal_tension_flag=false;
132                 }
133
134                 bool is_trivial()const
135                 {
136                         return !(
137                                 priority_flag||
138                                 before_flag||
139                                 after_flag||
140                                 tension_flag||
141                                 continuity_flag||
142                                 bias_flag||
143                                 temporal_tension_flag
144                         );
145                 }
146         };
147
148         enum Side
149         {
150                 SIDE_UNSPECIFIED, SIDE_LEFT, SIDE_RIGHT,
151
152             SIDE_END=2                          //!< \internal
153         };
154
155         /*
156  --     ** -- D A T A -------------------------------------------------------------
157         */
158
159 private:
160
161         int priority_;
162         etl::loose_handle<ValueNode> parent_;
163
164         Interpolation before, after;
165
166         etl::rhandle<ValueNode> value_node;
167
168         Time time;
169
170         // The following are for the INTERPOLATION_TCB type
171         Real tension;
172         Real continuity;
173         Real bias;
174
175         // The following are for the INTERPOLATION_MANUAL type
176         ValueBase cpoint_before,cpoint_after;
177
178
179         float time_tension;
180
181         /*
182  --     ** -- C O N S T R U C T O R S ---------------------------------------------
183         */
184
185 public:
186
187         Waypoint(ValueBase value, Time time);
188         Waypoint(etl::handle<ValueNode> value_node, Time time);
189
190         Waypoint();
191
192         /*
193  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
194         */
195
196 public:
197
198         void apply_model(const Model &x);
199
200         Interpolation get_before()const { return before; }
201         void set_before(Interpolation x) { before=x; }
202
203         Interpolation get_after()const { return after; }
204         void set_after(Interpolation x) { after=x; }
205
206         ValueBase get_value()const;
207         ValueBase get_value(const Time &t)const;
208         void set_value(const ValueBase &x);
209
210         const etl::rhandle<ValueNode> &get_value_node()const { return value_node; }
211         void set_value_node(const etl::handle<ValueNode> &x);
212
213         const Real &get_tension()const { return tension; }
214         void set_tension(const Real &x) { tension=x; }
215
216         const Real &get_continuity()const { return continuity; }
217         void set_continuity(const Real &x) { continuity=x; }
218
219         const Real &get_bias()const { return bias; }
220         void set_bias(const Real &x) { bias=x; }
221
222         const Time &get_time()const { return time; }
223         void set_time(const Time &x);
224
225         int get_priority()const { return priority_; }
226         void set_priority(int x) { priority_=x; }
227
228         const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
229         void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
230
231         bool is_static()const;
232
233         float get_time_tension()const { return time_tension; }
234         void set_time_tension(const float& x) { time_tension=x; }
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