1 /* === S Y N F I G ========================================================= */
2 /*! \file synfigapp/instance.cpp
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 ======================================================= */
34 #include "canvasinterface.h"
36 #include <synfig/loadcanvas.h>
37 #include <synfig/savecanvas.h>
38 #include <synfig/valuenode_composite.h>
39 #include <synfig/valuenode_radialcomposite.h>
40 #include <synfig/valuenode_reference.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
52 using namespace synfigapp;
54 /* === M A C R O S ========================================================= */
56 /* === G L O B A L S ======================================================= */
58 static std::map<loose_handle<Canvas>, loose_handle<Instance> > instance_map_;
60 /* === P R O C E D U R E S ================================================= */
63 synfigapp::is_editable(synfig::ValueNode::Handle value_node)
65 if(ValueNode_Const::Handle::cast_dynamic(value_node)
66 || ValueNode_Animated::Handle::cast_dynamic(value_node)
67 || ValueNode_Composite::Handle::cast_dynamic(value_node)
68 || ValueNode_RadialComposite::Handle::cast_dynamic(value_node)
69 || ValueNode_Reference::Handle::cast_dynamic(value_node)
76 synfigapp::find_instance(etl::handle<synfig::Canvas> canvas)
78 if(instance_map_.count(canvas)==0)
80 return instance_map_[canvas];
83 /* === M E T H O D S ======================================================= */
85 Instance::Instance(etl::handle<synfig::Canvas> canvas):
86 CVSInfo(canvas->get_file_name()),
89 assert(canvas->is_root());
91 unset_selection_manager();
93 instance_map_[canvas]=this;
94 } // END of synfigapp::Instance::Instance()
97 Instance::create(etl::handle<synfig::Canvas> canvas)
99 // Construct a new instance
100 handle<Instance> instance(new Instance(canvas));
103 } // END of synfigapp::Instance::create()
106 Instance::get_file_name()const
108 return get_canvas()->get_file_name();
112 Instance::set_file_name(const synfig::String &name)
114 get_canvas()->set_file_name(name);
115 CVSInfo::set_file_name(name);
118 Instance::~Instance()
120 instance_map_.erase(canvas_);
122 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
123 synfig::info("Instance::~Instance(): Deleted");
126 handle<CanvasInterface>
127 Instance::find_canvas_interface(synfig::Canvas::Handle canvas)
131 while(canvas->is_inline())
132 canvas=canvas->parent();
134 CanvasInterfaceList::iterator iter;
136 for(iter=canvas_interface_list().begin();iter!=canvas_interface_list().end();iter++)
137 if((*iter)->get_canvas()==canvas)
140 return CanvasInterface::create(this,canvas);
144 Instance::save()const
146 bool ret=save_canvas(get_file_name(),canvas_);
149 reset_action_count();
150 const_cast<sigc::signal<void>& >(signal_saved_)();
156 Instance::save_as(const synfig::String &file_name)
160 String old_file_name(get_file_name());
162 set_file_name(file_name);
164 ret=save_canvas(file_name,canvas_);
168 reset_action_count();
172 set_file_name(old_file_name);
174 signal_filename_changed_();