33 #include <SimoxUtility/algorithm/string/string_tools.h>
35 #include <Ice/Connection.h>
37 #include <QStandardItem>
38 #include <QFileSystemModel>
42 #define LiveMetaInfoDescriptionString "Live Meta Information"
49 connect(
this, SIGNAL(itemChanged(QStandardItem*)),
this, SLOT(
updateItem(QStandardItem*)));
71 for (
int i = 0; i < this->rowCount(); i++)
75 if (item->
getName().compare(name) == 0)
91 for (
int i = 0; i < this->rowCount(); i++)
99 auto proxy =
getIceManager()->getProxy<ArmarXManagerInterfacePrx>(item->
getName().toStdString());
101 item->
setManagerProxy(ArmarXManagerInterfacePrx::uncheckedCast(proxy));
118 for (
auto& name : managerNames)
123 auto proxy =
getIceManager()->getProxy<ArmarXManagerInterfacePrx>(name.toStdString());
125 result[name] = proxy;
141 dependenciesMap.clear();
144 std::map<std::string, std::vector<QString> > offererMap;
145 std::map<std::string, std::vector<QString> > listenerMap;
147 for (
int i = 0; i < this->rowCount(); i++)
162 auto it = managerDataMap.find(item->
getName());
163 if (it == managerDataMap.end())
166 if (deactivateIfMissing)
187 if (it->second.proxy)
195 for (
int j = 0; j < updates.size(); j++)
197 QString objName = updates.keys().at(j);
206 offererMap[
topic].push_back(objName);
210 listenerMap[
topic].push_back(objName);
214 dependenciesMap[objName.toStdString()] = objItem.
connectivity.dependencies;
222 for (
int i = 0; i < this->rowCount(); i++)
225 item->setEditable(
false);
231 managerBrush.setStyle(Qt::SolidPattern);
232 managerBrush.setColor(Qt::lightGray);
240 item->setBackground(managerBrush);
242 auto addPropertiesToItem = [](ObjectPropertyInfos
const & properties, QStandardItem * item)
244 if (!properties.empty())
246 QStandardItem* objectPropertiesItem =
new QStandardItem(
"Properties");
247 objectPropertiesItem->setEditable(
false);
249 QList<QStandardItem*> objectPropertiesRow;
251 for (
auto property : properties)
253 QStandardItem* objectPropertyItem =
new QStandardItem(QString(
"%1 %2: %3").arg(property.first.c_str())
254 .arg(property.second.constant ?
"(constant)" :
"")
255 .arg(property.second.value.c_str()));
256 objectPropertyItem->setEditable(!property.second.constant);
257 if (!property.second.constant)
259 objectPropertyItem->setToolTip(
"Double-click to edit this property and to send the updated property to the component.");
261 objectPropertiesRow.append(objectPropertyItem);
264 objectPropertiesItem->appendRows(objectPropertiesRow);
265 item->appendRow(objectPropertiesItem);
269 if (item->rowCount() == 0 && item->
isOnline())
271 auto applicationItem =
new QStandardItem(
"Application Properties");
273 applicationItem->setEditable(
false);
278 addPropertiesToItem(properties, applicationItem);
279 item->appendRow(applicationItem);
286 for (
int j = 0; j < objects.size(); j++)
288 QString objName = objects.keys().at(j);
294 objItem.
item =
new QStandardItem(objName);
295 objItem.
item->setEditable(
false);
297 item->appendRow(objItem.
item);
303 addPropertiesToItem(properties, objItem.
item);
306 metaInfoItem->setEditable(
false);
309 auto name = QString::fromStdString(pair.first);
310 auto value = QString::fromStdString(VariantPtr::dynamicCast(pair.second)->getOutputValueOnly());
311 QStandardItem* infoItem =
new QStandardItem(name +
": " + (
value.size() > 100 ? (
value.left(100) +
"...") :
value));
312 metaInfoItem->appendRow(infoItem);
314 objItem.
item->appendRow(metaInfoItem);
316 DependencyMap depMap = objItem.
connectivity.dependencies;
317 DependencyMap::iterator it = depMap.begin();
320 while (it != depMap.end())
322 QStandardItem* depObjItem =
new QStandardItem(it->second->getName().c_str());
323 depObjItem->setEditable(
false);
325 if (it->second->getResolved())
328 depObjItem->setBackground(QBrush(QColor(50, 205, 50)));
329 depObjItem->setToolTip(
"Dependency resolved");
334 depObjItem->setBackground(QBrush(QColor(255, 106, 106)));
335 depObjItem->setToolTip(
"Dependency missing");
337 objItem.
item->appendRow(depObjItem);
350 endpointItem =
new QStandardItem(endpointText);
351 endpointItem->setEditable(
false);
353 item->appendRow(endpointItem);
357 endpointItem->setText(endpointText);
360 DependencyMap depMap = objItem.
connectivity.dependencies;
361 DependencyMap::iterator it = depMap.begin();
364 while (it != depMap.end())
366 auto depObjItem = findItem(QString::fromStdString(it->second->getName()), objItem.
item);
371 depObjItem->setEditable(
false);
373 if (it->second->getResolved())
376 depObjItem->setBackground(QBrush(QColor(50, 205, 50)));
377 depObjItem->setToolTip(
"Dependency resolved");
382 depObjItem->setBackground(QBrush(QColor(255, 106, 106)));
383 depObjItem->setToolTip(
"Dependency missing");
393 auto topicsItem = findItem(QString(
"Offered Topics"), objItem.
item);
396 topicsItem =
new QStandardItem(QString::fromStdString(
"Offered Topics"));
397 topicsItem->setEditable(
false);
398 objItem.
item->appendRow(topicsItem);
403 auto topicItem = findItem(QString::fromStdString(
topic), topicsItem);
406 topicItem =
new QStandardItem(QString::fromStdString(
topic));
407 topicItem->setEditable(
false);
408 topicsItem->appendRow(topicItem);
410 auto& listeners = listenerMap[
topic];
411 syncStringListChildren(topicItem, listeners);
425 auto topicsItem = findItem(QString(
"Used Topics"), objItem.
item);
428 topicsItem =
new QStandardItem(QString::fromStdString(
"Used Topics"));
429 topicsItem->setEditable(
false);
430 objItem.
item->appendRow(topicsItem);
438 auto topicItem = findItem(QString::fromStdString(
topic), topicsItem);
441 topicItem =
new QStandardItem(QString::fromStdString(
topic));
442 topicItem->setEditable(
false);
443 topicsItem->appendRow(topicItem);
445 if (offererMap.count(
topic) == 0)
447 topicItem->setBackground(QBrush(QColor(255, 163, 33)));
448 topicItem->setToolTip(
"The topic " + QString::fromStdString(
topic) +
" is not offered by any listed component - though not all components might be listed");
452 topicItem->setBackground(QBrush());
453 auto& offerers = offererMap[
topic];
454 syncStringListChildren(topicItem, offerers);
464 topicItem->setEditable(
false);
474 metaInfoItem->removeRows(0, metaInfoItem->rowCount());
477 auto name = QString::fromStdString(pair.first);
478 auto value = QString::fromStdString(VariantPtr::dynamicCast(pair.second)->getOutputValueOnly());
479 QStandardItem* infoItem =
new QStandardItem(name +
": " + (
value.size() > 100 ? (
value.left(100) +
"...") :
value));
480 metaInfoItem->appendRow(infoItem);
486 auto stateBool = objItem.
state == eManagedIceObjectStarted;
494 ARMARX_DEBUG_S <<
"Updating SystemState model took " << (IceUtil::Time::now() - start).toMilliSecondsDouble() <<
" ms";
496 std::string dotString = GenerateDependencyGraph(dependenciesMap);
497 std::ofstream f(
"/tmp/dependencygraph.dot");
506 for (
int i = 0; i < this->rowCount(); i++)
528 swapSelection(
this, destinationModel, selectionModel);
536 swapSelection(sourceModel,
this, selectionModel);
542 QItemSelectionModel* selectionModel)
545 QList<QPersistentModelIndex> persistentSelectionModelList =
546 getPersistentModelIndex(selectionModel);
549 QList<QPersistentModelIndex>::Iterator persistentModelIndexIter;
550 persistentModelIndexIter = persistentSelectionModelList.begin();
552 while (persistentModelIndexIter != persistentSelectionModelList.end())
554 destinationModel->insertRow(destinationModel->rowCount(),
555 sourceModel->takeRow(
556 persistentModelIndexIter->row()));
558 ++persistentModelIndexIter;
566 QList<QPersistentModelIndex> persistentSelectionModelList =
567 getPersistentModelIndex(selectionModel);
569 QList<QPersistentModelIndex>::Iterator persistentModelIndexIter;
570 persistentModelIndexIter = persistentSelectionModelList.begin();
572 while (persistentModelIndexIter != persistentSelectionModelList.end())
574 takeRow(persistentModelIndexIter->row());
576 ++persistentModelIndexIter;
581 QList<QPersistentModelIndex> ArmarXManagerModel::getPersistentModelIndex(
582 QItemSelectionModel* selectionModel)
585 QModelIndexList selection = selectionModel->selectedRows();
588 QList<QPersistentModelIndex> persistentModelIndex;
589 QModelIndexList::Iterator modelIndexIter;
590 modelIndexIter = selection.begin();
592 while (modelIndexIter != selection.end())
594 persistentModelIndex.append(*modelIndexIter);
599 return persistentModelIndex;
606 if (role == Qt::DisplayRole)
608 if (orientation == Qt::Horizontal)
616 return "Object state";
639 managerItem->
setName(item->text());
647 QStringList managerList;
649 for (
int i = 0; i < this->rowCount(); i++)
659 return rowCount() == 0;
670 for (
int i = 0; i < managerList.size(); i++)
684 for (
int i = 0; i < rowCount(); i++)
688 modelCopy->appendRow(itemClone);
703 for (
int i = 0; i <
source->rowCount(); i++)
707 appendRow(itemClone);
714 this->iceManager = iceManager;
727 brush.setStyle(Qt::SolidPattern);
731 case armarx::eManagedIceObjectCreated:
732 brush.setColor(QColor(255, 196, 106));
735 case armarx::eManagedIceObjectInitializing:
736 brush.setColor(QColor(255, 255, 196));
739 case armarx::eManagedIceObjectInitialized:
740 brush.setColor(QColor(255, 255, 0));
743 case armarx::eManagedIceObjectInitializationFailed:
744 brush.setColor(QColor(255, 16, 16));
747 case armarx::eManagedIceObjectStarting:
748 brush.setColor(QColor(128, 196, 255));
751 case armarx::eManagedIceObjectStarted:
752 brush.setColor(QColor(128, 255, 128));
755 case armarx::eManagedIceObjectStartingFailed:
756 brush.setColor(QColor(255, 64, 64));
759 case armarx::eManagedIceObjectExiting:
760 brush.setColor(QColor(225, 225, 225));
763 case armarx::eManagedIceObjectExited:
764 brush.setColor(QColor(196, 196, 196));
771 QStandardItem* ArmarXManagerModel::findItem(
const QString& name, QStandardItem* item)
773 for (
int i = 0; i < item->rowCount(); ++i)
775 QStandardItem* curItem = item->child(i);
776 if (curItem->text() == name)
784 QStandardItem* ArmarXManagerModel::findItemByUserData(Qt::ItemDataRole role,
const QVariant&
data, QStandardItem* item)
786 for (
int i = 0; i < item->rowCount(); ++i)
788 QStandardItem* curItem = item->child(i);
789 if (curItem->data(role) ==
data)
797 void ArmarXManagerModel::syncStringListChildren(QStandardItem* item,
const std::vector<QString>& strings)
799 for (
int i = item->rowCount() - 1; i >= 0; i--)
801 QStandardItem* curItem = item->child(i);
802 if (std::find(strings.begin(), strings.end(), curItem->text()) == strings.end())
807 for (
const QString&
s : strings)
809 auto child = findItem(
s, item);
812 auto newChild =
new QStandardItem(
s);
813 newChild->setEditable(
false);
814 item->appendRow(newChild);
819 std::string ArmarXManagerModel::GenerateDependencyGraph(
const std::map<std::string, DependencyMap>& dependenciesMap)
821 std::stringstream ss;
822 ss <<
"digraph ArmarXDependencyGraph\n"
824 for (
auto& pair : dependenciesMap)
826 auto name = pair.first;
827 for (
auto& pair2 : pair.second)
829 auto name2 = pair2.first;
830 name = simox::alg::replace_all(name,
"-",
"_");
831 name2 = simox::alg::replace_all(name2,
"-",
"_");
832 name = simox::alg::replace_all(name,
">",
"_");
833 name2 = simox::alg::replace_all(name2,
">",
"_");
834 ss << name <<
" -> " << name2 <<
";\n";