Go to the documentation of this file.00001 #include "mrta/taxonomy.h"
00002 #include "rqt_mrta/config/architecture/architecture.h"
00003 #include "rqt_mrta/config/architecture/allocations.h"
00004 #include "rqt_mrta/config/architecture/robots.h"
00005 #include "rqt_mrta/config/architecture/rqt_mrta_architecture.h"
00006 #include "rqt_mrta/config/architecture/tasks.h"
00007 #include "rqt_mrta/register_architecture_widget.h"
00008 #include "rqt_mrta/ui_register_architecture_widget.h"
00009
00010 namespace rqt_mrta
00011 {
00012 RegisterArchitectureWidget::RegisterArchitectureWidget(QWidget* parent,
00013 Config* config)
00014 : QWidget(parent), ui_(new Ui::RegisterArchitectureWidget()), config_(NULL)
00015 {
00016 ui_->setupUi(this);
00017 setConfig(config);
00018 connect(ui_->allocations_type_combo_box, SIGNAL(currentIndexChanged(int)),
00019 this, SLOT(robotTypeChanged()));
00020 connect(ui_->robots_type_combo_box, SIGNAL(currentIndexChanged(int)), this,
00021 SLOT(taskTypeChanged()));
00022 connect(ui_->tasks_type_combo_box, SIGNAL(currentIndexChanged(int)), this,
00023 SLOT(allocationTypeChanged()));
00024 connect(ui_->architecture_line_edit, SIGNAL(textChanged(const QString&)),
00025 this, SLOT(packageChanged(const QString&)));
00026 }
00027
00028 RegisterArchitectureWidget::~RegisterArchitectureWidget()
00029 {
00030 config_ = NULL;
00031 if (ui_)
00032 {
00033 delete ui_;
00034 ui_ = NULL;
00035 }
00036 }
00037
00038 Config* RegisterArchitectureWidget::getConfig() const { return config_; }
00039
00040 void RegisterArchitectureWidget::setConfig(Config* config)
00041 {
00042 if (config != config_)
00043 {
00044 if (config_)
00045 {
00046 disconnect(config_, SIGNAL(changed()), this, SIGNAL(changed()));
00047 }
00048 config_ = config;
00049 if (config_)
00050 {
00051 ArchitectureConfig* architecture_config = config_->getArchitecture();
00052 RobotsConfig* robots_config = architecture_config->getRobots();
00053 TasksConfig* tasks_config = architecture_config->getTasks();
00054 AllocationsConfig* allocations_config =
00055 architecture_config->getAllocations();
00056 connect(config_, SIGNAL(changed()), this, SIGNAL(changed()));
00057 connect(config_, SIGNAL(architecturePackageChanged(const QString&)), this,
00058 SLOT(configPackageChanged(const QString&)));
00059 connect(robots_config, SIGNAL(typeChanged(const QString&)), this,
00060 SLOT(configRobotsTypeChanged(const QString&)));
00061 connect(tasks_config, SIGNAL(typeChanged(const QString&)), this,
00062 SLOT(configTasksTypeChanged(const QString&)));
00063 connect(allocations_config, SIGNAL(typeChanged(const QString&)), this,
00064 SLOT(configAllocationsTypeChanged(const QString&)));
00065 configPackageChanged(config_->getArchitecturePackage());
00066 configRobotsTypeChanged(robots_config->getType());
00067 configTasksTypeChanged(tasks_config->getType());
00068 configAllocationsTypeChanged(allocations_config->getType());
00069 }
00070 }
00071 }
00072
00073 QString RegisterArchitectureWidget::validate() const
00074 {
00075 if (!config_)
00076 {
00077 return "The ArchitectureConfig must be given.";
00078 }
00079 if (config_->getArchitecturePackage().isEmpty())
00080 {
00081 return "The architecture package must be given.";
00082 }
00083 if (config_->getArchitecture()->getRobots()->getType().isEmpty())
00084 {
00085 return "The robots type must be selected.";
00086 }
00087 if (config_->getArchitecture()->getTasks()->getType().isEmpty())
00088 {
00089 return "The tasks type must be selected.";
00090 }
00091 if (config_->getArchitecture()->getAllocations()->getType().isEmpty())
00092 {
00093 return "The allocations type must be selected.";
00094 }
00095 return "";
00096 }
00097
00098 void RegisterArchitectureWidget::packageChanged(const QString& package)
00099 {
00100 config_->setArchitecturePackage(package);
00101 }
00102
00103 void RegisterArchitectureWidget::robotTypeChanged()
00104 {
00105 mrta::Taxonomy::RobotType type(
00106 mrta::Taxonomy::getRobotType(ui_->robots_type_combo_box->currentText()));
00107 config_->getArchitecture()->getRobots()->setType(
00108 mrta::Taxonomy::toQString(type));
00109 }
00110
00111 void RegisterArchitectureWidget::taskTypeChanged()
00112 {
00113 mrta::Taxonomy::TaskType type(
00114 mrta::Taxonomy::getTaskType(ui_->tasks_type_combo_box->currentText()));
00115 config_->getArchitecture()->getTasks()->setType(
00116 mrta::Taxonomy::toQString(type));
00117 }
00118
00119 void RegisterArchitectureWidget::allocationTypeChanged()
00120 {
00121 mrta::Taxonomy::AllocationType type(mrta::Taxonomy::getAllocationType(
00122 ui_->allocations_type_combo_box->currentText()));
00123 config_->getArchitecture()->getAllocations()->setType(
00124 mrta::Taxonomy::toQString(type));
00125 }
00126
00127 void RegisterArchitectureWidget::configPackageChanged(const QString& package)
00128 {
00129 ui_->architecture_line_edit->setText(package);
00130 }
00131
00132 void RegisterArchitectureWidget::configRobotsTypeChanged(const QString& type)
00133 {
00134 ui_->robots_type_combo_box->setCurrentIndex(mrta::Taxonomy::getRobotType(type));
00135 }
00136
00137 void RegisterArchitectureWidget::configTasksTypeChanged(const QString& type)
00138 {
00139 ui_->tasks_type_combo_box->setCurrentIndex(mrta::Taxonomy::getTaskType(type));
00140 }
00141
00142 void RegisterArchitectureWidget::configAllocationsTypeChanged(
00143 const QString& type)
00144 {
00145 ui_->allocations_type_combo_box->setCurrentIndex(mrta::Taxonomy::getAllocationType(type));
00146 }
00147 }