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 #include "mainWindow.h"
00027
00028 #include <QDialog>
00029 #include <QStatusBar>
00030
00031 #include <QLineEdit>
00032 #include <QMessageBox>
00033 #include <QApplication>
00034 #include <QComboBox>
00035 #include <QStatusBar>
00036 #include <QTime>
00037 #include <QFileDialog>
00038
00039 #include <list>
00040
00041 #include "defines.h"
00042 #include "mytools.h"
00043 #include "robot.h"
00044 #include "ivmgr.h"
00045 #include "world.h"
00046 #include "body.h"
00047 #include "grasp.h"
00048 #include "gwsprojection.h"
00049 #include "quality.h"
00050 #include "graspitGUI.h"
00051 #include "humanHand.h"
00052
00053
00054
00055 #include "arch.h"
00056
00057 #include "debug.h"
00058
00059 #include "settingsDlg.h"
00060 #include "ui_about.h"
00061 #include "bodyPropDlg.h"
00062 #include "qmDlg.h"
00063 #include "gwsProjDlg.h"
00064 #include "plannerdlg.h"
00065 #include "eigenGraspDlg.h"
00066 #include "compliantPlannerDlg.h"
00067 #include "optimizerDlg.h"
00068 #include "gfoDlg.h"
00069 #include "contactExaminerDlg.h"
00070 #include "egPlannerDlg.h"
00071 #ifdef CGDB_ENABLED
00072 #include "DBase/dbaseDlg.h"
00073 #include "DBase/dbasePlannerDlg.h"
00074 #include "graspit_db_model.h"
00075 #endif
00076 #ifdef ARIZONA_PROJECT_ENABLED
00077 #include "arizona/arizonaProjectDlg.h"
00078 #endif
00079 #ifdef STAUBLI_CONTROL_ENABLED
00080 #include "staubli/staubliControlDlg.h"
00081 #endif
00082 #include "gloveCalibrationDlg.h"
00083 #include "graspCaptureDlg.h"
00084 #include "barrettHandDlg.h"
00085 #include "archBuilderDlg.h"
00086 #ifdef EIGENGRIDS
00087 #include "eigenGridsDlg.h"
00088 #endif
00089 #ifdef HARDWARE_LIB
00090 #include "sensorInputDlg.h"
00091 #endif
00092
00093
00094
00095 MainWindow::MainWindow(QWidget *parent)
00096 {
00097 mWindow = new Q3MainWindow(parent);
00098
00099 mUI = new Ui::MainWindowUI;
00100 mUI->setupUi(mWindow);
00101 init();
00102
00103 QObject::connect(mUI->fileNewAction, SIGNAL(triggered()), this, SLOT(fileNew()));
00104 QObject::connect(mUI->fileOpenAction, SIGNAL(triggered()), this, SLOT(fileOpen()));
00105 QObject::connect(mUI->fileSaveAction, SIGNAL(triggered()), this, SLOT(fileSave()));
00106 QObject::connect(mUI->fileSaveAsAction, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
00107 QObject::connect(mUI->fileImportRobotAction, SIGNAL(triggered()), this, SLOT(fileImportRobot()));
00108 QObject::connect(mUI->fileImportObstacleAction, SIGNAL(triggered()), this, SLOT(fileImportObstacle()));
00109 QObject::connect(mUI->fileImportObjectAction, SIGNAL(triggered()), this, SLOT(fileImportObject()));
00110 QObject::connect(mUI->fileEditSettingsAction, SIGNAL(triggered()), this, SLOT(fileEditSettings()));
00111 QObject::connect(mUI->fileSaveImageAction, SIGNAL(triggered()), this, SLOT(fileSaveImage()));
00112 QObject::connect(mUI->fileExitAction, SIGNAL(triggered()), this, SLOT(fileExit()));
00113
00114 QObject::connect(mUI->helpManualAction, SIGNAL(triggered()), this, SLOT(helpManual()));
00115 QObject::connect(mUI->helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()));
00116 QObject::connect(mUI->helpAboutQTAction, SIGNAL(triggered()), this, SLOT(helpAboutQT()));
00117
00118 QObject::connect(mUI->elementGroup, SIGNAL(selected(QAction*)), this, SLOT(setTool(QAction*)));
00119 QObject::connect(mUI->elementCollisionToggleAction, SIGNAL(activated()),
00120 this, SLOT(elementTurnOffCollisions()));
00121 QObject::connect(mUI->elementCollisionToggleAction, SIGNAL(toggled(bool)),
00122 this, SLOT(updateCollisionAction(bool)));
00123 QObject::connect(mUI->elementBodyPropertiesAction, SIGNAL(activated()),
00124 this, SLOT(elementBodyProperties()));
00125
00126 QObject::connect(mUI->graspAutoGraspAction, SIGNAL(triggered()), this, SLOT(graspAutoGrasp()));
00127 QObject::connect(mUI->graspAuto_OpenAction, SIGNAL(triggered()), this, SLOT(graspAutoOpen()));
00128 QObject::connect(mUI->graspQualityMeasuresAction, SIGNAL(triggered()), this, SLOT(graspQualityMeasures()));
00129 QObject::connect(mUI->graspCreateProjectionAction, SIGNAL(triggered()), this, SLOT(graspCreateProjection()));
00130 QObject::connect(mUI->graspPlannerAction, SIGNAL(triggered()), this, SLOT(graspPlanner()));
00131 QObject::connect(mUI->graspGFOAction, SIGNAL(triggered()), this, SLOT(graspForceOptimization()));
00132
00133 QObject::connect(mUI->graspEigenGrasp_InterfaceAction, SIGNAL(triggered()),
00134 this, SLOT(eigenGraspActivated()));
00135 QObject::connect(mUI->graspContact_ExaminerAction, SIGNAL(triggered()),
00136 this, SLOT(graspContactExaminer_activated()));
00137 QObject::connect(mUI->graspEigenGrasp_PlannerAction, SIGNAL(triggered()),
00138 this, SLOT(eigenGraspPlannerActivated()));
00139
00140 QObject::connect(mUI->dbaseGUIAction, SIGNAL(triggered()),
00141 this, SLOT(dbaseGUIAction_activated()));
00142 QObject::connect(mUI->dbasePlannerAction, SIGNAL(triggered()),
00143 this, SLOT(dbasePlannerAction_activated()));
00144 QObject::connect(mUI->dbaseGraspCaptureAction, SIGNAL(triggered()),
00145 this, SLOT(graspCapture()));
00146
00147 QObject::connect(mUI->sensorsSensor_InputAction, SIGNAL(triggered()),
00148 this, SLOT(sensorsSensor_InputAction_activated()));
00149 QObject::connect(mUI->sensorsBarrett_HandAction, SIGNAL(triggered()),
00150 this, SLOT(sensorsBarrettHandAction()));
00151
00152 QObject::connect(mUI->stereoOnAction, SIGNAL(triggered()), this, SLOT(stereoOn()));
00153 QObject::connect(mUI->stereoOffAction, SIGNAL(triggered()), this, SLOT(stereoOff()));
00154 QObject::connect(mUI->stereoFlip_leftrightAction, SIGNAL(triggered()), this, SLOT(stereoFlip()));
00155
00156 QObject::connect(mUI->dynamicsArch_BuilderAction, SIGNAL(triggered()), this, SLOT(archBuilder()));
00157 QObject::connect(mUI->miscOptimizerAction, SIGNAL(triggered()), this, SLOT(miscOptimizer()));
00158 QObject::connect(mUI->actionArizona_Project, SIGNAL(triggered()),
00159 this, SLOT(miscArizonaProjectDlg_activated()));
00160 QObject::connect(mUI->staubliControl, SIGNAL(triggered()),
00161 this, SLOT(misStaubliControlDlg()));
00162 QObject::connect(mUI->miscEigengridsAction, SIGNAL(triggered()), this, SLOT(miscEigengridsAction_activated()));
00163
00164 QObject::connect(mUI->contactsListBox, SIGNAL(highlighted(int)), this, SLOT(contactSelected(int)));
00165
00166 QObject::connect(mUI->dynamicsPlayAction, SIGNAL(activated()), this, SLOT(toggleDynamics()));
00167 QObject::connect(mUI->dynamicsPopAction, SIGNAL(activated()), this, SLOT(dynamicsPopState()));
00168 QObject::connect(mUI->dynamicsPushAction, SIGNAL(activated()), this, SLOT(dynamicsPushState()));
00169
00170 QObject::connect(mUI->materialComboBox, SIGNAL(activated(int)), this, SLOT(materialSelected(int)));
00171 QObject::connect(mUI->graspedBodyBox, SIGNAL(activated(int)), this, SLOT(selectGraspedBody(int)));
00172 QObject::connect(mUI->handSelectionBox, SIGNAL(activated(int)), this, SLOT(setCurrentHand(int)));
00173
00174 QObject::connect(mUI->TendonForceInput, SIGNAL(valueChanged(int)), this, SLOT(TendonForceInput_valueChanged(int)));
00175 QObject::connect(mUI->tendonNamesBox, SIGNAL(activated(int)), this, SLOT(tendonNamesBoxActivated(int)));
00176 QObject::connect(mUI->tendonVisibleCheckBox, SIGNAL(toggled(bool)), this, SLOT(tendonVisibleCheckBox_toggled(bool)));
00177 QObject::connect(mUI->forcesVisibleCheckBox, SIGNAL(toggled(bool)), this, SLOT(forcesVisibleCheckBox_toggled(bool)));}
00178
00183 void MainWindow::init()
00184 {
00185 world = NULL;
00186 mUI->timeReadout->display("00:00.000");
00187 mWindow->statusBar()->message("Ready",2000);
00188 QIcon playIconSet = mUI->dynamicsPlayAction->iconSet();
00189 playIconSet.setPixmap(load_pixmap( "pause.xpm" ),QIcon::Automatic,QIcon::Normal,QIcon::On);
00190 mUI->dynamicsPlayAction->setIconSet(playIconSet);
00191
00192 QIcon collisionIconSet = mUI->elementCollisionToggleAction->iconSet();
00193 collisionIconSet.setPixmap(load_pixmap("nocollide.xpm"),QIcon::Automatic,QIcon::Normal,QIcon::On);
00194 mUI->elementCollisionToggleAction->setIconSet(collisionIconSet);
00195 }
00196
00200 void MainWindow::destroy()
00201 {
00202 }
00203
00204 void MainWindow::destroyChildren()
00205 {
00206
00207
00208 }
00209
00214 void MainWindow::setMainWorld( World *w )
00215 {
00216 world = w;
00217 QObject::connect(world,SIGNAL(dynamicStepTaken()),this,SLOT(updateTimeReadout()));
00218 QObject::connect(world,SIGNAL(dynamicStepTaken()),graspItGUI->getIVmgr(),SLOT(drawDynamicForces()));
00219 QObject::connect(world,SIGNAL(dynamicsError(const char *)),this,SLOT(showDynamicsError(const char *)));
00220 QObject::connect(world,SIGNAL(selectionsChanged()),this,SLOT(updateElementMenu()));
00221 QObject::connect(world,SIGNAL(selectionsChanged()),this,SLOT(updateMaterialBox()));
00222 QObject::connect(world,SIGNAL(numElementsChanged()),this,SLOT(updateGraspBoxes()));
00223 QObject::connect(world,SIGNAL(numElementsChanged()),this,SLOT(updateGraspMenu()));
00224
00225 QObject::connect(world,SIGNAL(numElementsChanged()),this,SLOT(updateQualityList()));
00226 QObject::connect(world,SIGNAL(tendonSelectionChanged()),this,SLOT(handleTendonSelectionArea()));
00227 QObject::connect(world,SIGNAL(tendonDetailsChanged()),this,SLOT(handleTendonDetailsArea()));
00228 QObject::connect(world,SIGNAL(handSelectionChanged()),this,SLOT(handleHandSelectionChange()));
00229 QObject::connect(world,SIGNAL(graspsUpdated()),this,SLOT(updateQualityList()));
00230 QObject::connect(world,SIGNAL(graspsUpdated()),graspItGUI->getIVmgr(),SLOT(drawWorstCaseWrenches()));
00231 QObject::connect(world,SIGNAL(handRemoved()),this,SLOT(updateQualityList()));
00232 updateTimeReadout();
00233 updateMaterialBoxList();
00234 updateGraspBoxes();
00235 updateQualityList();
00236 updateElementMenu();
00237 updateGraspMenu();
00238 updateTendonNamesBox();
00239 handleTendonSelectionArea();
00240
00241 #ifdef EIGENGRIDS
00242 mUI->miscEigengridsAction->setEnabled(TRUE);
00243 #else
00244 mUI->miscEigengridsAction->setEnabled(FALSE);
00245 #endif
00246
00247 #ifdef HARDWARE_LIB
00248 mUI->sensorsSensor_InputAction->setEnabled(TRUE);
00249 #else
00250 mUI->sensorsSensor_InputAction->setEnabled(FALSE);
00251 #endif
00252
00253 }
00254
00255
00256
00262 void MainWindow::fileNew()
00263 {
00264 if ( saveAndContinue( "New" ) ) {
00265 graspItGUI->getIVmgr()->emptyWorld();
00266 setMainWorld(graspItGUI->getIVmgr()->getWorld());
00267 mUI->worldBox->setTitle("Untitled");
00268 }
00269 }
00270
00277 void MainWindow::fileOpen()
00278 {
00279 if ( !saveAndContinue( "Open" ) ) {
00280 return;
00281 }
00282 QString fn( QFileDialog::getOpenFileName(mWindow, QString(), QString(getenv("GRASPIT"))+QString("/worlds"),
00283 "GraspIt World Files (*.xml)") );
00284 if ( fn.isEmpty() ) {
00285 return;
00286 }
00287 fileName = fn;
00288 mUI->worldBox->setTitle(fileName);
00289 graspItGUI->getIVmgr()->emptyWorld();
00290 graspItGUI->getIVmgr()->getWorld()->load(fileName);
00291
00292 setMainWorld(graspItGUI->getIVmgr()->getWorld());
00293 }
00294
00299 void MainWindow::fileSave()
00300 {
00301 if ( fileName.isEmpty() ) {
00302 fileSaveAs();
00303 } else {
00304 graspItGUI->getIVmgr()->getWorld()->save(fileName);
00305 }
00306 }
00307
00313 void MainWindow::fileSaveAs()
00314 {
00315 QString fn = QFileDialog::getSaveFileName(mWindow, QString(), QString(getenv("GRASPIT"))+QString("/worlds"),
00316 "GraspIt World Files (*.xml)" );
00317 if ( !fn.isEmpty() ) {
00318 fileName = fn;
00319 if (fileName.section('.',1).isEmpty()) {
00320 fileName.append(".xml");
00321 }
00322 fileSave();
00323 mUI->worldBox->setTitle(fileName);
00324 }
00325 }
00326
00332 void MainWindow::fileImportRobot()
00333 {
00334 QString dir = QString(getenv("GRASPIT"))+QString("/models/robots");
00335 QString fn( QFileDialog::getOpenFileName(mWindow, QString(), dir, "XML GraspIt Robot Files (*.xml)") );
00336 if ( !fn.isEmpty() ) {
00337 world->importRobot(fn);
00338 }
00339 }
00340
00348 void MainWindow::fileImportObstacle()
00349 {
00350 QString fn( QFileDialog::getOpenFileName(mWindow, QString(),
00351 QString(getenv("GRASPIT"))+QString("/models/obstacles"),
00352 "Graspit XML Files (*.xml*);;IV files (*.iv);;WRL files (*.wrl);;OFF files (*.off);;PLY files (*.ply)" ) );
00353 if ( !fn.isEmpty() ) world->importBody("Body",fn);
00354 }
00355
00363 void MainWindow::fileImportObject()
00364 {
00365 QString fn( QFileDialog::getOpenFileName(mWindow, QString(),
00366 QString(getenv("GRASPIT"))+QString("/models/objects"),
00367 "Graspit XML Files (*.xml*);;IV files (*.iv);;WRL files (*.wrl);;OFF files (*.off);;PLY files (*.ply)" ) );
00368
00369 if ( !fn.isEmpty() ) world->importBody("GraspableBody",fn);
00370 }
00371
00377 void MainWindow::fileExit()
00378 {
00379 if ( saveAndContinue( "Exit" ) )
00380
00381 graspItGUI->exitMainLoop();
00382 }
00383
00391 int MainWindow::saveAndContinue(const QString & action)
00392 {
00393 int continueAction = 1;
00394
00395 if (world->wasModified()) {
00396 switch( QMessageBox::information(
00397 mWindow, "GraspIt!",
00398 "The document contains unsaved changes.\n"
00399 "Do you want to save the changes?",
00400 "&Save", "&Don't Save", "&Cancel " + action,
00401 0,
00402 2 ) ) {
00403 case 0:
00404 fileSave();
00405 break;
00406 case 1:
00407 break;
00408 case 2:
00409 continueAction = 0;
00410 break;
00411 }
00412 }
00413
00414 return continueAction;
00415 }
00416
00424 void MainWindow::fileEditSettings()
00425 {
00426 int i,j;
00427 SettingsDlg *dlg = new SettingsDlg(mWindow);
00428 dlg->setAttribute(Qt::WA_ShowModal, true);
00429
00430 if ( dlg->exec() == QDialog::Accepted) {
00431
00432 for (i=0;i<dlg->dlgUI->staticFrictionTable->numRows()-1;i++) {
00433 world->materialNames[i] = dlg->dlgUI->staticFrictionTable->text(i+1,0);
00434
00435 for (j=0;j<dlg->dlgUI->staticFrictionTable->numCols()-1;j++) {
00436 world->cofTable[i][j] = dlg->dlgUI->staticFrictionTable->text(i+1,j+1).toDouble();
00437 world->kcofTable[i][j] = dlg->dlgUI->kineticFrictionTable->text(i+1,j+1).toDouble();
00438 }
00439 }
00440 world->dynamicsTimeStep = dlg->dlgUI->timeStepLine->text().toDouble()*1.0e-3;
00441 updateMaterialBoxList();
00442
00443
00444 for (i=0;i<world->getNumBodies();i++) {
00445 world->getBody(i)->setMaterial(world->getBody(i)->getMaterial());
00446 }
00447 world->updateGrasps();
00448 }
00449 delete dlg;
00450 }
00451
00459 void MainWindow::fileSaveImage()
00460 {
00461 QString fn = QFileDialog::getSaveFileName( mWindow, QString(), QString(getenv("GRASPIT"))+QString("/images"),
00462 "Image Files (*.jpg)" );
00463 if ( !fn.isEmpty() ) {
00464 if (fn.section('.',-1)!="jpg") fn.append(".jpg");
00465 graspItGUI->getIVmgr()->saveImage(fn);
00466 }
00467 }
00468
00469
00470
00474 void MainWindow::helpManual()
00475 {
00476 QMessageBox::warning(NULL,"GraspIt!","You can find the GraspIt! User Manual in $GRASPIT/doc, " \
00477 "or online at http://www.cs.columbia.edu/~cmatei/graspit/",
00478 QMessageBox::Ok, Qt::NoButton,Qt::NoButton);
00479 }
00480
00485 void MainWindow::helpAbout()
00486 {
00487 Ui::AboutDlg dlgUI;
00488 QDialog dlgImpl(mWindow);
00489 dlgUI.setupUi(&dlgImpl);
00490 QString versionText("Version ");
00491 dlgUI.versionLabel->setText( versionText + GRASPIT_VERSION);
00492 dlgImpl.exec();
00493 }
00494
00495 void MainWindow::helpAboutQT()
00496 {
00497 QMessageBox::aboutQt(mWindow,"GraspIt!");
00498 }
00499
00500
00501
00505 void MainWindow::setTool( QAction *a )
00506 {
00507 if (a==mUI->translateToolAction) graspItGUI->getIVmgr()->setTool(TRANSLATE_TOOL);
00508 else if (a==mUI->rotateToolAction) graspItGUI->getIVmgr()->setTool(ROTATE_TOOL);
00509 else if (a==mUI->selectToolAction) graspItGUI->getIVmgr()->setTool(SELECT_TOOL);
00510 }
00511
00515 void MainWindow::elementTurnOffCollisions()
00516 {
00517 world->toggleAllCollisions(!mUI->elementCollisionToggleAction->isOn());
00518 }
00519
00525 void MainWindow::elementBodyProperties()
00526 {
00527 BodyPropDlg *dlg = new BodyPropDlg(mWindow);
00528 dlg->setAttribute(Qt::WA_ShowModal, true);
00529 if ( dlg->exec() == QDialog::Accepted) {
00530 world->updateGrasps();
00531 }
00532 delete dlg;
00533 }
00534
00535 void MainWindow::elementPrimitives()
00536 {
00537 #ifdef GEOMETRY_LIB
00538
00539
00540
00541
00542
00543
00544
00545 #endif
00546 }
00547
00553 void MainWindow::updateElementMenu()
00554 {
00555 bool collisionsOFF;
00556 std::list<WorldElement *> selectedElementList;
00557 std::list<WorldElement *>::iterator ep;
00558
00559 if (world->getNumSelectedElements()==0)
00560 mUI->elementBodyPropertiesAction->setEnabled(false);
00561 else
00562 mUI->elementBodyPropertiesAction->setEnabled(true);
00563
00564 #ifdef GEOMETRY_LIB
00565 if (world->getNumSelectedBodies()==1)
00566 elementPrimitivesAction->setEnabled(true);
00567 else
00568 elementPrimitivesAction->setEnabled(false);
00569 #endif
00570
00571 if (world->getNumSelectedElements()==0)
00572 collisionsOFF = world->collisionsAreOff();
00573
00574 else if (world->getNumSelectedElements()==2)
00575 collisionsOFF = world->collisionsAreOff(world->getSelectedElementList().front(),
00576 world->getSelectedElementList().back());
00577 else {
00578 collisionsOFF = true;
00579 selectedElementList = world->getSelectedElementList();
00580 for (ep=selectedElementList.begin();ep!=selectedElementList.end();ep++)
00581 if (!world->collisionsAreOff(*ep)) {
00582 collisionsOFF= false;
00583 break;
00584 }
00585 }
00586 mUI->elementCollisionToggleAction->setOn(collisionsOFF);
00587
00588 }
00589
00590
00591
00595 void MainWindow::updateGraspMenu()
00596 {
00597 bool handFound = (world->getCurrentHand() !=NULL);
00598 bool bodyFound = (world->getNumBodies() != 0);
00599 mUI->graspAutoGraspAction->setEnabled(handFound);
00600 mUI->graspAuto_OpenAction->setEnabled(handFound);
00601 mUI->graspCreateProjectionAction->setEnabled(handFound);
00602 mUI->graspQualityMeasuresAction->setEnabled(handFound);
00603 mUI->graspPlannerAction->setEnabled(handFound);
00604 mUI->graspGFOAction->setEnabled(handFound);
00605 mUI->graspEigenGrasp_InterfaceAction->setEnabled(handFound);
00606 mUI->graspContact_ExaminerAction->setEnabled(bodyFound);
00607 mUI->graspEigenGrasp_PlannerAction->setEnabled(handFound);
00608 mUI->graspCompliantPlannerAction->setEnabled(handFound);
00609 #ifdef CGDB_ENABLED
00610 mUI->dbaseGUIAction->setEnabled(handFound);
00611 mUI->dbasePlannerAction->setEnabled(handFound);
00612 #else
00613 mUI->dbaseGUIAction->setEnabled(false);
00614 mUI->dbasePlannerAction->setEnabled(false);
00615 #endif
00616
00617 #ifdef ARIZONA_PROJECT_ENABLED
00618 mUI->actionArizona_Project->setEnabled(true);
00619 #else
00620 mUI->actionArizona_Project->setEnabled(false);
00621 #endif
00622
00623 mUI->dbaseGraspCaptureAction->setEnabled(handFound);
00624 mUI->sensorsBarrett_HandAction->setEnabled(handFound);
00625 }
00626
00633 void MainWindow::graspCreateProjection(Grasp *g)
00634 {
00635 GWSProjDlg *dlg = new GWSProjDlg(mWindow);
00636 if ( dlg->exec() == QDialog::Accepted ) {
00637 Grasp *grasp;
00638 if(!g)
00639 grasp = world->getCurrentHand()->getGrasp();
00640 else
00641 grasp = g;
00642 GWS *gws = grasp->addGWS(dlg->gwsTypeComboBox->currentText().latin1());
00643
00644 double w[6];
00645 w[0] = dlg->fxCoord->text().toDouble();
00646 w[1] = dlg->fyCoord->text().toDouble();
00647 w[2] = dlg->fzCoord->text().toDouble();
00648 w[3] = dlg->txCoord->text().toDouble();
00649 w[4] = dlg->tyCoord->text().toDouble();
00650 w[5] = dlg->tzCoord->text().toDouble();
00651
00652 GWSprojection *gp = new GWSprojection(graspItGUI->getIVmgr()->getViewer(),gws,w,dlg->whichFixed);
00653 grasp->addProjection(gp);
00654 }
00655 delete dlg;
00656 }
00657
00663 void MainWindow::graspQualityMeasures()
00664 {
00665 QMDlg *dlg = new QMDlg(mWindow);
00666 dlg->setAttribute(Qt::WA_ShowModal, true);
00667 if ( dlg->exec() == QDialog::Accepted ) {
00668 Grasp *g = world->getCurrentHand()->getGrasp();
00669 if (g->getNumQM()) {
00670 connect(g,SIGNAL(graspUpdated()),this,SLOT(updateQualityList()));
00671 } else {
00672 disconnect(g,SIGNAL(graspUpdated()),this,SLOT(updateQualityList()));
00673 }
00674 }
00675 world->getCurrentHand()->setContactsChanged();
00676 world->updateGrasps();
00677 delete dlg;
00678 }
00679
00686 void MainWindow::graspPlanner()
00687 {
00688 if (!world->getCurrentHand()->getName().contains("Barrett")) {
00689 QMessageBox::warning(NULL,"GraspIt!",
00690 "The planner currently only works with the Barrett hand.",
00691 QMessageBox::Ok, Qt::NoButton,Qt::NoButton);
00692 return;
00693 }
00694 PlannerDlg *dlg =new PlannerDlg(mWindow);
00695 dlg->setAttribute(Qt::WA_ShowModal, false);
00696 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00697 dlg->show();
00698 }
00699
00700 void
00701 MainWindow::graspForceOptimization()
00702 {
00703 if (!world->getCurrentHand()) {
00704 DBGA("No hand selected");
00705 return;
00706 }
00707 GFODlg *dlg = new GFODlg(this, world->getCurrentHand(), mWindow);
00708 dlg->setAttribute(Qt::WA_ShowModal, false);
00709 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00710 dlg->show();
00711 }
00712
00717 void MainWindow::graspCompliantPlanner()
00718 {
00719 int gb = mUI->graspedBodyBox->currentItem();
00720 if ( gb < 0 || world->getNumGB() < gb+1 ) {
00721 fprintf(stderr,"No object selected\n");
00722 return;
00723 }
00724 CompliantPlannerDlg *dlg =new CompliantPlannerDlg(world->getCurrentHand(),
00725 world->getGB(gb), mWindow);
00726 dlg->setAttribute(Qt::WA_ShowModal, false);
00727 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00728 dlg->show();
00729 }
00734 void MainWindow::graspAutoGrasp()
00735 {
00736 world->getCurrentHand()->autoGrasp(true);
00737 world->updateGrasps();
00738 }
00739
00744 void MainWindow::graspAutoOpen()
00745 {
00746 world->getCurrentHand()->autoGrasp(true,-1.0);
00747 world->updateGrasps();
00748 }
00749
00750 void MainWindow::eigenGraspActivated()
00751 {
00752 EigenGraspDlg *dlg = new EigenGraspDlg(mWindow);
00753 dlg->setAttribute(Qt::WA_ShowModal, false);
00754 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00755
00756 if (!dlg->setWorld(world) ) {
00757 delete dlg;
00758 return;
00759 }
00760 dlg->show();
00761 }
00762
00763 void MainWindow::graspContactExaminer_activated()
00764 {
00765 ContactExaminerDlg *dlg = new ContactExaminerDlg(mWindow);
00766 dlg->setAttribute(Qt::WA_ShowModal, false);
00767 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00768 dlg->show();
00769 }
00770
00771 void MainWindow::eigenGraspPlannerActivated()
00772 {
00773 assert(world->getCurrentHand());
00774 if (world->getCurrentHand()->getEigenGrasps() == NULL) {
00775 fprintf(stderr,"Current hand has no EigenGrasp information!\n");
00776 return;
00777 }
00778 int gb = mUI->graspedBodyBox->currentItem();
00779 if ( gb < 0 || world->getNumGB() < gb+1 ) {
00780 fprintf(stderr,"No object selected\n");
00781 return;
00782 }
00783
00784 EigenGraspPlannerDlg *dlg = new EigenGraspPlannerDlg(mWindow);
00785 dlg->setMembers(world->getCurrentHand(), world->getGB(gb));
00786 dlg->setAttribute(Qt::WA_ShowModal, false);
00787 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00788 dlg->show();
00789 }
00790
00791 void MainWindow::dbaseGUIAction_activated()
00792 {
00793 #ifdef CGDB_ENABLED
00794 DBaseDlg *dlg = new DBaseDlg(mWindow);
00795 dlg->setAttribute(Qt::WA_ShowModal, false);
00796 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00797 dlg->show();
00798 #endif
00799 }
00800
00801 void MainWindow::dbasePlannerAction_activated()
00802 {
00803 #ifdef CGDB_ENABLED
00804 if (!world->getCurrentHand()) {
00805 QTWARNING("No hand selected");
00806 return;
00807 }
00808 int gb = mUI->graspedBodyBox->currentItem();
00809 if ( gb < 0 || world->getNumGB() < gb+1 ) {
00810 QTWARNING("No object selected");
00811 return;
00812 }
00813 if (!graspItGUI->getIVmgr()->getDBMgr()) {
00814 QTWARNING("Connection to database not established. Connect to database first.");
00815 return;
00816 }
00817 if (!world->getGB(gb)->getDBModel()) {
00818 QTWARNING("DBase Planner currently works only with models loaded from the database");
00819 return;
00820 }
00821 DBasePlannerDlg *dlg = new DBasePlannerDlg(mWindow, graspItGUI->getIVmgr()->getDBMgr(),
00822 world->getGB(gb)->getDBModel(), world->getCurrentHand());
00823 dlg->setAttribute(Qt::WA_ShowModal, false);
00824 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00825 dlg->show();
00826 #endif
00827 }
00828
00829
00830 void MainWindow::miscArizonaProjectDlg_activated()
00831 {
00832 #ifdef ARIZONA_PROJECT_ENABLED
00833 ArizonaProjectDlg *dlg = new ArizonaProjectDlg(mWindow);
00834 dlg->setAttribute(Qt::WA_ShowModal, false);
00835 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00836 dlg->show();
00837 #endif
00838 }
00839
00840 void MainWindow::misStaubliControlDlg()
00841 {
00842 #ifdef STAUBLI_CONTROL_ENABLED
00843 StaubliControlDlg *dlg = new StaubliControlDlg(mWindow);
00844 dlg->setAttribute(Qt::WA_ShowModal, false);
00845 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00846 dlg->show();
00847 #endif
00848 }
00849
00850
00851 void MainWindow::sensorsSensor_InputAction_activated()
00852 {
00853 #ifdef HARDWARE_LIB
00854 SensorInputDlg *dlg = new SensorInputDlg(world, mWindow);
00855 dlg->setAttribute(Qt::WA_ShowModal, false);
00856 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00857 dlg->show();
00858 #endif
00859 }
00860
00861 void MainWindow::graspCapture()
00862 {
00863 GraspCaptureDlg *dlg = new GraspCaptureDlg(world,mWindow);
00864 dlg->setAttribute(Qt::WA_ShowModal, false);
00865 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00866
00867 dlg->show();
00868 }
00869
00870 void MainWindow::sensorsBarrettHandAction()
00871 {
00872
00873 #ifdef HARDWARE_LIB
00874 BarrettHandDlg *dlg = new BarrettHandDlg(mWindow);
00875 dlg->setAttribute(Qt::WA_ShowModal, false);
00876 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00877 if (dlg->setWorld(world)) {
00878 dlg->show();
00879 } else {
00880 delete dlg;
00881 return;
00882 }
00883 #endif
00884
00885 }
00886
00887
00888
00889 void MainWindow::stereoOn()
00890 {
00891 DBGA("Stereo on");
00892
00893 mUI->worldBox->setTitle(NULL);
00894 mUI->contactsGroupBox->hide();
00895 mUI->qualityGroupBox->hide();
00896
00897 mUI->toolBar->hide();
00898 mUI->Toolbar_2->hide();
00899 mUI->ToolbarDynamics->hide();
00900 mUI->graspToolbar->hide();
00901 mUI->tendonToolbar->hide();
00902
00903 mWindow->menuBar()->hide();
00904 graspItGUI->getIVmgr()->getViewer()->setDecoration(false);
00905 mWindow->showFullScreen();
00906
00907 graspItGUI->getIVmgr()->setStereo(true);
00908
00909
00910
00911
00912
00913
00914 }
00915
00916 void MainWindow::stereoOff()
00917 {
00918 mUI->contactsGroupBox->show();
00919 mUI->qualityGroupBox->show();
00920
00921 mUI->toolBar->show();
00922 mUI->Toolbar_2->show();
00923 mUI->ToolbarDynamics->show();
00924 mUI->graspToolbar->show();
00925 mUI->tendonToolbar->show();
00926
00927 mWindow->menuBar()->show();
00928 DBGA("Stereo off");
00929 graspItGUI->getIVmgr()->getViewer()->setDecoration(true);
00930 mWindow->showNormal();
00931 graspItGUI->getIVmgr()->setStereo(false);
00932 }
00933
00934 void MainWindow::stereoFlip()
00935 {
00936 DBGA("Stereo flip");
00937 graspItGUI->getIVmgr()->flipStereo();
00938 }
00939
00940
00941
00942 void MainWindow::archBuilder()
00943 {
00944 ArchBuilderDlg dlg(mWindow);
00945
00946 if ( dlg.exec() != QDialog::Accepted) {
00947 return;
00948 }
00949
00950 double innerRadius = dlg.innerRadiusEdit->text().toDouble();
00951 double outerRadius = dlg.outerRadiusEdit->text().toDouble();
00952 double thickness = dlg.thicknessEdit->text().toDouble();
00953 int nBlocks = dlg.numberBlocksBox->value();
00954 if (innerRadius <= 0 || outerRadius <= 0 || thickness <= 0 || nBlocks <= 1) {
00955 QMessageBox::warning(mWindow,"Error","Invalid parameters",
00956 QMessageBox::Ok,Qt::NoButton,Qt::NoButton);
00957 return;
00958 }
00959 bool addSupports = dlg.supportsCheckBox->isChecked();
00960 create_arch(world, innerRadius, outerRadius, thickness, nBlocks, addSupports);
00961 }
00962
00963 void MainWindow::miscOptimizer()
00964 {
00965 OptimizerDlg* dlg = new OptimizerDlg(world, mWindow);
00966 dlg->setAttribute(Qt::WA_ShowModal, false);
00967 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00968 dlg->show();
00969 }
00970
00971 void MainWindow::miscEigengridsAction_activated()
00972 {
00973 #ifdef EIGENGRIDS
00974 EigenGridsDlg *dlg = new EigenGridsDlg(mWindow);
00975 dlg->setAttribute(Qt::WA_ShowModal, false);
00976 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
00977 dlg->show();
00978 #endif
00979 }
00980
00987 void MainWindow::updateContactsList()
00988 {
00989 std::list<Contact *> contactList;
00990 std::list<Contact *>::iterator cp;
00991 int b,contactNum = 0;;
00992 double *contactForce;
00993
00994 clearContactsList();
00995
00996 for (b=0;b<world->getNumGB();b++) {
00997 contactList = world->getGB(b)->getContacts();
00998
00999 for (cp=contactList.begin();cp!=contactList.end();cp++,contactNum++) {
01000 contactForce = (*cp)->getDynamicContactWrench();
01001 mUI->contactsListBox->insertItem(QString("Contact %1: force %2 %3 %4 torque %5 %6 %7").
01002 arg(contactNum+1).
01003 arg(contactForce[0],5,'f',2).arg(contactForce[1],5,'f',2).arg(contactForce[2],5,'f',2).
01004 arg(contactForce[3],5,'f',4).arg(contactForce[4],5,'f',4).arg(contactForce[5],5,'f',4));
01005 }
01006 }
01007 }
01008
01014 void MainWindow::contactSelected(int newSelection)
01015 {
01016 if (selectedContact == newSelection) {
01017 graspItGUI->getIVmgr()->unhilightObjContact(selectedContact);
01018 selectedContact = -1;
01019 }
01020 else {
01021 if (selectedContact >= 0) {
01022 graspItGUI->getIVmgr()->unhilightObjContact(selectedContact);
01023 }
01024 graspItGUI->getIVmgr()->hilightObjContact(newSelection);
01025 selectedContact = newSelection;
01026 }
01027 }
01028
01032 void MainWindow::clearContactsList()
01033 {
01034 selectedContact = -1;
01035 mUI->contactsListBox->clear();
01036 }
01037
01041 void MainWindow::updateTimeReadout()
01042 {
01043 QTime simTime;
01044 double seconds = world->getWorldTime();
01045 simTime = simTime.addMSecs(ROUND(seconds*1000));
01046 mUI->timeReadout->display(simTime.toString("mm:ss.zzz"));
01047 mUI->timeReadout->update();
01048 }
01049
01055 void MainWindow::toggleDynamics()
01056 {
01057 if (world->dynamicsAreOn()) {
01058 world->turnOffDynamics();
01059 mUI->dynamicsPlayAction->setText("Start Simulation");
01060 graspItGUI->getIVmgr()->drawDynamicForces();
01061 updateContactsList();
01062 } else {
01063 world->turnOnDynamics();
01064 mUI->dynamicsPlayAction->setText("Pause Simulation");
01065 clearContactsList();
01066 }
01067 }
01068
01073 void MainWindow::updateQualityList()
01074 {
01075 QString valStr;
01076 Hand *h;
01077 Grasp *g;
01078 int numHands = world->getNumHands();
01079
01080 mUI->qualityListBox->clear();
01081
01082 for (int i=0;i<numHands;i++) {
01083 h = world->getHand(i);
01084 g = h->getGrasp();
01085
01086 mUI->qualityListBox->insertItem(h->getName());
01087
01088 for (int j=0;j<g->getNumQM();j++) {
01089 valStr = " " + g->getQM(j)->getName() +
01090 QString(": %1").arg(g->getQM(j)->evaluate(),6,'g',3);
01091 mUI->qualityListBox->insertItem(valStr);
01092 }
01093 }
01094 }
01095
01100 void MainWindow::showDynamicsError( const char *errMsg )
01101 {
01102 mUI->dynamicsPlayAction->setOn(false);
01103 QTWARNING(errMsg);
01104 }
01105
01109 void MainWindow::dynamicsPushState()
01110 {
01111 world->pushDynamicState();
01112 }
01113
01118 void MainWindow::dynamicsPopState()
01119 {
01120 world->popDynamicState();
01121 }
01122
01127 void MainWindow::updateMaterialBoxList()
01128 {
01129 mUI->materialComboBox->clear();
01130 for (int i=0;i<world->getNumMaterials();i++)
01131 mUI->materialComboBox->insertItem(world->getMaterialName(i));
01132 }
01133
01137 void MainWindow::materialSelected( int whichMat )
01138 {
01139 if (whichMat >= 0 && whichMat < world->getNumMaterials()) {
01140 for (int i=0;i<world->getNumSelectedBodies();i++)
01141 world->getSelectedBody(i)->setMaterial(whichMat);
01142 world->updateGrasps();
01143 }
01144 }
01145
01151 void MainWindow::updateMaterialBox()
01152 {
01153 int i;
01154 if (world->getNumSelectedBodies() > 0) {
01155 int firstMat = world->getSelectedBody(0)->getMaterial();
01156 for (i=1;i<world->getNumSelectedBodies();i++)
01157 if (world->getSelectedBody(i)->getMaterial() != firstMat) break;
01158 if (i==world->getNumSelectedBodies()) {
01159 mUI->materialComboBox->setCurrentItem(firstMat);
01160 if (mUI->materialComboBox->count() > world->getNumMaterials())
01161 mUI->materialComboBox->removeItem(world->getNumMaterials());
01162 }
01163 else {
01164 if (mUI->materialComboBox->count() == world->getNumMaterials())
01165 mUI->materialComboBox->insertItem(QString(" "));
01166 mUI->materialComboBox->setCurrentItem(world->getNumMaterials());
01167 }
01168 }
01169 }
01170
01175 void MainWindow::updateGraspBoxes()
01176 {
01177 mUI->handSelectionBox->clear();
01178 for (int i=0; i<world->getNumHands(); i++) {
01179 mUI->handSelectionBox->insertItem(world->getHand(i)->getName());
01180 if (world->getCurrentHand() == world->getHand(i)) {
01181 mUI->handSelectionBox->setCurrentItem(i);
01182 }
01183 updateTendonNamesBox();
01184 world->deselectTendon();
01185 }
01186 mUI->graspedBodyBox->clear();
01187 if (world->getCurrentHand()) {
01188 for (int i=0;i<world->getNumGB();i++) {
01189 mUI->graspedBodyBox->insertItem(world->getGB(i)->getName());
01190 if (world->getCurrentHand()->getGrasp()->getObject() == world->getGB(i)) {
01191 mUI->graspedBodyBox->setCurrentItem(i);
01192 }
01193 }
01194 }
01195 }
01196
01197
01198 void MainWindow::handleHandSelectionChange()
01199 {
01200 int i;
01201 for (i=0;i<world->getNumHands();i++) {
01202 if (world->getCurrentHand() == world->getHand(i))
01203 mUI->handSelectionBox->setCurrentItem(i);
01204 }
01205 updateTendonNamesBox();
01206 }
01207
01213 void MainWindow::selectGraspedBody(int sb)
01214 {
01215 GraspableBody *b = world->getGB(sb);
01216 world->getHand(mUI->handSelectionBox->currentItem())->getGrasp()->setObject(b);
01217 updateQualityList();
01218 }
01219
01224 void MainWindow::setCurrentHand( int sh )
01225 {
01226 world->setCurrentHand(world->getHand(sh));
01227 updateGraspBoxes();
01228
01229 updateTendonNamesBox();
01230 world->deselectTendon();
01231
01232 }
01233
01237 void MainWindow::updateCollisionAction(bool state)
01238 {
01239 if (state)
01240 mUI->elementCollisionToggleAction->setText("Collisions OFF");
01241 else
01242 mUI->elementCollisionToggleAction->setText("Collisions ON");
01243 }
01244
01245 void MainWindow::handleTendonSelectionArea()
01246 {
01247 if (!world->queryTendonSelected()) {
01248 mUI->tendonActiveForceLabel->setEnabled(false);
01249 mUI->TendonForceInput->setEnabled(false);
01250 mUI->tendonPassiveForceLabel->setEnabled(false);
01251 mUI->tendonPassiveForceEdit->setEnabled(false);
01252 mUI->tendonExcursionLabel->setEnabled(false);
01253 mUI->tendonExcursionEdit->setEnabled(false);
01254 mUI->tendonVisibleLabel->setEnabled(false);
01255 mUI->tendonVisibleCheckBox->setEnabled(false);
01256 mUI->forcesVisibleLabel->setEnabled(false);
01257 mUI->forcesVisibleCheckBox->setEnabled(false);
01258 if (mUI->tendonNamesBox->isEnabled() ) {
01259 mUI->tendonNamesBox->setCurrentItem ( mUI->tendonNamesBox->count() - 1 );
01260 }
01261 } else {
01262 mUI->tendonActiveForceLabel->setEnabled(true);
01263 mUI->TendonForceInput->setEnabled(true);
01264 mUI->tendonPassiveForceLabel->setEnabled(true);
01265 mUI->tendonPassiveForceEdit->setEnabled(true);
01266 mUI->tendonExcursionLabel->setEnabled(true);
01267 mUI->tendonExcursionEdit->setEnabled(true);
01268 mUI->tendonVisibleLabel->setEnabled(true);
01269 mUI->tendonVisibleCheckBox->setEnabled(true);
01270 if (mUI->tendonVisibleCheckBox->isChecked()) {
01271 mUI->forcesVisibleLabel->setEnabled(true);
01272 mUI->forcesVisibleCheckBox->setEnabled(true);
01273 } else {
01274 mUI->forcesVisibleLabel->setEnabled(false);
01275 mUI->forcesVisibleCheckBox->setEnabled(false);
01276 }
01277
01278 for (int i=0; i<mUI->tendonNamesBox->count(); i++) {
01279 if ( mUI->tendonNamesBox->text(i)==world->getSelectedTendon()->getName() ) {
01280 mUI->tendonNamesBox->setCurrentItem(i);
01281 break;
01282 }
01283 }
01284
01285
01286
01287
01288 float getForce = world->getSelectedTendon()->getActiveForce();
01289
01290 mUI->TendonForceInput->setValue( int(getForce*1.0e-6) );
01291
01292 handleTendonDetailsArea();
01293 }
01294 }
01295
01296 void MainWindow::handleTendonDetailsArea()
01297 {
01298
01299 if (!world->queryTendonSelected())
01300 return;
01301
01302 QString exc;
01303 exc.setNum( world->getSelectedTendon()->getExcursion() , 'f' , 1);
01304 mUI->tendonExcursionEdit->setText( exc );
01305
01306 QString psf;
01307 float getForce = world->getSelectedTendon()->getPassiveForce() * 1.0e-6;
01308 psf.setNum( getForce , 'f' , 2);
01309 mUI->tendonPassiveForceEdit->setText( psf );
01310
01311 mUI->tendonVisibleCheckBox->setChecked( world->getSelectedTendon()->isVisible() );
01312 mUI->forcesVisibleCheckBox->setChecked( world->getSelectedTendon()->forcesVisible() );
01313 }
01314
01315 void MainWindow::TendonForceInput_valueChanged( int f)
01316 {
01317 float newForce = (float)f * 1.0e6;
01318 world->getSelectedTendon()->setActiveForce( newForce );
01319 }
01320
01321 void MainWindow::tendonNamesBoxActivated( int i)
01322 {
01323 if ( i<mUI->tendonNamesBox->count()-1) {
01324
01325 world->selectTendon(i);
01326 } else {
01327 world->deselectTendon();
01328 }
01329
01330 }
01331
01332
01333 void MainWindow::tendonVisibleCheckBox_toggled( bool vis)
01334 {
01335 world->getSelectedTendon()->setVisible( vis );
01336 if (vis) {
01337 mUI->forcesVisibleLabel->setEnabled(true);
01338 mUI->forcesVisibleCheckBox->setEnabled(true);
01339 } else {
01340 mUI->forcesVisibleLabel->setEnabled(false);
01341 mUI->forcesVisibleCheckBox->setEnabled(false);
01342 }
01343 }
01344
01345 void MainWindow::forcesVisibleCheckBox_toggled( bool vis)
01346 {
01347 world->getSelectedTendon()->setForcesVisible( vis );
01348 }
01349
01350
01351 void MainWindow::updateTendonNamesBox()
01352 {
01353 int i, nrTendons = world->getCurrentHandNumberTendons();
01354 if (nrTendons==0) {
01355 mUI->tendonNamesBox->clear();
01356 mUI->Tendon_force_label->setEnabled(false);
01357 mUI->tendonNamesBox->setEnabled(false);
01358 return;
01359 }
01360
01361 mUI->Tendon_force_label->setEnabled(true);
01362 mUI->tendonNamesBox->setEnabled(true);
01363 mUI->tendonNamesBox->clear();
01364 for (i=0; i<nrTendons; i++) {
01365 mUI->tendonNamesBox->insertItem( world->getSelectedHandTendonName(i) );
01366 }
01367 mUI->tendonNamesBox->insertItem( QString("--none selected--") );
01368 }