/*
 * $Id: eventmanager.h,v 1.6 2008-09-20 21:13:13 kybav1 Exp $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __MANIP_MANAGER__H__
#define __MANIP_MANAGER__H__

//#include <wx/event.h>
#include "serverbase.h"
#include "cameramodule.h"
//#include "rendermanager.h"


namespace VRUT
{
	class Camera;

	///Server managing all kinds of manipulator modules
	class ManipulatorManager : public ServerBase<ManipulatorModule>
	{
	protected:
	public:
		///Class constructor
		ManipulatorManager() : ServerBase<ManipulatorModule>(MANIP_MANAGER) {}
		///Class destructor
		virtual ~ManipulatorManager() {}

		///Pass camera to manipulator
		///\param[in] sceneID Scene with camera node
		///\param[in] cameraID Camera node ID to manipulate
		///\param[in] windowID Render window displaying camera's view
		///\return ID of module used or \c MODULE_ID_NONE if failed
		MODULE_ID ManipulateCamera(SCENE_ID sceneID, NODE_ID cameraID, RENDER_WINDOW_ID windowID)
		{
			//code 3: set predefined variables, the Navigation name is hardcoded for now - I have not better idea now...
			Parameter::ParameterIdentifier scenePI(wxT("Navigation"), wxT("sceneID"), wxT("predef"));
			KERNEL->environment.SetParam(scenePI, wxString::Format(wxT("%lu"), (unsigned long)sceneID));
			Parameter::ParameterIdentifier camPI(wxT("Navigation"), wxT("nodeID"), wxT("predef"));
			KERNEL->environment.SetParam(camPI, wxString::Format(wxT("%lu"), (unsigned long)cameraID));
			Parameter::ParameterIdentifier winPI(wxT("Navigation"), wxT("windowID"), wxT("predef"));
			KERNEL->environment.SetParam(winPI, wxString::Format(wxT("%lu"), (unsigned long)windowID));
			//end of code 3
			///Create input handler module instance
			MODULE_ID moduleID = getOrCreateModuleInstance();
			ManipulatorModule* module = getModule(moduleID);
			if (!module)
				return MODULE_ID_NONE;

			ModuleHandle<ManipulatorModule>::StartModuleThread(module);
			if (module && module->IsOfType(MODULE_TYPE_CAMERA))
				return moduleID;
			else
			{
				releaseModule(moduleID);
				return MODULE_ID_NONE;
			}
		}

		void StopManipulateCamera(RENDER_WINDOW_ID windowID)
		{
			ModuleList moduleInstances;
			KERNEL->GetModules(&moduleInstances, wxT("Navigation"));//hardcoded for now
			for (auto &moduleInstance : moduleInstances) {
				CameraModule *module=(CameraModule *)moduleInstance.first;
				if (module && (module->GetWindowID()==windowID))
					releaseModule(module->GetID());
			}
		}
	};
}


#endif
