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