00001 //###################################################################### 00002 // 00003 // GraspIt! 00004 // Copyright (C) 2002-2009 Columbia University in the City of New York. 00005 // All rights reserved. 00006 // 00007 // GraspIt! is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // GraspIt! is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GraspIt!. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // Author(s): Andrew T. Miller 00021 // 00022 // $Id: 00023 // 00024 //###################################################################### 00025 00026 #include <QHBoxLayout> 00027 #include "qmDlg.h" 00028 #include "graspitGUI.h" 00029 #include "ivmgr.h" 00030 #include "grasp.h" 00031 #include "list" 00032 #include "world.h" 00033 #include "robot.h" 00034 00035 //#define GRASPITDBG 00036 #include "debug.h" 00037 00045 void QMDlg::init() 00046 { 00047 std::list<QualityMeasure *>::iterator qp; 00048 Grasp *g = graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp(); 00049 int i; 00050 00051 qmListBox->insertItem("New quality measure"); 00052 for (qp=g->qmList.begin(),i=1;qp!=g->qmList.end();qp++,i++) 00053 qmListBox->insertItem((*qp)->getName()); 00054 00055 for (i=0;QualityMeasure::TYPE_LIST[i];i++) 00056 qmTypeComboBox->insertItem(QString(QualityMeasure::TYPE_LIST[i])); 00057 00058 qmSettingsBox->setColumnLayout(0, Qt::Vertical ); 00059 QHBoxLayout *settingsBoxLayout = new QHBoxLayout(qmSettingsBox->layout()); 00060 settingsBoxLayout->setAlignment( Qt::AlignTop ); 00061 00062 qmDlgData.settingsArea = new QWidget(qmSettingsBox); 00063 settingsBoxLayout->addWidget(qmDlgData.settingsArea); 00064 00065 qmDlgData.grasp = g; 00066 qmDlgData.qmTypeComboBox = qmTypeComboBox; 00067 qmDlgData.qmName = qmName; 00068 gravityBox->setChecked( g->isGravitySet() ); 00069 00070 qmListBox->setCurrentItem(0); 00071 } 00072 00073 00077 void QMDlg::selectQMType(const QString &typeStr) 00078 { 00079 qmDlgData.qmType = typeStr.latin1(); 00080 updateSettingsBox(); 00081 } 00082 00088 void QMDlg::updateSettingsBox() 00089 { 00090 delete qmDlgData.settingsArea; 00091 00092 qmDlgData.settingsArea = new QWidget(qmSettingsBox); 00093 qmSettingsBox->layout()->setAlignment(Qt::AlignTop); 00094 qmSettingsBox->layout()->add(qmDlgData.settingsArea); 00095 QualityMeasure::buildParamArea(&qmDlgData); 00096 00097 qmDlgData.settingsArea->show(); 00098 } 00099 00106 void QMDlg::addEditQM() 00107 { 00108 Grasp *g = graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp(); 00109 QualityMeasure *newQM; 00110 int selectedQM; 00111 00112 newQM = QualityMeasure::createInstance(&qmDlgData); 00113 00114 selectedQM = qmListBox->currentItem(); 00115 if (selectedQM == 0) { // create a new quality measure 00116 g->addQM(newQM); 00117 00118 qmListBox->insertItem(qmName->text()); 00119 } 00120 else { // replace an old quality measure with a new one 00121 g->replaceQM(selectedQM-1,newQM); 00122 qmListBox->changeItem(qmName->text(),selectedQM); 00123 } 00124 00125 qmListBox->setCurrentItem(0); 00126 qmListBox->update(); 00127 qmListBox->show(); 00128 00129 } 00130 00135 void QMDlg::deleteQM() 00136 { 00137 int selectedQM; 00138 int numItems; 00139 00140 selectedQM = qmListBox->currentItem(); 00141 graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp()-> 00142 removeQM(selectedQM-1); 00143 qmListBox->removeItem(selectedQM); 00144 00145 // select the next item in the list 00146 numItems = qmListBox->count(); 00147 qmListBox->setCurrentItem(selectedQM < numItems ? selectedQM : 0); 00148 qmListBox->update(); 00149 } 00150 00158 void QMDlg::selectQM( int which) 00159 { 00160 if (which==0) { // "New quality measure" selected 00161 qmDlgData.currQM = NULL; 00162 qmDlgData.qmType = QualityMeasure::TYPE_LIST[0]; 00163 qmTypeComboBox->setCurrentItem(0); 00164 DeleteButton->setEnabled(false); 00165 qmName->setText(QString("New Quality Measure")); 00166 } 00167 else { 00168 DeleteButton->setEnabled(true); 00169 Grasp *g = graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp(); 00170 qmDlgData.currQM = g->getQM(which-1); 00171 00172 for (int i=0;QualityMeasure::TYPE_LIST[i];i++) { 00173 if (!strcmp(QualityMeasure::TYPE_LIST[i],qmDlgData.currQM->getType())) { 00174 qmTypeComboBox->setCurrentItem(i); 00175 qmDlgData.qmType = QualityMeasure::TYPE_LIST[i]; 00176 break; 00177 } 00178 } 00179 qmName->setText(qmListBox->text(which)); 00180 } 00181 updateSettingsBox(); 00182 } 00183 00184 void QMDlg::gravityBox_clicked() 00185 { 00186 Grasp *g = graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp(); 00187 g->setGravity( gravityBox->isChecked() ); 00188 if ( gravityBox->isChecked() ) { 00189 fprintf(stderr,"Gravity on\n"); 00190 } else { 00191 fprintf(stderr,"Gravity off\n"); 00192 } 00193 // g->updateWrenchSpaces(); 00194 g->update(); 00195 }