00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015
00016 #ifndef __IO_H__
00017 #define __IO_H__
00018
00019 #include "../../core/src/iomodule.h"
00020 #include "../../core/src/textparser.h"
00021 #include "../../core/src/geometrynode.h"
00022 #include "../../core/src/geometrytriangles.h"
00023
00024
00025 namespace VRUT
00026 {
00028 const int MODULE_VERSION = 1;
00029
00031 class _io: public IOModule
00032 {
00033 protected:
00035 int var;
00037 Parameter::ParameterIdentificator varParamID;
00038
00040 virtual void processEvent(wxCommandEvent & evt)
00041 {
00043 IOModule::processEvent(evt);
00044
00045 switch (evt.GetEventType())
00046 {
00048 case Event::EVT_PARAM_SET:
00049 UPDATE_PARAM_FROM_EVENT_INT(varParamID, var, evt);
00050 break;
00051 }
00052 }
00054 virtual void run()
00055 {
00058 LOG(wxT("<_io>I am still alive"));
00060 if (TestExit())
00062 return;
00063 }
00064
00065 public:
00067 _io(const MODULE_ID & _id, const wxString & _name, EventHandler * msgSink)
00068 : IOModule(_id, _name, 0, msgSink),
00071 varParamID(_name, wxT("var"), _id)
00072 {
00074 REGISTER_PARAM_GUI_SLIDER(varParamID, wxT("100"), 0, 200);
00075 }
00077 virtual ~_io()
00078 {
00079 }
00080
00082 virtual wxString GetDesc() const
00083 {
00084 return wxT("This is my module");
00085 }
00087 virtual wxString GetSupportedExts() const
00088 {
00090 return wxT("NONE1 NONE2 NONE3 FHS");
00091 }
00094 virtual bool ImportScene(const wxString & fname, SCENE_ID _sceneID, const wxString & rootName)
00095 {
00098 wxInputStream * inputStream = IOModule::GetInputStream(fname);
00099 if (inputStream)
00100 {
00102 TextParser textParser(inputStream, 10000, 1000);
00103 LOG(wxT("<_io>") + textParser.GetWxLine());
00105 SAFE_DELETE(inputStream);
00106 }
00107
00110 SceneNode * node = new GeometryNode(wxT("_io_test"));
00112 wxCommandEvent evt = Event::GET_EVT_SCENE_NODE_INSERT(_sceneID, node, rootName);
00113 PostToKernel(evt);
00115 GeometryTriangles * geom = new GeometryTriangles(wxT("_io_test_geometry"));
00116 geom->vertices.push_back(VECTOR3(-1,0,0));
00117 geom->vertices.push_back(VECTOR3(0,1,0));
00118 geom->vertices.push_back(VECTOR3(0,0,-1));
00119 geom->indices.push_back(0);
00120 geom->indices.push_back(1);
00121 geom->indices.push_back(2);
00122 geom->normals.push_back(VECTOR3(0, -1, 0));
00123 geom->normals.push_back(VECTOR3(0, -1, 0));
00124 geom->normals.push_back(VECTOR3(0, -1, 0));
00127 std::pair<GeometryTriangles::Indice, GeometryTriangles::PRIMITIVE_TYPE> triDesc(0, GeometryTriangles::TRI_LIST);
00129 geom->triDescList.push_back(triDesc);
00131 wxCommandEvent evt2 = Event::GET_EVT_SCENE_GEOMETRY_ADD(_sceneID, geom);
00132 PostToKernel(evt2);
00134 wxCommandEvent evt3 = Event::GET_EVT_SCENE_NODE_GEOMETRY_SET(_sceneID, wxT("_io_test"), geom->GetName());
00135 PostToKernel(evt3);
00136
00138 wxCommandEvent ev4 = Event::GET_EVT_IO_SCENE_IMPORT_DONE(_sceneID);
00139 PostToKernel(ev4);
00140
00141 return true;
00142 }
00143 virtual bool ExportScene(const wxString & fname, const Scene * scene)
00144 {
00145 if (scene)
00146 LOG(wxString::Format(wxT("<_io>Saving scene '%s' to file '%s'"), scene->GetName().c_str(), fname.c_str()));
00148
00149 return true;
00150 }
00151 };
00152 };
00153
00154
00155 EXPORT_VRUT_MODULE_FUNCTIONS( _io )
00156
00157
00158 #endif