Commit 06ea75ec authored by roangel's avatar roangel
Browse files

Added linker object that will link CFZones to CFs

parent 83e4ba26
......@@ -233,6 +233,7 @@ set(MY_CPP_SOURCES # compilation of sources
${MY_LIB_PATH_SRC}/marker.cpp
${MY_LIB_PATH_SRC}/rosNodeThread.cpp
${MY_LIB_PATH_SRC}/crazyFly.cpp
${MY_LIB_PATH_SRC}/CFLinker.cpp
)
......
#ifndef CFLINKER_H
#define CFLINKER_H
#include "globalDefinitions.h"
#include "crazyFly.h"
#include "crazyFlyZone.h"
class CFLinker
{
public:
explicit CFLinker();
~CFLinker();
void link(crazyFly* crazyfly, crazyFlyZone* crazyfly_zone);
void link(crazyFlyZone* crazyfly_zone, crazyFly* crazyfly);
void unlink(crazyFly* crazyfly, crazyFlyZone* crazyfly_zone);
private:
struct link {
int cf_zone_index;
std::string cf_name;
};
std::vector<struct link> links;
};
#endif
......@@ -34,6 +34,11 @@ public:
void setScaleCFs(double scale);
// linking stuff
void assignCFZone(int cf_zone_index);
void removeAssigned();
bool isAssigned();
private:
// info to fill by message
......@@ -49,6 +54,10 @@ private:
// info for plotting CF
qreal m_width;
qreal m_height;
// linking stuff
bool m_assigned;
int m_assigned_cf_zone_index;
};
......
......@@ -10,6 +10,7 @@ class crazyFlyZone : public myGraphicsRectItem
{
public:
explicit crazyFlyZone(const QRectF & rect, int index, QGraphicsItem * parent = 0);
~crazyFlyZone();
int getIndex();
void setIndex(int index);
......@@ -17,11 +18,21 @@ public:
void setLabelPosition();
void updateLabel(QString string);
void rectSizeChanged();
// stuff for linking
void linkCF(std::string cf_name);
bool isLinked();
void removeLink();
protected:
private:
int _index;
QGraphicsSimpleTextItem* label;
// stuff for linking
bool m_linked;
std::string m_crazyfly_linked_name; //in the future this will be a vector of crazyFlies maybe
};
......
......@@ -12,8 +12,10 @@
#include "rosNodeThread.h"
#include "marker.h"
#include "crazyFly.h"
#include "CFLinker.h"
#endif
#include "ui_mainguiwindow.h"
#include "myGraphicsScene.h"
#include "globalDefinitions.h"
......@@ -110,10 +112,12 @@ private:
myGraphicsScene* scene;
void _init();
#ifdef CATKIN_MAKE
rosNodeThread* _rosNodeThread;
std::vector<Marker*> markers_vector;
std::vector<crazyFly*> crazyflies_vector;
CFLinker cf_linker;
#endif
};
......
#include "CFLinker.h"
CFLinker::CFLinker()
{
}
CFLinker::~CFLinker()
{
}
void CFLinker::link(crazyFly* crazyfly, crazyFlyZone* crazyfly_zone)
{
struct link tmp_link;
tmp_link.cf_zone_index = crazyfly_zone->getIndex();
tmp_link.cf_name = crazyfly->getName();
crazyfly_zone->linkCF(tmp_link.cf_name);
crazyfly->assignCFZone(tmp_link.cf_zone_index);
links.push_back(tmp_link);
}
void CFLinker::link(crazyFlyZone* crazyfly_zone, crazyFly* crazyfly)
{
link(crazyfly, crazyfly_zone);
}
void CFLinker::unlink(crazyFly* crazyfly, crazyFlyZone* crazyfly_zone)
{
bool found = false;
int index_found;
for(int i = 0; i < links.size(); i++)
{
if(links[i].cf_zone_index == crazyfly_zone->getIndex())
{
if(crazyfly->getName() == links[i].cf_name)
{
found = true;
index_found = i;
}
}
}
if(found)
{
crazyfly_zone->removeLink();
crazyfly->removeAssigned();
links.erase(links.begin() + index_found);
}
}
......@@ -10,6 +10,7 @@ crazyFly::crazyFly(const CrazyflieData* p_crazyfly_msg, QGraphicsItem * parent)
updateCF(p_crazyfly_msg);
m_width = DRONE_WIDTH;
m_height = DRONE_HEIGHT;
m_assigned = false;
}
crazyFly::~crazyFly()
......@@ -54,3 +55,23 @@ void crazyFly::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
{
this->renderer()->render(painter,this->boundingRect());
}
void crazyFly::assignCFZone(int cf_zone_index)
{
m_assigned = true;
m_assigned_cf_zone_index = cf_zone_index;
}
void crazyFly::removeAssigned()
{
if(m_assigned)
{
m_assigned = false;
m_assigned_cf_zone_index = -1;
}
}
bool crazyFly::isAssigned()
{
return m_assigned;
}
......@@ -6,6 +6,11 @@ crazyFlyZone::crazyFlyZone(const QRectF & rect, int index, QGraphicsItem * pare
{
this->setPen(QPen(Qt::black, 0));
setIndex(index);
m_linked = false;
}
crazyFlyZone::~crazyFlyZone()
{
}
void crazyFlyZone::updateLabel(QString string)
......@@ -45,3 +50,23 @@ void crazyFlyZone::rectSizeChanged() // pure virtual coming from parent
{
setLabelPosition();
}
void crazyFlyZone::linkCF(std::string cf_name)
{
m_crazyfly_linked_name = cf_name;
m_linked = true;
}
bool crazyFlyZone::isLinked()
{
return m_linked;
}
void crazyFlyZone::removeLink()
{
if(m_linked)
{
m_crazyfly_linked_name = "";
m_linked = false;
}
}
......@@ -23,27 +23,19 @@
using namespace d_fall_pps;
#endif
#ifdef CATKIN_MAKE
MainGUIWindow::MainGUIWindow(int argc, char **argv, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainGUIWindow)//,
// _rosNodeThread(argc, argv, "/ViconDataPublisher/ViconData")
{
_rosNodeThread = new rosNodeThread(argc, argv, "/ViconDataPublisher/ViconData");
ui->setupUi(this);
_init();
}
#else
MainGUIWindow::MainGUIWindow(int argc, char **argv, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainGUIWindow)
#ifdef CATKIN_MAKE
,cf_linker()
#endif
{
#ifdef CATKIN_MAKE
_rosNodeThread = new rosNodeThread(argc, argv, "/ViconDataPublisher/ViconData");
#endif
ui->setupUi(this);
_init();
}
#endif
MainGUIWindow::~MainGUIWindow()
......@@ -100,11 +92,14 @@ void MainGUIWindow::_init()
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// scene
scene = new myGraphicsScene(ui->frame_drawing);
scene->setSceneRect(-100 * FROM_METERS_TO_UNITS, -100 * FROM_METERS_TO_UNITS, 200 * FROM_METERS_TO_UNITS, 200 * FROM_METERS_TO_UNITS);
ui->graphicsView->setScene(scene);
// connections
QObject::connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), scene, SLOT(removeCrazyFlyZone(int)));
QObject::connect(scene, SIGNAL(numCrazyFlyZonesChanged(int)), this, SLOT(doNumCrazyFlyZonesChanged(int)));
QObject::connect(ui->tabWidget, SIGNAL(currentChanged(int)), scene, SLOT(setSelectedCrazyFlyZone(int)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment