AddPreset.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
00028 #include "AddPreset.h"
00029
00030 #include <iostream>
00031 #include <sstream>
00032 #include <cstdlib>
00033 #include <sofa/gui/qt/FileManagement.h>
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
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
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
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
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 }
00185
00186 }
00187
00188 }
00189