PriorMemoryEditorPlugin.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::MemoryX::PriorMemoryEditorPlugin
17 * @author Alexey Kozlov (kozlov at kit dot edu)
18 * @copyright 2012
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 
22 */
23 
24 #pragma once
25 
26 /* ArmarX headers */
28 
31 
34 
35 #include <MemoryX/gui-plugins/PriorMemoryEditor/ui_PriorMemoryEditorPlugin.h>
36 
37 /* VirtualRobot headers */
38 #include <VirtualRobot/SceneObject.h>
39 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
40 #include <VirtualRobot/Visualization/VisualizationFactory.h>
41 
42 /* MemoryX headers */
44 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
46 
47 /* Qt headers */
48 #include <memory>
49 
50 #include <QMainWindow>
51 
52 /* Coin3D/SoQt headers */
53 #include <Inventor/Qt/SoQt.h>
54 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
55 #include <Inventor/nodes/SoEventCallback.h>
56 #include <Inventor/nodes/SoMatrixTransform.h>
57 #include <Inventor/nodes/SoNode.h>
58 #include <Inventor/nodes/SoSeparator.h>
59 #include <Inventor/sensors/SoTimerSensor.h>
60 
61 namespace memoryx
62 {
63  class PriorEditorConfigDialog;
64  class CollectionCreateDialog;
65 
66  /**
67  * \class PriorMemoryEditorPlugin
68  * \brief The PriorMemoryEditorPlugin provides a widget that allows to view and edit data entries in the prior memory.
69  * \see PriorEditorController
70  */
72  {
73  Q_OBJECT
74  Q_INTERFACES(ArmarXGuiInterface)
75  Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
76  public:
78  };
79 
80  /**
81  \page MemoryX-GuiPlugins-PriorMemoryEditor PriorMemoryEditor
82  \brief This widget allows viewing and editing data entries in the prior memory.
83 
84  \image html PriorMemoryEditor.png
85  You can inspect the different collections that are stored as prior knowledge by selecting a
86  collection from the collection drop-down-menu. All object classes that are stored within a collection
87  are listed in the table in the center of the screen. You may view the visual or collision model for
88  an object class by hitting the respective buttons. Similarly, you can also add, remove and edit entries.
89 
90  When you add the widget to the Gui, you need to specify the following parameters:
91 
92  Parameter Name | Example Value | Required? | Description
93  :---------------- | :-------------: | :-------------- |:--------------------
94  MongoDB host | localhost:27017 | Yes | The address of the mongo database that contains the prior memory.
95  MongoDB user | username | Only if DB is remote | ?
96  Password | userPassword | Only if DB is remote | ?
97  Gui Plugin Name | PriorMemoryEditorPlugin | Yes | ?
98  PriorMemory Name | PriorKnowledge | Yes | ?
99 
100  \note In order to use this Gui there must be prior knowledge within a MongoDB available.
101  PriorMemoryEditor API Documentation \ref PriorEditorController
102 
103  How to use:
104 
105  \li Gui->addWidget->PriorMemoryEditorPlugin
106  \li Different collection Lists (all collections need pr_ prefix so the gui can distinguish between different types)
107  \li All classes/objects are shown in list -> double click shows the 3D model in Viewer
108  \li Edit
109  -> parent classes (Food, used for queries like common places for Food),
110  -> model files via XML or separate IV files -> in /data/
111 
112 
113  \see PriorMemoryEditorPlugin
114  */
115 
116  /**
117  * @class PriorEditorController
118  * \brief This widget allows to view and edit data entries in the prior memory.
119  *
120  * @see PriorMemoryEditorPlugin
121  */
123  public armarx::ArmarXComponentWidgetControllerTemplate<PriorEditorController>
124  {
125  Q_OBJECT
126  public:
128 
130  {
131  }
132 
133  // inherited from Component
134  void onInitComponent() override;
135  void onConnectComponent() override;
136  void onDisconnectComponent() override;
137  void onExitComponent() override;
138 
139  // end of inherited from Component
140 
141  // inherited of ArmarXWidget
142  static QString
144  {
145  return "MemoryX.PriorMemoryEditor";
146  }
147 
148  static QIcon
150  {
151  return QIcon("://icons/database.svg");
152  }
153 
154  static QIcon
156  {
157  return QIcon("://icons/database.svg");
158  }
159 
160  void loadSettings(QSettings* settings) override;
161  void saveSettings(QSettings* settings) override;
162  QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
163  void configured() override;
164 
165  SoNode* getScene() override;
166 
167  bool setupViewer();
168 
169  signals:
170 
171  void objectsLoaded();
172 
173  void objectChanged(QString objectId, bool isNew);
174 
175  public slots:
176 
177  void reconnect();
178  void collectionChanged();
179  void addCollection();
180  void refetchData();
181 
182  void showObjectClassVisu();
183  void showObjectClassColl();
184  void addObjectClass();
185  void editObjectClass();
186  void removeObjectClass();
187  void treeItemDoubleClicked(QTreeWidgetItem* item, int column);
188  void treeCurrentItemChanged(QTreeWidgetItem* cur, QTreeWidgetItem* prev);
189 
190  void clearVisualization();
191 
192  protected:
193  using ObjectEntryMap = std::map<std::string, ObjectClassPtr>;
194 
195  void connectSlots();
196 
197  Ui::PriorMemoryEditorPlugin ui;
198 
199  bool verbose;
200 
201  // maps entityId with data
204 
205  SoSeparator* visu;
206 
207  //void updateModel();
208 
209  void updateObject(const memoryx::ObjectClassPtr obj, bool force = false);
210 
211  // build visualization
213 
214  void clearObjects();
215 
216 
217  private:
218  std::recursive_mutex mutexEntities;
219 
220  CommonStorageInterfacePrx databasePrx;
221  PriorKnowledgeInterfacePrx memoryPrx;
222  PersistentObjectClassSegmentBasePrx classesSegmentPrx;
223 
224  GridFileManagerPtr fileManager;
225 
226  void doEditClass(bool isNew);
227 
228  VirtualRobot::ManipulationObjectPtr loadManipulationObjectFile(const std::string& xmlFName);
229  VirtualRobot::ManipulationObjectPtr
230  createManipulationObjectFromIvFiles(const std::string& objName,
231  const std::string& ivFnameVis,
232  const std::string& ivFNameCollision);
233 
234  void storeClassManipulationFile(memoryx::ObjectClassPtr objClass,
235  const std::string& xmlFName);
236  void storeClassManipulationObject(memoryx::ObjectClassPtr objClass,
237  const VirtualRobot::ManipulationObjectPtr mo);
238  void storeClassIVFiles(memoryx::ObjectClassPtr objClass,
239  const std::string& visuFName,
240  const std::string& collisionFName);
241 
242  void findIVTextures(const std::string& ivFName, NameList& textures);
243 
244  void updateObjectInTree(memoryx::ObjectClassPtr obj);
245  std::string getSelectedClassId();
246  std::string getSelectedClassName();
247 
248  std::string getFilesDBName();
249 
250  void showObjectClassModel(const std::string& objectId,
251  VirtualRobot::SceneObject::VisualizationType visuType);
252 
253  void refreshControls();
254 
255  void setCurrentCollection(const std::string& collNS);
256  void refreshCollectionList();
257 
258  QPointer<PriorEditorConfigDialog> dialog;
259  QPointer<CollectionCreateDialog> collCreateDialog;
260 
261  std::string settings_priorMemory;
262  std::string settings_mongoHost;
263  std::string settings_mongoUser;
264  std::string settings_mongoPass;
265  std::string settings_robotStateComponentProxyName;
266  armarx::RobotStateComponentInterfacePrx robotStateComponent;
267 
268  bool connected;
269  };
270 
271  using PriorEditorControllerPtr = std::shared_ptr<PriorEditorController>;
272 } // namespace memoryx
RemoteRobot.h
memoryx::PriorEditorController::~PriorEditorController
virtual ~PriorEditorController()
Definition: PriorMemoryEditorPlugin.h:129
memoryx::PriorEditorControllerPtr
std::shared_ptr< PriorEditorController > PriorEditorControllerPtr
Definition: PriorMemoryEditorPlugin.h:271
memoryx::PriorEditorController::updateObject
void updateObject(const memoryx::ObjectClassPtr obj, bool force=false)
Definition: PriorMemoryEditorPlugin.cpp:701
memoryx::PriorEditorController::addCollection
void addCollection()
Definition: PriorMemoryEditorPlugin.cpp:326
memoryx::PriorEditorController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: PriorMemoryEditorPlugin.cpp:145
memoryx::PriorEditorController::show3DViewer
bool show3DViewer
Definition: PriorMemoryEditorPlugin.h:203
memoryx::PriorMemoryEditorPlugin
The PriorMemoryEditorPlugin provides a widget that allows to view and edit data entries in the prior ...
Definition: PriorMemoryEditorPlugin.h:71
memoryx::PriorEditorController::visu
SoSeparator * visu
Definition: PriorMemoryEditorPlugin.h:205
Pose.h
armarx::ArmarXGuiPlugin
Definition: ArmarXGuiPlugin.h:46
memoryx::PriorEditorController::GetWidgetName
static QString GetWidgetName()
Definition: PriorMemoryEditorPlugin.h:143
memoryx::PriorEditorController::showObjectClassColl
void showObjectClassColl()
Definition: PriorMemoryEditorPlugin.cpp:784
memoryx::PriorEditorController::reconnect
void reconnect()
Definition: PriorMemoryEditorPlugin.cpp:284
memoryx::PriorEditorController::addObjectClass
void addObjectClass()
Definition: PriorMemoryEditorPlugin.cpp:462
GridFileManager.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::PriorEditorController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: PriorMemoryEditorPlugin.cpp:207
memoryx::PriorEditorController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: PriorMemoryEditorPlugin.cpp:180
ObjectClass.h
memoryx::PriorEditorController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: PriorMemoryEditorPlugin.cpp:231
memoryx::PriorEditorController::clearVisualization
void clearVisualization()
Definition: PriorMemoryEditorPlugin.cpp:804
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
memoryx::PriorEditorController::createVisualization
void createVisualization(const ::memoryx::ObjectClassPtr obj)
memoryx::PriorEditorController::PriorEditorController
PriorEditorController()
Definition: PriorMemoryEditorPlugin.cpp:110
memoryx::PriorEditorController::collectionChanged
void collectionChanged()
Definition: PriorMemoryEditorPlugin.cpp:312
memoryx::PriorEditorController::connectSlots
void connectSlots()
Definition: PriorMemoryEditorPlugin.cpp:251
ArmarXGuiInterface
The main gui interface.
Definition: ArmarXGuiInterface.h:80
IceInternal::Handle< ObjectClass >
ArmarXGuiPlugin.h
memoryx::PriorEditorController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: PriorMemoryEditorPlugin.h:149
memoryx::PriorEditorController::currentObjectClasses
ObjectEntryMap currentObjectClasses
Definition: PriorMemoryEditorPlugin.h:202
ArmarXComponentWidgetController.h
memoryx::PriorEditorController::treeItemDoubleClicked
void treeItemDoubleClicked(QTreeWidgetItem *item, int column)
Definition: PriorMemoryEditorPlugin.cpp:640
memoryx::PriorEditorController::verbose
bool verbose
Definition: PriorMemoryEditorPlugin.h:199
memoryx::PriorEditorController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: PriorMemoryEditorPlugin.cpp:124
memoryx::PriorEditorController::objectsLoaded
void objectsLoaded()
memoryx::PriorEditorController::ui
Ui::PriorMemoryEditorPlugin ui
Definition: PriorMemoryEditorPlugin.h:197
memoryx::PriorEditorController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: PriorMemoryEditorPlugin.h:155
memoryx::PriorEditorController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: PriorMemoryEditorPlugin.cpp:223
memoryx::PriorEditorController::treeCurrentItemChanged
void treeCurrentItemChanged(QTreeWidgetItem *cur, QTreeWidgetItem *prev)
Definition: PriorMemoryEditorPlugin.cpp:633
memoryx::PriorEditorController::ObjectEntryMap
std::map< std::string, ObjectClassPtr > ObjectEntryMap
Definition: PriorMemoryEditorPlugin.h:193
Component.h
memoryx::PriorEditorController::editObjectClass
void editObjectClass()
Definition: PriorMemoryEditorPlugin.cpp:469
memoryx::PriorEditorController::setupViewer
bool setupViewer()
memoryx::PriorEditorController::objectChanged
void objectChanged(QString objectId, bool isNew)
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
memoryx::PriorEditorController::getScene
SoNode * getScene() override
Reimplementing this function and returning a SoNode* will show this SoNode in the 3DViewerWidget,...
Definition: PriorMemoryEditorPlugin.cpp:239
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
memoryx::PriorEditorController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: PriorMemoryEditorPlugin.cpp:169
memoryx::PriorEditorController::removeObjectClass
void removeObjectClass()
Definition: PriorMemoryEditorPlugin.cpp:540
memoryx::ObjectClassPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
Definition: ObjectClass.h:35
memoryx::PriorEditorController
This widget allows to view and edit data entries in the prior memory.
Definition: PriorMemoryEditorPlugin.h:122
memoryx::PriorEditorController::refetchData
void refetchData()
Definition: PriorMemoryEditorPlugin.cpp:343
memoryx::PriorEditorController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: PriorMemoryEditorPlugin.cpp:192
memoryx::PriorMemoryEditorPlugin::PriorMemoryEditorPlugin
PriorMemoryEditorPlugin()
Definition: PriorMemoryEditorPlugin.cpp:105
memoryx::PriorEditorController::showObjectClassVisu
void showObjectClassVisu()
Definition: PriorMemoryEditorPlugin.cpp:777
memoryx::PriorEditorController::clearObjects
void clearObjects()
Definition: PriorMemoryEditorPlugin.cpp:791