30 #include <QFileSystemModel>
31 #include <QStandardItem>
33 #include <Ice/Connection.h>
35 #include <SimoxUtility/algorithm/string/string_tools.h>
44 #define LiveMetaInfoDescriptionString "Live Meta Information"
50 connect(
this, SIGNAL(itemChanged(QStandardItem*)),
this, SLOT(
updateItem(QStandardItem*)));
70 for (
int i = 0; i < this->rowCount(); i++)
74 if (item->
getName().compare(name) == 0)
91 for (
int i = 0; i < this->rowCount(); i++)
99 auto proxy =
getIceManager()->getProxy<ArmarXManagerInterfacePrx>(
100 item->
getName().toStdString());
102 item->
setManagerProxy(ArmarXManagerInterfacePrx::uncheckedCast(proxy));
119 for (
auto& name : managerNames)
125 getIceManager()->getProxy<ArmarXManagerInterfacePrx>(name.toStdString());
127 result[name] = proxy;
142 bool deactivateIfMissing)
145 dependenciesMap.clear();
148 std::map<std::string, std::vector<QString>> offererMap;
149 std::map<std::string, std::vector<QString>> listenerMap;
151 for (
int i = 0; i < this->rowCount(); i++)
166 auto it = managerDataMap.find(item->
getName());
167 if (it == managerDataMap.end())
170 << item->
getName().toStdString();
171 if (deactivateIfMissing)
192 if (it->second.proxy)
200 for (
int j = 0; j < updates.size(); j++)
202 QString objName = updates.keys().at(j);
211 offererMap[
topic].push_back(objName);
215 listenerMap[
topic].push_back(objName);
219 dependenciesMap[objName.toStdString()] = objItem.
connectivity.dependencies;
226 for (
int i = 0; i < this->rowCount(); i++)
229 item->setEditable(
false);
235 managerBrush.setStyle(Qt::SolidPattern);
236 managerBrush.setColor(Qt::lightGray);
244 item->setBackground(managerBrush);
246 auto addPropertiesToItem =
247 [](ObjectPropertyInfos
const& properties, QStandardItem* item)
249 if (!properties.empty())
251 QStandardItem* objectPropertiesItem =
new QStandardItem(
"Properties");
252 objectPropertiesItem->setEditable(
false);
254 QList<QStandardItem*> objectPropertiesRow;
256 for (
auto property : properties)
258 QStandardItem* objectPropertyItem =
259 new QStandardItem(QString(
"%1 %2: %3")
260 .arg(property.first.c_str())
261 .arg(property.second.constant ?
"(constant)" :
"")
262 .arg(property.second.value.c_str()));
263 objectPropertyItem->setEditable(!property.second.constant);
264 if (!property.second.constant)
266 objectPropertyItem->setToolTip(
267 "Double-click to edit this property and to send the updated "
268 "property to the component.");
270 objectPropertiesRow.append(objectPropertyItem);
273 objectPropertiesItem->appendRows(objectPropertiesRow);
274 item->appendRow(objectPropertiesItem);
278 if (item->rowCount() == 0 && item->
isOnline())
280 auto applicationItem =
new QStandardItem(
"Application Properties");
283 applicationItem->setEditable(
false);
289 addPropertiesToItem(properties, applicationItem);
290 item->appendRow(applicationItem);
299 for (
int j = 0; j < objects.size(); j++)
301 QString objName = objects.keys().at(j);
307 objItem.
item =
new QStandardItem(objName);
308 objItem.
item->setEditable(
false);
310 item->appendRow(objItem.
item);
316 addPropertiesToItem(properties, objItem.
item);
319 metaInfoItem->setEditable(
false);
322 auto name = QString::fromStdString(pair.first);
323 auto value = QString::fromStdString(
324 VariantPtr::dynamicCast(pair.second)->getOutputValueOnly());
325 QStandardItem* infoItem =
new QStandardItem(
326 name +
": " + (
value.size() > 100 ? (
value.left(100) +
"...") :
value));
327 metaInfoItem->appendRow(infoItem);
329 objItem.
item->appendRow(metaInfoItem);
331 DependencyMap depMap = objItem.
connectivity.dependencies;
332 DependencyMap::iterator it = depMap.begin();
335 while (it != depMap.end())
337 QStandardItem* depObjItem =
338 new QStandardItem(it->second->getName().c_str());
339 depObjItem->setEditable(
false);
341 if (it->second->getResolved())
344 depObjItem->setBackground(QBrush(QColor(50, 205, 50)));
345 depObjItem->setToolTip(
"Dependency resolved");
350 depObjItem->setBackground(QBrush(QColor(255, 106, 106)));
351 depObjItem->setToolTip(
"Dependency missing");
353 objItem.
item->appendRow(depObjItem);
368 endpointItem =
new QStandardItem(endpointText);
369 endpointItem->setEditable(
false);
372 item->appendRow(endpointItem);
376 endpointItem->setText(endpointText);
379 DependencyMap depMap = objItem.
connectivity.dependencies;
380 DependencyMap::iterator it = depMap.begin();
383 while (it != depMap.end())
386 findItem(QString::fromStdString(it->second->getName()), objItem.
item);
391 depObjItem->setEditable(
false);
393 if (it->second->getResolved())
396 depObjItem->setBackground(QBrush(QColor(50, 205, 50)));
397 depObjItem->setToolTip(
"Dependency resolved");
402 depObjItem->setBackground(QBrush(QColor(255, 106, 106)));
403 depObjItem->setToolTip(
"Dependency missing");
413 auto topicsItem = findItem(QString(
"Offered Topics"), objItem.
item);
417 new QStandardItem(QString::fromStdString(
"Offered Topics"));
418 topicsItem->setEditable(
false);
419 objItem.
item->appendRow(topicsItem);
424 auto topicItem = findItem(QString::fromStdString(
topic), topicsItem);
427 topicItem =
new QStandardItem(QString::fromStdString(
topic));
428 topicItem->setEditable(
false);
429 topicsItem->appendRow(topicItem);
431 auto& listeners = listenerMap[
topic];
432 syncStringListChildren(topicItem, listeners);
445 auto topicsItem = findItem(QString(
"Used Topics"), objItem.
item);
448 topicsItem =
new QStandardItem(QString::fromStdString(
"Used Topics"));
449 topicsItem->setEditable(
false);
450 objItem.
item->appendRow(topicsItem);
459 findItem(QString::fromStdString(
topic), topicsItem);
462 topicItem =
new QStandardItem(QString::fromStdString(
topic));
463 topicItem->setEditable(
false);
464 topicsItem->appendRow(topicItem);
466 if (offererMap.count(
topic) == 0)
468 topicItem->setBackground(QBrush(QColor(255, 163, 33)));
469 topicItem->setToolTip(
470 "The topic " + QString::fromStdString(
topic) +
471 " is not offered by any listed component - though not all "
472 "components might be listed");
476 topicItem->setBackground(QBrush());
477 auto& offerers = offererMap[
topic];
478 syncStringListChildren(topicItem, offerers);
487 topicItem->setEditable(
false);
498 metaInfoItem->removeRows(0, metaInfoItem->rowCount());
501 auto name = QString::fromStdString(pair.first);
502 auto value = QString::fromStdString(
503 VariantPtr::dynamicCast(pair.second)->getOutputValueOnly());
504 QStandardItem* infoItem =
new QStandardItem(
507 metaInfoItem->appendRow(infoItem);
513 auto stateBool = objItem.
state == eManagedIceObjectStarted;
516 objItem.
item->setToolTip(
517 "Component state: " +
518 QString::fromStdString(
525 << (IceUtil::Time::now() - start).toMilliSecondsDouble() <<
" ms";
527 std::string dotString = GenerateDependencyGraph(dependenciesMap);
528 std::ofstream f(
"/tmp/dependencygraph.dot");
538 for (
int i = 0; i < this->rowCount(); i++)
560 swapSelection(
this, destinationModel, selectionModel);
568 swapSelection(sourceModel,
this, selectionModel);
574 QItemSelectionModel* selectionModel)
577 QList<QPersistentModelIndex> persistentSelectionModelList =
578 getPersistentModelIndex(selectionModel);
581 QList<QPersistentModelIndex>::Iterator persistentModelIndexIter;
582 persistentModelIndexIter = persistentSelectionModelList.begin();
584 while (persistentModelIndexIter != persistentSelectionModelList.end())
586 destinationModel->insertRow(destinationModel->rowCount(),
587 sourceModel->takeRow(persistentModelIndexIter->row()));
589 ++persistentModelIndexIter;
597 QList<QPersistentModelIndex> persistentSelectionModelList =
598 getPersistentModelIndex(selectionModel);
600 QList<QPersistentModelIndex>::Iterator persistentModelIndexIter;
601 persistentModelIndexIter = persistentSelectionModelList.begin();
603 while (persistentModelIndexIter != persistentSelectionModelList.end())
605 takeRow(persistentModelIndexIter->row());
607 ++persistentModelIndexIter;
611 QList<QPersistentModelIndex>
612 ArmarXManagerModel::getPersistentModelIndex(QItemSelectionModel* selectionModel)
615 QModelIndexList selection = selectionModel->selectedRows();
618 QList<QPersistentModelIndex> persistentModelIndex;
619 QModelIndexList::Iterator modelIndexIter;
620 modelIndexIter = selection.begin();
622 while (modelIndexIter != selection.end())
624 persistentModelIndex.append(*modelIndexIter);
629 return persistentModelIndex;
636 if (role == Qt::DisplayRole)
638 if (orientation == Qt::Horizontal)
646 return "Object state";
670 managerItem->
setName(item->text());
678 QStringList managerList;
680 for (
int i = 0; i < this->rowCount(); i++)
691 return rowCount() == 0;
702 for (
int i = 0; i < managerList.size(); i++)
716 for (
int i = 0; i < rowCount(); i++)
720 modelCopy->appendRow(itemClone);
735 for (
int i = 0; i <
source->rowCount(); i++)
739 appendRow(itemClone);
746 this->iceManager = iceManager;
759 brush.setStyle(Qt::SolidPattern);
763 case armarx::eManagedIceObjectCreated:
764 brush.setColor(QColor(255, 196, 106));
767 case armarx::eManagedIceObjectInitializing:
768 brush.setColor(QColor(255, 255, 196));
771 case armarx::eManagedIceObjectInitialized:
772 brush.setColor(QColor(255, 255, 0));
775 case armarx::eManagedIceObjectInitializationFailed:
776 brush.setColor(QColor(255, 16, 16));
779 case armarx::eManagedIceObjectStarting:
780 brush.setColor(QColor(128, 196, 255));
783 case armarx::eManagedIceObjectStarted:
784 brush.setColor(QColor(128, 255, 128));
787 case armarx::eManagedIceObjectStartingFailed:
788 brush.setColor(QColor(255, 64, 64));
791 case armarx::eManagedIceObjectExiting:
792 brush.setColor(QColor(225, 225, 225));
795 case armarx::eManagedIceObjectExited:
796 brush.setColor(QColor(196, 196, 196));
804 ArmarXManagerModel::findItem(
const QString& name, QStandardItem* item)
806 for (
int i = 0; i < item->rowCount(); ++i)
808 QStandardItem* curItem = item->child(i);
809 if (curItem->text() == name)
818 ArmarXManagerModel::findItemByUserData(Qt::ItemDataRole role,
819 const QVariant&
data,
822 for (
int i = 0; i < item->rowCount(); ++i)
824 QStandardItem* curItem = item->child(i);
825 if (curItem->data(role) ==
data)
834 ArmarXManagerModel::syncStringListChildren(QStandardItem* item,
835 const std::vector<QString>& strings)
837 for (
int i = item->rowCount() - 1; i >= 0; i--)
839 QStandardItem* curItem = item->child(i);
840 if (std::find(strings.begin(), strings.end(), curItem->text()) == strings.end())
845 for (
const QString&
s : strings)
847 auto child = findItem(
s, item);
850 auto newChild =
new QStandardItem(
s);
851 newChild->setEditable(
false);
852 item->appendRow(newChild);
858 ArmarXManagerModel::GenerateDependencyGraph(
859 const std::map<std::string, DependencyMap>& dependenciesMap)
861 std::stringstream ss;
862 ss <<
"digraph ArmarXDependencyGraph\n"
864 for (
auto& pair : dependenciesMap)
866 auto name = pair.first;
867 for (
auto& pair2 : pair.second)
869 auto name2 = pair2.first;
870 name = simox::alg::replace_all(name,
"-",
"_");
871 name2 = simox::alg::replace_all(name2,
"-",
"_");
872 name = simox::alg::replace_all(name,
">",
"_");
873 name2 = simox::alg::replace_all(name2,
">",
"_");
874 ss << name <<
" -> " << name2 <<
";\n";