VRUT::IOManager Class Reference

Server managing import/export modules. More...

#include <iomanager.h>

Inheritance diagram for VRUT::IOManager:

VRUT::ServerBase< T >

List of all members.

Public Member Functions

 IOManager ()
 Class constructor.
virtual ~IOManager ()
 Class destructor.
SCENE_ID ImportScene (const wxString &fname)
 Try to load scene from file using module.
void ExportScene (const Scene *scene, const wxString &fname)
 Try to save scene to file using module.

Protected Member Functions

IOModulefindModule (const wxString &extension)
bool moduleSupportsExt (IOModule *module, const wxString &ext)


Detailed Description

Server managing import/export modules.

Definition at line 22 of file iomanager.h.


Constructor & Destructor Documentation

IOManager::IOManager (  ) 

Class constructor.

Definition at line 20 of file iomanager.cpp.

00020                      : ServerBase<IOModule>(IO_MANAGER)
00021 {
00022 }

IOManager::~IOManager (  )  [virtual]

Class destructor.

Definition at line 25 of file iomanager.cpp.

00026 {
00027 }


Member Function Documentation

IOModule * IOManager::findModule ( const wxString &  extension  )  [protected]

Search for available module with support for given extension

Returns:
Loaded module if found, NULL otherwise

Try prefered module

Try scene IO modules with name containing extension

Try other scene IO modules

Definition at line 45 of file iomanager.cpp.

00046 {
00048        MODULE_ID modID = createPreferedModuleInstance();
00049        IOModule * mod = getModule(modID);
00050        if (mod)
00051        {
00052               if (mod->GetSupportedExts().Upper().Find(extension.Upper()) != wxNOT_FOUND)
00053                      return mod;
00054               LOGVERBOSE(wxString::Format(wxT("%sModule '%s' available and valid but without support for '%s' file format, skipping"),
00055                                           SERVER_CLASS_NAMES[serverID].c_str(), mod->GetName().c_str(), extension.c_str()));
00056               releaseModule(modID);
00057        }
00058 
00060        wxString lookFor = wxString::Format(wxT("*%s*"), extension.c_str());
00061        modID = createModuleInstance(lookFor);
00062        mod = getModule(modID);
00063        if (mod)
00064        {
00065               if (mod->GetSupportedExts().Upper().Find(extension.Upper()) != wxNOT_FOUND)
00066                      return mod;
00067               LOGVERBOSE(wxString::Format(wxT("%sModule '%s' available and valid but without support for '%s' file format, skipping"),
00068                                           SERVER_CLASS_NAMES[serverID].c_str(), mod->GetName().c_str(), extension.c_str()));
00069               releaseModule(modID);
00070        }
00071 
00073        std::vector<MODULE_HANDLE_ID> handles = findModuleHandles(wxT("*"));
00074        for (std::vector<MODULE_HANDLE_ID>::const_iterator it = handles.begin();
00075                it != handles.end(); it++)
00076        {
00077               ModuleHandle<IOModule> * handle = getModuleHandle(*it);
00078               if (handle)
00079               {
00080                      MODULE_ID modID = createModuleInstance(handle->GetFileName().GetName());
00081                      mod = getModule(modID);
00082                      if (mod)
00083                      {
00084                             if (mod->GetSupportedExts().Upper().Find(extension.Upper()) != wxNOT_FOUND)
00085                                    return mod;
00086                             releaseModule(modID);
00087                      }
00088               }
00089        }
00090 
00091        return (IOModule *)NULL;
00092 }

bool IOManager::moduleSupportsExt ( IOModule module,
const wxString &  ext 
) [protected]

Query module for file format support

Parameters:
[in] module Module
[in] ext Format file extension
Returns:
true if file format is supported

Definition at line 30 of file iomanager.cpp.

00031 {
00032        if (module)
00033        {
00034               wxStringTokenizer tkz(module->GetSupportedExts(), wxT(" ,;|"));
00035               while (tkz.HasMoreTokens())
00036               {
00037                      if (tkz.GetNextToken().IsSameAs(ext, false))
00038                             return true;
00039               }
00040        }
00041        return false;
00042 }

SCENE_ID IOManager::ImportScene ( const wxString &  fname  ) 

Try to load scene from file using module.

Is bzip2 or gzip archive?

Is tar or zip archive?

Definition at line 95 of file iomanager.cpp.

00096 {
00097        LOG(SERVER_CLASS_NAMES[serverID] + wxT("Importing scene from '") + fname + wxT("'"));
00098 
00099        wxFileName wxFname(fname);
00100        if (!wxFname.FileExists())
00101        {
00102               LOGERROR(wxT("<IOModule>File '") + fname + wxT("' not found"));
00103               return SCENE_ID_NONE;
00104        }
00105 
00107        const wxFilterClassFactory * ffactory = wxFilterClassFactory::Find(wxFname.GetFullName(), wxSTREAM_FILEEXT);
00108        if (ffactory)
00109               wxFname.SetFullName(ffactory->PopExtension(wxFname.GetFullName()));
00111        const wxArchiveClassFactory * afactory = wxArchiveClassFactory::Find(wxFname.GetFullName(), wxSTREAM_FILEEXT);
00112        if (afactory)
00113        {
00114               wxFileInputStream fis(wxFname.GetFullPath());
00115               wxArchiveInputStream * arcin(afactory->NewStream(fis));
00116               if (arcin)
00117               {
00118                      wxArchiveEntry * entry(arcin->GetNextEntry());
00119                      if (entry)
00120                      {
00121                             wxFname = wxFileName(entry->GetInternalName());
00122                             delete entry;
00123                      }
00124                      delete arcin;
00125               }
00126        }
00127 
00128        IOModule * module = findModule(wxFname.GetExt());
00129        if (!module)
00130        {
00131 
00132               LOGERROR(SERVER_CLASS_NAMES[serverID] + wxT("File '") + fname + wxT("' not supported"));
00133               return SCENE_ID_NONE;
00134        }
00135 
00136        module->SetSceneMgr(KERNEL->sceneManager);
00137        SCENE_ID sceneID = SCENE_ID_NONE;
00138        if (!module->IsActive())
00139               ModuleHandle<IOModule>::StartModuleThread(module);
00140        wxString rootName(wxT("scene_root"));
00141        sceneID = KERNEL->sceneManager->AddSceneGraph(new SceneNode(rootName, rootName, SceneNode::ROOT));
00142        Scene * scene = KERNEL->sceneManager->GetScene(sceneID);
00143        scene->SetName(wxFname.GetFullName() + wxString::Format(wxT(".%i"), sceneID));
00144        wxCommandEvent imEvt = Event::GET_EVT_IO_SCENE_IMPORT_DO(sceneID, scene->GetRootID(), fname);
00145        module->PostEvent(imEvt);
00146 
00147        return sceneID;
00148 }

void IOManager::ExportScene ( const Scene scene,
const wxString &  fname 
)

Try to save scene to file using module.

Definition at line 150 of file iomanager.cpp.

00151 {
00152        LOG(wxString::Format(wxT("%sSaving scene to '%s'"), SERVER_CLASS_NAMES[serverID].c_str(), fname.c_str()));
00153        wxFileName wxFname(fname);
00154        IOModule * module = findModule(wxFname.GetExt());
00155        if (!module)
00156        {
00157               LOGERROR(wxString::Format(wxT("%sFile '%s' not supported"), SERVER_CLASS_NAMES[serverID].c_str(), fname.c_str()));
00158               return;
00159        }
00160        wxStopWatch sw;
00161        if (module->ExportScene(fname, scene))
00162               LOG(wxString::Format(wxT("%sScene saved in %.3f secs"), SERVER_CLASS_NAMES[serverID].c_str(), 0.001f * sw.Time()));
00163 }


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:43 2009 for VRUT by  doxygen 1.5.5