00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <wx/stopwatch.h>
00012 #include <wx/tokenzr.h>
00013 #include <wx/zstream.h>
00014 #include "iovrml.h"
00015 #include "vrmlparser.h"
00016 #include "vrmlwriter.h"
00017
00018 using namespace VRUT;
00019
00020
00021 IOVrmlModule::IOVrmlModule(const MODULE_ID & _id, const wxString & _name, EventHandler * msgSink)
00022 : IOModule(_id, _name, 0, msgSink)
00023 {
00024 teselate = true;
00025 REGISTER_PARAM_GUI_CHECKBOX(teselateParamID, wxT("teselate"), wxT("1"), wxT("teselate"));
00026 hFlag = true;
00027 REGISTER_PARAM_GUI_CHECKBOX(hierarchyFlagParamID, wxT("hFlag"), wxT("1"), wxT("Hierarchy flag."));
00028 extraCams = true;
00029 REGISTER_PARAM_GUI_CHECKBOX(extraCamsParamID, wxT("extraCams"), wxT("1"), wxT("Export extra cameras"));
00030 }
00031
00032
00033 IOVrmlModule::~IOVrmlModule()
00034 {
00035 }
00036
00037 void IOVrmlModule::processEvent(wxCommandEvent & evt)
00038 {
00039 IOModule::processEvent(evt);
00040 switch (evt.GetEventType())
00041 {
00042 case Event::EVT_PARAM_SET:
00043 {
00044 UPDATE_PARAM_FROM_EVENT_BOOL(teselateParamID, teselate, evt);
00045 UPDATE_PARAM_FROM_EVENT_BOOL(hierarchyFlagParamID, hFlag, evt);
00046 UPDATE_PARAM_FROM_EVENT_BOOL(extraCamsParamID, extraCams, evt);
00047 }
00048 break;
00049 default:
00050 break;
00051 }
00052 }
00053
00054 wxString IOVrmlModule::GetDesc() const
00055 {
00056 return wxT("Import and export VRML files with scene hierarchy and geometry data");
00057 }
00058
00059
00060 wxString IOVrmlModule::GetSupportedExts() const
00061 {
00062 return wxT("WRL");
00063 }
00064
00065
00066 bool IOVrmlModule::ImportScene(const wxString & fname, SCENE_ID _sceneID, const wxString & rootUid)
00067 {
00068 wxStopWatch sw;
00069 bool ret = false;
00070 wxInputStream * is = GetInputStream(fname);
00071 if (is)
00072 {
00074 unsigned char buffer[2];
00075 is -> Read(buffer, sizeof(unsigned char)*2);
00076 if ( buffer[0] == 31 && buffer[1] == 139){
00077 wxFileName wxFname(fname);
00078 delete is;
00079 is = new wxFileInputStream(wxFname.GetFullPath());
00080 is = new wxZlibInputStream(is,wxZLIB_GZIP);
00081 VRMLParser vrmlParser2(is, _sceneID, fname, this);
00082 ret = vrmlParser2.Parse(rootUid, teselate, NULL);
00083 delete is;
00084 }
00085 else {
00086 is -> Ungetch(buffer, sizeof(unsigned char)*2);
00087 VRMLParser vrmlParser(is, _sceneID, fname, this);
00088 ret = vrmlParser.Parse(rootUid, teselate, NULL);
00089 delete is;
00090 }
00091 }
00092 LOG(wxString::Format(wxT("<VRMLParser>Scene parsed in %.3f secs, ID %i"), 0.001f * sw.Time(), _sceneID));
00093 wxCommandEvent ev = Event::GET_EVT_IO_SCENE_IMPORT_DONE(_sceneID);
00094 PostToKernel(ev);
00095 return ret;
00096 }
00097
00098
00099 bool IOVrmlModule::ExportScene(const wxString & fname, const Scene * scene)
00100 {
00101
00102 LOG(wxT("<IOVrmlModule>Inside IOVrmlModule::ExportScene"));
00103 wxOutputStream * sceneStream = new wxFileOutputStream(fname);
00104 if (sceneStream && sceneStream->IsOk())
00105 {
00106 wxBufferedOutputStream *sceneStream2=new wxBufferedOutputStream(*sceneStream);
00107 VRMLWriter vrmlWriter(sceneStream2, scene, fname);
00108 vrmlWriter.Write(hFlag, extraCams);
00109 sceneStream2->Sync();
00110 SAFE_DELETE(sceneStream2);
00111 return true;
00112 }
00113 SAFE_DELETE(sceneStream);
00114 return false;
00115 }