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
00030 #include "settingsDlg.h"
00031 #include "world.h"
00032 #include "graspitGUI.h"
00033 #include "ivmgr.h"
00034
00035 #include <QValidator>
00036 #include <QMessageBox>
00037
00047 void SettingsDlg::init()
00048 {
00049 int i,j;
00050 QString val;
00051 World *w = graspItGUI->getIVmgr()->getWorld();
00052
00053 dlgUI->staticFrictionTable->horizontalHeader()->hide();
00054 dlgUI->staticFrictionTable->verticalHeader()->hide();
00055 dlgUI->kineticFrictionTable->horizontalHeader()->hide();
00056 dlgUI->kineticFrictionTable->verticalHeader()->hide();
00057 dlgUI->staticFrictionTable->setTopMargin(0);
00058 dlgUI->staticFrictionTable->setLeftMargin(0);
00059 dlgUI->kineticFrictionTable->setTopMargin(0);
00060 dlgUI->kineticFrictionTable->setLeftMargin(0);
00061
00062
00063 dlgUI->staticFrictionTable->setNumRows(w->getNumMaterials()+1);
00064 dlgUI->staticFrictionTable->setNumCols(w->getNumMaterials()+1);
00065 dlgUI->kineticFrictionTable->setNumRows(w->getNumMaterials()+1);
00066 dlgUI->kineticFrictionTable->setNumCols(w->getNumMaterials()+1);
00067
00068 dlgUI->staticFrictionTable->setItem(0,0,new Q3TableItem(dlgUI->staticFrictionTable,Q3TableItem::Never,""));
00069 dlgUI->kineticFrictionTable->setItem(0,0,new Q3TableItem(dlgUI->kineticFrictionTable,Q3TableItem::Never,""));
00070
00071 for (i=0;i<w->getNumMaterials();i++) {
00072 dlgUI->staticFrictionTable->setText(0,i+1,w->getMaterialName(i));
00073 dlgUI->staticFrictionTable->setText(i+1,0,w->getMaterialName(i));
00074 dlgUI->kineticFrictionTable->setText(0,i+1,w->getMaterialName(i));
00075 dlgUI->kineticFrictionTable->setText(i+1,0,w->getMaterialName(i));
00076 }
00077
00078 for (i=0;i<w->getNumMaterials();i++) {
00079 for (j=0;j<w->getNumMaterials();j++) {
00080 dlgUI->staticFrictionTable->setText(i+1,j+1,val.setNum(w->getCOF(i,j)));
00081 dlgUI->kineticFrictionTable->setText(i+1,j+1,val.setNum(w->getKCOF(i,j)));
00082 }
00083 }
00084
00085 dlgUI->timeStepLine->setText(QString::number(w->getTimeStep() * 1.0e+3));
00086 dlgUI->timeStepLine->setValidator(new QDoubleValidator(1.0e-2,1.0e+4,10,dlgImpl));
00087
00088 QObject::connect(dlgUI->staticFrictionTable, SIGNAL(currentChanged(int,int)),
00089 this, SLOT(saveCurrentCOF(int,int)) );
00090 QObject::connect(dlgUI->kineticFrictionTable, SIGNAL(currentChanged(int,int)),
00091 this, SLOT(saveCurrentKCOF(int,int)) );
00092
00093 QObject::connect(dlgUI->staticFrictionTable, SIGNAL(valueChanged(int,int)),
00094 this, SLOT(checkCOFEntry(int,int)) );
00095 QObject::connect(dlgUI->kineticFrictionTable, SIGNAL(valueChanged(int,int)),
00096 this, SLOT(checkKCOFEntry(int,int)) );
00097
00098 QObject::connect(dlgUI->okButton, SIGNAL(clicked()), this, SLOT(validateDlg()) );
00099
00100 }
00101
00102 SettingsDlg::~SettingsDlg()
00103 {
00104 delete dlgImpl;
00105 delete dlgUI;
00106 }
00107
00115 void SettingsDlg::checkCOFEntry( int row, int col )
00116 {
00117 double val;
00118 bool ok;
00119
00120 if (row>0 && col>0) {
00121 val = dlgUI->staticFrictionTable->text(row,col).toDouble(&ok);
00122 if (!ok || val < 0) {
00123 dlgUI->staticFrictionTable->setText(row,col,QString::number(currCOFVal));
00124 return;
00125 }
00126 }
00127 else {
00128 dlgUI->kineticFrictionTable->setText(row,col,dlgUI->staticFrictionTable->text(row,col));
00129 dlgUI->kineticFrictionTable->setText(col,row,dlgUI->staticFrictionTable->text(row,col));
00130 }
00131 dlgUI->staticFrictionTable->setText(col,row,dlgUI->staticFrictionTable->text(row,col));
00132 }
00133
00134
00140 void SettingsDlg::saveCurrentCOF( int row, int col )
00141 {
00142 currCOFVal = dlgUI->staticFrictionTable->text(row,col).toDouble();
00143 }
00144
00150 void SettingsDlg::saveCurrentKCOF( int row, int col )
00151 {
00152 currKCOFVal = dlgUI->kineticFrictionTable->text(row,col).toDouble();
00153 }
00154
00155
00163 void SettingsDlg::checkKCOFEntry( int row, int col )
00164 {
00165 double val;
00166 bool ok;
00167 if (row>0 && col>0) {
00168 val = dlgUI->kineticFrictionTable->text(row,col).toDouble(&ok);
00169 if (!ok || val < 0) {
00170 dlgUI->kineticFrictionTable->setText(row,col,QString::number(currKCOFVal));
00171 return;
00172 }
00173 }
00174 else {
00175 dlgUI->staticFrictionTable->setText(row,col,dlgUI->kineticFrictionTable->text(row,col));
00176 dlgUI->staticFrictionTable->setText(col,row,dlgUI->kineticFrictionTable->text(row,col));
00177 }
00178 dlgUI->kineticFrictionTable->setText(col,row,dlgUI->kineticFrictionTable->text(row,col));
00179 }
00180
00181
00188 void SettingsDlg::validateDlg()
00189 {
00190 int zero=0;
00191 QString tst = dlgUI->timeStepLine->text();
00192 QString msg;
00193 QDoubleValidator *tsv = (QDoubleValidator *)dlgUI->timeStepLine->validator();
00194
00195 if (tsv->validate(tst,zero) != QValidator::Acceptable) {
00196 msg = QString("Dynamic time step must be between %1 and %2").arg(tsv->bottom()).arg(tsv->top());
00197 }
00198
00199 if (!msg.isEmpty()) {
00200 QMessageBox::warning(NULL,"GraspIt!",msg,QMessageBox::Ok, Qt::NoButton,Qt::NoButton);
00201 } else {
00202 dlgImpl->accept();
00203 }
00204 }