30#include <MemoryX/gui-plugins/PriorMemoryEditor/ui_CollectionCreateDialog.h>
31#include <MemoryX/gui-plugins/PriorMemoryEditor/ui_PriorEditorConfigDialog.h>
35#include <ArmarXCore/interface/core/Log.h>
47#include <QStandardItemModel>
54#include <Inventor/Qt/SoQt.h>
55#include <Inventor/SoDB.h>
56#include <Inventor/nodes/SoUnits.h>
71#include <VirtualRobot/CollisionDetection/CollisionModel.h>
72#include <VirtualRobot/Grasping/Grasp.h>
73#include <VirtualRobot/Grasping/GraspSet.h>
74#include <VirtualRobot/ManipulationObject.h>
75#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
76#include <VirtualRobot/XML/ObjectIO.h>
77#include <VirtualRobot/XML/RobotIO.h>
90namespace fs = std::filesystem;
92#define DEFAULT_SETTINGS_PLUGIN_NAME "PriorMemoryEditorPlugin"
93#define DEFAULT_SETTINGS_PRIORMEMORY_NAME "PriorKnowledge"
119 collCreateDialog->setCollectionPrefix(memoryx::PRIOR_COLLECTION_PREFIX);
129 visu =
new SoSeparator();
134 ARMARX_INFO <<
"PriorMemory: " << settings_priorMemory;
138 if (!settings_robotStateComponentProxyName.empty())
140 usingProxy(settings_robotStateComponentProxyName);
149 classesSegmentPrx = memoryPrx->getObjectClassesSegment();
150 databasePrx = memoryPrx->getCommonStorage();
151 if (!settings_robotStateComponentProxyName.empty())
153 getProxy(robotStateComponent, settings_robotStateComponentProxyName);
158 ui.editHost->setText(QString::fromStdString(databasePrx->getMongoHostAndPort()));
160 connected = databasePrx->isConnected();
163 refreshCollectionList();
164 setCurrentCollection(classesSegmentPrx->getWriteCollectionNS());
173 collCreateDialog->close();
197 dialog->ui->editPriorMemoryEditorName->setText(
199 dialog->ui->editPriorMemoryName->setText(
203 return qobject_cast<PriorEditorConfigDialog*>(dialog);
210 settings_mongoHost = dialog->ui->editMongoHost->text().toStdString();
211 settings_mongoUser = dialog->ui->editMongoUser->text().toStdString();
212 settings_mongoPass = dialog->ui->editMongoPass->text().toStdString();
213 settings_priorMemory = dialog->ui->editPriorMemoryName->text().toStdString();
215 settings_robotStateComponentProxyName =
216 dialog->proxyFinder->getSelectedProxyName().toStdString();
244 std::cout <<
"returning scene=" <<
visu->getName() << std::endl;
254 connect(
ui.btnReconnect, SIGNAL(clicked()),
this, SLOT(
reconnect()));
256 connect(
ui.btnAddCollection, SIGNAL(clicked()),
this, SLOT(
addCollection()));
257 connect(
ui.btnRefetch, SIGNAL(clicked()),
this, SLOT(
refetchData()));
259 connect(
ui.cbCollection,
260 SIGNAL(currentIndexChanged(
int)),
263 Qt::QueuedConnection);
273 connect(
ui.treeWidgetEntities,
274 SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
277 connect(
ui.treeWidgetEntities,
278 SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
288 connected = databasePrx->reconnect(
289 ui.editHost->text().toStdString(), settings_mongoUser, settings_mongoPass);
295 msgBox.setText(
"Error connecting to MongoDB! \nCheck if mongod is running on " +
296 ui.editHost->text());
297 msgBox.setIcon(QMessageBox::Critical);
301 refreshCollectionList();
305PriorEditorController::setCurrentCollection(
const std::string& collNS)
308 ui.cbCollection->setCurrentIndex(
ui.cbCollection->findText(QString::fromStdString(collNS)));
315 const std::string collName =
ui.cbCollection->currentText().toStdString();
317 if (!collName.empty())
319 CollectionInterfacePrx coll = databasePrx->requestCollection(collName);
320 classesSegmentPrx->setWriteCollection(coll);
329 const NameList dbNames = databasePrx->getDBNames();
330 collCreateDialog->setDatabases(dbNames);
331 int result = collCreateDialog->exec();
333 if (result == QDialog::Accepted)
335 const std::string collectionNS =
336 collCreateDialog->getDBName() +
"." + collCreateDialog->getCollectionName();
337 ui.cbCollection->addItem(QString::fromStdString(collectionNS));
338 setCurrentCollection(collectionNS);
346 const std::string collName =
ui.cbCollection->currentText().toStdString();
347 ARMARX_INFO <<
"Refetching data from DB from collection '" << collName <<
"'";
348 std::unique_lock lock(mutexEntities);
351 auto collection = databasePrx->requestCollection(collName);
352 auto ids = collection->findAllIds();
353 ARMARX_INFO <<
"Found " << ids.size() <<
" entities";
356 for (
const auto&
id : ids)
358 EntityBasePtr entity = classesSegmentPrx->getEntityById(
id);
362 ARMARX_WARNING <<
"Could not find entity with id " <<
id <<
" in collection "
366 const ObjectClassPtr objClass = ObjectClassPtr::dynamicCast(entity);
374 ARMARX_WARNING <<
"Failed to cast to ObjectClass: " << entity->getName() <<
", "
375 << entity->getId() <<
", " << entity->ice_id();
380 ui.treeWidgetEntities->sortByColumn(0, Qt::AscendingOrder);
386PriorEditorController::refreshCollectionList()
389 ui.cbCollection->clear();
396 auto activeReadCollectionNames = memoryPrx->getObjectClassesSegment()->getReadCollectionsNS();
397 const NameList dbNames = databasePrx->getDBNames();
398 int firstActiveCollection = -1;
400 for (std::string
const& dbName : dbNames)
402 const NameList collNames = databasePrx->getCollectionNames(dbName);
404 for (std::string
const& collName : collNames)
406 std::string fullCollName = dbName +
"." + collName;
407 if (memoryPrx->isPriorCollection(fullCollName))
409 if (std::find(activeReadCollectionNames.begin(),
410 activeReadCollectionNames.end(),
411 fullCollName) != activeReadCollectionNames.end())
413 ui.cbCollection->addItem(QString::fromStdString(fullCollName));
415 if (firstActiveCollection == -1)
417 firstActiveCollection =
ui.cbCollection->count() - 1;
422 ui.cbCollection->addItem(QString::fromStdString(
423 collName +
"(not selected in PriorKnowledge config)"));
424 const QStandardItemModel* model =
425 qobject_cast<const QStandardItemModel*>(
ui.cbCollection->model());
427 QStandardItem* item = model->item(model->rowCount() - 1);
430 item->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled));
433 ui.cbCollection->palette().color(
442 if (
ui.cbCollection->currentIndex() >= 0)
444 const QStandardItemModel* model =
445 qobject_cast<const QStandardItemModel*>(
ui.cbCollection->model());
447 QStandardItem* item = model->item(
ui.cbCollection->currentIndex());
450 if (!(item->flags() & Qt::ItemIsEnabled))
452 ui.cbCollection->setCurrentIndex(firstActiveCollection);
457 ui.cbCollection->setCurrentIndex(firstActiveCollection);
476PriorEditorController::doEditClass(
bool isNew)
482 const std::string clsId = getSelectedClassId();
502 ObjectClassEditDialog* classEditDialog =
new ObjectClassEditDialog(robotStateComponent);
511 int result = classEditDialog->exec();
513 if (result == QDialog::Accepted)
515 ARMARX_INFO <<
"Saving changes to object class...";
518 classEditDialog->
updateEntity(objectClass, getFilesDBName());
523 const std::string
id = classesSegmentPrx->addEntity(objectClass);
524 objectClass->setId(
id);
529 classesSegmentPrx->updateEntity(objectClass->getId(), objectClass);
532 updateObjectInTree(objectClass);
536 delete classEditDialog;
543 const std::string clsName = getSelectedClassName();
544 const std::string clsId = getSelectedClassId();
552 msgBox.setText(
"Delete object class " + QString(clsName.c_str()) +
"?");
553 msgBox.setIcon(QMessageBox::Question);
554 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
555 int ret = msgBox.exec();
557 if (ret == QMessageBox::Yes)
567 classesSegmentPrx->removeEntity(clsId);
568 QTreeWidgetItem* selItem =
ui.treeWidgetEntities->currentItem();
572 delete ui.treeWidgetEntities->takeTopLevelItem(
573 ui.treeWidgetEntities->indexOfTopLevelItem(selItem));
581PriorEditorController::getSelectedClassId()
584 QTreeWidgetItem* selItem =
ui.treeWidgetEntities->currentItem();
588 return selItem->text(1).toStdString();
597PriorEditorController::getSelectedClassName()
600 QTreeWidgetItem* selItem =
ui.treeWidgetEntities->currentItem();
604 return selItem->text(0).toStdString();
613PriorEditorController::refreshControls()
616 ui.lblConnected->setText(QString::fromStdString(connected ?
"Connected" :
"Disconnected"));
617 ui.lblConnected->setStyleSheet(
618 QString::fromStdString(connected ?
"color: rgb(0, 170, 0);" :
"color: rgb(170, 0, 0);"));
620 ui.btnAddCollection->setEnabled(connected);
621 ui.btnRefetch->setEnabled(connected);
623 QTreeWidgetItem* cur =
ui.treeWidgetEntities->currentItem();
625 ui.btnAdd->setEnabled(connected);
626 ui.btnEdit->setEnabled(clsSelected);
627 ui.btnRemove->setEnabled(clsSelected);
628 ui.btnShowVisu->setEnabled(clsSelected);
629 ui.btnShowColl->setEnabled(clsSelected);
645 ARMARX_INFO <<
" Selected object: " << item->text(1).toStdString();
646 showObjectClassModel(item->text(1).toStdString(), SceneObject::Full);
651PriorEditorController::getFilesDBName()
654 const std::string ns = classesSegmentPrx->getWriteCollectionNS();
655 const size_t found = ns.find_first_of(
'.');
656 return (found != std::string::npos) ? ns.substr(0, found) :
"";
663 QString objName(obj->getName().c_str());
664 QString objId(obj->getId().c_str());
666 QList<QTreeWidgetItem*> oldItems =
667 ui.treeWidgetEntities->findItems(objId, Qt::MatchFixedString, 1);
669 QTreeWidgetItem* objItem =
670 (oldItems.size() == 0)
673 objItem->setText(0, objName);
674 objItem->setText(1, objId);
709 std::unique_lock lock(mutexEntities);
711 const std::string
id = objClass->getId();
716 ARMARX_INFO <<
"Building new entry for object class " << objClass->getName();
727 updateObjectInTree(objClass);
731PriorEditorController::showObjectClassModel(
const std::string& objectId,
732 SceneObject::VisualizationType visuType)
735 std::unique_lock lock(mutexEntities);
745 Eigen::Matrix4f m = Eigen::Matrix4f::Identity();
749 auto mo = simoxWrapper->getManipulationObject();
752 mo->setGlobalPose(m);
753 mo->showCoordinateSystem(
true);
756 VisualizationNodePtr visNode;
758 if (visuType == SceneObject::Full)
761 visNode = simoxWrapper->getVisualization();
763 else if (visuType == SceneObject::Collision && simoxWrapper->getCollisionModel())
766 visNode = simoxWrapper->getCollisionModel()->getVisualization();
772 visu->addChild(VirtualRobot::CoinVisualizationFactory::getCoinVisualization(visNode));
780 showObjectClassModel(getSelectedClassId(), SceneObject::Full);
787 showObjectClassModel(getSelectedClassId(), SceneObject::Collision);
794 std::unique_lock lock(mutexEntities);
800 ui.treeWidgetEntities->clear();
807 visu->removeAllChildren();
#define DEFAULT_SETTINGS_PRIORMEMORY_NAME
#define DEFAULT_SETTINGS_PLUGIN_NAME
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArMarkerWrapper offers a simplified access to the necessary information for localization of AR marker...
HandMarkerBallWrapper offers a simplified access to the necessary information for localization of the...
SegmentableRecognitionWrapper offers a simplified access to the data of an object class or instance r...
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
TexturedRecognitionWrapper offers a simplified access to the data of an object class or instance rela...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
void setClassNameEditable(bool editable)
void updateEntity(const EntityPtr &entity, std::string filesDBName) override
Pure virtual method.
void updateGui(const EntityPtr &entity) override
Pure virtual method.
void onInitComponent() override
Pure virtual hook for the subclass.
void treeItemDoubleClicked(QTreeWidgetItem *item, int column)
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
SoNode * getScene() override
Reimplementing this function and returning a SoNode* will show this SoNode in the 3DViewerWidget,...
Ui::PriorMemoryEditorPlugin ui
void showObjectClassColl()
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void onConnectComponent() override
Pure virtual hook for the subclass.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
ObjectEntryMap currentObjectClasses
void treeCurrentItemChanged(QTreeWidgetItem *cur, QTreeWidgetItem *prev)
void updateObject(const memoryx::ObjectClassPtr obj, bool force=false)
void onExitComponent() override
Hook for subclass.
void showObjectClassVisu()
void clearVisualization()
PriorMemoryEditorPlugin()
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr