00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __IOMODULE__H__
00013 #define __IOMODULE__H__
00014
00015 #include <wx/archive.h>
00016 #include <wx/wfstream.h>
00017 #include "scenemodule.h"
00018 #include "common.h"
00019
00020 namespace VRUT
00021 {
00023 class IOModule : public SceneModule
00024 {
00025 protected:
00027 virtual void processEvent(wxCommandEvent & evt)
00028 {
00029 SceneModule::processEvent(evt);
00030 switch (evt.GetEventType())
00031 {
00032 case Event::EVT_IO_SCENE_IMPORT_DO:
00033 {
00034 SCENE_ID _sceneID = SCENE_ID(evt.GetId());
00035 Scene * scene = GetSceneMgr()->GetScene(_sceneID);
00036 if (scene)
00037 {
00038 const SceneNode * root = scene->GetNode(NODE_ID(evt.GetInt()));
00039 if (root)
00040 {
00041 wxCommandEvent evCache = Event::GET_EVT_RENDER_CACHE_START(_sceneID);
00042 PostToKernel(evCache);
00043 ImportScene(evt.GetString(), _sceneID, root->GetUid());
00044 }
00045 else
00046 LOGERROR(wxT("<IOModule>Invalid root node to start import"));
00047 }
00048 else
00049 LOGERROR(wxT("<IOModule>Invalid scene defined to start import"));
00050 }
00051 break;
00052 default:
00053 break;
00054 }
00055 }
00056
00057 public:
00059 IOModule(const MODULE_ID & _id, const wxString & _name, unsigned _type, EventHandler * msgSink)
00060 : SceneModule(_id, _name, (_type | MODULE_TYPE_IO ), msgSink)
00061 {
00062 REGISTER_LISTENER(Event::EVT_IO_SCENE_IMPORT_DO);
00063 wxCommandEvent evt = Event::GET_EVT_PARAM_GUIUNREGISTER(Parameter::ParameterIdentificator(_name, wxT("*"), _id));
00064 PostToKernel(evt);
00065 }
00067 virtual ~IOModule() {}
00068
00070 virtual wxString GetSupportedExts() const = 0;
00072 static wxInputStream * GetInputStream(const wxString & fname)
00073 {
00074 wxFileName wxFname(fname);
00075 if (!wxFname.FileExists())
00076 {
00077 LOGERROR(wxT("<IOModule>File '") + fname + wxT("' not found"));
00078 return (wxInputStream *)NULL;
00079 }
00080
00081 wxInputStream * sceneStream = new wxFileInputStream(wxFname.GetFullPath());
00082
00084 const wxFilterClassFactory * ffactory = wxFilterClassFactory::Find(wxFname.GetFullName(), wxSTREAM_FILEEXT);
00085 if (ffactory)
00086 {
00087 sceneStream = ffactory->NewStream(sceneStream);
00088 wxFname.SetFullName(ffactory->PopExtension(wxFname.GetFullName()));
00089 }
00090
00092 const wxArchiveClassFactory * afactory = wxArchiveClassFactory::Find(wxFname.GetFullName(), wxSTREAM_FILEEXT);
00093 if (afactory)
00094 {
00095 sceneStream = afactory->NewStream(sceneStream);
00096 if (sceneStream)
00097 {
00098 wxArchiveEntry * entry(((wxArchiveInputStream *)sceneStream)->GetNextEntry());
00099 if (entry)
00100 {
00101 wxFname = wxFileName(entry->GetInternalName());
00102 ((wxArchiveInputStream *)sceneStream)->CloseEntry();
00103 delete entry;
00104 }
00105 }
00106 }
00107
00108 if (!sceneStream || !sceneStream->IsOk())
00109 {
00110 LOGERROR(wxT("<IOModule>File '") + fname + wxT("' cannot be read"));
00111 SAFE_DELETE(sceneStream);
00112 return (wxInputStream *)NULL;
00113 }
00114
00115 return sceneStream;
00116 }
00122 virtual bool ImportScene(const wxString & fname, SCENE_ID _sceneID, const wxString & rootUid) = 0;
00124 virtual bool ExportScene(const wxString & fname, const Scene * scene) = 0;
00125 };
00126 };
00127
00128
00129 #endif