1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_PARENTNODE_H
26 #define __SYNFIG_PARENTNODE_H
28 /* === H E A D E R S ======================================================= */
30 #include <sigc++/signal.h>
35 #include "interpolation.h"
38 /* === M A C R O S ========================================================= */
40 // When a PasteCanvas layer has a non-zero 'time offset' parameter, should
41 // the waypoints shown for the canvas be adjusted? This currently only
42 // partially works - see the TODO at the end of layer_pastecanvas.cpp
43 #define ADJUST_WAYPOINTS_FOR_TIME_OFFSET
45 /* === T Y P E D E F S ===================================================== */
47 /* === C L A S S E S & S T R U C T S ======================================= */
55 Interpolation before,after;
58 TimePoint(const Time& x=Time::begin()):
61 before(INTERPOLATION_NIL),
62 after(INTERPOLATION_NIL)
66 const GUID& get_guid()const { return guid; }
67 const Time& get_time()const { return time; }
68 Interpolation get_before()const { return before; }
69 Interpolation get_after()const { return after; }
71 void set_guid(const GUID& x) { guid=x; }
72 void set_time(const Time& x) { time=x; }
73 void set_before(Interpolation x) { before=x; }
74 void set_after(Interpolation x) { after=x; }
76 void absorb(const TimePoint& x);
77 }; // END of class TimePoint
79 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
80 { lhs.set_time(lhs.get_time()+rhs); return lhs; }
82 inline TimePoint operator-(TimePoint lhs,const Time& rhs)
83 { lhs.set_time(lhs.get_time()-rhs); return lhs; }
85 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
86 { return lhs.get_time()<rhs.get_time(); }
88 inline bool operator<(const TimePoint& lhs,const Time& rhs)
89 { return lhs.get_time()<rhs; }
91 inline bool operator<(const Time& lhs,const TimePoint& rhs)
92 { return lhs<rhs.get_time(); }
94 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
95 { return lhs.get_time()==rhs.get_time(); }
97 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
98 { return lhs.get_time()!=rhs.get_time(); }
100 class TimePointSet : public std::set<TimePoint>
103 iterator insert(const TimePoint& x);
105 template <typename ITER> void insert(ITER begin, ITER end)
106 { for(;begin!=end;++begin) insert(*begin); }
108 }; // END of class TimePointSet
110 class Node : public etl::rshared_object
113 -- ** -- T Y P E S -----------------------------------------------------------
119 typedef TimePointSet time_set;
122 -- ** -- D A T A -------------------------------------------------------------
130 //! cached time values for all the children
131 mutable time_set times;
134 mutable bool bchanged;
137 mutable int time_last_changed_;
140 mutable RWLock rw_lock_;
147 //! \todo This should really be private
148 std::set<Node*> parent_set;
151 -- ** -- S I G N A L S -------------------------------------------------------
156 sigc::signal<void> signal_changed_;
159 /*! \note The second parameter is the *OLD* guid! */
160 sigc::signal<void,GUID> signal_guid_changed_;
163 sigc::signal<void> signal_deleted_;
166 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
171 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
173 sigc::signal<void>& signal_changed() { return signal_changed_; }
176 /*! \note The second parameter is the *OLD* guid! */
177 sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
180 -- ** -- C O N S T R U C T O R S ---------------------------------------------
187 // This class cannot be copied -- use clone() if necessary
195 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
202 //! Gets the GUID for this value node
203 const GUID& get_guid()const;
205 //! Sets the GUID for this value node
206 void set_guid(const GUID& x);
208 int get_time_last_changed()const;
210 void add_child(Node*x);
212 void remove_child(Node*x);
214 int parent_count()const;
216 const time_set &get_times() const;
218 RWLock& get_rw_lock()const { return rw_lock_; }
225 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
229 virtual void on_changed();
231 virtual void on_guid_changed(GUID guid);
233 /*! Function to be overloaded that fills
235 virtual void get_times_vfunc(time_set &set) const = 0;
238 synfig::Node* find_node(const synfig::GUID& guid);
240 template<typename T> etl::handle<T>
241 guid_cast(const synfig::GUID& guid)
243 return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
246 typedef etl::handle<Node> NodeHandle;
248 }; // END of namespace synfig
250 /* === E N D =============================================================== */