Go to the documentation of this file.00001 #include <QDir>
00002 #include <QPushButton>
00003 #include <QVBoxLayout>
00004 #include "rqt_mrta/new_application_wizard.h"
00005 #include "rqt_mrta/define_application_wizard_page.h"
00006 #include "rqt_mrta/define_architecture_wizard_page.h"
00007 #include "rqt_mrta/define_robots_wizard_page.h"
00008 #include "rqt_mrta/define_parameters_wizard_page.h"
00009 #include <ros/console.h>
00010 #include <ros/package.h>
00011 #include "utilities/exception.h"
00012
00013 namespace rqt_mrta
00014 {
00015 NewApplicationWizard::NewApplicationWizard(
00016 QWidget* parent, RqtMrtaApplicationConfig* application_config,
00017 Qt::WindowFlags flags)
00018 : QWizard(parent, flags), application_config_(application_config),
00019 package_config_(new RqtMrtaApplicationPackageConfig(this)),
00020 architecture_config_(new RqtMrtaArchitectureConfig(this)),
00021 summary_label_(new QLabel(this))
00022 {
00023 if (!application_config_)
00024 {
00025 throw utilities::Exception(
00026 "The application configuration must not be null.");
00027 }
00028 setPage(DefineApplication, new DefineApplicationWizardPage(this));
00029 setPage(DefineArchitecture, new DefineArchitectureWizardPage(this));
00030 setPage(DefineRobots, new DefineRobotsWizardPage(this));
00031 setPage(DefineParameters, new DefineParametersWizardPage(this));
00032 setPage(Summary, createSummaryPage());
00033 setWindowTitle("New application ...");
00034 connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(summary()));
00035 connect(this, SIGNAL(accepted()), this, SLOT(generate()));
00036 connect(this, SIGNAL(rejected()), this, SLOT(resetConfig()));
00037 }
00038
00039 NewApplicationWizard::~NewApplicationWizard()
00040 {
00041 application_config_ = NULL;
00042 if (architecture_config_)
00043 {
00044 delete architecture_config_;
00045 architecture_config_ = NULL;
00046 }
00047 if (package_config_)
00048 {
00049 delete package_config_;
00050 package_config_ = NULL;
00051 }
00052 }
00053
00054 RqtMrtaApplicationConfig* NewApplicationWizard::getApplicationConfig() const
00055 {
00056 return application_config_;
00057 }
00058
00059 RqtMrtaApplicationPackageConfig* NewApplicationWizard::getPackageConfig() const
00060 {
00061 return package_config_;
00062 }
00063
00064 RqtMrtaArchitectureConfig* NewApplicationWizard::getArchitectureConfig() const
00065 {
00066 return architecture_config_;
00067 }
00068
00069 void NewApplicationWizard::generate()
00070 {
00071 package_config_->addRunDepend(
00072 application_config_->getApplication()->getArchitecturePackage());
00073 if (package_config_->createPackage())
00074 {
00075 QString package_url(package_config_->getUrl());
00076 application_config_->setApplicationPackage(package_config_->getName());
00077 application_config_->setApplicationPackageUrl(package_url);
00078 ROS_INFO_STREAM(
00079 "Created package ["
00080 << application_config_->getApplicationPackage().toStdString() << "] @ ["
00081 << package_url.toStdString()
00082 << "].");
00083 application_config_->save();
00084 application_config_->getConfigs()->saveAsYaml(package_url);
00085 application_config_->getLaunches()->saveAsLaunch(package_url);
00086 }
00087 }
00088
00089 NewApplicationWizardPage* NewApplicationWizard::createSummaryPage()
00090 {
00091 NewApplicationWizardPage* page =
00092 new NewApplicationWizardPage(this, "Summary");
00093 page->setWidget(summary_label_);
00094 return page;
00095 }
00096
00097 void NewApplicationWizard::summary()
00098 {
00099 if (currentId() != Summary)
00100 {
00101 return;
00102 }
00103 QString summary;
00104 if (!package_config_->workspaceExists())
00105 {
00106 summary += "A ROS workspace will be created in:\n\n\t" +
00107 package_config_->getWorkspaceUrl() + "\n";
00108 }
00109 summary += "\nA ROS package will be created in:\n\n\t" +
00110 package_config_->getUrl() + "\n";
00111 summary += "\nThe following files and folder will be generated inside this "
00112 "ROS package:\n";
00113 QStringList list;
00114 list.append(package_config_->willBeGenerated());
00115 list.append(application_config_->getConfigs()->willBeGenerated());
00116 list.append(application_config_->getLaunches()->willBeGenerated());
00117 list.sort();
00118 for (size_t index(0); index < list.count(); index++)
00119 {
00120 summary += "\n\t" + list[index];
00121 }
00122 summary_label_->setText(summary);
00123 }
00124
00125 void NewApplicationWizard::resetConfig()
00126 {
00127 application_config_->reset();
00128 package_config_->reset();
00129 architecture_config_->reset();
00130 }
00131 }