Go to the documentation of this file.00001 #include <QFileInfo>
00002 #include <ros/console.h>
00003 #include "rqt_mrta/config/architecture/rqt_mrta_architecture.h"
00004 #include "utilities/exception.h"
00005 #include "utilities/simple_xml_settings.h"
00006
00007 namespace rqt_mrta
00008 {
00009 namespace config
00010 {
00011 namespace architecture
00012 {
00013 RqtMrtaArchitecture::RqtMrtaArchitecture(QObject* parent)
00014 : AbstractConfig(parent), architecture_(new Architecture(this)),
00015 configs_(new Configs(this)), launches_(new Launches(this)), widgets_(new Widgets(this))
00016 {
00017 reset();
00018 connect(architecture_, SIGNAL(changed()), this, SIGNAL(changed()));
00019 connect(configs_, SIGNAL(changed()), this, SIGNAL(changed()));
00020 connect(launches_, SIGNAL(changed()), this, SIGNAL(changed()));
00021 connect(widgets_, SIGNAL(changed()), this, SIGNAL(changed()));
00022 }
00023
00024 RqtMrtaArchitecture::~RqtMrtaArchitecture()
00025 {
00026 if (architecture_)
00027 {
00028 delete architecture_;
00029 architecture_ = NULL;
00030 }
00031 if (configs_)
00032 {
00033 delete configs_;
00034 configs_ = NULL;
00035 }
00036 if (launches_)
00037 {
00038 delete launches_;
00039 launches_ = NULL;
00040 }
00041 if (widgets_)
00042 {
00043 delete widgets_;
00044 widgets_ = NULL;
00045 }
00046 }
00047
00048 QString RqtMrtaArchitecture::getArchitecturePackage() const
00049 {
00050 return package_;
00051 }
00052
00053 QString RqtMrtaArchitecture::getArchitecturePackageUrl() const
00054 {
00055 return url_;
00056 }
00057
00058 Architecture* RqtMrtaArchitecture::getArchitecture() const
00059 {
00060 return architecture_;
00061 }
00062
00063 Configs* RqtMrtaArchitecture::getConfigs() const { return configs_; }
00064
00065 Launches *RqtMrtaArchitecture::getLaunches() const
00066 {
00067 return launches_;
00068 }
00069
00070 Widgets* RqtMrtaArchitecture::getWidgets() const { return widgets_; }
00071
00072 void RqtMrtaArchitecture::setArchitecturePackage(const QString &package)
00073 {
00074 if (package != package_)
00075 {
00076 package_ = package;
00077 emit architecturePackageChanged(package);
00078 emit changed();
00079 }
00080 }
00081
00082 void RqtMrtaArchitecture::setArchitecturePackageUrl(const QString &url)
00083 {
00084 if (url != url_)
00085 {
00086 url_ = url;
00087 emit architecturePackageUrlChanged(url);
00088 emit changed();
00089 }
00090 }
00091
00092 void RqtMrtaArchitecture::save(const QString& url) const
00093 {
00094 if (url.isEmpty())
00095 {
00096 return;
00097 }
00098 QSettings settings(url, utilities::SimpleXmlSettings::format);
00099 if (settings.isWritable())
00100 {
00101 settings.clear();
00102 save(settings);
00103 settings.sync();
00104 if (settings.status() != QSettings::NoError)
00105 {
00106 ROS_ERROR("This architecture configuration file cannot be saved.");
00107 return;
00108 }
00109 ROS_INFO_STREAM("Saved architecture configuration file ["
00110 << url.toStdString() << "].");
00111 }
00112 }
00113
00114 void RqtMrtaArchitecture::save(QSettings& settings) const
00115 {
00116 settings.beginGroup("rqt_mrta");
00117
00118 architecture_->save(settings);
00119 configs_->save(settings);
00120 launches_->save(settings);
00121 widgets_->save(settings);
00122 settings.endGroup();
00123 }
00124
00125 void RqtMrtaArchitecture::load(const QString& url)
00126 {
00127 QFileInfo file_info(url);
00128 if (!file_info.isReadable())
00129 {
00130 return;
00131 }
00132 QSettings settings(url, utilities::SimpleXmlSettings::format);
00133 if (settings.status() != QSettings::NoError)
00134 {
00135 ROS_ERROR_STREAM("The given file is not well formatted ["
00136 << url.toStdString() << "].");
00137 return;
00138 }
00139 load(settings);
00140 ROS_INFO_STREAM("Loaded architecture configuration file ["
00141 << url.toStdString() << "].");
00142 }
00143
00144 void RqtMrtaArchitecture::load(QSettings& settings)
00145 {
00146 settings.beginGroup("rqt_mrta");
00147 QString type(settings.value("@format").toString());
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 architecture_->load(settings);
00161 configs_->load(settings);
00162 launches_->load(settings);
00163 widgets_->load(settings);
00164 settings.endGroup();
00165 }
00166
00167 void RqtMrtaArchitecture::reset()
00168 {
00169 setArchitecturePackage("");
00170 setArchitecturePackageUrl("");
00171 architecture_->reset();
00172 configs_->reset();
00173 launches_->reset();
00174 widgets_->reset();
00175 }
00176
00177 void RqtMrtaArchitecture::write(QDataStream& stream) const
00178 {
00179 architecture_->write(stream);
00180 configs_->write(stream);
00181 launches_->write(stream);
00182 widgets_->write(stream);
00183 }
00184
00185 void RqtMrtaArchitecture::read(QDataStream& stream)
00186 {
00187 architecture_->read(stream);
00188 configs_->read(stream);
00189 launches_->read(stream);
00190 widgets_->read(stream);
00191 }
00192
00193 RqtMrtaArchitecture& RqtMrtaArchitecture::
00194 operator=(const RqtMrtaArchitecture& config)
00195 {
00196 setArchitecturePackage(config.package_);
00197 setArchitecturePackageUrl(config.url_);
00198 *architecture_ = *config.architecture_;
00199 *configs_ = *config.configs_;
00200 *launches_ = *config.launches_;
00201 *widgets_ = *config.widgets_;
00202 return *this;
00203 }
00204 }
00205 }
00206 }