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

#include "ui_window.h"

#include <QVBoxLayout>

#include "Topology/generic/genericmap.h"

#include "types.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
11 12 13
#include "system.h"
#include "splitArea.h"
#include "mapHandler.h"
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

class Scene;
class View;
class Camera;
class Plugin;
class Context;
class MapHandler;

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

public:
	/**
	 * \fn Window(QWidget* parent=0)
	 * \brief Default (and unique) constructor
	 *
	 * \param parent the parent of the window
	 */
	Window(QWidget *parent = 0);
	/**
	 * \fn ~Window()
	 * \brief the class destructor
	 */
	~Window();

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 170
	 * \see getPlugins()
	 * \see Plugin::enable()
	 */
	bool 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 213 214 215 216
	 */
//	Plugin *checkPluginDependencie(QString name, Plugin *dependantPlugin);

	/**
	 *
	 */
	QList<Plugin*> getPlugins();
217

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

Pierre Kraemer's avatar
Pierre Kraemer committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
	bool addScene(const QString& name);

	bool addNewEmptyScene(QString name, Scene *&scene, bool dialog, Camera *sharedCamera = NULL);
	bool addNewSceneView(Scene *scene, View *view);

	/**
	 *
	 */
	QList<Scene*> getScenes();

	bool associateSceneWithPlugin(QString glviewer, Plugin *plugin, Scene *&scene, bool cb_initGL = false);

	bool addNewSceneFromPlugin(QString name, Plugin *plugin, Scene *&scene);
	bool addNewSceneFromPluginDialog(QString name, Plugin *plugin, Scene *&scene);

	void removeScene(QString name);
238 239 240 241

	void linkDialog(Scene *scene);
	void unlinkDialog(Scene *scene, QList<Plugin *> dependingPlugins);

Pierre Kraemer's avatar
Pierre Kraemer committed
242 243 244 245 246 247 248 249 250 251 252 253 254
	/*********************************************************
	 * MANAGE MAPS
	 *********************************************************/










255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
	bool addReferencedMap(QString map_name, MapHandler *map);

	/**
	 * \fn bool addNewReferencedMap(QString map_name, T* &map)
	 * \brief adds and reference a new map
	 *
	 * This method insert in the map hash table a new map that will be referenced under
	 * the given name.
	 *
	 * \warning This function was meant to be used by the plugins and GLViewers, you should probably not call it.
	 *
	 * \tparam T the template parameter which the type of the map you want to add. T must be a CGoGN
	 *      map type, that is to say an instance of a class that inherits CGoGN::GenericMap.
	 *
	 * \param[in] map_name The name under which will be referenced the map
	 * \param[out] map A pointer to a type T map, which will be set to the adress of the newly created map, or
	 *      to the already existing map refererence by the same name
	 *
	 * \return true if the map is created, false if creation fails (returns false if a same named map already exists)
	 *
	 * \see getReferencedMap()
	 */
	template<typename T>
	MapHandler *addNewReferencedMap(QString map_name, T *&map)
	{
		//if a map isn't already referenced under that name
		MapHash::iterator it;

		if ((it = h_vizu.find(map_name)) == h_vizu.end())
		{
			//the map is created, inserted, and reference under the given name
			map = new T();
			MapHandler *vh = new MapHandler((CGoGN::GenericMap *)map);
			h_vizu.insert(map_name, vh);

			return vh;
		}
		//if a map already has that name
		else
		{
			//failure + map affected with the address of the already existing map
			map = ((T *)((*it)->map()));
			System::Error::code = System::Error::MAP_EXISTS_f(map_name);
			return NULL;
		}
	}

	/**
	 * \fn T* getReferencedMap(QString map_name)
	 * \brief return the map referenced under the given name
	 *
	 * \warning This function was meant to be used by the plugins and GLViewers, you should probably not call it.
	 *
	 * \tparam T the type of the referenced map you want to fetch.
	 *
	 * \param map_name the name under which is referenced the map.
	 *
	 * \return a T type pointer to the map referenced under the given name, if faillure it returns NULL
	 *
	 * 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 addNewReferencedMap()
	 */
//	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;
//		}
//	}
	MapHandler *getReferencedMap(QString map_name);

Pierre Kraemer's avatar
Pierre Kraemer committed
332
	Context* getContext()
333 334 335 336 337 338 339 340 341 342
	{
		return m_context;
	}

	QList<MapHandler *> maps()
	{
		return h_vizu.values();
	}

protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
343
	bool m_initialization;
344

Pierre Kraemer's avatar
Pierre Kraemer committed
345 346
	QVBoxLayout* m_verticalLayout;
	SplitArea* m_splitArea;
347

Pierre Kraemer's avatar
Pierre Kraemer committed
348
	Context* m_context;
349

Pierre Kraemer's avatar
Pierre Kraemer committed
350 351
	QDockWidget* m_dock;
	QTabWidget* m_dockTabWidget;
352

Pierre Kraemer's avatar
Pierre Kraemer committed
353 354 355
	SceneHash h_scenes;
	PluginHash h_plugins;
	MapHash h_maps;
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408

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

	/**
	 * \fn void keyPressEvent( QKeyEvent * event )
	 * \brief handles the mouse button pressure
	 *
	 * Overload function from "QWidget" in order to handle the mouse
	 * button pressure. See the Qt documentation for more details
	 * ( http://qt-project.org/doc/qt-4.8/qwidget.html#mousePressEvent ).
	 */
	void keyPressEvent(QKeyEvent *event);

	/**
	 * \fn void keyReleaseEvent( QKeyEvent * event )
	 * \brief handles the mouse button release
	 *
	 * Overload function from "QWidget" in order to handle the mouse
	 * button release. See the Qt documentation for more details
	 * ( http://qt-project.org/doc/qt-4.8/qwidget.html#mouseReleaseEvent ).
	 */
	void keyReleaseEvent(QKeyEvent *event);

	/**
	 * \fn void moveView()
	 * \brief shows a reordering dialog for the Views
	 *
	 * Make a call with the rigth parameters to the dialog class
	 * GLVSelector and show this dialog.
	 *
	 * This method is meant to be called when the user press
	 * CTRL+Shift+M.
	 */
	void moveView();

public slots:
	/**
	 * \fn void cb_about_CGoGN();
	 * \brief function that is called when the "about CGOGN" menu action is triggered
	 */
	void cb_about_CGoGN();
	/**
	 * \fn void cb_pluginDialog()
	 * \brief method called when the "Plugins" menu action is triggered. Show the plugin managmement dialog:
	 *              PluginDialog
	 */
	void cb_pluginDialog();

	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
409 410
	 * \fn void cb_newView()
	 * \brief method called when the "add new view" button is pushed. Show the new empty view creation dialog:
411 412
	 *              NewViewDialog
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
413
	void cb_newScene();
414 415 416 417 418 419 420

	void cb_globalCamera();

	void cb_mapPlugin();
};

#endif