experiments/icubsimulator/src/icubsimulatorviewer.cpp

00001 /********************************************************************************
00002  *  FARSA Experiments Library                                                   *
00003  *  Copyright (C) 2007-2012                                                     *
00004  *  Gianluca Massera <emmegian@yahoo.it>                                        *
00005  *  Stefano Nolfi <stefano.nolfi@istc.cnr.it>                                   *
00006  *  Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it>                         *
00007  *                                                                              *
00008  *  This program is free software; you can redistribute it and/or modify        *
00009  *  it under the terms of the GNU General Public License as published by        *
00010  *  the Free Software Foundation; either version 2 of the License, or           *
00011  *  (at your option) any later version.                                         *
00012  *                                                                              *
00013  *  This program is distributed in the hope that it will be useful,             *
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00016  *  GNU General Public License for more details.                                *
00017  *                                                                              *
00018  *  You should have received a copy of the GNU General Public License           *
00019  *  along with this program; if not, write to the Free Software                 *
00020  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00021  ********************************************************************************/
00022 
00023 #ifdef FARSA_USE_YARP_AND_ICUB
00024 
00025 #include "icubsimulatorviewer.h"
00026 #include <QLabel>
00027 #include <QVBoxLayout>
00028 #include <QMenu>
00029 #include <QAction>
00030 
00031 using namespace qglviewer;
00032 
00033 namespace farsa {
00034 
00035 iCubSimulatorViewer::iCubSimulatorViewer( iCubSimulator* icubsim )
00036     : ComponentUI() {
00037     this->icubsimulator = icubsim;
00038 }
00039 
00040 iCubSimulatorViewer::~iCubSimulatorViewer() {
00041 }
00042 
00043 void iCubSimulatorViewer::fillActionsMenu( QMenu* actionsMenu ) {
00044     actionsMenu->addAction( "Start", icubsimulator, SLOT(start()) );
00045     actionsMenu->addAction( "Suspend", icubsimulator, SLOT(suspend()) );
00046     actionsMenu->addAction( "Step", icubsimulator, SLOT(step()) );
00047 }
00048 
00049 QList<ComponentUIViewer> iCubSimulatorViewer::getViewers( QWidget* parent, Qt::WindowFlags flags ) {
00050     renderworld = new RenderWorld( parent );
00051     renderworld->setWorld(icubsimulator->getWorld());
00052     renderworld->setWindowFlags( flags );
00053     wMatrix icubTm = icubsimulator->getICub()->matrix();
00054     wVector cameraDefaultPosition = icubTm.transformVector( wVector( -0.8f, 0.0f, +0.6f ) );
00055     renderworld->camera()->setPosition( Vec( cameraDefaultPosition[0], cameraDefaultPosition[1], cameraDefaultPosition[2] ) );
00056     renderworld->camera()->setUpVector( Vec(0.0f, 0.0f, 1.0f) );
00057     renderworld->camera()->lookAt( Vec( icubTm.w_pos[0], icubTm.w_pos[1], icubTm.w_pos[2] ) );
00058     //connect( (icubsimulator->getWorld()), SIGNAL(advanced()), renderworld, SLOT(update()) );
00059     QList<ComponentUIViewer> viewsList;
00060     viewsList.append( ComponentUIViewer( renderworld, "iCub Simulator", QString(), "3D visualization of the world and the iCub robot" ) );
00061     return viewsList;
00062 }
00063 
00064 } // end namespace farsa
00065 
00066 #endif // FARSA_USE_YARP_AND_ICUB