window.h 11.1 KB
Newer Older
1 2 3 4 5 6 7 8
#ifndef _WINDOW_H_
#define _WINDOW_H_

#include "ui_window.h"

#include <QVBoxLayout>

#include "types.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
9 10
#include "system.h"
#include "splitArea.h"
11

12
class Plugin;
13 14 15
class Scene;
class View;
class Camera;
16
//class Context;
17 18 19 20 21 22 23 24
class MapHandler;

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

public:
	/**
25
	 * \fn Window(QWidget* parent = NULL)
26 27 28 29
	 * \brief Default (and unique) constructor
	 *
	 * \param parent the parent of the window
	 */
30 31
	Window(QWidget* parent = NULL);

32 33 34 35 36 37
	/**
	 * \fn ~Window()
	 * \brief the class destructor
	 */
	~Window();

38 39
	QGLContext* getContext() { return m_context; }

Pierre Kraemer's avatar
Pierre Kraemer committed
40 41 42
	/*********************************************************
	 * MANAGE DOCK
	 *********************************************************/
43 44 45 46 47 48 49

	/**
	 * \fn QTabWidget* getDockTabWidget()
	 * \brief Accessor to the QTabWidget of this interface
	 *
	 * \return a pointer to the TabWidget, NULL if not allocated yet
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
50
	QTabWidget* getDockTabWidget();
51 52

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

	/**
	 * \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.
	 *
	 * \see addWidgetInDockTab()
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74 75 76 77
	void removeTabInDock(QWidget* tabWidget);

	/*********************************************************
	 * MANAGE MENU ACTIONS
	 *********************************************************/
78 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 138 139 140
	void removeToolbarAction(QAction* action);

	/*********************************************************
	 * MANAGE PLUGINS
	 *********************************************************/
141 142 143 144 145 146 147 148

	/**
	 * \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
149
	 * where the extension ('.so', '.dylib') and the prefix 'lib' were removed.
150 151 152 153 154 155
	 *
	 *  <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
156 157
	 * 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.
158
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
159
	 * \warning In the program this method is called under specific and controlled circumstances, you should probably not call it.
160
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
161
	 * \return a boolean whether the loading succeeded or not.
162 163
	 *
	 * If the function failed, the error code ( Error::code ) is affected with a value
Pierre Kraemer's avatar
Pierre Kraemer committed
164
	 * depending on the error. This error can be shown with Error::showError
165 166
	 *
	 * \see unloadPlugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
167 168 169
	 * \see getPlugins()
	 * \see Plugin::enable()
	 */
170
	Plugin* loadPlugin(const QString& pluginPath);
171 172 173 174 175 176 177

	/**
	 * \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
178
	 * The Plugin of the given name is dereferenced and deleted, if it exists and was previously
179 180
	 * referenced, if not, the method does nothing.
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
181 182
	 * 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.
183 184 185 186
	 *
	 * \warning In the program this method is called under specific and controlled circumstances, you should probably not call it.
	 *
	 * \see loadPlugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
187
	 * \see getPlugins()
188 189
	 * \see Plugin::disable()
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
190
	void unloadPlugin(const QString& pluginName);
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

	/**
	 * \fn Plugin* checkPluginDependencie(QString name, Plugin* dependantPlugin)
	 * \brief checks for a dependencie Plugin, and set the dependencie link for the found Plugin
	 *
	 * \param name the name of the Plugin you have to check the existence in order to make a dependencie
	 * \param dependantPlugin a reference to the Plugin that asks for the dependencie that will be set as a
	 *          dependant Plugin for the found Plugin
	 *
	 * \warning In the program this method is called under specific and controlled circumstances
	 *          by the Plugins you should probably not call it.
	 *
	 * \return a pointer to the found dependencie Plugin, NULL if this Plugin wasn't referenced
	 *
	 * If the function failed, the error code ( Error::code ) is affected with a value
	     depending on the error. This error can be shown with Error::showError
	 *
	 * \see loadPlugin()
	 * \see VisualPlugin::addDependencie()
Pierre Kraemer's avatar
Pierre Kraemer committed
210 211 212
	 */
//	Plugin *checkPluginDependencie(QString name, Plugin *dependantPlugin);

213 214 215
	Plugin* getPlugin(const QString& name);

	QList<Plugin*> getPlugins() { return h_plugins.values(); }
216

Pierre Kraemer's avatar
Pierre Kraemer committed
217 218 219
	/*********************************************************
	 * MANAGE SCENES
	 *********************************************************/
220

221 222 223 224
	Scene* addScene(const QString& name);
	void removeScene(const QString& name);
	Scene* getScene(const QString& name);
	QList<Scene*> getScenes() { return h_scenes.values(); }
Pierre Kraemer's avatar
Pierre Kraemer committed
225

226 227
//	bool addNewEmptyScene(QString name, Scene *&scene, bool dialog, Camera *sharedCamera = NULL);
//	bool addNewSceneView(Scene *scene, View *view);
Pierre Kraemer's avatar
Pierre Kraemer committed
228

229
//	bool associateSceneWithPlugin(QString glviewer, Plugin *plugin, Scene *&scene, bool cb_initGL = false);
Pierre Kraemer's avatar
Pierre Kraemer committed
230

231 232
//	bool addNewSceneFromPlugin(QString name, Plugin *plugin, Scene *&scene);
//	bool addNewSceneFromPluginDialog(QString name, Plugin *plugin, Scene *&scene);
Pierre Kraemer's avatar
Pierre Kraemer committed
233

234 235
//	void linkDialog(Scene *scene);
//	void unlinkDialog(Scene *scene, QList<Plugin *> dependingPlugins);
236

Pierre Kraemer's avatar
Pierre Kraemer committed
237
	/*********************************************************
238
	 * MANAGE VIEWS
Pierre Kraemer's avatar
Pierre Kraemer committed
239 240
	 *********************************************************/

241 242 243 244 245
	View* addView(const QString& name);
	void removeView(const QString& name);
	View* getView(const QString& name);
	QList<View*> getView() { return h_views.values(); }

Pierre Kraemer's avatar
Pierre Kraemer committed
246 247 248 249
	/*********************************************************
	 * MANAGE CAMERAS
	 *********************************************************/

250 251 252
	Camera* addCamera(const QString& name);
	void removeCamera(const QString& name);
	Camera* getCamera(const QString& name);
Pierre Kraemer's avatar
Pierre Kraemer committed
253
	QList<Camera*> getCameras() { return h_cameras.values(); }
Pierre Kraemer's avatar
Pierre Kraemer committed
254

255 256 257
	/*********************************************************
	 * MANAGE MAPS
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
258

259 260 261 262
	bool addMap(const QString& name, MapHandler* map);
	void removeMap(const QString& name);
	MapHandler* getMap(const QString& name);
	QList<MapHandler*> getMaps() { return h_maps.values(); }
Pierre Kraemer's avatar
Pierre Kraemer committed
263

264 265 266 267 268 269 270 271 272 273 274 275 276
//	template<typename T>
//	T* getReferencedMap(QString map_name){
//		MapHash::iterator it;
//		if((it=h_map.find(map_name))!=h_map.end()){
//			return ((T*)(*it));
//		}
//		else{
//			System::Error::code= System::Error::MAP_UNREFERENCED_f(map_name);
//			return NULL;
//		}
//	}

protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
277
	bool m_initialization;
278

Pierre Kraemer's avatar
Pierre Kraemer committed
279 280
	QVBoxLayout* m_verticalLayout;
	SplitArea* m_splitArea;
281

282
	QGLContext* m_context;
283

Pierre Kraemer's avatar
Pierre Kraemer committed
284 285
	QDockWidget* m_dock;
	QTabWidget* m_dockTabWidget;
286

Pierre Kraemer's avatar
Pierre Kraemer committed
287
	PluginHash h_plugins;
288 289
	SceneHash h_scenes;
	ViewHash h_views;
Pierre Kraemer's avatar
Pierre Kraemer committed
290
	CameraHash h_cameras;
291
	MapHash h_maps;
292 293 294 295 296 297 298 299 300 301 302 303 304

	/**
	 * \var bool keys[3]
	 * \brief a static tab to store state of some keys (here: M, Shift and CTRL)
	 */
	bool keys[3];
	void keyPressEvent(QKeyEvent *event);
	void keyReleaseEvent(QKeyEvent *event);

	/**
	 * \fn void moveView()
	 * \brief shows a reordering dialog for the Views
	 *
305
	 * Make a call with the right parameters to the dialog class
306 307 308 309 310 311 312 313
	 * GLVSelector and show this dialog.
	 *
	 * This method is meant to be called when the user press
	 * CTRL+Shift+M.
	 */
	void moveView();

public slots:
314 315 316 317 318 319
	/**
	 * \fn void cb_about_SCHNApps();
	 * \brief function that is called when the "about SCHNApps" menu action is triggered
	 */
	void cb_aboutSCHNApps();

320 321 322 323
	/**
	 * \fn void cb_about_CGoGN();
	 * \brief function that is called when the "about CGOGN" menu action is triggered
	 */
324 325
	void cb_aboutCGoGN();

326
	/**
327 328 329
	 * \fn void cb_managePlugins()
	 * \brief method called when the "Plugins" action is triggered.
	 * Show the plugins management dialog
330
	 */
331
	void cb_managePlugins();
332 333

	/**
334 335 336
	 * \fn void cb_manageScenes()
	 * \brief method called when the "Scenes" action is triggered.
	 * Show the scenes management dialog:
337
	 */
338
	void cb_manageScenes();
339

340 341 342 343 344 345
	/**
	 * \fn void cb_manageCameras()
	 * \brief method called when the "Cameras" action is triggered.
	 * Show the cameras management dialog:
	 */
	void cb_manageCameras();
346

347 348 349 350 351 352
	/**
	 * \fn void cb_manageMaps()
	 * \brief method called when the "Maps" action is triggered.
	 * Show the maps management dialog:
	 */
	void cb_manageMaps();
353 354 355
};

#endif