ArmarXMainWindow.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-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
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <QAction>
27 #include <QDir>
28 #include <QDockWidget>
29 #include <QMainWindow>
30 #include <QPluginLoader>
31 #include <QSplashScreen>
32 
36 
42 
43 #include <Inventor/nodes/SoNode.h>
44 #include <Inventor/nodes/SoSeparator.h>
45 
46 class QToolButton;
47 class QLabel;
48 class QScrollArea;
49 class QSignalMapper;
50 class QListWidgetItem;
51 class QActionGroup;
52 class QLineEdit;
53 
54 namespace Ui
55 {
56  class ArmarXMainWindow;
57 }
58 
59 // project
60 namespace armarx
61 {
62  class GuiUseCaseSelector;
63  class AddArmarXWidgetAction;
64 
65  class ArmarXDockWidget;
66 
67  struct Viewer3DInfo
68  {
69  SoNode* node;
70  QPointer<QDialog> sceneConfigDialog;
71  };
72 
73  /**
74  * \brief The ArmarXMainWindow class
75  */
76  class ArmarXMainWindow : public QMainWindow, virtual public armarx::Logging
77  {
78  Q_OBJECT
79 
80  public:
82  const std::vector<std::string>& packages,
83  const QString& configToLoad,
84  bool disablePreloading);
85  ~ArmarXMainWindow() override;
86 
87  /**
88  * loads a plugin with the given file path
89  */
90  void loadPlugin(QString filePath);
91 
92  /**
93  * emits the closeRequest signal
94  */
95  void closeEvent(QCloseEvent* event) override;
96 
98  void addToRecentlyOpenedFileList(QString configFilepath);
99 
100  /**
101  * @brief getDefaultPackageNames returns the names of all packages which are searched for plugins when the ArmarXGuiApp is started.
102  * @return vector of strings containing the names of the default packages
103  */
104  std::vector<std::string> getDefaultPackageNames();
105 
106  /**
107  * Provides access to a viewer widget, if existent
108  */
110 
111  /*!
112  * \brief Provides access to the coin3d mutex. Use this mutex to protect access to the 3d scene.
113  * \return
114  */
115  std::shared_ptr<std::recursive_mutex> getMutex3D();
116 
117  bool existsWidget(const QString& widgetName);
118  QString getLibraryPathFromPackage(const QString& packageName);
119 
120  QStringList getFavoriteWidgets();
121 
122  public slots:
123  void loadPluginsFromPackage(const QString& packageName);
124  void loadGuiConfig(QString configFilepath = "", bool showAsOpenGuiConfig = true);
125  void appendFileToWindowTitle(const QString& filepath = "");
126 
127  signals:
128  /**
129  * emitted, when the main window should be closed
130  */
131  void closeRequest();
132 
133 
134  void updateSceneList(QMap<QString, Viewer3DInfo>);
135  private slots:
136  void closeAllWidgets();
137  void closeAllWidgetsWithDialog();
138  void saveGuiConfig();
139  void saveGuiConfigAs();
140  void updateStatusOfOpenWidgets();
141  void enterFullscreenMode();
142  void leaveFullscreenMode();
143  void toggleWidgetLock();
144 
145 
146  /**
147  * shows a file dialog for loading a gui plugin
148  */
149  void pluginDialog();
150 
151 
152  // void listIndexes(const QModelIndexList & indexes);
153  ArmarXWidgetControllerPtr createArmarXWidget(QString widgetName,
154  QString customInstanceName,
155  QSettings* settings = NULL);
156  ArmarXWidgetControllerPtr addArmarXWidget(ArmarXWidgetControllerPtr newWidgetController,
157  bool createViewerWidget = true);
158  void addArmarXWidgetCanceled(ArmarXWidgetControllerPtr newWidgetController);
159  void removeArmarXWidget(QObject* widget);
160  void removeViewerWidget(QObject* widget);
161 
162  void on_actionClear_tip_blacklist_triggered();
163 
164  void on_actionAbout_triggered();
165 
166  void on_actionLoadLastConfig_toggled(bool toggled);
167 
168  void on_actionArmarX_Documentation_triggered();
169 
170  void on_actionOpen_Use_Case_triggered();
171 
172  void on_actionClear_plugin_cache_triggered();
173 
174  void updateOpenWidgetButtonStatus(QString widgetName);
175 
176  void openWidgetButtonClicked();
177 
178  void onContextMenuFavoritesRequested(const QPoint& pos);
179  void onNumberOfMaxFavoritesChanged(int i);
180 
181  void updatefavoriteActions();
182 
183  private:
184  /**
185  * @brief updates the menu entry with the available widgets.
186  */
187  void updateAvailableWidgetList();
188  void updateOpenWidgetList();
189 
190  /**
191  * Add the (optional) icon button to start ArViz Godot to the main widgets if ArViz Godot is available.
192  */
193  void addArVizGodotIcon();
194 
195  /**
196  * sets a SoQtExamine rViewer up. This ExaminerViewer is contained by the class member QWidget* view
197  */
198  Viewer3DWidgetPtr setupViewerWidget();
199 
200  /**
201  * loads all gui plugins in home/armarx recursively
202  */
203  void loadPlugins(const QString& pluginDir, bool searchRecursive = true);
204 
205 
206  void loadPlugins(const QSet<QString>& pluginDirs, bool searchRecursive = true);
207  void loadPlugins(const QStringList& fileNames);
208 
209  QAction* addActionToToolBar(QAction* action, bool allowText);
210 
211  PluginCache pluginCache;
212  QDir pluginsDir;
213  QStringList loadedPackages;
214  std::vector<QPluginLoader*> pluginsToLoad;
215  QList<QDir> directoriesToCheck;
216 
217  ::Ui::ArmarXMainWindow* ui;
218 
220 
221  std::vector<ArmarXGuiInterface*> plugins;
222  QStringList loadedPluginFilepaths;
223 
224  QList<QWidget*> widgetsList;
225  // WidgetCreatorMap availableWidgets;
226 
227  QMap<QString, Viewer3DInfo> viewer3DMap;
228 
229  QSignalMapper* signalMapper;
230  QActionGroup* layoutActions;
231  using OpenWidgetMap = QMap<QString, QPair<QDockWidget*, ArmarXWidgetControllerPtr>>;
232  OpenWidgetMap listOpenWidgets;
233  std::vector<ArmarXWidgetControllerPtr> pendingWidgets;
234  QListWidgetItem* viewerItem;
235 
236  QPointer<TipDialog> tipDialog;
237  const int widgetUsageHistoryLength = 100;
238 
239 
240  std::vector<std::string> defaultPackageNames;
241 
242 
243  // Emergency Stop
244  EmergencyStopWidgetPtr emergencyStopWidget;
245  BatteryWidgetPtr batteryWidget;
246 
247  QAction* leaveFullScreenActionF11;
248  QAction* leaveFullScreenActionEsc;
249 
250  bool widgetsLocked;
251 
252  private:
253  QPointer<QDockWidget> getBiggestOpenWidget();
254  QMenu* getCategoryMenu(const std::string& categoryString, QMenu* menu, QIcon widgetIcon);
255  const std::string settingsFile;
256  QSettings mainSettings;
257  QString configFilepath;
258  QString guiWindowBaseName;
259  QTimer* connectionStatusTimer;
260  QSplashScreen* splashSceen;
261  QString splashscreenPrefix;
262  GuiUseCaseSelector* guiUseCaseSelector;
263  QStringList mainWidgetNames;
264  QToolButton* openWidgetButton;
265  QLineEdit* searchField;
266  AddArmarXWidgetAction* addWidgetAction;
267  std::shared_ptr<std::recursive_mutex> mutex3d;
268  QMap<QString, QAction*> actionList;
269 
270  QLabel* favoritesLabel;
271  std::vector<QAction*> favoriteActions;
272  QStringList favoriteActionWidgetNames;
273 
274  friend class WidgetNameDialog;
275  friend class Viewer3DWidget;
276  };
277 
278  /////////////////////////////////////////////////////////////////////////
279  //// Additional Helper Classes
280  /////////////////////////////////////////////////////////////////////////
281 
282  class WidgetNameDialog;
283 
284  /**
285  * \brief The ArmarXDockWidget class
286  */
287  class ArmarXDockWidget : public QDockWidget
288  {
289  public:
291  ~ArmarXDockWidget() override;
292  void setArmarXWidget(QWidget* widget);
293  void closeEvent(QCloseEvent* event) override;
294 
295  void lockWidget();
296  void unlockWidget();
297 
298  private:
300  QScrollArea* scrollArea;
301 
302  QWidget* savedTitleBar;
303  };
304 
305  class AddArmarXWidgetAction : public QAction
306  {
307  Q_OBJECT
308  public:
309  AddArmarXWidgetAction(QString widgetName,
310  QObject* parent = 0,
311  ArmarXMainWindow* mainGui = 0);
312  ~AddArmarXWidgetAction() override;
313 
314  public slots:
315  void triggered(QString widgetName = QString());
316  void addArmarXWidget();
317  void dialogAccepted();
318  signals:
319  void clicked(QString widgetName, QString customInstanceName);
320  void accepted();
321 
322  private:
323  ArmarXMainWindow* mainGui;
324  WidgetNameDialog* dialog;
325  };
326 
327  class OpenRecentlyOpenedFileAction : public QAction
328  {
329  Q_OBJECT
330  public:
331  OpenRecentlyOpenedFileAction(QString text,
332  QObject* parent = 0,
333  ArmarXMainWindow* mainGui = 0);
334  public slots:
335  void openFile();
336 
337  private:
338  ArmarXMainWindow* mainGui;
339  };
340 
341 
342 } // namespace armarx
armarx::Viewer3DInfo::sceneConfigDialog
QPointer< QDialog > sceneConfigDialog
Definition: ArmarXMainWindow.h:70
armarx::AddArmarXWidgetAction::triggered
void triggered(QString widgetName=QString())
Definition: ArmarXMainWindow.cpp:1617
armarx::ArmarXDockWidget::lockWidget
void lockWidget()
Definition: ArmarXMainWindow.cpp:1705
armarx::ArmarXMainWindow::getFavoriteWidgets
QStringList getFavoriteWidgets()
Definition: ArmarXMainWindow.cpp:400
armarx::ArmarXMainWindow::closeEvent
void closeEvent(QCloseEvent *event) override
emits the closeRequest signal
Definition: ArmarXMainWindow.cpp:547
armarx::ArmarXMainWindow::~ArmarXMainWindow
~ArmarXMainWindow() override
Definition: ArmarXMainWindow.cpp:261
armarx::ArmarXMainWindow
The ArmarXMainWindow class.
Definition: ArmarXMainWindow.h:76
armarx::Viewer3DWidget
The Viewer3DWidget class.
Definition: ViewerWidget.h:55
armarx::ArmarXMainWindow::updateRecentlyOpenedFileList
void updateRecentlyOpenedFileList()
Definition: ArmarXMainWindow.cpp:1478
RunningTask.h
armarx::AddArmarXWidgetAction::~AddArmarXWidgetAction
~AddArmarXWidgetAction() override
Definition: ArmarXMainWindow.cpp:1611
armarx::ArmarXMainWindow::appendFileToWindowTitle
void appendFileToWindowTitle(const QString &filepath="")
Definition: ArmarXMainWindow.cpp:878
plugins
EmergencyStopWidget.h
armarx::ArmarXMainWindow::loadPlugin
void loadPlugin(QString filePath)
loads a plugin with the given file path
Definition: ArmarXMainWindow.cpp:526
armarx::ArmarXMainWindow::addToRecentlyOpenedFileList
void addToRecentlyOpenedFileList(QString configFilepath)
Definition: ArmarXMainWindow.cpp:604
IceInternal::Handle< EmergencyStopWidget >
ArmarXGuiPlugin.h
armarx::ArmarXMainWindow::updateSceneList
void updateSceneList(QMap< QString, Viewer3DInfo >)
armarx::ArmarXDockWidget::ArmarXDockWidget
ArmarXDockWidget(QString name, ArmarXWidgetControllerPtr controller)
Definition: ArmarXMainWindow.cpp:1661
armarx::ArmarXMainWindow::existsWidget
bool existsWidget(const QString &widgetName)
Definition: ArmarXMainWindow.cpp:519
controller
Definition: AddOperation.h:39
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::ArmarXMainWindow::getMutex3D
std::shared_ptr< std::recursive_mutex > getMutex3D()
Provides access to the coin3d mutex. Use this mutex to protect access to the 3d scene.
BatteryWidget.h
armarx::ArmarXMainWindow::getLibraryPathFromPackage
QString getLibraryPathFromPackage(const QString &packageName)
Definition: ArmarXMainWindow.cpp:389
armarx::ArmarXMainWindow::getViewerWidget
Viewer3DWidgetPtr getViewerWidget()
Provides access to a viewer widget, if existent.
Definition: ArmarXMainWindow.cpp:629
armarx::WidgetNameDialog
The WidgetNameDialog class.
Definition: WidgetNameDialog.h:42
armarx::ArmarXMainWindow::getDefaultPackageNames
std::vector< std::string > getDefaultPackageNames()
getDefaultPackageNames returns the names of all packages which are searched for plugins when the Arma...
Definition: ArmarXMainWindow.cpp:623
ViewerWidget.h
armarx::ArmarXDockWidget::setArmarXWidget
void setArmarXWidget(QWidget *widget)
Definition: ArmarXMainWindow.cpp:1681
armarx::ArmarXMainWindow::loadGuiConfig
void loadGuiConfig(QString configFilepath="", bool showAsOpenGuiConfig=true)
Definition: ArmarXMainWindow.cpp:643
armarx::ArmarXDockWidget::unlockWidget
void unlockWidget()
Definition: ArmarXMainWindow.cpp:1717
armarx::OpenRecentlyOpenedFileAction
Definition: ArmarXMainWindow.h:327
armarx::AddArmarXWidgetAction::AddArmarXWidgetAction
AddArmarXWidgetAction(QString widgetName, QObject *parent=0, ArmarXMainWindow *mainGui=0)
Definition: ArmarXMainWindow.cpp:1602
armarx::ArmarXMainWindow::ArmarXMainWindow
ArmarXMainWindow(const armarx::ManagedIceObjectRegistryInterfacePtr &registry, const std::vector< std::string > &packages, const QString &configToLoad, bool disablePreloading)
Definition: ArmarXMainWindow.cpp:108
armarx::OpenRecentlyOpenedFileAction::OpenRecentlyOpenedFileAction
OpenRecentlyOpenedFileAction(QString text, QObject *parent=0, ArmarXMainWindow *mainGui=0)
Definition: ArmarXMainWindow.cpp:1736
armarx::AddArmarXWidgetAction::accepted
void accepted()
armarx::ArmarXMainWindow::closeRequest
void closeRequest()
emitted, when the main window should be closed
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
IceUtil::Handle< ManagedIceObjectRegistryInterface >
armarx::ArmarXDockWidget
The ArmarXDockWidget class.
Definition: ArmarXMainWindow.h:287
armarx::Viewer3DInfo::node
SoNode * node
Definition: ArmarXMainWindow.h:69
Logging.h
armarx::GuiUseCaseSelector
Definition: GuiUseCaseSelector.h:40
armarx::ArmarXMainWindow::loadPluginsFromPackage
void loadPluginsFromPackage(const QString &packageName)
Definition: ArmarXMainWindow.cpp:436
armarx::ArmarXDockWidget::~ArmarXDockWidget
~ArmarXDockWidget() override
Definition: ArmarXMainWindow.cpp:1674
armarx::AddArmarXWidgetAction
Definition: ArmarXMainWindow.h:305
armarx::AddArmarXWidgetAction::clicked
void clicked(QString widgetName, QString customInstanceName)
armarx::AddArmarXWidgetAction::addArmarXWidget
void addArmarXWidget()
Definition: ArmarXMainWindow.cpp:1638
armarx::OpenRecentlyOpenedFileAction::openFile
void openFile()
Definition: ArmarXMainWindow.cpp:1744
PluginCache.h
armarx::ArmarXDockWidget::closeEvent
void closeEvent(QCloseEvent *event) override
Definition: ArmarXMainWindow.cpp:1687
armarx::AddArmarXWidgetAction::dialogAccepted
void dialogAccepted()
Definition: ArmarXMainWindow.cpp:1655
armarx::Viewer3DInfo
Definition: ArmarXMainWindow.h:67
armarx::PluginCache
Definition: PluginCache.h:36
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
Application.h