icubsimulatorviewer.cpp
1 /********************************************************************************
2  * FARSA Experiments Library *
3  * Copyright (C) 2007-2012 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21  ********************************************************************************/
22 
23 #ifdef FARSA_USE_YARP_AND_ICUB
24 
25 #include "icubsimulatorviewer.h"
26 #include <QLabel>
27 #include <QVBoxLayout>
28 #include <QMenu>
29 #include <QAction>
30 
31 using namespace qglviewer;
32 
33 namespace farsa {
34 
35 iCubSimulatorViewer::iCubSimulatorViewer( iCubSimulator* icubsim )
37  this->icubsimulator = icubsim;
38 }
39 
41 }
42 
43 void iCubSimulatorViewer::fillActionsMenu( QMenu* actionsMenu ) {
44  actionsMenu->addAction( "Start", icubsimulator, SLOT(start()) );
45  actionsMenu->addAction( "Suspend", icubsimulator, SLOT(suspend()) );
46  actionsMenu->addAction( "Step", icubsimulator, SLOT(step()) );
47 }
48 
49 QList<ParameterSettableUIViewer> iCubSimulatorViewer::getViewers( QWidget* parent, Qt::WindowFlags flags ) {
50  renderworld = new RenderWorld( parent );
51  renderworld->setWorld(icubsimulator->getWorld());
52  renderworld->setWindowFlags( flags );
53  wMatrix icubTm = icubsimulator->getICub()->matrix();
54  wVector cameraDefaultPosition = icubTm.transformVector( wVector( -0.8f, 0.0f, +0.6f ) );
55  renderworld->camera()->setPosition( Vec( cameraDefaultPosition[0], cameraDefaultPosition[1], cameraDefaultPosition[2] ) );
56  renderworld->camera()->setUpVector( Vec(0.0f, 0.0f, 1.0f) );
57  renderworld->camera()->lookAt( Vec( icubTm.w_pos[0], icubTm.w_pos[1], icubTm.w_pos[2] ) );
58  //connect( (icubsimulator->getWorld()), SIGNAL(advanced()), renderworld, SLOT(update()) );
59  QList<ParameterSettableUIViewer> viewsList;
60  viewsList.append( ParameterSettableUIViewer( renderworld, "iCub Simulator", QString(), "3D visualization of the world and the iCub robot" ) );
61  return viewsList;
62 }
63 
64 } // end namespace farsa
65 
66 #endif // FARSA_USE_YARP_AND_ICUB