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)
67 const char *c_str()const;
70 const GUID& get_guid()const { return guid; }
71 const Time& get_time()const { return time; }
72 Interpolation get_before()const { return before; }
73 Interpolation get_after()const { return after; }
75 void set_guid(const GUID& x) { guid=x; }
76 void set_time(const Time& x) { time=x; }
77 void set_before(Interpolation x) { before=x; }
78 void set_after(Interpolation x) { after=x; }
80 void absorb(const TimePoint& x);
81 }; // END of class TimePoint
83 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
84 { lhs.set_time(lhs.get_time()+rhs); return lhs; }
86 inline TimePoint operator-(TimePoint lhs,const Time& rhs)
87 { lhs.set_time(lhs.get_time()-rhs); return lhs; }
89 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
90 { return lhs.get_time()<rhs.get_time(); }
92 inline bool operator<(const TimePoint& lhs,const Time& rhs)
93 { return lhs.get_time()<rhs; }
95 inline bool operator<(const Time& lhs,const TimePoint& rhs)
96 { return lhs<rhs.get_time(); }
98 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
99 { return lhs.get_time()==rhs.get_time(); }
101 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
102 { return lhs.get_time()!=rhs.get_time(); }
104 class TimePointSet : public std::set<TimePoint>
107 iterator insert(const TimePoint& x);
109 template <typename ITER> void insert(ITER begin, ITER end)
110 { for(;begin!=end;++begin) insert(*begin); }
112 }; // END of class TimePointSet
114 class Node : public etl::rshared_object
117 -- ** -- T Y P E S -----------------------------------------------------------
123 typedef TimePointSet time_set;
126 -- ** -- D A T A -------------------------------------------------------------
134 //! cached time values for all the children
135 mutable time_set times;
138 mutable bool bchanged;
141 mutable int time_last_changed_;
144 mutable RWLock rw_lock_;
151 //! \todo This should really be private
152 std::set<Node*> parent_set;
155 -- ** -- S I G N A L S -------------------------------------------------------
160 sigc::signal<void> signal_changed_;
163 /*! \note The second parameter is the *OLD* guid! */
164 sigc::signal<void,GUID> signal_guid_changed_;
167 sigc::signal<void> signal_deleted_;
170 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
175 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
177 sigc::signal<void>& signal_changed() { return signal_changed_; }
180 /*! \note The second parameter is the *OLD* guid! */
181 sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
184 -- ** -- C O N S T R U C T O R S ---------------------------------------------
191 // This class cannot be copied -- use clone() if necessary
199 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
206 //! Gets the GUID for this value node
207 const GUID& get_guid()const;
209 //! Sets the GUID for this value node
210 void set_guid(const GUID& x);
212 int get_time_last_changed()const;
214 void add_child(Node*x);
216 void remove_child(Node*x);
218 int parent_count()const;
220 const time_set &get_times() const;
222 RWLock& get_rw_lock()const { return rw_lock_; }
229 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
233 virtual void on_changed();
235 virtual void on_guid_changed(GUID guid);
237 /*! Function to be overloaded that fills
239 virtual void get_times_vfunc(time_set &set) const = 0;
242 synfig::Node* find_node(const synfig::GUID& guid);
244 template<typename T> etl::handle<T>
245 guid_cast(const synfig::GUID& guid)
247 return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
251 template <typename T>
252 synfig::String set_string(T start, T end)
254 synfig::String ret("[");
255 bool started = false;
259 if (started) ret += ", ";
262 ret += synfig::String((*start).c_str());
269 template <typename T>
270 synfig::String set_string(T set)
272 return set_string(set.begin(), set.end());
276 typedef etl::handle<Node> NodeHandle;
278 }; // END of namespace synfig
280 /* === E N D =============================================================== */