Commit 078e3e0a authored by roangel's avatar roangel
Browse files

added exceptions, link process is apparently already done. Next: unlink process

parent 2dca70a6
......@@ -18,15 +18,19 @@ public:
int cf_zone_index;
std::string cf_name;
};
explicit CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones);
~CFLinker();
void link();
void unlink();
std::vector<struct link> links;
bool isStudentIDLinked(int student_id);
bool isCFZoneLinked(int cf_zone_index);
bool isCFLinked(std::string cf_name);
private:
// QTableWidget m_p_table;
......
......@@ -111,6 +111,8 @@ private slots:
void on_link_button_clicked();
void on_unlink_button_clicked();
private:
Ui::MainGUIWindow *ui;
......
......@@ -29,6 +29,48 @@ int CFLinker::getCFIndexFromName(std::string name)
}
}
bool CFLinker::isStudentIDLinked(int student_id)
{
bool is_linked = false;
for(int i = 0; i < links.size(); i++)
{
if(links[i].student_id == student_id)
{
is_linked = true;
}
}
return is_linked;
}
bool CFLinker::isCFZoneLinked(int cf_zone_index)
{
bool is_linked = false;
for(int i = 0; i < links.size(); i++)
{
if(links[i].cf_zone_index == cf_zone_index)
{
is_linked = true;
}
}
return is_linked;
}
bool CFLinker::isCFLinked(std::string cf_name)
{
bool is_linked = false;
for(int i = 0; i < links.size(); i++)
{
if(links[i].cf_name == cf_name)
{
is_linked = true;
}
}
return is_linked;
}
void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_index)
{
m_ui->table_links->insertRow(m_ui->table_links->rowCount());
......@@ -74,24 +116,5 @@ void CFLinker::link()
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;
// }
// }
// }
// if(found)
// {
// crazyfly_zone->removeLink();
// crazyfly->removeAssigned();
// links.erase(links.begin() + index_found);
// }
}
......@@ -54,24 +54,36 @@ void MainGUIWindow::doNumCrazyFlyZonesChanged(int n)
connect(widget, SIGNAL(centerButtonClickedSignal(int)), this, SLOT(centerViewIndex(int)));
}
// add options to QComboBox of CFZones
int current_count = ui->comboBoxCFZones->count();
if(n > current_count)
ui->comboBoxCFZones->clear();
#ifdef CATKIN_MAKE
for(int i = 0; i < scene->crazyfly_zones.size(); i++)
{
for(int i = current_count; i < n; i++)
if(!cf_linker->isCFZoneLinked(scene->crazyfly_zones[i]->getIndex()))
{
QString qstr = "CrazyFlyZone ";
qstr.append(QString::number(i+1));
ui->comboBoxCFZones->addItem(qstr);
}
}
else if(n < current_count)
{
for(int i = current_count; i >= n; i--)
{
ui->comboBoxCFZones->removeItem(i);
}
}
#endif
// add options to QComboBox of CFZones
// int current_count = ui->comboBoxCFZones->count();
// if(n > current_count)
// {
// for(int i = current_count; i < n; i++)
// {
// QString qstr = "CrazyFlyZone ";
// qstr.append(QString::number(i+1));
// ui->comboBoxCFZones->addItem(qstr);
// }
// }
// else if(n < current_count)
// {
// for(int i = current_count; i >= n; i--)
// {
// ui->comboBoxCFZones->removeItem(i);
// }
// }
}
......@@ -90,6 +102,19 @@ void MainGUIWindow::_init()
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// error messages
// ui->err_message_cf->hide();
// ui->err_message_cf_zone->hide();
// ui->err_message_student_id->hide();
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_cf->clear();
ui->err_message_cf_zone->clear();
ui->err_message_student_id->clear();
// initialize table_links
ui->table_links->setColumnCount(3);
QStringList horizontal_header;
......@@ -122,8 +147,9 @@ void MainGUIWindow::_init()
ui->graphicsView->setScene(scene);
// after scene is created, create CFlinker
#ifdef CATKIN_MAKE
cf_linker = new CFLinker(ui, &crazyflies_vector, &scene->crazyfly_zones);
#endif
// connections
QObject::connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), scene, SLOT(removeCrazyFlyZone(int)));
QObject::connect(scene, SIGNAL(numCrazyFlyZonesChanged(int)), this, SLOT(doNumCrazyFlyZonesChanged(int)));
......@@ -500,11 +526,13 @@ 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());
ui->comboBoxCFs->addItem(qstr);
if(!cf_linker->isCFLinked(crazyflies_vector[i]->getName()))
{
QString qstr = QString::fromStdString(crazyflies_vector[i]->getName());
ui->comboBoxCFs->addItem(qstr);
}
}
#endif
}
......@@ -555,28 +583,45 @@ void MainGUIWindow::on_link_button_clicked()
if(ui->comboBoxCFs->count() == 0)
{
// plot error message
ui->err_message_cf->setText("CF box is empty");
error = true;
}
else
{
ui->err_message_cf->clear();
}
if(ui->comboBoxCFZones->count() == 0)
{
// plot error message
ui->err_message_cf_zone->setText("CFZone box is empty");
error = true;
}
else
{
ui->err_message_cf_zone->clear();
}
for(int i = 0; i < cf_linker->links.size(); i++)
if(cf_linker->isStudentIDLinked(ui->spinBox_student_ids->value()))
{
if(cf_linker->links[i].student_id == ui->spinBox_student_ids->value())
{
// value already linked, choose different one
// plot error message
error = true;
}
// plot error message
ui->err_message_student_id->setText("This StudentID has already been linked");
error = true;
}
else
{
ui->err_message_student_id->clear();
}
if(!error)
{
// remove error messages
cf_linker->link();
}
#endif
}
void MainGUIWindow::on_unlink_button_clicked()
{
#ifdef CATKIN_MAKE
cf_linker->unlink();
#endif
}
......@@ -241,6 +241,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>350</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
......@@ -285,6 +291,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="3" column="1">
......@@ -294,30 +306,41 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QComboBox" name="comboBoxCFs"/>
</item>
<item row="9" column="1">
<item row="13" column="1">
<widget class="QComboBox" name="comboBoxCFZones"/>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Choose CF to link:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="12" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Choose CF Zone to link:</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="refresh_cfs_button">
<item row="14" column="1" colspan="2">
<widget class="QLabel" name="err_message_cf_zone">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>Refresh CFs</string>
<string>TextLabel</string>
</property>
</widget>
</item>
......@@ -328,21 +351,20 @@
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QPushButton" name="link_button">
<property name="text">
<string>Link!</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<item row="16" column="1" colspan="2">
<widget class="QTableWidget" name="table_links">
<property name="minimumSize">
<size>
<width>273</width>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
......@@ -353,10 +375,67 @@
<number>0</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
<bool>false</bool>
</attribute>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="err_message_student_id">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QPushButton" name="refresh_cfs_button">
<property name="text">
<string>Refresh CFs</string>
</property>
</widget>
</item>
<item row="13" column="2">
<widget class="QPushButton" name="link_button">
<property name="text">
<string>Link!</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QLabel" name="err_message_cf">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="17" column="2">
<widget class="QPushButton" name="unlink_button">
<property name="text">
<string>Unlink!</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
......
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