00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 #ifndef USE_SOWIN
00035
00036 #include "../include/IPSA/ipsaclasses.h"
00037 #include "../include/IPSA/IpsaSimulator.h"
00038 #include "../include/IPSA/viewer/IpsaDialog.h"
00039 #include "../include/IPSA/viewer/instructions/NVInstructions.h"
00040
00041 #include <qpushbutton.h>
00042 #include <qlabel.h>
00043 #include <qlineedit.h>
00044 #include <qcombobox.h>
00045 #include <qlayout.h>
00046 #include <qtooltip.h>
00047 #include <qwhatsthis.h>
00048
00049 #include <sstream>
00050
00051
00059 #if IS_QT4
00060 IpsaDialog::IpsaDialog(IpsaSimulator* simulator, QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
00061 : QDialog(parent, fl),
00062 #else
00063 IpsaDialog::IpsaDialog(IpsaSimulator* simulator, QWidget* parent, const char* name, bool modal, WFlags fl )
00064 : QDialog(parent, name, modal, fl),
00065 #endif
00066 ipsaSimulator(simulator),
00067 bodySelectionName(QString("body")),
00068 jointSelectionName(QString("joint"))
00069 {
00070 if ( !name )
00071 setName( "IpsaDialog" );
00072 this->buildGui();
00073
00074 commandMap = NVInstructions::CreateInstructionMap(ipsaSimulator);
00075
00076 #if IS_QT4
00077 modeSelector->addItem( bodySelectionName );
00078 modeSelector->addItem( jointSelectionName );
00079 #else
00080 modeSelector->insertItem( bodySelectionName );
00081 modeSelector->insertItem( jointSelectionName );
00082 #endif
00083
00084 reloadData();
00085 }
00086
00087
00091 IpsaDialog::~IpsaDialog()
00092 {
00093
00094 }
00095
00096
00101 void IpsaDialog::getSetValue()
00102 {
00103 Instruction* instr = commandMap[currentCommand.latin1()];
00104 if (NULL == instr)
00105 return;
00106
00107
00108 static std::vector<std::string> commandParameters;
00109 commandParameters.clear();
00110
00111 const unsigned int PARAMETER_COUNT = instr->getCommandParameterCount();
00112
00113 commandParameters.push_back(currentCommand.latin1());
00114 if (PARAMETER_COUNT > 0)
00115 commandParameters.push_back(currentNode.latin1());
00116 if (PARAMETER_COUNT > 1)
00117 commandParameters.push_back(value1->text().latin1());
00118 if (PARAMETER_COUNT > 2)
00119 commandParameters.push_back(value2->text().latin1());
00120 if (PARAMETER_COUNT > 3)
00121 commandParameters.push_back(value3->text().latin1());
00122
00123
00124 std::ostringstream answer;
00125 unsigned int numberOfReturnValues;
00126 instr->findAndExecute(commandParameters, answer, numberOfReturnValues);
00127 this->evaluateAnswer(answer, numberOfReturnValues);
00128 }
00129
00130
00134 void IpsaDialog::evaluateAnswer(const std::ostringstream& answer, unsigned int numberOfReturnValues)
00135 {
00136 if (answer.str().empty())
00137 return;
00138
00139 std::vector<float> resultVector(numberOfReturnValues, 0.0f);
00140 if(convertAnswerToVector(answer.str(), resultVector, numberOfReturnValues))
00141 convertAnswerToType<float>(answer.str(), resultVector.at(0));
00142
00143 QString floatString;
00144 if (1 <= numberOfReturnValues)
00145 {
00146 floatString.setNum(resultVector.at(0));
00147 value1->setText(floatString);
00148 }
00149 if (2 <= numberOfReturnValues)
00150 {
00151 floatString.setNum(resultVector.at(1));
00152 value2->setText(floatString);
00153 }
00154 if (3 <= numberOfReturnValues)
00155 {
00156 floatString.setNum(resultVector.at(2));
00157 value3->setText(floatString);
00158 }
00159 }
00160
00161
00166 void IpsaDialog::modeSelected(const QString& mode)
00167 {
00168 static std::map<std::string, std::string> BodyMap;
00169 BodyMap.clear();
00170 nodeList->clear();
00171 commandList->clear();
00172
00173 if (mode.contains(bodySelectionName))
00174 BodyMap = Instruction::GetAllNodesOfTypeFromViewer<SoPhysics>(ipsaSimulator);
00175 else
00176 BodyMap = Instruction::GetAllNodesOfTypeFromViewer<SoJoint>(ipsaSimulator);
00177
00178
00179 for (std::map<std::string, std::string>::iterator it = BodyMap.begin(); it != BodyMap.end(); it++)
00180 {
00181 #if IS_QT4
00182 nodeList->addItem( it->first.c_str() );
00183 #else
00184 nodeList->insertItem( it->first.c_str() );
00185 #endif
00186 }
00187
00188
00189 for (std::map<std::string, Instruction*>::iterator it = commandMap.begin(); it != commandMap.end(); it++)
00190 {
00191 if (std::string::npos != it->first.find(mode.latin1()))
00192 {
00193 #if IS_QT4
00194 commandList->addItem( it->first.c_str() );
00195 #else
00196 commandList->insertItem( it->first.c_str() );
00197 #endif
00198 }
00199 }
00200
00201 this->nodeSelected(nodeList->currentText());
00202 this->commandSelected(commandList->currentText());
00203 }
00204
00205
00209 void IpsaDialog::nodeSelected(const QString& node)
00210 {
00211 currentNode = node;
00212 }
00213
00214
00219 void IpsaDialog::commandSelected(const QString& command)
00220 {
00221 currentCommand = command;
00222
00223 unsigned int parameterCount = commandMap[currentCommand.latin1()]->getCommandParameterCount();
00224
00225 value1->setEnabled(1 < parameterCount);
00226 value2->setEnabled(2 < parameterCount);
00227 value3->setEnabled(3 < parameterCount);
00228
00229 value1->setText("0");
00230 value2->setText("0");
00231 value3->setText("0");
00232 }
00233
00234
00239 void IpsaDialog::reloadData()
00240 {
00241 modeSelected(modeSelector->currentText());
00242 }
00243
00244
00248 void IpsaDialog::buildGui()
00249 {
00250 setSizeGripEnabled( TRUE );
00251
00252 QWidget* privateLayoutWidget = new QWidget( this, "Layout5" );
00253 privateLayoutWidget->setGeometry( QRect( 500, 30, 84, 180 ) );
00254 Layout5 = new QVBoxLayout( privateLayoutWidget, 0, 6, "Layout5");
00255
00256 value1label = new QLabel( this, "value1label" );
00257 value1label->setGeometry( QRect( 40, 70, 90, 21 ) );
00258
00259 value2lable = new QLabel( this, "value2lable" );
00260 value2lable->setGeometry( QRect( 40, 100, 90, 21 ) );
00261
00262 value3label = new QLabel( this, "value3label" );
00263 value3label->setGeometry( QRect( 40, 130, 90, 21 ) );
00264
00265 value1 = new QLineEdit( this, "value1" );
00266 value1->setGeometry( QRect( 165, 70, 160, 20 ) );
00267 value1->setText("0");
00268
00269 value2 = new QLineEdit( this, "value2" );
00270 value2->setGeometry( QRect( 165, 100, 160, 20 ) );
00271 value2->setText("0");
00272
00273 value3 = new QLineEdit( this, "value3" );
00274 value3->setGeometry( QRect( 165, 130, 160, 20 ) );
00275 value3->setText("0");
00276
00277 modeSelector = new QComboBox( FALSE, this, "modeSelector" );
00278 modeSelector->setGeometry( QRect( 40, 30, 100, 21 ) );
00279
00280 nodeList = new QComboBox( FALSE, this, "nodeList" );
00281 nodeList->setGeometry( QRect( 160, 30, 330, 21 ) );
00282
00283 commandList = new QComboBox( FALSE, this, "commandList" );
00284 commandList->setGeometry( QRect( 350, 70, 140, 20 ) );
00285
00286 action = new QPushButton( this, "apply" );
00287 action->setGeometry( QRect( 30, 170, 441, 41 ) );
00288 languageChange();
00289 resize( QSize(605, 238).expandedTo(minimumSizeHint()) );
00290
00291
00292 connect( action, SIGNAL( clicked() ), this, SLOT( getSetValue() ) );
00293 connect( modeSelector, SIGNAL( activated(const QString&) ), this, SLOT( modeSelected(const QString&) ) );
00294 connect( nodeList, SIGNAL( activated(const QString&) ), this, SLOT( nodeSelected(const QString&) ) );
00295 connect( commandList, SIGNAL( activated(const QString&) ), this, SLOT( commandSelected(const QString&) ) );
00296
00297
00298 setTabOrder( modeSelector, nodeList );
00299 setTabOrder( nodeList, value1 );
00300 setTabOrder( value1, value2 );
00301 setTabOrder( value2, value3 );
00302 setTabOrder( value3, action );
00303 setTabOrder( action, commandList );
00304 }
00305
00306
00311 void IpsaDialog::languageChange()
00312 {
00313 setCaption( tr( "Get And Set IPSA Values" ) );
00314 value1label->setText( tr( "X" ) );
00315 value2lable->setText( tr( "Y" ) );
00316 value3label->setText( tr( "Z" ) );
00317 commandList->clear();
00318 action->setText( tr( "Apply" ) );
00319 }
00320
00321 #endif