1 /* === S Y N F I G ========================================================= */
3 ** \brief Canvas Class Member Definitions
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
26 #define SYNFIG_NO_ANGLE
38 #include "exception.h"
41 #include "layer_pastecanvas.h"
42 #include <sigc++/bind.h>
46 using namespace synfig;
50 namespace synfig { extern Canvas::Handle open_canvas(const String &filename); };
52 /* === M A C R O S ========================================================= */
60 synfig::error("%d canvases not yet deleted!",counter);
64 int _CanvasCounter::counter(0);
66 /* === G L O B A L S ======================================================= */
68 /* === P R O C E D U R E S ================================================= */
70 /* === M E T H O D S ======================================================= */
72 Canvas::Canvas(const String &id):
79 _CanvasCounter::counter++;
92 //if(is_inline() && parent_) assert(0);
93 _CanvasCounter::counter--;
102 return CanvasBase::end()-1;
105 Canvas::const_iterator
108 return CanvasBase::end()-1;
111 Canvas::reverse_iterator
114 return CanvasBase::rbegin()+1;
117 Canvas::const_reverse_iterator
118 Canvas::rbegin()const
120 return CanvasBase::rbegin()+1;
126 return CanvasBase::size()-1;
134 Layer::Handle layer(front());
135 //if(layer->count()>2)synfig::info("before layer->count()=%d",layer->count());
138 //if(layer->count()>1)synfig::info("after layer->count()=%d",layer->count());
140 //CanvasBase::clear();
142 // We need to keep a blank handle at the
143 // end of the image list, and acts at
144 // the bottom. Without it, the layers
145 // would just continue going when polled
147 CanvasBase::push_back(Layer::Handle());
155 return CanvasBase::size()<=1;
161 return *(CanvasBase::end()-1);
164 const Layer::Handle &
167 return *(CanvasBase::end()-1);
171 Canvas::get_context()const
176 const ValueNodeList &
177 Canvas::value_node_list()const
179 if(is_inline() && parent_)
180 return parent_->value_node_list();
181 return value_node_list_;
185 Canvas::keyframe_list()
187 if(is_inline() && parent_)
188 return parent_->keyframe_list();
189 return keyframe_list_;
193 Canvas::keyframe_list()const
195 if(is_inline() && parent_)
196 return parent_->keyframe_list();
197 return keyframe_list_;
201 Canvas::find_layer(const Point &pos)
203 return get_context().hit_check(pos);
207 valid_id(const String &x)
209 static const char bad_chars[]=" :#@$^&()*";
212 if(!x.empty() && x[0]>='0' && x[0]<='9')
215 for(i=0;i<sizeof(bad_chars);i++)
216 if(x.find_first_of(bad_chars[i])!=string::npos)
223 Canvas::set_id(const String &x)
225 if(is_inline() && parent_)
226 throw runtime_error("Inline Canvas cannot have an ID");
229 throw runtime_error("Invalid ID");
231 signal_id_changed_();
235 Canvas::set_name(const String &x)
238 signal_meta_data_changed()("name");
239 signal_meta_data_changed("name")();
243 Canvas::set_author(const String &x)
246 signal_meta_data_changed()("author");
247 signal_meta_data_changed("author")();
251 Canvas::set_description(const String &x)
254 signal_meta_data_changed()("description");
255 signal_meta_data_changed("description")();
259 Canvas::set_time(Time t)const
261 if(is_dirty_ || !get_time().is_equal(t))
266 synfig::info("is_dirty_=%d",is_dirty_);
267 synfig::info("get_time()=%f",(float)get_time());
268 synfig::info("t=%f",(float)t);
273 const_cast<Canvas&>(*this).cur_time_=t;
276 get_context().set_time(t);
282 Canvas::get_root()const
284 return parent_?parent_->get_root().get():const_cast<synfig::Canvas *>(this);
288 Canvas::get_depth(etl::handle<Layer> layer)const
292 for(iter=begin();iter!=end();++iter,i++)
301 Canvas::get_relative_id(etl::loose_handle<const Canvas> x)const
303 if(x->get_root()==this)
305 if(is_inline() && parent_)
306 return parent_->_get_relative_id(x);
307 return _get_relative_id(x);
311 Canvas::_get_relative_id(etl::loose_handle<const Canvas> x)const
313 if(is_inline() && parent_)
314 return parent_->_get_relative_id(x);
319 if(parent()==x.get())
324 const Canvas* canvas=this;
326 for(;!canvas->is_root();canvas=canvas->parent().get())
327 id=':'+canvas->get_id()+id;
329 if(x && get_root()!=x->get_root())
331 //String file_name=get_file_name();
332 //String file_path=x->get_file_path();
335 if(is_absolute_path(get_file_name()))
336 file_name=etl::relative_path(x->get_file_path(),get_file_name());
338 file_name=get_file_name();
340 // If the path of X is inside of file_name,
342 //if(file_name.size()>file_path.size())
343 // if(file_path==String(file_name,0,file_path.size()))
344 // file_name.erase(0,file_path.size()+1);
354 Canvas::find_value_node(const String &id)
357 ValueNode::Handle::cast_const(
358 const_cast<const Canvas*>(this)->find_value_node(id)
362 ValueNode::ConstHandle
363 Canvas::find_value_node(const String &id)const
365 if(is_inline() && parent_)
366 return parent_->find_value_node(id);
369 throw Exception::IDNotFound("Empty ID");
371 // If we do not have any resolution, then we assume that the
372 // request is for this immediate canvas
373 if(id.find_first_of(':')==string::npos && id.find_first_of('#')==string::npos)
374 return value_node_list_.find(id);
376 String canvas_id(id,0,id.rfind(':'));
377 String value_node_id(id,id.rfind(':')+1);
378 if(canvas_id.empty())
380 //synfig::warning("constfind:value_node_id: "+value_node_id);
381 //synfig::warning("constfind:canvas_id: "+canvas_id);
383 return find_canvas(canvas_id)->value_node_list_.find(value_node_id);
387 Canvas::surefind_value_node(const String &id)
389 if(is_inline() && parent_)
390 return parent_->surefind_value_node(id);
393 throw Exception::IDNotFound("Empty ID");
395 // If we do not have any resolution, then we assume that the
396 // request is for this immediate canvas
397 if(id.find_first_of(':')==string::npos && id.find_first_of('#')==string::npos)
398 return value_node_list_.surefind(id);
400 String canvas_id(id,0,id.rfind(':'));
401 String value_node_id(id,id.rfind(':')+1);
402 if(canvas_id.empty())
405 return surefind_canvas(canvas_id)->value_node_list_.surefind(value_node_id);
409 Canvas::add_value_node(ValueNode::Handle x, const String &id)
411 if(is_inline() && parent_)
412 return parent_->add_value_node(x,id);
413 // throw runtime_error("You cannot add a ValueNode to an inline Canvas");
417 throw runtime_error("ValueNode is already exported");
420 throw Exception::BadLinkName("Empty ID");
422 if(id.find_first_of(':',0)!=string::npos)
423 throw Exception::BadLinkName("Bad character");
428 if(PlaceholderValueNode::Handle::cast_dynamic(value_node_list_.find(id)))
429 throw Exception::IDNotFound("add_value_node()");
432 throw Exception::IDAlreadyExists(id);
434 catch(Exception::IDNotFound)
439 x->set_parent_canvas(this);
441 if(!value_node_list_.add(x))
443 synfig::error("Unable to add ValueNode");
444 throw std::runtime_error("Unable to add ValueNode");
454 Canvas::rename_value_node(ValueNode::Handle x, const String &id)
457 throw Exception::BadLinkName("Empty ID");
459 if(id.find_first_of(": ",0)!=string::npos)
460 throw Exception::BadLinkName("Bad character");
464 if(PlaceholderValueNode::Handle::cast_dynamic(value_node_list_.find(id)))
465 throw Exception::IDNotFound("rename_value_node");
466 throw Exception::IDAlreadyExists(id);
468 catch(Exception::IDNotFound)
478 Canvas::remove_value_node(ValueNode::Handle x)
480 if(is_inline() && parent_)
481 return parent_->remove_value_node(x);
482 // throw Exception::IDNotFound("Canvas::remove_value_node() was called from an inline canvas");
485 throw Exception::IDNotFound("Canvas::remove_value_node() was passed empty handle");
487 if(!value_node_list_.erase(x))
488 throw Exception::IDNotFound("Canvas::remove_value_node(): ValueNode was not found inside of this canvas");
490 //x->set_parent_canvas(0);
497 Canvas::surefind_canvas(const String &id)
499 if(is_inline() && parent_)
500 return parent_->surefind_canvas(id);
505 // If the ID contains a "#" character, then a filename is
506 // expected on the left side.
507 if(id.find_first_of('#')!=string::npos)
509 // If '#' is the first character, remove it
510 // and attempt to parse the ID again.
512 return surefind_canvas(String(id,1));
514 //! \todo This needs a lot more optimization
515 String file_name(id,0,id.find_first_of('#'));
516 String external_id(id,id.find_first_of('#')+1);
518 file_name=unix_to_local_path(file_name);
520 Canvas::Handle external_canvas;
522 // If the composition is already open, then use it.
523 if(externals_.count(file_name))
524 external_canvas=externals_[file_name];
527 if(is_absolute_path(file_name))
528 external_canvas=open_canvas(file_name);
530 external_canvas=open_canvas(get_file_path()+ETL_DIRECTORY_SEPARATOR+file_name);
533 throw Exception::FileNotFound(file_name);
534 externals_[file_name]=external_canvas;
537 return Handle::cast_const(external_canvas.constant()->find_canvas(external_id));
540 // If we do not have any resolution, then we assume that the
541 // request is for this immediate canvas
542 if(id.find_first_of(':')==string::npos)
544 Children::iterator iter;
546 // Search for the image in the image list,
547 // and return it if it is found
548 for(iter=children().begin();iter!=children().end();iter++)
549 if(id==(*iter)->get_id())
552 // Create a new canvas and return it
553 //synfig::warning("Implicitly creating canvas named "+id);
554 return new_child_canvas(id);
557 // If the first character is the separator, then
558 // this references the root canvas.
560 return get_root()->surefind_canvas(string(id,1));
562 // Now we know that the requested Canvas is in a child
563 // of this canvas. We have to find that canvas and
564 // call "find_canvas" on it, and return the result.
566 String canvas_name=string(id,0,id.find_first_of(':'));
568 Canvas::Handle child_canvas=surefind_canvas(canvas_name);
570 return child_canvas->surefind_canvas(string(id,id.find_first_of(':')+1));
574 Canvas::find_canvas(const String &id)
577 Canvas::Handle::cast_const(
578 const_cast<const Canvas*>(this)->find_canvas(id)
583 Canvas::find_canvas(const String &id)const
585 if(is_inline() && parent_)return parent_->find_canvas(id);
590 // If the ID contains a "#" character, then a filename is
591 // expected on the left side.
592 if(id.find_first_of('#')!=string::npos)
594 // If '#' is the first character, remove it
595 // and attempt to parse the ID again.
597 return find_canvas(String(id,1));
599 //! \todo This needs a lot more optimization
600 String file_name(id,0,id.find_first_of('#'));
601 String external_id(id,id.find_first_of('#')+1);
603 file_name=unix_to_local_path(file_name);
605 Canvas::Handle external_canvas;
607 // If the composition is already open, then use it.
608 if(externals_.count(file_name))
609 external_canvas=externals_[file_name];
612 if(is_absolute_path(file_name))
613 external_canvas=open_canvas(file_name);
615 external_canvas=open_canvas(get_file_path()+ETL_DIRECTORY_SEPARATOR+file_name);
618 throw Exception::FileNotFound(file_name);
619 externals_[file_name]=external_canvas;
622 return Handle::cast_const(external_canvas.constant()->find_canvas(external_id));
625 // If we do not have any resolution, then we assume that the
626 // request is for this immediate canvas
627 if(id.find_first_of(':')==string::npos)
629 Children::const_iterator iter;
631 // Search for the image in the image list,
632 // and return it if it is found
633 for(iter=children().begin();iter!=children().end();iter++)
634 if(id==(*iter)->get_id())
637 throw Exception::IDNotFound("Child Canvas in Parent Canvas: (child)"+id);
640 // If the first character is the separator, then
641 // this references the root canvas.
642 if(id.find_first_of(':')==0)
643 return get_root()->find_canvas(string(id,1));
645 // Now we know that the requested Canvas is in a child
646 // of this canvas. We have to find that canvas and
647 // call "find_canvas" on it, and return the result.
649 String canvas_name=string(id,0,id.find_first_of(':'));
651 Canvas::ConstHandle child_canvas=find_canvas(canvas_name);
653 return child_canvas->find_canvas(string(id,id.find_first_of(':')+1));
660 return new Canvas("Untitled");
664 Canvas::push_back(etl::handle<Layer> x)
667 // int i(x->count());
669 //if(x->count()!=i+1)synfig::info("push_back before %d, after %d",i,x->count());
673 Canvas::push_front(etl::handle<Layer> x)
676 // int i(x->count());
678 //if(x->count()!=i+1)synfig::error("push_front before %d, after %d",i,x->count());
682 Canvas::insert(iterator iter,etl::handle<Layer> x)
684 // int i(x->count());
685 CanvasBase::insert(iter,x);
687 /*if(x->count()!=i+1)
689 synfig::error(__FILE__":%d: Canvas::insert(): ***FAILURE*** before %d, after %d",__LINE__,i,x->count());
691 //throw runtime_error("Canvas Insertion Failed");
700 LooseHandle correct_canvas(this);
701 //while(correct_canvas->is_inline())correct_canvas=correct_canvas->parent();
702 Layer::LooseHandle loose_layer(x);
704 add_connection(loose_layer,
705 sigc::connection::connection(
706 x->signal_added_to_group().connect(
710 &Canvas::add_group_pair),
712 add_connection(loose_layer,
713 sigc::connection::connection(
714 x->signal_removed_from_group().connect(
718 &Canvas::remove_group_pair),
722 if(!x->get_group().empty())
723 add_group_pair(x->get_group(),x);
730 Canvas::push_back_simple(etl::handle<Layer> x)
732 CanvasBase::insert(end(),x);
737 Canvas::erase(iterator iter)
739 if(!(*iter)->get_group().empty())
740 remove_group_pair((*iter)->get_group(),(*iter));
742 // HACK: We really shouldn't be wiping
743 // out these signals entirely. We should
744 // only be removing the specific connections
745 // that we made. At the moment, I'm too
746 // lazy to add the code to keep track
747 // of those connections, and no one else
748 // is using these signals, so I'll just
749 // leave these next two lines like they
750 // are for now - darco 07-30-2004
752 // so don't wipe them out entirely
753 // - dooglus 09-21-2007
754 disconnect_connections(*iter);
756 if(!op_flag_)remove_child(iter->get());
758 CanvasBase::erase(iter);
759 if(!op_flag_)changed();
763 Canvas::clone(const GUID& deriv_guid)const
770 name=get_id()+"_CLONE";
772 throw runtime_error("Cloning of non-inline canvases is not yet supported");
775 Handle canvas(new Canvas(name));
779 canvas->is_inline_=true;
780 // \todo this was setting parent_=0 - is there a reason for that?
781 // this was causing bug 1838132, where cloning an inline canvas that contains an imported image fails
782 // it was failing to ascertain the absolute pathname of the imported image, since it needs the pathname
783 // of the canvas to get that, which is stored in the parent canvas
784 canvas->parent_=parent();
785 //canvas->set_inline(parent());
788 canvas->set_guid(get_guid()^deriv_guid);
791 for(iter=begin();iter!=end();++iter)
793 Layer::Handle layer((*iter)->clone(deriv_guid));
796 assert(layer.count()==1);
798 canvas->push_back(layer);
799 if(!(layer.count()>1))
801 synfig::error("Canvas::clone(): Cloned layer insertion failure!");
802 synfig::error("Canvas::clone(): \tlayer.count()=%d",layer.count());
803 synfig::error("Canvas::clone(): \tlayer->get_name()=%s",layer->get_name().c_str());
804 synfig::error("Canvas::clone(): \tbefore size()=%d",presize);
805 synfig::error("Canvas::clone(): \tafter size()=%d",size());
807 assert(layer.count()>1);
811 synfig::error("Unable to clone layer");
815 canvas->signal_group_pair_removed().clear();
816 canvas->signal_group_pair_added().clear();
822 Canvas::set_inline(LooseHandle parent)
824 if(is_inline_ && parent_)
833 // Have the parent inherit all of the group stuff
835 std::map<String,std::set<etl::handle<Layer> > >::const_iterator iter;
837 for(iter=group_db_.begin();iter!=group_db_.end();++iter)
839 parent->group_db_[iter->first].insert(iter->second.begin(),iter->second.end());
842 rend_desc()=parent->rend_desc();
846 Canvas::create_inline(Handle parent)
849 //if(parent->is_inline())
850 // return create_inline(parent->parent());
852 Handle canvas(new Canvas("inline"));
853 canvas->set_inline(parent);
858 Canvas::new_child_canvas()
860 if(is_inline() && parent_)
861 return parent_->new_child_canvas();
862 // runtime_error("You cannot create a child Canvas in an inline Canvas");
864 // Create a new canvas
865 children().push_back(create());
866 Canvas::Handle canvas(children().back());
868 canvas->parent_=this;
870 canvas->rend_desc()=rend_desc();
876 Canvas::new_child_canvas(const String &id)
878 if(is_inline() && parent_)
879 return parent_->new_child_canvas(id);
880 // runtime_error("You cannot create a child Canvas in an inline Canvas");
882 // Create a new canvas
883 children().push_back(create());
884 Canvas::Handle canvas(children().back());
887 canvas->parent_=this;
888 canvas->rend_desc()=rend_desc();
894 Canvas::add_child_canvas(Canvas::Handle child_canvas, const synfig::String& id)
896 if(is_inline() && parent_)
897 return parent_->add_child_canvas(child_canvas,id);
899 if(child_canvas->parent() && !child_canvas->is_inline())
900 throw std::runtime_error("Cannot add child canvas because it belongs to someone else!");
903 throw runtime_error("Invalid ID");
908 throw Exception::IDAlreadyExists(id);
910 catch(Exception::IDNotFound)
912 if(child_canvas->is_inline())
913 child_canvas->is_inline_=false;
914 child_canvas->id_=id;
915 children().push_back(child_canvas);
916 child_canvas->parent_=this;
923 Canvas::remove_child_canvas(Canvas::Handle child_canvas)
925 if(is_inline() && parent_)
926 return parent_->remove_child_canvas(child_canvas);
928 if(child_canvas->parent_!=this)
929 throw runtime_error("Given child does not belong to me");
931 if(find(children().begin(),children().end(),child_canvas)==children().end())
932 throw Exception::IDNotFound(child_canvas->get_id());
934 children().remove(child_canvas);
936 child_canvas->parent_=0;
940 Canvas::set_file_name(const String &file_name)
943 parent()->set_file_name(file_name);
946 file_name_=file_name;
947 signal_file_name_changed_();
952 Canvas::signal_file_name_changed()
955 return signal_file_name_changed();
957 return signal_file_name_changed_;
961 Canvas::get_file_name()const
964 return parent()->get_file_name();
969 Canvas::get_file_path()const
972 return parent()->get_file_path();
973 return dirname(file_name_);
978 Canvas::get_meta_data(const String& key)const
980 if(!meta_data_.count(key))
982 return meta_data_.find(key)->second;
986 Canvas::set_meta_data(const String& key, const String& data)
988 if(meta_data_[key]!=data)
990 meta_data_[key]=data;
991 signal_meta_data_changed()(key);
992 signal_meta_data_changed(key)();
997 Canvas::erase_meta_data(const String& key)
999 if(meta_data_.count(key))
1001 meta_data_.erase(key);
1002 signal_meta_data_changed()(key);
1003 signal_meta_data_changed(key)();
1008 Canvas::get_meta_data_keys()const
1010 std::list<String> ret;
1012 std::map<String,String>::const_iterator iter;
1014 for(iter=meta_data_.begin();!(iter==meta_data_.end());++iter)
1015 ret.push_back(iter->first);
1021 synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_motion_blur_in_parent)
1025 std::vector< std::pair<float,Layer::Handle> > sort_list;
1026 int i, motion_blur_i=0; // motion_blur_i is for resolving which layer comes first in the event of a z_depth tie
1027 float motion_blur_z_depth=0; // the z_depth of the least deep motion blur layer in this context
1028 bool seen_motion_blur_locally = false;
1029 bool motion_blurred; // the final result - is this layer blurred or not?
1031 // If the parent didn't cause us to already be motion blurred,
1032 // check whether there's a motion blur in this context,
1033 // and if so, calculate its z_depth.
1034 if (!seen_motion_blur_in_parent)
1035 for(iter=context,i=0;*iter;iter++,i++)
1037 Layer::Handle layer=*iter;
1039 // If the layer isn't active, don't worry about it
1040 if(!layer->active())
1043 // Any layer with an amount of zero is implicitly disabled.
1044 ValueBase value(layer->get_param("amount"));
1045 if(value.get_type()==ValueBase::TYPE_REAL && value.get(Real())==0)
1048 if(layer->get_name()=="MotionBlur")
1050 float z_depth(layer->get_z_depth()*1.0001+i);
1052 // If we've seen a motion blur before in this context...
1053 if (seen_motion_blur_locally)
1055 // ... then we're only interested in this one if it's less deep...
1056 if (z_depth < motion_blur_z_depth)
1058 motion_blur_z_depth = z_depth;
1062 // ... otherwise we're always interested in it.
1065 motion_blur_z_depth = z_depth;
1067 seen_motion_blur_locally = true;
1072 // Go ahead and start romping through the canvas to paste
1073 for(iter=context,i=0;*iter;iter++,i++)
1075 Layer::Handle layer=*iter;
1076 float z_depth(layer->get_z_depth()*1.0001+i);
1078 // If the layer isn't active, don't worry about it
1079 if(!layer->active())
1082 // Any layer with an amount of zero is implicitly disabled.
1083 ValueBase value(layer->get_param("amount"));
1084 if(value.get_type()==ValueBase::TYPE_REAL && value.get(Real())==0)
1087 Layer_PasteCanvas* paste_canvas(static_cast<Layer_PasteCanvas*>(layer.get()));
1089 // note: this used to include "&& paste_canvas->get_time_offset()==0", but then
1090 // time-shifted layers weren't being sorted by z-depth (bug #1806852)
1091 if(layer->get_name()=="PasteCanvas")
1093 // we need to blur the sub canvas if:
1094 // our parent is blurred,
1095 // or the child is lower than a local blur,
1096 // or the child is at the same z_depth as a local blur, but later in the context
1099 if (seen_motion_blur_in_parent) synfig::info("seen BLUR in parent\n");
1100 else if (seen_motion_blur_locally)
1101 if (z_depth > motion_blur_z_depth) synfig::info("paste is deeper than BLUR\n");
1102 else if (z_depth == motion_blur_z_depth) { synfig::info("paste is same depth as BLUR\n");
1103 if (i > motion_blur_i) synfig::info("paste is physically deeper than BLUR\n");
1104 else synfig::info("paste is less physically deep than BLUR\n");
1105 } else synfig::info("paste is less deep than BLUR\n");
1106 else synfig::info("no BLUR at all\n");
1109 motion_blurred = (seen_motion_blur_in_parent ||
1110 (seen_motion_blur_locally &&
1111 (z_depth > motion_blur_z_depth ||
1112 (z_depth == motion_blur_z_depth && i > motion_blur_i))));
1114 Canvas::Handle sub_canvas(Canvas::create_inline(op_canvas));
1115 Canvas::Handle paste_sub_canvas = paste_canvas->get_sub_canvas();
1116 if(paste_sub_canvas)
1117 optimize_layers(paste_sub_canvas->get_context(),sub_canvas,motion_blurred);
1118 //#define SYNFIG_OPTIMIZE_PASTE_CANVAS 1
1120 #ifdef SYNFIG_OPTIMIZE_PASTE_CANVAS
1121 Canvas::iterator sub_iter;
1122 // Determine if we can just remove the paste canvas
1124 if(paste_canvas->get_blend_method()==Color::BLEND_COMPOSITE && paste_canvas->get_amount()==1.0f && paste_canvas->get_zoom()==0 && paste_canvas->get_time_offset()==0 && paste_canvas->get_origin()==Point(0,0))
1126 for(sub_iter=sub_canvas->begin();sub_iter!=sub_canvas->end();++sub_iter)
1128 Layer* layer=sub_iter->get();
1130 // any layers that deform end up breaking things
1131 // so do things the old way if we run into anything like this
1132 if(!dynamic_cast<Layer_NoDeform*>(layer))
1135 ValueBase value(layer->get_param("blend_method"));
1136 if(value.get_type()!=ValueBase::TYPE_INTEGER || value.get(int())!=(int)Color::BLEND_COMPOSITE)
1140 // It has turned out that we don't need a paste canvas
1141 // layer, so just go ahead and add all the layers onto
1142 // the current stack and be done with it
1143 while(sub_canvas->size())
1145 sort_list.push_back(std::pair<float,Layer::Handle>(z_depth,sub_canvas->front()));
1146 //op_canvas->push_back_simple(sub_canvas->front());
1147 sub_canvas->pop_front();
1152 Layer::Handle new_layer(Layer::create("PasteCanvas"));
1153 dynamic_cast<Layer_PasteCanvas*>(new_layer.get())->set_muck_with_time(false);
1156 Layer::DynamicParamList dynamic_param_list(paste_canvas->dynamic_param_list());
1157 for(Layer::DynamicParamList::const_iterator iter(dynamic_param_list.begin()); iter != dynamic_param_list.end(); ++iter)
1158 new_layer->connect_dynamic_param(iter->first, iter->second);
1160 Layer::ParamList param_list(paste_canvas->get_param_list());
1161 //param_list.erase("canvas");
1162 new_layer->set_param_list(param_list);
1163 dynamic_cast<Layer_PasteCanvas*>(new_layer.get())->set_sub_canvas(sub_canvas);
1164 dynamic_cast<Layer_PasteCanvas*>(new_layer.get())->set_muck_with_time(true);
1168 sort_list.push_back(std::pair<float,Layer::Handle>(z_depth,layer));
1169 //op_canvas->push_back_simple(layer);
1173 stable_sort(sort_list.begin(),sort_list.end());
1174 std::vector< std::pair<float,Layer::Handle> >::iterator iter2;
1175 for(iter2=sort_list.begin();iter2!=sort_list.end();++iter2)
1176 op_canvas->push_back_simple(iter2->second);
1177 op_canvas->op_flag_=true;
1181 Canvas::get_times_vfunc(Node::time_set &set) const
1183 const_iterator i = begin(),
1186 for(; i != iend; ++i)
1188 const Node::time_set &tset = (*i)->get_times();
1189 set.insert(tset.begin(),tset.end());
1193 std::set<etl::handle<Layer> >
1194 Canvas::get_layers_in_group(const String&group)
1196 if(is_inline() && parent_)
1197 return parent_->get_layers_in_group(group);
1199 if(group_db_.count(group)==0)
1200 return std::set<etl::handle<Layer> >();
1201 return group_db_.find(group)->second;
1205 Canvas::get_groups()const
1207 if(is_inline() && parent_)
1208 return parent_->get_groups();
1210 std::set<String> ret;
1211 std::map<String,std::set<etl::handle<Layer> > >::const_iterator iter;
1212 for(iter=group_db_.begin();iter!=group_db_.end();++iter)
1213 ret.insert(iter->first);
1218 Canvas::get_group_count()const
1220 if(is_inline() && parent_)
1221 return parent_->get_group_count();
1223 return group_db_.size();
1227 Canvas::add_group_pair(String group, etl::handle<Layer> layer)
1229 group_db_[group].insert(layer);
1230 if(group_db_[group].size()==1)
1231 signal_group_added()(group);
1233 signal_group_changed()(group);
1235 signal_group_pair_added()(group,layer);
1237 if(is_inline() && parent_)
1238 return parent_->add_group_pair(group,layer);
1242 Canvas::remove_group_pair(String group, etl::handle<Layer> layer)
1244 group_db_[group].erase(layer);
1246 signal_group_pair_removed()(group,layer);
1248 if(group_db_[group].empty())
1250 group_db_.erase(group);
1251 signal_group_removed()(group);
1254 signal_group_changed()(group);
1256 if(is_inline() && parent_)
1257 return parent_->remove_group_pair(group,layer);
1261 Canvas::add_connection(etl::loose_handle<Layer> layer, sigc::connection connection)
1263 connections_[layer].push_back(connection);
1267 Canvas::disconnect_connections(etl::loose_handle<Layer> layer)
1269 std::vector<sigc::connection>::iterator iter;
1270 for(iter=connections_[layer].begin();iter!=connections_[layer].end();++iter)
1272 connections_[layer].clear();
1276 Canvas::rename_group(const String&old_name,const String&new_name)
1278 if(is_inline() && parent_)
1279 return parent_->rename_group(old_name,new_name);
1282 std::map<String,std::set<etl::handle<Layer> > >::iterator iter;
1283 iter=group_db_.find(old_name);
1284 if(iter!=group_db_.end())
1285 for(++iter;iter!=group_db_.end() && iter->first.find(old_name)==0;iter=group_db_.find(old_name),++iter)
1287 String name(iter->first,old_name.size(),String::npos);
1289 rename_group(iter->first,name);
1293 std::set<etl::handle<Layer> > layers(get_layers_in_group(old_name));
1294 std::set<etl::handle<Layer> >::iterator iter;
1296 for(iter=layers.begin();iter!=layers.end();++iter)
1298 (*iter)->remove_from_group(old_name);
1299 (*iter)->add_to_group(new_name);