7#include "ui_mainwindow.h"
30#include <QDesktopServices>
31#include <QInputDialog>
40# pragma warning (disable : 4250)
41# pragma warning (disable : 4520)
46# if defined(YARP_HAS_SYS_TYPES_H)
47# include <sys/types.h>
49# if defined(YARP_HAS_SYS_WAIT_H)
55 #define APP_NAME "yarpmanager"
61 if (path[0]==
'/'||path[0]==
'\\') {
64 std::string str(path);
79 qRegisterMetaType< QVector<int> >(
"QVector<int>");
80 ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
81 ui->menuBar->setContextMenuPolicy(Qt::PreventContextMenu);
82 auto label =
new QLabel(
"", ui->statusBar);
83 auto yarpino =
new QLabel(
"", ui->statusBar);
84 QPixmap pixmap(QPixmap(
":/yarp-robot-22.png").scaledToHeight(ui->statusBar->height()));
85 yarpino->setPixmap(pixmap);
86 label->setText(
"Powered by");
87 ui->statusBar->insertPermanentWidget(0,label);
88 ui->statusBar->insertPermanentWidget(1,yarpino);
91 watcher =
new QFileSystemWatcher(
this);
98 connect(ui->entitiesTree,
SIGNAL(openFiles()),
this,SLOT(onOpen()));
99 connect(ui->entitiesTree,
SIGNAL(importFiles()),
this,SLOT(onImportFiles()));
100 connect(ui->entitiesTree,
SIGNAL(removeApplication(QString, QString)),
this,SLOT(onRemoveApplication(QString, QString)));
101 connect(ui->entitiesTree,
SIGNAL(removeModule(QString)),
this,SLOT(onRemoveModule(QString)));
102 connect(ui->entitiesTree,
SIGNAL(removeResource(QString)),
this,SLOT(onRemoveResource(QString)));
103 connect(ui->entitiesTree,
SIGNAL(reopenApplication(QString,QString)),
this,SLOT(onReopenApplication(QString,QString)),Qt::DirectConnection);
104 connect(ui->entitiesTree,
SIGNAL(reopenModule(QString,QString)),
this,SLOT(onReopenModule(QString,QString)),Qt::DirectConnection);
105 connect(ui->entitiesTree,
SIGNAL(reopenResource(QString,QString)),
this,SLOT(onReopenResource(QString,QString)),Qt::DirectConnection);
107 connect(ui->actionRun_all,
SIGNAL(triggered()),
this,SLOT(onRun()));
108 connect(ui->actionStop_all,
SIGNAL(triggered()),
this,SLOT(onStop()));
109 connect(ui->actionKill_all,
SIGNAL(triggered()),
this,SLOT(onKill()));
110 connect(ui->actionConnect_all,
SIGNAL(triggered()),
this,SLOT(onConnect()));
111 connect(ui->actionDisconnect_all,
SIGNAL(triggered()),
this,SLOT(onDisconnect()));
113 connect(ui->actionRun,
SIGNAL(triggered()),
this,SLOT(onRunSelected()));
114 connect(ui->actionStop,
SIGNAL(triggered()),
this,SLOT(onStopSelected()));
115 connect(ui->actionKill,
SIGNAL(triggered()),
this,SLOT(onKillSelected()));
116 connect(ui->actionConnect,
SIGNAL(triggered()),
this,SLOT(onConnectSelected()));
117 connect(ui->actionDisconnect,
SIGNAL(triggered()),
this,SLOT(onDisconnectSelected()));
119 connect(ui->actionRefresh_Status,
SIGNAL(triggered()),
this,SLOT(onRefresh()));
120 connect(ui->actionSelect_All,
SIGNAL(triggered()),
this,SLOT(onSelectAll()));
121 connect(ui->actionExport_Graph,
SIGNAL(triggered()),
this,SLOT(onExportGraph()));
122 connect(ui->actionNew_Application,
SIGNAL(triggered()),
this,SLOT(onNewApplication()));
123 connect(ui->actionImport_Files,
SIGNAL(triggered()),
this,SLOT(onImportFiles()));
124 connect(ui->mainTabs,
SIGNAL(tabCloseRequested(
int)),
this,SLOT(onTabClose(
int)));
125 connect(ui->mainTabs,
SIGNAL(currentChanged(
int)),
this,SLOT(onTabChangeItem(
int)));
126 connect(ui->actionNew_Module,
SIGNAL(triggered()),
this,SLOT(onNewModule()));
127 connect(ui->actionNew_Resource,
SIGNAL(triggered()),
this,SLOT(onNewResource()));
128 connect(ui->actionClose,
SIGNAL(triggered()),
this,SLOT(onClose()));
129 connect(ui->actionQuit,
SIGNAL(triggered()),
this,SLOT(close()));
130 connect(ui->actionOpen_File,
SIGNAL(triggered()),
this,SLOT(onOpen()));
131 connect(ui->actionSave,
SIGNAL(triggered()),
this,SLOT(onSave()));
132 connect(ui->actionSave_As,
SIGNAL(triggered()),
this,SLOT(onSaveAs()));
133 connect(ui->actionHelp,
SIGNAL(triggered()),
this,SLOT(onHelp()));
134 connect(ui->actionAbout,
SIGNAL(triggered()),
this,SLOT(onAbout()));
135 connect(ui->actionYarpClean,
SIGNAL(triggered()),
this, SLOT(onYarpClean()));
136 connect(ui->actionYarpNameList,
SIGNAL(triggered()),
this, SLOT(onYarpNameList()));
138 connect(
this,
SIGNAL(selectItem(QString,
bool)),ui->entitiesTree,SLOT(onSelectItem(QString,
bool)));
140 connect(watcher,
SIGNAL(fileChanged(
const QString &)),
this, SLOT(onFileChanged(
const QString &)));
143 this->addAction(ui->actionQuit);
144 this->addAction(ui->actionSave);
145 this->addAction(ui->actionSave_As);
146 this->addAction(ui->actionClose);
147 this->addAction(ui->actionRefresh_Status);
150 ui->actionConnect->setEnabled(
false);
151 ui->actionDisconnect->setEnabled(
false);
152 ui->actionRun->setEnabled(
false);
153 ui->actionStop->setEnabled(
false);
154 ui->actionKill->setEnabled(
false);
156 ui->actionAuto_reload->setChecked(
true);
158 ui->action_Manager_Window->setChecked(
true);
160 ui->tabWidgetLeft->tabBar()->hide();
165 if (!confFile.empty())
167 ui->clusterWidget->setConfigFile(confFile);
168 ui->clusterWidget->init();
169 connect(ui->clusterWidget,
SIGNAL(logError(QString)),
this, SLOT(onLogError(QString)));
170 connect(ui->clusterWidget,
SIGNAL(logMessage(QString)),
this, SLOT(onLogMessage(QString)));
174 ui->tabWidgetLeft->tabBar()->hide();
187 for(
int i=0;i<ui->mainTabs->count();i++){
196void MainWindow::onWizardError(QString err)
199 logger->
addError(err.toLatin1().data());
209 this->config = config;
214 if(config.
check(
"modpath")){
216 std::string modPaths(config.
find(
"modpath").
asString());
217 while (modPaths!=
""){
218 std::string::size_type pos=modPaths.find(
';');
219 strPath=modPaths.substr(0, pos);
222 strPath.insert(0, basepath);
224 if ((strPath.rfind(directorySeparator) == std::string::npos) || (strPath.rfind(directorySeparator) != strPath.size() - 1)) {
225 strPath.append(directorySeparator);
228 if (pos == std::string::npos || pos == 0) {
231 modPaths=modPaths.substr(pos+1);
235 if(config.
check(
"respath")){
237 std::string resPaths(config.
find(
"respath").
asString());
238 while (resPaths!=
""){
239 std::string::size_type pos=resPaths.find(
';');
240 strPath=resPaths.substr(0, pos);
243 strPath.insert(0, basepath);
246 if ((strPath.rfind(directorySeparator) == std::string::npos) || (strPath.rfind(directorySeparator) != strPath.size() - 1)) {
247 strPath.append(directorySeparator);
251 if (pos == std::string::npos) {
254 resPaths=resPaths.substr(pos+1);
261 if(config.
check(
"apppath")){
263 std::string appPaths(config.
find(
"apppath").
asString());
264 while (appPaths!=
""){
265 std::string::size_type pos=appPaths.find(
';');
266 strPath=appPaths.substr(0, pos);
269 strPath.insert(0, basepath);
272 if((strPath.rfind(directorySeparator)==std::string::npos) ||
273 (strPath.rfind(directorySeparator)!=strPath.size()-1)){
274 strPath.append(directorySeparator);
278 if(!loadRecursiveApplications(strPath.c_str())){
279 logger->
addError(
"Cannot load the applications from " + strPath);
281 loadRecursiveTemplates(strPath.c_str());
282 ui->entitiesTree->header()->setSortIndicator(0,Qt::SortOrder::AscendingOrder);
287 if (pos==std::string::npos){
290 appPaths=appPaths.substr(pos+1);
294 if (config.
check(
"templpath")){
296 std::string templPaths(config.
find(
"templpath").
asString());
297 while (templPaths!=
""){
298 std::string::size_type pos=templPaths.find(
';');
299 strPath=templPaths.substr(0, pos);
302 strPath.insert(0, basepath);
305 if(!loadRecursiveTemplates(strPath.c_str())){
306 logger->
addError(
"Cannot load the templates from " + strPath);
309 if (pos==std::string::npos){
312 templPaths=templPaths.substr(pos+1);
316 if(config.
check(
"external_editor")){
321 ext_editor =
"notepad.exe";
323 ext_editor =
"xdg-open";
329 syncApplicationList();
331 if(config.
check(
"application")){
343 syncApplicationList();
348 if (config.
check(
"load_application")){
349 std::string applicationName = config.
find(
"load_application").
asString();
352 logger->
addError(
"Cannot load the application with XmlAppLoader from " + applicationName);
357 logger->
addError(
"Cannot load the application from " + applicationName);
363 syncApplicationList();
370 if(config.
check(
"disable_autoreload")){
371 ui->actionAuto_reload->setChecked(
false);
395void MainWindow::syncApplicationList(QString selectNodeForEditing,
bool open)
397 if (!listOfAppFiles.isEmpty())
399 watcher->removePaths(listOfAppFiles);
401 listOfAppFiles.clear();
402 ui->entitiesTree->clearApplications();
403 ui->entitiesTree->clearModules();
404 ui->entitiesTree->clearResources();
408 unsigned int cnt = 0;
409 for(
auto&
itr : apps){
413 ui->entitiesTree->addApplication(app);
414 if(strcmp(selectNodeForEditing.toLatin1().data(),app->getName())==0){
417 listOfAppFiles.push_back(app->getXmlFile());
421 watcher->addPaths(listOfAppFiles);
424 for(
auto& resource : resources) {
427 ui->entitiesTree->addComputer(comp);
432 for(
auto& module : modules) {
435 ui->entitiesTree->addModule(mod);
441 QString msg = QString(
"%1 applications are loaded successfully.").arg(cnt);
445 QString msg = QString(
"No application is loaded!");
453bool MainWindow::loadRecursiveTemplates(
const char* szPath)
456 std::string strPath = szPath;
457 if((strPath.rfind(directorySeparator)==std::string::npos) ||
458 (strPath.rfind(directorySeparator)!=strPath.size()-1)) {
459 strPath.append(directorySeparator);
463 struct dirent *entry;
464 if ((dir = opendir(strPath.c_str())) ==
nullptr) {
473 while((tmp = tempload.getNextAppTemplate())){
474 ui->entitiesTree->addAppTemplate(tmp);
478 while((entry = readdir(dir)))
480 if((std::string(entry->d_name) != std::string(
"."))
481 && (std::string(entry->d_name) != std::string(
"..")))
484 std::string name = strPath + std::string(entry->d_name);
485 loadRecursiveTemplates(name.c_str());
496bool MainWindow::loadRecursiveApplications(
const char* szPath)
499 std::string strPath = szPath;
500 if ((strPath.rfind(directorySeparator) == std::string::npos) || (strPath.rfind(directorySeparator) != strPath.size() - 1)) {
501 strPath = strPath + directorySeparator;
505 struct dirent *entry;
506 if ((dir = opendir(strPath.c_str())) ==
nullptr) {
512 while((entry = readdir(dir)))
514 if((std::string(entry->d_name) != std::string(
"."))
515 && (std::string(entry->d_name) != std::string(
"..")))
517 std::string name = strPath + std::string(entry->d_name);
518 loadRecursiveApplications(name.c_str());
525bool MainWindow::initializeFile(std::string _class)
528 bool b = f.open(QIODevice::ReadWrite);
529 QString appTemplate =
"<application>\n"
530 " <name>" + currentAppName +
"</name>\n"
531 " <description>" + currentAppDescription +
"</description>\n"
532 " <version>" + currentAppVersion +
"</version>\n"
537 if (_class ==
"Resource") {
539 }
else if (_class ==
"Module") {
541 }
else if (_class ==
"Application") {
542 f.write(appTemplate.toStdString().c_str());
551 QString err = QString(
"Cannot create %1").arg(fileName);
552 logger->
addError(err.toLatin1().data());
558int MainWindow::getAppTabIndex(QString appName)
560 for (
int i=0; i<ui->mainTabs->count(); i++){
561 if (ui->mainTabs->tabText(i) == appName){
568QString MainWindow::getAppNameFromXml(QString fileName)
573 for(
auto&
itr : apps)
578 if(app->getXmlFile() == fileName.toStdString())
592 for(
int i=0;i<ui->mainTabs->count();i++){
593 if(ui->mainTabs->tabText(i) == res->
getName()){
594 ui->mainTabs->setCurrentIndex(i);
600 int index = ui->mainTabs->addTab(w,res->
getName());
601 ui->mainTabs->setTabIcon(index,QIcon(
":/computer22.svg"));
602 ui->mainTabs->setCurrentIndex(index);
610 for(
int i=0;i<ui->mainTabs->count();i++){
611 if(ui->mainTabs->tabText(i) == module->
getName()){
612 ui->mainTabs->setCurrentIndex(i);
618 int index = ui->mainTabs->addTab(w,module->
getName());
619 ui->mainTabs->setTabIcon(index,QIcon(
":/module22.svg"));
620 ui->mainTabs->setCurrentIndex(index);
629 for (
int i=0; i<ui->mainTabs->count(); i++){
630 if (ui->mainTabs->tabText(i) == app->
getName()){
631 ui->mainTabs->setCurrentIndex(i);
637 connect(w,
SIGNAL(logError(QString)),
this,SLOT(onLogError(QString)));
638 connect(w,
SIGNAL(logWarning(QString)),
this,SLOT(onLogWarning(QString)));
639 connect(w,
SIGNAL(modified(
bool)),
this,SLOT(onModified(
bool)));
640 int index = ui->mainTabs->addTab(w,app->
getName());
641 ui->mainTabs->setTabIcon(index,QIcon(
":/run22.svg"));
642 ui->mainTabs->setCurrentIndex(index);
649 ui->actionSelect_All->setEnabled(
false);
650 ui->actionRefresh_Status->setEnabled(
false);
651 ui->actionExport_Graph->setEnabled(
false);
652 ui->actionConnect_all->setEnabled(
false);
653 ui->actionDisconnect_all->setEnabled(
false);
654 ui->actionRun_all->setEnabled(
false);
655 ui->actionStop_all->setEnabled(
false);
656 ui->actionKill_all->setEnabled(
false);
657 ui->actionConnect->setEnabled(
false);
658 ui->actionDisconnect->setEnabled(
false);
659 ui->actionRun->setEnabled(
false);
660 ui->actionStop->setEnabled(
false);
661 ui->actionKill->setEnabled(
false);
663 ui->actionSelect_All->setEnabled(
true);
664 ui->actionRefresh_Status->setEnabled(
true);
665 ui->actionExport_Graph->setEnabled(
true);
666 ui->actionConnect_all->setEnabled(
true);
667 ui->actionDisconnect_all->setEnabled(
true);
668 ui->actionRun_all->setEnabled(
true);
669 ui->actionStop_all->setEnabled(
true);
670 ui->actionKill_all->setEnabled(
true);
677void MainWindow::onExportGraph()
679 QWidget *w = ui->mainTabs->currentWidget();
692void MainWindow::onRun(
bool onlySelected)
694 QWidget *w = ui->mainTabs->currentWidget();
701 ww->runApplicationSet(onlySelected);
707void MainWindow::onStop(
bool onlySelected)
709 QWidget *w = ui->mainTabs->currentWidget();
716 ww->stopApplicationSet(onlySelected);
722void MainWindow::onKill(
bool onlySelected)
724 QWidget *w = ui->mainTabs->currentWidget();
731 ww->killApplicationSet(onlySelected);
737void MainWindow::onConnect(
bool onlySelected)
739 QWidget *w = ui->mainTabs->currentWidget();
746 ww->connectConnectionSet(onlySelected);
751void MainWindow::onDisconnect(
bool onlySelected)
753 QWidget *w = ui->mainTabs->currentWidget();
760 ww->disconnectConnectionSet(onlySelected);
764void MainWindow::onRunSelected()
768void MainWindow::onStopSelected()
772void MainWindow::onKillSelected()
776void MainWindow::onConnectSelected()
780void MainWindow::onDisconnectSelected()
786void MainWindow::onRefresh()
788 QWidget *w = ui->mainTabs->currentWidget();
806void MainWindow::onSelectAll()
808 QWidget *w = ui->mainTabs->currentWidget();
822bool MainWindow::onTabClose(
int index)
833 msgBox.setIcon(QMessageBox::Icon::Warning);
834 msgBox.setWindowTitle(QString(
"Closing %1").arg(ui->mainTabs->tabText(index)));
835 msgBox.setText(tr(
"You have some running module. After closing the application window you might not be able to recover them. Are you sure?"));
836 QPushButton* noButton = msgBox.addButton(tr(
"No"), QMessageBox::NoRole);
837 QPushButton* pstopAndClose = msgBox.addButton(tr(
"Yes and Stop"), QMessageBox::YesRole);
838 msgBox.addButton(tr(
"Yes"), QMessageBox::YesRole);
839 msgBox.setDefaultButton(noButton);
842 if (msgBox.clickedButton() == noButton)
846 else if(msgBox.clickedButton() == pstopAndClose)
855 QMessageBox::StandardButton btn = QMessageBox::question(
this,
"Save",QString(
"%1 has been modified\nDo you want to save it before closing?").arg(aw->
getAppName().toLatin1().data()),
856 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
857 if(btn == QMessageBox::Yes){
858 bool ret = aw->
save();
861 ui->mainTabs->removeTab(index);
866 QMessageBox::critical(
this,
"Error",QString(
"Error Saving the file"));
870 if(btn == QMessageBox::Cancel){
873 if (btn == QMessageBox::No){
874 QFile file(fileOfCurrentApp);
876 ui->entitiesTree->setCurrentItem(ui->entitiesTree->getWidgetItemByFilename(fileOfCurrentApp));
877 ui->entitiesTree->onRemove();
879 ui->mainTabs->removeTab(index);
888 ui->mainTabs->removeTab(index);
896void MainWindow::onLogError(QString msg)
898 QString text = QString (
"[ERR] %1").arg(msg);
899 ui->logWidget->addItem(text);
900 ui->logWidget->item(ui->logWidget->count() - 1)->setBackground(QColor(
"#F9CCCA"));
901 ui->logWidget->setCurrentRow(ui->logWidget->count() - 1);
907void MainWindow::onLogWarning(QString msg)
909 QString text = QString (
"[WAR] %1").arg(msg);
910 ui->logWidget->addItem(text);
911 ui->logWidget->item(ui->logWidget->count() - 1)->setBackground(QColor(
"#FFF6C8"));
912 ui->logWidget->setCurrentRow(ui->logWidget->count() - 1);
918void MainWindow::onLogMessage(QString msg)
922 QString text = QString (
"[MSG] %1").arg(msg);
923 ui->logWidget->addItem(text);
924 ui->logWidget->setCurrentRow(ui->logWidget->count() - 1);
938 ui->actionSelect_All->setEnabled(
false);
939 ui->actionRefresh_Status->setEnabled(
false);
940 ui->actionExport_Graph->setEnabled(
false);
941 ui->actionConnect_all->setEnabled(
false);
942 ui->actionDisconnect_all->setEnabled(
false);
943 ui->actionRun_all->setEnabled(
false);
944 ui->actionStop_all->setEnabled(
false);
945 ui->actionKill_all->setEnabled(
false);
946 ui->actionConnect->setEnabled(
false);
947 ui->actionDisconnect->setEnabled(
false);
948 ui->actionRun->setEnabled(
false);
949 ui->actionStop->setEnabled(
false);
950 ui->actionKill->setEnabled(
false);
952 ui->actionSelect_All->setEnabled(
true);
953 ui->actionRefresh_Status->setEnabled(
true);
954 ui->actionExport_Graph->setEnabled(
true);
955 ui->actionConnect_all->setEnabled(
true);
956 ui->actionDisconnect_all->setEnabled(
true);
957 ui->actionRun_all->setEnabled(
true);
958 ui->actionStop_all->setEnabled(
true);
959 ui->actionKill_all->setEnabled(
true);
965 ui->actionSave->setEnabled(
true);
966 ui->actionSave_As->setEnabled(
true);
968 ui->actionSave->setEnabled(
false);
969 ui->actionSave_As->setEnabled(
false);
975 ui->actionRefresh_Status->setEnabled(
true);
978 ui->actionRefresh_Status->setEnabled(
false);
979 prevWidget =
nullptr;
982 ui->actionSelect_All->setEnabled(
false);
983 ui->actionExport_Graph->setEnabled(
false);
984 ui->actionConnect_all->setEnabled(
false);
985 ui->actionDisconnect_all->setEnabled(
false);
986 ui->actionRun_all->setEnabled(
false);
987 ui->actionStop_all->setEnabled(
false);
988 ui->actionKill_all->setEnabled(
false);
989 ui->actionConnect->setEnabled(
false);
990 ui->actionDisconnect->setEnabled(
false);
991 ui->actionRun->setEnabled(
false);
992 ui->actionStop->setEnabled(
false);
993 ui->actionKill->setEnabled(
false);
998void MainWindow::onNewApplication()
1001 newApplicationWizard->setWindowTitle(
"Create New Application");
1002 if (newApplicationWizard->exec() == QDialog::Accepted){
1004 currentAppName = newApplicationWizard->name;
1005 currentAppDescription = newApplicationWizard->description;
1006 currentAppVersion = newApplicationWizard->version;
1007 fileName = newApplicationWizard->fileName;
1008 size_t len = newApplicationWizard->name.toLatin1().size();
1010 appName =
new char [len+1];
1011 strncpy(appName, newApplicationWizard->name.toLatin1().data(), len);
1012 appName[len] =
'\0';
1013 if (newApplicationWizard->alreadyExists)
1015 if (!lazyManager.
removeApplication(newApplicationWizard->fileName.toLatin1().data(),
1027 initializeFile(
"Application");
1029 if (lazyManager.
addApplication(newApplicationWizard->fileName.toLatin1().data(),
1032 QString newApp(appName);
1033 syncApplicationList(newApp);
1046 delete newApplicationWizard;
1052 delete newApplicationWizard;
1053 qDebug() <<
"Rejected";
1057void MainWindow::onNewResource()
1061 fileName = QFileDialog::getSaveFileName(
this,
"Create new Resource description file",QApplication::applicationDirPath(),
1062 "Resource description files (*.xml)");
1064 if(!initializeFile(
"Resource"))
1066 QString msg = QString(
"Error while initializing %1.").arg(fileName.toStdString().c_str());
1067 logger->
addError(msg.toLatin1().data());
1073 if(launcher.
init(ext_editor.c_str(), fileName.toLatin1().data(),
nullptr,
nullptr,
nullptr,
nullptr)){
1074 if(!launcher.
start() && !launcher.
error().empty()){
1075 QString msg = QString(
"Error while launching %1. %2").arg(ext_editor.c_str()).arg(launcher.
error().c_str());
1076 logger->
addError(msg.toLatin1().data());
1084void MainWindow::onNewModule()
1088 fileName = QFileDialog::getSaveFileName(
this,
"Create new Module description file",QApplication::applicationDirPath(),
1089 "Module description files (*.xml)");
1091 if(!initializeFile(
"Module"))
1093 QString msg = QString(
"Error while initializing %1.").arg(fileName.toStdString().c_str());
1094 logger->
addError(msg.toLatin1().data());
1100 if(launcher.
init(ext_editor.c_str(), fileName.toLatin1().data(),
nullptr,
nullptr,
nullptr,
nullptr)){
1101 if(!launcher.
start() && !launcher.
error().empty()){
1102 QString msg = QString(
"Error while launching %1. %2").arg(ext_editor.c_str()).arg(launcher.
error().c_str());
1103 logger->
addError(msg.toLatin1().data());
1111void MainWindow::onImportFiles()
1113 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Please choose a folder"),
1114 QApplication::applicationDirPath(),
1115 QFileDialog::ShowDirsOnly
1116 | QFileDialog::DontResolveSymlinks);
1118 if(config.
find(
"load_subfolders").
asString() ==
"yes"){
1119 if (loadRecursiveApplications(dir.toLatin1().data())) {
1120 syncApplicationList();
1125 syncApplicationList();
1130 syncApplicationList();
1133 if(lazyManager.
addModules(dir.toLatin1().data())){
1134 syncApplicationList();
1142void MainWindow::onClose()
1144 int index = ui->mainTabs->currentIndex();
1151void MainWindow::onModified(
bool mod)
1153 ui->actionSave->setEnabled(mod);
1154 ui->actionSave_As->setEnabled(mod);
1155 int index = ui->mainTabs->currentIndex();
1160 ui->mainTabs->setTabText(index,w->getAppName() +
"*");
1161 gw->setModified(mod);
1163 ui->mainTabs->setTabText(index,w->getAppName());
1168void MainWindow::onFileChanged(
const QString &path)
1171 watcher->addPaths(listOfAppFiles);
1172 if (!ui->actionAuto_reload->isChecked())
1178 QString appName = getAppNameFromXml(path);
1180 QMessageBox::StandardButton reply;
1181 reply = QMessageBox::question(
this,
"File changed",
"Xml file '" + path +
1182 "' changed.\nDo you want to reload the application? If open, the respective tab will be closed",
1183 QMessageBox::Yes|QMessageBox::No);
1184 if (reply == QMessageBox::No) {
1191 int index = getAppTabIndex(appName);
1194 if (!onTabClose(index))
1221void MainWindow::onYarpClean()
1225 onLogWarning(QString::fromLatin1(
"yarpserver is not running"));
1228 QInputDialog* inputDialog =
new QInputDialog(
this);
1229 inputDialog->setOptions(QInputDialog::NoButtons);
1233 float timeout = inputDialog->getDouble(
nullptr ,
"Running yarp clean",
1234 "Be aware that yarp clean with a little timetout could\n"
1235 "unregister ports that are actually open.\n\n"
1236 "Timeout(seconds):", 0.3, 0, 2147483647, 1, &ok);
1239 onLogMessage(QString(
"YARP clean: cleaning death ports..."));
1246void MainWindow::onYarpNameList()
1250 onLogWarning(QString::fromLatin1(
"yarpserver is not running"));
1253 ui->entitiesTree->clearPorts();
1256 for(
auto& port : ports)
1258 std::string portName = port.name;
1259 std::string portIp = port.ip +
" port " + port.port_number;
1260 ui->entitiesTree->addPort(QStringList() << QString(portName.c_str())
1261 << QString(portIp.c_str()));
1263 onLogMessage(QString::fromLatin1(
"Running yarp name list...found %1 ports").arg(ports.size()));
1266void MainWindow::onSave()
1275 bool ret = ww->save();
1279 QMessageBox::critical(
this,
"Error",QString(
"Error Saving the file"));
1284void MainWindow::onSaveAs()
1287 newApplicationWizard->setWindowTitle(
"Save Application as");
1288 if(newApplicationWizard->exec() == QDialog::Accepted){
1289 fileName = newApplicationWizard->fileName;
1290 delete newApplicationWizard;
1294 delete newApplicationWizard;
1297 if(fileName.trimmed().size() == 0 || fileName.contains(
" ")){
1298 QMessageBox::critical(
nullptr, QObject::tr(
"Error"), QObject::tr(std::string(
"Invalid file name " + fileName.toStdString()).c_str()));
1309 QString oldAppName = ww->getAppName();
1310 QString oldFileName = ww->getFileName();
1311 ww->setFileName(fileName);
1312 size_t it1 = fileName.toStdString().find(
".xml");
1313 if(it1 == std::string::npos)
1315 yError(
"yarpmanager: '.xml' not present in filename");
1318 QString appName = fileName.toStdString().substr(0,it1).c_str();
1319 size_t it2 =appName.toStdString().find_last_of(
'/');
1320 if(it2 != std::string::npos)
1322 currentAppName = appName.toStdString().substr(it2+1).c_str();
1326 currentAppName = appName;
1328 ww->setAppName(currentAppName);
1329 if(fileName.isEmpty()){
1334 ww->setAppName(oldAppName);
1335 ww->setFileName(oldFileName);
1336 onTabClose(ui->mainTabs->currentIndex());
1337 syncApplicationList();
1347void MainWindow::onOpen()
1349 QString fileName = QFileDialog::getOpenFileName(
this,
"Please choose a File",QCoreApplication::applicationDirPath(),
1350 "Application description files (*.xml);;Modules description files (*.xml);;Resource description files (*.xml);;Any files (*.xml)");
1352 if(fileName.isEmpty()){
1356 char* name =
nullptr;
1358 if(lazyManager.
addApplication(fileName.toLatin1().data(), &name,
true)){
1359 QString appName(name);
1360 syncApplicationList(appName,
true);
1368 if(lazyManager.
addResource(fileName.toLatin1().data())){
1369 syncApplicationList();
1371 if(lazyManager.
addModule(fileName.toLatin1().data())){
1372 syncApplicationList();
1378void MainWindow::onAbout()
1380 QString copyright =
"Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)";
1383 AboutDlg dlg(name,version,copyright,
"https://www.iit.it/");
1389void MainWindow::onHelp()
1391 QDesktopServices::openUrl(QUrl(
"http://www.yarp.it/yarpmanager.html"));
1396 lazyManager.
removeApplication(xmlFile.toLatin1().data(),appName.toLatin1().data());
1397 syncApplicationList();
1403 lazyManager.
removeApplication(fileName.toLatin1().data(), appName.toLatin1().data());
1404 char * appNamePtr = appName.toLatin1().data();
1405 lazyManager.
addApplication(fileName.toLatin1().data(), &appNamePtr);
1406 syncApplicationList();
1412 syncApplicationList();
1418 lazyManager.
addModule(fileName.toLatin1().data());
1419 syncApplicationList();
1425 syncApplicationList();
1431 lazyManager.
addResource(fileName.toLatin1().data());
1432 syncApplicationList();
1437 QWidget *w = ui->mainTabs->currentWidget();
1444 ui->actionRun->setEnabled(ww->anyModuleSelected());
1445 ui->actionStop->setEnabled(ww->anyModuleSelected());
1446 ui->actionKill->setEnabled(ww->anyModuleSelected());
1447 ui->actionConnect->setEnabled(ww->anyConnectionSelected());
1448 ui->actionDisconnect->setEnabled(ww->anyConnectionSelected());
int SIGNAL(int pid, int signum)
void closeEvent(QCloseEvent *event) override
void onReopenApplication(QString, QString)
void init(yarp::os::Property config)
Init the application with the current configuration.
MainWindow(const yarp::os::ResourceFinder &rf, yarp::dev::IBattery *ibat, QWidget *parent=0, double refresh_period=10.0)
void onReopenModule(QString, QString)
void viewApplication(yarp::manager::Application *app, bool editingMode)
Load the Application on the MainWindow.
void onTabChangeItem(int)
Called when a tab has been pressed.
void viewModule(yarp::manager::Module *)
Load the Module on the MainWindow.
void selectItem(QString, bool)
void onApplicationSelectionChanged()
void onRemoveResource(QString)
void onRemoveApplication(QString, QString)
void onReopenResource(QString, QString)
void onRemoveModule(QString)
void reportErrors()
Reports tge error on the log window.
void viewResource(yarp::manager::Computer *res)
Load the Resource on the MainWindow.
friend class NewApplicationWizard
Singleton class For storing execution start time.
static ClockStart & getInstance()
std::string getStartTime() const
Get the starting time as a string in HH:MM:SS format.
Singleton class ErrorLogger.
const char * getLastError()
void addError(const char *szError)
static ErrorLogger * Instance()
Singleton class ErrorLogger.
const char * getLastWarning()
const ModulePContainer & getModules(Application *parent=nullptr)
Application * getApplication()
const ApplicaitonPContainer & getApplications(Application *parent=nullptr)
const ResourcePContainer & getResources(Application *parent=nullptr)
bool addApplication(Application *application, char **szAppName_=nullptr, bool modifyName=false)
std::string error() override
bool removeApplication(const char *szFileName, const char *szAppName)
bool addModule(const char *szFileName)
bool removeModule(const char *szModName)
bool addModules(const char *szPath)
bool addResources(const char *szPath)
Node * getNode(std::string appName)
bool addApplication(const char *szFileName, char **szAppName_=nullptr, bool modifyName=false)
bool addResource(const char *szFileName)
bool removeResource(const char *szResName)
bool addApplications(const char *szPath)
KnowledgeBase * getKnowledgeBase()
Application * getNextApplication() override
static bool checkNetwork()
Check if the YARP Network is up and running.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Helper class for finding config files and other external resources.
static ResourceFinder & getResourceFinderSingleton()
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
std::string findFileByName(const std::string &name)
Find the full path to a file.
A single value (typically within a Bottle).
virtual std::string asString() const
Get string value.
static bool getPortsList(ports_name_set &ports, bool complete=false)
static bool yarpClean(float timeout=0.1)
std::vector< PortInfo > ports_name_set
static constexpr value_type preferred_separator
void trimString(std::string &str)
enum yarp::manager::__NodeType NodeType
std::vector< Module * > ModulePContainer
std::vector< GenericResource * > ResourcePContainer
std::string getElapsedTimeString(const std::string &startTimeStr)
std::vector< Application * > ApplicaitonPContainer
Abstract Class TempLoader.
static const std::string str_res_template
static const std::string str_mod_template
bool isAbsolute(const char *path)