arena.h
1 /********************************************************************************
2  * FARSA Experimentes 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 #ifndef ARENA_H
24 #define ARENA_H
25 
26 #include "experimentsconfig.h"
27 #include "parametersettable.h"
28 #include "resourcesuser.h"
29 #include "world.h"
30 #include "wheeledexperimenthelper.h"
31 #include <QVector>
32 #include <QMap>
33 
34 namespace farsa {
35 
46 class FARSA_EXPERIMENTS_API Arena : public ParameterSettableInConstructor, public ConcurrentResourcesUser
47 {
48 public:
59  Arena(ConfigurationParameters& params, QString prefix);
60 
64  virtual ~Arena();
65 
76  virtual void save(ConfigurationParameters& params, QString prefix);
77 
90  static void describe(QString type);
91 
97  const QVector<PhyObject2DWrapper*>& getObjects() const
98  {
99  return m_objects2DList;
100  }
101 
107  real getZ() const
108  {
109  return m_z;
110  }
111 
117  real getWidth() const
118  {
119  return m_plane->phyObject()->sideX();
120  }
121 
127  real getHeight() const
128  {
129  return m_plane->phyObject()->sideY();
130  }
131 
140  void addRobots(QStringList robots);
141 
150  const WheeledRobot2DWrapper* getRobotWrapper(QString robotName) const;
151 
157  Box2DWrapper* getPlane();
158 
176  Box2DWrapper* createWall(QColor color, wVector start, wVector end, real thickness, real height = -1.0);
177 
188  Cylinder2DWrapper* createSmallCylinder(QColor color, real height = -1.0);
189 
200  Cylinder2DWrapper* createBigCylinder(QColor color, real height = -1.0);
201 
211  Cylinder2DWrapper* createCircularTargetArea(real radius, QColor color);
212 
223  Box2DWrapper* createRectangularTargetArea(real width, real depth, QColor color);
224 
238  bool delete2DObject(PhyObject2DWrapper* obj);
239 
248  void prepareToHandleKinematicRobotCollisions();
249 
258  void handleKinematicRobotCollisions();
259 
260 private:
271  Cylinder2DWrapper* createCylinder(QColor color, real radius, real height, Cylinder2DWrapper::Type type);
272 
284  Box2DWrapper* createBox(QColor color, real width, real depth, real height, Box2DWrapper::Type type);
285 
293  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
294 
298  const real m_z;
299 
303  QVector<PhyObject2DWrapper*> m_objects2DList;
304 
308  Box2DWrapper* const m_plane;
309 
315  QMap<QString, WheeledRobot2DWrapper*> m_robotResourceWrappers;
316 
320  World* m_world;
321 
331  static Box2DWrapper* createPlane(ConfigurationParameters& params, QString prefix, real z, Arena* arena);
332 
342  static Box2DWrapper* createPlane2(ConfigurationParameters& params, QString prefix, real z, Arena* arena);
343 };
344 
345 } // end namespace farsa
346 
347 #endif