Go to the documentation of this file.00001 #include "mrta/architecture.h"
00002 #include <rospack/rospack.h>
00003 #include "rqt_mrta/architecture_combo_box.h"
00004
00005 namespace rqt_mrta
00006 {
00007 ArchitectureComboBox::ArchitectureComboBox(QWidget* parent)
00008 : QComboBox(parent), current_architecture_(NULL),
00009 allocation_type_(mrta::Taxonomy::UnknownAllocationType),
00010 robot_type_(mrta::Taxonomy::UnknownRobotType),
00011 task_type_(mrta::Taxonomy::UnknownTaskType)
00012 {
00013 load();
00014 filter();
00015 connect(this, SIGNAL(currentIndexChanged(int)), this,
00016 SLOT(currentArchitectureChanged(int)));
00017 }
00018
00019 ArchitectureComboBox::~ArchitectureComboBox()
00020 {
00021 current_architecture_ = NULL;
00022 }
00023
00024 mrta::Architecture* ArchitectureComboBox::getCurrentArchitecture() const
00025 {
00026 return current_architecture_;
00027 }
00028
00029 void ArchitectureComboBox::setFilterAllocationType(
00030 const mrta::Taxonomy::AllocationType& allocation_type)
00031 {
00032 if (allocation_type != allocation_type_)
00033 {
00034 allocation_type_ = allocation_type;
00035 filter();
00036 emit filterChanged();
00037 emit changed();
00038 }
00039 }
00040
00041 void ArchitectureComboBox::setFilterRobotType(
00042 const mrta::Taxonomy::RobotType& robot_type)
00043 {
00044 if (robot_type != robot_type_)
00045 {
00046 robot_type_ = robot_type;
00047 filter();
00048 emit filterChanged();
00049 emit changed();
00050 }
00051 }
00052
00053 void ArchitectureComboBox::setFilterTaskType(
00054 const mrta::Taxonomy::TaskType& task_type)
00055 {
00056 if (task_type != task_type_)
00057 {
00058 task_type_ = task_type;
00059 filter();
00060 emit filterChanged();
00061 emit changed();
00062 }
00063 }
00064
00065 void ArchitectureComboBox::load()
00066 {
00067 std::vector<std::string> architectures;
00068 rospack::Rospack rp;
00069 rp.setQuiet(true);
00070 std::vector<std::string> search_path;
00071 rp.getSearchPathFromEnv(search_path);
00072 rp.crawl(search_path, true);
00073 indexes_.clear();
00074 indexes_.append(-1);
00075 architectures_.clear();
00076 if (rp.plugins("rqt_mrta", "architecture", "", architectures))
00077 {
00078 for (size_t i(0); i < architectures.size(); i++)
00079 {
00080 size_t index(architectures[i].find(' '));
00081 QString package(
00082 QString::fromStdString(architectures[i].substr(0, index)));
00083 QString architecture_config_path(
00084 QString::fromStdString(architectures[i].substr(index + 1)));
00085 indexes_.append(i);
00086 architectures_.append(
00087 new mrta::Architecture(NULL, package, architecture_config_path));
00088 }
00089 }
00090 }
00091
00092 void ArchitectureComboBox::filter()
00093 {
00094 setEnabled(false);
00095 blockSignals(true);
00096 clear();
00097 addItem("");
00098 int counter(1), index(-1);
00099 for (size_t i(0); i < architectures_.count(); i++)
00100 {
00101 indexes_[counter] = -1;
00102 if (architectures_[i]->belongs(allocation_type_, robot_type_, task_type_))
00103 {
00104 indexes_[counter] = i;
00105 addItem(architectures_[i]->getPackage());
00106 if (current_architecture_ && *architectures_[i] == *current_architecture_)
00107 {
00108 index = counter;
00109 }
00110 counter++;
00111 }
00112 }
00113 if (count() > 1)
00114 {
00115 setEnabled(true);
00116 }
00117 blockSignals(false);
00118 if (index != -1)
00119 {
00120 setCurrentIndex(index);
00121 }
00122 else
00123 {
00124 current_architecture_ = NULL;
00125 emit unknownAchitecture();
00126 }
00127 emit filtered();
00128 emit changed();
00129 }
00130
00131 void ArchitectureComboBox::currentArchitectureChanged(int index)
00132 {
00133 current_architecture_ = index != -1 && indexes_[index] != -1
00134 ? architectures_[indexes_[index]]
00135 : NULL;
00136 if (!current_architecture_)
00137 {
00138 emit unknownAchitecture();
00139 }
00140 emit currentArchitectureChanged(current_architecture_);
00141 emit changed();
00142 }
00143 }