1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_PARENTNODE_H
27 #define __SYNFIG_PARENTNODE_H
29 /* === H E A D E R S ======================================================= */
31 #include <sigc++/signal.h>
36 #include "interpolation.h"
39 /* === M A C R O S ========================================================= */
41 // When a PasteCanvas layer has a non-zero 'time offset' parameter, should
42 // the waypoints shown for the canvas be adjusted? This currently only
43 // partially works - see the TODO at the end of layer_pastecanvas.cpp
44 #define ADJUST_WAYPOINTS_FOR_TIME_OFFSET
46 /* === T Y P E D E F S ===================================================== */
48 /* === C L A S S E S & S T R U C T S ======================================= */
56 Interpolation before,after;
59 TimePoint(const Time& x=Time::begin()):
62 before(INTERPOLATION_NIL),
63 after(INTERPOLATION_NIL)
68 const char *c_str()const;
71 const GUID& get_guid()const { return guid; }
72 const Time& get_time()const { return time; }
73 Interpolation get_before()const { return before; }
74 Interpolation get_after()const { return after; }
76 void set_guid(const GUID& x) { guid=x; }
77 void set_time(const Time& x) { time=x; }
78 void set_before(Interpolation x) { before=x; }
79 void set_after(Interpolation x) { after=x; }
81 void absorb(const TimePoint& x);
82 }; // END of class TimePoint
84 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
85 { lhs.set_time(lhs.get_time()+rhs); return lhs; }
87 inline TimePoint operator-(TimePoint lhs,const Time& rhs)
88 { lhs.set_time(lhs.get_time()-rhs); return lhs; }
90 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
91 { return lhs.get_time()<rhs.get_time(); }
93 inline bool operator<(const TimePoint& lhs,const Time& rhs)
94 { return lhs.get_time()<rhs; }
96 inline bool operator<(const Time& lhs,const TimePoint& rhs)
97 { return lhs<rhs.get_time(); }
99 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
100 { return lhs.get_time()==rhs.get_time(); }
102 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
103 { return lhs.get_time()!=rhs.get_time(); }
105 class TimePointSet : public std::set<TimePoint>
108 iterator insert(const TimePoint& x);
110 template <typename ITER> void insert(ITER begin, ITER end)
111 { for(;begin!=end;++begin) insert(*begin); }
113 }; // END of class TimePointSet
115 class Node : public etl::rshared_object
118 -- ** -- T Y P E S -----------------------------------------------------------
124 typedef TimePointSet time_set;
127 -- ** -- D A T A -------------------------------------------------------------
135 //! cached time values for all the children
136 mutable time_set times;
139 mutable bool bchanged;
142 mutable int time_last_changed_;
145 mutable RWLock rw_lock_;
152 //! \todo This should really be private
153 std::set<Node*> parent_set;
156 -- ** -- S I G N A L S -------------------------------------------------------
161 sigc::signal<void> signal_changed_;
164 /*! \note The second parameter is the *OLD* guid! */
165 sigc::signal<void,GUID> signal_guid_changed_;
168 sigc::signal<void> signal_deleted_;
171 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
176 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
178 sigc::signal<void>& signal_changed() { return signal_changed_; }
181 /*! \note The second parameter is the *OLD* guid! */
182 sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
185 -- ** -- C O N S T R U C T O R S ---------------------------------------------
192 // This class cannot be copied -- use clone() if necessary
200 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
207 //! Gets the GUID for this value node
208 const GUID& get_guid()const;
210 //! Sets the GUID for this value node
211 void set_guid(const GUID& x);
213 int get_time_last_changed()const;
215 void add_child(Node*x);
217 void remove_child(Node*x);
219 int parent_count()const;
221 const time_set &get_times() const;
223 RWLock& get_rw_lock()const { return rw_lock_; }
230 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
234 virtual void on_changed();
236 virtual void on_guid_changed(GUID guid);
238 /*! Function to be overloaded that fills
240 virtual void get_times_vfunc(time_set &set) const = 0;
243 synfig::Node* find_node(const synfig::GUID& guid);
245 template<typename T> etl::handle<T>
246 guid_cast(const synfig::GUID& guid)
248 return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
252 template <typename T>
253 synfig::String set_string(T start, T end)
255 synfig::String ret("[");
256 bool started = false;
260 if (started) ret += ", ";
263 ret += synfig::String((*start).c_str());
270 template <typename T>
271 synfig::String set_string(T set)
273 return set_string(set.begin(), set.end());
277 typedef etl::handle<Node> NodeHandle;
279 }; // END of namespace synfig
281 /* === E N D =============================================================== */