CFLinker.cpp 1.73 KB
Newer Older
1
2
3
#include "CFLinker.h"


4
CFLinker::CFLinker(Ui::MainGUIWindow* ui)
5
{
6
    m_ui = ui;
7
8
9
10
11
12
}

CFLinker::~CFLinker()
{
}

13
void CFLinker::link(int student_id, crazyFly* crazyfly, crazyFlyZone* crazyfly_zone)
14
15
16
17
18
19
20
21
22
{
    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);

23
24
25
26
    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);
27
    QString str_id = QString::number(student_id);
28
    m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 0, new QTableWidgetItem(str_id));
29
    QString str_cf_name = QString::fromStdString(crazyfly->getName());
30
31
32
    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));
    m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 2, new QTableWidgetItem(str_cf_zone_index));
33

34
    links.push_back(tmp_link);
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
}

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);
    }
}