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:
Model()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
get_before()105 		Interpolation get_before()const { return before; }
106 		//! Sets before Interpolation
set_before(Interpolation x)107 		void set_before(Interpolation x) { before=x; before_flag=true;}
108 		//! Gets after Interpolation
get_after()109 		Interpolation get_after()const { return after; }
110 		//! Sets after Interpolation
set_after(Interpolation x)111 		void set_after(Interpolation x) { after=x; after_flag=true;}
112 		//! Gets tension
get_tension()113 		const Real &get_tension()const { return tension; }
114 		//! Sets tension
set_tension(const Real & x)115 		void set_tension(const Real &x) { tension=x; tension_flag=true;}
116 		//! Gets continuity
get_continuity()117 		const Real &get_continuity()const { return continuity; }
118 		//! Sets continuity
set_continuity(const Real & x)119 		void set_continuity(const Real &x) { continuity=x; continuity_flag=true;}
120 		//! Gets bias
get_bias()121 		const Real &get_bias()const { return bias; }
122 		//! Sets bias
set_bias(const Real & x)123 		void set_bias(const Real &x) { bias=x; bias_flag=true;}
124 		//! Gets temporal tension
get_temporal_tension()125 		const Real &get_temporal_tension()const { return temporal_tension; }
126 		//! Sets temporal tension
set_temporal_tension(const Real & x)127 		void set_temporal_tension(const Real &x) { temporal_tension=x; temporal_tension_flag=true;}
128 		//! Gets priority
get_priority()129 		int get_priority()const { return priority; }
130 		//! Sets priority
set_priority(int x)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)
FLAG_MACRO(before)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)
is_trivial()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 	}; // END of class Model
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 	//! Shouldn't be Real?
204 	float time_tension;
205 
206 	/*
207  --	** -- C O N S T R U C T O R S ---------------------------------------------
208 	*/
209 
210 public:
211 
212 	//! Constructor for constant Waypoint
213 	Waypoint(ValueBase value, Time time);
214 	//! Constructor for animated Waypoint
215 	//! Is is called anytime?
216 	Waypoint(etl::handle<ValueNode> value_node, Time time);
217 
218 	//! Default constructor. Leaves unset the Value Node
219 	Waypoint();
220 
221 	/*
222  --	** -- M E M B E R   F U N C T I O N S -------------------------------------
223 	*/
224 
225 public:
226 
227 	//! Applies the content of the Model to the Waypoint. It doesn't alter
228 	//! the Value Node hold or the time.
229 	void apply_model(const Model &x);
230 
231 	//! Gets the before Interpolation
get_before()232 	Interpolation get_before()const { return before; }
233 	//! Sets the before Interpolation
set_before(Interpolation x)234 	void set_before(Interpolation x) { before=x; }
235 	//! Gets the after Interpolation
get_after()236 	Interpolation get_after()const { return after; }
237 	//! Sets the after Interpolation
set_after(Interpolation x)238 	void set_after(Interpolation x) { after=x; }
239 	//! Gets the value hold by the Waypoint
240 	ValueBase get_value()const;
241 	//!Gets the value hold by the Waypoint at time \t when it is animated
242 	ValueBase get_value(const Time &t)const;
243 	//!Sets the value of the Waypoint.
244 	//!Maybe it would be posible to define set_value(const ValueBase &x, Time &t) ?
245 	void set_value(const ValueBase &x);
246 	//! Returns the handle to the value node
get_value_node()247 	const etl::rhandle<ValueNode> &get_value_node()const { return value_node; }
248 	//! Sets the value node by handle
249 	void set_value_node(const etl::handle<ValueNode> &x);
250 
251 	//! Gets tension
get_tension()252 	const Real &get_tension()const { return tension; }
253 	//! Sets tension
set_tension(const Real & x)254 	void set_tension(const Real &x) { tension=x; }
255 	//! Gets continuity
get_continuity()256 	const Real &get_continuity()const { return continuity; }
257 	//! Sets continuity
set_continuity(const Real & x)258 	void set_continuity(const Real &x) { continuity=x; }
259 	//! Gets bias
get_bias()260 	const Real &get_bias()const { return bias; }
261 	//! Sets bias
set_bias(const Real & x)262 	void set_bias(const Real &x) { bias=x; }
263 
264 	//! Gets the time of the waypoint
get_time()265 	const Time &get_time()const { return time; }
266 	//! Sets the time of the waypoint
267 	void set_time(const Time &x);
268 
get_priority()269 	int get_priority()const { return priority_; }
set_priority(int x)270 	void set_priority(int x) { priority_=x; }
271 
272 	//! Gets parent Value Node
get_parent_value_node()273 	const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
274 
275 	//! Sets parent Value Node
276 	void set_parent_value_node(const etl::loose_handle<ValueNode> &x);
277 
278 	//! \true if the Value Node is constant, not null and not exported
279 	bool is_static()const;
280 
281 	//!! Gets temporal tension
get_temporal_tension()282 	float get_temporal_tension()const { return time_tension; }
283 	//!! Sets temporal tension
set_temporal_tension(const float & x)284 	void set_temporal_tension(const float& x) { time_tension=x; }
285 
286 	//! True if the current waypoint's time is earlier than the compared waypoint's time
287 	bool operator<(const Waypoint &rhs)const
288 	{ return time<rhs.time; }
289 	//! True if the current waypoint's time is earlier than the given time
290 	bool operator<(const Time &rhs)const
291 	{ return time.is_less_than(rhs); }
292 	//! True if the current waypoint's time is later than the given time
293 	bool operator>(const Time &rhs)const
294 	{ return time.is_more_than(rhs); }
295 	//! True if the waypoint's time is the same than the given time
296 	bool operator==(const Time &rhs)const
297 	{ return time.is_equal(rhs); }
298 	//! True if the waypoint's time is different than the given time
299 	bool operator!=(const Time &rhs)const
300 	{ return !time.is_equal(rhs); }
301 
302 	//! True if the Waypoint's Unique Id is the same than the argument's Unique ID
303 	bool operator==(const UniqueID &rhs)const
304 	{ return get_uid()==rhs.get_uid(); }
305 	//! True if the Waypoint's Unique Id is different than the argument's Unique ID
306 	bool operator!=(const UniqueID &rhs)const
307 	{ return get_uid()!=rhs.get_uid(); }
308 
309 
310 	//! Clones the Value Node if it is not exported and returns a Waypoint
311 	//! with no parent.
312 	Waypoint clone(etl::loose_handle<Canvas> canvas, const GUID& deriv_guid=GUID())const;
313 
314 	//! Returns a hack GUID using the UniqueID's value
315 	GUID get_guid()const;
316 }; // END of class Waypoint
317 
318 typedef std::vector< Waypoint > WaypointList;
319 
320 }; // END of namespace synfig
321 
322 /* === E N D =============================================================== */
323 
324 #endif
325