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();
391void MainWindow::syncApplicationList(QString selectNodeForEditing,
bool open)
393 if (!listOfAppFiles.isEmpty())
395 watcher->removePaths(listOfAppFiles);
397 listOfAppFiles.clear();
398 ui->entitiesTree->clearApplications();
399 ui->entitiesTree->clearModules();
400 ui->entitiesTree->clearResources();
404 unsigned int cnt = 0;
405 for(
auto&
itr : apps){
409 ui->entitiesTree->addApplication(app);
410 if(strcmp(selectNodeForEditing.toLatin1().data(),app->getName())==0){
413 listOfAppFiles.push_back(app->getXmlFile());
417 watcher->addPaths(listOfAppFiles);
420 for(
auto& resource : resources) {
423 ui->entitiesTree->addComputer(comp);
428 for(
auto& module : modules) {
431 ui->entitiesTree->addModule(mod);
437 QString msg = QString(
"%1 applications are loaded successfully.").arg(cnt);
441 QString msg = QString(
"No application is loaded!");
449bool MainWindow::loadRecursiveTemplates(
const char* szPath)
452 std::string strPath = szPath;
453 if((strPath.rfind(directorySeparator)==std::string::npos) ||
454 (strPath.rfind(directorySeparator)!=strPath.size()-1)) {
455 strPath.append(directorySeparator);
459 struct dirent *entry;
460 if ((dir = opendir(strPath.c_str())) ==
nullptr) {
469 while((tmp = tempload.getNextAppTemplate())){
470 ui->entitiesTree->addAppTemplate(tmp);
474 while((entry = readdir(dir)))
476 if((std::string(entry->d_name) != std::string(
"."))
477 && (std::string(entry->d_name) != std::string(
"..")))
480 std::string name = strPath + std::string(entry->d_name);
481 loadRecursiveTemplates(name.c_str());
492bool MainWindow::loadRecursiveApplications(
const char* szPath)
495 std::string strPath = szPath;
496 if ((strPath.rfind(directorySeparator) == std::string::npos) || (strPath.rfind(directorySeparator) != strPath.size() - 1)) {
497 strPath = strPath + directorySeparator;
501 struct dirent *entry;
502 if ((dir = opendir(strPath.c_str())) ==
nullptr) {
508 while((entry = readdir(dir)))
510 if((std::string(entry->d_name) != std::string(
"."))
511 && (std::string(entry->d_name) != std::string(
"..")))
513 std::string name = strPath + std::string(entry->d_name);
514 loadRecursiveApplications(name.c_str());
521bool MainWindow::initializeFile(std::string _class)
524 bool b = f.open(QIODevice::ReadWrite);
525 QString appTemplate =
"<application>\n"
526 " <name>" + currentAppName +
"</name>\n"
527 " <description>" + currentAppDescription +
"</description>\n"
528 " <version>" + currentAppVersion +
"</version>\n"
533 if (_class ==
"Resource") {
535 }
else if (_class ==
"Module") {
537 }
else if (_class ==
"Application") {
538 f.write(appTemplate.toStdString().c_str());
547 QString err = QString(
"Cannot create %1").arg(fileName);
548 logger->
addError(err.toLatin1().data());
554int MainWindow::getAppTabIndex(QString appName)
556 for (
int i=0; i<ui->mainTabs->count(); i++){
557 if (ui->mainTabs->tabText(i) == appName){
564QString MainWindow::getAppNameFromXml(QString fileName)
569 for(
auto&
itr : apps)
574 if(app->getXmlFile() == fileName.toStdString())
588 for(
int i=0;i<ui->mainTabs->count();i++){
589 if(ui->mainTabs->tabText(i) == res->
getName()){
590 ui->mainTabs->setCurrentIndex(i);
596 int index = ui->mainTabs->addTab(w,res->
getName());
597 ui->mainTabs->setTabIcon(index,QIcon(
":/computer22.svg"));
598 ui->mainTabs->setCurrentIndex(index);
606 for(
int i=0;i<ui->mainTabs->count();i++){
607 if(ui->mainTabs->tabText(i) == module->
getName()){
608 ui->mainTabs->setCurrentIndex(i);
614 int index = ui->mainTabs->addTab(w,module->
getName());
615 ui->mainTabs->setTabIcon(index,QIcon(
":/module22.svg"));
616 ui->mainTabs->setCurrentIndex(index);
625 for (
int i=0; i<ui->mainTabs->count(); i++){
626 if (ui->mainTabs->tabText(i) == app->
getName()){
627 ui->mainTabs->setCurrentIndex(i);
633 connect(w,
SIGNAL(logError(QString)),
this,SLOT(onLogError(QString)));
634 connect(w,
SIGNAL(logWarning(QString)),
this,SLOT(onLogWarning(QString)));
635 connect(w,
SIGNAL(modified(
bool)),
this,SLOT(onModified(
bool)));
636 int index = ui->mainTabs->addTab(w,app->
getName());
637 ui->mainTabs->setTabIcon(index,QIcon(
":/run22.svg"));
638 ui->mainTabs->setCurrentIndex(index);
645 ui->actionSelect_All->setEnabled(
false);
646 ui->actionRefresh_Status->setEnabled(
false);
647 ui->actionExport_Graph->setEnabled(
false);
648 ui->actionConnect_all->setEnabled(
false);
649 ui->actionDisconnect_all->setEnabled(
false);
650 ui->actionRun_all->setEnabled(
false);
651 ui->actionStop_all->setEnabled(
false);
652 ui->actionKill_all->setEnabled(
false);
653 ui->actionConnect->setEnabled(
false);
654 ui->actionDisconnect->setEnabled(
false);
655 ui->actionRun->setEnabled(
false);
656 ui->actionStop->setEnabled(
false);
657 ui->actionKill->setEnabled(
false);
659 ui->actionSelect_All->setEnabled(
true);
660 ui->actionRefresh_Status->setEnabled(
true);
661 ui->actionExport_Graph->setEnabled(
true);
662 ui->actionConnect_all->setEnabled(
true);
663 ui->actionDisconnect_all->setEnabled(
true);
664 ui->actionRun_all->setEnabled(
true);
665 ui->actionStop_all->setEnabled(
true);
666 ui->actionKill_all->setEnabled(
true);
673void MainWindow::onExportGraph()
675 QWidget *w = ui->mainTabs->currentWidget();
688void MainWindow::onRun(
bool onlySelected)
690 QWidget *w = ui->mainTabs->currentWidget();
697 ww->runApplicationSet(onlySelected);
703void MainWindow::onStop(
bool onlySelected)
705 QWidget *w = ui->mainTabs->currentWidget();
712 ww->stopApplicationSet(onlySelected);
718void MainWindow::onKill(
bool onlySelected)
720 QWidget *w = ui->mainTabs->currentWidget();
727 ww->killApplicationSet(onlySelected);
733void MainWindow::onConnect(
bool onlySelected)
735 QWidget *w = ui->mainTabs->currentWidget();
742 ww->connectConnectionSet(onlySelected);
747void MainWindow::onDisconnect(
bool onlySelected)
749 QWidget *w = ui->mainTabs->currentWidget();
756 ww->disconnectConnectionSet(onlySelected);
760void MainWindow::onRunSelected()
764void MainWindow::onStopSelected()
768void MainWindow::onKillSelected()
772void MainWindow::onConnectSelected()
776void MainWindow::onDisconnectSelected()
782void MainWindow::onRefresh()
784 QWidget *w = ui->mainTabs->currentWidget();
802void MainWindow::onSelectAll()
804 QWidget *w = ui->mainTabs->currentWidget();
818bool MainWindow::onTabClose(
int index)
829 msgBox.setIcon(QMessageBox::Icon::Warning);
830 msgBox.setWindowTitle(QString(
"Closing %1").arg(ui->mainTabs->tabText(index)));
831 msgBox.setText(tr(
"You have some running module. After closing the application window you might not be able to recover them. Are you sure?"));
832 QPushButton* noButton = msgBox.addButton(tr(
"No"), QMessageBox::NoRole);
833 QPushButton* pstopAndClose = msgBox.addButton(tr(
"Yes and Stop"), QMessageBox::YesRole);
834 msgBox.addButton(tr(
"Yes"), QMessageBox::YesRole);
835 msgBox.setDefaultButton(noButton);
838 if (msgBox.clickedButton() == noButton)
842 else if(msgBox.clickedButton() == pstopAndClose)
851 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()),
852 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
853 if(btn == QMessageBox::Yes){
857 ui->mainTabs->removeTab(index);
862 QMessageBox::critical(
this,
"Error",QString(
"Error Saving the file"));
866 if(btn == QMessageBox::Cancel){
869 if (btn == QMessageBox::No){
870 QFile file(fileOfCurrentApp);
872 ui->entitiesTree->setCurrentItem(ui->entitiesTree->getWidgetItemByFilename(fileOfCurrentApp));
873 ui->entitiesTree->onRemove();
875 ui->mainTabs->removeTab(index);
884 ui->mainTabs->removeTab(index);
892void MainWindow::onLogError(QString msg)
894 QString text = QString (
"[ERR] %1").arg(msg);
895 ui->logWidget->addItem(text);
896 ui->logWidget->item(ui->logWidget->count() - 1)->setBackground(QColor(
"#F9CCCA"));
897 ui->logWidget->setCurrentRow(ui->logWidget->count() - 1);
903void MainWindow::onLogWarning(QString msg)
905 QString text = QString (
"[WAR] %1").arg(msg);
906 ui->logWidget->addItem(text);
907 ui->logWidget->item(ui->logWidget->count() - 1)->setBackground(QColor(
"#FFF6C8"));
908 ui->logWidget->setCurrentRow(ui->logWidget->count() - 1);
914void MainWindow::onLogMessage(QString msg)
918 QString text = QString (
"[MSG] %1").arg(msg);
919 ui->logWidget->addItem(text);
920 ui->logWidget->setCurrentRow(ui->logWidget->count() - 1);
934 ui->actionSelect_All->setEnabled(
false);
935 ui->actionRefresh_Status->setEnabled(
false);
936 ui->actionExport_Graph->setEnabled(
false);
937 ui->actionConnect_all->setEnabled(
false);
938 ui->actionDisconnect_all->setEnabled(
false);
939 ui->actionRun_all->setEnabled(
false);
940 ui->actionStop_all->setEnabled(
false);
941 ui->actionKill_all->setEnabled(
false);
942 ui->actionConnect->setEnabled(
false);
943 ui->actionDisconnect->setEnabled(
false);
944 ui->actionRun->setEnabled(
false);
945 ui->actionStop->setEnabled(
false);
946 ui->actionKill->setEnabled(
false);
948 ui->actionSelect_All->setEnabled(
true);
949 ui->actionRefresh_Status->setEnabled(
true);
950 ui->actionExport_Graph->setEnabled(
true);
951 ui->actionConnect_all->setEnabled(
true);
952 ui->actionDisconnect_all->setEnabled(
true);
953 ui->actionRun_all->setEnabled(
true);
954 ui->actionStop_all->setEnabled(
true);
955 ui->actionKill_all->setEnabled(
true);
961 ui->actionSave->setEnabled(
true);
962 ui->actionSave_As->setEnabled(
true);
964 ui->actionSave->setEnabled(
false);
965 ui->actionSave_As->setEnabled(
false);
971 ui->actionRefresh_Status->setEnabled(
true);
974 ui->actionRefresh_Status->setEnabled(
false);
975 prevWidget =
nullptr;
978 ui->actionSelect_All->setEnabled(
false);
979 ui->actionExport_Graph->setEnabled(
false);
980 ui->actionConnect_all->setEnabled(
false);
981 ui->actionDisconnect_all->setEnabled(
false);
982 ui->actionRun_all->setEnabled(
false);
983 ui->actionStop_all->setEnabled(
false);
984 ui->actionKill_all->setEnabled(
false);
985 ui->actionConnect->setEnabled(
false);
986 ui->actionDisconnect->setEnabled(
false);
987 ui->actionRun->setEnabled(
false);
988 ui->actionStop->setEnabled(
false);
989 ui->actionKill->setEnabled(
false);
994void MainWindow::onNewApplication()
997 newApplicationWizard->setWindowTitle(
"Create New Application");
998 if (newApplicationWizard->exec() == QDialog::Accepted){
1000 currentAppName = newApplicationWizard->name;
1001 currentAppDescription = newApplicationWizard->description;
1002 currentAppVersion = newApplicationWizard->version;
1003 fileName = newApplicationWizard->fileName;
1004 size_t len = newApplicationWizard->name.toLatin1().size();
1006 appName =
new char [len+1];
1007 strncpy(appName, newApplicationWizard->name.toLatin1().data(), len);
1008 appName[len] =
'\0';
1009 if (newApplicationWizard->alreadyExists)
1011 if (!lazyManager.
removeApplication(newApplicationWizard->fileName.toLatin1().data(),
1023 initializeFile(
"Application");
1025 if (lazyManager.
addApplication(newApplicationWizard->fileName.toLatin1().data(),
1028 QString newApp(appName);
1029 syncApplicationList(newApp);
1042 delete newApplicationWizard;
1048 delete newApplicationWizard;
1049 qDebug() <<
"Rejected";
1053void MainWindow::onNewResource()
1057 fileName = QFileDialog::getSaveFileName(
this,
"Create new Resource description file",QApplication::applicationDirPath(),
1058 "Resource description files (*.xml)");
1060 if(!initializeFile(
"Resource"))
1062 QString msg = QString(
"Error while initializing %1.").arg(fileName.toStdString().c_str());
1063 logger->
addError(msg.toLatin1().data());
1069 if(launcher.
init(ext_editor.c_str(), fileName.toLatin1().data(),
nullptr,
nullptr,
nullptr,
nullptr)){
1070 if(!launcher.
start() && !launcher.
error().empty()){
1071 QString msg = QString(
"Error while launching %1. %2").arg(ext_editor.c_str()).arg(launcher.
error().c_str());
1072 logger->
addError(msg.toLatin1().data());
1080void MainWindow::onNewModule()
1084 fileName = QFileDialog::getSaveFileName(
this,
"Create new Module description file",QApplication::applicationDirPath(),
1085 "Module description files (*.xml)");
1087 if(!initializeFile(
"Module"))
1089 QString msg = QString(
"Error while initializing %1.").arg(fileName.toStdString().c_str());
1090 logger->
addError(msg.toLatin1().data());
1096 if(launcher.
init(ext_editor.c_str(), fileName.toLatin1().data(),
nullptr,
nullptr,
nullptr,
nullptr)){
1097 if(!launcher.
start() && !launcher.
error().empty()){
1098 QString msg = QString(
"Error while launching %1. %2").arg(ext_editor.c_str()).arg(launcher.
error().c_str());
1099 logger->
addError(msg.toLatin1().data());
1107void MainWindow::onImportFiles()
1109 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Please choose a folder"),
1110 QApplication::applicationDirPath(),
1111 QFileDialog::ShowDirsOnly
1112 | QFileDialog::DontResolveSymlinks);
1114 if(config.
find(
"load_subfolders").
asString() ==
"yes"){
1115 if (loadRecursiveApplications(dir.toLatin1().data())) {
1116 syncApplicationList();
1121 syncApplicationList();
1126 syncApplicationList();
1129 if(lazyManager.
addModules(dir.toLatin1().data())){
1130 syncApplicationList();
1138void MainWindow::onClose()
1140 int index = ui->mainTabs->currentIndex();
1147void MainWindow::onModified(
bool mod)
1149 ui->actionSave->setEnabled(mod);
1150 ui->actionSave_As->setEnabled(mod);
1151 int index = ui->mainTabs->currentIndex();
1156 ui->mainTabs->setTabText(index,w->getAppName() +
"*");
1157 gw->setModified(mod);
1159 ui->mainTabs->setTabText(index,w->getAppName());
1164void MainWindow::onFileChanged(
const QString &path)
1167 watcher->addPaths(listOfAppFiles);
1168 if (!ui->actionAuto_reload->isChecked())
1174 QString appName = getAppNameFromXml(path);
1176 QMessageBox::StandardButton reply;
1177 reply = QMessageBox::question(
this,
"File changed",
"Xml file '" + path +
1178 "' changed.\nDo you want to reload the application? If open, the respective tab will be closed",
1179 QMessageBox::Yes|QMessageBox::No);
1180 if (reply == QMessageBox::No) {
1187 int index = getAppTabIndex(appName);
1190 if (!onTabClose(index))
1217void MainWindow::onYarpClean()
1221 onLogWarning(QString::fromLatin1(
"yarpserver is not running"));
1224 QInputDialog* inputDialog =
new QInputDialog(
this);
1225 inputDialog->setOptions(QInputDialog::NoButtons);
1229 float timeout = inputDialog->getDouble(
nullptr ,
"Running yarp clean",
1230 "Be aware that yarp clean with a little timetout could\n"
1231 "unregister ports that are actually open.\n\n"
1232 "Timeout(seconds):", 0.3, 0, 2147483647, 1, &ok);
1235 onLogMessage(QString(
"YARP clean: cleaning death ports..."));
1242void MainWindow::onYarpNameList()
1246 onLogWarning(QString::fromLatin1(
"yarpserver is not running"));
1249 ui->entitiesTree->clearPorts();
1252 for(
auto& port : ports)
1254 std::string portName = port.name;
1255 std::string portIp = port.ip +
" port " + port.port_number;
1256 ui->entitiesTree->addPort(QStringList() << QString(portName.c_str())
1257 << QString(portIp.c_str()));
1259 onLogMessage(QString::fromLatin1(
"Running yarp name list...found %1 ports").arg(ports.size()));
1262void MainWindow::onSave()
1271 bool ret = ww->save();
1275 QMessageBox::critical(
this,
"Error",QString(
"Error Saving the file"));
1280void MainWindow::onSaveAs()
1283 newApplicationWizard->setWindowTitle(
"Save Application as");
1284 if(newApplicationWizard->exec() == QDialog::Accepted){
1285 fileName = newApplicationWizard->fileName;
1286 delete newApplicationWizard;
1290 delete newApplicationWizard;
1293 if(fileName.trimmed().size() == 0 || fileName.contains(
" ")){
1294 QMessageBox::critical(
nullptr, QObject::tr(
"Error"), QObject::tr(std::string(
"Invalid file name " + fileName.toStdString()).c_str()));
1305 QString oldAppName = ww->getAppName();
1306 QString oldFileName = ww->getFileName();
1307 ww->setFileName(fileName);
1308 size_t it1 = fileName.toStdString().find(
".xml");
1309 if(it1 == std::string::npos)
1311 yError(
"yarpmanager: '.xml' not present in filename");
1314 QString appName = fileName.toStdString().substr(0,it1).c_str();
1315 size_t it2 =appName.toStdString().find_last_of(
'/');
1316 if(it2 != std::string::npos)
1318 currentAppName = appName.toStdString().substr(it2+1).c_str();
1322 currentAppName = appName;
1324 ww->setAppName(currentAppName);
1325 if(fileName.isEmpty()){
1330 ww->setAppName(oldAppName);
1331 ww->setFileName(oldFileName);
1332 onTabClose(ui->mainTabs->currentIndex());
1333 syncApplicationList();
1343void MainWindow::onOpen()
1345 QString fileName = QFileDialog::getOpenFileName(
this,
"Please choose a File",QCoreApplication::applicationDirPath(),
1346 "Application description files (*.xml);;Modules description files (*.xml);;Resource description files (*.xml);;Any files (*.xml)");
1348 if(fileName.isEmpty()){
1352 char* name =
nullptr;
1354 if(lazyManager.
addApplication(fileName.toLatin1().data(), &name,
true)){
1355 QString appName(name);
1356 syncApplicationList(appName,
true);
1364 if(lazyManager.
addResource(fileName.toLatin1().data())){
1365 syncApplicationList();
1367 if(lazyManager.
addModule(fileName.toLatin1().data())){
1368 syncApplicationList();
1374void MainWindow::onAbout()
1376 QString copyright =
"Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)";
1379 AboutDlg dlg(name,version,copyright,
"https://www.iit.it/");
1385void MainWindow::onHelp()
1387 QDesktopServices::openUrl(QUrl(
"http://www.yarp.it/yarpmanager.html"));
1392 lazyManager.
removeApplication(xmlFile.toLatin1().data(),appName.toLatin1().data());
1393 syncApplicationList();
1399 lazyManager.
removeApplication(fileName.toLatin1().data(), appName.toLatin1().data());
1400 char * appNamePtr = appName.toLatin1().data();
1401 lazyManager.
addApplication(fileName.toLatin1().data(), &appNamePtr);
1402 syncApplicationList();
1408 syncApplicationList();
1414 lazyManager.
addModule(fileName.toLatin1().data());
1415 syncApplicationList();
1421 syncApplicationList();
1427 lazyManager.
addResource(fileName.toLatin1().data());
1428 syncApplicationList();
1433 QWidget *w = ui->mainTabs->currentWidget();
1440 ui->actionRun->setEnabled(ww->anyModuleSelected());
1441 ui->actionStop->setEnabled(ww->anyModuleSelected());
1442 ui->actionKill->setEnabled(ww->anyModuleSelected());
1443 ui->actionConnect->setEnabled(ww->anyConnectionSelected());
1444 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)