AddPreset.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 
00028 #include "AddPreset.h"
00029 
00030 #include <iostream> 
00031 #include <sstream>  
00032 #include <cstdlib>
00033 #include <sofa/gui/qt/FileManagement.h> //static functions to manage opening/ saving of files
00034 #include <sofa/helper/system/SetDirectory.h>
00035 
00036 #ifdef SOFA_QT4
00037 #include <Q3FileDialog>   
00038 #include <QLineEdit>
00039 #include <QLabel>
00040 #include <QRadioButton>
00041 #include <QPushButton>
00042 #include <Q3ButtonGroup>
00043 #include <QGridLayout>
00044 #else
00045 #include <qfiledialog.h>
00046 #include <qlineedit.h>
00047 #include <qlabel.h>
00048 #include <qradiobutton.h>
00049 #include <qpushbutton.h>
00050 #include <qbuttongroup.h>
00051 #include <qlayout.h>
00052 #endif
00053 
00054 namespace sofa
00055 {
00056 
00057   namespace gui
00058   {
00059 
00060     namespace qt
00061     {
00062 
00063 
00064 #ifndef SOFA_QT4
00065       typedef QFileDialog  Q3FileDialog;
00066       typedef QButtonGroup Q3ButtonGroup;
00067 #endif
00068 
00069   
00070       AddPreset::AddPreset(  QWidget* parent , const char* name, bool *elementPresent, bool , Qt::WFlags ): DialogAddPreset(parent, name)
00071       {
00072     this->setCaption(QString(sofa::helper::system::SetDirectory::GetFileName(name).c_str()));
00073     clear();
00074 
00075     if (elementPresent != NULL)
00076       {
00077         if (!elementPresent[0]) 
00078           {
00079         openFileText0->hide();
00080         openFilePath0->hide();
00081         openFileButton0->hide();
00082           }
00083         else
00084           {
00085         openFileText0->show();
00086         openFilePath0->show();
00087         openFileButton0->show();
00088           }
00089         if (!elementPresent[1]) 
00090           {
00091         openFileText1->hide();
00092         openFilePath1->hide();
00093         openFileButton1->hide();
00094           }
00095         else                    
00096           {
00097         openFileText1->show();
00098         openFilePath1->show();
00099         openFileButton1->show();
00100           }
00101         if (!elementPresent[2]) 
00102           {
00103         openFileText2->hide();
00104         openFilePath2->hide();
00105         openFileButton2->hide();
00106           }
00107         else                    
00108           {
00109         openFileText2->show();
00110         openFilePath2->show();
00111         openFileButton2->show();
00112           }
00113       }
00114     //Make the connection between this widget and the parent
00115     connect( this, SIGNAL(loadPreset(GNode*,std::string,std::string*, std::string*,std::string*,std::string)), 
00116          parent, SLOT(loadPreset(GNode*,std::string,std::string*, std::string*,std::string*,std::string)));
00117       }
00118 
00119       //Clear the dialoag
00120       void AddPreset::clear()
00121       {
00122     positionX->setText("0");
00123     positionY->setText("0");
00124     positionZ->setText("0");
00125     
00126     rotationX->setText("0");
00127     rotationY->setText("0");
00128     rotationZ->setText("0");
00129     
00130     scaleValue->setText("1");
00131 
00132     openFilePath0->setText(NULL);
00133     openFilePath1->setText(NULL);
00134     openFilePath2->setText(NULL);
00135 
00136       }
00137 
00138       //**************************************************************************************
00139       //When the Ok Button is clicked, this method is called: we just have to emit a signal to the parent, with the information on the object
00140       void AddPreset::accept()
00141       {
00142     std::string position[3];
00143     std::string rotation[3];
00144     std::string scale;
00145 
00146     std::string filenames[3];
00147     filenames[0] = openFilePath0->text().ascii();
00148     filenames[1] = openFilePath1->text().ascii();
00149     filenames[2] = openFilePath2->text().ascii();
00150     
00151     position[0] = positionX->text().ascii();
00152     position[1] = positionY->text().ascii();
00153     position[2] = positionZ->text().ascii();
00154     
00155     rotation[0] = rotationX->text().ascii();
00156     rotation[1] = rotationY->text().ascii();
00157     rotation[2] = rotationZ->text().ascii();
00158     
00159     scale       = scaleValue->text().ascii();
00160 
00161     emit( loadPreset(node, presetFile,filenames,position,rotation,scale));
00162     clear();
00163     QDialog::accept();
00164       }
00165 
00166 
00167       //**************************************************************************************
00168       //Open a file Dialog and set the path of the selected path in the text field.
00169       void AddPreset::fileOpen()
00170       {
00171     QString s  = getOpenFileName(this, QString(fileName.c_str()), "Mesh File (*.msh *.mesh *.obj *.sph *.xs3 *.bvh *.rigid)", "open file dialog",  "Choose a file to open" );
00172     
00173     if (s.isNull() ) return;
00174     fileName=std::string (s.ascii());
00175     
00176     if (sender() == openFileButton0)
00177       openFilePath0->setText(QString(fileName.c_str()));
00178     else if (sender() == openFileButton1)
00179       openFilePath1->setText(QString(fileName.c_str()));
00180     else if (sender() == openFileButton2)
00181       openFilePath2->setText(QString(fileName.c_str()));
00182       }
00183 
00184     } // namespace qt
00185 
00186   } // namespace gui
00187 
00188 } // namespace sofa
00189 

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