simplecontrol.cpp
1 /********************************************************************************
2  * WorldSim -- library for robot simulations *
3  * Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #include "simplecontrol.h"
21 #include "world.h"
22 #include <QLabel>
23 #include <QBoxLayout>
24 #include <QPushButton>
25 #include "renderworld.h"
26 
27 namespace farsa {
28 
29 SimpleControl::SimpleControl( QWidget* centralUI, World* world, QWidget* parent )
30  : QWidget( parent ) {
31  cui = centralUI;
32  cui->setParent( this );
33  this->world = world;
34 
35  QBoxLayout* toplay = new QVBoxLayout( this );
36 
37  //--- if cui is a RenderWorld it also add infoObject label on top
38  RenderWorld* rw = dynamic_cast<RenderWorld*>(cui);
39  if ( rw ) {
40  infoObject = new QLabel("Info about selected Object", this );
41  infoObject->setFixedHeight( 50 );
42  connect( rw, SIGNAL( drawFinished(bool) ),
43  this, SLOT( updateInfoObject() ), Qt::DirectConnection );
44  toplay->addWidget( infoObject );
45  }
46  toplay->addWidget( cui );
47 
48  QBoxLayout* inlay = new QHBoxLayout( );
49  toplay->addLayout( inlay );
50 
51  QPushButton* bt = new QPushButton( "Play", this );
52  connect( bt, SIGNAL( clicked() ),
53  world, SLOT( play() ), Qt::DirectConnection );
54  inlay->addWidget( bt );
55 
56  bt = new QPushButton( "Pause", this );
57  connect( bt, SIGNAL( clicked() ),
58  world, SLOT( pause() ), Qt::DirectConnection );
59  inlay->addWidget( bt );
60 
61  bt = new QPushButton( "Stop", this );
62  connect( bt, SIGNAL( clicked() ),
63  world, SLOT( stop() ), Qt::DirectConnection );
64  inlay->addWidget( bt );
65 
66  bt = new QPushButton( "Step", this );
67  connect( bt, SIGNAL( clicked() ),
68  world, SLOT( advance() ), Qt::DirectConnection );
69  bt->setAutoRepeat( true );
70  inlay->addWidget( bt );
71 }
72 
74  delete world;
75 }
76 
78  RenderWorld* rw = (RenderWorld*)(cui);
79  int i = rw->selectedName();
80  if ( i != -1 ) {
81  QString name = rw->graphics()[i]->object()->name();
82  wVector pos = rw->graphics()[i]->object()->matrix().w_pos;
83  infoObject->setText( QString("Name: %1 \t Pos: %2, %3, %4").arg(name).arg(pos[0]).arg(pos[1]).arg(pos[2]) );
84  }
85 }
86 
87 } // end namespace farsa