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 <vector>
00027
00028 #include "bodyPropDlg.h"
00029 #include "body.h"
00030
00031 #include "robot.h"
00032 #include "world.h"
00033 #include "graspitGUI.h"
00034 #include "ivmgr.h"
00035 #include "qvalidator.h"
00036 #include "collisionStructures.h"
00037 #include "bBox.h"
00038
00052 void BodyPropDlg::init()
00053 {
00054 int i,c,l;
00055 World *w=graspItGUI->getIVmgr()->getWorld();
00056 std::list<WorldElement *> elemList = w->getSelectedElementList();
00057 std::list<WorldElement *>::iterator ep;
00058
00059 dynBod=NULL;
00060 massLineEdit->setValidator(new QDoubleValidator(0,1.0e+100,6,this));
00061
00062 for (ep=elemList.begin();ep!=elemList.end();ep++) {
00063 if ((*ep)->inherits("Body")) bodyVec.push_back((Body *)(*ep));
00064 else if ((*ep)->inherits("Robot")) {
00065 Robot *r = (Robot *)(*ep);
00066 bodyVec.push_back(r->getBase());
00067 for (c=0;c<r->getNumChains();c++)
00068 for (l=0;l<r->getChain(c)->getNumLinks();l++)
00069 bodyVec.push_back(r->getChain(c)->getLink(l));
00070 }
00071 }
00072 numBodies = bodyVec.size();
00073
00074 if (numBodies > 1) {
00075 dynamicCheckBox->setEnabled(false);
00076 axesCheckBox->setEnabled(false);
00077 dynamicForcesCheckBox->setEnabled(false);
00078 massLineEdit->setEnabled(false);
00079 }
00080 else {
00081 if (bodyVec[0]->inherits("DynamicBody")) {
00082 dynBod = (DynamicBody *)bodyVec[0];
00083 if (dynBod->isDynamic()) {
00084 axesCheckBox->setChecked(dynBod->axesShown());
00085 dynamicForcesCheckBox->setChecked(dynBod->dynContactForcesShown());
00086 massLineEdit->setText(QString::number(dynBod->getMass()));
00087 }
00088 dynamicCheckBox->setChecked(dynBod->isDynamic());
00089 }
00090 if (!(dynBod && dynBod->isDynamic())) {
00091 axesCheckBox->setEnabled(false);
00092 dynamicForcesCheckBox->setEnabled(false);
00093 massLineEdit->setEnabled(false);
00094 }
00095 }
00096
00097
00098 for (i=0;i<numBodies;i++) {
00099 origMaterials.push_back(bodyVec[i]->getMaterial());
00100 origShowFC.push_back(bodyVec[i]->frictionConesShown());
00101 origTransparencies.push_back(bodyVec[i]->getTransparency());
00102 }
00103 if (dynBod) {
00104 origIsDynamic = dynBod->isDynamic();
00105 origMass = dynBod->getMass();
00106 origAxesShown = dynBod->axesShown();
00107 origDynContactForcesShown = dynBod->dynContactForcesShown();
00108 }
00109 else origIsDynamic = false;
00110
00111 for (i=0;i<w->getNumMaterials();i++)
00112 materialComboBox->insertItem(w->getMaterialName(i));
00113 int firstMat = bodyVec[0]->getMaterial();
00114 for (i=1;i<numBodies;i++)
00115 if (bodyVec[i]->getMaterial() != firstMat) break;
00116 if (i==numBodies) materialComboBox->setCurrentItem(firstMat);
00117 else {
00118 materialComboBox->insertItem(QString("Keep Original"));
00119 materialComboBox->setCurrentItem(w->getNumMaterials());
00120 }
00121
00122 bool showFC = bodyVec[0]->frictionConesShown();
00123 for (i=1;i<numBodies;i++)
00124 if (bodyVec[i]->frictionConesShown() != showFC) break;
00125 if (i==numBodies) fcCheckBox->setChecked(showFC);
00126 else {
00127 fcCheckBox->setTristate(true);
00128 fcCheckBox->setNoChange();
00129 }
00130
00131 float transp = bodyVec[0]->getTransparency();
00132 for (i=1;i<numBodies;i++)
00133 if (bodyVec[i]->getTransparency() != transp) break;
00134 if (i==numBodies) transparencySlider->setValue((int) (transp*transparencySlider->maxValue()));
00135
00136 boundingCheckBox->setChecked(false);
00137 boundingSpinBox->setEnabled(false);
00138 QObject::connect( boundingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showBvs()) );
00139 QObject::connect( boundingSpinBox, SIGNAL(valueChanged(int)), this, SLOT(showBvs()) );
00140
00141 }
00142
00147 void BodyPropDlg::setTransparency( int val )
00148 {
00149 float ratio = (float)val/(float)transparencySlider->maxValue();
00150 for (int i=0;i<numBodies;i++)
00151 bodyVec[i]->setTransparency(ratio);
00152 }
00153
00158 void BodyPropDlg::setShowAxes( int state)
00159 {
00160 if (!dynBod) return;
00161 if (state == QCheckBox::On) dynBod->showAxes(true);
00162 else if (state == QCheckBox::Off) dynBod->showAxes(false);
00163 }
00164
00169 void BodyPropDlg::setShowFC( int state )
00170 {
00171 for (int i=0;i<numBodies;i++)
00172 if (state == QCheckBox::On) bodyVec[i]->showFrictionCones(true);
00173 else if (state == QCheckBox::Off) bodyVec[i]->showFrictionCones(false);
00174 else if (state == QCheckBox::NoChange) bodyVec[i]->showFrictionCones(origShowFC[i]);
00175 }
00176
00186 void BodyPropDlg::setDynamic( int state )
00187 {
00188 if (dynBod) {
00189 if (state==QCheckBox::On) dynBod->setUseDynamics(true);
00190 else if (state == QCheckBox::Off) {
00191 dynBod->setUseDynamics(false);
00192 axesCheckBox->setEnabled(false);
00193 dynamicForcesCheckBox->setEnabled(false);
00194 massLineEdit->setEnabled(false);
00195 }
00196 }
00197 else if (state==QCheckBox::On) {
00198 bodyVec[0]->getWorld()->deselectElement(bodyVec[0]);
00199 dynBod = bodyVec[0]->getWorld()->makeBodyDynamic(bodyVec[0],DynamicBody::defaultMass);
00200 dynBod->getWorld()->selectElement(dynBod);
00201 origMass = dynBod->getMass();
00202 origAxesShown = dynBod->axesShown();
00203 origDynContactForcesShown = dynBod->dynContactForcesShown();
00204 }
00205 if (state == QCheckBox::On) {
00206 axesCheckBox->setEnabled(true);
00207 dynamicForcesCheckBox->setEnabled(true);
00208 massLineEdit->setEnabled(true);
00209 axesCheckBox->setChecked(dynBod->axesShown());
00210 dynamicForcesCheckBox->setChecked(dynBod->dynContactForcesShown());
00211 massLineEdit->setText(QString::number(dynBod->getMass()));
00212 }
00213 }
00214
00218 void BodyPropDlg::setShowDynContactForces( int state )
00219 {
00220 if (!dynBod) return;
00221 if (state == QCheckBox::On) dynBod->showDynContactForces(true);
00222 else if (state == QCheckBox::Off) dynBod->showDynContactForces(false);
00223 }
00224
00231 void BodyPropDlg::setMaterial( int choice )
00232 {
00233 World *w=graspItGUI->getIVmgr()->getWorld();
00234
00235 if (choice == w->getNumMaterials()) {
00236 for (int i=0;i<numBodies;i++)
00237 bodyVec[i]->setMaterial(origMaterials[i]);
00238 }
00239 else {
00240 for (int i=0;i<numBodies;i++)
00241 bodyVec[i]->setMaterial(choice);
00242 }
00243 }
00244
00249 void BodyPropDlg::revertAndClose()
00250 {
00251
00252 for (int i=0;i<numBodies;i++) {
00253 bodyVec[i]->setTransparency(origTransparencies[i]);
00254 bodyVec[i]->showFrictionCones(origShowFC[i]);
00255 bodyVec[i]->setMaterial(origMaterials[i]);
00256 }
00257 if (dynBod) {
00258 dynBod->setUseDynamics(origIsDynamic);
00259 dynBod->setMass(origMass);
00260 dynBod->showAxes(origAxesShown);
00261 dynBod->showDynContactForces(origDynContactForcesShown);
00262 }
00263 reject();
00264 }
00265
00273 void
00274 BodyPropDlg::showBvs()
00275 {
00276 std::vector<BoundingBox> bvs;
00277 World *w=graspItGUI->getIVmgr()->getWorld();
00278 int depth = -1;
00279 if (!boundingCheckBox->isChecked()) {
00280 boundingSpinBox->setEnabled(false);
00281 } else {
00282 boundingSpinBox->setEnabled(true);
00283 depth = boundingSpinBox->value();
00284 }
00285 for (int i=0; i<numBodies; i++) {
00286 bvs.clear();
00287 if (depth >= 0) {
00288 w->getBvs(bodyVec[i], depth, &bvs);
00289 }
00290 bodyVec[i]->setBVGeometry(bvs);
00291 }
00292 }