From daf267d5a9117ebd1f22861959a8fe5142a20eef Mon Sep 17 00:00:00 2001 From: roangel <roangel@student.ethz.ch> Date: Thu, 1 Jun 2017 16:24:11 +0200 Subject: [PATCH] Added support for Address. Need to do it in a better way, now it is in a simple way, need to write the whole address --- .../GUI_Qt/CrazyFlyGUI/include/CFLinker.h | 6 ++- .../GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp | 26 ++++++++++-- .../GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp | 28 +++++++++++-- .../GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui | 40 ++++++++++++++----- pps_ws/src/d_fall_pps/param/Crazyflie.db | 6 +-- 5 files changed, 85 insertions(+), 21 deletions(-) diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h index 327a8cc9..7531b4c3 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h @@ -20,12 +20,13 @@ public: int student_id; int cf_zone_index; std::string cf_name; + std::string radio_address;; }; explicit CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones); ~CFLinker(); - void link(int student_id, int cf_zone_index, std::string cf_name); + void link(int student_id, int cf_zone_index, std::string cf_name, std::string radio_address); void unlink_selection(); void unlink_cf_zone(int cf_zone_index); @@ -34,6 +35,7 @@ public: bool isStudentIDLinked(int student_id); bool isCFZoneLinked(int cf_zone_index); bool isCFLinked(std::string cf_name); + bool isRadioAddressLinked(std::string radio_address); int getCFZoneIndexFromName(QString name); int getCFIndexFromName(std::string name); @@ -50,7 +52,7 @@ private: std::vector<crazyFly*>* m_crazyflies_vector; std::vector<crazyFlyZone*>* m_crazyfly_zones; - void addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index); + void addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index, std::string radio_address); }; diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp index 9af98b8c..fa45dfe1 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp @@ -44,6 +44,19 @@ bool CFLinker::isStudentIDLinked(int student_id) return is_linked; } +bool CFLinker::isRadioAddressLinked(std::string radio_address) +{ + bool is_linked = false; + for(int i = 0; i < links.size(); i++) + { + if(links[i].radio_address == radio_address) + { + is_linked = true; + } + } + return is_linked; +} + bool CFLinker::isCFZoneLinked(int cf_zone_index) { bool is_linked = false; @@ -72,7 +85,7 @@ bool CFLinker::isCFLinked(std::string cf_name) } -void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index) +void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index, std::string radio_address) { m_ui->table_links->insertRow(m_ui->table_links->rowCount()); QString str_id = QString::number(student_id); @@ -89,9 +102,14 @@ void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_ QTableWidgetItem *item_cf_zone = new QTableWidgetItem(str_cf_zone_index); item_cf_zone->setFlags(item_cf_zone->flags() & ~Qt::ItemIsEditable); m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 2, item_cf_zone); + + QString str_radio_address = QString::fromStdString(radio_address); + QTableWidgetItem *item_radio_address = new QTableWidgetItem(str_radio_address); + item_cf->setFlags(item_radio_address->flags() & ~Qt::ItemIsEditable); + m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 3, item_radio_address); } -void CFLinker::link(int student_id, int cf_zone_index, std::string cf_name) +void CFLinker::link(int student_id, int cf_zone_index, std::string cf_name, std::string radio_address) { m_ui->table_links->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); struct link tmp_link; @@ -99,15 +117,17 @@ void CFLinker::link(int student_id, int cf_zone_index, std::string cf_name) tmp_link.student_id = student_id; tmp_link.cf_zone_index = cf_zone_index; tmp_link.cf_name = cf_name; + tmp_link.radio_address = radio_address; ROS_INFO("tmp_link.student_id %d", tmp_link.student_id); 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()); + ROS_INFO("tmp_link.radio_address %s", tmp_link.radio_address.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(tmp_link.student_id, tmp_link.cf_name, tmp_link.cf_zone_index); + addNewRow(tmp_link.student_id, tmp_link.cf_name, tmp_link.cf_zone_index, tmp_link.radio_address); links.push_back(tmp_link); // TODO: remove options linked from available ones diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp index 61710e13..409d5963 100755 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp @@ -133,13 +133,15 @@ void MainGUIWindow::_init() ui->err_message_cf->setStyleSheet("QLabel { color : red; }"); ui->err_message_cf_zone->setStyleSheet("QLabel { color : red; }"); ui->err_message_student_id->setStyleSheet("QLabel { color : red; }"); + ui->err_message_radio_address->setStyleSheet("QLabel { color : red; }"); ui->err_message_cf->clear(); ui->err_message_cf_zone->clear(); ui->err_message_student_id->clear(); + ui->err_message_radio_address->clear(); // initialize table_links - ui->table_links->setColumnCount(3); + ui->table_links->setColumnCount(4); QFont fnt; fnt.setPointSize(7); @@ -160,7 +162,7 @@ void MainGUIWindow::_init() } ui->table_links->setSelectionBehavior(QAbstractItemView::SelectRows); QStringList horizontal_header; - horizontal_header << "Student ID" << "CrazyFly" << "CrazyFly Zone"; + horizontal_header << "Student ID" << "CrazyFly" << "CrazyFly Zone" << "Radio Address"; ui->table_links->setHorizontalHeaderLabels(horizontal_header); // scene @@ -659,6 +661,7 @@ void MainGUIWindow::on_link_button_clicked() { ui->err_message_cf->clear(); } + if(ui->comboBoxCFZones->count() == 0) { // plot error message @@ -670,6 +673,21 @@ void MainGUIWindow::on_link_button_clicked() ui->err_message_cf_zone->clear(); } + if(cf_linker->isRadioAddressLinked(ui->radioAddress_text->text().toStdString())) + { + ui->err_message_radio_address->setText("Already in use"); + error = true; + } + else if(ui->radioAddress_text->text().toStdString() == "") + { + ui->err_message_radio_address->setText("Field is empty"); + error = true; + } + else + { + ui->err_message_radio_address->clear(); + } + if(cf_linker->isStudentIDLinked(ui->spinBox_student_ids->value())) { // plot error message @@ -683,7 +701,7 @@ void MainGUIWindow::on_link_button_clicked() if(!error) { - cf_linker->link(ui->spinBox_student_ids->value(), cf_linker->getCFZoneIndexFromName(ui->comboBoxCFZones->currentText()), ui->comboBoxCFs->currentText().toStdString()); + cf_linker->link(ui->spinBox_student_ids->value(), cf_linker->getCFZoneIndexFromName(ui->comboBoxCFZones->currentText()), ui->comboBoxCFs->currentText().toStdString(), ui->radioAddress_text->text().toStdString()); } #endif } @@ -703,6 +721,7 @@ void MainGUIWindow::on_save_in_DB_button_clicked() { CrazyflieEntry tmp_entry; tmp_entry.crazyflieContext.crazyflieName = cf_linker->links[i].cf_name; + tmp_entry.crazyflieContext.crazyflieAddress = cf_linker->links[i].radio_address; tmp_entry.crazyflieContext.localArea.crazyfly_zone_index = cf_linker->links[i].cf_zone_index; tmp_entry.studentID = cf_linker->links[i].student_id; @@ -829,6 +848,7 @@ void MainGUIWindow::on_load_from_DB_button_clicked() for(int i = 0; i < m_data_base.crazyflieEntries.size(); i++) { std::string cf_name = m_data_base.crazyflieEntries[i].crazyflieContext.crazyflieName; + std::string radio_address = m_data_base.crazyflieEntries[i].crazyflieContext.crazyflieAddress; int cf_zone_index = m_data_base.crazyflieEntries[i].crazyflieContext.localArea.crazyfly_zone_index; // we should first create the cf zones that are in the database? bool cf_zone_exists; @@ -844,7 +864,7 @@ void MainGUIWindow::on_load_from_DB_button_clicked() scene->addCFZone(tmp_rect, cf_zone_index); - cf_linker->link(student_id, cf_zone_index, cf_name); + cf_linker->link(student_id, cf_zone_index, cf_name, radio_address); } } diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui index 0aed3657..c4de6169 100755 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>866</width> - <height>663</height> + <height>719</height> </rect> </property> <property name="windowTitle"> @@ -270,7 +270,7 @@ </property> </widget> </item> - <item row="12" column="1" colspan="6"> + <item row="14" column="1" colspan="6"> <widget class="QLabel" name="err_message_cf_zone"> <property name="font"> <font> @@ -323,7 +323,7 @@ </property> </widget> </item> - <item row="11" column="1"> + <item row="13" column="1"> <widget class="QComboBox" name="comboBoxCFZones"/> </item> <item row="8" column="1"> @@ -343,7 +343,7 @@ </property> </widget> </item> - <item row="10" column="1"> + <item row="12" column="1"> <widget class="QLabel" name="label_3"> <property name="text"> <string>Choose CF Zone to link:</string> @@ -364,7 +364,7 @@ </property> </widget> </item> - <item row="13" column="1" colspan="6"> + <item row="15" column="1" colspan="6"> <widget class="QTableWidget" name="table_links"> <property name="minimumSize"> <size> @@ -386,34 +386,56 @@ </attribute> </widget> </item> - <item row="11" column="6"> + <item row="13" column="6"> <widget class="QPushButton" name="link_button"> <property name="text"> <string>Link!</string> </property> </widget> </item> - <item row="15" column="6"> + <item row="17" column="6"> <widget class="QPushButton" name="unlink_button"> <property name="text"> <string>Unlink!</string> </property> </widget> </item> - <item row="17" column="6"> + <item row="19" column="6"> <widget class="QPushButton" name="save_in_DB_button"> <property name="text"> <string>Save in DB</string> </property> </widget> </item> - <item row="16" column="6"> + <item row="18" column="6"> <widget class="QPushButton" name="load_from_DB_button"> <property name="text"> <string>Load from DB</string> </property> </widget> </item> + <item row="10" column="1"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Radio Address:</string> + </property> + </widget> + </item> + <item row="10" column="6"> + <widget class="QLineEdit" name="radioAddress_text"/> + </item> + <item row="11" column="6"> + <widget class="QLabel" name="err_message_radio_address"> + <property name="font"> + <font> + <pointsize>7</pointsize> + </font> + </property> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> </layout> </widget> </widget> diff --git a/pps_ws/src/d_fall_pps/param/Crazyflie.db b/pps_ws/src/d_fall_pps/param/Crazyflie.db index a4c31853..c9b62127 100644 --- a/pps_ws/src/d_fall_pps/param/Crazyflie.db +++ b/pps_ws/src/d_fall_pps/param/Crazyflie.db @@ -1,3 +1,3 @@ -1,CF1,,0,2.30378,0.506831,0,4.29424,2.29456,0 -2,CF2,,1,1.59421,0.884651,0,2.66317,1.62186,0 -3,CF3,,2,1.51128,1.97203,0,3.11471,2.82904,0 +1,CF1,A,0,-0.01,1,0,0.8,1.83,0 +2,CF2,B,1,-0.03,-0.8,0,0.49,-0,0 +3,CF3,C,2,0,-1.84,0,0.53,-1.53,0 -- GitLab