QtOgreViewer_slots.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 "OgreVector3.h"
00028 #include <sofa/gui/qt/viewer/qtogre/QtOgreViewer.h>
00029 #include <GenGraphForm.h>
00030 
00031 #ifdef SOFA_QT4
00032 #include <QFileDialog>
00033 #else
00034 #include <qfiledialog.h>
00035 #endif
00036 
00037 
00038 namespace sofa
00039 {
00040   namespace gui
00041   {
00042     namespace qt
00043     {
00044       namespace viewer
00045       {
00046     namespace qtogre
00047     {
00048 
00049       //*****************************************************************************************
00050       // Just modify the point of view, keep the simulation running.
00051       void QtOgreViewer::resetView()
00052       {
00053         using namespace Ogre;
00054 
00055         //if no view file was present, we set up automatically the view.
00056         showEntireScene();
00057 
00058         if (!sceneFileName.empty())
00059           {
00060         std::string viewFileName = sceneFileName+".ogre.view";
00061         std::ifstream in(viewFileName.c_str());
00062         if (!in.fail())
00063           {
00064             Ogre::Vector3 camera_position;
00065             Ogre::Quaternion camera_orientation;
00066 
00067             in >> camera_position[0];
00068             in >> camera_position[1];
00069             in >> camera_position[2];
00070 
00071 
00072             in >> camera_orientation.w;
00073             in >> camera_orientation.x;
00074             in >> camera_orientation.y;
00075             in >> camera_orientation.z;
00076             camera_orientation.normalise();
00077 
00078             mCamera->setOrientation(camera_orientation);            
00079 
00080             mCamera->setPosition(camera_position);
00081 
00082             in.close();
00083             update();
00084             return;
00085           }     
00086           } 
00087         update();
00088       }
00089 
00090 
00091 
00092       //*****************************************************************************************
00093       // Resize
00094       void QtOgreViewer::setSizeW( int size )
00095       {
00096 
00097         if (mRenderWindow != NULL){
00098           mRenderWindow->resize( size, mRenderWindow->getHeight());
00099           mRenderWindow->windowMovedOrResized();
00100         }
00101         QWidget::resize(size,mRenderWindow->getHeight());
00102         update();
00103       }
00104 
00105       void QtOgreViewer::setSizeH( int size )
00106       {
00107         if (mRenderWindow != NULL){
00108           mRenderWindow->resize( mRenderWindow->getWidth(), size);
00109           mRenderWindow->windowMovedOrResized();
00110         }
00111         QWidget::resize(mRenderWindow->getWidth(),size);
00112         update();
00113       }
00114 
00115 
00116       void QtOgreViewer::saveView()
00117       {
00118         if (!sceneFileName.empty())
00119           {
00120         std::string viewFileName = sceneFileName+".ogre.view";
00121         std::ofstream out(viewFileName.c_str());
00122         if (!out.fail())
00123           {
00124             Ogre::Vector3 position_cam = mCamera->getPosition();
00125             Ogre::Quaternion orientation_cam = mCamera->getOrientation();
00126 
00127             out << position_cam[0] << " " << position_cam[1] << " " << position_cam[2] << "\n";
00128             out << orientation_cam.x << " " << orientation_cam.y << " " << orientation_cam.z << " " << orientation_cam.w << "\n";
00129             out.close();
00130 
00131 
00132           }
00133         std::cout << "View parameters saved in "<<viewFileName<<std::endl;
00134           }
00135       }
00136 
00137 
00138     } //qtogre
00139       } //viewer
00140     } //qt
00141   } //gui
00142 } //sofa

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