Main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "SofaGUI.h"
00028 #include <sofa/component/init.h>
00029
00030 namespace sofa
00031 {
00032
00033 namespace gui
00034 {
00035
00036 SOFA_LINK_CLASS(BatchGUI)
00037
00038 #ifdef SOFA_GUI_GLUT
00039 SOFA_LINK_CLASS(SimpleGUI)
00040 #endif
00041
00042 #ifdef SOFA_GUI_QGLVIEWER
00043 SOFA_LINK_CLASS(QGLViewerGUI)
00044 #endif
00045 #ifdef SOFA_GUI_QTVIEWER
00046 SOFA_LINK_CLASS(QTGUI)
00047 #endif
00048 #ifdef SOFA_GUI_QTOGREVIEWER
00049 SOFA_LINK_CLASS(OgreGUI)
00050 #endif
00051
00052 int SofaGUI::Init()
00053 {
00054 sofa::component::init();
00055 if (guiCreators().empty())
00056 {
00057 std::cerr << "ERROR(SofaGUI): No GUI registered."<<std::endl;
00058 return 1;
00059 }
00060 const char* name = GetGUIName();
00061 if (currentGUI)
00062 return 0;
00063
00064 GUICreator* creator = GetGUICreator(name);
00065 if (!creator)
00066 {
00067 return 1;
00068 }
00069 if (creator->init)
00070 return (*creator->init)(name, guiOptions);
00071 else
00072 return 0;
00073 }
00074
00075 int SofaGUI::MainLoop(sofa::simulation::Node* groot, const char* filename)
00076 {
00077 int ret = 0;
00078 const char* name = GetGUIName();
00079 if (!currentGUI)
00080 {
00081 GUICreator* creator = GetGUICreator(name);
00082 if (!creator)
00083 {
00084 return 1;
00085 }
00086 currentGUI = (*creator->creator)(name, guiOptions, groot, filename);
00087 if (!currentGUI)
00088 {
00089 std::cerr << "ERROR(SofaGUI): GUI "<<name<<" creation failed."<<std::endl;
00090 return 1;
00091 }
00092 }
00093 ret = currentGUI->mainLoop();
00094 if (ret)
00095 {
00096 std::cerr << "ERROR(SofaGUI): GUI "<<name<<" main loop failed (code "<<ret<<")."<<std::endl;
00097 return ret;
00098 }
00099 return ret;
00100 }
00101
00102 }
00103
00104 }