2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_MODEL_H )
23 #define INCLUDED_MODEL_H
25 #include "entitylib.h"
26 #include "traverselib.h"
27 #include "generic/callback.h"
28 #include "stream/stringstream.h"
30 #include "moduleobserver.h"
32 class EModel : public ModuleObserver
34 ResourceReference m_resource;
35 scene::Traversable& m_traverse;
37 Callback<void()> m_modelChanged;
40 EModel( scene::Traversable& traversable, const Callback<void()>& modelChanged )
41 : m_resource( "" ), m_traverse( traversable ), m_node( 0 ), m_modelChanged( modelChanged ){
42 m_resource.attach( *this );
45 m_resource.detach( *this );
49 m_resource.get()->load();
50 m_node = m_resource.get()->getNode();
52 m_traverse.insert( *m_node );
57 m_traverse.erase( *m_node );
61 void modelChanged( const char* value ){
62 StringOutputStream cleaned( string_length( value ) );
63 cleaned << PathCleaned( value );
64 m_resource.detach( *this );
65 m_resource.setName( cleaned.c_str() );
66 m_resource.attach( *this );
69 typedef MemberCaller<EModel, void(const char*), &EModel::modelChanged> ModelChangedCaller;
71 const char* getName() const {
72 return m_resource.getName();
74 scene::Node* getNode() const {
81 TraversableNode m_traverse;
85 : m_model( m_traverse, Callback<void()>() ){
88 void attach( scene::Traversable::Observer* observer ){
89 m_traverse.attach( observer );
91 void detach( scene::Traversable::Observer* observer ){
92 m_traverse.detach( observer );
95 scene::Traversable& getTraversable(){
99 void modelChanged( const char* value ){
100 m_model.modelChanged( value );
102 typedef MemberCaller<SingletonModel, void(const char*), &SingletonModel::modelChanged> ModelChangedCaller;
104 scene::Node* getNode() const {
105 return m_model.getNode();