Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / waypoint.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file waypoint.h
3 **      \brief Waypoint class 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 "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 Waypoint is used to handle variations along the time of the ValueNodes
54 *
55 * The Waypoint is a child of a ValueNode (or any of inherited) and it describes the
56 * Interpolation type (before and after), the ValueNode (usually waypoints are constant
57 * but in fact they can be animated) and the time where the waypoint is.
58 * \see Waypoint::get_value(), Waypoint::get_value(const Time &t)
59 */
60 class Waypoint : public UniqueID
61 {
62         /*
63  --     ** -- T Y P E S -----------------------------------------------------------
64         */
65
66 public:
67
68         typedef synfig::Interpolation Interpolation;
69
70 /*! \class Waypoint::Model
71  *      \brief Waypoint::Model is a Waypoint model. It is used to store and
72  *      retrieve the values of the waypoint that is going to be modified. Once
73  *      the model is completely modifed then it can be applied to the waypoint
74  *      itself by using the \apply_model() member
75  */
76         class Model
77         {
78                 friend class Waypoint;
79
80                 int priority;
81                 Interpolation before;
82                 Interpolation after;
83                 Real tension;
84                 Real continuity;
85                 Real bias;
86                 Real temporal_tension;
87
88                 bool priority_flag,before_flag,after_flag,tension_flag,continuity_flag,bias_flag,temporal_tension_flag;
89
90         public:
91                 Model():
92                         // we don't need to initialise these 5, but the compiler thinks they're used uninitialised if we don't
93                         // and this constructor isn't called often, so it's ok
94                         priority(0), before(INTERPOLATION_NIL), after(INTERPOLATION_NIL), tension(0), continuity(0), bias(0), temporal_tension(0),
95
96                         priority_flag(false),
97                         before_flag(false),
98                         after_flag(false),
99                         tension_flag(false),
100                         continuity_flag(false),
101                         bias_flag(false),
102                         temporal_tension_flag(false) { }
103
104                 //! Gets before Interpolation
105                 Interpolation get_before()const { return before; }
106                 //! Sets before Interpolation
107                 void set_before(Interpolation x) { before=x; before_flag=true;}
108                 //! Gets after Interpolation
109                 Interpolation get_after()const { return after; }
110                 //! Sets after Interpolation
111                 void set_after(Interpolation x) { after=x; after_flag=true;}
112                 //! Gets tension
113                 const Real &get_tension()const { return tension; }
114                 //! Sets tension
115                 void set_tension(const Real &x) { tension=x; tension_flag=true;}
116                 //! Gets continuity
117                 const Real &get_continuity()const { return continuity; }
118                 //! Sets continuity
119                 void set_continuity(const Real &x) { continuity=x; continuity_flag=true;}
120                 //! Gets bias
121                 const Real &get_bias()const { return bias; }
122                 //! Sets bias
123                 void set_bias(const Real &x) { bias=x; bias_flag=true;}
124                 //! Gets temporal tension
125                 const Real &get_temporal_tension()const { return temporal_tension; }
126                 //! Sets temporal tension
127                 void set_temporal_tension(const Real &x) { temporal_tension=x; temporal_tension_flag=true;}
128                 //! Gets priority
129                 int get_priority()const { return priority; }
130                 //! Sets priority
131                 void set_priority(int x) { priority=x; priority_flag=true;}
132
133                 //! Get & Set members for the flags
134                 #define FLAG_MACRO(x) bool get_##x##_flag()const { return x##_flag; } void set_##x##_flag(bool y) { x##_flag=y; }
135                 FLAG_MACRO(priority)
136                 FLAG_MACRO(before)
137                 FLAG_MACRO(after)
138                 FLAG_MACRO(tension)
139                 FLAG_MACRO(continuity)
140                 FLAG_MACRO(bias)
141                 FLAG_MACRO(temporal_tension)
142                 #undef FLAG_MACRO
143
144                 //! Converts the Model in trivial: None of its values will be applied
145                 void reset()
146                 {
147                         priority_flag=false;
148                         before_flag=false;
149                         after_flag=false;
150                         tension_flag=false;
151                         continuity_flag=false;
152                         bias_flag=false;
153                         temporal_tension_flag=false;
154                 }
155
156                 //! Checks if none of the Model information is relevant for the Waypoint
157                 //! If all the flags are off, the Model doesn't apply wnything to the
158                 //! waypoint. \see apply_model(const Model &x)
159                 bool is_trivial()const
160                 {
161                         return !(
162                                 priority_flag||
163                                 before_flag||
164                                 after_flag||
165                                 tension_flag||
166                                 continuity_flag||
167                                 bias_flag||
168                                 temporal_tension_flag
169                         );
170                 }
171         };
172
173         enum Side
174         {
175                 SIDE_UNSPECIFIED, SIDE_LEFT, SIDE_RIGHT,
176
177             SIDE_END=2                          //!< \internal
178         };
179
180         /*
181  --     ** -- D A T A -------------------------------------------------------------
182         */
183
184 private:
185
186         //! Writeme
187         int priority_;
188         //! Usually Animated Value Nodes are parents of waypoints
189         //! \see class ValueNode_Animated
190         etl::loose_handle<ValueNode> parent_;
191         //! The two Interpolations before and after
192         Interpolation before, after;
193         //! The value node that is hold by the waypoint
194         etl::rhandle<ValueNode> value_node;
195         //! The time of the waypoint
196         Time time;
197
198         //! The following are for the INTERPOLATION_TCB type
199         Real tension;
200         Real continuity;
201         Real bias;
202
203         //! The following are for the INTERPOLATION_MANUAL type
204         //! Seems to be not used
205         ValueBase cpoint_before,cpoint_after;
206
207         //! Shouldn't be Real?
208         float time_tension;
209
210         /*
211  --     ** -- C O N S T R U C T O R S ---------------------------------------------
212         */
213
214 public:
215
216         //! Constructor for constant Waypoint
217         Waypoint(ValueBase value, Time time);
218         //! Constructor for animated Waypoint
219         //! Is is called anytime?
220         Waypoint(etl::handle<ValueNode> value_node, Time time);
221
222         //! Default constructor. Leaves unset the Value Node
223         Waypoint();
224
225         /*
226  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
227         */
228
229 public:
230
231         //! Applies the content of the Model to the Waypoint. It doesn't alter
232         //! the Value Node hold or the time.
233         void apply_model(const Model &x);
234
235         //! Gets the before Interpolation
236         Interpolation get_before()const { return before; }
237         //! Sets the before Interpolation
238         void set_before(Interpolation x) { before=x; }
239         //! Gets the after Interpolation
240         Interpolation get_after()const { return after; }
241         //! Sets the after Interpolation
242         void set_after(Interpolation x) { after=x; }
243         //! Gets the value hold by the Waypoint
244         ValueBase get_value()const;
245         //!Gets the value hold by the Waypoint at time \t when it is animated
246         ValueBase get_value(const Time &t)const;
247         //!Sets the value of the Waypoint.
248         //!Maybe it would be posible to define set_value(const ValueBase &x, Time &t) ?
249         void set_value(const ValueBase &x);
250         //! Returns the handle to the value node
251         const etl::rhandle<ValueNode> &get_value_node()const { return value_node; }
252         //! Sets the value node by handle
253         void set_value_node(const etl::handle<ValueNode> &x);
254
255         //! Gets tension
256         const Real &get_tension()const { return tension; }
257         //! Sets tension
258         void set_tension(const Real &x) { tension=x; }
259         //! Gets continuity
260         const Real &get_continuity()const { return continuity; }
261         //! Sets continuity
262         void set_continuity(const Real &x) { continuity=x; }
263         //! Gets bias
264         const Real &get_bias()const { return bias; }
265         //! Sets bias
266         void set_bias(const Real &x) { bias=x; }
267
268         //! Gets the time of the waypoint
269         const Time &get_time()const { return time; }
270         //! Sets the time of the waypoint
271         void set_time(const Time &x);
272
273         int get_priority()const { return priority_; }
274         void set_priority(int x) { priority_=x; }
275
276         //! Gets parent Value Node
277         const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
278         //! Sets parent Value Node
279         void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
280
281         //! \true if the Value Node is constant, not null and not exported
282         bool is_static()const;
283
284         //!! Gets temporal tension
285         float get_temporal_tension()const { return time_tension; }
286         //!! Sets temporal tension
287         void set_temporal_tension(const float& x) { time_tension=x; }
288
289         //! True if the current waypoint's time is earlier than the compared waypoint's time
290         bool operator<(const Waypoint &rhs)const
291         { return time<rhs.time; }
292         //! True if the current waypoint's time is earlier than the given time
293         bool operator<(const Time &rhs)const
294         { return time.is_less_than(rhs); }
295         //! True if the current waypoint's time is later than the given time
296         bool operator>(const Time &rhs)const
297         { return time.is_more_than(rhs); }
298         //! True if the waypoint's time is the same than the given time
299         bool operator==(const Time &rhs)const
300         { return time.is_equal(rhs); }
301         //! True if the waypoint's time is different than the given time
302         bool operator!=(const Time &rhs)const
303         { return !time.is_equal(rhs); }
304
305         //! True if the Waypoint's Unique Id is the same than the argument's Unique ID
306         bool operator==(const UniqueID &rhs)const
307         { return get_uid()==rhs.get_uid(); }
308         //! True if the Waypoint's Unique Id is different than the argument's Unique ID
309         bool operator!=(const UniqueID &rhs)const
310         { return get_uid()!=rhs.get_uid(); }
311
312         //! Clones the Value Node if it is not exported and returns a Waypoint
313         //! with no parent.
314         Waypoint clone(const GUID& deriv_guid=GUID())const;
315
316         //! Returns a hack GUID using the UniqueID's value
317         GUID get_guid()const;
318 }; // END of class Waypoint
319
320 typedef std::vector< Waypoint > WaypointList;
321
322 }; // END of namespace synfig
323
324 /* === E N D =============================================================== */
325
326 #endif