00001 /* 00002 * $Id: scenemanager.cpp 481 2008-11-15 16:36:05Z kybav1 $ 00003 * 00004 * Description : One line description of file. 00005 * Author : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com> <ICQ: 98576293> 00006 * 00007 * Purpose : 00008 * Long description of what the file is for. 00009 */ 00010 00011 00012 #include <wx/image.h> 00013 #include "scenemanager.h" 00014 #include "flexilog.h" 00015 #include "imagrgb.h" 00016 #include "events.h" 00017 #include "kernel.h" 00018 00019 using namespace VRUT; 00020 00021 00022 SceneManager::SceneManager() 00023 { 00024 wxImage::AddHandler(new wxRGBHandler()); 00025 } 00026 00027 00028 SceneManager::~SceneManager() 00029 { 00030 SAFE_DELETE_ARR_EACH(sceneList, sceneList.size()); 00031 ImageList::iterator it = imageList.begin(); 00032 for ( ; it != imageList.end(); it++) 00033 SAFE_DELETE(it->second); 00034 } 00035 00036 00037 size_t SceneManager::GetSceneIDs(std::vector<SCENE_ID> &IDlist) const 00038 { 00039 IDlist.clear(); 00040 for (size_t i=0; i<sceneList.size(); i++) 00041 { 00042 if (sceneList[i]) 00043 IDlist.push_back(SCENE_ID(i)); 00044 } 00045 return IDlist.size(); 00046 } 00047 00048 00049 SCENE_ID SceneManager::AddSceneGraph(SceneNode * sceneRoot) 00050 { 00051 SCENE_ID id = SCENE_ID(sceneList.size()); 00052 Scene * scene = new Scene(id, KERNEL->GetMessageSink()); 00053 scene->Insert(sceneRoot, NODE_ID_NONE); 00054 sceneList.push_back(scene); 00055 scene->sceneManager = this; 00056 return id; 00057 } 00058 00059 00060 Scene * SceneManager::RemoveSceneGraph(SCENE_ID id) 00061 { 00062 Scene * scene = GetScene(id); 00063 if (scene) 00064 { 00065 sceneList[id] = (Scene *)NULL; 00066 scene->sceneManager = (SceneManager *)NULL; 00067 } 00068 return scene; 00069 } 00070 00071 00072 const Image * SceneManager::GetImage(const wxString & imgPath, bool loadIfNotFound) 00073 { 00074 ImageList::iterator img = imageList.find(imgPath); 00075 if (img != imageList.end()) 00076 return img->second; 00077 else if (loadIfNotFound) 00078 { 00079 wxFileName fname(imgPath); 00080 Image * image = (Image *)NULL; 00081 if (fname.GetExt().IsSameAs(wxT("dds"), false)) 00082 image = new ImageDDS; 00083 else 00084 image = new ImageCommon; 00085 if (image && image->Load(imgPath)) 00086 { 00087 ImageList::Insert_Result res = imageList.insert(ImageList::value_type(imgPath, image)); 00088 if (res.second) 00089 { 00090 wxCommandEvent evRes = Event::GET_EVT_SCENE_IMAGE_ADDED(imgPath); 00091 KERNEL->GetMessageSink()->PostEvent(evRes); 00092 return image; 00093 } 00094 } 00095 else 00096 SAFE_DELETE(image); 00097 } 00098 00099 return (Image *)NULL; 00100 }
1.5.5