Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_03 / synfig-core / src / synfig / canvas.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvas.h
3 **      \brief Canvas Class Implementation
4 **
5 **      $Id: canvas.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_CANVAS_H
26 #define __SYNFIG_CANVAS_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <map>
31 #include <list>
32 #include <ETL/handle>
33 #include <sigc++/signal.h>
34
35 #include "vector.h"
36 #include "string.h"
37 #include "canvasbase.h"
38 #include "valuenode.h"
39 #include "keyframe.h"
40 #include "renddesc.h"
41 #include "node.h"
42 #include "guid.h"
43
44 /* === M A C R O S ========================================================= */
45
46 /* === T Y P E D E F S ===================================================== */
47
48 /* === C L A S S E S & S T R U C T S ======================================= */
49
50 namespace synfig {
51
52 class Context;
53 class GUID;
54         
55 /*!     \class Canvas
56 **      \todo writeme
57 */
58 class Canvas : public CanvasBase, public Node
59 {
60         /*
61  --     ** -- T Y P E S -----------------------------------------------------------
62         */
63
64 public:
65         typedef etl::handle<Canvas> Handle;
66         typedef etl::loose_handle<Canvas> LooseHandle;
67         typedef etl::handle<const Canvas> ConstHandle;
68
69         typedef std::list<Handle> Children;
70
71         friend void synfig::optimize_layers(Context, Canvas::Handle);
72
73         /*
74  --     ** -- D A T A -------------------------------------------------------------
75         */
76
77 private:
78
79         //! Contains the ID string for the Canvas
80         /*!     \see get_id(), set_id() */
81         String id_;
82
83         //! Contains the name of the Canvas
84         /*!     \see set_name(), get_name() */
85         String name_;
86
87         //! Contains a description of the Canvas
88         /*!     \see set_description(), get_description() */
89         String description_;
90
91         //! Contains the author's name
92         /*!     \see set_author(), get_author() */
93         String author_;
94
95         //! Contains the author's email address
96         /*!     \todo This private parameter has no binding, so it's unusable at the moment */
97         String email_;
98
99         //! File name of Canvas
100         /*! \see get_file_name(), set_file_name() */
101         String file_name_;
102
103         //! Metadata map for Canvas.
104         /*! \see get_meta_data(), set_meta_data(), erase_meta_data() */
105         std::map<String, String> meta_data_;
106
107         //! Contains a list of ValueNodes that are in this Canvas
108         /*!     \see value_node_list(), find_value_node() */
109         ValueNodeList value_node_list_;
110
111         //! \writeme
112         KeyframeList keyframe_list_;
113
114         //! A handle to the parent canvas of this canvas.
115         /*!     If canvas is a root canvas, then this handle is empty
116         **      \see parent()
117         */
118         LooseHandle parent_;
119
120         //! List containing any child Canvases
121         /*!     \see children() */
122         Children children_;             
123         
124         //! Render Description for Canvas
125         /*!     \see rend_desc() */
126     RendDesc desc_;
127
128         //! Contains the value of the last call to set_time()
129         Time cur_time_;
130
131         //! \writeme
132         mutable std::map<String,Handle> externals_;
133         
134         //! This flag is set if this canvas is "inline"
135         bool is_inline_;
136
137         mutable bool is_dirty_;
138         
139         bool op_flag_;
140         
141         //! Layer Group database
142         std::map<String,std::set<etl::handle<Layer> > > group_db_;      
143
144         /*
145  -- ** -- S I G N A L S -------------------------------------------------------
146         */
147
148 private:
149
150         //!     Group Added
151         sigc::signal<void,String> signal_group_added_;  
152
153         //!     Group Removed
154         sigc::signal<void,String> signal_group_removed_;        
155         
156         //! Group Changed
157         sigc::signal<void,String> signal_group_changed_;        
158
159         sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_added_;
160         sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_removed_;
161
162         //!     Layers Reordered
163         sigc::signal<void,int*> signal_layers_reordered_;       
164         
165         //!     RendDesc Changed
166         sigc::signal<void> signal_rend_desc_changed_;   
167         
168         //!     ID Changed
169         sigc::signal<void> signal_id_changed_;  
170
171         //!     Dirty
172         //sigc::signal<void> signal_dirty_;     
173
174         //!     FileName Changed
175         sigc::signal<void> signal_file_name_changed_;   
176
177         //!     Metadata Changed
178         sigc::signal<void, String> signal_meta_data_changed_;   
179
180         //! Key-Specific meta data changed signals
181         std::map<String, sigc::signal<void> > signal_map_meta_data_changed_;
182
183
184         //!     ValueBasenode Changed
185         sigc::signal<void, etl::handle<ValueNode> > signal_value_node_changed_; 
186
187         sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_added_;     
188
189         sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_removed_;   
190
191         /*
192  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
193         */
194
195 public:
196
197         sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_added() { return signal_group_pair_added_; }
198         sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_removed() { return signal_group_pair_removed_; }
199
200         //!     Group Added
201         sigc::signal<void,String>& signal_group_added() { return signal_group_added_; }
202
203         //!     Group Removed
204         sigc::signal<void,String>& signal_group_removed() { return signal_group_removed_; }
205         
206         //! Group Changed
207         sigc::signal<void,String>& signal_group_changed() { return signal_group_changed_; }
208
209         //!     Layers Reordered
210         sigc::signal<void,int*>& signal_layers_reordered() { return signal_layers_reordered_; }
211         
212         //!     RendDesc Changed
213         sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
214         
215         //!     ID Changed
216         sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
217
218         //!     File name Changed
219         sigc::signal<void>& signal_file_name_changed();
220         
221         //!     Metadata Changed
222         sigc::signal<void, String>& signal_meta_data_changed() { return signal_meta_data_changed_; }
223
224         //!     Metadata Changed
225         sigc::signal<void>& signal_meta_data_changed(const String& key) { return signal_map_meta_data_changed_[key]; }
226         
227
228         sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_changed() { return signal_value_node_changed_; } 
229
230         //!     Dirty
231         sigc::signal<void>& signal_dirty() { return signal_changed();   }
232
233         //! \writeme
234         sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_added() { return signal_value_node_child_added_; }
235
236         //! \writeme
237         sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_removed() { return signal_value_node_child_removed_; }
238
239         /*
240  --     ** -- C O N S T R U C T O R S ---------------------------------------------
241         */
242
243 protected:
244
245         Canvas(const String &name);
246
247 public:
248
249         ~Canvas();
250
251         /*
252  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
253         */
254
255 public:
256
257         //! Returns the set of layers in group
258         std::set<etl::handle<Layer> > get_layers_in_group(const String&group);
259         
260         //! Gets all the groups
261         std::set<String> get_groups()const;
262         
263         //! Gets the number of groups in this canvas
264         int get_group_count()const;
265
266         //! Renames the given group
267         void rename_group(const String&old_name,const String&new_name);
268
269         //! \writeme
270         bool is_inline()const { return is_inline_; }
271
272         //! Returns a handle to the RendDesc for this Canvas
273         RendDesc &rend_desc() { return desc_; }
274
275         //! Returns a handle to the RendDesc for this Canvas
276         const RendDesc &rend_desc()const { return desc_; }
277
278         //! Gets the name of the canvas
279         const String & get_name()const { return name_; }
280
281         //! Sets the name of the canvas
282         void set_name(const String &x);
283
284         //! Gets the author of the canvas
285         const String & get_author()const { return author_; }
286
287         //! Sets the author of the canvas
288         void set_author(const String &x);
289
290         //! Gets the description of the canvas
291         const String & get_description()const { return description_; }
292
293         //! Sets the name of the canvas
294         void set_description(const String &x);
295
296         //! Gets the ID of the canvas
297         const String & get_id()const { return id_; }
298
299         //! Sets the ID of the canvas
300         void set_id(const String &x);
301         
302         //!     Returns the data string for the given meta data key
303         String get_meta_data(const String& key)const;
304
305         //!     Returns a list of meta data keys
306         std::list<String> get_meta_data_keys()const;
307
308         //! Sets a meta data key to a specific string
309         void set_meta_data(const String& key, const String& data);
310
311         //! Removes a meta data key
312         void erase_meta_data(const String& key);
313
314         //! \writeme
315         String get_relative_id(etl::loose_handle<const Canvas> x)const;
316
317         //! \internal \writeme
318         String _get_relative_id(etl::loose_handle<const Canvas> x)const;
319
320         //! Returns \c true if the Canvas is a root Canvas. \c false otherwise
321         bool is_root()const { return !parent_; }
322
323         //! Returns a handle to the parent Canvas.
324         /*! The returned handle will be empty if this is a root canvas */
325         LooseHandle parent()const { return parent_; }
326
327         LooseHandle get_root()const;
328         
329         //! Returns a list of all child canvases in this canvas
330         std::list<Handle> &children() { return children_; }
331
332         //! Returns a list of all child canvases in this canvas
333         const std::list<Handle> &children()const { return children_; }
334
335         //! Gets the color at the specified point
336         //Color get_color(const Point &pos)const;
337
338         //! Sets the time for all the layers in the canvas
339         void set_time(Time t)const;
340
341         //! \writeme
342         Time get_time()const { return cur_time_; }
343
344         //! Returns the number of layers in the canvas
345         int size()const;
346
347         //! Removes all the layers from the canvas
348         void clear();
349
350         //! Returns true if the canvas has no layers
351         bool empty()const;
352
353         //! Returns a reference to the ValueNodeList for this Canvas
354         // ValueNodeList &value_node_list() { return value_node_list_; }
355
356         //! Returns a reference to the ValueNodeList for this Canvas
357         const ValueNodeList &value_node_list()const;
358
359         //! Returns a reference to the KeyframeList for this Canvas
360         KeyframeList &keyframe_list();
361
362         //! Returns a reference to the KeyframeList for this Canvas
363         const KeyframeList &keyframe_list()const;
364
365         //! Finds the ValueNode in the Canvas with the given \a id
366         /*!     \return If found, returns a handle to the ValueNode.
367         **              Otherwise, returns an empty handle.
368         */
369         ValueNode::Handle find_value_node(const String &id);
370
371         //! \internal \writeme
372         ValueNode::Handle surefind_value_node(const String &id);
373
374         //! Finds the ValueNode in the Canvas with the given \a id
375         /*!     \return If found, returns a handle to the ValueNode.
376         **              Otherwise, returns an empty handle.
377         */
378         ValueNode::ConstHandle find_value_node(const String &id)const;
379
380         //! \writeme
381         void add_value_node(ValueNode::Handle x, const String &id);
382
383         //! \writeme
384         //void rename_value_node(ValueNode::Handle x, const String &id);
385
386         //! \writeme
387         void remove_value_node(ValueNode::Handle x);
388
389         //! \writeme
390         void remove_value_node(const String &id) { remove_value_node(find_value_node(id)); }
391
392         //! Finds a child Canvas in the Canvas with the given \a name
393         /*!     \return If found, returns a handle to the child Canvas.
394         **              If not found, it creates a new Canvas and returns it
395         **              If an error occurs, it returns an empty handle
396         */
397         Handle surefind_canvas(const String &id);
398
399         //! Finds a child Canvas in the Canvas with the given \a id
400         /*!     \return If found, returns a handle to the child Canvas.
401         **              Otherwise, returns an empty handle.
402         */
403         Handle find_canvas(const String &id);
404
405         //! Finds a child Canvas in the Canvas with the given \a id
406         /*!     \return If found, returns a handle to the child Canvas.
407         **              Otherwise, returns an empty handle.
408         */
409         ConstHandle find_canvas(const String &id)const;
410
411         //! Sets the file path for the Canvas
412         //void set_file_path(const String &);
413
414         //! Returns the file path from the file name
415         String get_file_path()const;
416
417         //! Sets the filename (with path)
418         void set_file_name(const String &);
419
420         //! Gets the filename (with path)
421         String get_file_name()const;
422         
423         //! Creates a new child canvas, and returns its handle
424         Handle new_child_canvas();
425
426         //! Creates a new child canvas with an ID of \aid, and returns its handle
427         Handle new_child_canvas(const String &id);
428
429         //! Adds the given canvas as a child
430         Handle add_child_canvas(Handle child_canvas, const String &id);
431
432         void remove_child_canvas(Handle child_canvas);
433
434         etl::handle<Layer> find_layer(const Point &pos);
435
436         int get_depth(etl::handle<Layer>)const;
437
438         Context get_context()const;
439
440         iterator end();
441
442         const_iterator end()const;
443
444         reverse_iterator rbegin();
445
446         const_reverse_iterator rbegin()const;
447
448         etl::handle<Layer> &back();
449         
450         void push_back(etl::handle<Layer> x);
451
452         void push_front(etl::handle<Layer> x);
453
454         void push_back_simple(etl::handle<Layer> x);
455
456         void insert(iterator iter,etl::handle<Layer> x);
457         void erase(iterator iter);
458         
459         const etl::handle<Layer> &back()const;
460
461         void set_inline(LooseHandle parent);
462
463         static Handle create();
464
465         static Handle create_inline(Handle parent);
466         
467         Handle clone(const GUID& deriv_guid=GUID())const;
468
469 private:
470         void add_group_pair(String group, etl::handle<Layer> layer);
471         void remove_group_pair(String group, etl::handle<Layer> layer);
472
473 protected:
474         virtual void on_changed();
475         virtual void get_times_vfunc(Node::time_set &set) const;
476 }; // END of class Canvas
477
478 void optimize_layers(Context context, Canvas::Handle op_canvas);
479
480
481 }; // END of namespace synfig
482
483 /* === E N D =============================================================== */
484
485 #endif