1 /* === S I N F G =========================================================== */
5 ** $Id: instance.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include "canvasinterface.h"
34 #include <sinfg/loadcanvas.h>
35 #include <sinfg/savecanvas.h>
36 #include <sinfg/valuenode_composite.h>
37 #include <sinfg/valuenode_radialcomposite.h>
38 #include <sinfg/valuenode_reference.h>
43 /* === U S I N G =========================================================== */
47 using namespace sinfg;
48 using namespace sinfgapp;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 static std::map<loose_handle<Canvas>, loose_handle<Instance> > instance_map_;
56 /* === P R O C E D U R E S ================================================= */
59 sinfgapp::is_editable(sinfg::ValueNode::Handle value_node)
61 if(ValueNode_Const::Handle::cast_dynamic(value_node)
62 || ValueNode_TimedSwap::Handle::cast_dynamic(value_node)
63 || ValueNode_Animated::Handle::cast_dynamic(value_node)
64 || ValueNode_Composite::Handle::cast_dynamic(value_node)
65 || ValueNode_RadialComposite::Handle::cast_dynamic(value_node)
66 || ValueNode_Reference::Handle::cast_dynamic(value_node)
73 sinfgapp::find_instance(etl::handle<sinfg::Canvas> canvas)
75 if(instance_map_.count(canvas)==0)
77 return instance_map_[canvas];
80 /* === M E T H O D S ======================================================= */
82 Instance::Instance(Canvas::Handle canvas):
83 CVSInfo(canvas->get_file_name()),
86 assert(canvas->is_root());
88 unset_selection_manager();
90 instance_map_[canvas]=this;
91 } // END of sinfgapp::Instance::Instance()
94 Instance::create(Canvas::Handle canvas)
96 // Construct a new instance
97 handle<Instance> instance(new Instance(canvas));
100 } // END of sinfgapp::Instance::create()
103 Instance::get_file_name()const
105 return get_canvas()->get_file_name();
109 Instance::set_file_name(const sinfg::String &name)
111 get_canvas()->set_file_name(name);
112 CVSInfo::set_file_name(name);
115 Instance::~Instance()
117 instance_map_.erase(canvas_);
118 sinfg::info("studio::Instance::~Instance(): Deleted");
119 } // END of studio::Instance::~Instance()
121 handle<CanvasInterface>
122 Instance::find_canvas_interface(handle<Canvas> canvas)
126 while(canvas->is_inline())
127 canvas=canvas->parent();
129 CanvasInterfaceList::iterator iter;
131 for(iter=canvas_interface_list().begin();iter!=canvas_interface_list().end();iter++)
132 if((*iter)->get_canvas()==canvas)
135 return CanvasInterface::create(this,canvas);
139 Instance::save()const
141 bool ret=save_canvas(get_file_name(),canvas_);
144 reset_action_count();
145 const_cast<sigc::signal<void>& >(signal_saved_)();
151 Instance::save_as(const std::string &file_name)const
153 bool ret=save_canvas(file_name,canvas_);
156 reset_action_count();
157 const_cast<sigc::signal<void>& >(signal_saved_)();
163 Instance::save_as(const std::string &file_name)
167 String old_file_name(get_file_name());
169 set_file_name(file_name);
171 ret=save_canvas(file_name,canvas_);
175 reset_action_count();
180 set_file_name(old_file_name);
183 signal_filename_changed_();