synfig-core  1.0.3
node.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
25 /* ========================================================================= */
26 
27 /* === S T A R T =========================================================== */
28 
29 #ifndef __SYNFIG_PARENTNODE_H
30 #define __SYNFIG_PARENTNODE_H
31 
32 /* === H E A D E R S ======================================================= */
33 
34 #include <sigc++/signal.h>
35 #include <set>
36 #include "time.h"
37 #include "guid.h"
38 #include <ETL/handle>
39 #include "interpolation.h"
40 #include "mutex.h"
41 
42 /* === M A C R O S ========================================================= */
43 
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
48 
49 /* === T Y P E D E F S ===================================================== */
50 
51 /* === C L A S S E S & S T R U C T S ======================================= */
52 
53 namespace synfig {
54 
56 
60 class TimePoint
61 {
62  GUID guid;
63  Time time;
64  Interpolation before,after;
65 public:
66 
67  TimePoint(const Time& x=Time::begin()):
68  guid(0),
69  time(x),
70  before(INTERPOLATION_NIL),
71  after(INTERPOLATION_NIL)
72  {
73  }
74 
75 #ifdef _DEBUG
76  const char *c_str()const;
77 #endif
78 
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; }
83 
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; }
88 
92  void absorb(const TimePoint& x);
93 }; // END of class TimePoint
94 
95 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
96  { lhs.set_time(lhs.get_time()+rhs); return lhs; }
97 
98 inline TimePoint operator-(TimePoint lhs,const Time& rhs)
99  { lhs.set_time(lhs.get_time()-rhs); return lhs; }
100 
101 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
102  { return lhs.get_time()<rhs.get_time(); }
103 
104 inline bool operator<(const TimePoint& lhs,const Time& rhs)
105  { return lhs.get_time()<rhs; }
106 
107 inline bool operator<(const Time& lhs,const TimePoint& rhs)
108  { return lhs<rhs.get_time(); }
109 
110 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
111  { return lhs.get_time()==rhs.get_time(); }
112 
113 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
114  { return lhs.get_time()!=rhs.get_time(); }
115 
116 class TimePointSet : public std::set<TimePoint>
117 {
118 public:
119  iterator insert(const TimePoint& x);
120 
121  template <typename ITER> void insert(ITER begin, ITER end)
122  { for(;begin!=end;++begin) insert(*begin); }
123 
124 }; // END of class TimePointSet
125 
126 class Node : public etl::rshared_object
127 {
128  /*
129  -- ** -- T Y P E S -----------------------------------------------------------
130  */
131 
132 public:
133 
136 
137  /*
138  -- ** -- D A T A -------------------------------------------------------------
139  */
140 
141 private:
142 
144  GUID guid_;
145 
147  mutable time_set times;
148 
150  mutable bool bchanged;
151 
154  mutable int time_last_changed_;
155 
158  mutable RWLock rw_lock_;
159 
161  bool deleting_;
162 
163 public:
164 
167  std::set<Node*> parent_set;
168 
169  /*
170  -- ** -- S I G N A L S -------------------------------------------------------
171  */
172 
173 private:
174 
176  sigc::signal<void> signal_changed_;
177 
179 
180  sigc::signal<void,GUID> signal_guid_changed_;
181 
183  sigc::signal<void> signal_deleted_;
184 
185  /*
186  -- ** -- S I G N A L I N T E R F A C E -------------------------------------
187  */
188 
189 public:
190 
191  sigc::signal<void>& signal_deleted() { return signal_deleted_; }
192 
193  sigc::signal<void>& signal_changed() { return signal_changed_; }
194 
196 
197  sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
198 
199  /*
200  -- ** -- C O N S T R U C T O R S ---------------------------------------------
201  */
202 
203 protected:
204 
205  Node();
206 
207  // This class cannot be copied -- use clone() if necessary
208 private:
209  Node(const Node &x);
210 
211 public:
212  virtual ~Node();
213 
214  /*
215  -- ** -- M E M B E R F U N C T I O N S -------------------------------------
216  */
217 
218 public:
219 
220  void changed();
221 
223  const GUID& get_guid()const;
224 
226  virtual void set_guid(const GUID& x);
227 
229  int get_time_last_changed()const;
230 
232  void add_child(Node*x);
233 
235  void remove_child(Node*x);
236 
238  int parent_count()const;
239 
241  const time_set &get_times() const;
242 
244  RWLock& get_rw_lock()const { return rw_lock_; }
245 
246  virtual String get_string()const = 0;
247 protected:
248 
249  void begin_delete();
250 
251  /*
252  -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
253  */
254 
255 protected:
259  virtual void on_changed();
260 
264  virtual void on_guid_changed(GUID guid);
265 
268  virtual void get_times_vfunc(time_set &set) const = 0;
269 }; // End of Node class
270 
273 synfig::Node* find_node(const synfig::GUID& guid);
274 
276 template<typename T> etl::handle<T>
278 {
279  return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
280 }
281 
282 #ifdef _DEBUG
283 template <typename T>
284 synfig::String set_string(T start, T end)
285 {
286  synfig::String ret("[");
287  bool started = false;
288 
289  while (start != end)
290  {
291  if (started) ret += ", ";
292  else started = true;
293 
294  ret += synfig::String((*start).c_str());
295  start++;
296  }
297 
298  return ret + "]";
299 }
300 
301 template <typename T>
302 synfig::String set_string(T set)
303 {
304  return set_string(set.begin(), set.end());
305 }
306 #endif // _DEBUG
307 
308 typedef etl::handle<Node> NodeHandle;
309 
310 }; // END of namespace synfig
311 
312 /* === E N D =============================================================== */
313 
314 #endif