SceneEditorMainWindowController.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditorWidgetController
19  * @author Kiron Mirdha ( kiron dot mirdha at student dot kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 
28 /* ArmarX headers */
32 
33 /* C++ libraries */
34 #include <string>
35 
36 /* Qt headers */
37 #include <QWidget>
38 #include <QToolBar>
39 #include <QTranslator>
40 #include <QVariant>
41 #include <QSettings>
42 #include <QComboBox>
43 
44 /* SceneEditor headers */
45 #include "SceneEditorMainWindow.h"
50 #include "dialog/ShortcutDialog.h"
51 #include "ShortcutController.h"
53 #include "../controller/Controller.h"
54 
55 namespace gui
56 {
57  class SceneEditorMainWindow;
58 }
59 
60 namespace gui
61 {
62  /**
63  \page MemoryX-GuiPlugins-SceneEditor SceneEditor
64  \tableofcontents
65  This Plugin is an editor for the selected WorkingMemory which contains the current knowledge of the roboter about its environment.
66  With this editor it is only possible to edit the scene and not relationships between objects or related properties.
67 
68  This is a live-editor which means, that any changes made to the scene are directly transfered to the used WorkingMemory.
69  Therefore it might happen that other plugins show inconsistent states of the WorkingMemory.
70  This plugin on the other hand detects changes made by other instances and adjusts the shown scene immediately.
71 
72  \section MemoryX-GuiPlugins-SceneEditor-startingEditor Starting the Editor
73  @image html SceneEditor_ConfigDialog.png "The config-dialog of the plugin"
74 
75  When you add the widget to the Gui, you need to specify the following parameters:
76 
77  Parameter Name | Example Value | Required? | Description
78  :---------------- | :-------------: | :-------------- |:--------------------
79  Select Configuration-File | .../armarx/MemoryX/build/bin/SceneEditor.ini | yes | Settings for this plugin
80  Working Memory Name | Working Memory | yes | ?
81  Working-Memory-Updates | WorkingMemoryUpdates | yes | the topic that publishes changes in the selected working memory
82  Prior Memory Name | PriorKnowledge | Yes | The name of the prior memory
83 
84  \note In order to use this plugin following memories must be available:
85  \note - WorkingMemory
86  \note - PriorKnowledge
87  \note - CommonStorage
88  \note - LongtermMemory
89 
90  Make sure that these four components are getting started in the scenario-file you use.
91 
92  \section MemoryX-GuiPlugins-SceneEditor-overview Overview
93  @image html SceneEditor_wholeWindow.png "The plugin's UI"
94  -# Object Explorer
95  - Contains the every readable collection of addable objects.
96  - By selecting an object its properties are shown in the Object Inspector.
97  - Objects can be added to scene via Drag-and-Drop.
98  -# Scene-ViewMemoryX-GuiPlugins-SceneEditor-groups
99  - A 3D-Representation of the current content of the WorkingMemory
100  - Two modes:
101  - Editor-Mode: The scene can be manipulated, buttons for undo/redo and different manipulators are accessible.
102  - Viewer-Mode: Manipulation not possible, can be used for presentations.
103  - \ref MemoryX-GuiPlugins-SceneEditor-navigationManipulation
104  -# Object Inspector
105  - \ref MemoryX-GuiPlugins-SceneEditor-objectInspector
106  -# Minimap
107  - Simply a top-view of the whole scene.
108  - By clicking on it the camera of the Scene-View will be set to same position as in the minimap
109  -# Group Explorer
110  - List of all current groups
111  - Two Buttons per Entry:
112  - Add every object that is currently selected in the scene to that group
113  - Add every object in that group to the current selection
114  - All selected objects can be added to a new group
115  - By double-clicking on a group the Group-Explorer opens. See \ref MemoryX-GuiPlugins-SceneEditor-groups
116  -# Snapshots and Settings
117  - Buttons for ...
118  - Loading/Saving Snapshots (\ref MemoryX-GuiPlugins-SceneEditor-snapshots)
119  - Opening shortcut-settings where every shortcut working in this plugin can be found and edited.
120  - Opening group explorer (\ref MemoryX-GuiPlugins-SceneEditor-groups)
121  - Clearing the whole scene and thus the whole working memory and deleting every object
122  - Selecting language of the plugin
123 
124  \section MemoryX-GuiPlugins-SceneEditor-snapshots Load-Save Snapshot
125  @image html SceneEditor_loadSnapshot.png "Loading a Snapshot into the scene/working-memory"
126 
127  - Select the snapshot to load and its content will be <b>added</b> to the current scene. The scene will not be cleared before the loading.
128  - The objects in the loaded snapshot are always added together to a new group (\ref MemoryX-GuiPlugins-SceneEditor-groups).
129 
130  @image html SceneEditor_saveSnapshot.png "Saving the scene/working-memory into a snapshot"
131 
132  - It is either possible to create a new snapshot or override an existing one. The name of a new snapshot has to start with the prefix
133  "Snapshot_" otherwise it will be added to the name automatically.
134  - By selecting 'Save all' every object of the scene is saved.
135  - On the other hand you can select specific \ref MemoryX-GuiPlugins-SceneEditor-groups and only the objects in these groups are saved.
136 
137  \section MemoryX-GuiPlugins-SceneEditor-navigationManipulation Navigation and Manipulation
138  - The navigation through the scene is quite similar to other 3D-Manipulation-Programs:
139  - Left click to select objects ('Shift' + left-click to select several objects successively)
140  - Hold mouse wheel + 'Shift' to move the camera
141  - Hold mouse wheel to rotate the camera (for rotation shortcuts check the shortcut-settings)
142  - Use mouse wheel to zoom
143 
144  @image html SceneEditor_SceneViewButtons.png "Buttons accessible in Editor-Mode"
145 
146  -# Toggle between showing the visualisation meshes or the collision meshes of the objects
147  -# (De-)Activate Rotation-Manipulator
148  - Adds a sphere around selected objects which allows to rotate the object by clicking on and moving the green points.
149  - If more than one object is selected all of them are rotated around their common center.
150  -# (Se-)Activate Translation-Manipulator
151  - Adds a cuboid around selected objects.
152  - Left-CLick an -Hold on one side of the cuboid allows to move the objects within this level.
153  - Additional holding 'Shift' allows to move only in one direction.
154  - Additional holding 'Ctrl' allows to move only in the direction orthogonal to the selected side.
155  -# Undo last action (select/move/rotate/add/remove object/s)
156  - 'Ctrl' + 'Z'
157  -# Redo last action
158  - 'Ctrl' + 'Shift' + 'Z'
159  -# Delete selected objects
160  - 'Del'
161 
162  \section MemoryX-GuiPlugins-SceneEditor-objectInspector Object Inspector
163  @image html SceneEditor_ObjectInspector.png "Object Inspector while an object in the scene is selected
164 
165  - Shows the instance attributes of the selected object
166  - If several objects are selected the attributes of the object that has been selected last are shown (orange border in scene view)
167  - Allows to edit the location and orientaion of an object in the scene. (Press 'Enter' to confirm input)
168 
169  \note Although it is possible to edit the orientation with the Object Inspector it is not very useful:
170  \note Due to the fact that quanternions are used to store the orientation and location
171  the angle-axis-representation is not very practical for editing.
172  \note (You will see the values change after you hit 'Enter'.
173 
174  \section MemoryX-GuiPlugins-SceneEditor-groups Groups
175 
176  You can create groups of objects in the scene to simplify your task.
177  They provide the advantage that it is possible to easily select a large number of objects over and over with only one click.
178  Check \ref MemoryX-GuiPlugins-SceneEditor-overview to see how to create groups directly from the main-window.
179  \note They exist only as long as the plugin is running, because they will not be saved in a snapshot.
180 
181 
182  @image html SceneEditor_GroupEditor.png "The Group-Explorer for maintaining groups"
183 
184  Following actions are possible:
185  - Changing the name of selected group
186  - Deleting the selected group. (Only the group not the objects within the group)
187  - Creating a new empty group
188  - Showing the objects that belong to a group
189  - Remove an object from a group (Button 'Delete Object')
190 
191  @see SceneEditorMainWindowController
192 
193  */
194 
195  /**
196  * This class is a custom armarx::ArmarXComponentWidgetController.
197  * It creates the main window of the plugin and provides all functions to integrate the plugin in the ArmarXGui.
198  * It establishes the connection to MemoryX via Ice.
199  *
200  * @class SceneEditorMainWindow
201  * @brief SceneEditorMainWindow brief one line description
202  *
203  */
206  public armarx::ArmarXComponentWidgetControllerTemplate<SceneEditorMainWindowController>
207  {
208  Q_OBJECT
209 
210  public:
211  /**
212  * Constructor.
213  * Creates an instance of SceneEditorMainWindowController.
214  *
215  */
217 
218  /**
219  * Destructor.
220  * Destroys the instance of SceneEditorMainWindowController.
221  *
222  */
224 
225  /**
226  * Reimplemented ArmarXWidgetController:loadSettings().
227  *
228  * @param settings Qt::QSettings
229  * @see ArmarXWidgetController:loadSettings()
230  *
231  */
232  void loadSettings(QSettings* settings) override;
233 
234  /**
235  * Reimplemented ArmarXWidgetController:saveSettings().
236  *
237  * @param settings Qt::QSettings
238  * @see ArmarXWidgetController:saveSettings()
239  *
240  */
241  void saveSettings(QSettings* settings) override;
242 
243  /**
244  * Reimplemented armarx::Component:getWidgetName().
245  *
246  * Returns the widget name displayed in the ArmarXGui to create an
247  * instance of this class.
248  *
249  * @see armarx::Component:getWidgetName()
250  *
251  */
252  static QString GetWidgetName()
253  {
254  return "MemoryX.SceneEditor";
255  }
256 
257  /**
258  * Reimplemented armarx::Component:onInitComponent().
259  *
260  * @see armarx::Component:onInitComponent()
261  *
262  */
263  void onInitComponent() override;
264 
265  /**
266  * Reimplementiert armarx::Component:onConnectComponent().
267  *
268  * @see armarx::Component:onConnectComponent()
269  *
270  */
271  void onConnectComponent() override;
272 
273  /**
274  * @see armarx::Component::onDisconnectComponent()
275  */
276  void onDisconnectComponent() override;
277 
278  QPointer<QWidget> getWidget() override;
279 
280  /**
281  * Reimplemented ArmarXWidgetController:getCustomTitlebarWidget().
282  *
283  * @param parent parent widget
284  * @see ArmarXWidgetController:getCustomTitlebarWidget()
285  *
286  */
287  QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
288 
289  /**
290  * Reimplemented ArmarXWidgetController:getConfigDialog().
291  *
292  * @param parent parent widget
293  * @see ArmarXWidgetController:getConfigDialog()
294  *
295  */
296  QPointer<QDialog> getConfigDialog(QWidget* parent) override;
297 
298  /**
299  * Reimplemented ArmarXWidgetController:configured().
300  *
301  * @see ArmarXWidgetController:configured()
302  *
303  */
304  void configured() override;
305 
306  private slots:
307  /** this slot is called by the language menu actions
308  */
309  void slotLanguageChanged(const int languageIndex);
310  /** this slot is called when a language change event occurs in the main window
311  */
312  void slotLanguageChangedByUser();
313 
314  private:
315  QPointer<SceneEditorMainWindow> mainWindow;
316  QPointer<dialog::SceneEditorConfigDialog> configDialog;
317  QPointer<QToolBar> customToolbar;
318  QPointer<dialog::GroupExplorerDialog> groupEditorDialog;
319  QPointer<dialog::LoadSnapshotDialog> loadSnapshotDialog;
320  QPointer<dialog::SaveSnapshotDialog> saveSnapshotDialog;
321  QPointer<dialog::ShortcutDialog> shortcutDialog;
322  QPointer<QComboBox> languageSelection;
323 
324  QPointer<QAction> loadSnapshotAction;
325  QPointer<QAction> saveSnapshotAction;
326  QPointer<QAction> openShortcutDialogAction;
327  QPointer<QAction> openGroupEditorAction;
328  QPointer<QAction> clearWorkingMemoryAction;
329 
331 
332  std::string workingMemoryName;
333  std::string workingMemoryUpdatesTopic;
334  std::string objectInstancesSegmentName;
335  std::string priorMemoryName;
336 
337  QString settingsPath;
338 
339  /** Loads a language by the given language abbreviation (e.g. de, en, ...)
340  * @param language the abbreviation of the language to load
341  */
342  void loadLanguage(const QString& language);
343 
344  /** creates the language menu dynamically from the content of m_langPath
345  */
346  void createLanguageMenu();
347 
348  /**
349  * @brief Removes the current translator and installs the given translator.
350  * The translator loads its needed .qm file with the given filename from the given directory
351  *
352  * @param translator the new translator
353  * @param filename the name of the .qm file the translator will load
354  * @param directory the location of the .qm file
355  */
356  void switchTranslator(QTranslator& translator, const QString& filename, const QString& directory);
357 
358  QTranslator m_translator; /**< contains the translations for this application */
359  QTranslator m_translatorQt;
360  QString m_currLang; /**< contains the currently loaded language */
361  QString m_langPath; /**< Path of language files */
362 
363  private slots:
364  void clearScene();
365  void openLoadSnapshotDialog();
366  void openSaveSnapshotDialog();
367  void openShortcutDialog();
368  void openGroupEditorDialog();
369  void onConnectComponentQt();
370  void onDisconnectComponentQt();
371 
372  signals:
373  void connectComponent();
374  void disconnectComponent();
375 
376 
377  // ArmarXWidgetController interface
378  public:
379  void postDocking() override;
380  };
381 }
382 
gui::SceneEditorMainWindowController
Definition: SceneEditorMainWindowController.h:204
GroupExplorerDialog.h
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
gui::SceneEditorMainWindowController::GetWidgetName
static QString GetWidgetName()
Reimplemented armarx::Component:getWidgetName().
Definition: SceneEditorMainWindowController.h:252
LoadSnapshotDialog.h
ArmarXGuiPlugin.h
SceneEditorConfigDialog.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
filename
std::string filename
Definition: VisualizationRobot.cpp:84
ShortcutController.h
SaveSnapshotDialog.h
SceneEditorMainWindow.h
ShortcutDialog.h
control
This file is part of ArmarX.
ImportExportComponent.h