Main.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This program is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU General Public License as published by the Free  *
00007 * Software Foundation; either version 2 of the License, or (at your option)   *
00008 * any later version.                                                          *
00009 *                                                                             *
00010 * This program is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
00013 * more details.                                                               *
00014 *                                                                             *
00015 * You should have received a copy of the GNU General Public License along     *
00016 * with this program; if not, write to the Free Software Foundation, Inc., 51  *
00017 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
00018 *******************************************************************************
00019 *                            SOFA :: Applications                             *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
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; // already initialized
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 } // namespace gui
00103 
00104 } // namespace sofa

Generated on Sun Nov 23 02:28:34 2008 for Sofa by  doxygen 1.5.7.1