GCC Code Coverage Report


Directory: ./
File: include/gepetto/gui/mainwindow.hh
Date: 2024-08-14 11:04:57
Exec Total Coverage
Lines: 0 4 0.0%
Branches: 0 2 0.0%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef GEPETTO_GUI_MAINWINDOW_HH
18 #define GEPETTO_GUI_MAINWINDOW_HH
19
20 #include <QCheckBox>
21 #include <QLabel>
22 #include <QList>
23 #include <QMainWindow>
24 #include <QStandardItemModel>
25 #include <gepetto/gui/dialog/dialogloadenvironment.hh>
26 #include <gepetto/gui/dialog/dialogloadrobot.hh>
27 #include <gepetto/gui/dialog/pluginmanagerdialog.hh>
28 #include <gepetto/gui/ledindicator.hh>
29 #include <gepetto/gui/settings.hh>
30
31 #include "gepetto/gui/fwd.hh"
32
33 namespace Ui {
34 class MainWindow;
35 }
36
37 namespace gepetto {
38 namespace gui {
39 /// Class
40 class MainWindow : public QMainWindow {
41 Q_OBJECT
42
43 public:
44 enum RefreshType {
45 RefreshBodyTree = 1,
46 RefreshPlugins = 2,
47 RefreshAll = RefreshBodyTree + RefreshPlugins
48 };
49
50 Settings* settings_;
51
52 explicit MainWindow(Settings* settings, QWidget* parent = 0);
53 ~MainWindow();
54
55 /// Return the instance of MainWindow stored
56 static MainWindow* instance();
57
58 /// Insert a dockwidget in the dock area of the window.
59 /// \param dock widget to add
60 /// \param area where the widget will be add
61 /// \param orientation of the widget
62 void insertDockWidget(QDockWidget* dock,
63 Qt::DockWidgetArea area = Qt::AllDockWidgetAreas,
64 Qt::Orientation orientation = Qt::Horizontal);
65
66 /// Remove a dock widget.
67 /// \param dock widget to remove
68 void removeDockWidget(QDockWidget* dock);
69
70 /// Get
71 WindowsManagerPtr_t osg() const;
72
73 SelectionHandler* selectionHandler() { return selectionHandler_; }
74
75 /// Get the list of windows.
76 QList<OSGWidget*> osgWindows() const;
77
78 /// Get the plugin manager.
79 PluginManager* pluginManager();
80
81 ActionSearchBar* actionSearchBar() const;
82
83 QMenu* pluginMenu() const;
84
85 #if GEPETTO_GUI_HAS_PYTHONQT
86 /// Get the python widget.
87 PythonWidget* pythonWidget() { return pythonWidget_; }
88 #endif
89
90 signals:
91 /// Triggered when an OSGWidget is created.
92 void viewCreated(OSGWidget* widget);
93 void refresh();
94 void applyCurrentConfiguration();
95 void configurationValidation();
96 void selectJointFromBodyName(const QString bodyName);
97
98 void logString(QString msg);
99 void logErrorString(QString msg);
100
101 public slots:
102 /// \ingroup plugin_python
103 /// \{
104
105 /// Get the body tree widget.
106 BodyTreeWidget* bodyTree() const;
107
108 /// Add the text to logs.
109 /// \param text text to log
110 void log(const QString& text);
111 /// Add the text to logs and colors it in red.
112 /// \param text text to log
113 void logError(const QString& text);
114
115 /// Log that a job has started.
116 /// \param id id of the job
117 /// \param text text to log
118 void logJobStarted(int id, const QString& text);
119
120 /// Log that a job has successfuly finished.
121 /// \param id id of the job
122 /// \param text text to log
123 void logJobDone(int id, const QString& text);
124
125 /// Log that a job has failed.
126 /// \param id id of the job
127 /// \param text text to log
128 void logJobFailed(int id, const QString& text);
129
130 /// Request a refresh of the interface.
131 /// \param refreshType tells what to refresh. See RefreshType
132 void requestRefresh();
133 /// Emit a signal to display the current configuration in the viewer.
134 void requestApplyCurrentConfiguration();
135
136 /// Emit a signal to check if the the current configuration is valid.
137 void requestConfigurationValidation();
138
139 /// Display if a configuration is valid or not.
140 /// \param valid configuration is valid
141 void configurationValidationStatusChanged(bool valid);
142
143 /// Display if a configuration is valid or not.
144 /// \param bodiesInCollision list of bodies in collision
145 void configurationValidationStatusChanged(QStringList bodiesInCollision);
146
147 /// Emit a signal to tell that a body has been selected.
148 /// \param bodyName name of the body selected
149 void requestSelectJointFromBodyName(const QString bodyName);
150
151 /// Open the plugin manager dialog.
152 void onOpenPluginManager();
153
154 /// Register an object signal that can be accessible without knowing the class
155 /// definition. \param signal signal's name \param obj object's instance
156 void registerSignal(const char* signal, QObject* obj);
157
158 /// Get the instance of object which holds the signal.
159 /// \param signal signal's name
160 /// \return object's instance
161 QObject* getFromSignal(const char* signal);
162
163 /// Connect an object's slot to a registered signal.
164 /// \param signal signal's name
165 /// \param slot slot's name
166 /// \param obj object's instance
167 void connectSignal(const char* signal, const char* slot, QObject* obj);
168
169 /// Register an object slot that can be accessible without knowing the class
170 /// definition. \param slot slot's name \param obj object's instance
171 void registerSlot(const char* slot, QObject* obj);
172
173 /// Get the instance of object which holds the slot.
174 /// \param slot slot's name
175 /// \return object's instance
176 QObject* getFromSlot(const char* slot);
177
178 /// Connect an object's signal to a registered slot.
179 /// \param slot slot's name
180 /// \param signal signal's name
181 /// \param obj object's instance
182 void connectSlot(const char* slot, const char* signal, QObject* obj);
183
184 /// Register an action on which users can change the shortcut to trigger it.
185 /// \param widgetName widget's name that handle the action
186 /// \param actionName action's name
187 /// \param action action to modify
188 void registerShortcut(QString widgetName, QString actionName,
189 QAction* action);
190
191 /// Register an action on which users can change the shortcut to trigger it.
192 /// User action->text() as action name.
193 /// \param widgetName widget's name that handle the action
194 /// \param action action to modify
195 void registerShortcut(QString widgetName, QAction* action);
196
197 /// \}
198
199 OSGWidget* createView(const std::string& name);
200
201 private slots:
202 void addOSGWidget(OSGWidget* osgWidget);
203 void createDefaultView();
204 void openLoadRobotDialog();
205 void openLoadEnvironmentDialog();
206 void activateCollision(bool activate);
207 void dockVisibilityChanged(bool visible);
208 void hsplitTabifiedDockWidget();
209 void vsplitTabifiedDockWidget();
210
211 void handleWorkerDone(int id);
212
213 void resetConnection();
214 void closeConnection();
215 void about();
216
217 private:
218 void splitTabifiedDockWidget(Qt::Orientation orientation);
219 void setupInterface();
220 void createCentralWidget();
221
222 static MainWindow* instance_;
223
224 ::Ui::MainWindow* ui_;
225 OSGWidget* centralWidget_;
226 QList<OSGWidget*> osgWindows_;
227 #if GEPETTO_GUI_HAS_PYTHONQT
228 PythonWidget* pythonWidget_;
229 #endif
230 ShortcutFactory* shortcutFactory_;
231 SelectionHandler* selectionHandler_;
232
233 WindowsManagerPtr_t osgViewerManagers_;
234 QThread worker_;
235
236 QCheckBox* collisionValidationActivated_;
237 LedIndicator* collisionIndicator_;
238 QLabel* collisionLabel_;
239
240 QStandardItemModel* bodyTreeModel_;
241
242 ActionSearchBar* actionSearchBar_;
243
244 QStringList robotNames_;
245 QStringList lastBodiesInCollision_;
246
247 std::map<std::string, QObject*> registeredSlots_;
248 std::map<std::string, QObject*> registeredSignals_;
249 };
250 } // namespace gui
251 } // namespace gepetto
252
253 Q_DECLARE_METATYPE(std::string)
254
255 #endif // GEPETTO_GUI_MAINWINDOW_HH
256