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, 2008 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>
41 #include <synfig/valuenode_greyed.h>
42 #include <synfig/valuenode_blinecalctangent.h>
43 #include <synfig/valuenode_blinecalcvertex.h>
44 #include <synfig/valuenode_blinecalcwidth.h>
45 #include <synfig/valuenode_scale.h>
52 /* === U S I N G =========================================================== */
56 using namespace synfig;
57 using namespace synfigapp;
59 /* === M A C R O S ========================================================= */
61 /* === G L O B A L S ======================================================= */
63 static std::map<loose_handle<Canvas>, loose_handle<Instance> > instance_map_;
65 /* === P R O C E D U R E S ================================================= */
68 synfigapp::is_editable(synfig::ValueNode::Handle value_node)
70 if(ValueNode_Const::Handle::cast_dynamic(value_node)
71 || ValueNode_Animated::Handle::cast_dynamic(value_node)
72 || ValueNode_Composite::Handle::cast_dynamic(value_node)
73 || ValueNode_RadialComposite::Handle::cast_dynamic(value_node)
74 ||(ValueNode_Reference::Handle::cast_dynamic(value_node) && !ValueNode_Greyed::Handle::cast_dynamic(value_node))
75 || ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_node)
76 || ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_node)
77 || ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_node)
78 || ValueNode_Scale::Handle::cast_dynamic(value_node)
85 synfigapp::find_instance(etl::handle<synfig::Canvas> canvas)
87 if(instance_map_.count(canvas)==0)
89 return instance_map_[canvas];
92 /* === M E T H O D S ======================================================= */
94 Instance::Instance(etl::handle<synfig::Canvas> canvas):
95 CVSInfo(canvas->get_file_name()),
98 assert(canvas->is_root());
100 unset_selection_manager();
102 instance_map_[canvas]=this;
103 } // END of synfigapp::Instance::Instance()
106 Instance::create(etl::handle<synfig::Canvas> canvas)
108 // Construct a new instance
109 handle<Instance> instance(new Instance(canvas));
112 } // END of synfigapp::Instance::create()
115 Instance::get_file_name()const
117 return get_canvas()->get_file_name();
121 Instance::set_file_name(const synfig::String &name)
123 get_canvas()->set_file_name(name);
124 CVSInfo::set_file_name(name);
127 Instance::~Instance()
129 instance_map_.erase(canvas_);
131 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
132 synfig::info("Instance::~Instance(): Deleted");
135 handle<CanvasInterface>
136 Instance::find_canvas_interface(synfig::Canvas::Handle canvas)
140 while(canvas->is_inline())
141 canvas=canvas->parent();
143 CanvasInterfaceList::iterator iter;
145 for(iter=canvas_interface_list().begin();iter!=canvas_interface_list().end();iter++)
146 if((*iter)->get_canvas()==canvas)
149 return CanvasInterface::create(this,canvas);
153 Instance::save()const
155 bool ret=save_canvas(get_file_name(),canvas_);
158 reset_action_count();
159 const_cast<sigc::signal<void>& >(signal_saved_)();
165 Instance::save_as(const synfig::String &file_name)
169 String old_file_name(get_file_name());
171 set_file_name(file_name);
173 ret=save_canvas(file_name,canvas_);
177 reset_action_count();
181 set_file_name(old_file_name);
183 signal_filename_changed_();