00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <wx/stopwatch.h>
00013 #include "iofhs.h"
00014 #include "fhsparser.h"
00015 #include "fhswriter.h"
00016
00017 using namespace VRUT;
00018
00019
00020 IOFhsModule::IOFhsModule(const MODULE_ID & _id, const wxString & _name, EventHandler * msgSink)
00021 : IOModule(_id, _name, 0, msgSink)
00022 {
00023
00024 }
00025
00026
00027 IOFhsModule::~IOFhsModule()
00028 {
00029 }
00030
00031
00032 wxString IOFhsModule::GetDesc() const
00033 {
00034 return wxT("Import and export FHS files with scene hierarchy and geometry data");
00035 }
00036
00037
00038 wxString IOFhsModule::GetSupportedExts() const
00039 {
00040 return wxT("FHS");
00041 }
00042
00043
00044 bool IOFhsModule::ImportScene(const wxString & fname, SCENE_ID _sceneID, const wxString & rootUid)
00045 {
00046 wxStopWatch sw;
00047 bool ret = false;
00048 wxInputStream * is = GetInputStream(fname);
00049 if (is)
00050 {
00051 FHSParser fhsParser(is, _sceneID, fname, this);
00052 ret = fhsParser.Parse(rootUid);
00053 delete is;
00054 }
00055 LOG(wxString::Format(wxT("<FHSParser>Scene parsed in %.3f secs, ID %i"), 0.001f * sw.Time(), _sceneID));
00056 wxCommandEvent ev = Event::GET_EVT_IO_SCENE_IMPORT_DONE(_sceneID);
00057 PostToKernel(ev);
00058 return ret;
00059 }
00060
00061
00062 bool IOFhsModule::ExportScene(const wxString & fname, const Scene * scene)
00063 {
00064 wxOutputStream * sceneStream = new wxFileOutputStream(fname);
00065 if (sceneStream && sceneStream->IsOk())
00066 {
00067 wxBufferedOutputStream *sceneStream2=new wxBufferedOutputStream(*sceneStream);
00068 FHSWriter fhsWriter(sceneStream2, scene);
00069 fhsWriter.Write();
00070 sceneStream2->Sync();
00071 SAFE_DELETE(sceneStream);
00072 return true;
00073 }
00074 SAFE_DELETE(sceneStream);
00075 return false;
00076 }