Typo: 'consistant' -> 'consistent'.
[synfig.git] / synfig-studio / trunk / src / synfigapp / canvasinterface.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasinterface.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 //#include <iostream>
34
35 #include <ETL/clock>
36 #include <synfig/valuenode_scale.h>
37 #include <synfig/valuenode_timedswap.h>
38 #include <synfig/valuenode_composite.h>
39 #include <synfig/valuenode_subtract.h>
40 #include <synfig/valuenode_linear.h>
41 #include <synfig/valuenode_reference.h>
42 #include <synfig/valuenode_twotone.h>
43 #include <synfig/valuenode_stripes.h>
44
45 #include <synfig/waypoint.h>
46 #include <synfig/loadcanvas.h>
47 #include <synfig/importer.h>
48 #include <synfig/guidset.h>
49
50 #include "canvasinterface.h"
51 #include "instance.h"
52
53 #include "actions/layeradd.h"
54 #include "actions/valuedescconvert.h"
55 #include "actions/valuenodeadd.h"
56 #include "actions/editmodeset.h"
57 #include "action_system.h"
58
59 #include "main.h"
60
61 #include <synfig/gradient.h>
62
63 #endif
64
65 /* === U S I N G =========================================================== */
66
67 using namespace std;
68 using namespace etl;
69 using namespace synfig;
70 using namespace synfigapp;
71
72 /* === M A C R O S ========================================================= */
73
74 /* === G L O B A L S ======================================================= */
75
76 /* === P R O C E D U R E S ================================================= */
77
78 /* === M E T H O D S ======================================================= */
79
80 CanvasInterface::CanvasInterface(loose_handle<Instance> instance,handle<Canvas> canvas):
81         instance_(instance),
82         canvas_(canvas),
83         cur_time_(canvas->rend_desc().get_frame_start()),
84         mode_(MODE_NORMAL|MODE_ANIMATE_PAST|MODE_ANIMATE_FUTURE)
85 {
86         set_selection_manager(get_instance()->get_selection_manager());
87         set_ui_interface(get_instance()->get_ui_interface());
88 }
89
90 CanvasInterface::~CanvasInterface()
91 {
92         synfig::info("synfigapp::CanvasInterface::~CanvasInterface(): Deleted");
93 }
94
95 void
96 CanvasInterface::set_time(synfig::Time x)
97 {
98         if(get_canvas()->rend_desc().get_frame_rate())
99         {
100                 float fps(get_canvas()->rend_desc().get_frame_rate());
101                 Time r(x.round(fps));
102                 //synfig::info("CanvasInterface::set_time(): %s rounded to %s\n",x.get_string(fps).c_str(),r.get_string(fps).c_str());
103                 x=r;
104         }
105         if(cur_time_.is_equal(x))
106                 return;
107         get_canvas()->set_time(cur_time_=x);
108
109         // update the time in all the child canvases
110         Canvas::Children children = get_canvas()->get_root()->children();
111         handle<CanvasInterface> interface;
112         for (Canvas::Children::iterator iter = children.begin(); iter != children.end(); iter++)
113                 if ((interface = get_instance()->find_canvas_interface(*iter)) != this)
114                         interface->set_time(interface->get_canvas()->get_time());
115
116         signal_time_changed()();
117         signal_dirty_preview()();
118 }
119
120 synfig::Time
121 CanvasInterface::get_time()const
122 {
123         return cur_time_;
124 }
125
126 void
127 CanvasInterface::refresh_current_values()
128 {
129         get_canvas()->set_time(cur_time_);
130         signal_time_changed()();
131         signal_dirty_preview()();
132 }
133
134 etl::handle<CanvasInterface>
135 CanvasInterface::create(loose_handle<Instance> instance,handle<Canvas> canvas)
136 {
137         etl::handle<CanvasInterface> intrfc;
138         intrfc=new CanvasInterface(instance,canvas);
139         instance->canvas_interface_list().push_front(intrfc);
140         return intrfc;
141 }
142
143 void
144 CanvasInterface::set_mode(Mode x)
145 {
146         Action::Handle  action(Action::EditModeSet::create());
147
148         assert(action);
149
150         action->set_param("canvas",get_canvas());
151         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
152         action->set_param("edit_mode",x);
153
154         if(!action->is_ready())
155         {
156                 get_ui_interface()->error(_("Action Not Ready, unable to change mode"));
157                 assert(0);
158                 return;
159         }
160
161         if(!get_instance()->perform_action(action))
162                 get_ui_interface()->error(_("Unable to change mode"));
163
164 //      mode_=x;
165 //      signal_mode_changed_(x);
166 }
167
168 CanvasInterface::Mode
169 CanvasInterface::get_mode()const
170 {
171         return mode_;
172 }
173
174
175
176 Layer::Handle
177 CanvasInterface::add_layer_to(String name, Canvas::Handle canvas, int depth)
178 {
179         synfigapp::Action::PassiveGrouper group(get_instance().get(),_("Add Layer To"));
180
181         Layer::Handle   layer(Layer::create(name));
182
183         assert(layer);
184
185         if(!layer)
186                 return 0;
187
188         if(canvas!=get_canvas() && !canvas->is_inline())
189         {
190                 synfig::error("Bad canvas passed to \"add_layer_to\"");
191                 return 0;
192         }
193
194         layer->set_canvas(canvas);
195
196         // Apply some defaults
197         if(layer->set_param("fg",synfigapp::Main::get_foreground_color()))
198                 layer->set_param("bg",synfigapp::Main::get_background_color());
199         else
200                 layer->set_param("color",synfigapp::Main::get_foreground_color());
201
202         layer->set_param("width",synfigapp::Main::get_bline_width().units(get_canvas()->rend_desc()));
203         layer->set_param("gradient",synfigapp::Main::get_gradient());
204         if(name!="zoom")
205                 layer->set_param("amount",synfigapp::Main::get_opacity());
206         layer->set_param("blend_method",synfigapp::Main::get_blend_method());
207
208         {
209                 // Grab the layer's list of parameters
210                 Layer::ParamList paramlist=layer->get_param_list();
211                 Layer::ParamList::iterator iter;
212                 for(iter=paramlist.begin();iter!=paramlist.end();++iter)
213                 {
214                         ValueNode::Handle value_node;
215
216                         if(iter->second.get_type()==ValueBase::TYPE_LIST)
217                                 value_node=LinkableValueNode::create("dynamic_list",iter->second);
218                         else if(LinkableValueNode::check_type("composite",iter->second.get_type()) &&
219                                 (iter->second.get_type()!=ValueBase::TYPE_COLOR && iter->second.get_type()!=ValueBase::TYPE_VECTOR)
220                         )
221                                 value_node=LinkableValueNode::create("composite",iter->second);
222
223                         if(value_node)
224                                 layer->connect_dynamic_param(iter->first,value_node);
225                 }
226         }
227
228         // Action to add the layer
229         Action::Handle  action(Action::LayerAdd::create());
230
231         assert(action);
232         if(!action)
233                 return 0;
234
235         action->set_param("canvas",canvas);
236         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
237         action->set_param("new",layer);
238
239         if(!action->is_ready())
240         {
241                 get_ui_interface()->error(_("Action Not Ready"));
242                 return 0;
243         }
244
245         if(!get_instance()->perform_action(action))
246         {
247                 get_ui_interface()->error(_("Action Failed."));
248                 return 0;
249         }
250
251         synfig::info("DEPTH=%d",depth);
252         // Action to move the layer (if necessary)
253         if(depth>0)
254         {
255                 Action::Handle  action(Action::create("layer_move"));
256
257                 assert(action);
258                 if(!action)
259                         return 0;
260
261                 action->set_param("canvas",canvas);
262                 action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
263                 action->set_param("layer",layer);
264                 action->set_param("new_index",depth);
265
266                 if(!action->is_ready())
267                 {
268                         get_ui_interface()->error(_("Move Action Not Ready"));
269                         return 0;
270                 }
271
272                 if(!get_instance()->perform_action(action))
273                 {
274                         get_ui_interface()->error(_("Move Action Failed."));
275                         return 0;
276                 }
277         }
278
279
280         return layer;
281 }
282
283
284 bool
285 CanvasInterface::convert(ValueDesc value_desc, String type)
286 {
287         Action::Handle  action(Action::ValueDescConvert::create());
288
289         assert(action);
290         if(!action)
291                 return 0;
292
293         action->set_param("canvas",get_canvas());
294         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
295         action->set_param("value_desc",value_desc);
296         action->set_param("type",type);
297
298         if(!action->is_ready())
299         {
300                 get_ui_interface()->error(_("Action Not Ready"));
301                 return 0;
302         }
303
304         if(get_instance()->perform_action(action))
305                 return true;
306
307         get_ui_interface()->error(_("Action Failed."));
308         return false;
309 }
310
311 bool
312 CanvasInterface::add_value_node(synfig::ValueNode::Handle value_node, synfig::String name)
313 {
314         if(name.empty())
315         {
316                 get_ui_interface()->error(_("Empty name!"));
317                 return false;
318         }
319
320         Action::Handle  action(Action::ValueNodeAdd::create());
321
322         assert(action);
323         if(!action)
324                 return 0;
325
326         action->set_param("canvas",get_canvas());
327         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
328         action->set_param("new",value_node);
329         action->set_param("name",name);
330
331         if(!action->is_ready())
332         {
333                 get_ui_interface()->error(_("Action Not Ready"));
334                 return 0;
335         }
336
337         if(get_instance()->perform_action(action))
338                 return true;
339
340         get_ui_interface()->error(_("Action Failed."));
341         return false;
342 }
343
344 Action::ParamList
345 CanvasInterface::generate_param_list(const ValueDesc &value_desc)
346 {
347         synfigapp::Action::ParamList param_list;
348         param_list.add("time",get_time());
349         param_list.add("canvas_interface",etl::handle<CanvasInterface>(this));
350         param_list.add("canvas",get_canvas());
351
352         param_list.add("value_desc",value_desc);
353
354         if(value_desc.parent_is_value_node())
355                 param_list.add("parent_value_node",value_desc.get_parent_value_node());
356
357         if(value_desc.is_value_node())
358                 param_list.add("value_node",value_desc.get_value_node());
359
360         if(value_desc.is_const())
361                 param_list.add("value",value_desc.get_value());
362
363         if(value_desc.parent_is_layer_param())
364         {
365                 param_list.add("parent_layer",value_desc.get_layer());
366                 param_list.add("parent_layer_param",value_desc.get_param_name());
367         }
368
369         {
370                 synfigapp::SelectionManager::ChildrenList children_list;
371                 children_list=get_selection_manager()->get_selected_children();
372                 if(!value_desc.parent_is_canvas() && children_list.size()==1)
373                 {
374                         param_list.add("dest",value_desc);
375                         param_list.add("src",children_list.front().get_value_node());
376                 }
377         }
378         return param_list;
379 }
380
381 Action::ParamList
382 CanvasInterface::generate_param_list(const std::list<synfigapp::ValueDesc> &value_desc_list)
383 {
384         synfigapp::Action::ParamList param_list;
385         param_list.add("time",get_time());
386         param_list.add("canvas_interface",etl::handle<CanvasInterface>(this));
387         param_list.add("canvas",get_canvas());
388
389         std::list<synfigapp::ValueDesc>::const_iterator iter;
390         for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
391         {
392                 param_list.add("value_desc",*iter);
393                 if(iter->is_value_node())
394                 {
395                         param_list.add("value_node",iter->get_value_node());
396                 }
397         }
398
399
400         return param_list;
401 }
402
403 void
404 CanvasInterface::set_rend_desc(const synfig::RendDesc &rend_desc)
405 {
406         Action::Handle  action(Action::create("canvas_rend_desc_set"));
407
408         assert(action);
409         if(!action)
410                 return;
411
412         action->set_param("canvas",get_canvas());
413         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
414         action->set_param("rend_desc",rend_desc);
415
416         if(!get_instance()->perform_action(action))
417                 get_ui_interface()->error(_("Action Failed."));
418 }
419
420 bool
421 CanvasInterface::set_name(const String &x)
422 {
423         //! \todo This needs to be converted into an action
424         get_canvas()->set_name(x);
425         signal_id_changed_();
426         return true;
427 }
428
429 bool
430 CanvasInterface::set_description(const String &x)
431 {
432         //! \todo This needs to be converted into an action
433         get_canvas()->set_description(x);
434         return true;
435 }
436
437 bool
438 CanvasInterface::set_id(const String &x)
439 {
440         //! \todo This needs to be converted into an action
441         get_canvas()->set_id(x);
442         signal_id_changed_();
443         return true;
444 }
445
446
447 void
448 CanvasInterface::jump_to_next_keyframe()
449 {
450         synfig::info("Current time: %s",get_time().get_string().c_str());
451         try
452         {
453                 synfig::Keyframe keyframe(*get_canvas()->keyframe_list().find_next(get_time()));
454                 synfig::info("Jumping to keyframe \"%s\" at %s",keyframe.get_description().c_str(),keyframe.get_time().get_string().c_str());
455                 set_time(keyframe.get_time());
456         }
457         catch(...) { synfig::warning("Unable to find next keyframe"); }
458 }
459
460 void
461 CanvasInterface::jump_to_prev_keyframe()
462 {
463         synfig::info("Current time: %s",get_time().get_string().c_str());
464         try
465         {
466                 synfig::Keyframe keyframe(*get_canvas()->keyframe_list().find_prev(get_time()));
467                 synfig::info("Jumping to keyframe \"%s\" at %s",keyframe.get_description().c_str(),keyframe.get_time().get_string().c_str());
468                 set_time(keyframe.get_time());
469         }
470         catch(...) { synfig::warning("Unable to find prev keyframe"); }
471 }
472
473 bool
474 CanvasInterface::import(const synfig::String &filename, bool /*copy*/)
475 {
476         Action::PassiveGrouper group(get_instance().get(),_("Import Image"));
477
478         synfig::info("Attempting to import "+filename);
479
480         if (filename_extension(filename) == "")
481         {
482                 get_ui_interface()->error("Filename must have an extension!");
483                 return false;
484         }
485
486         String ext(filename_extension(filename));
487         if (ext.size()) ext = ext.substr(1); // skip initial '.'
488         std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
489
490         // If this is a SIF file, then we need to do things slightly differently
491         if(ext=="sif" || ext=="sifz")try
492         {
493
494                 Canvas::Handle outside_canvas(synfig::open_canvas(filename));
495                 if(!outside_canvas)
496                         throw String(_("Unable to open this composition"));
497
498                 Layer::Handle layer(add_layer_to("PasteCanvas",get_canvas()));
499                 if(!layer)
500                         throw String(_("Unable to create \"Paste Canvas\" layer"));
501                 if(!layer->set_param("canvas",ValueBase(outside_canvas)))
502                         throw int();
503
504                 //layer->set_description(basename(filename));
505                 signal_layer_new_description()(layer,filename);
506                 return true;
507         }
508         catch(String x)
509         {
510                 get_ui_interface()->error(x+" -- "+filename);
511                 return false;
512         }
513         catch(...)
514         {
515                 get_ui_interface()->error(_("Uncaught exception when attempting\nto open this composition -- ")+filename);
516                 return false;
517         }
518
519         if(!Importer::book().count(ext))
520         {
521                 get_ui_interface()->error(_("I don't know how to open images of this type -- ")+ext);
522                 return false;
523         }
524
525         try
526         {
527                 Layer::Handle layer(add_layer_to("Import",get_canvas()));
528                 int w,h;
529                 if(!layer)
530                         throw int();
531                 if(!layer->set_param("filename",ValueBase(filename)))
532                         throw int();
533                 w=layer->get_param("_width").get(int());
534                 h=layer->get_param("_height").get(int());
535                 if(w&&h)
536                 {
537                         Vector size=ValueBase(get_canvas()->rend_desc().get_br()-get_canvas()->rend_desc().get_tl());
538                         Vector x;
539                         if(size[0]<size[1])
540                         {
541                                 x[0]=size[0];
542                                 x[1]=size[0]/w*h;
543                                 if(size[0]<0 ^ size[1]<0)
544                                         x[1]=-x[1];
545                         }
546                         else
547                         {
548                                 x[1]=size[1];
549                                 x[0]=size[1]/h*w;
550                                 if(size[0]<0 ^ size[1]<0)
551                                         x[0]=-x[0];
552                         }
553                         if(!layer->set_param("tl",ValueBase(-x/2)))
554                                 throw int();
555                         if(!layer->set_param("br",ValueBase(x/2)))
556                                 throw int();
557                 }
558                 else
559                 {
560                         if(!layer->set_param("tl",ValueBase(get_canvas()->rend_desc().get_tl())))
561                                 throw int();
562                         if(!layer->set_param("br",ValueBase(get_canvas()->rend_desc().get_br())))
563                                 throw int();
564                 }
565
566                 layer->set_description(basename(filename));
567                 signal_layer_new_description()(layer,filename);
568
569                 return true;
570         }
571         catch(...)
572         {
573                 get_ui_interface()->error("Unable to import "+filename);
574                 group.cancel();
575                 return false;
576         }
577 }
578
579
580 void
581 CanvasInterface::waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint)
582 {
583         Action::Handle  action(Action::create("waypoint_set_smart"));
584
585         assert(action);
586         if(!action)
587                 return;
588
589         waypoint.make_unique();
590         waypoint.set_time(get_time());
591
592         ValueNode::Handle value_node(value_desc.get_value_node());
593
594         action->set_param("canvas",get_canvas());
595         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
596         action->set_param("waypoint",waypoint);
597         action->set_param("time",get_time());
598         action->set_param("value_node",value_node);
599
600         if(!get_instance()->perform_action(action))
601                 get_ui_interface()->error(_("Action Failed."));
602 }
603
604 void
605 CanvasInterface::waypoint_remove(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint)
606 {
607         Action::Handle  action(Action::create("waypoint_remove"));
608
609         assert(action);
610         if(!action)
611                 return;
612
613         ValueNode::Handle value_node(value_desc.get_value_node());
614
615         action->set_param("canvas",get_canvas());
616         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
617         action->set_param("waypoint",waypoint);
618         action->set_param("value_node",value_node);
619
620         if(!get_instance()->perform_action(action))
621                 get_ui_interface()->error(_("Action Failed."));
622 }
623
624
625 void
626 CanvasInterface::auto_export(ValueNode::Handle /*value_node*/)
627 {
628 /*
629         // Check to see if we are already exported.
630         if(value_node->is_exported())
631                 return;
632
633         Action::Handle  action(Action::create("value_node_add"));
634
635         assert(action);
636         if(!action)
637                 return;
638
639         String name(strprintf(_("Unnamed%08d"),synfig::UniqueID().get_uid()));
640
641         action->set_param("canvas",get_canvas());
642         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
643         action->set_param("new",value_node);
644         action->set_param("name",name);
645
646         if(!get_instance()->perform_action(action))
647                 get_ui_interface()->error(_("Action Failed."));
648 */
649 }
650
651 void
652 CanvasInterface::auto_export(const ValueDesc& /*value_desc*/)
653 {
654         // THIS FUNCTION IS DEPRECATED, AND IS NOW A STUB.
655 #if 0
656         // Check to see if we are already exported.
657         if(value_desc.is_exported())
658                 return;
659
660         Action::Handle  action(Action::create("value_desc_export"));
661
662         assert(action);
663         if(!action)
664                 return;
665
666         String name(strprintf(_("Unnamed%08d"),synfig::UniqueID().get_uid()));
667
668         action->set_param("canvas",get_canvas());
669         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
670         action->set_param("value_desc",value_desc);
671         action->set_param("name",name);
672
673         if(!get_instance()->perform_action(action))
674                 get_ui_interface()->error(_("Action Failed."));
675 #endif
676 }
677
678 bool
679 CanvasInterface::change_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
680 {
681         // If this isn't really a change, then don't bother
682         if(new_value==value_desc.get_value(get_time()))
683                 return true;
684
685         // If this change needs to take place elsewhere, then so be it.
686         if(value_desc.get_canvas() && value_desc.get_canvas()->get_root()!=get_canvas()->get_root())do
687         {
688                 etl::handle<Instance> instance;
689                 instance=find_instance(value_desc.get_canvas()->get_root());
690
691                 if(instance)
692                         return instance->find_canvas_interface(value_desc.get_canvas())->change_value(value_desc,new_value);
693                 else
694                 {
695                         get_ui_interface()->error(_("The value you are trying to edit is in a composition\nwhich doesn't seem to be open. Open that composition and you\nshould be able to edit this value as normal."));
696                         return false;
697                 }
698         }while(0);
699 #ifdef _DEBUG
700         else
701         { synfig::warning("Can't get canvas from value desc...?"); }
702 #endif
703
704         synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_set"));
705         if(!action)
706         {
707                 return false;
708         }
709
710         action->set_param("canvas",get_canvas());
711         action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
712         action->set_param("time",get_time());
713         action->set_param("value_desc",value_desc);
714         action->set_param("new_value",new_value);
715
716         return get_instance()->perform_action(action);
717 }
718
719 void
720 CanvasInterface::set_meta_data(const synfig::String& key,const synfig::String& data)
721 {
722         get_canvas()->set_meta_data(key,data);
723 }
724
725
726 // this function goes with find_important_value_descs()
727 static int
728 _process_value_desc(const synfigapp::ValueDesc& value_desc,std::vector<synfigapp::ValueDesc>& out, synfig::GUIDSet& guid_set)
729 {
730         int ret(0);
731
732         if(value_desc.get_value_type()==ValueBase::TYPE_CANVAS)
733         {
734                 Canvas::Handle canvas;
735                 canvas=value_desc.get_value().get(canvas);
736                 if(!canvas || !canvas->is_inline())
737                         return ret;
738                 ret+=CanvasInterface::find_important_value_descs(canvas,out,guid_set);
739         }
740
741         if(value_desc.is_value_node())
742         {
743                 ValueNode::Handle value_node(value_desc.get_value_node());
744
745                 if(guid_set.count(value_node->get_guid()))
746                         return ret;
747                 guid_set.insert(value_node->get_guid());
748
749                 if(LinkableValueNode::Handle::cast_dynamic(value_node))
750                 {
751                         if(ValueNode_DynamicList::Handle::cast_dynamic(value_node))
752                         {
753                                 out.push_back(value_desc);
754                                 ret++;
755                         }
756                         // Process the linkable ValueNode's children
757                         LinkableValueNode::Handle value_node_copy(LinkableValueNode::Handle::cast_dynamic(value_node));
758                         int i;
759                         for(i=0;i<value_node_copy->link_count();i++)
760                         {
761                                 ValueNode::Handle link(value_node_copy->get_link(i));
762                                 if(!link->is_exported())
763                                         ret+=_process_value_desc(ValueDesc(value_node_copy,i),out,guid_set);
764                         }
765                 }
766                 else if(ValueNode_Animated::Handle::cast_dynamic(value_node))
767                 {
768                         out.push_back(value_desc);
769                         ret++;
770                 }
771         }
772
773         return ret;
774 }
775
776 int
777 CanvasInterface::find_important_value_descs(synfig::Canvas::Handle canvas,std::vector<synfigapp::ValueDesc>& out,synfig::GUIDSet& guid_set)
778 {
779         int ret(0);
780         if(!canvas->is_inline())
781         {
782                 ValueNodeList::const_iterator iter;
783
784                 for(
785                         iter=canvas->value_node_list().begin();
786                         iter!=canvas->value_node_list().end();
787                         ++iter)
788                         ret+=_process_value_desc(ValueDesc(canvas,(*iter)->get_id()),out,guid_set);
789         }
790
791         Canvas::const_iterator iter;
792
793         for(iter=canvas->begin();iter!=canvas->end();++iter)
794         {
795                 Layer::Handle layer(*iter);
796
797                 Layer::DynamicParamList::const_iterator iter;
798                 for(
799                         iter=layer->dynamic_param_list().begin();
800                         iter!=layer->dynamic_param_list().end();
801                         ++iter)
802                 {
803                         if(!iter->second->is_exported())
804                                 ret+=_process_value_desc(ValueDesc(layer,iter->first),out,guid_set);
805                 }
806                 ValueBase value(layer->get_param("canvas"));
807                 if(value.is_valid())
808                         ret+=_process_value_desc(ValueDesc(layer,"canvas"),out,guid_set);
809         }
810
811         return ret;
812 }
813
814 int
815 CanvasInterface::find_important_value_descs(std::vector<synfigapp::ValueDesc>& out)
816 {
817         synfig::GUIDSet tmp;
818         return find_important_value_descs(get_canvas(),out,tmp);
819 }
820
821 void
822 CanvasInterface::seek_frame(int frames)
823 {
824         if(!frames)
825                 return;
826         float fps(get_canvas()->rend_desc().get_frame_rate());
827         Time newtime(get_time()+(float)frames/fps);
828         newtime=newtime.round(fps);
829
830         if(newtime<=get_canvas()->rend_desc().get_time_start())
831                 newtime=get_canvas()->rend_desc().get_time_start();
832         if(newtime>=get_canvas()->rend_desc().get_time_end())
833                 newtime=get_canvas()->rend_desc().get_time_end();
834         set_time(newtime);
835 }
836
837 void
838 CanvasInterface::seek_time(synfig::Time time)
839 {
840         if(!time)
841                 return;
842
843         float fps(get_canvas()->rend_desc().get_frame_rate());
844
845         if(time>=synfig::Time::end())
846         {
847                 set_time(get_canvas()->rend_desc().get_time_end());
848                 return;
849         }
850         if(time<=synfig::Time::begin())
851         {
852                 set_time(get_canvas()->rend_desc().get_time_start());
853                 return;
854         }
855
856         Time newtime(get_time()+time);
857         newtime=newtime.round(fps);
858
859         if(newtime<=get_canvas()->rend_desc().get_time_start())
860                 newtime=get_canvas()->rend_desc().get_time_start();
861         if(newtime>=get_canvas()->rend_desc().get_time_end())
862                 newtime=get_canvas()->rend_desc().get_time_end();
863         set_time(newtime);
864 }