/*
 *=======================================================================================
 * Name        :EditorPO.hpp
 * Author      :Vincent Lhullier			Date :05/06/97
 * Description :Description of Editor Physical object
 *=======================================================================================
 * Modification -> Author :					Date :
 * Description :
 *=======================================================================================
 */
 
#ifndef __EDITORPO_HPP__
#define __EDITORPO_HPP__
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include "ITF.h"
#include "MEC.h"
#define D_PhysiCol_Define
#include "GAM.h"
#include "SPO.h"
#include "PO.h"
#undef  D_PhysiCol_Define
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
class Geometry3D;
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#ifndef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else
#define CPA_EXPORT
#endif
#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
/*
 =======================================================================================
	Constants 
 =======================================================================================
 */
/*
 * origin of PO object
 */
#define C_cFromFamilies	0
#define C_cFromLevels	1
#define C_cFromClasses	2
 
/*
 * unsed index
 */
#define C_uwNotInTable  ((unsigned short)-1)
 
 
/*
 =======================================================================================
	Editor Physical Object class 
 =======================================================================================
 */
class EditorPO : public CPA_SaveObject,public CPA_EdMot<PO_tdxHandleToPhysicalObject>
{
  private:
	char				m_cOrigin;
	Geometry3D			**m_dp_oLodGeom;
	CPA_BaseObject		*m_ap_oZone[ 4 ];
 
	CPA_SectionObject	*m_p_oPCSSection;
	CPA_SectionObject	*m_p_oVSESection;		/* object associated with VisualSet section of this PO object*/
 
	unsigned short		 m_uwIndexInObjectsTable;
/*ANNECY TQ 22/06/98{*/
	ACP_tdxHandleOfObject	m_hBoundingVolume;
/*ENDANNECY TQ}*/
 
 
/*ROMTEAM WorldEditor (Cristian Stegaru 12/97)*/
  protected:
	 BOOL		m_bIsClone;
/*ENDROMTEAM WorldEditor (Cristian Stegaru)*/
 
  public:
	  /*CPA2 Stegaru Cristian 98-03*/
	  CString mfn_csGetFullGeomSectionName ();
	  CString mfn_csGetModSectionName ();
	  /*End CPA2 Stegaru Cristian 98-03*/
	  /*CPA2 Stegaru Cristian 98-05	*/
	  ACP_tdxIndex		mfn_iGetFacesNumber ();
	  MTH3D_tdstVector	mfn_3dvGetMinCoordinates ();
	  MTH3D_tdstVector	mfn_3dvGetMaxCoordinates ();
	  MTH3D_tdstVector	mfn_3dvGetSizes ();	/*dX, dY, dZ*/
	  /*End CPA2 Stegaru Cristian 98-05*/
	  
 
/*ROMTEAM WorldEditor (Nicu 16/01/98)*/
	  BOOL mfn_bIsClone () { return m_bIsClone;}
	  void mfn_vSetClone (BOOL bIsClone) { m_bIsClone = bIsClone;}
		Geometry3D			*m_pGeom, /* pointer to the geometric object (Shape3D)*/
										*m_pOrigGeom;
		int m_iIdx;								/* geometric object index		*/
		BOOL IsCandidatePO () { return -2 != m_iIdx;}
/*ENDROMTEAM WorldEditor (Nicu)*/
 
 
	/* ==> constructor / destructor */
	EditorPO (
				CPA_EditorBase *p_oDLL,
				PO_tdxHandleToPhysicalObject hObj,
				CPA_BaseObject *p_oOwner,
				CString csName = "",
				CString csFileName = "",
				CString csSectionName = ""
			 );
 
	~EditorPO();
 
	/* ==> initialisation of data members */
	static void			StaticInit();
	void				m_fn_vInitDataMembers( BOOL _bSecondPass = FALSE );
 
 
	/* ==> access to origin */
	char				*fn_szComputeOrigin( char *_szFileName, char *_cOrigin );
	char				fn_cGetOrigin( void ) { return m_cOrigin; }
 
	/* ==> loading engine PO */
	BOOL				m_fn_bLoadEnginePO( void );
 
	/* ==> Access to data type */
    long				GetDataType(void) { return HIE_C_ulPO; }
    void				*GetData(void) { return GetStruct(); }
 
	/* ==> Access to Objects Table Index */
	unsigned short		m_fn_uwGetIndexInObjectTable(void)			{ return m_uwIndexInObjectsTable; }
	void				m_fn_vSetIndexInObjectTable(unsigned short _uwIndex)	{ m_uwIndexInObjectsTable = _uwIndex; }
 
	/* ==> name unicity */
	tdeMissingCriteria	fn_eCheckUnicity (const CString csNewName) { return fn_eCheckUnicityWithOwner(csNewName); }
 
	/* ==> Notification */
	void				fn_vNotifySave(void);
	void				fn_vNotifyUnSave(void);
	void				fn_vNotifyRestore(void);
	void				fn_vNotifyRename(void);
	
	void				fn_vUpdateSectionName (void);
	
	/* ==> access to Physical Coll Set section object */
	void				fn_vComputePCSSectionName( char *szPCSSectionName );
	CPA_SectionObject	*fn_p_oGetPCSSection (void) { return m_p_oPCSSection; }
	
	/* ==> access to VisaulSet section object and information */
	void				fn_vComputeVSESectionName( char *szVSESectionName );
	CPA_SectionObject	*fn_p_oGetVSESection( void ) { return m_p_oVSESection; }
 
	/* ==> access to engine struct */
	void				*GetEngineStruct() { return GetStruct(); };
	void				SetEngineStruct (PO_tdxHandleToPhysicalObject hObj) { SetStruct(hObj); }
 
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	Geometry3D *m_fnp_oGetGeometricWithDistance( MTH_tdxReal xDistance)
	{
		GEO_tdxHandleToVisualSet	hVSE;
		ACP_tdxIndex				xNumberOfLod;
		ACP_tdxIndex				xIndexOfLod;
		MTH_tdxReal					xThreshold;
		ACP_tdxHandleOfObject		hGeoObj;
 
		if (!GetStruct())
			return NULL;
		
		hVSE = PO_fn_hGetVisualSet( GetStruct() );
		xNumberOfLod = (ACP_tdxIndex) GLI_lGetVisualSetNumbertOfLOD( hVSE );
 
		for (xIndexOfLod = 0; xIndexOfLod < xNumberOfLod - 1; xIndexOfLod ++)
		{
			GLI_vGetVisualSetLOD( hVSE, xIndexOfLod + 1, &xThreshold, &hGeoObj );
			if (xThreshold > xDistance) break;
		}
		return m_dp_oLodGeom[xIndexOfLod];
	}
 
	/* ==> access to zone */		
	CPA_BaseObject		*GetZone( char cTypeZone ) { return m_ap_oZone[ cTypeZone ]; }
 
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*ROMTEAM WorldEditor (Nicu 07/11/97) */
    void SetZone (char cTypeZone , CPA_BaseObject *_pZDxObject, BOOL bStandardPO = TRUE)  
			{ 
				m_ap_oZone[ cTypeZone ] = _pZDxObject;
				if (!bStandardPO) 
					m_pGeom = m_pOrigGeom = (Geometry3D*)_pZDxObject;
/*ENDROMTEAM WorldEditor (Nicu) */
                PCS_tdxHandleToPhysicalCollSet hCollSet = PO_fn_hGetCollideSet(GetStruct ());
                if (! hCollSet)
                {
					hCollSet = PCS_fn_hCreatePhysicalCollideSet();
                    PO_fn_vSetCollideSet (GetStruct () , hCollSet);
                }
                void * pEngineZone;
                if (_pZDxObject)    /* _pZDxObject can be a ZDx object or a PO*/
                {
                    if (_pZDxObject -> fn_bIsOfType (C_szPhysicalObjectTypeName))
                         pEngineZone = ((CPA_BaseObject *) ((EditorPO *) _pZDxObject) ->
                                                            m_fnp_oGetGeometricWithDistance (0)) -> GetData ();
                    else pEngineZone = _pZDxObject -> GetData ();
                }
                else pEngineZone = NULL;
 
                PCS_fn_vSetGeoObjOfPhysicalCollSet(cTypeZone , hCollSet , (ACP_tdxHandleOfObject) pEngineZone);
 
/*ROMTEAM WorldEditor (Nicu 07/11/97) */
	if(m_p_oPCSSection)
/*ENDROMTEAM WorldEditor (Nicu) */
				m_p_oPCSSection->fn_vWriteSection();
			}
 
	/* ==> filenames */
    CString fn_csConstructFileName(CString csFileName);
/*ANNECY TQ 22/06/98{*/
	ACP_tdxHandleOfObject	fn_hGetEditorPOBoundingVolume() { return m_hBoundingVolume; }
	void fn_vSetEditorPOBoundingVolume(ACP_tdxHandleOfObject hBoundingVolume) { m_hBoundingVolume = hBoundingVolume; }
/*ENDANNECY TQ}*/
 
 
 
};
 
#endif /*__3DOBJECT_HPP__*/
