Documentation


massSpringEngineGUI.cpp

Go to the documentation of this file.
00001 #include <qcombobox.h>
00002 #include <qspinbox.h>
00003 #include <qgroupbox.h>
00004 #include <qcheckbox.h>
00005 
00006 #include <animal/X3DTK/Qt/engineGUI/engineGUI.h>
00007 #include <animal/X3DTK/Qt/objectGUI/WFloatLineEdit.h>
00008 #include "massSpringEngineGUI.h"
00009 
00010 
00011 namespace X3DTK{
00012 namespace Qt{
00013 
00014 MassSpringEngineQt::MassSpringEngineQt( AMassSpringEngine * massSpringEngine)
00015   : MassSpringEngineDesigner(0,"main q object")
00016   , _massSpringEngine(massSpringEngine)
00017 {
00018   method_comboBox->insertItem( QString("euler") );
00019   method_comboBox->insertItem( QString("rk2") );
00020   method_comboBox->insertItem( QString("rk4") );
00021   method_comboBox->insertItem( QString("midpoint") );
00022   method_comboBox->insertItem( QString("velocity verlet") );
00023   method_comboBox->insertItem( QString("implicit euler") );
00024   connect(method_comboBox,SIGNAL(activated(int)),
00025           this, SLOT(setIntegrationMethod(int)));
00026   setIntegrationMethod( _massSpringEngine->getMethod() );
00027   method_comboBox->setCurrentItem( _massSpringEngine->getMethod() );
00028 
00029   // max nb of iterations
00030   cg_maxiter_spinBox->setValue(_massSpringEngine->maxCGiterations() );
00031   connect(cg_maxiter_spinBox,SIGNAL(valueChanged(int)),
00032           this, SLOT(setMaxCGiterations(int)));
00033 
00034   // damping ratio
00035   cg_damping_wFloatLineEdit->setFloatValue( _massSpringEngine->dampingRatio());
00036   cg_damping_wFloatLineEdit->setMinFloatValue( 0.0 );
00037   cg_damping_wFloatLineEdit->setMaxFloatValue( 1000.0 );
00038   connect(cg_damping_wFloatLineEdit,SIGNAL(floatValueChanged(float)),
00039           this, SLOT(setImplicitEulerDampingRatio(float)));
00040 
00041   // divider threshold
00042   cg_divider_wFloatLineEdit->setFloatValue( _massSpringEngine->smallDenominatorThreshold());
00043   cg_divider_wFloatLineEdit->setMinFloatValue( 0.0 );
00044   cg_divider_wFloatLineEdit->setMaxFloatValue( 1000.0 );
00045   connect(cg_divider_wFloatLineEdit,SIGNAL(floatValueChanged(float)),
00046           this, SLOT(setImplicitEulerDividerThreshold(float)));
00047 
00048 
00049   // isotropy
00050   isotropy_spinBox->setValue( static_cast<int>(_massSpringEngine->getIsotropy()*100+0.5) );
00051   connect(isotropy_spinBox,SIGNAL(valueChanged(int)),
00052           this, SLOT(setIsotropy(int)));
00053 
00054 
00055   // modified midpoint substeps
00056   mmid_spinBox->setValue( _massSpringEngine->MMIDsteps() );
00057   connect(mmid_spinBox,SIGNAL(valueChanged(int)),
00058           this, SLOT(setMmidSubsteps(int)));
00059 
00060 
00061   // exponential damping
00062   connect(exponentialDamping_wFloatLineEdit,SIGNAL(floatValueChanged(float)),
00063           this, SLOT(setExponentialDamping(float)));
00064   //cerr<<"MassSpringEngineQt::MassSpringEngineQt exponentialDamping "<<_massSpringEngine->get_exponentialDamping() << endl;
00065   exponentialDamping_wFloatLineEdit->setMinFloatValue( 0.0 );
00066   exponentialDamping_wFloatLineEdit->setMaxFloatValue( 1000.0 );
00067   exponentialDamping_wFloatLineEdit->setFloatValue( _massSpringEngine->get_exponentialDamping() );
00068 
00069   connect(exponentialDamping_checkBox,SIGNAL(toggled(bool)),
00070           this, SLOT(toggleExponentialDamping(bool)));
00071   exponentialDamping_checkBox->setChecked( _massSpringEngine->get_useExponentialDamping() );
00072 
00073  // gravity
00074  gravity_checkBox->setChecked( _massSpringEngine->get_useGravity() );
00075  connect(gravity_checkBox,SIGNAL(toggled(bool)),
00076           this, SLOT(toggleGravity(bool)));
00077  connect(gravity_x_wFloatLineEdit,SIGNAL(floatValueChanged(float)),
00078           this, SLOT(setXgravity(float)));
00079  connect(gravity_y_wFloatLineEdit,SIGNAL(floatValueChanged(float)),
00080           this, SLOT(setYgravity(float)));
00081  connect(gravity_z_wFloatLineEdit,SIGNAL(floatValueChanged(float)),
00082           this, SLOT(setZgravity(float)));
00083 
00084  gravity_x_wFloatLineEdit->setMinFloatValue( -1.0e+6 );
00085  gravity_x_wFloatLineEdit->setMaxFloatValue( +1.0e+6 );
00086  gravity_y_wFloatLineEdit->setMinFloatValue( -1.0e+6 );
00087  gravity_y_wFloatLineEdit->setMaxFloatValue( +1.0e+6 );
00088  gravity_z_wFloatLineEdit->setMinFloatValue( -1.0e+6 );
00089  gravity_z_wFloatLineEdit->setMaxFloatValue( +1.0e+6 );
00090  
00091  AMassSpringEngine::Vec g = _massSpringEngine->get_gravity();
00092  gravity_x_wFloatLineEdit->setFloatValue( g.x );
00093  gravity_y_wFloatLineEdit->setFloatValue( g.y );
00094  gravity_z_wFloatLineEdit->setFloatValue( g.z );
00095 
00096  // mass
00097  mass_groupBox->setEnabled( false );
00098  
00099  // threshold distance
00100  connect(threshold_distancewFloatLineEdit,SIGNAL(floatValueChanged(float)),
00101           this, SLOT(setThresholdDistance(float)));
00102   threshold_distancewFloatLineEdit->setMinFloatValue( 1.0e-20 );
00103   threshold_distancewFloatLineEdit->setMaxFloatValue( 1 );
00104   threshold_distancewFloatLineEdit->setFloatValue(_massSpringEngine->get_thresholdDistance() );
00105   
00106   // display mass_spring
00107   displayMScheckBox->setChecked( _massSpringEngine->get_displayMassSpring() );
00108   MS_colourgroupBox->setEnabled( _massSpringEngine->get_displayMassSpring() );
00109   connect(displayMScheckBox,SIGNAL(toggled(bool)),
00110     this, SLOT(setDisplayMassSpring(bool)));
00111   
00112   // mass_spring colour
00113   MS_colour_compressedcheck_Box->setChecked( _massSpringEngine->get_compressed_ok() );
00114   connect(MS_colour_compressedcheck_Box,SIGNAL(toggled(bool)),
00115      this, SLOT(setCompressed_ok(bool)));
00116   
00117   MS_colour_elongated_check_Box->setChecked( _massSpringEngine->get_elongated_ok() );
00118   connect(MS_colour_elongated_check_Box,SIGNAL(toggled (bool)),
00119      this, SLOT(setElongated_ok(bool)));
00120 
00121 
00122   // point size
00123   width_points_spinBox->setValue( _massSpringEngine->get_pointSize() );
00124   connect( width_points_spinBox,SIGNAL(valueChanged(int)), this, SLOT(setPointWidth(int)));
00125   
00126   // line width
00127   width_edges_spinBox->setValue( _massSpringEngine->get_lineWidth() );
00128   connect( width_edges_spinBox,SIGNAL(valueChanged(int)), this, SLOT(setLineWidth(int)));
00129   
00130      
00131   // debug info
00132   connect(debug_infocheckBox, SIGNAL(toggled(bool)),
00133     this, SLOT(toggleDebugInfo(bool)));
00134   debug_infocheckBox->setChecked(_massSpringEngine->get_debugInfo() );
00135 
00136 //  // Set the interpolation method
00137 //  if (massSpringEngine->getInterpolationID())
00138 //    linearRadioButton->setChecked(false);
00139 //  else
00140 //    linearRadioButton->setChecked(true);
00141 //
00142 }
00143 
00144 MassSpringEngineQt::~MassSpringEngineQt()
00145 {
00146 }
00147 
00149 void MassSpringEngineQt::setIntegrationMethod( int methodID )
00150 {
00151   _massSpringEngine->setMethod( methodID );
00152   //cerr<<"MassSpringEngineQt::setIntegrationMethod "<< methodID << endl;
00153 
00154   if( _massSpringEngine->getMethod()==AMassSpringEngine::IMPLICIT_EULER ){
00155     cg_groupBox->setEnabled(true);
00156   }
00157   else{
00158     cg_groupBox->setEnabled(false);
00159   }
00160 
00161   if( _massSpringEngine->getMethod()==AMassSpringEngine::MODMID ){
00162     mmid_groupBox->setEnabled(true);
00163   }
00164   else{
00165     mmid_groupBox->setEnabled(false);
00166   }
00167   emit changed();
00168 }
00169 
00171 void MassSpringEngineQt::setMaxCGiterations( int maxvalue )
00172 {
00173   //cerr<<"MassSpringEngineQt::setMaxCGiterations "<< maxvalue << endl;
00174    _massSpringEngine->setMaxCGiterations( maxvalue );
00175   emit changed();
00176 }
00177 
00179 void MassSpringEngineQt::setIsotropy( int isotropy )
00180 {
00181   //cerr<<"MassSpringEngineQt::setIsotropy "<< isotropy << endl;
00182    _massSpringEngine->setIsotropy( isotropy/100.0 );
00183   emit changed();
00184 }
00185 
00187 void MassSpringEngineQt::setMmidSubsteps( int nb )
00188 {
00189   //cerr<<"MassSpringEngineQt::setMmidSubsteps "<< nb << endl;
00190    _massSpringEngine->setMMIDsteps(nb);
00191   emit changed();
00192 }
00193 
00195 void MassSpringEngineQt::setImplicitEulerDampingRatio( float r )
00196 {
00197   //cerr<<"MassSpringEngineQt::setImplicitEulerDampingRatio "<< r << endl;
00198    _massSpringEngine->setDampingRatio(r);
00199   emit changed();
00200 }
00201 
00203 void MassSpringEngineQt::setImplicitEulerDividerThreshold( float d )
00204 {
00205   //cerr<<"MassSpringEngineQt::setImplicitEulerDividerThreshold "<< d << endl;
00206    _massSpringEngine->setSmallDenominatorThreshold(d);
00207   emit changed();
00208 }
00209 
00211 void MassSpringEngineQt::setExponentialDamping( float value )
00212 {
00213   //cerr<<"MassSpringEngineQt::setExponentialDamping "<< value << endl;
00214    _massSpringEngine->set_exponentialDamping(value);
00215   emit changed();
00216 }
00217 
00219 void MassSpringEngineQt::toggleExponentialDamping( bool value )
00220 {
00221   //cerr<<"MassSpringEngineQt::toggleExponentialDamping "<< value << endl;
00222    _massSpringEngine->set_useExponentialDamping(value);
00223   emit changed();
00224 }
00225 
00227 void MassSpringEngineQt::toggleGravity( bool value )
00228 {
00229   //cerr<<"MassSpringEngineQt::toggleGravity "<< value << endl;
00230    _massSpringEngine->set_useGravity(value);
00231   emit changed();
00232 }
00233 void MassSpringEngineQt::setXgravity( float value )
00234 {
00235   //cerr<<"MassSpringEngineQt::setXgravity "<< value << endl;
00236   AMassSpringEngine::Vec g = _massSpringEngine->get_gravity();
00237   g.x=value;
00238   _massSpringEngine->set_gravity(g);
00239   emit changed();
00240 }
00241 void MassSpringEngineQt::setYgravity( float value )
00242 {
00243   //cerr<<"MassSpringEngineQt::setYgravity "<< value << endl;
00244   AMassSpringEngine::Vec g = _massSpringEngine->get_gravity();
00245   g.y=value;
00246   _massSpringEngine->set_gravity(g);
00247   emit changed();
00248 }
00249 void MassSpringEngineQt::setZgravity( float value )
00250 {
00251   //cerr<<"MassSpringEngineQt::setZgravity "<< value << endl;
00252   AMassSpringEngine::Vec g = _massSpringEngine->get_gravity();
00253   g.z=value;
00254   _massSpringEngine->set_gravity(g);
00255   emit changed();
00256 }
00258 void MassSpringEngineQt::setThresholdDistance(float value)
00259 {
00260   //cerr << "MassSpringEngineQt::setThresholdDistance " << value << endl;
00261   _massSpringEngine->set_thresholdDistance(value);
00262   emit changed();
00263 }
00265 void MassSpringEngineQt::setCompressed_ok(bool b)
00266 {
00267   //cerr << "MassSpringEngineQt::setCompressed_ok " << b << endl;
00268   _massSpringEngine->set_compressed_ok(b);
00269   emit changed();
00270 }
00272 void MassSpringEngineQt::setElongated_ok(bool b)
00273 {  
00274   //cerr << "MassSpringEngineQt::setElongated_ok " << b << endl;
00275   _massSpringEngine->set_elongated_ok(b);
00276   emit changed();
00277 }
00279 void MassSpringEngineQt::setDisplayMassSpring(bool b)
00280 {
00281   //cerr << "MassSpringEngineQt::setDisplayMassSpring " << b << endl;
00282   _massSpringEngine->set_displayMassSpring(b);
00283   MS_colourgroupBox->setEnabled(b);
00284   setElongated_ok(b); MS_colour_elongated_check_Box->setChecked(b);
00285   setCompressed_ok(b); MS_colour_compressedcheck_Box->setChecked(b);
00286   emit changed();
00287 }
00288 
00290 void MassSpringEngineQt::setPointWidth(int w)
00291 {  
00292     _massSpringEngine->set_pointSize(w);
00293   emit changed();
00294 }
00295 
00297 void MassSpringEngineQt::setLineWidth(int w)
00298 {  
00299     _massSpringEngine->set_lineWidth(w);
00300   emit changed();
00301 }
00302 
00304   void MassSpringEngineQt::toggleDebugInfo(bool b){
00305     _massSpringEngine->set_debugInfo(b);
00306   emit changed();
00307 }
00308 
00309 
00311 //void MassSpringEngineQt::toggleLinearMethod(bool b)
00312 //{
00313 //  massSpringEngine->toggleLinearMethod(b);
00314 //}
00315 //
00316 //void MassSpringEngineQt::toggleCatmullRomMethod(bool b)
00317 //{
00318 //  massSpringEngine->toggleCatmullRomMethod(b);
00319 //}
00320 
00322 QWidget * createMassSpringNodeQWidget(X3D::MassSpringNode * node, QWidget * parent)
00323 {
00324   //std::cerr<< "createMassSpringNodeQWidget"<<std::endl;
00325 
00326   if (node)
00327   {
00328     MassSpringEngineQt * MSEQt = new MassSpringEngineQt(node);
00329     //MSEQt->reparent(parent, 0, QPoint(0,0));
00330 
00331     // Create the GUI of a animal::engine and insert the new features of a MassSpring
00332     EngineGUI * engineGUI = static_cast<EngineGUI *>(createEngineNodeQWidget(node, parent));
00333     engineGUI->insertTab(MSEQt, "MassSpring",0);
00334     engineGUI->setCurrentPage(0);
00335     QWidget::connect( MSEQt, SIGNAL( changed() ), engineGUI, SLOT(ok()));
00336     
00337     return engineGUI;
00338   }
00339   
00340   std::cerr<<"Warning createMassSpringNodeQWidget(): impossible to create a X3DTK::Qt::EngineGUI because the associated animal::Engine is NULL."<<std::endl;
00341   std::cerr<<"        or the MainController is NULL."<<std::endl;
00342   return NULL;
00343 }
00344 
00345 }// Qt
00346 }// X3DTK
00347 

Generated on Thu Dec 23 13:52:25 2004 by doxygen 1.3.6