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