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

#include "ui_window.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
6
#include "PythonQt/PythonQt.h"
7
#include "types.h"
8

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

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

namespace SCHNApps
{

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

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

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
43 44 45
	/*********************************************************
	 * MANAGE DOCK
	 *********************************************************/
46 47 48 49 50 51 52

	/**
	 * \fn QTabWidget* getDockTabWidget()
	 * \brief Accessor to the QTabWidget of this interface
	 *
	 * \return a pointer to the TabWidget, NULL if not allocated yet
	 */
53
	QTabWidget* getDockTabWidget() const { return m_dockTabWidget; }
54 55

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

	/**
	 * \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
76 77
	void removeTabInDock(QWidget* tabWidget);

78 79 80
	void enablePluginTabWidgets(Plugin* plugin);
	void disablePluginTabWidgets(Plugin* plugin);

Pierre Kraemer's avatar
Pierre Kraemer committed
81 82 83
	/*********************************************************
	 * MANAGE MENU ACTIONS
	 *********************************************************/
84 85

	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
86
	 * \fn bool addMenuAction(const QString& menuPath, QAction* action)
87 88 89
	 * \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
90
	 * \param action a pointer to the allocated action to add in the menu. All the details on that action (such as
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
	 *          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
107
	 *  This method is called by Plugin methods
108 109 110 111
	 *
	 *  \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
112
	 *    depending on the error. This error can be shown with Error::showError
113 114
	 *
	 * \see deleteMenuAction()
Pierre Kraemer's avatar
Pierre Kraemer committed
115
	 * \see Plugin::addMenuAction()
116
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
117
	bool addMenuAction(const QString& menuPath, QAction* action);
118 119

	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
120
	 * \fn void deleteMenuAction(QAction* action)
121 122
	 * \brief delete an action from the menu bar
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
123
	 * \param action pointer to the allocated action to delete.
124 125 126 127 128
	 *
	 *  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
129
	 *  This method is called by Plugin methods
130 131
	 *
	 *  \see addMenuAction()
Pierre Kraemer's avatar
Pierre Kraemer committed
132
	 *  \see Plugin::removeMenuAction()
133
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
134 135 136 137 138 139 140
	void removeMenuAction(QAction* action);

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

	bool addToolbarAction(QAction* action);
141

Pierre Kraemer's avatar
Pierre Kraemer committed
142 143
	void removeToolbarAction(QAction* action);

144 145 146 147 148 149 150
	/*********************************************************
	 * MANAGE CAMERAS
	 *********************************************************/

	Camera* addCamera(const QString& name);
	Camera* addCamera();
	void removeCamera(const QString& name);
151 152 153
	Camera* getCamera(const QString& name) const;
	QList<Camera*> getCamerasList() const { return h_cameras.values(); }
	const CameraHash& getCamerasHash() const { return h_cameras; }
154 155 156 157 158 159 160 161

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

	View* addView(const QString& name);
	View* addView();
	void removeView(const QString& name);
162 163 164 165 166 167 168
	View* getView(const QString& name) const;
	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
169
	void splitView(const QString& name, Qt::Orientation orientation);
170

Pierre Kraemer's avatar
Pierre Kraemer committed
171 172 173
	/*********************************************************
	 * MANAGE PLUGINS
	 *********************************************************/
174 175 176 177 178 179 180 181

	/**
	 * \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
182
	 * where the extension ('.so', '.dylib') and the prefix 'lib' were removed.
183 184 185 186 187 188
	 *
	 *  <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
189 190
	 * 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.
191
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
192
	 * \warning In the program this method is called under specific and controlled circumstances, you should probably not call it.
193
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
194
	 * \return a boolean whether the loading succeeded or not.
195 196
	 *
	 * If the function failed, the error code ( Error::code ) is affected with a value
Pierre Kraemer's avatar
Pierre Kraemer committed
197
	 * depending on the error. This error can be shown with Error::showError
198 199
	 *
	 * \see unloadPlugin()
Pierre Kraemer's avatar
Pierre Kraemer committed
200 201 202
	 * \see getPlugins()
	 * \see Plugin::enable()
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
203
//	Plugin* loadPlugin(const QString& pluginFilePath);
204 205 206 207 208 209 210

	/**
	 * \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
211
	 * The Plugin of the given name is dereferenced and deleted, if it exists and was previously
212 213
	 * referenced, if not, the method does nothing.
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
214 215
	 * 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.
216 217 218 219
	 *
	 * \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
220
	 * \see getPlugins()
221 222
	 * \see Plugin::disable()
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
223
	void unloadPlugin(const QString& pluginName);
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

	/**
	 * \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
243 244 245
	 */
//	Plugin *checkPluginDependencie(QString name, Plugin *dependantPlugin);

246 247 248
	Plugin* getPlugin(const QString& name) const;
	QList<Plugin*> getPluginsList() const { return h_plugins.values(); }
	const PluginHash& getPluginsHash() const { return h_plugins; }
249

250 251 252
	/*********************************************************
	 * MANAGE MAPS
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
253

254
	GenericMap* createMap(unsigned int dim);
255
	bool addMap(MapHandlerGen* map);
256
	void removeMap(const QString& name);
257 258 259
	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
260

261 262 263 264 265 266
	/*********************************************************
	 * MANAGE TEXTURES
	 *********************************************************/

	Texture* getTexture(const QString& image);
	void releaseTexture(const QString& image);
267 268

protected:
269
	QString m_appPath;
Pierre Kraemer's avatar
Pierre Kraemer committed
270
	PythonQtObjectPtr& m_pythonContext;
271

Pierre Kraemer's avatar
Pierre Kraemer committed
272
	bool m_initialization;
273

Pierre Kraemer's avatar
Pierre Kraemer committed
274 275 276
	QVBoxLayout* m_centralLayout;
	QSplitter* m_rootSplitter;
	bool b_rootSplitterInitialized;
277

278
	View* m_firstView;
279
	View* m_currentView;
280

Pierre Kraemer's avatar
Pierre Kraemer committed
281 282
	QDockWidget* m_dock;
	QTabWidget* m_dockTabWidget;
283

Pierre Kraemer's avatar
Pierre Kraemer committed
284
	PluginHash h_plugins;
285
	ViewHash h_views;
Pierre Kraemer's avatar
Pierre Kraemer committed
286
	CameraHash h_cameras;
287
	MapHash h_maps;
288

289 290
	TextureHash h_textures;

Pierre Kraemer's avatar
Pierre Kraemer committed
291 292 293
	CamerasDialog* m_camerasDialog;
	PluginsDialog* m_pluginsDialog;
	MapsDialog* m_mapsDialog;
294 295

public slots:
Pierre Kraemer's avatar
Pierre Kraemer committed
296 297 298

	Plugin* loadPlugin(const QString& pluginFilePath);

299 300 301 302 303 304
	/**
	 * \fn void cb_about_SCHNApps();
	 * \brief function that is called when the "about SCHNApps" menu action is triggered
	 */
	void cb_aboutSCHNApps();

305 306 307 308
	/**
	 * \fn void cb_about_CGoGN();
	 * \brief function that is called when the "about CGOGN" menu action is triggered
	 */
309
	void cb_aboutCGoGN();
310 311
	
	void cb_showHideDock();
312

313
	/**
314 315 316
	 * \fn void cb_manageCameras()
	 * \brief method called when the "Cameras" action is triggered.
	 * Show the cameras management dialog:
317
	 */
318
	void cb_manageCameras();
319

320
	/**
321 322 323
	 * \fn void cb_managePlugins()
	 * \brief method called when the "Plugins" action is triggered.
	 * Show the plugins management dialog
324
	 */
325 326
	void cb_managePlugins();

327 328
	void cb_manageMaps();

329 330 331 332 333 334 335
signals:
	void cameraAdded(Camera* camera);
	void cameraRemoved(Camera* camera);

	void viewAdded(View* view);
	void viewRemoved(View* view);

336 337
	void mapAdded(MapHandlerGen* map);
	void mapRemoved(MapHandlerGen* map);
338 339 340

	void pluginAdded(Plugin* plugin);
	void pluginRemoved(Plugin* plugin);
341 342
};

Pierre Kraemer's avatar
Pierre Kraemer committed
343 344 345 346
} // namespace SCHNApps

} // namespace CGoGN

347
#endif