Commit 590f03d6 authored by roangel's avatar roangel
Browse files

restructuration in LINKER. Need to see if everything goes OK. Need to unlink,...

restructuration in LINKER. Need to see if everything goes OK. Need to unlink, need to remove options, etc..
parent b05f63e7
......@@ -12,12 +12,12 @@
class CFLinker
{
public:
explicit CFLinker(Ui::MainGUIWindow* ui);
explicit CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones);
~CFLinker();
void link(int student_id, crazyFly* crazyfly, crazyFlyZone* crazyfly_zone);
void link();
void unlink(crazyFly* crazyfly, crazyFlyZone* crazyfly_zone);
void unlink();
private:
......@@ -31,6 +31,12 @@ private:
// QTableWidget m_p_table;
Ui::MainGUIWindow* m_ui;
std::vector<crazyFly*>* m_crazyflies_vector;
std::vector<crazyFlyZone*>* m_crazyfly_zones;
int getCFZoneIndexFromName(QString name);
int getCFIndexFromName(std::string name);
void addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index);
};
......
#include "CFLinker.h"
#include <QHeaderView>
CFLinker::CFLinker(Ui::MainGUIWindow* ui)
CFLinker::CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones)
{
m_ui = ui;
m_crazyflies_vector = crazyflies_vector;
m_crazyfly_zones = crazyfly_zones;
}
CFLinker::~CFLinker()
{
}
void CFLinker::link(int student_id, crazyFly* crazyfly, crazyFlyZone* crazyfly_zone)
int CFLinker::getCFZoneIndexFromName(QString name)
{
struct link tmp_link;
tmp_link.cf_zone_index = crazyfly_zone->getIndex();
tmp_link.cf_name = crazyfly->getName();
return name.split(" ")[1].toInt() - 1;
}
crazyfly_zone->linkCF(tmp_link.cf_name);
crazyfly->assignCFZone(tmp_link.cf_zone_index);
int CFLinker::getCFIndexFromName(std::string name)
{
for(int i = 0; (*m_crazyflies_vector).size(); i++)
{
if(name == (*m_crazyflies_vector)[i]->getName())
{
return i;
}
}
}
ROS_INFO("tmp_link.cf_name = %s", tmp_link.cf_name.c_str());
int row_count = m_ui->table_links->rowCount();
ROS_INFO("row_count %d", row_count);
m_ui->table_links->insertRow(row_count);
void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index)
{
m_ui->table_links->insertRow(m_ui->table_links->rowCount());
QString str_id = QString::number(student_id);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 0, new QTableWidgetItem(str_id));
QString str_cf_name = QString::fromStdString(crazyfly->getName());
QString str_cf_name = QString::fromStdString(crazyfly_name);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 1, new QTableWidgetItem(str_cf_name));
QString str_cf_zone_index = QString("CrazyFlyZone ").append(QString::number(crazyfly_zone->getIndex() + 1));
QString str_cf_zone_index = QString("CrazyFlyZone ").append(QString::number(cf_zone_index + 1));
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 2, new QTableWidgetItem(str_cf_zone_index));
}
void CFLinker::link()
{
m_ui->table_links->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
struct link tmp_link;
tmp_link.cf_zone_index = getCFZoneIndexFromName(m_ui->comboBoxCFZones->currentText());
tmp_link.cf_name = m_ui->comboBoxCFs->currentText().toStdString();
ROS_INFO("tmp_link.cf_zone_index %d", tmp_link.cf_zone_index);
ROS_INFO("tmp_link.cf_name %s", tmp_link.cf_name.c_str());
(*m_crazyfly_zones)[tmp_link.cf_zone_index]->linkCF(tmp_link.cf_name);
(*m_crazyflies_vector)[getCFIndexFromName(tmp_link.cf_name)]->assignCFZone(tmp_link.cf_zone_index);
addNewRow(m_ui->spinBox_student_ids->value(), tmp_link.cf_name, tmp_link.cf_zone_index);
links.push_back(tmp_link);
// TODO: remove options linked from available ones
}
void CFLinker::unlink(crazyFly* crazyfly, crazyFlyZone* crazyfly_zone)
void CFLinker::unlink()
{
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;
}
}
}
// 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);
}
// if(found)
// {
// crazyfly_zone->removeLink();
// crazyfly->removeAssigned();
// links.erase(links.begin() + index_found);
// }
}
......@@ -30,7 +30,6 @@ MainGUIWindow::MainGUIWindow(int argc, char **argv, QWidget *parent) :
{
#ifdef CATKIN_MAKE
_rosNodeThread = new rosNodeThread(argc, argv, "/ViconDataPublisher/ViconData");
cf_linker = new CFLinker(ui);
#endif
ui->setupUi(this);
_init();
......@@ -101,6 +100,7 @@ void MainGUIWindow::_init()
ui->table_links->horizontalHeader()->setFont(fnt);
ui->table_links->horizontalHeader()->setDefaultSectionSize(90);
// ui->table_links->verticalHeader()->setDefaultSectionSize(20);
ui->table_links->verticalHeader()->setDefaultSectionSize(20);
const int rowCount = ui->table_links->rowCount();
......@@ -120,6 +120,9 @@ void MainGUIWindow::_init()
ui->graphicsView->setScene(scene);
// after scene is created, create CFlinker
cf_linker = new CFLinker(ui, &crazyflies_vector, &scene->crazyfly_zones);
// connections
QObject::connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), scene, SLOT(removeCrazyFlyZone(int)));
QObject::connect(scene, SIGNAL(numCrazyFlyZonesChanged(int)), this, SLOT(doNumCrazyFlyZonesChanged(int)));
......@@ -496,6 +499,7 @@ void MainGUIWindow::on_refresh_cfs_button_clicked()
{
#ifdef CATKIN_MAKE
ui->comboBoxCFs->clear();
// TODO: grey out the ones that are already linked
for(int i = 0; i < crazyflies_vector.size(); i++)
{
QString qstr = QString::fromStdString(crazyflies_vector[i]->getName());
......@@ -545,21 +549,6 @@ void MainGUIWindow::on_refresh_student_ids_button_clicked()
void MainGUIWindow::on_link_button_clicked()
{
#ifdef CATKIN_MAKE
QString cfzone_str = ui->comboBoxCFZones->currentText();
crazyFly* p_tmp_cf;
for(int i = 0; i < crazyflies_vector.size(); i++)
{
if(ui->comboBoxCFs->currentText().toStdString() == crazyflies_vector[i]->getName())
{
ROS_INFO("crazyfly to link found!--------------------------");
p_tmp_cf = crazyflies_vector[i];
}
}
int cf_zone_index = cfzone_str.split(" ")[1].toInt() - 1;
crazyFlyZone* p_tmp_cf_zone = scene->crazyfly_zones[cf_zone_index];
ROS_INFO("cf_zone_index: %d", cf_zone_index);
cf_linker->link(ui->spinBox_student_ids->value(), p_tmp_cf, p_tmp_cf_zone);
cf_linker->link();
#endif
}
Supports Markdown
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