1 /* === S Y N F I G ========================================================= */
3 ** \brief Base class for Layers and Value Nodes.
4 ** It defines the base members for the parent - child relationship,
5 ** the times where the node is modified and the handling of
6 ** the GUID on deletion and changing.
11 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
12 ** Copyright (c) 2007 Chris Moore
14 ** This package is free software; you can redistribute it and/or
15 ** modify it under the terms of the GNU General Public License as
16 ** published by the Free Software Foundation; either version 2 of
17 ** the License, or (at your option) any later version.
19 ** This package is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ** General Public License for more details.
25 /* ========================================================================= */
27 /* === S T A R T =========================================================== */
29 #ifndef __SYNFIG_PARENTNODE_H
30 #define __SYNFIG_PARENTNODE_H
32 /* === H E A D E R S ======================================================= */
34 #include <sigc++/signal.h>
39 #include "interpolation.h"
42 /* === M A C R O S ========================================================= */
44 // When a PasteCanvas layer has a non-zero 'time offset' parameter, should
45 // the waypoints shown for the canvas be adjusted? This currently only
46 // partially works - see the TODO at the end of layer_pastecanvas.cpp
47 #define ADJUST_WAYPOINTS_FOR_TIME_OFFSET
49 /* === T Y P E D E F S ===================================================== */
51 /* === C L A S S E S & S T R U C T S ======================================= */
55 //!\brief TimePoint class: holds the time and the before and after interpolation mode
57 * It includes a GUID, to make it unique
58 * \see guid.h interpolation.h
64 Interpolation before,after;
67 TimePoint(const Time& x=Time::begin()):
70 before(INTERPOLATION_NIL),
71 after(INTERPOLATION_NIL)
76 const char *c_str()const;
79 const GUID& get_guid()const { return guid; }
80 const Time& get_time()const { return time; }
81 Interpolation get_before()const { return before; }
82 Interpolation get_after()const { return after; }
84 void set_guid(const GUID& x) { guid=x; }
85 void set_time(const Time& x) { time=x; }
86 void set_before(Interpolation x) { before=x; }
87 void set_after(Interpolation x) { after=x; }
89 //! Modify the TimePoint based on the values of \x "merging"
90 //! the interpolations. Used to insert a Time Point in a Time Points Set
91 //! \see TimePointSet::iterator TimePointSet::insert(const TimePoint& x)
92 void absorb(const TimePoint& x);
93 }; // END of class TimePoint
95 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
96 { lhs.set_time(lhs.get_time()+rhs); return lhs; }
98 inline TimePoint operator-(TimePoint lhs,const Time& rhs)
99 { lhs.set_time(lhs.get_time()-rhs); return lhs; }
101 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
102 { return lhs.get_time()<rhs.get_time(); }
104 inline bool operator<(const TimePoint& lhs,const Time& rhs)
105 { return lhs.get_time()<rhs; }
107 inline bool operator<(const Time& lhs,const TimePoint& rhs)
108 { return lhs<rhs.get_time(); }
110 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
111 { return lhs.get_time()==rhs.get_time(); }
113 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
114 { return lhs.get_time()!=rhs.get_time(); }
116 class TimePointSet : public std::set<TimePoint>
119 iterator insert(const TimePoint& x);
121 template <typename ITER> void insert(ITER begin, ITER end)
122 { for(;begin!=end;++begin) insert(*begin); }
124 }; // END of class TimePointSet
126 class Node : public etl::rshared_object
129 -- ** -- T Y P E S -----------------------------------------------------------
135 typedef TimePointSet time_set;
138 -- ** -- D A T A -------------------------------------------------------------
146 //! cached time values for all the children
147 mutable time_set times;
150 mutable bool bchanged;
153 mutable int time_last_changed_;
156 mutable RWLock rw_lock_;
163 //! \todo This should really be private
164 std::set<Node*> parent_set;
167 -- ** -- S I G N A L S -------------------------------------------------------
172 sigc::signal<void> signal_changed_;
175 /*! \note The second parameter is the *OLD* guid! */
176 sigc::signal<void,GUID> signal_guid_changed_;
179 sigc::signal<void> signal_deleted_;
182 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
187 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
189 sigc::signal<void>& signal_changed() { return signal_changed_; }
192 /*! \note The second parameter is the *OLD* guid! */
193 sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
196 -- ** -- C O N S T R U C T O R S ---------------------------------------------
203 // This class cannot be copied -- use clone() if necessary
211 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
218 //! Gets the GUID for this Node
219 const GUID& get_guid()const;
221 //! Sets the GUID for this Node
222 void set_guid(const GUID& x);
224 //! Gets the time when the Node was changed
225 int get_time_last_changed()const;
227 //! Adds the parameter \x as the child of the current Node
228 void add_child(Node*x);
230 //! Removes the parameter \x as a child of the current Node
231 void remove_child(Node*x);
233 //!Returns how many parenst has the current Node
234 int parent_count()const;
236 //! Returns the cached times values for all the children
237 const time_set &get_times() const;
240 RWLock& get_rw_lock()const { return rw_lock_; }
247 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
251 //! Used when the node has changed. Makes changed the parent too.
252 //! To be overloaded by the derivative classes. Emits a signal where the
253 //! the GUI can be connected to.
254 virtual void on_changed();
256 //! Used when the node's GUID has changed.
257 //! To be overloaded by the derivative classes. Emits a signal where the
258 //! the GUI can be connected to.
259 virtual void on_guid_changed(GUID guid);
261 //! Function to be overloaded that fills the Time Point Set with
262 //! all the children Time Points.
263 virtual void get_times_vfunc(time_set &set) const = 0;
264 }; // End of Node class
266 //! Finds a node by its GUID.
267 //! \see global_node_map()
268 synfig::Node* find_node(const synfig::GUID& guid);
270 //! Returns a Handle to the Node by its GUID
271 template<typename T> etl::handle<T>
272 guid_cast(const synfig::GUID& guid)
274 return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
278 template <typename T>
279 synfig::String set_string(T start, T end)
281 synfig::String ret("[");
282 bool started = false;
286 if (started) ret += ", ";
289 ret += synfig::String((*start).c_str());
296 template <typename T>
297 synfig::String set_string(T set)
299 return set_string(set.begin(), set.end());
303 typedef etl::handle<Node> NodeHandle;
305 }; // END of namespace synfig
307 /* === E N D =============================================================== */