AddObject.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 "AddObject.h"
00029 #include "RealGUI.h"
00030
00031 #include <iostream>
00032 #include <sstream>
00033
00034 #ifdef SOFA_QT4
00035 #include <Q3FileDialog>
00036 #include <QLineEdit>
00037 #include <QLabel>
00038 #include <QRadioButton>
00039 #include <QPushButton>
00040 #include <Q3ButtonGroup>
00041 #include <QGridLayout>
00042 #else
00043 #include <qfiledialog.h>
00044 #include <qlineedit.h>
00045 #include <qlabel.h>
00046 #include <qradiobutton.h>
00047 #include <qpushbutton.h>
00048 #include <qbuttongroup.h>
00049 #include <qlayout.h>
00050 #endif
00051
00052 namespace sofa
00053 {
00054
00055 namespace gui
00056 {
00057
00058 namespace qt
00059 {
00060
00061
00062 #ifndef SOFA_QT4
00063 typedef QFileDialog Q3FileDialog;
00064 typedef QButtonGroup Q3ButtonGroup;
00065 #endif
00066
00067
00068 AddObject::AddObject( std::vector< std::string > *list_object_, QWidget* parent , const char* name, bool , Qt::WFlags ): DialogAddObject(parent, name), list_object(list_object_)
00069 {
00070
00071 custom->setChecked(true);
00072
00073
00074
00075 if (list_object != NULL)
00076 {
00077 QRadioButton *button;
00078 std::string current_name;
00079
00080 for (int i=0;i<(int)list_object->size();i++)
00081 {
00082 std::ostringstream ofilename;
00083 current_name = (*list_object)[i];
00084 std::string::size_type pos=current_name.rfind('/');
00085
00086 if (pos != std::string::npos)
00087 {
00088 current_name = current_name.substr(pos+1, current_name.size()-pos-5);
00089 }
00090 button = new QRadioButton( buttonGroup, QString(current_name.c_str()) );
00091 button->setText(current_name.c_str());
00092
00093 #ifdef SOFA_QT4
00094 gridLayout1->addWidget( button, i+1, 0 );
00095 #else
00096 buttonGroupLayout->addWidget( button, i+1, 0 );
00097 #endif
00098 }
00099 }
00100
00101 positionX->setText("0");
00102 positionY->setText("0");
00103 positionZ->setText("0");
00104
00105 rotationX->setText("0");
00106 rotationY->setText("0");
00107 rotationZ->setText("0");
00108
00109 scaleValue->setText("1");
00110
00111 scaleValue->hide();
00112 scaleText->hide();
00113
00114 openFilePath->setText(NULL);
00115
00116
00117 connect( this, SIGNAL(loadObject(std::string, double, double, double, double, double, double,double)), parent, SLOT(loadObject(std::string, double, double, double,double, double, double, double)));
00118
00119 connect( buttonGroup, SIGNAL( clicked(int) ), this, SLOT (buttonUpdate(int)));
00120 }
00121
00122
00123
00124 void AddObject::accept()
00125 {
00126 std::string position[3];
00127 std::string rotation[3];
00128 std::string scale;
00129 #ifdef SOFA_QT4
00130 std::string object_fileName(openFilePath->text().toStdString());
00131 position[0] = positionX->text().toStdString();
00132 position[1] = positionY->text().toStdString();
00133 position[2] = positionZ->text().toStdString();
00134
00135 rotation[0] = rotationX->text().toStdString();
00136 rotation[1] = rotationY->text().toStdString();
00137 rotation[2] = rotationZ->text().toStdString();
00138
00139 scale = scaleValue->text().toStdString();
00140 #else
00141 std::string object_fileName(openFilePath->text().latin1());
00142 position[0] = positionX->text().latin1();
00143 position[1] = positionY->text().latin1();
00144 position[2] = positionZ->text().latin1();
00145
00146 rotation[0] = rotationX->text().latin1();
00147 rotation[1] = rotationY->text().latin1();
00148 rotation[2] = rotationZ->text().latin1();
00149
00150 scale = scaleValue->text().latin1();
00151 #endif
00152 emit( loadObject(object_fileName, atof(position[0].c_str()),atof(position[1].c_str()),atof(position[2].c_str()),
00153 atof(rotation[0].c_str()),atof(rotation[1].c_str()),atof(rotation[2].c_str()),
00154 atof(scale.c_str())));
00155 setPath(object_fileName);
00156 QDialog::accept();
00157 }
00158
00159
00160
00161 void AddObject::setPath(const std::string path)
00162 {
00163 fileName = path;
00164 openFilePath->setText(QString(fileName.c_str()));
00165 }
00166
00167
00168
00169 void AddObject::fileOpen()
00170 {
00171 QString s = getOpenFileName(this, QString(fileName.c_str()), "Sofa Element (*.xml *.scn)", "open file dialog", "Choose a file to open" );
00172
00173 if (s.isNull() ) return;
00174 #ifdef SOFA_QT4
00175 std::string object_fileName(s.toStdString());
00176 #else
00177 std::string object_fileName(s.latin1());
00178 #endif
00179
00180 openFilePath->setText(QString(object_fileName.c_str()));
00181 }
00182
00183
00184
00185
00186 void AddObject::buttonUpdate(int Id)
00187 {
00188
00189 if (Id == 0)
00190 {
00191 openFilePath->setText(fileName.c_str());
00192 openFileText->show();
00193 openFilePath->show();
00194 openFileButton->show();
00195 }
00196 else
00197 {
00198 openFilePath->setText((*list_object)[Id-1].c_str());
00199 openFileText->hide();
00200 openFilePath->hide();
00201 openFileButton->hide();
00202 }
00203 }
00204 }
00205
00206 }
00207
00208 }
00209