--- /dev/null
+/*
+ * Map.cpp 11/01/31
+ *
+ * Draw a map on the playground.
+ *
+ * Copyright: (c) 2007 CTU Dragons
+ * CTU FEE - Department of Control Engineering
+ * Authors: Michal Vokac, Michal Sojka
+ * License: GNU GPL v.2
+ */
+
+#include <math.h>
+#include <QPen>
+
+#include "PlaygroundScene.h"
+#include "Map.h"
+#include <map.h>
+#include <robodim.h>
+#include <iostream>
+
+Map::Map(const QPen &pen, const QBrush &brush) :
+ QObject(), QGraphicsItem()
+{
+ this->pen = pen;
+ this->brush = brush;
+ mapImage = QImage(MAP_WIDTH, MAP_HEIGHT, QImage::Format_ARGB32);
+ mapImage.fill(QColor(0, 0, 0, 200).rgba());
+ setVisible(false);
+}
+
+Map::~Map()
+{
+}
+
+QRectF Map::boundingRect() const
+{
+ return QRectF(0,0,PLAYGROUND_WIDTH_MM,PLAYGROUND_HEIGHT_MM);
+}
+
+void Map::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ Q_UNUSED(painter);
+
+ painter->setPen(pen);
+ painter->setBrush(brush);
+ painter->drawImage(QPointF(0,0),mapImage) ;
+}
+
+void Map::setPixelColor(int x, int y, QColor color)
+{
+ QRgb value;
+
+ value = color.rgb();
+
+ mapImage.setPixel(x, y, value);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Map.h 11/01/31
+ *
+ * Draw a map on the playground.
+ *
+ * Copyright: (c) 2007 CTU Dragons
+ * CTU FEE - Department of Control Engineering
+ * Authors: Michal Vokac, Michal Sojka
+ * License: GNU GPL v.2
+ */
+
+#ifndef MAP_H
+#define MAP_H
+
+#include <QGraphicsItem>
+#include <QPainter>
+#include <QObject>
+
+class Map : public QObject, public QGraphicsItem
+{
+ Q_OBJECT
+ Q_INTERFACES(QGraphicsItem);
+public:
+ Map(const QPen &pen = QPen(), const QBrush &brush = QBrush());
+ ~Map();
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ void setPixelColor(int x, int y, QColor color);
+public slots:
+private:
+ QImage mapImage;
+ QPen pen;
+ QBrush brush;
+};
+
+#endif
* Copyright: (c) 2007 CTU Dragons
* CTU FEE - Department of Control Engineering
* Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
- * Edit: Petr Kubiznak
+ * Michal Vokac, Petr Kubiznak
* License: GNU GPL v.2
*/
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
+#include <QImage>
+
using namespace Qt;
#include "PlaygroundScene.h"
#include "../robofsm/corns_configs.h"
//margin around borders (just for better look)
-#define MARGIN 40
+#define MARGIN 40
//playground borders
-#define BORDER_WIDTH 22
-#define BORDER_COLOR black
+#define BORDER_WIDTH 22
+#define BORDER_COLOR black
//playground
-#define PLAYGROUND_WIDTH 3000
-#define PLAYGROUND_HEIGHT 2100
-#define PLAYGROUND_COLOR green
+/*FIXME update accordingly to playground dimmensions in robodim.h
+Why robomon playground do not accept defined values from robodim.h?
+*/
+#define PLAYGROUND_WIDTH PLAYGROUND_WIDTH_MM
+#define PLAYGROUND_HEIGHT PLAYGROUND_HEIGHT_MM
+#define PLAYGROUND_COLOR green
//squares
#define SQUARE_WIDTH 350
g = addEllipse(QRect(centerX - FIGURE_WIDTH/2, centerY - FIGURE_WIDTH/2, FIGURE_WIDTH, FIGURE_WIDTH), QPen(), QBrush(QUEEN_COLOR));
g->setZValue(3);
}
-
PlaygroundScene::PlaygroundScene(QObject *parent)
: QGraphicsScene(parent)
{
/* All scene units are milimeters */
setSceneRect(QRectF(QPointF(-MARGIN, -MARGIN), QPointF(PLAYGROUND_WIDTH+MARGIN, PLAYGROUND_HEIGHT+MARGIN)));
-
+
/* playground border */
addRect(QRect(0, 0, -BORDER_WIDTH, PLAYGROUND_HEIGHT), QPen(), QBrush(BORDER_COLOR)); //left
addRect(QRect(-BORDER_WIDTH, PLAYGROUND_HEIGHT, PLAYGROUND_WIDTH + 2*BORDER_WIDTH, BORDER_WIDTH), QPen(), QBrush(BORDER_COLOR)); //top
addRect(QRect(PLAYGROUND_WIDTH, 0, BORDER_WIDTH, PLAYGROUND_HEIGHT), QPen(), QBrush(BORDER_COLOR)); //right
addRect(QRect(-BORDER_WIDTH, -BORDER_WIDTH, PLAYGROUND_WIDTH + 2*BORDER_WIDTH, BORDER_WIDTH), QPen(), QBrush(BORDER_COLOR)); //bottom
-
+
/* playground */
tempRect = addRect(QRect(0, 0, PLAYGROUND_WIDTH, PLAYGROUND_HEIGHT), QPen(), PLAYGROUND_COLOR);
tempRect->setZValue(0);
-
+
/* squares */
for(int i = 0; i<6; i++){
for(int j = 0; j<6; j++){
obstacle->setVisible(false);
obstacle->setPos(QPointF(2000, 1000));
this->addItem(obstacle);
-
- initMap();
}
PlaygroundScene::~PlaygroundScene()
QPointF PlaygroundScene::scene2world(QPointF scenePos)
{
return QPointF((scenePos.x()) / 1000.0,
- (scenePos.y()) / 1000.0);
+ (scenePos.y()) / 1000.0);
}
else
obstacle->setVisible(false);
}
-
-void PlaygroundScene::initMap()
-{
-#define MAP_RECT_SCALE 1.0
- this->map = new QGraphicsItemGroup();
- for(int i=0; i < MAP_WIDTH; i++) {
- for(int j=0; j<MAP_HEIGHT; j++) {
- rects[i][j] = new QGraphicsRectItem(
- QRectF(i*MAP_CELL_SIZE_MM + MAP_CELL_SIZE_MM * (1 - MAP_RECT_SCALE)/2,
- (MAP_HEIGHT-1-j)*MAP_CELL_SIZE_MM + MAP_CELL_SIZE_MM * (1 - MAP_RECT_SCALE)/2,
- MAP_CELL_SIZE_MM * MAP_RECT_SCALE ,
- MAP_CELL_SIZE_MM * MAP_RECT_SCALE));
- rects[i][j]->setPen(QPen(Qt::NoPen));
- rects[i][j]->setBrush(QBrush(Qt::lightGray));
- map->addToGroup(rects[i][j]);
- }
- }
- map->setVisible(false);
- map->setZValue(4);
- addItem(map);
-}
-
-void PlaygroundScene::showMap(bool show)
-{
- map->setVisible(show);
-}
-
-void PlaygroundScene::setMapColor(int x, int y, QColor color)
-{
- color.setAlpha(200);
- rects[x][y]->setBrush(QBrush(color));
-}
#define PLAYGROUND_SCENE_H
#include <QGraphicsScene>
+#include <QPainter>
#include <map.h>
#define SIM_OBST_SIZE_M 0.3
~PlaygroundScene();
static QPointF scene2world(QPointF scenePos);
static QPointF world2scene(QPointF worldPos);
- void setMapColor(int x, int y, QColor color);
-
signals:
void obstacleChanged(QPointF pos);
void mouseMoved(QPointF pos);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
private:
- void initMap();
- QGraphicsItemGroup *map;
- QGraphicsRectItem *rects[MAP_WIDTH][MAP_HEIGHT]; // This must be slow - convert to pixmap. -- M.S.
QGraphicsEllipseItem *obstacle;
void paintCorns(int side_configuration, int center_configuration);
void putPawn(QGraphicsEllipseItem *g, int centerX, int centerY);
void putKing(QGraphicsEllipseItem *g, int centerX, int centerY);
void putQueen(QGraphicsEllipseItem *g, int centerX, int centerY);
-
+
public slots:
void showObstacle(int val);
- void showMap(bool show);
};
#endif
createOrte();
createRobots();
createActions();
+ createMap();
// connect(vidle, SIGNAL(valueChanged(int)),
// robotEstPosBest, SLOT(setVidle(int)));
powerGroupBox->setLayout(layout);
}
-#if 0
-void RobomonAtlantis::createMotorsGroupBox()
-{
- enginesGroupBox = new QGroupBox(tr("Motors"));
- QVBoxLayout *layout = new QVBoxLayout();
- QHBoxLayout *layout1 = new QHBoxLayout();
- QHBoxLayout *layout2 = new QHBoxLayout();
-
- leftMotorSlider = new QSlider(Qt::Vertical);
- rightMotorSlider = new QSlider(Qt::Vertical);
- bothMotorsCheckBox = new QCheckBox(tr("Lock both"));
- stopMotorsPushButton = new QPushButton(tr("Stop Motors"));
-
- leftMotorSlider->setMinimum(-100);
- leftMotorSlider->setMaximum(100);
- leftMotorSlider->setTracking(false);
- leftMotorSlider->setTickPosition(QSlider::TicksLeft);
-
- rightMotorSlider->setMinimum(-100);
- rightMotorSlider->setMaximum(100);
- rightMotorSlider->setTracking(false);
- rightMotorSlider->setTickPosition(QSlider::TicksRight);
-
- stopMotorsPushButton->setMaximumWidth(90);
-
- layout1->addWidget(leftMotorSlider);
- layout1->addWidget(MiscGui::createLabel("0"));
- layout1->addWidget(rightMotorSlider);
-
- layout2->addWidget(bothMotorsCheckBox);
-
- layout->addWidget(MiscGui::createLabel("100"));
- layout->addLayout(layout1);
- layout->addWidget(MiscGui::createLabel("-100"));
- layout->addLayout(layout2);
- layout->addWidget(stopMotorsPushButton);
- enginesGroupBox->setLayout(layout);
-}
-#endif
-
void RobomonAtlantis::createRobots()
{
robotRefPos = new Robot("Ref", QPen(Qt::darkBlue), QBrush(Qt::NoBrush));
}
+void RobomonAtlantis::createMap()
+{
+ mapImage = new Map(QPen(Qt::lightGray), QBrush(Qt::NoBrush));
+ mapImage->setZValue(3);
+
+ playgroundScene->addItem(mapImage);
+}
+
/**********************************************************************
* GUI actions
**********************************************************************/
disconnect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
}
}
- playgroundScene->showMap(show);
+ mapImage->setVisible(show);
}
void RobomonAtlantis::paintMap()
if (cell->flags & MAP_FLAG_DET_OBST)
color = cyan;
- playgroundScene->setMapColor(i, j, color);
+ mapImage->setPixelColor(i, j, color);
}
}
}
#include "PlaygroundScene.h"
#include "playgroundview.h"
#include "Robot.h"
+#include "Map.h"
#include <roboorte_robottype.h>
#include "trail.h"
#include "hokuyoscan.h"
class QSlider;
class QProgressBar;
class QFont;
+class QImage;
class RobomonAtlantis : public QWidget
{
void motionStatusReceivedSignal();
void actualPositionReceivedSignal();
void powerVoltageReceivedSignal();
-
+
public slots:
void showMap(bool show);
void useOpenGL(bool use);
void resetTrails();
private slots:
/************************************************************
- * GUI actions
+ * GUI actions
************************************************************/
void setVoltage33(int state);
void setVoltage50(int state);
void setTeamColor(int plug);
/************************************************************
- * ORTE
+ * ORTE
************************************************************/
void motionStatusReceived();
void actualPositionReceived();
void createRobots();
void createActions();
+ void createMap();
QVBoxLayout *leftLayout;
QVBoxLayout *rightLayout;
Robot *robotEstPosBest;
Robot *robotEstPosIndepOdo;
Robot *robotEstPosOdo;
+
+ Map *mapImage;
private:
Trail *trailRefPos;
Trail *trailEstPosBest;
void openSharedMemory();
bool sharedMemoryOpened;
QTimer *mapTimer;
-
+
/* obstacle simulation */
double distanceToWallHokuyo(int beamnum);
double distanceToObstacleHokuyo(int beamnum, Point obstacle, double obstacleSize);
Point simulatedObstacle;
/************************************************************
- * ORTE
+ * ORTE
************************************************************/
void createOrte();
RobomonTuning.cpp \
PlaygroundScene.cpp \
Robot.cpp \
+ Map.cpp \
Widget.cpp \
GlWidget.cpp \
MiscGui.cpp \
RobomonTuning.h \
PlaygroundScene.h \
Robot.h \
+ Map.h \
Painter.h \
Widget.h \
GlWidget.h \