Go to the documentation of this file.00001 #include "mrta/robot.h"
00002 #include "mrta/task.h"
00003 #include <QSettings>
00004 #include <ros/console.h>
00005 #include <ros/package.h>
00006 #include "rqt_mrta/config/application/robots.h"
00007 #include "rqt_mrta/config/application/robot.h"
00008 #include "rqt_mrta/config/application/tasks.h"
00009 #include "rqt_mrta/config/application/task.h"
00010 #include "rqt_mrta/config/application/rqt_mrta_application.h"
00011 #include "rqt_mrta/define_robots_widget.h"
00012 #include "rqt_mrta/ui_define_robots_widget.h"
00013 #include "utilities/exception.h"
00014
00015 namespace rqt_mrta
00016 {
00017 DefineRobotsWidget::DefineRobotsWidget(QWidget* parent, RqtMrtaApplicationConfig* application_config)
00018 : QWidget(parent), ui_(new Ui::DefineRobotsWidget()),
00019 application_config_(NULL), tasks_model_(new QStringListModel(this))
00020 {
00021 if (!application_config)
00022 {
00023 throw utilities::Exception(
00024 "[DefineApplicationWidget] The application config must not be NULL.");
00025 }
00026 ui_->setupUi(this);
00027 ui_->id_line_edit->setEnabled(false);
00028 ui_->tasks_list_view->setModel(tasks_model_);
00029 QIcon new_icon(QString::fromStdString(
00030 ros::package::getPath("rqt_mrta").append("/resource/22x22/new.png")));
00031 ui_->new_robot_command_link_button->setIcon(new_icon);
00032 ui_->new_task_command_link_button->setIcon(new_icon);
00033 ui_->new_task_command_link_button->setEnabled(false);
00034 connect(ui_->id_line_edit, SIGNAL(textChanged(const QString&)), this,
00035 SLOT(idChanged(const QString&)));
00036 connect(ui_->new_robot_command_link_button, SIGNAL(clicked()), this,
00037 SLOT(newRobotButtonClicked()));
00038 connect(ui_->new_task_command_link_button, SIGNAL(clicked()), this,
00039 SLOT(newTaskButtonClicked()));
00040 connect(ui_->robot_tree_widget, SIGNAL(robotSelected(const QString&)),
00041 this, SLOT(robotSelected(const QString&)));
00042 connect(ui_->robot_tree_widget, SIGNAL(taskSelected(const QString&)),
00043 this, SLOT(taskSelected(const QString&)));
00044 setApplicationConfig(application_config);
00045 }
00046
00047 DefineRobotsWidget::~DefineRobotsWidget()
00048 {
00049 application_config_ = NULL;
00050 if (ui_)
00051 {
00052 delete ui_;
00053 ui_ = NULL;
00054 }
00055 }
00056
00057 RqtMrtaApplicationConfig* DefineRobotsWidget::getApplicationConfig() const
00058 {
00059 return application_config_;
00060 }
00061
00062 void DefineRobotsWidget::setApplicationConfig(RqtMrtaApplicationConfig* config)
00063 {
00064 if (application_config_ != config)
00065 {
00066 if (application_config_)
00067 {
00068 disconnect(application_config_, SIGNAL(changed()), this, SIGNAL(changed()));
00069 ui_->robot_tree_widget->setConfig(NULL);
00070 ui_->new_robot_command_link_button->setEnabled(false);
00071 ui_->new_robot_command_link_button->setEnabled(false);
00072 }
00073 application_config_ = config;
00074 if (application_config_)
00075 {
00076 connect(application_config_, SIGNAL(changed()), this, SIGNAL(changed()));
00077 ui_->robot_tree_widget->setConfig(application_config_->getApplication()->getRobots());
00078 ui_->new_robot_command_link_button->setEnabled(true);
00079 }
00080 }
00081 }
00082
00083 QString DefineRobotsWidget::validate() const
00084 {
00085 QString tip(ui_->robot_tree_widget->validate());
00086 ui_->robot_tree_widget->setToolTip(tip);
00087 return tip;
00088 }
00089
00090 void DefineRobotsWidget::idChanged(const QString &id)
00091 {
00092 ui_->robot_tree_widget->setCurrentId(id);
00093 }
00094
00095 void DefineRobotsWidget::newRobotButtonClicked()
00096 {
00097 ui_->robot_tree_widget->addRobot();
00098 }
00099
00100 void DefineRobotsWidget::newTaskButtonClicked()
00101 {
00102 ui_->robot_tree_widget->addTask();
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 void DefineRobotsWidget::robotSelected(const QString &robot_id)
00113 {
00114 ui_->id_line_edit->setText(robot_id);
00115 ui_->new_task_command_link_button->setEnabled(true);
00116 ui_->id_line_edit->setEnabled(true);
00117 }
00118
00119 void DefineRobotsWidget::taskSelected(const QString &task_id)
00120 {
00121 ui_->id_line_edit->setText(task_id);
00122 ui_->new_task_command_link_button->setEnabled(false);
00123 ui_->id_line_edit->setEnabled(true);
00124 }
00125 }