00001 #include "mrta/architecture.h" 00002 #include "mrta/architecture_config.h" 00003 #include <QFileInfo> 00004 #include "rqt_mrta/config/architecture/rqt_mrta_architecture.h" 00005 #include "utilities/simple_xml_settings.h" 00006 00007 namespace mrta 00008 { 00009 Architecture::Architecture(QObject* parent, Config* config) : QObject(parent) 00010 { 00011 setAllocationType(Taxonomy::getAllocationType( 00012 config->getArchitecture()->getAllocations()->getType())); 00013 setRobotType(Taxonomy::getRobotType( 00014 config->getArchitecture()->getRobots()->getType())); 00015 setTaskType( 00016 Taxonomy::getTaskType(config->getArchitecture()->getTasks()->getType())); 00017 } 00018 00019 Architecture::Architecture(QObject* parent, const QString& package, 00020 const QString& config_file_path) 00021 : QObject(parent), package_(package), config_file_path_(config_file_path) 00022 { 00023 ArchitectureConfig config; 00024 config.setArchitecture(this); 00025 if (!config_file_path.isEmpty()) 00026 { 00027 QFileInfo file_info(config_file_path); 00028 if (file_info.isReadable()) 00029 { 00030 QSettings settings(config_file_path, utilities::SimpleXmlSettings::format); 00031 if (settings.status() == QSettings::NoError) 00032 { 00033 settings.beginGroup("rqt_mrta"); 00034 config.load(settings); 00035 settings.endGroup(); 00036 } 00037 } 00038 } 00039 } 00040 00041 Architecture::~Architecture() 00042 { 00043 ROS_INFO_STREAM("[~Architecture]"); 00044 } 00045 00046 QString Architecture::getPackage() const { return package_; } 00047 00048 QString Architecture::getConfigFilePath() const { return config_file_path_; } 00049 00050 QString Architecture::getName() const { return name_; } 00051 00052 Taxonomy::AllocationType Architecture::getAllocationType() const 00053 { 00054 return allocation_type_; 00055 } 00056 00057 Taxonomy::RobotType Architecture::getRobotType() const { return robot_type_; } 00058 00059 Taxonomy::TaskType Architecture::getTaskType() const { return task_type_; } 00060 00061 void Architecture::setName(const QString& name) { name_ = name; } 00062 00063 void Architecture::setAllocationType(const Taxonomy::AllocationType& type) 00064 { 00065 allocation_type_ = type; 00066 } 00067 00068 void Architecture::setRobotType(const Taxonomy::RobotType& type) 00069 { 00070 robot_type_ = type; 00071 } 00072 00073 void Architecture::setTaskType(const Taxonomy::TaskType& type) 00074 { 00075 task_type_ = type; 00076 } 00077 00078 bool Architecture::belongs(const Taxonomy::AllocationType& allocation_type, 00079 const Taxonomy::RobotType& robot_type, 00080 const Taxonomy::TaskType& task_type) const 00081 { 00082 return (allocation_type_ == allocation_type || 00083 allocation_type == Taxonomy::UnknownAllocationType) && 00084 (robot_type_ == robot_type || 00085 robot_type == Taxonomy::UnknownRobotType) && 00086 (task_type_ == task_type || task_type == Taxonomy::UnknownTaskType); 00087 } 00088 00089 QString Architecture::toString() const { return package_; } 00090 00091 bool Architecture::operator==(const QString& package) const 00092 { 00093 return package_ == package; 00094 } 00095 00096 bool Architecture::operator==(const Architecture& architecture) const 00097 { 00098 return package_ == architecture.package_; 00099 } 00100 00101 bool Architecture::isValid(Taxonomy::AllocationType type) const 00102 { 00103 return allocation_type_ == type; 00104 } 00105 00106 bool Architecture::isValid(Taxonomy::RobotType type) const 00107 { 00108 return robot_type_ == type; 00109 } 00110 00111 bool Architecture::isValid(Taxonomy::TaskType type) const 00112 { 00113 return task_type_ == type; 00114 } 00115 }