Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

SIG_LanguageParameters.cpp

00001 // #include <qpixmap.h>
00002 #include <qlistview.h>
00003 #include <qspinbox.h>
00004 #include <qlabel.h>
00005 #include <qlineedit.h>
00006 #include <qradiobutton.h>
00007 
00008 #include "SIGEL_MasterGUI/SIG_LanguageParameters.h"
00009 #include "SIGEL_MasterGUI/SIG_EditCommandDialog.h"
00010 
00011 #include "SIGEL_Robot/SIG_LanguageParameters.h"
00012 #include "SIGEL_Robot/SIG_CommandParameters.h"
00013 
00014 #include "SIGEL_Tools/SIG_IO.h"
00015 
00016 #include <cstdlib>
00017 
00018 namespace SIGEL_MasterGUI
00019 {
00020 
00021 /* 
00022  *  Constructs a SIG_LanguageParameters which is a child of 'parent', with the 
00023  *  name 'name' and widget flags set to 'f' 
00024  */
00025 SIG_LanguageParameters::SIG_LanguageParameters( QWidget* parent,  const char* name, WFlags fl, SIGEL_GP::SIG_GPExperiment &theExperiment )
00026   : SIG_LanguageParametersBase( parent, name, fl ), theExperiment( theExperiment ), sigelRoot( std::getenv( "SIGEL_ROOT" ) )//, allow( sigelRoot + "/pixmaps/allow.xpm" ), disallow( sigelRoot + "/pixmaps/disallow.xpm" )
00027 {
00028   // sigelRoot = QString( std::getenv( "SIGEL_ROOT") );
00029   allow = QPixmap( sigelRoot + "/pixmaps/allow.xpm" );
00030   disallow = QPixmap( sigelRoot + "/pixmaps/disallow.xpm" );
00031   // get the language parameters out of the experiment
00032   SIGEL_Robot::SIG_LanguageParameters *languageParameters = theExperiment.robot.getLangParam();
00033 
00034   // update the list
00035   QListViewItem *newItem;
00036 
00037   if( languageParameters->hasCommand( "SUB" ) )
00038     {
00039       newItem  = new QListViewItem( listviewCommands );
00040       newItem->setPixmap( 0, allow );
00041       newItem->setText( 1, "SUB" );
00042       QString duration = QString::number( languageParameters->getCommand( "SUB" )->getDuration(), 'g', 10 );
00043       newItem->setText( 2, duration );
00044     }
00045   
00046   if( languageParameters->hasCommand( "SENSE" ) )
00047     {
00048       newItem  = new QListViewItem( listviewCommands );
00049       newItem->setPixmap( 0, allow );
00050       newItem->setText( 1, "SENSE" );
00051       QString duration = QString::number( languageParameters->getCommand( "SENSE" )->getDuration(), 'g', 10 );
00052       newItem->setText( 2, duration );
00053     }
00054   
00055   if( languageParameters->hasCommand( "NOP" ) )
00056     {
00057       newItem  = new QListViewItem( listviewCommands );
00058       newItem->setPixmap( 0, allow );
00059       newItem->setText( 1, "NOP" );
00060       QString duration = QString::number( languageParameters->getCommand( "NOP" )->getDuration(), 'g', 10 );
00061       newItem->setText( 2, duration );
00062     }
00063   
00064   if( languageParameters->hasCommand( "MUL" ) )
00065     {
00066       newItem  = new QListViewItem( listviewCommands );
00067       newItem->setPixmap( 0, allow );
00068       newItem->setText( 1, "MUL" );
00069       QString duration = QString::number( languageParameters->getCommand( "MUL" )->getDuration(), 'g', 10 );
00070       newItem->setText( 2, duration );
00071     }
00072   
00073   if( languageParameters->hasCommand( "MOVE" ) )
00074     {
00075       newItem  = new QListViewItem( listviewCommands );
00076       newItem->setPixmap( 0, allow );
00077       newItem->setText( 1, "MOVE" );
00078       QString duration = QString::number( languageParameters->getCommand( "MOVE" )->getDuration(), 'g', 10 );
00079       newItem->setText( 2, duration );
00080     }
00081   
00082   if( languageParameters->hasCommand( "MOD" ) )
00083     {
00084       newItem  = new QListViewItem( listviewCommands );
00085       newItem->setPixmap( 0, allow );
00086       newItem->setText( 1, "MOD" );
00087       QString duration = QString::number( languageParameters->getCommand( "MOD" )->getDuration(), 'g', 10 );
00088       newItem->setText( 2, duration );
00089     }
00090   
00091   if( languageParameters->hasCommand( "MIN" ) )
00092     {
00093       newItem  = new QListViewItem( listviewCommands );
00094       newItem->setPixmap( 0, allow );
00095       newItem->setText( 1, "MIN" );
00096       QString duration = QString::number( languageParameters->getCommand( "MIN" )->getDuration(), 'g', 10 );
00097       newItem->setText( 2, duration );
00098     }
00099   
00100   if( languageParameters->hasCommand( "MAX" ) )
00101     {
00102       newItem  = new QListViewItem( listviewCommands );
00103       newItem->setPixmap( 0, allow );
00104       newItem->setText( 1, "MAX" );
00105       QString duration = QString::number( languageParameters->getCommand( "MAX" )->getDuration(), 'g', 10 );
00106       newItem->setText( 2, duration );
00107     }
00108   
00109   if( languageParameters->hasCommand( "LOAD" ) )
00110     {
00111       newItem  = new QListViewItem( listviewCommands );
00112       newItem->setPixmap( 0, allow );
00113       newItem->setText( 1, "LOAD" );
00114       QString duration = QString::number( languageParameters->getCommand( "LOAD" )->getDuration(), 'g', 10 );
00115       newItem->setText( 2, duration );
00116     }
00117 
00118   if( languageParameters->hasCommand( "JMP" ) )
00119     {
00120       newItem  = new QListViewItem( listviewCommands );
00121       newItem->setPixmap( 0, allow );
00122       newItem->setText( 1, "JMP" );
00123       QString duration = QString::number( languageParameters->getCommand( "JMP" )->getDuration(), 'g', 10 );
00124       newItem->setText( 2, duration );
00125     }
00126 
00127   if( languageParameters->hasCommand( "DIV" ) )
00128     {
00129       newItem  = new QListViewItem( listviewCommands );
00130       newItem->setPixmap( 0, allow );
00131       newItem->setText( 1, "DIV" );
00132       QString duration = QString::number( languageParameters->getCommand( "DIV" )->getDuration(), 'g', 10 );
00133       newItem->setText( 2, duration );
00134     }
00135 
00136   if( languageParameters->hasCommand( "DELAY" ) )
00137     {
00138       newItem  = new QListViewItem( listviewCommands );
00139       newItem->setPixmap( 0, allow );
00140       newItem->setText( 1, "DELAY" );
00141       QString duration = QString::number( languageParameters->getCommand( "DELAY" )->getDuration(), 'g', 10 );
00142       newItem->setText( 2, duration );
00143     }
00144 
00145   if( languageParameters->hasCommand( "COPY" ) )
00146     {
00147       newItem  = new QListViewItem( listviewCommands );
00148       newItem->setPixmap( 0, allow );
00149       newItem->setText( 1, "COPY" );
00150       QString duration = QString::number( languageParameters->getCommand( "COPY" )->getDuration(), 'g', 10 );
00151       newItem->setText( 2, duration );
00152     }
00153 
00154   if( languageParameters->hasCommand( "CMP" ) )
00155     {
00156       newItem  = new QListViewItem( listviewCommands );
00157       newItem->setPixmap( 0, allow );
00158       newItem->setText( 1, "CMP" );
00159       QString duration = QString::number( languageParameters->getCommand( "CMP" )->getDuration(), 'g', 10 );
00160       newItem->setText( 2, duration );
00161     }
00162 
00163   if( languageParameters->hasCommand( "ADD" ) )
00164     {
00165       newItem  = new QListViewItem( listviewCommands );
00166       newItem->setPixmap( 0, allow );
00167       newItem->setText( 1, "ADD" );
00168       QString duration = QString::number( languageParameters->getCommand( "ADD" )->getDuration(), 'g', 10 );
00169       newItem->setText( 2, duration );
00170     }
00171   
00172   spinboxNumberOfRegisters->setValue( languageParameters->getMemorySize() );
00173   spinboxRegisterWidth->setValue( languageParameters->getRegisterWidth() );
00174 
00175   // editCommandDialog = new SIG_EditCommandDialog( this, "EditCommandDialog", true );
00176 
00177   QObject::connect( listviewCommands,
00178                     SIGNAL( doubleClicked( QListViewItem * ) ),
00179                     this,
00180                     SLOT( slotCommandDoubleClicked( QListViewItem *) ) );
00181 };
00182 
00183 /*  
00184  *  Destroys the object and frees any allocated resources
00185  */
00186 SIG_LanguageParameters::~SIG_LanguageParameters()
00187 {
00188     // no need to delete child widgets, Qt does it all for us
00189 };
00190 
00191 void SIG_LanguageParameters::putIntoExperiment()
00192 {
00193   // we don't need to update the command as they are updated when one works on them
00194 
00195   theExperiment.robot.getLangParam()->setMemorySize( spinboxNumberOfRegisters->value() );
00196   theExperiment.robot.getLangParam()->setRegisterWidth( spinboxRegisterWidth->value() );
00197   theExperiment.robot.getLangParam()->setMaximalDelayTime( spinboxMaximalDelayTime->value() );
00198 };
00199 
00200 void SIG_LanguageParameters::getOutOfExperiment()
00201 {
00202   QListViewItemIterator it( listviewCommands );
00203   for( ; it.current(); ++it )
00204     {
00205       QString command = it.current()->text( 1 );
00206       if( theExperiment.robot.getLangParam()->hasCommand( command ) )
00207         {
00208           it.current()->setPixmap( 0, allow );
00209           it.current()->setText( 2, QString::number( theExperiment.robot.getLangParam()->getCommand( command )->getDuration() ) );
00210         }
00211       else
00212         {
00213           it.current()->setPixmap( 0, disallow );
00214           it.current()->setText( 2, "0" );
00215         }
00216     }
00217 
00218   spinboxNumberOfRegisters->setValue( theExperiment.robot.getLangParam()->getMemorySize() );
00219   spinboxRegisterWidth->setValue( theExperiment.robot.getLangParam()->getRegisterWidth() );
00220   spinboxMaximalDelayTime->setValue( theExperiment.robot.getLangParam()->getMaximalDelayTime() );
00221 };
00222 
00223 void SIG_LanguageParameters::slotPushButtonEditClicked()
00224 {
00225   slotCommandDoubleClicked( listviewCommands->currentItem() );
00226 };
00227 
00228 void SIG_LanguageParameters::slotPushButtonAllowAllClicked()
00229 {
00230   QListViewItemIterator it( listviewCommands );
00231   for( ; it.current(); ++it )
00232     {
00233       QString command = it.current()->text( 1 );
00234       if( !theExperiment.robot.getLangParam()->hasCommand( command ) )
00235         theExperiment.robot.getLangParam()->addCommand( command, new SIGEL_Robot::SIG_CommandParameters() );
00236       SIGEL_Robot::SIG_CommandParameters *commandParameters = theExperiment.robot.getLangParam()->getCommand( command );
00237       commandParameters->setDuration( it.current()->text( 2 ).toDouble() );
00238       it.current()->setPixmap( 0, allow );
00239     }
00240 };
00241 
00242 void SIG_LanguageParameters::slotPushButtonDisallowAllClicked()
00243 {
00244   QListViewItemIterator it( listviewCommands );
00245   for( ; it.current(); ++it )
00246     {
00247       QString command = it.current()->text( 1 );
00248       theExperiment.robot.getLangParam()->removeCommand( command );
00249       it.current()->setPixmap( 0, disallow );
00250     }
00251 };
00252 
00253 void SIG_LanguageParameters::slotCommandDoubleClicked( QListViewItem *theItem )
00254 {
00255   if( theItem )
00256     {
00257       // lets collect all selected commands
00258       int numberOfSelectedCommands = 0;
00259       QListViewItemIterator listIt( listviewCommands );
00260       for( ; listIt.current(); ++listIt )
00261         {
00262           if( listIt.current()->isSelected() )
00263             ++numberOfSelectedCommands;
00264         }
00265       
00266       QString command = theItem->text( 1 ); // HAS TO BE IN THE TRUE-BRANCH OF IF!!!
00267       SIG_EditCommandDialog editCommandDialog( this, "EditCommandDialog", true );
00268       if( numberOfSelectedCommands == 1 )
00269         {
00270           editCommandDialog.setCaption( "Edit command " + command );
00271           editCommandDialog.textlabelCommand->setText( "Command: " + command );
00272           if( theExperiment.robot.getLangParam()->hasCommand( command ) )
00273             editCommandDialog.radiobuttonAllow->setChecked( true );
00274           else
00275             editCommandDialog.radiobuttonDisallow->setChecked( true );
00276           editCommandDialog.lineeditDuration->setText( theItem->text( 2 ) );
00277           editCommandDialog.lineeditDuration->setFocus();
00278         }
00279       else
00280         {
00281           editCommandDialog.setCaption( "Edit commands..." );
00282           editCommandDialog.textlabelCommand->hide( );
00283           if( theExperiment.robot.getLangParam()->hasCommand( command ) )
00284             editCommandDialog.radiobuttonAllow->setChecked( true );
00285           else
00286             editCommandDialog.radiobuttonDisallow->setChecked( true );
00287           editCommandDialog.lineeditDuration->setText( theItem->text( 2 ) );
00288           editCommandDialog.lineeditDuration->setFocus();
00289           editCommandDialog.resize( QSize() );
00290         }
00291 
00292       QListViewItemIterator listIt2( listviewCommands );
00293       
00294       switch( editCommandDialog.exec() )
00295         {
00296           // the OK button was clicked
00297         case QDialog::Accepted:
00298           // iterate over the listview
00299           for( ; listIt2.current(); listIt2++ )
00300             {
00301               // check if the current is selected
00302               if( listIt2.current()->isSelected() )
00303                 {
00304                   // which command are we in currently
00305                   QString currentCommand = listIt2.current()->text( 1 );
00306                   // check if the command is allowed
00307                   if( editCommandDialog.radiobuttonDisallow->isChecked() )
00308                     {
00309                       // the command is not allowed...
00310                       theExperiment.robot.getLangParam()->removeCommand( currentCommand );
00311                       listIt2.current()->setPixmap( 0, disallow );
00312                       listIt2.current()->setText( 2, editCommandDialog.lineeditDuration->text() );
00313                     }
00314                   else
00315                     {
00316                       // we will work on command parameters, so we need this pointer.
00317                       SIGEL_Robot::SIG_CommandParameters *commandParameters = 0;
00318                       
00319                       // lets see if we first need to add the command and create a new SIG_CommandParameters object...
00320                       if( !theExperiment.robot.getLangParam()->hasCommand( currentCommand ) )
00321                         // there is no such command, so we first have to add it...
00322                         theExperiment.robot.getLangParam()->addCommand( currentCommand, new SIGEL_Robot::SIG_CommandParameters() );
00323                       
00324                       // lets enter the data into the SIG_CommandParameters object associated with the command
00325                       commandParameters = theExperiment.robot.getLangParam()->getCommand( currentCommand );
00326                       commandParameters->setDuration( editCommandDialog.lineeditDuration->text().toDouble() );
00327                       
00328                       // lets enter the data into the GUI
00329                       listIt2.current()->setPixmap( 0, allow );
00330                       listIt2.current()->setText( 2, editCommandDialog.lineeditDuration->text() );
00331                     } // end of else
00332                 } // end of second if
00333             } // end for
00334           break;
00335           
00336         case QDialog::Rejected:
00337           break;
00338         }
00339     }
00340 };
00341 
00342 }

Generated at Mon Sep 3 01:32:26 2001 for PG 368 - SIGEL by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000