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