/****************************************************************************************************

		Modeler.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Arnaud
		Date:	12/2/2004

****************************************************************************************************/

#ifndef __Modeler__
#define __Modeler__

#if CP_PRAGMA_ONCE
#pragma once
#endif


#include "BasicModule.h"
#include "I3DShRenderable.h"
#include "MCPtr.h"

struct	I3DEditorHostPart;
struct	I3DShPrimitive;
struct	IChangeChannel;
struct	I3DShFacetMeshPrimitive;
struct	IWorkingBoxPlane;
class	TRenderable;
class	TPanePart;
class	TPrimitivePropertiesClient;
class	TPropertiesClient;


struct TModelerPrefs
{
	int32		 fPreferedSplitSize;


	TModelerPrefs()
	{
		fPreferedSplitSize= 300;
	}
};


class TModeler : public TBasicModule
{
public:
	static const MCGUID sClassID;

	TModeler();
	~TModeler();

	STANDARD_RELEASE;

	virtual int32	 MCCOMAPI GetParamsBufferSize	() const			{ return 0;}

	// I3DExModule methods
	virtual MCCOMErr MCCOMAPI Initialize			(IMCUnknown* inElement);
	virtual MCCOMErr MCCOMAPI Destroy				();
	virtual MCCOMErr MCCOMAPI Hydrate				();
	virtual MCCOMErr MCCOMAPI Dehydrate				();
	virtual MCCOMErr MCCOMAPI Activate				();
	virtual MCCOMErr MCCOMAPI Deactivate			();
	virtual MCCOMErr MCCOMAPI AboutToCloseMainWindow();
	virtual	MCCOMErr MCCOMAPI Import				(IMCUnknown* inElement, void* inImportData);
	virtual int32	 MCCOMAPI GetPrefsBufferSize	() const			{ return sizeof(TModelerPrefs); }
	virtual void MCCOMAPI GetToolBarsInfo(TMCArray<TToolBarInfo>& toolbarList){}

	// IMFExResponder
	virtual void	 MCCOMAPI SelfPrepareMenus		();


	// IChangeListener methods
	virtual void 		MCCOMAPI DataChanged		(IChangeChannel* 	channel, 
													 IDType 			changeKind, 
													 IMCUnknown* 		changedData);

	//Our methods
	void						AddPrimitiveRenderables	(TRenderableAndTfmArray& outRenderables);

	void						GetCurrentFacetMesh		(real lod, FacetMesh** outMesh);
	void						GetCurrentBoundingBox	(TBBox3D& bb);
		
	boolean						GetImmediateUpdate		()				{ return fImmediateUpdate; }

	I3DShPrimitive*				GetPrimitive			()				{ return fPrimitive; }
	I3DShFacetMeshPrimitive*	GetFacetMeshPrimitive	()				{ return fFacetMeshPrimitive; }

	boolean						MouseDownInPane			(	TPanePart*					inPane,
															const TMCPoint& 			inWhere, 
															const TMCPlatformEvent&	inEvent);

	IMFResponder*				GetActionsContext		()				{ return fActionsContext; }
	
	void						BeginImmediateUpdate	();
	void						PostImmediateUpdate		(boolean invalidateGeometry);
	void						EndImmediateUpdate		();

	IWorkingBoxPlane*			GetWorkingPlane			();

	TModelerPrefs*				GetModelerPrefs			();

protected:
	void						Initialize2		();
	void						CreateWindows	();
	void						DestroyWindows	();
	void						SetWindowTitle	();

protected:
	TMCCountedPtr<IMFWindow>			fWindow;
	TMCCountedPtr<I3DShModule>			fModule;
	TMCCountedPtr<IMFDocument>			fDocument;
	TMCCountedPtr<IMFResponder>			fActionsContext; //fDocument as responder

	TMCCountedPtr<I3DEditorHostPart>	f3DEditorHostPart;	
	TMCCountedPtrArray<TPanePart>		fPaneExtensions;
	

	TMCCountedPtr<I3DShPrimitive>		fPrimitive;
	TMCCountedPtr<I3DShFacetMeshPrimitive>		fFacetMeshPrimitive;

	TMCCountedPtr<IChangeChannel>		fImmediateUpdateChannel;
	TMCCountedPtr<IChangeChannel>		fTreePropertyChangeChannel;

	TMCCountedPtr<TPropertiesClient>	fPropertiesClient;

	boolean								fImmediateUpdate;	
	uint32								fActionBeingProcessed;		//For message blocking
	

protected:
	TMCCountedPtr<TRenderable>		fPrimitiveRenderable;
};








#endif
