/*======================================================================================

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkVisualizationUnit.h
	Version:		$Revision: 2786 $
	Date:			$Date: 2012-03-13 17:51:50 +0100 (Di, 13 Mrz 2012) $

	Copyright (c) 2010-2011
	Pattern Recognition Lab, 
    University Erlangen-Nuremberg, Germany
    All rights reserved.

	This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
	See RITKCopyright.txt for more information.

	http://www5.informatik.uni-erlangen.de/research/software/ritk

========================================================================================*/

#ifndef VISUALIZATIONUNIT_H__
#define VISUALIZATIONUNIT_H__

#include "ritkVisualization.h"

#include <QMutex>

#include "ritkOpenGLEntity.h"
#include "ritkOpenGLCamera.h"

#include "ritkOpenGLVisualizationWidget.h"

namespace ritk
{








/**	@ingroup	Visualization
*	@class		VisualizationUnit
*	@author		Sven Haase, Jakob Wasza
*	@brief		A compound for an OpenGL visualization widget and control widgets
*
*	@details
*/
class VISUALIZATION_EXPORT VisualizationUnit : public QMainWindow
{

	// The invisible FullscreenWindow, gets active and visible at fullscreenmode
	class VISUALIZATION_EXPORT FullscreenWindow : public QMainWindow
	{
		public:
			FullscreenWindow(QWidget* parent, Qt::WindowFlags flags = 0) : QMainWindow(parent, flags){};
		protected:
			// Override necessary. The Fullscreen Window needs to send the Keyboard Input to the VisualizationUnit.
			void keyPressEvent(QKeyEvent *e);
	};



	Q_OBJECT

public:
	/// Constructor
	VisualizationUnit(QWidget* parent = 0, Qt::WindowFlags flags = 0);
	/// Destructor
	~VisualizationUnit();

	/**	@name Get the internal visualization widget */
	//@{
	const OpenGLVisualizationWidget* GetVisualizationWidget() const;
	OpenGLVisualizationWidget* GetVisualizationWidget();
	//@}

	/**	Add/remove entities. Convenience methods that simply call the corresponding method on the internal visualization widget. */
	//@{
	bool AddEntity(OpenGLEntity *e);
	bool RemoveEntity(OpenGLEntity *e);
	bool SetPrimaryEntity(OpenGLEntity *e);
	bool RemovePrimaryEntity();
	const OpenGLEntity *GetPrimaryEntity();
	//@}

	/// Repaint the Widget
	void UpdateWidget();

	/// Set RenderMode to either 3D or 2D
	virtual void SetRender3D(bool enable3D);

	/// Disable Rendermode changes (Disables the function SetRender3D)
	virtual void SetRenderModeFixed(bool enabled);

	/// Enables/Disables FullScreen
	virtual void SetFullScreenMode(bool enabled);


	/**	@name	Keyboard events */
	//@{
	void keyPressEvent(QKeyEvent *e);
	//@}

	
protected:

	/// Attaches controlWidgets to the active VisualizationWindow or removes them if controls are disabled
	void attachControlWidgets();	

protected:

	/// Show control widget
	bool m_ShowControls;

	/// Fullscreen
	bool m_FullScreen;

	/// internal state of controlWidgets
	bool m_controlWidgetsAttachedNormal;
	bool m_controlWidgetsAttachedFullscreen;

	/// The widget for visualization
	OpenGLVisualizationWidget* m_VisualizationWidget;

	/// normally invisible, used to display the Widget in FullScreen
	FullscreenWindow *m_FullscreenWindow;
	

	/// Mutex used to synchronize rendering and data update
	QMutex m_Mutex;
};











} // end namespace ritk

#endif // VISUALIZATIONUNIT_H__