window.h 9.93 KB
Newer Older
1
2
3
4
5
#ifndef _WINDOW_H_
#define _WINDOW_H_

#include "ui_window.h"

6
#include "types.h"
7
8
#include "PythonQt/PythonQt.h"
#include "PythonQt/gui/PythonQtScriptingConsole.h"
9

Pierre Kraemer's avatar
Pierre Kraemer committed
10
11
12
class QVBoxLayout;
class QSplitter;

Pierre Kraemer's avatar
Pierre Kraemer committed
13
14
15
16
17
18
namespace CGoGN
{

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
19
20
21
22
class CamerasDialog;
class PluginsDialog;
class MapsDialog;

Pierre Kraemer's avatar
Pierre Kraemer committed
23
struct Texture;
24
25
26
27
28
29
30

class Window : public QMainWindow, Ui::Window
{
	Q_OBJECT

public:
	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
31
32
	 * \fn Window()
	 * \brief Constructor
33
	 */
34
	Window(const QString& appPath, PythonQtObjectPtr& pythonContext, PythonQtScriptingConsole& pythonConsole);
35

36
37
	/**
	 * \fn ~Window()
Pierre Kraemer's avatar
Pierre Kraemer committed
38
	 * \brief Destructor
39
40
41
	 */
	~Window();

42
43
	const QString& getAppPath() { return m_appPath; }

Pierre Kraemer's avatar
Pierre Kraemer committed
44
45
46
	/*********************************************************
	 * MANAGE DOCK
	 *********************************************************/
47

48
	QTabWidget* getDockTabWidget() const { return m_dockTabWidget; }
49
50

	/**
51
	 * \fn void addTabInDock(QWidget* tabWidget, const QString& tabText, bool enable)
52
53
	 * \brief Adds the widget as a new tab in the interface's dock
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
54
	 * \param tabWidget the created and allocated pointer to the QWidget to add in the dock
55
	 * \param tabText The text that will appears in the tab label
56
	 * \param enable is the new tab enabled ?
57
	 */
58
	void addTabInDock(QWidget* tabWidget, const QString& tabText, bool enable);
59
60
61
62
63
64
65
66
67

	/**
	 * \fn void removeTabInDock(QWidget* tabWidget)
	 * \brief removes a given widget from the tab
	 *
	 * \param tabWidget the reference to the widget you want to remove
	 *
	 * If the widget does belong to the tab, it will be destroyed.
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
68
69
	void removeTabInDock(QWidget* tabWidget);

70
public slots:
71
72
73
	void enablePluginTabWidgets(Plugin* plugin);
	void disablePluginTabWidgets(Plugin* plugin);

Pierre Kraemer's avatar
Pierre Kraemer committed
74
75
76
	/*********************************************************
	 * MANAGE MENU ACTIONS
	 *********************************************************/
77

78
public:
79
	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
80
	 * \fn bool addMenuAction(const QString& menuPath, QAction* action)
81
82
83
	 * \brief adds an action in the program menu bar
	 *
	 * \param menuPath the menu path (see details below) to specify a location for the action in the menu.
Pierre Kraemer's avatar
Pierre Kraemer committed
84
	 * \param action a pointer to the allocated action to add in the menu. All the details on that action (such as
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	 *          QObject::connect() calls) are not dealt in this function.
	 *
	 *  The menu path is a string used to specify the location of the new action in the menu bar.
	 *  In such path every menu step of the path should be separate by ';'. The action is the last substring after
	 *  the last ';', and will be added in the menu with that name. All non-existing menu specified in the path
	 *  shall be created.
	 *
	 *  <b>Example 1:</b> if you want to add an entry <em>"action"</em> to the existing menu <em>"Plugins"</em> the
	 *                  menu path shall be: <em>Plugins;action</em>
	 *
	 *  <b>Example 2:</b> if you want to add an entry <em>"action"</em> in a new menu <em>"config"</em> that is also a
	 *                  submenu of a new menu <em>"Settings"</em>, the menu path
	 *                  shall be: <em>Settings;config;action</em>
	 *
	 *  A new action should at least belong to one menu (already existing or not). Otherwise the method will fail.
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
101
	 *  This method is called by Plugin methods
102
103
104
105
	 *
	 *  \return a boolean whether the method succeeded or not.
	 *
	 * If the function failed, the error code ( Error::code ) is affected with a value
Pierre Kraemer's avatar
Pierre Kraemer committed
106
	 *    depending on the error. This error can be shown with Error::showError
107
108
	 *
	 * \see deleteMenuAction()
Pierre Kraemer's avatar
Pierre Kraemer committed
109
	 * \see Plugin::addMenuAction()
110
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
111
	bool addMenuAction(const QString& menuPath, QAction* action);
112
113

	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
114
	 * \fn void deleteMenuAction(QAction* action)
115
116
	 * \brief delete an action from the menu bar
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
117
	 * \param action pointer to the allocated action to delete.
118
119
120
121
122
	 *
	 *  If this action was the only action remaining in a menu, this menu will also be deleted.
	 *
	 *  \warning DO NOT use this method with an action that hasn't been added with addMenuAction()
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
123
	 *  This method is called by Plugin methods
124
125
	 *
	 *  \see addMenuAction()
Pierre Kraemer's avatar
Pierre Kraemer committed
126
	 *  \see Plugin::removeMenuAction()
127
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
128
129
130
131
132
133
134
	void removeMenuAction(QAction* action);

	/*********************************************************
	 * MANAGE TOOLBAR ACTIONS
	 *********************************************************/

	bool addToolbarAction(QAction* action);
135

Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
	void removeToolbarAction(QAction* action);

138
139
140
141
142
143
144
	/*********************************************************
	 * MANAGE CAMERAS
	 *********************************************************/

	Camera* addCamera(const QString& name);
	Camera* addCamera();
	void removeCamera(const QString& name);
145
146
147
	Camera* getCamera(const QString& name) const;
	QList<Camera*> getCamerasList() const { return h_cameras.values(); }
	const CameraHash& getCamerasHash() const { return h_cameras; }
148
149
150
151
152
153
154
155

	/*********************************************************
	 * MANAGE VIEWS
	 *********************************************************/

	View* addView(const QString& name);
	View* addView();
	void removeView(const QString& name);
156
157

public slots:
158
	View* getView(const QString& name) const;
159
160

public:
161
162
163
164
165
166
	QList<View*> getViewsList() const { return h_views.values(); }
	const ViewHash& getViewsHash() const { return h_views; }

	View* getCurrentView() const { return m_currentView; }
	void setCurrentView(View* view);

Pierre Kraemer's avatar
Pierre Kraemer committed
167
	void splitView(const QString& name, Qt::Orientation orientation);
168

Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
	/*********************************************************
	 * MANAGE PLUGINS
	 *********************************************************/
172

173
public slots:
174
175
	void registerPluginsDirectory(const QString& path);

176
177
178
179
180
181
182
	/**
	 * \fn bool loadPlugin(QString pluginPath)
	 * \brief Loads and references a Plugin
	 *
	 * \param pluginPath the absolute path of the Plugin location
	 *
	 * The Plugin is loaded and referenced under a name that is the Plugin file name
Pierre Kraemer's avatar
Pierre Kraemer committed
183
	 * where the extension ('.so', '.dylib') and the prefix 'lib' were removed.
184
185
186
187
188
189
	 *
	 *  <b>Example:</b> <em>/path/libExample.so</em> will be referenced as <em>Example</em>
	 *
	 * You have to make sure that a Plugin file with a similar name hasn't been loaded yet, otherwise
	 * the loading will fail.
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
190
191
	 * This method calls the Plugin::enable() method of the concerned Plugin. That is why
	 * when Plugin are written, this method is overriden and used as an initialization method.
192
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
193
194
	 * \return a boolean whether the loading succeeded or not.
	 */
195
	Plugin* loadPlugin(const QString& pluginFilePath);
196
197
198
199
200
201
202

	/**
	 * \fn void unloadPlugin(QString pluginName)
	 * \brief Unload the Plugin of a given name
	 *
	 * \param pluginName the name under which the Plugin is referenced
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
203
	 * The Plugin of the given name is dereferenced and deleted, if it exists and was previously
204
205
	 * referenced, if not, the method does nothing.
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
206
207
	 * This method calls the Plugin::disable() method of the concerned Plugin. That is why,
	 * when Plugin are written, this method is overriden and used as a destruction method.
208
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
209
	void unloadPlugin(const QString& pluginName);
210

211
public:
212
213
214
	Plugin* getPlugin(const QString& name) const;
	QList<Plugin*> getPluginsList() const { return h_plugins.values(); }
	const PluginHash& getPluginsHash() const { return h_plugins; }
215

216
217
	const QMap<QString, QString>& getAvailablePlugins() const { return m_availablePlugins; }

218
219
220
	/*********************************************************
	 * MANAGE MAPS
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
221

Pierre Kraemer's avatar
Pierre Kraemer committed
222
	MapHandlerGen* addMap(const QString& name, unsigned int dim);
223
	void removeMap(const QString& name);
224
225
226
	MapHandlerGen* getMap(const QString& name) const;
	QList<MapHandlerGen*> getMapsList() const { return h_maps.values(); }
	const MapHash& getMapsHash() const { return h_maps; }
Pierre Kraemer's avatar
Pierre Kraemer committed
227

228
229
230
231
232
	/*********************************************************
	 * MANAGE LINKS
	 *********************************************************/

public slots:
233
	void linkViewAndCamera(View* v, Camera* c);
234
	void linkViewAndCamera(const QString& viewName, const QString& cameraName);
235
236

	void linkViewAndMap(View* v, MapHandlerGen* m);
237
	void linkViewAndMap(const QString& viewName, const QString& mapName);
238
	void unlinkViewAndMap(View* v, MapHandlerGen* m);
239
	void unlinkViewAndMap(const QString& viewName, const QString& mapName);
240

241
	void linkViewAndPlugin(View* v, Plugin* p);
242
	void linkViewAndPlugin(const QString& viewName, const QString& pluginName);
243
	void unlinkViewAndPlugin(View* v, Plugin* p);
244
	void unlinkViewAndPlugin(const QString& viewName, const QString& pluginName);
245

246
247
248
249
	/*********************************************************
	 * MANAGE TEXTURES
	 *********************************************************/

250
public:
251
252
	Texture* getTexture(const QString& image);
	void releaseTexture(const QString& image);
253
254

protected:
255
	QString m_appPath;
Pierre Kraemer's avatar
Pierre Kraemer committed
256
	PythonQtObjectPtr& m_pythonContext;
257
	PythonQtScriptingConsole& m_pythonConsole;
258

Pierre Kraemer's avatar
Pierre Kraemer committed
259
260
261
	QVBoxLayout* m_centralLayout;
	QSplitter* m_rootSplitter;
	bool b_rootSplitterInitialized;
262

263
	View* m_firstView;
264
	View* m_currentView;
265

Pierre Kraemer's avatar
Pierre Kraemer committed
266
267
	QDockWidget* m_dock;
	QTabWidget* m_dockTabWidget;
268

269
270
	QDockWidget* m_pythonDock;

271
272
	QMap<QString, QString> m_availablePlugins;

Pierre Kraemer's avatar
Pierre Kraemer committed
273
	PluginHash h_plugins;
274
	ViewHash h_views;
Pierre Kraemer's avatar
Pierre Kraemer committed
275
	CameraHash h_cameras;
276
	MapHash h_maps;
277

278
279
	TextureHash h_textures;

Pierre Kraemer's avatar
Pierre Kraemer committed
280
281
282
	CamerasDialog* m_camerasDialog;
	PluginsDialog* m_pluginsDialog;
	MapsDialog* m_mapsDialog;
283
284

public slots:
285
286
	void cb_aboutSCHNApps();
	void cb_aboutCGoGN();
287
288
	
	void cb_showHideDock();
289
290
	void cb_showHidePythonDock();

291
292
	void cb_manageCameras();
	void cb_managePlugins();
293
294
	void cb_manageMaps();

295
296
297
298
299
300
signals:
	void cameraAdded(Camera* camera);
	void cameraRemoved(Camera* camera);

	void viewAdded(View* view);
	void viewRemoved(View* view);
301
	void currentViewChanged(View* view);
302

303
304
	void mapAdded(MapHandlerGen* map);
	void mapRemoved(MapHandlerGen* map);
305

306
307
	void pluginLoaded(Plugin* plugin);
	void pluginUnloaded(Plugin* plugin);
308
309
310
311
312
313
314
315
316

	void viewAndCameraLinked(View* view, Camera* camera);
	void viewAndCameraUnlinked(View* view, Camera* camera);

	void viewAndMapLinked(View* view, MapHandlerGen* map);
	void viewAndMapUnlinked(View* view, MapHandlerGen* map);

	void viewAndPluginLinked(View* view, Plugin* plugin);
	void viewAndPluginUnlinked(View* view, Plugin* plugin);
317
318
};

Pierre Kraemer's avatar
Pierre Kraemer committed
319
320
321
322
} // namespace SCHNApps

} // namespace CGoGN

323
#endif