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 */
27 #include <MemoryX/gui-plugins/PriorMemoryEditor/ui_PriorMemoryEditorPlugin.h>
33 
34 /* VirtualRobot headers */
35 #include <VirtualRobot/SceneObject.h>
36 #include <VirtualRobot/Visualization/VisualizationFactory.h>
37 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
38 
39 /* MemoryX headers */
40 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
43 
44 /* Qt headers */
45 #include <QMainWindow>
46 
47 #include <memory>
48 
49 /* Coin3D/SoQt headers */
50 #include <Inventor/nodes/SoNode.h>
51 #include <Inventor/nodes/SoSeparator.h>
52 #include <Inventor/sensors/SoTimerSensor.h>
53 #include <Inventor/nodes/SoEventCallback.h>
54 #include <Inventor/nodes/SoMatrixTransform.h>
55 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
56 #include <Inventor/Qt/SoQt.h>
57 
58 namespace memoryx
59 {
60  class PriorEditorConfigDialog;
61  class CollectionCreateDialog;
62 
63  /**
64  * \class PriorMemoryEditorPlugin
65  * \brief The PriorMemoryEditorPlugin provides a widget that allows to view and edit data entries in the prior memory.
66  * \see PriorEditorController
67  */
70  {
71  Q_OBJECT
72  Q_INTERFACES(ArmarXGuiInterface)
73  Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
74  public:
76  };
77 
78  /**
79  \page MemoryX-GuiPlugins-PriorMemoryEditor PriorMemoryEditor
80  \brief This widget allows viewing and editing data entries in the prior memory.
81 
82  \image html PriorMemoryEditor.png
83  You can inspect the different collections that are stored as prior knowledge by selecting a
84  collection from the collection drop-down-menu. All object classes that are stored within a collection
85  are listed in the table in the center of the screen. You may view the visual or collision model for
86  an object class by hitting the respective buttons. Similarly, you can also add, remove and edit entries.
87 
88  When you add the widget to the Gui, you need to specify the following parameters:
89 
90  Parameter Name | Example Value | Required? | Description
91  :---------------- | :-------------: | :-------------- |:--------------------
92  MongoDB host | localhost:27017 | Yes | The address of the mongo database that contains the prior memory.
93  MongoDB user | username | Only if DB is remote | ?
94  Password | userPassword | Only if DB is remote | ?
95  Gui Plugin Name | PriorMemoryEditorPlugin | Yes | ?
96  PriorMemory Name | PriorKnowledge | Yes | ?
97 
98  \note In order to use this Gui there must be prior knowledge within a MongoDB available.
99  PriorMemoryEditor API Documentation \ref PriorEditorController
100 
101  How to use:
102 
103  \li Gui->addWidget->PriorMemoryEditorPlugin
104  \li Different collection Lists (all collections need pr_ prefix so the gui can distinguish between different types)
105  \li All classes/objects are shown in list -> double click shows the 3D model in Viewer
106  \li Edit
107  -> parent classes (Food, used for queries like common places for Food),
108  -> model files via XML or separate IV files -> in /data/
109 
110 
111  \see PriorMemoryEditorPlugin
112  */
113 
114  /**
115  * @class PriorEditorController
116  * \brief This widget allows to view and edit data entries in the prior memory.
117  *
118  * @see PriorMemoryEditorPlugin
119  */
121  public armarx::ArmarXComponentWidgetControllerTemplate<PriorEditorController>
122  {
123  Q_OBJECT
124  public:
127 
128  // inherited from Component
129  void onInitComponent() override;
130  void onConnectComponent() override;
131  void onDisconnectComponent() override;
132  void onExitComponent() override;
133  // end of inherited from Component
134 
135  // inherited of ArmarXWidget
136  static QString GetWidgetName()
137  {
138  return "MemoryX.PriorMemoryEditor";
139  }
140  static QIcon GetWidgetIcon()
141  {
142  return QIcon("://icons/database.svg");
143  }
144  static QIcon GetWidgetCategoryIcon()
145  {
146  return QIcon("://icons/database.svg");
147  }
148  void loadSettings(QSettings* settings) override;
149  void saveSettings(QSettings* settings) override;
150  QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
151  void configured() override;
152 
153  SoNode* getScene() override;
154 
155  bool setupViewer();
156 
157  signals:
158 
159  void objectsLoaded();
160 
161  void objectChanged(QString objectId, bool isNew);
162 
163  public slots:
164 
165  void reconnect();
166  void collectionChanged();
167  void addCollection();
168  void refetchData();
169 
170  void showObjectClassVisu();
171  void showObjectClassColl();
172  void addObjectClass();
173  void editObjectClass();
174  void removeObjectClass();
175  void treeItemDoubleClicked(QTreeWidgetItem* item, int column);
176  void treeCurrentItemChanged(QTreeWidgetItem* cur, QTreeWidgetItem* prev);
177 
178  void clearVisualization();
179 
180  protected:
181 
182  using ObjectEntryMap = std::map<std::string, ObjectClassPtr>;
183 
184  void connectSlots();
185 
186  Ui::PriorMemoryEditorPlugin ui;
187 
188  bool verbose;
189 
190  // maps entityId with data
193 
194  SoSeparator* visu;
195 
196  //void updateModel();
197 
198  void updateObject(const memoryx::ObjectClassPtr obj, bool force = false);
199 
200  // build visualization
202 
203  void clearObjects();
204 
205 
206  private:
207 
208  std::recursive_mutex mutexEntities;
209 
210  CommonStorageInterfacePrx databasePrx;
211  PriorKnowledgeInterfacePrx memoryPrx;
212  PersistentObjectClassSegmentBasePrx classesSegmentPrx;
213 
214  GridFileManagerPtr fileManager;
215 
216  void doEditClass(bool isNew);
217 
218  VirtualRobot::ManipulationObjectPtr loadManipulationObjectFile(const std::string& xmlFName);
219  VirtualRobot::ManipulationObjectPtr createManipulationObjectFromIvFiles(const std::string& objName,
220  const std::string& ivFnameVis, const std::string& ivFNameCollision);
221 
222  void storeClassManipulationFile(memoryx::ObjectClassPtr objClass, const std::string& xmlFName);
223  void storeClassManipulationObject(memoryx::ObjectClassPtr objClass,
224  const VirtualRobot::ManipulationObjectPtr mo);
225  void storeClassIVFiles(memoryx::ObjectClassPtr objClass,
226  const std::string& visuFName, const std::string& collisionFName);
227 
228  void findIVTextures(const std::string& ivFName, NameList& textures);
229 
230  void updateObjectInTree(memoryx::ObjectClassPtr obj);
231  std::string getSelectedClassId();
232  std::string getSelectedClassName();
233 
234  std::string getFilesDBName();
235 
236  void showObjectClassModel(const std::string& objectId, VirtualRobot::SceneObject::VisualizationType visuType);
237 
238  void refreshControls();
239 
240  void setCurrentCollection(const std::string& collNS);
241  void refreshCollectionList();
242 
243  QPointer<PriorEditorConfigDialog> dialog;
244  QPointer<CollectionCreateDialog> collCreateDialog;
245 
246  std::string settings_priorMemory;
247  std::string settings_mongoHost;
248  std::string settings_mongoUser;
249  std::string settings_mongoPass;
250  std::string settings_robotStateComponentProxyName;
251  armarx::RobotStateComponentInterfacePrx robotStateComponent;
252 
253  bool connected;
254 
255  };
256  using PriorEditorControllerPtr = std::shared_ptr<PriorEditorController>;
257 }
258 
259 
260 
RemoteRobot.h
memoryx::PriorEditorController::~PriorEditorController
virtual ~PriorEditorController()
Definition: PriorMemoryEditorPlugin.h:126
memoryx::PriorEditorControllerPtr
std::shared_ptr< PriorEditorController > PriorEditorControllerPtr
Definition: PriorMemoryEditorPlugin.h:256
memoryx::PriorEditorController::updateObject
void updateObject(const memoryx::ObjectClassPtr obj, bool force=false)
Definition: PriorMemoryEditorPlugin.cpp:648
memoryx::PriorEditorController::addCollection
void addCollection()
Definition: PriorMemoryEditorPlugin.cpp:300
memoryx::PriorEditorController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: PriorMemoryEditorPlugin.cpp:141
memoryx::PriorEditorController::show3DViewer
bool show3DViewer
Definition: PriorMemoryEditorPlugin.h:192
memoryx::PriorMemoryEditorPlugin
The PriorMemoryEditorPlugin provides a widget that allows to view and edit data entries in the prior ...
Definition: PriorMemoryEditorPlugin.h:68
memoryx::PriorEditorController::visu
SoSeparator * visu
Definition: PriorMemoryEditorPlugin.h:194
Pose.h
armarx::ArmarXGuiPlugin
Definition: ArmarXGuiPlugin.h:46
memoryx::PriorEditorController::GetWidgetName
static QString GetWidgetName()
Definition: PriorMemoryEditorPlugin.h:136
memoryx::PriorEditorController::showObjectClassColl
void showObjectClassColl()
Definition: PriorMemoryEditorPlugin.cpp:727
memoryx::PriorEditorController::reconnect
void reconnect()
Definition: PriorMemoryEditorPlugin.cpp:263
memoryx::PriorEditorController::addObjectClass
void addObjectClass()
Definition: PriorMemoryEditorPlugin.cpp:425
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:197
memoryx::PriorEditorController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: PriorMemoryEditorPlugin.cpp:174
ObjectClass.h
memoryx::PriorEditorController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: PriorMemoryEditorPlugin.cpp:219
memoryx::PriorEditorController::clearVisualization
void clearVisualization()
Definition: PriorMemoryEditorPlugin.cpp:745
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
memoryx::PriorEditorController::createVisualization
void createVisualization(const ::memoryx::ObjectClassPtr obj)
memoryx::PriorEditorController::PriorEditorController
PriorEditorController()
Definition: PriorMemoryEditorPlugin.cpp:107
memoryx::PriorEditorController::collectionChanged
void collectionChanged()
Definition: PriorMemoryEditorPlugin.cpp:287
memoryx::PriorEditorController::connectSlots
void connectSlots()
Definition: PriorMemoryEditorPlugin.cpp:238
ArmarXGuiInterface
The main gui interface.
Definition: ArmarXGuiInterface.h:74
IceInternal::Handle< ObjectClass >
ArmarXGuiPlugin.h
memoryx::PriorEditorController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: PriorMemoryEditorPlugin.h:140
memoryx::PriorEditorController::currentObjectClasses
ObjectEntryMap currentObjectClasses
Definition: PriorMemoryEditorPlugin.h:191
ArmarXComponentWidgetController.h
memoryx::PriorEditorController::treeItemDoubleClicked
void treeItemDoubleClicked(QTreeWidgetItem *item, int column)
Definition: PriorMemoryEditorPlugin.cpp:593
memoryx::PriorEditorController::verbose
bool verbose
Definition: PriorMemoryEditorPlugin.h:188
memoryx::PriorEditorController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: PriorMemoryEditorPlugin.cpp:121
memoryx::PriorEditorController::objectsLoaded
void objectsLoaded()
memoryx::PriorEditorController::ui
Ui::PriorMemoryEditorPlugin ui
Definition: PriorMemoryEditorPlugin.h:186
memoryx::PriorEditorController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: PriorMemoryEditorPlugin.h:144
memoryx::PriorEditorController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: PriorMemoryEditorPlugin.cpp:212
memoryx::PriorEditorController::treeCurrentItemChanged
void treeCurrentItemChanged(QTreeWidgetItem *cur, QTreeWidgetItem *prev)
Definition: PriorMemoryEditorPlugin.cpp:587
memoryx::PriorEditorController::ObjectEntryMap
std::map< std::string, ObjectClassPtr > ObjectEntryMap
Definition: PriorMemoryEditorPlugin.h:182
Component.h
memoryx::PriorEditorController::editObjectClass
void editObjectClass()
Definition: PriorMemoryEditorPlugin.cpp:431
memoryx::PriorEditorController::setupViewer
bool setupViewer()
memoryx::PriorEditorController::objectChanged
void objectChanged(QString objectId, bool isNew)
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
memoryx::PriorEditorController::getScene
SoNode * getScene() override
Reimplementing this function and returning a SoNode* will show this SoNode in the 3DViewerWidget,...
Definition: PriorMemoryEditorPlugin.cpp:227
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
memoryx::PriorEditorController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: PriorMemoryEditorPlugin.cpp:164
memoryx::PriorEditorController::removeObjectClass
void removeObjectClass()
Definition: PriorMemoryEditorPlugin.cpp:500
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:120
memoryx::PriorEditorController::refetchData
void refetchData()
Definition: PriorMemoryEditorPlugin.cpp:315
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:185
memoryx::PriorMemoryEditorPlugin::PriorMemoryEditorPlugin
PriorMemoryEditorPlugin()
Definition: PriorMemoryEditorPlugin.cpp:101
memoryx::PriorEditorController::showObjectClassVisu
void showObjectClassVisu()
Definition: PriorMemoryEditorPlugin.cpp:721
memoryx::PriorEditorController::clearObjects
void clearObjects()
Definition: PriorMemoryEditorPlugin.cpp:733