YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
applicationviewwidget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
7#include "ui_applicationviewwidget.h"
8#include <QMessageBox>
9#include <QMenu>
10#include <QFileDialog>
11#include <yarp/os/Log.h>
12#include <yarp/os/LogStream.h>
13#include <yarp/os/Bottle.h>
14#include <yarp/os/Carriers.h>
16#include "yscopewindow.h"
17#include <QTreeWidgetItem>
18#include <QMainWindow>
19#include <QMdiArea>
20
21
23 yarp::manager::Manager *lazyManager,
24 yarp::os::Property* config,
25 bool editingMode,
26 QWidget *parent) :
29 modRunAction(nullptr),
30 modStopAction(nullptr),
31 modkillAction(nullptr),
32 modSeparator(nullptr),
33 modRefreshAction(nullptr),
34 modSelectAllAction(nullptr),
35 modAttachAction(nullptr),
36 modAssignAction(nullptr),
37 connContex(nullptr),
38 connSubMenu(nullptr),
39 connConnectAction(nullptr),
40 connDisconnectAction(nullptr),
41 connSeparatorAction(nullptr),
42 connRefreshAction(nullptr),
43 connSelectAllAction(nullptr),
44 conn1SeparatorAction(nullptr),
45 connInspectAction(nullptr),
46 connYARPViewAction(nullptr),
47 connYARPReadAction(nullptr),
48 connYARPHearAction(nullptr),
49 connYARPScopeAction(nullptr),
50 resRefreshAction(nullptr),
51 resSelectAllAction(nullptr)
52{
53 ui->setupUi(this);
54 lazy = lazyManager;
55 this->app = app;
56 m_pConfig = config;
57 this->editingMode = editingMode;
58 this->m_modified = false;
60
61 QGridLayout *l;
62
63 if (!editingMode) {
64 prepareManagerFrom(lazy);
65
66 ui->moduleList->resizeColumnToContents(0);
67 ui->moduleList->resizeColumnToContents(1);
68 ui->moduleList->resizeColumnToContents(2);
69 ui->moduleList->resizeColumnToContents(3);
70 ui->moduleList->resizeColumnToContents(4);
71 ui->moduleList->resizeColumnToContents(5);
72 ui->moduleList->resizeColumnToContents(6);
73 ui->moduleList->resizeColumnToContents(7);
74
75 ui->resourcesList->resizeColumnToContents(0);
76 ui->resourcesList->resizeColumnToContents(1);
77 ui->resourcesList->resizeColumnToContents(2);
78 ui->resourcesList->resizeColumnToContents(3);
79
80
81 ui->connectionList->resizeColumnToContents(0);
82 ui->connectionList->resizeColumnToContents(1);
83 ui->connectionList->resizeColumnToContents(2);
84 ui->connectionList->resizeColumnToContents(3);
85 ui->connectionList->resizeColumnToContents(4);
86 ui->connectionList->resizeColumnToContents(5);
87
88 connect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
89 connect(ui->moduleList,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,int)));
90
91 connect(ui->resourcesList,SIGNAL(itemSelectionChanged()),this,SLOT(onResourceItemSelectionChanged()));
92 connect(ui->resourcesList,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,int)));
93
94 connect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
95 connect(ui->connectionList,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onItemDoubleClicked(QTreeWidgetItem*,int)));
96
97 connect(this,SIGNAL(selfSafeLoadBolance()),this,SLOT(onSelfSafeLoadBalance()),Qt::QueuedConnection);
98 connect(this,SIGNAL(selfConnect(int)),this,SLOT(onSelfConnect(int)),Qt::QueuedConnection);
99 connect(this,SIGNAL(selfDisconnect(int)),this,SLOT(onSelfDisconnect(int)),Qt::QueuedConnection);
100 connect(this,SIGNAL(selfResAvailable(int)),this,SLOT(onSelfResAvailable(int)),Qt::QueuedConnection);
101 connect(this,SIGNAL(selfResUnavailable(int)),this,SLOT(onSelfResUnavailable(int)),Qt::QueuedConnection);
102 connect(this,SIGNAL(selfStart(int)),this,SLOT(onSelfStart(int)),Qt::QueuedConnection);
103 connect(this,SIGNAL(selfStop(int)),this,SLOT(onSelfStop(int)),Qt::QueuedConnection);
104
105 createModulesViewContextMenu();
106 createConnectionsViewContextMenu();
107 createResourcesViewContextMenu();
108
109 l = new QGridLayout(ui->builderContainer);
110 ui->builderContainer->setLayout(l);
111
112
113 } else {
114 layout()->removeWidget(ui->mainSplietter);
115 delete ui->mainSplietter;
116 l = (QGridLayout*)layout();
117
118 }
119
120
121 l->setMargin(0);
122
123
124 builderWindowContainer = new QMainWindow(nullptr,Qt::Widget);
125 builderWindowContainer->setDockNestingEnabled(true);
126 l->addWidget(builderWindowContainer);
127
128 builderWidget = new QDockWidget("YARP Builder",builderWindowContainer);
129 builderWindowContainer->addDockWidget(Qt::TopDockWidgetArea,builderWidget);
130 builder = YarpBuilderLib::getBuilder(this->app,lazyManager,&safeManager,editingMode);
131 builderWidget->setWidget(builder);
132 //builderWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
133 builderWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
134 connect(builderWidget,SIGNAL(topLevelChanged(bool)),this,SLOT(onBuilderFloatChanged(bool)));
135
136 //builderWidget->pos()
137
138 if (!editingMode) {
139 //builder->addAction(modRunAction);
140 //builder->addAction(modStopAction);
141 //builder->addAction(modkillAction);
142 //builder->addAction(modSeparator);
143 //builder->addAction(modRefreshAction);
144 builder->addAction(modSelectAllAction);
145 //builder->addAction(modAttachAction);
146 //builder->addAction(modAssignAction);
147 builder->addAction(modSeparator);
148 //builder->addAction(connConnectAction);
149 //builder->addAction(connDisconnectAction);
150 //builder->addAction(connSeparatorAction);
151 //builder->addAction(connRefreshAction);
152 builder->addAction(connSelectAllAction);
153 //builder->addAction(conn1SeparatorAction);
154
155
156 builder->addModulesAction(modRunAction);
157 builder->addModulesAction(modStopAction);
158 builder->addModulesAction(modkillAction);
159 builder->addModulesAction(modSeparator);
160 builder->addModulesAction(modRefreshAction);
161 builder->addModulesAction(modSelectAllAction);
162 builder->addModulesAction(modAttachAction);
163 builder->addModulesAction(modAssignAction);
164
165 builder->addConnectionsAction(connConnectAction);
166 builder->addConnectionsAction(connDisconnectAction);
167 builder->addConnectionsAction(connSeparatorAction);
168 builder->addConnectionsAction(connRefreshAction);
169 builder->addConnectionsAction(connSelectAllAction);
170 builder->addConnectionsAction(conn1SeparatorAction);
171
172
173 connect(builder,SIGNAL(refreshApplication()),
174 this,SLOT(onRefreshApplication()),Qt::DirectConnection);
175 connect(builder,SIGNAL(setModuleSelected(QList<int>)),this,SLOT(onModuleSelected(QList<int>)));
176 connect(builder,SIGNAL(setConnectionSelected(QList<int>)),this,SLOT(onConnectionSelected(QList<int>)));
177
178 } else {
179 connect(builder,SIGNAL(modified(bool)),this,SLOT(onModified(bool)));
180 }
181
182
183 builder->load();
184 builderToolBar = builder->getToolBar();
185}
186
188{
189 bool ret = true;
190 if (builder) {
191 ret = builder->save();
192 }
193 return ret;
194}
195
197{
198 if (builder) {
199 return builder->getFileName();
200 } else {
201 return {};
202 };
203}
204
206{
207 if (builder) {
208 builder->setFileName(filename);
209 }
210 return;
211}
212
214{
215 if (builder) {
216 return builder->getAppName();
217 } else {
218 return {};
219 };
220}
221
223{
224 if (builder) {
225 builder->setAppName(appName);
226 }
227 return;
228}
229
234
236{
237 builderWidget->setVisible(show);
238}
239
241{
242 return !ui->moduleList->selectedItems().isEmpty();
243}
245{
246 return !ui->connectionList->selectedItems().isEmpty();
247}
248
250{
251 return ui->moduleList;
252}
253
255{
256 return ui->connectionList;
257}
258
260{
261 return builderToolBar;
262}
263
265void ApplicationViewWidget::createModulesViewContextMenu()
266{
267 modRunAction = new QAction("Run",this);
268 modStopAction = new QAction("Stop",this);
269 modkillAction = new QAction("Kill",this);
270 modSeparator = new QAction(this);
271 modSeparator->setSeparator(true);
272 modRefreshAction = new QAction("Refresh Status",this);
273 modSelectAllAction = new QAction("Select All Modules",this);
274 modAttachAction = new QAction("Attach to stdout",this);
275 modAssignAction = new QAction("Assign Hosts",this);
276
277 modRunAction->setIcon(QIcon(":/play22.svg"));
278 modStopAction->setIcon(QIcon(":/stop22.svg"));
279 modkillAction->setIcon(QIcon(":/kill22.svg"));
280 modRefreshAction->setIcon(QIcon(":/refresh22.svg"));
281 modSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
282 modAssignAction->setIcon(QIcon(":/computer-available22.svg"));
283
284
285 ui->moduleList->addAction(modRunAction);
286 ui->moduleList->addAction(modStopAction);
287 ui->moduleList->addAction(modkillAction);
288 ui->moduleList->addAction(modSeparator);
289 ui->moduleList->addAction(modRefreshAction);
290 ui->moduleList->addAction(modSelectAllAction);
291 ui->moduleList->addAction(modAttachAction);
292 ui->moduleList->addAction(modAssignAction);
293
294 connect(modRunAction,SIGNAL(triggered()),this,SLOT(onRun()));
295 connect(modStopAction,SIGNAL(triggered()),this,SLOT(onStop()));
296 connect(modkillAction,SIGNAL(triggered()),this,SLOT(onKill()));
297 connect(modRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
298 connect(modSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllModule()));
299 connect(modAttachAction,SIGNAL(triggered()),this,SLOT(onAttachStdout()));
300 connect(modAssignAction,SIGNAL(triggered()),this,SLOT(onAssignHost()));
301
302 onModuleItemSelectionChanged();
303}
304
306void ApplicationViewWidget::createConnectionsViewContextMenu()
307{
308 connContex = new QMenu(ui->connectionList);
309 connSubMenu = new QMenu("Inspect",connContex);
310
311 connConnectAction = new QAction("Connect",connContex);
312 connDisconnectAction = new QAction("Disconnect",connContex);
313 connSeparatorAction = new QAction(connContex);
314 connSeparatorAction->setSeparator(true);
315 connRefreshAction = new QAction("Refresh Status",connContex);
316 connSelectAllAction = new QAction("Select All Connections",connContex);
317 conn1SeparatorAction = new QAction(connContex);
318 conn1SeparatorAction->setSeparator(connContex);
319
320 connYARPViewAction = new QAction("yarpview",connSubMenu);
321 connYARPReadAction = new QAction("yarpread",connSubMenu);
322 connYARPHearAction = new QAction("yarphear",connSubMenu);
323 connYARPScopeAction = new QAction("yarpscope",connSubMenu);
324
325 connSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
326 connRefreshAction->setIcon(QIcon(":/refresh22.svg"));
327 connConnectAction->setIcon(QIcon(":/connect22.svg"));
328 connDisconnectAction->setIcon(QIcon(":/disconnect22.svg"));
329
330 connect(connConnectAction,SIGNAL(triggered()),this,SLOT(onConnect()));
331 connect(connDisconnectAction,SIGNAL(triggered()),this,SLOT(onDisconnect()));
332 connect(connRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
333 connect(connSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllConnections()));
334
335 connect(connYARPViewAction,SIGNAL(triggered()),this,SLOT(onYARPView()));
336 connect(connYARPReadAction,SIGNAL(triggered()),this,SLOT(onYARPRead()));
337 connect(connYARPHearAction,SIGNAL(triggered()),this,SLOT(onYARPHear()));
338 connect(connYARPScopeAction,SIGNAL(triggered()),this,SLOT(onYARPScope()));
339
340 connContex->addAction(connConnectAction);
341 connContex->addAction(connDisconnectAction);
342 connContex->addAction(connSeparatorAction);
343 connContex->addAction(connRefreshAction);
344 connContex->addAction(connSelectAllAction);
345 connContex->addAction(conn1SeparatorAction);
346 connContex->addMenu(connSubMenu);
347
348 connSubMenu->addAction(connYARPViewAction);
349 connSubMenu->addAction(connYARPReadAction);
350 connSubMenu->addAction(connYARPHearAction);
351 connSubMenu->addAction(connYARPScopeAction);
352
353
354 ui->connectionList->setContextMenu(connContex);
355
356 onConnectionItemSelectionChanged();
357
358}
359
361void ApplicationViewWidget::createResourcesViewContextMenu()
362{
363 resRefreshAction = new QAction("Refresh Status", this);
364 resSelectAllAction = new QAction("Select All Resources", this);
365
366 resRefreshAction->setIcon(QIcon(":/refresh22.svg"));
367 resSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
368
369 ui->resourcesList->addAction(resRefreshAction);
370 ui->resourcesList->addAction(resSelectAllAction);
371
372 connect(resRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
373 connect(resSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllResources()));
374}
375
377void ApplicationViewWidget::onConnectionItemSelectionChanged()
378{
379 if (ui->connectionList->selectedItems().isEmpty()) {
380 connConnectAction->setEnabled(false);
381 connDisconnectAction->setEnabled(false);
382 connSeparatorAction->setEnabled(false);
383 connRefreshAction->setEnabled(false);
384 } else {
385 connConnectAction->setEnabled(true);
386 connDisconnectAction->setEnabled(true);
387 connSeparatorAction->setEnabled(true);
388 connRefreshAction->setEnabled(true);
389 }
390
391 if (ui->connectionList->hasFocus()) {
392 QList<int>selectedIds;
393 QList<QTreeWidgetItem*> selectedItems = ui->connectionList->selectedItems();
394 foreach(QTreeWidgetItem *it,selectedItems) {
395 QString id = it->text(1);
396 selectedIds.append(id.toInt());
397 }
398
399 builder->setSelectedConnections(selectedIds);
400 }
401}
402
404void ApplicationViewWidget::onModuleItemSelectionChanged()
405{
406
407 if (ui->moduleList->selectedItems().isEmpty()) {
408 modRunAction->setEnabled(false);
409 modStopAction->setEnabled(false);
410 modkillAction->setEnabled(false);
411 modAttachAction->setEnabled(false);
412 modAssignAction->setEnabled(false);
413 modRefreshAction->setEnabled(false);
414 } else {
415 modRunAction->setEnabled(true);
416 modStopAction->setEnabled(true);
417 modkillAction->setEnabled(true);
418
419 bool all = true;
420 foreach (QTreeWidgetItem *it, ui->moduleList->selectedItems()) {
421 if (it->text(3) != "localhost") {
422 modAttachAction->setEnabled(false);
423 all = false;
424 break;
425 }
426 }
427 if (all) {
428 modAttachAction->setEnabled(true);
429 }
430
431 modAssignAction->setEnabled(true);
432 modRefreshAction->setEnabled(true);
433
434
435
436 if (ui->moduleList->hasFocus()) {
437
438 QList<int>selectedIds;
439 QList<QTreeWidgetItem*> selectedItems = ui->moduleList->selectedItems();
440 foreach(QTreeWidgetItem *it,selectedItems) {
441 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
442 for(int j=0;j<it->childCount();j++) {
443 QTreeWidgetItem *child = it->child(j);
444 child->setSelected(true);
445 }
446
447 }
448
449 }
450 selectedItems = ui->moduleList->selectedItems();
451 foreach(QTreeWidgetItem *it,selectedItems) {
452 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
453 continue;
454 }
455 QString id = it->text(1);
456 selectedIds.append(id.toInt());
457 }
458
459 builder->setSelectedModules(selectedIds);
460 }
461 }
462
463
464}
465
467void ApplicationViewWidget::onResourceItemSelectionChanged()
468{
469 if (ui->resourcesList->currentItem() == nullptr) {
470 resRefreshAction->setEnabled(false);
471 } else {
472 resRefreshAction->setEnabled(true);
473 }
474}
475
476void ApplicationViewWidget::prepareManagerFrom(yarp::manager::Manager* lazy)
477{
478
479 safeManager.prepare(lazy, m_pConfig,dynamic_cast<ApplicationEvent*>(this));
480
481 // loading application
482 if (safeManager.loadApplication(app->getName())) {
483 updateApplicationWindow();
484 }
485
486 reportErrors();
487}
488
489void ApplicationViewWidget::onRefreshApplication()
490{
491 //manager.close();
492
493 // loading application
494
495 if (safeManager.loadApplication(app->getName())) {
496 updateApplicationWindow();
497 }
498
499 reportErrors();
500}
501
502
503
504void ApplicationViewWidget::onConnectionSelected(QList<int> id)
505{
506 disconnect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
507 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
508 ui->connectionList->topLevelItem(i)->setSelected(false);
509 }
510 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
511 for(int j=0;j<id.count();j++) {
512 if (ui->connectionList->topLevelItem(i)->text(1).toInt() == id.at(j)) {
513 ui->connectionList->topLevelItem(i)->setSelected(true);
514 }
515 }
516
517 }
518 onConnectionItemSelectionChanged();
519 connect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
520}
521
522void ApplicationViewWidget::onModuleSelected(QList<int> id)
523{
524 disconnect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
525 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
526 ui->moduleList->topLevelItem(i)->setSelected(false);
527 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole) == APPLICATION ) {
528 for(int k=0;k<ui->moduleList->topLevelItem(i)->childCount();k++) {
529 ui->moduleList->topLevelItem(i)->child(k)->setSelected(false);
530 }
531 }
532 }
533
534 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
535 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole) == APPLICATION ) {
536 for(int k=0;k<ui->moduleList->topLevelItem(i)->childCount();k++) {
537 for(int j=0;j<id.count();j++) {
538 if (ui->moduleList->topLevelItem(i)->child(k)->text(1).toInt() == id.at(j)) {
539 ui->moduleList->topLevelItem(i)->child(k)->setSelected(true);
540 }
541 }
542
543
544 }
545
546 } else {
547 for(int j=0;j<id.count();j++) {
548 if (ui->moduleList->topLevelItem(i)->text(1).toInt() == id.at(j)) {
549 ui->moduleList->topLevelItem(i)->setSelected(true);
550 }
551 }
552 }
553
554
555 }
556 onModuleItemSelectionChanged();
557 connect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
558}
559
561void ApplicationViewWidget::updateApplicationWindow()
562{
563 ui->moduleList->clear();
564 ui->connectionList->clear();
565 ui->resourcesList->clear();
566 listOfResourceNames.clear();
567
568 disconnect(ui->moduleList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModuleItemChanged(QTreeWidgetItem*,int)));
569
571 yarp::manager::CnnContainer connections = safeManager.getConnections();
574
575 int id = 0;
576 for(moditr=modules.begin(); moditr<modules.end(); moditr++)
577 {
578
579 Module *mod = (*moditr)->getModule();
580 CustomTreeWidgetItem *appNode = nullptr;
581 QString modLabel = mod->owner()->getLabel();
582 QString appLabel = app->getLabel();
583 if (modLabel != appLabel) {
584
585 for(int i=0; i < ui->moduleList->topLevelItemCount();i++) {
586 if (ui->moduleList->topLevelItem(i)->data(0,Qt::UserRole + 1).toString() == modLabel) {
587 appNode = (CustomTreeWidgetItem*) ui->moduleList->topLevelItem(i);
588 break;
589 }
590 }
591 if (!appNode) {
592 QStringList l;
593 l << ((Application*)mod->owner())->getName();
594
595 appNode = new CustomTreeWidgetItem(ui->moduleList,l);
596 appNode->setData(0,Qt::UserRole + 1,modLabel);
597 appNode->setData(0,Qt::UserRole,APPLICATION);
598 appNode->setExpanded(true);
599 appNode->setIcon(0,QIcon(":/run22.svg"));
600 }
601 }
602 QString id = QString("%1").arg((*moditr)->getID());
603 QString command = QString("%1").arg((*moditr)->getCommand());
604 QString host = QString("%1").arg((*moditr)->getHost());
605 QString param = QString("%1").arg((*moditr)->getParam());
606 QString stdio = QString("%1").arg((*moditr)->getStdio());
607 QString workDir = QString("%1").arg((*moditr)->getWorkDir());
608 QString env = QString("%1").arg((*moditr)->getEnv());
609
610 // The default host is "localhost" if the <node> is not specified.
611 if(host.isEmpty())
612 {
613 host = "localhost";
614 }
615
616 QStringList l;
617 l << command << id << "stopped" << host << param << stdio << workDir << env;
618
620 if (!appNode) {
621 it = new CustomTreeWidgetItem(ui->moduleList,l);
622 } else {
623 it = new CustomTreeWidgetItem(appNode, l);
624 }
625
626 //it->setFlags(it->flags() | Qt::ItemIsEditable);
627 it->setData(0,Qt::UserRole,yarp::manager::MODULE);
628 it->setIcon(0,QIcon(":/close.svg"));
629 it->setForeground(2,QColor("#BF0303"));
630 ui->moduleList->addTopLevelItem(it);
631 }
632
633 id = 0;
634 for(cnnitr=connections.begin(); cnnitr<connections.end(); cnnitr++)
635 {
636 QString type;
637 if ((*cnnitr).isPersistent()) {
638 type = "Persistent";
639 } else {
640 if ((*cnnitr).isExternalFrom() || (*cnnitr).isExternalTo()) {
641 type = "External";
642 } else {
643 type = "Internal";
644 }
645 }
646 QString sId = QString("%1").arg(id);
647 QString from = QString("%1").arg((*cnnitr).from());
648 QString to = QString("%1").arg((*cnnitr).to());
649 QString carrier = QString("%1").arg((*cnnitr).carrier());
650 QString status = "disconnected";
651 QString modifier="";
652 // The default carrier is "tcp" if <protocol> is not specified.
653 if(carrier.isEmpty())
654 {
655 carrier = "tcp";
656 }
657 size_t pos = carrier.toStdString().find('+');
658 if(pos != std::string::npos)
659 {
660 modifier = carrier.mid(pos);
661 QStringList myStringList = carrier.split('+');
662 carrier = myStringList.first();
663 }
664
665
666 QStringList l;
667 l << type << sId << status << from << to << carrier << modifier;
668 auto* it = new CustomTreeWidgetItem(ui->connectionList,l);
669 ui->moduleList->addTopLevelItem(it);
670
671 //scanning available carriers:
672 scanAvailableCarriers(carrier,false);
673
674 auto* comboBox = new QComboBox(this);
675 comboBox->addItems(stringLst);
676 comboBox->setEditable(true);
677 ui->connectionList->setItemWidget((QTreeWidgetItem *) it,5, comboBox);
678 it->setData(0,Qt::UserRole,yarp::manager::INOUTD);
679 it->setIcon(0,QIcon(":/disconnect22.svg"));
680 it->setForeground(2,QColor("#BF0303"));
681 id++;
682 }
683
684 id = 0;
686 for(itrS=safeManager.getResources().begin(); itrS!=safeManager.getResources().end(); itrS++)
687 {
688 //m_resRow = *(m_refTreeResModel->append());
689 QString sId = QString("%1").arg(id);
690 QString type;
691 if (dynamic_cast<yarp::manager::Computer*>(*itrS))
692 {
693 type = "computer";
694 }
695 else if (dynamic_cast<yarp::manager::ResYarpPort*>(*itrS))
696 {
697 type = "port";
698 }
699 QString res = QString("%1").arg((*itrS)->getName());
700 if (std::find(listOfResourceNames.begin(),
701 listOfResourceNames.end(),
702 res.toStdString()) == listOfResourceNames.end())
703 {
704 listOfResourceNames.push_back(res.toStdString());
705 }
706 else
707 {
708 // The resource has been already added
709 continue;
710 }
711 QString status = "unknown";
712 //m_resRow[m_resColumns.m_col_color] = Gdk::Color("#00000");
713
714 QStringList l;
715 l << res << sId << type << status ;
716 auto* it = new CustomTreeWidgetItem(ui->resourcesList,l);
717 ui->moduleList->addTopLevelItem(it);
718 it->setData(0,Qt::UserRole,yarp::manager::RESOURCE);
719 if (type == "computer") {
720 it->setIcon(0,QIcon(":/computer-unavailable22.svg"));
721 it->setForeground(3,QColor("#BF0303"));
722 } else {
723 it->setIcon(0,QIcon(":/port-unavailable22.svg"));
724 it->setForeground(3,QColor("#BF0303"));
725 }
726 id++;
727 }
728 connect(ui->moduleList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModuleItemChanged(QTreeWidgetItem*,int)));
729}
730
731void ApplicationViewWidget::onModuleItemChanged(QTreeWidgetItem *it,int col)
732{
733 Qt::ItemFlags tmp = it->flags();
734 if (!(tmp & Qt::ItemIsEditable)) {
735 return;
736 }
737}
738
740void ApplicationViewWidget::onItemDoubleClicked(QTreeWidgetItem *it,int col)
741{
742 Qt::ItemFlags tmp = it->flags();
743 if (isEditable(it, col)) {
744 it->setFlags(tmp | Qt::ItemIsEditable);
745 disconnect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
746 connect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
747 } else if (tmp & Qt::ItemIsEditable) {
748 it->setFlags(tmp ^ Qt::ItemIsEditable);
749 disconnect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
750 connect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
751 }
752}
753
755void ApplicationViewWidget::onItemChanged(QTreeWidgetItem *it,int col)
756{
757 yarp::manager::NodeType type = (yarp::manager::NodeType)it->data(0,Qt::UserRole).toInt();
758 switch (type) {
760 ui->connectionList->blockSignals(true);
761 if (col == 3) {
762 updateConnectionItem(it);
763 bool res = safeManager.existPortFrom(it->text(1).toInt());
764 it->setForeground(3,QColor(res ? "#008C00" : "#BF0303"));
765 if (!res)
766 {
767 reportErrors();
768 }
769 }
770 if (col == 4) {
771 updateConnectionItem(it);
772 bool res = safeManager.existPortTo(it->text(1).toInt());
773 it->setForeground(3,QColor(res ? "#008C00" : "#BF0303"));
774 if (!res)
775 {
776 reportErrors();
777 }
778 }
779 ui->connectionList->blockSignals(false);
780 disconnect(ui->connectionList,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onItemChanged(QTreeWidgetItem*,int)));
781 break;
782 }
785 default:
786 break;
787 }
788}
789
794bool ApplicationViewWidget::isEditable(QTreeWidgetItem *it,int col)
795{
796 yarp::manager::NodeType type = (yarp::manager::NodeType)it->data(0,Qt::UserRole).toInt();
797
798 switch (type) {
800 if (col == 4 || col == 5 || col == 6 || col == 7) {
801 if (it->text(2) == "stopped") {
802 return true;
803 }
804 }
805 if (col == 3) {
806 if (it->text(2) == "stopped") {
807 return true;
808 }
809 }
810 break;
811 }
813 if (col == 3 || col == 4 || col == 5 || col == 6) {
814 if (it->text(2) == "disconnected") {
815 return true;
816 }
817 }
818 break;
819 }
821 return false;
822 break;
823 }
824 default:
825 break;
826 }
827
828 return false;
829}
830
831void ApplicationViewWidget::onCloseStdOut(int id)
832{
833 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
834 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
835 if (it->data(0,Qt::UserRole) == APPLICATION) {
836 closeNestedApplicationStdOut(it,id);
837 } else {
838 if (it->text(1).toInt() == id) {
839 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
840 if (stdouWin && stdouWin->getId() == id) {
841 delete stdouWin;
842 it->setData(0,Qt::UserRole,QVariant::fromValue(NULL));
843 return;
844 }
845 }
846 }
847 }
848}
849
850void ApplicationViewWidget::closeNestedApplicationStdOut(QTreeWidgetItem *it, int id)
851{
852 for(int j=0; j<it->childCount();j++) {
853 QTreeWidgetItem *ch = it->child(j);
854 if (ch->data(0,Qt::UserRole) == APPLICATION) {
855 closeNestedApplicationStdOut(it,id);
856 } else {
857 if (ch->text(1).toInt() == id) {
858 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
859 if (stdouWin && stdouWin->getId() == id) {
860 delete stdouWin;
861 ch->setData(0,Qt::UserRole,QVariant::fromValue(NULL));
862 return;
863 }
864 }
865 }
866 }
867}
868
869bool ApplicationViewWidget::areAllShutdown()
870{
871 bool ret = true;
872 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
873 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
874 if (it->data(0,Qt::UserRole) == APPLICATION) {
875 ret = areAllNestedApplicationShutdown(it);
876 if (!ret) {
877 return false;
878 }
879 } else {
880 if (it->text(2) != "stopped") {
881 return false;
882 }
883 }
884 }
885
886 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
887 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
888 if (it->text(2) != "disconnected") {
889 return false;
890 }
891 }
892
893 return ret;
894}
895
896bool ApplicationViewWidget::areAllNestedApplicationShutdown(QTreeWidgetItem *it)
897{
898 bool ret = true;
899 for(int j=0; j<it->childCount();j++) {
900 QTreeWidgetItem *ch = it->child(j);
901 if (ch->data(0,Qt::UserRole) == APPLICATION) {
902 ret = areAllNestedApplicationShutdown(ch);
903 if (!ret) {
904 return false;
905 }
906 } else {
907 if (ch->text(2) != "stopped") {
908 return false;
909 }
910 }
911 }
912 return ret;
913}
914
915void ApplicationViewWidget::onSelfSafeLoadBalance()
916{
917 updateApplicationWindow();
918 reportErrors();
919}
920
921void ApplicationViewWidget::onAssignHost()
922{
923 if (areAllShutdown() && !safeManager.busy()) {
924 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
925 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
926 if (it->data(0,Qt::UserRole) == APPLICATION) {
927 assignHostNestedApplication(it);
928 } else {
929 if (it->isSelected()) {
930 //QString waitHost = QString("%1").arg("?");
931 it->setText(2,"waiting");
932 it->setText(3,"?");
933 }
934 }
935
936
937 }
938 safeManager.safeLoadBalance();
940
941
942 } else {
944 logger->addError("Running modules should be stopped before assigning hosts.");
945 reportErrors();
946 }
947}
948
949void ApplicationViewWidget::assignHostNestedApplication(QTreeWidgetItem *it)
950{
951 for(int j=0; j<it->childCount();j++) {
952 QTreeWidgetItem *ch = it->child(j);
953 if (ch->data(0,Qt::UserRole) == APPLICATION) {
954 assignHostNestedApplication(ch);
955 } else {
956 if (ch->isSelected()) {
957 //QString waitHost = QString("%1").arg("?");
958 ch->setText(2,"waiting");
959 ch->setText(3,"?");
960 }
961 }
962 }
963}
964
965void ApplicationViewWidget::onAttachStdout()
966{
967 if (safeManager.busy()) {
968 return;
969 }
970
971 std::vector<int> MIDs;
972 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
973 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
974 if (it->data(0,Qt::UserRole) == APPLICATION) {
975 attachStdOutNestedApplication(it,&MIDs);
976 } else {
977 if (it->isSelected()) {
978 int id = it->text(1).toInt();
979
980 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
981 if (stdouWin && stdouWin->getId() == id) {
982 // found
983 continue;
984 }
985
986 MIDs.push_back(it->text(1).toInt());
987
988 QString name = QString("%1").arg(app->getName());
989 QString strTitle = name + ":" + it->text(0) + ":" + it->text(1);
990
991 StdoutWindow *stdOutWindow = new StdoutWindow(id,strTitle);
992 connect(stdOutWindow,SIGNAL(closeStdOut(int)),this,SLOT(onCloseStdOut(int)));
993 //stdoutWinList.append(stdOutWindow);
994 it->setData(0,Qt::UserRole,QVariant::fromValue(stdOutWindow));
995 stdOutWindow->show();
996 }
997 }
998
999
1000 }
1001 safeManager.safeAttachStdout(MIDs);
1002
1003 //return true;
1004}
1005
1006void ApplicationViewWidget::attachStdOutNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1007{
1008 for(int j=0; j<it->childCount();j++) {
1009 QTreeWidgetItem *ch = it->child(j);
1010 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1011 attachStdOutNestedApplication(ch,MIDs);
1012 } else {
1013 if (ch->isSelected()) {
1014 int id = ch->text(1).toInt();
1015
1016 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
1017 if (stdouWin && stdouWin->getId() == id) {
1018 // found
1019 continue;
1020 }
1021
1022 MIDs->push_back(ch->text(1).toInt());
1023
1024 QString name = QString("%1").arg(app->getName());
1025 QString strTitle = name + ":" + ch->text(0) + ":" + ch->text(1);
1026
1027 StdoutWindow *stdOutWindow = new StdoutWindow(id,strTitle);
1028 connect(stdOutWindow,SIGNAL(closeStdOut(int)),this,SLOT(onCloseStdOut(int)));
1029 //stdoutWinList.append(stdOutWindow);
1030 ch->setData(0,Qt::UserRole,QVariant::fromValue(stdOutWindow));
1031 stdOutWindow->show();
1032 }
1033
1034 }
1035 }
1036}
1037
1039bool ApplicationViewWidget::onRun()
1040{
1041 selectAllConnections(true);
1042 selectAllResources(true);
1043 if (safeManager.busy() ) {
1044 return false;
1045 }
1046
1047 std::vector<int> MIDs;
1048 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1049 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1050
1051 if (it->data(0,Qt::UserRole) == APPLICATION) {
1052 runNestedApplication(it,&MIDs);
1053
1054 } else {
1055 if (it->isSelected()) {
1056 MIDs.push_back(it->text(1).toInt());
1057 safeManager.updateExecutable(it->text(1).toInt(),
1058 it->text(4).toLatin1().data(),
1059 it->text(3).toLatin1().data(),
1060 it->text(5).toLatin1().data(),
1061 it->text(6).toLatin1().data(),
1062 it->text(7).toLatin1().data());
1063
1064 it->setText(2,"waiting");
1065 it->setIcon(0,QIcon(":/refresh.svg"));
1066 it->setForeground(2,QColor("#000000"));
1067
1068 }
1069
1070 //yDebug("Trying to run module ID %i param %s host %s stdio %s wdir %s env %s",it->text(1).toInt(),it->text(4).toLatin1().data(),
1071 // it->text(3).toLatin1().data(),it->text(5).toLatin1().data(),it->text(6).toLatin1().data(),it->text(7).toLatin1().data());
1072 }
1073 }
1074
1075 std::vector<int> CIDs;
1076 /*for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1077 {
1078 updateConnection(i, CIDs);
1079 }*/
1080
1081 std::vector<int> RIDs;
1082 /*for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1083 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1084 if (it->isSelected()) {
1085 RIDs.push_back(it->text(1).toInt());
1086 it->setText(3,"waiting");
1087 it->setIcon(0,QIcon(":/refresh22.svg"));
1088 it->setForeground(3,QColor("#000000"));
1089 }
1090 }*/
1091
1092
1093 safeManager.safeRun(MIDs,CIDs,RIDs);
1095 selectAllModule(false);
1096 selectAllConnections(false);
1097 selectAllResources(false);
1098 return true;
1099}
1100
1101void ApplicationViewWidget::runNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1102{
1103 for(int j=0; j<it->childCount();j++) {
1104 QTreeWidgetItem *ch = it->child(j);
1105
1106 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1107 runNestedApplication(ch,MIDs);
1108 } else {
1109 if (ch->isSelected()) {
1110 MIDs->push_back(ch->text(1).toInt());
1111 safeManager.updateExecutable(ch->text(1).toInt(),
1112 ch->text(4).toLatin1().data(),
1113 ch->text(3).toLatin1().data(),
1114 ch->text(5).toLatin1().data(),
1115 ch->text(6).toLatin1().data(),
1116 ch->text(7).toLatin1().data());
1117
1118 ch->setText(2,"waiting");
1119 ch->setIcon(0,QIcon(":/refresh.svg"));
1120 ch->setForeground(2,QColor("#000000"));
1121 }
1122 }
1123
1124
1125
1126 }
1127}
1128
1130bool ApplicationViewWidget::onStop()
1131{
1132 selectAllConnections(true);
1133 selectAllResources(true);
1134 if (safeManager.busy()) {
1135 return false;
1136 }
1137
1138 std::vector<int> MIDs;
1139 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1140 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1141 if (it->data(0,Qt::UserRole) == APPLICATION) {
1142 stopNestedApplication(it,&MIDs);
1143
1144 } else {
1145 if (it->isSelected()) {
1146 //moduluesIDs.append(it->text(1).toInt());
1147 MIDs.push_back(it->text(1).toInt());
1148 safeManager.updateExecutable(it->text(1).toInt(),
1149 it->text(4).toLatin1().data(),
1150 it->text(3).toLatin1().data(),
1151 it->text(5).toLatin1().data(),
1152 it->text(6).toLatin1().data(),
1153 it->text(7).toLatin1().data());
1154
1155 it->setText(2,"waiting");
1156 it->setIcon(0,QIcon(":/refresh.svg"));
1157 it->setForeground(2,QColor("#000000"));
1158
1159 }
1160 }
1161
1162 }
1163
1164 std::vector<int> CIDs;
1165 /*for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1166 {
1167 updateConnection(i, CIDs);
1168 }*/
1169
1170 std::vector<int> RIDs;
1171 /*for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1172 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1173 if (it->isSelected()) {
1174 RIDs.push_back(it->text(1).toInt());
1175 it->setText(3,"waiting");
1176 it->setIcon(0,QIcon(":/refresh22.svg"));
1177 it->setForeground(3,QColor("#000000"));
1178 }
1179 }*/
1180
1181
1182 safeManager.safeStop(MIDs,CIDs,RIDs);
1184 selectAllModule(false);
1185 selectAllConnections(false);
1186 selectAllResources(false);
1187 return true;
1188}
1189
1190void ApplicationViewWidget::stopNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1191{
1192 for(int j=0; j<it->childCount();j++) {
1193 QTreeWidgetItem *ch = it->child(j);
1194 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1195 stopNestedApplication(ch,MIDs);
1196 } else {
1197 if (ch->isSelected()) {
1198 MIDs->push_back(ch->text(1).toInt());
1199 safeManager.updateExecutable(ch->text(1).toInt(),
1200 ch->text(4).toLatin1().data(),
1201 ch->text(3).toLatin1().data(),
1202 ch->text(5).toLatin1().data(),
1203 ch->text(6).toLatin1().data(),
1204 ch->text(7).toLatin1().data());
1205
1206 ch->setText(2,"waiting");
1207 ch->setIcon(0,QIcon(":/refresh.svg"));
1208 ch->setForeground(2,QColor("#000000"));
1209 }
1210 }
1211
1212
1213
1214 }
1215}
1216
1218bool ApplicationViewWidget::onKill()
1219{
1220 selectAllConnections(true);
1221 selectAllResources(true);
1222 if (safeManager.busy()) {
1223 return false;
1224 }
1225
1226 if (QMessageBox::question(this,"Killing modules!","Are you sure?") != QMessageBox::Yes) {
1227 return true;
1228 }
1229
1230 std::vector<int> MIDs;
1231 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1232 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1233 if (it->data(0,Qt::UserRole) == APPLICATION) {
1234 killNestedApplication(it,&MIDs);
1235 } else {
1236 if (it->isSelected()) {
1237 //moduluesIDs.append(it->text(1).toInt());
1238 MIDs.push_back(it->text(1).toInt());
1239 safeManager.updateExecutable(it->text(1).toInt(),
1240 it->text(4).toLatin1().data(),
1241 it->text(3).toLatin1().data(),
1242 it->text(5).toLatin1().data(),
1243 it->text(6).toLatin1().data(),
1244 it->text(7).toLatin1().data());
1245
1246 it->setText(2,"waiting");
1247 it->setIcon(0,QIcon(":/refresh22.svg"));
1248 it->setForeground(2,QColor("#000000"));
1249
1250 }
1251 }
1252
1253 }
1254
1255 std::vector<int> CIDs;
1256 /*for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1257 {
1258 updateConnection(i, CIDs);
1259
1260 }*/
1261
1262 std::vector<int> RIDs;
1263 /*for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1264 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1265 if (it->isSelected()) {
1266 RIDs.push_back(it->text(1).toInt());
1267 it->setText(3,"waiting");
1268 it->setIcon(0,QIcon(":/refresh22.svg"));
1269 it->setForeground(3,QColor("#000000"));
1270 }
1271 }*/
1272
1273
1274 safeManager.safeKill(MIDs, CIDs, RIDs);
1276 selectAllModule(false);
1277 selectAllConnections(false);
1278 selectAllResources(false);
1279 return true;
1280}
1281
1282void ApplicationViewWidget::killNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1283{
1284 for(int j=0; j<it->childCount();j++) {
1285 QTreeWidgetItem *ch = it->child(j);
1286 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1287 killNestedApplication(ch,MIDs);
1288 } else {
1289 if (ch->isSelected()) {
1290 MIDs->push_back(ch->text(1).toInt());
1291 safeManager.updateExecutable(ch->text(1).toInt(),
1292 ch->text(4).toLatin1().data(),
1293 ch->text(3).toLatin1().data(),
1294 ch->text(5).toLatin1().data(),
1295 ch->text(6).toLatin1().data(),
1296 ch->text(7).toLatin1().data());
1297
1298 ch->setText(2,"waiting");
1299 ch->setIcon(0,QIcon(":/refresh.svg"));
1300 ch->setForeground(2,QColor("#000000"));
1301 }
1302 }
1303
1304
1305
1306 }
1307}
1308
1310bool ApplicationViewWidget::onConnect()
1311{
1312 if (safeManager.busy()) {
1313 return false;
1314 }
1315
1316
1317 std::vector<int> CIDs;
1318 for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1319 {
1320 updateConnection(i,CIDs);
1321 }
1322
1323
1324 safeManager.safeConnect(CIDs);
1326 selectAllConnections(false);
1327 return true;
1328}
1329
1331bool ApplicationViewWidget::onDisconnect()
1332{
1333 if (safeManager.busy()) {
1334 return false;
1335 }
1336
1337
1338 std::vector<int> CIDs;
1339 for(int i=0;i<ui->connectionList->topLevelItemCount();i++)
1340 {
1341 updateConnection(i, CIDs);
1342 }
1343
1344
1345 safeManager.safeDisconnect(CIDs);
1347 selectAllConnections(false);
1348 return true;
1349}
1350
1351
1353bool ApplicationViewWidget::onRefresh()
1354{
1355 if (safeManager.busy()) {
1356 return false;
1357 }
1358
1359 std::vector<int> modulesIDs;
1360 std::vector<int> connectionsIDs;
1361 std::vector<int> resourcesIDs;
1362
1363 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1364 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1365 if (it->data(0,Qt::UserRole) == APPLICATION) {
1366 refreshNestedApplication(it,&modulesIDs);
1367 } else {
1368 if (it->isSelected()) {
1369 modulesIDs.push_back(it->text(1).toInt());
1370 safeManager.updateExecutable(it->text(1).toInt(),
1371 it->text(4).toLatin1().data(),
1372 it->text(3).toLatin1().data(),
1373 it->text(5).toLatin1().data(),
1374 it->text(6).toLatin1().data(),
1375 it->text(7).toLatin1().data());
1376 it->setText(2,"waiting");
1377 it->setIcon(0,QIcon(":/refresh22.svg"));
1378 it->setForeground(2,QColor("#000000"));
1379 }
1380 }
1381
1382 }
1383
1384 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1385 updateConnection(i,connectionsIDs);
1386 }
1387
1388 for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1389 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1390 if (it->isSelected()) {
1391 resourcesIDs.push_back(it->text(1).toInt());
1392 it->setText(3,"waiting");
1393 it->setIcon(0,QIcon(":/refresh22.svg"));
1394 it->setForeground(3,QColor("#000000"));
1395 }
1396 }
1397
1398 safeManager.safeRefresh(modulesIDs,
1399 connectionsIDs,
1400 resourcesIDs);
1402 selectAllConnections(false);
1403 selectAllModule(false);
1404 selectAllResources(false);
1405
1406 return true;
1407}
1408void ApplicationViewWidget::refreshNestedApplication(QTreeWidgetItem *it,std::vector<int> *MIDs)
1409{
1410 for(int j=0; j<it->childCount();j++) {
1411 QTreeWidgetItem *ch = it->child(j);
1412
1413 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1414 refreshNestedApplication(ch,MIDs);
1415 } else {
1416 if (ch->isSelected()) {
1417 MIDs->push_back(ch->text(1).toInt());
1418 ch->setText(2,"waiting");
1419 ch->setIcon(0,QIcon(":/refresh22.svg"));
1420 ch->setForeground(2,QColor("#000000"));
1421 }
1422 }
1423
1424 }
1425}
1426
1428void ApplicationViewWidget::selectAllModule()
1429{
1430 selectAllModule(true);
1431}
1432
1434void ApplicationViewWidget::selectAllConnections()
1435{
1436 selectAllConnections(true);
1437}
1438
1440void ApplicationViewWidget::selectAllResources()
1441{
1442 selectAllResources(true);
1443}
1444
1448void ApplicationViewWidget::selectAllModule(bool check)
1449{
1450 disconnect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
1451 for(int i=0;i<ui->moduleList->topLevelItemCount();i++) {
1452 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
1453 if (it->data(0,Qt::UserRole) == APPLICATION) {
1454 selectAllNestedApplicationModule(it,check);
1455 } else {
1456 it->setSelected(check);
1457 }
1458 }
1459 if (ui->moduleList->selectedItems().isEmpty()) {
1460 modRunAction->setEnabled(false);
1461 modStopAction->setEnabled(false);
1462 modkillAction->setEnabled(false);
1463 modAttachAction->setEnabled(false);
1464 modAssignAction->setEnabled(false);
1465 modRefreshAction->setEnabled(false);
1466 } else {
1467 modRunAction->setEnabled(true);
1468 modStopAction->setEnabled(true);
1469 modkillAction->setEnabled(true);
1470
1471 bool all = true;
1472 foreach (QTreeWidgetItem *it, ui->moduleList->selectedItems()) {
1473 if (it->text(3) != "localhost") {
1474 modAttachAction->setEnabled(false);
1475 all = false;
1476 break;
1477 }
1478 }
1479 if (all) {
1480 modAttachAction->setEnabled(true);
1481 }
1482// if (ui->moduleList->currentItem()->text(3) == "localhost")
1483// {
1484// modAttachAction->setEnabled(true);
1485// }
1486// else
1487// {
1488// modAttachAction->setEnabled(false);
1489// }
1490 modAssignAction->setEnabled(true);
1491 modRefreshAction->setEnabled(true);
1492
1493
1494
1495
1496 QList<int>selectedIds;
1497 QList<QTreeWidgetItem*> selectedItems = ui->moduleList->selectedItems();
1498 foreach(QTreeWidgetItem *it,selectedItems) {
1499 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
1500 for(int j=0;j<it->childCount();j++) {
1501 QTreeWidgetItem *child = it->child(j);
1502 child->setSelected(true);
1503 }
1504
1505 }
1506
1507 }
1508 selectedItems = ui->moduleList->selectedItems();
1509 foreach(QTreeWidgetItem *it,selectedItems) {
1510 if (it->data(0,Qt::UserRole).toInt() == APPLICATION) {
1511 continue;
1512 }
1513 QString id = it->text(1);
1514 selectedIds.append(id.toInt());
1515 }
1516
1517 builder->setSelectedModules(selectedIds);
1518 }
1519
1520
1521 connect(ui->moduleList,SIGNAL(itemSelectionChanged()),this,SLOT(onModuleItemSelectionChanged()));
1522}
1523
1524void ApplicationViewWidget::selectAllNestedApplicationModule(QTreeWidgetItem *it,bool check)
1525{
1526 for(int j=0;j<it->childCount();j++) {
1527 QTreeWidgetItem *ch = it->child(j);
1528 if (ch->data(0,Qt::UserRole) == APPLICATION) {
1529 selectAllNestedApplicationModule(ch, check);
1530 } else {
1531 ch->setSelected(check);
1532 }
1533 }
1534}
1535
1536bool ApplicationViewWidget::scanAvailableCarriers(QString carrier, bool isConnection){
1539 bool res=false;
1540 stringLst.clear();
1541 stringLst.push_back(carrier);
1542 for (size_t i=0; i<lst.size(); i++)
1543 {
1544 if (lst.get(i).asString() == carrier.toStdString()) {
1545 res = true;
1546 } else {
1547 stringLst.push_back(lst.get(i).asString().c_str());
1548 }
1549 }
1550 if (!res && isConnection)
1551 {
1552 std::string msg = "Unable to find '"+ carrier.toStdString() +
1553 "' among the available carriers in this machine, the connection could fail.";
1554 logger->addWarning(msg.c_str());
1555 }
1556 return res;
1557}
1558
1559void ApplicationViewWidget::updateConnection(int index, std::vector<int>& CIDs)
1560{
1561 QTreeWidgetItem *it = ui->connectionList->topLevelItem(index);
1562 if (it->isSelected()) {
1563 updateConnectionItem(it);
1564
1565 CIDs.push_back(it->text(1).toInt());
1566
1567 it->setText(2,"waiting");
1568 it->setIcon(0,QIcon(":/refresh22.svg"));
1569 it->setForeground(2,QColor("#000000"));
1570 }
1571
1572}
1573
1574void ApplicationViewWidget::updateConnectionItem(QTreeWidgetItem *it)
1575{
1576 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
1577 QString carrier, modifier;
1578 if (box)
1579 {
1580 carrier = box->currentText();
1581
1582 }
1583 else
1584 {
1585 carrier=it->text(5);
1586 }
1587
1588 //checking if in the carrier has been added a modifier
1589
1590 size_t pos = carrier.toStdString().find('+');
1591 if(pos != std::string::npos)
1592 {
1593 modifier = carrier.mid(pos);
1594 QStringList myStringList = carrier.split('+');
1595 carrier = myStringList.first();
1596 box->setCurrentText(carrier);
1597 it->setText(6,modifier);
1598 }
1599
1600 // scan the available carriers in the system where yarpmanager is launched.
1601 scanAvailableCarriers(carrier);
1602 carrier = carrier + it->text(6); //adding modifier.
1603 safeManager.updateConnection(it->text(1).toInt(),
1604 it->text(3).toLatin1().data(),
1605 it->text(4).toLatin1().data(),
1606 carrier.toLatin1().data());
1607}
1608
1612void ApplicationViewWidget::selectAllConnections(bool check)
1613{
1614 disconnect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
1615 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1616 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1617 it->setSelected(check);
1618 }
1619
1620 if (ui->connectionList->selectedItems().isEmpty()) {
1621 connConnectAction->setEnabled(false);
1622 connDisconnectAction->setEnabled(false);
1623 connSeparatorAction->setEnabled(false);
1624 connRefreshAction->setEnabled(false);
1625 } else {
1626 connConnectAction->setEnabled(true);
1627 connDisconnectAction->setEnabled(true);
1628 connSeparatorAction->setEnabled(true);
1629 connRefreshAction->setEnabled(true);
1630 }
1631
1632 QList<int>selectedIds;
1633 QList<QTreeWidgetItem*> selectedItems = ui->connectionList->selectedItems();
1634 foreach(QTreeWidgetItem *it,selectedItems) {
1635 QString id = it->text(1);
1636 selectedIds.append(id.toInt());
1637 }
1638
1639 builder->setSelectedConnections(selectedIds);
1640 connect(ui->connectionList,SIGNAL(itemSelectionChanged()),this,SLOT(onConnectionItemSelectionChanged()));
1641
1642}
1643
1647void ApplicationViewWidget::selectAllResources(bool check)
1648{
1649 for(int i=0;i<ui->resourcesList->topLevelItemCount();i++) {
1650 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
1651 it->setSelected(check);
1652 }
1653}
1654
1658{
1659 selectAllConnections(true);
1660 selectAllModule(true);
1661 selectAllResources(true);
1662}
1663
1666{
1667 if (!onlySelected) {
1668 selectAllModule(true);
1669 }
1670 onRun();
1671}
1672
1675{
1676 if (!onlySelected) {
1677 selectAllModule(true);
1678 }
1679 onStop();
1680}
1681
1684{
1685 if (!onlySelected) {
1686 selectAllModule(true);
1687 }
1688 onKill();
1689}
1690
1693{
1694 if (!onlySelected) {
1695 selectAllConnections(true);
1696 }
1697 onConnect();
1698}
1699
1702{
1703 if (!onlySelected) {
1704 selectAllConnections(true);
1705 }
1706 onDisconnect();
1707}
1708
1711{
1712 selectAllConnections(true);
1713 selectAllModule(true);
1714 selectAllResources(true);
1715
1716 onRefresh();
1717}
1718
1720void ApplicationViewWidget::reportErrors()
1721{
1723 if (logger->errorCount() || logger->warningCount())
1724 {
1725 const char* err;
1726 while((err=logger->getLastError()))
1727 {
1728 QString msg = QString("(%1) %2").arg(app->getName()).arg(err);
1729 emit logError(msg);
1730 }
1731
1732 while((err=logger->getLastWarning()))
1733 {
1734 QString msg = QString("(%1) %2").arg(app->getName()).arg(err);
1735 emit logWarning(msg);
1736 }
1737 }
1738}
1739
1740
1743{
1744 QString fileName = QFileDialog::getSaveFileName(this,"Export Graph",QApplication::applicationDirPath(),"GraphViz format (*.dot)");
1745
1746 if (!fileName.isEmpty()) {
1747 if (!safeManager.exportDependencyGraph(fileName.toLatin1().data()))
1748 {
1750 logger->addError("Cannot export graph");
1751 reportErrors();
1752 return;
1753 }
1754 }
1755}
1756
1757
1759void ApplicationViewWidget::onYARPView()
1760{
1761 if (safeManager.busy()) {
1762 return;
1763 }
1765
1766 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1767 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1768 if (it->isSelected()) {
1769 QString from = it->text(3);
1770 QString to = QString("/inspect").arg(from);
1771 QString env = QString("YARP_PORT_PREFIX=%1").arg(to);
1772 to += "/yarpview/img:i";
1773
1775 if (launcher.init("yarpview", nullptr, nullptr, nullptr, nullptr, env.toLatin1().data()))
1776 {
1777 if (!launcher.start() && !launcher.error().empty())
1778 {
1779 QString msg;
1780 msg = QString("Error while launching yarpview. %1").arg(launcher.error().c_str());
1781 logger->addError(msg.toLatin1().data());
1782 reportErrors();
1783 }
1784 else
1785 {
1786 // waiting for the port to get open
1787 double base = yarp::os::SystemClock::nowSystem();
1788 while(!timeout(base, 3.0)) {
1789 if (launcher.exists(to.toLatin1().data())) {
1790 break;
1791 }
1792 }
1793 if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
1794 QString msg;
1795 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
1796 logger->addError(msg.toLatin1().data());
1797 launcher.stop();
1798 reportErrors();
1799 }
1800 }
1801 }
1802 }
1803 }
1804
1805
1807}
1808
1810void ApplicationViewWidget::onYARPHear()
1811{
1812 if (safeManager.busy()) {
1813 return;
1814 }
1816
1817 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1818 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1819 if (it->isSelected()) {
1820 QString from = it->text(3);
1821 QString to = QString("/inspect/hear%1").arg(from);
1822
1823#if defined(_WIN32)
1824 QString cmd = "cmd.exe";
1825 QString param;
1826 param = QString("/C yarphear --name %1").arg(to);
1827
1828#else
1829 QString cmd = "xterm";
1830 QString param;
1831 param = QString("-hold -title %1 -e yarphear --nodevice --name %2").arg(from).arg(to);
1832#endif
1833
1836 if (launcher.init(cmd.toLatin1().data(), param.toLatin1().data(), nullptr, nullptr, nullptr, nullptr))
1837 {
1838 if (!launcher.start() && !launcher.error().empty())
1839 {
1840 QString msg;
1841 msg = QString("Error while launching yarpread. %1").arg(launcher.error().c_str());
1842 logger->addError(msg.toLatin1().data());
1843 reportErrors();
1844 }
1845 else
1846 {
1847 // waiting for the port to get open
1848 double base = yarp::os::SystemClock::nowSystem();
1849 while(!timeout(base, 3.0)) {
1850 if (launcher.exists(to.toLatin1().data())) {
1851 break;
1852 }
1853 }
1854 if (!launcher.exists(to.toLatin1().data())) {
1855 QString msg;
1856 msg = QString("Cannot inspect '%1' : %2. Did you build yarp with 'portaudio' module?").arg(from).arg(launcher.error().c_str());
1857 logger->addError(msg.toLatin1().data());
1858 launcher.stop();
1859 reportErrors();
1860 }else if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
1861 QString msg;
1862 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
1863 logger->addError(msg.toLatin1().data());
1864 launcher.stop();
1865 reportErrors();
1866 }
1867 }
1868 }
1869
1870 }
1871 }
1873
1874
1875
1876}
1877
1879void ApplicationViewWidget::onYARPRead()
1880{
1881 if (safeManager.busy()) {
1882 return;
1883 }
1885
1886 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1887 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1888 if (it->isSelected()) {
1889 QString from = it->text(3);
1890 QString to = QString("/inspect/read%1").arg(from);
1891
1892#if defined(_WIN32)
1893 QString cmd = "cmd.exe";
1894 QString param;
1895 param = QString("/C yarp read %1").arg(to);
1896
1897#else
1898 QString cmd = "xterm";
1899 QString param;
1900 param = QString("-hold -title %1 -e yarp read %2").arg(from).arg(to);
1901#endif
1902
1905 if (launcher.init(cmd.toLatin1().data(), param.toLatin1().data(), nullptr, nullptr, nullptr, nullptr))
1906 {
1907 if (!launcher.start() && !launcher.error().empty())
1908 {
1909 QString msg;
1910 msg = QString("Error while launching yarpread. %1").arg(launcher.error().c_str());
1911 logger->addError(msg.toLatin1().data());
1912 reportErrors();
1913 }
1914 else
1915 {
1916 // waiting for the port to get open
1917 double base = yarp::os::SystemClock::nowSystem();
1918 while(!timeout(base, 3.0)) {
1919 if (launcher.exists(to.toLatin1().data())) {
1920 break;
1921 }
1922 }
1923 if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
1924 QString msg;
1925 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
1926 logger->addError(msg.toLatin1().data());
1927 launcher.stop();
1928 reportErrors();
1929 }
1930 }
1931 }
1932 }
1933 }
1934
1935
1937
1938}
1939
1941void ApplicationViewWidget::onYARPScope()
1942{
1943 if (safeManager.busy()) {
1944 return;
1945 }
1947
1948 YscopeWindow dlg;
1949 dlg.setModal(true);
1950 if (dlg.exec() != QDialog::Accepted) {
1951 return;
1952 }
1953 int strIndex = dlg.getIndex();
1954
1955
1956
1957
1958 for(int i=0;i<ui->connectionList->topLevelItemCount();i++) {
1959 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
1960 if (it->isSelected()) {
1961 QString from = it->text(3);
1962 QString to = QString("/inspect").arg(from);
1963 QString env = QString("YARP_PORT_PREFIX=%1").arg(to);
1964 to += "/yarpscope";
1965
1966 QString param;
1967 param = QString("--title %1:%2 --bgcolor white --color blue --graph_size 2 --index %2").arg(from).arg(strIndex);
1968
1969
1971 if (launcher.init("yarpscope", param.toLatin1().data(), nullptr, nullptr, nullptr, env.toLatin1().data())) {
1972 if (!launcher.start() && !launcher.error().empty()) {
1973 QString msg;
1974 msg = QString("Error while launching yarpscope. %1").arg(launcher.error().c_str());
1975 logger->addError(msg.toLatin1().data());
1976 reportErrors();
1977 }
1978 else{
1979 // waiting for the port to get open
1980 double base = yarp::os::SystemClock::nowSystem();
1981 while (!timeout(base, 3.0)) {
1982 if (launcher.exists(to.toLatin1().data())) {
1983 break;
1984 }
1985 }
1986 if (!launcher.connect(from.toLatin1().data(), to.toLatin1().data(), "udp")) {
1987 QString msg;
1988 msg = QString("Cannot inspect '%1' : %2").arg(from).arg(launcher.error().c_str());
1989 logger->addError(msg.toLatin1().data());
1990 launcher.stop();
1991 reportErrors();
1992 }
1993 }
1994 }
1995
1996 }
1997 }
1999}
2000
2001
2002
2003bool ApplicationViewWidget::timeout(double base, double timeout)
2004{
2006 if ((yarp::os::SystemClock::nowSystem() - base) > timeout) {
2007 return true;
2008 }
2009 return false;
2010}
2011
2012
2013
2014
2017{
2018 if (editingMode) {
2019 return false;
2020 }
2021 for(int i=0; i< ui->moduleList->topLevelItemCount();i++) {
2022 if (ui->moduleList->topLevelItem(i)->text(2) == "running") {
2023 return true;
2024 }
2025 }
2026 return false;
2027}
2028
2030{
2031 return editingMode;
2032}
2033
2034void ApplicationViewWidget::onSelfConnect(int which)
2035{
2036 int row;
2037 if (!getConRowByID(which, &row))
2038 {
2039 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2040 return;
2041 }
2042
2043 QTreeWidgetItem *it = ui->connectionList->topLevelItem(row);
2044 if (it) {
2045 it->setText(2,"connected");
2046 it->setIcon(0,QIcon(":/connect22.svg"));
2047 it->setForeground(2,QColor("#008C00"));
2048 QString from = it->text(3);
2049 QString to = it->text(4);
2050 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
2051 box->setEnabled(false);
2052 builder->setConnectionConnected(true,from,to);
2053 }
2054
2055 /* row[m_conColumns.m_col_status] = "connected";
2056 row[m_conColumns.m_col_editable] = false;
2057 row[m_conColumns.m_col_color] = Gdk::Color("#008C00");
2058 row.set_value(0, m_refPixConnected);*/
2059
2060 reportErrors();
2061}
2062
2063void ApplicationViewWidget::onSelfDisconnect(int which)
2064{
2065 int row;
2066 if (!getConRowByID(which, &row))
2067 {
2068 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2069 return;
2070 }
2071
2072 QTreeWidgetItem *it = ui->connectionList->topLevelItem(row);
2073 if (it) {
2074 it->setText(2,"disconnected");
2075 it->setIcon(0,QIcon(":/disconnect22.svg"));
2076 it->setForeground(2,QColor("#BF0303"));
2077 QString from = it->text(3);
2078 QString to = it->text(4);
2079 auto* box = qobject_cast<QComboBox*>(ui->connectionList->itemWidget((QTreeWidgetItem *)it, 5));
2080 box->setEnabled(true);
2081 builder->setConnectionConnected(false,from,to);
2082 }
2083 reportErrors();
2084}
2085
2086void ApplicationViewWidget::onSelfResAvailable(int which)
2087{
2088 int row;
2089 if (!getResRowByID(which, &row))
2090 {
2091 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2092 return;
2093 }
2094
2095 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(row);
2096 if (it) {
2097 it->setText(3,"available");
2098 if (it->text(2) == "computer") {
2099 it->setIcon(0,QIcon(":/computer-available22.svg"));
2100 it->setForeground(3,QColor("#008C00"));
2101 } else {
2102 it->setIcon(0,QIcon(":/port-available22.svg"));
2103 it->setForeground(3,QColor("#008C00"));
2104 }
2105 /*if (row[m_resColumns.m_col_type] == Glib::ustring("computer"))
2106 row.set_value(0, m_refPixAvailable);
2107 else
2108 row.set_value(0, m_refPixPortAvaibable);*/
2109 }
2110
2111
2112 reportErrors();
2113}
2114
2115void ApplicationViewWidget::onSelfResUnavailable(int which)
2116{
2117 int row;
2118 if (!getResRowByID(which, &row))
2119 {
2120 yError()<<"ApplicationViewWidget: unable to find row with id:"<<which;
2121 return;
2122 }
2123
2124 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(row);
2125 if (it) {
2126 it->setText(3,"unavailable");
2127 if (it->text(2) == "computer") {
2128 it->setIcon(0,QIcon(":/computer-unavailable22.svg"));
2129 it->setForeground(3,QColor("#BF0303"));
2130 } else {
2131 it->setIcon(0,QIcon(":/port-unavailable22.svg"));
2132 it->setForeground(3,QColor("#BF0303"));
2133 }
2134 }
2135 reportErrors();
2136}
2137
2138void ApplicationViewWidget::onSelfStart(int which)
2139{
2140 QTreeWidgetItem *it = getModRowByID(which);
2141 if (it) {
2142 it->setText(2,"running");
2143 it->setIcon(0,QIcon(":/apply.svg"));
2144 it->setForeground(2,QColor("#008C00"));
2145 builder->setModuleRunning(true,which);
2146 //row[m_modColumns.m_col_editable] = false;
2147 //row[m_modColumns.m_col_color] = Gdk::Color("#008C00");
2148 //row.set_value(0, m_refPixRunning);
2149 }
2150
2151 reportErrors();
2152}
2153
2154void ApplicationViewWidget::onSelfStop(int which)
2155{
2156 QTreeWidgetItem *it = getModRowByID(which);
2157 if (it) {
2158 it->setText(2,"stopped");
2159 it->setIcon(0,QIcon(":/close.svg"));
2160 it->setForeground(2,QColor("#BF0303"));
2161 builder->setModuleRunning(false,which);
2162 }
2163 reportErrors();
2164}
2165
2170{
2171 emit selfStart(which);
2172}
2173
2178{
2179 emit selfStop(which);
2180}
2185void ApplicationViewWidget::onModStdout(int which, const char* msg)
2186{
2187 QString s = QString("%1").arg(msg);
2188 for(int j=0;j<ui->moduleList->topLevelItemCount();j++) {
2189 QTreeWidgetItem *it = ui->moduleList->topLevelItem(j);
2190 if (it->data(0,Qt::UserRole) == APPLICATION) {
2191 modStdOutNestedApplication(it,which,s);
2192 } else {
2193 auto* stdouWin = qvariant_cast<StdoutWindow *>(it->data(0,Qt::UserRole));
2194 if (stdouWin && stdouWin->getId() == which) {
2195 stdouWin->addMessage(s);
2196 break;
2197 }
2198 }
2199
2200 }
2201}
2202
2203void ApplicationViewWidget::modStdOutNestedApplication(QTreeWidgetItem *it, int id,QString s)
2204{
2205 for(int j=0; j<it->childCount();j++) {
2206 QTreeWidgetItem *ch = it->child(j);
2207 if (ch->data(0,Qt::UserRole) == APPLICATION) {
2208 modStdOutNestedApplication(ch,id,s);
2209 } else {
2210 auto* stdouWin = qvariant_cast<StdoutWindow *>(ch->data(0,Qt::UserRole));
2211 if (stdouWin && stdouWin->getId() == id) {
2212 stdouWin->addMessage(s);
2213 break;
2214 }
2215 }
2216 }
2217}
2218
2223{
2224 emit selfConnect(which);
2225}
2226
2231{
2232 emit selfDisconnect(which);
2233}
2234
2239{
2240 emit selfResAvailable(which);
2241}
2242
2247{
2248 emit selfResUnavailable(which);
2249}
2250
2255{
2256 if (from >= 0) {
2257 int row;
2258 if (getConRowByID(from, &row)) {
2259 ui->connectionList->topLevelItem(row)->setForeground(3,QColor("#008C00"));
2260 builder->setOutputPortAvailable(ui->connectionList->topLevelItem(row)->text(3),true);
2261 }
2262 }
2263
2264 if (to >= 0) {
2265 int row;
2266 if (getConRowByID(to, &row)) {
2267 ui->connectionList->topLevelItem(row)->setForeground(4,QColor("#008C00"));
2268 builder->setInputPortAvailable(ui->connectionList->topLevelItem(row)->text(4),true);
2269 }
2270 }
2271 reportErrors();
2272}
2273
2278{
2279 if (from >= 0) {
2280 int row;
2281 if (getConRowByID(from, &row)) {
2282 ui->connectionList->topLevelItem(row)->setForeground(3,QColor("#BF0303"));
2283 builder->setOutputPortAvailable(ui->connectionList->topLevelItem(row)->text(3),false);
2284 }
2285 }
2286
2287 if (to >= 0) {
2288 int row;
2289 if (getConRowByID(to, &row)) {
2290 ui->connectionList->topLevelItem(row)->setForeground(4,QColor("#BF0303"));
2291 builder->setInputPortAvailable(ui->connectionList->topLevelItem(row)->text(4),false);
2292 }
2293 }
2294 reportErrors();
2295}
2296
2301{
2302 reportErrors();
2303}
2304
2311
2312
2313
2314void ApplicationViewWidget::onDetachStdout()
2315{
2316
2317}
2318
2323bool ApplicationViewWidget::getConRowByID(int id, int *row)
2324{
2325 for(int i=0;i< ui->connectionList->topLevelItemCount();i++) {
2326 QTreeWidgetItem *it = ui->connectionList->topLevelItem(i);
2327
2328 if (it->text(1).toInt() == id) {
2329 *row = i;
2330 return true;
2331 }
2332 }
2333 return false;
2334}
2335
2340bool ApplicationViewWidget::getResRowByID(int id, int *row)
2341{
2342 for(int i=0;i< ui->resourcesList->topLevelItemCount();i++) {
2343 QTreeWidgetItem *it = ui->resourcesList->topLevelItem(i);
2344
2345 if (it->text(1).toInt() == id) {
2346 *row = i;
2347 return true;
2348 }
2349 }
2350 return false;
2351}
2356QTreeWidgetItem* ApplicationViewWidget::getModRowByID(int id, QTreeWidgetItem *parent)
2357{
2358 QTreeWidgetItem *ret = nullptr;
2359 if (!parent) {
2360 for(int i=0;i< ui->moduleList->topLevelItemCount();i++) {
2361 QTreeWidgetItem *it = ui->moduleList->topLevelItem(i);
2362 if (it->data(0,Qt::UserRole) == APPLICATION) {
2363 ret = getModRowByID(id,it);
2364 if (ret) {
2365 break;
2366 }
2367 }
2368
2369 if (it->text(1).toInt() == id) {
2370 return it;
2371 }
2372 }
2373 } else {
2374 for(int i=0;i< parent->childCount();i++) {
2375 QTreeWidgetItem *it = parent->child(i);
2376 if (it->data(0,Qt::UserRole) == APPLICATION) {
2377 ret = getModRowByID(id,it);
2378 if (ret) {
2379 break;
2380 }
2381 }
2382
2383 if (it->text(1).toInt() == id) {
2384 return it;
2385 }
2386 }
2387 }
2388
2389 return ret;
2390}
2391
2392
2394 safeManager.close();
2395}
bool ret
#define yError(...)
Definition Log.h:361
int SIGNAL(int pid, int signum)
The Application View Widget.
void onError() override
Called when an error occurred.
void selfResAvailable(int)
void connectConnectionSet(bool onlySelected)
Connect all modules in the application to their ports using connections list.
void selfResUnavailable(int)
void selectAll()
Select all element in the widget (modules, connections, resources)
void setFileName(QString filename)
void runApplicationSet(bool onlySelected)
Run all modules in the application.
ApplicationViewWidget(yarp::manager::Application *, yarp::manager::Manager *lazyManager, yarp::os::Property *config, bool editingMode=false, QWidget *parent=nullptr)
void onConConnect(int which) override
Called when a connection has been performed.
void exportGraph()
Export the current Graph.
void logWarning(QString)
void onConAvailable(int from, int to) override
Called when a connection become available.
bool isRunning()
Tells if a modules is in running state.
void onModStart(int which) override
Called when a modlue has been started.
void onLoadBalance() override
Refresh all and reports errors.
void onModStop(int which) override
Called when a modlue has been stopped.
void killApplicationSet(bool onlySelected)
Kill all running modules in the application.
void onConUnAvailable(int from, int to) override
Called when a connection become unavailable.
CustomTreeWidget * getConnectionList()
void setAppName(QString appName)
void onResUnAvailable(int which) override
Called when a resource become unavailable.
void logError(QString)
void disconnectConnectionSet(bool onlySelected)
Disconnect all modules in the application to their ports using connections list.
void onConDisconnect(int which) override
Called when a disconnection has been performed.
CustomTreeWidget * getModuleList()
void onModStdout(int which, const char *msg) override
Called when a modlue has writes on stdout.
void onResAvailable(int which) override
Called when a resource became available.
void stopApplicationSet(bool onlySelected)
Stop all modules in the application.
void setSelectedConnections(QList< int >selectedIds)
void load(bool refresh=false)
void addModulesAction(QAction *)
QString getAppName()
void setFileName(QString filename)
void setInputPortAvailable(QString, bool)
QString getFileName()
void setConnectionConnected(bool, QString from, QString to)
void addAction(QAction *)
void setAppName(QString appName)
void setModuleRunning(bool, int id)
void setOutputPortAvailable(QString, bool)
QToolBar * getToolBar()
void addConnectionsAction(QAction *)
void setSelectedModules(QList< int >selectedIds)
A custom QTreeWidgetItem.
A custom QTreeWidget.
Generic View Widget.
void modified(bool)
void onModified(bool mod)
yarp::manager::NodeType type
void safeConnect(std::vector< int > &CIDs)
void safeStop(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeRun(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeKill(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeRefresh(std::vector< int > &MIDs, std::vector< int > &CIDs, std::vector< int > &RIDs)
void safeLoadBalance()
void safeAttachStdout(std::vector< int > &MIDs)
bool prepare(yarp::manager::Manager *lazy, yarp::os::Property *config, ApplicationEvent *event=nullptr)
void safeDisconnect(std::vector< int > &CDs)
static BuilderWindow * getBuilder(Application *app, Manager *lazyManager, SafeManager *manager, bool editingMode)
Class Application.
Singleton class ErrorLogger.
Definition utility.h:58
const char * getLastError()
Definition utility.cpp:148
void addError(const char *szError)
Definition utility.cpp:126
void addWarning(const char *szWarning)
Definition utility.cpp:104
static ErrorLogger * Instance()
Singleton class ErrorLogger.
Definition utility.cpp:98
const char * getLastWarning()
Definition utility.cpp:167
Class LocalBroker.
Definition localbroker.h:33
void setWindowMode(WindowMode m)
Define if the application will be visible or not.
bool exists(const std::string &port) override
std::string error() override
bool connect(const std::string &from, const std::string &to, const std::string &carrier, bool persist=false) override
connection broker
Class Manager.
Definition manager.h:20
ExecutablePContainer & getExecutables()
Definition manager.h:82
bool updateConnection(unsigned int id, const char *from, const char *to, const char *carrier)
Definition manager.cpp:456
CnnContainer & getConnections()
Definition manager.h:85
ResourcePContainer & getResources()
Definition manager.h:86
bool existPortFrom(unsigned int id)
Definition manager.cpp:731
bool existPortTo(unsigned int id)
Definition manager.cpp:752
bool updateExecutable(unsigned int id, const char *szparam, const char *szhost, const char *szstdio, const char *szworkdir, const char *szenv)
Definition manager.cpp:430
bool loadApplication(const char *szAppName)
Definition manager.cpp:240
bool exportDependencyGraph(const char *szFileName)
Definition manager.h:99
Class Module.
Definition module.h:99
const char * getLabel()
Definition node.h:93
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
static Bottle listCarriers()
Definition Carriers.cpp:317
A class for storing options and configuration information.
Definition Property.h:33
static double nowSystem()
static void delaySystem(double seconds)
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
Definition aboutdlg.h:11
std::vector< Executable * >::iterator ExecutablePIterator
Definition executable.h:167
std::vector< GenericResource * >::iterator ResourcePIterator
Definition resource.h:59
enum yarp::manager::__NodeType NodeType
std::vector< Connection >::iterator CnnIterator
std::vector< Executable * > ExecutablePContainer
Definition executable.h:166
std::vector< Connection > CnnContainer