31 #include <ArmarXCore/interface/observers/ConditionHandlerInterface.h>
41 : QStandardItemModel(0, 1),
42 iceManager(iceManager),
53 channelRegistry[observerName] = channels;
54 availableChecks[observerName] = checks;
58 markAllForDelete(invisibleRootItem());
61 QStandardItem* observerItem = updateObserver(observerName);
64 updateChannels(getChildByName(observerItem,
"channels"), channels);
67 updateChecks(getChildByName(observerItem,
"checks"), checks);
73 deleteUnusedItems(observerItem);
78 QStandardItem* item = itemFromIndex(
index);
94 QString channelName =
id.toString();
95 QString observerName = item->parent()->parent()->data(
OBSERVER_ITEM_ID).toString();
96 ChannelRegistryEntry& entry = channelRegistry[observerName.toLatin1().data()][channelName.toLatin1().data()];
99 widget =
new ChannelPropertiesWidget(channelName.toLatin1().data(), observerName.toLatin1().data(), entry.description, parent);
111 "No channel registry for name '" << dataFieldIdentifier.
getObserverName() <<
"' "
112 <<
"Available names:\n" <<
getMapKeys(channelRegistry);
113 ChannelRegistry& chanReg = channelRegistry.at(dataFieldIdentifier.
getObserverName());
118 <<
"' has no channel '" << dataFieldIdentifier.
getChannelName() <<
"' "
119 <<
"Available channels:\n" <<
getMapKeys(chanReg);
120 ChannelRegistryEntry& chanRegEntry = chanReg.at(dataFieldIdentifier.
getChannelName());
125 <<
"'. Available datafields:\n" <<
getMapKeys(chanRegEntry.dataFields);
126 DataFieldRegistryEntry& entry = chanRegEntry.dataFields.at(dataFieldIdentifier.
getDataFieldName());
130 if (info && (!entry.value->data || entry.value->data->ice_id() ==
"::armarx::VariantData"))
132 ARMARX_INFO <<
"Variant Factory for " << entry.typeName <<
" is missing - trying to load lib now";
133 auto lib = info->loadLibraryOfVariant(entry.typeName);
136 widget =
new QWidget(parent);
140 entry.value = ref->getDataField();
142 widget =
new DataFieldPropertiesWidget(entry.description, ref, VariantPtr::dynamicCast(entry.value), iceManager, parent);
149 QString checkName =
id.toString();
150 QString observerName = item->parent()->parent()->data(
OBSERVER_ITEM_ID).toString();
151 ConditionCheckBasePtr check = availableChecks[observerName.toLatin1().data()][checkName.toLatin1().data()];
188 widget =
new QWidget(parent);
206 ConditionHandlerInterfacePrx handler = iceManager->getProxy<ConditionHandlerInterfacePrx>(
"ConditionHandler");
210 ObserverList registeredObs = handler->getObserverNames();
211 list = registeredObs;
220 ObserverList globalList = iceManager->getIceGridSession()->getRegisteredObjectNames<ObserverInterfacePrx>(
"*Observer");
221 list.insert(
list.end(), globalList.begin(), globalList.end());
222 std::sort(
list.begin(),
list.end());
223 ObserverList::iterator it = std::unique(
list.begin(),
list.end());
237 ObserverList::iterator iter = observerList.begin();
239 while (iter != observerList.end())
241 ObserverInterfacePrx proxy;
244 proxy = iceManager->getProxy<ObserverInterfacePrx>(*iter);
245 updateModel(*iter, proxy->getAvailableChannels(
true), proxy->getAvailableChecks());
251 iceManager->removeProxyFromCache(proxy);
259 QStandardItem* ObserverItemModel::updateObserver(std::string observerName)
262 QStandardItem* observerItem =
new QStandardItem(QString(observerName.c_str()));
265 observerItem = updateOrInsertItem(invisibleRootItem(), observerItem);
268 QStandardItem* channelsItem =
new QStandardItem(QString(
"channels"));
271 updateOrInsertItem(observerItem, channelsItem);
274 QStandardItem* checksItem =
new QStandardItem(QString(
"checks"));
277 updateOrInsertItem(observerItem, checksItem);
288 void ObserverItemModel::updateChannels(QStandardItem* channelsItem,
const ChannelRegistry& channels)
296 ChannelRegistry::const_iterator iterChannels = channels.begin();
298 while (iterChannels != channels.end())
301 QStandardItem* channelItem =
new QStandardItem(QString(iterChannels->second.name.c_str()));
304 channelItem->setData(QVariant(iterChannels->second.name.c_str()),
OBSERVER_ITEM_ID);
307 channelItem = updateOrInsertItem(channelsItem, channelItem);
310 DataFieldRegistry::const_iterator iterDataFields = iterChannels->second.dataFields.begin();
312 while (iterDataFields != iterChannels->second.dataFields.end())
315 std::string datafieldName = iterDataFields->second.identifier->channelRef->observerName +
"." + iterDataFields->second.identifier->channelRef->channelName +
"." + iterDataFields->second.identifier->datafieldName;
316 QStandardItem* dataFieldItem =
new QStandardItem(QString(iterDataFields->second.identifier->datafieldName.c_str()));
321 updateOrInsertItem(channelItem, dataFieldItem);
329 void ObserverItemModel::updateChecks(QStandardItem* checksItem,
const StringConditionCheckMap& checks)
336 StringConditionCheckMap::const_iterator iterChecks = checks.begin();
338 while (iterChecks != checks.end())
340 QStandardItem* checkItem =
new QStandardItem(QString(iterChecks->first.c_str()));
344 updateOrInsertItem(checksItem, checkItem);
383 QStandardItem* ObserverItemModel::updateOrInsertItem(QStandardItem* parent, QStandardItem*
insert)
386 for (
int r = 0 ; r < parent->rowCount() ; r++)
388 QStandardItem* item = parent->child(r);
398 parent->appendRow(
insert);
404 QStandardItem* ObserverItemModel::getChildByName(QStandardItem* item,
const QString& name)
406 for (
int r = 0 ; r < item->rowCount() ; r++)
410 return item->child(r);
419 void ObserverItemModel::markAllForDelete(QStandardItem* observerItem)
422 std::list<QStandardItem*> markList;
423 markList.push_back(observerItem);
425 while (markList.size() > 0)
427 QStandardItem* current = markList.front();
428 markList.pop_front();
432 if (current->hasChildren())
434 for (
int r = 0 ; r < current->rowCount() ; r++)
436 markList.push_back(current->child(r));
442 void ObserverItemModel::deleteUnusedItems(QStandardItem* observerItem)
444 std::list<QStandardItem*> searchList;
445 std::vector<int> removeRows;
447 searchList.push_back(observerItem);
449 while (searchList.size() > 0)
451 QStandardItem* current = searchList.back();
452 searchList.pop_back();
460 if (current->hasChildren())
464 for (
int r = 0 ; r < current->rowCount() ; r++)
469 removeRows.push_back(r);
474 searchList.push_back(current->child(r));
479 std::vector<int>::reverse_iterator iter = removeRows.rbegin();
481 while (iter != removeRows.rend())
483 current->removeRow(*iter);