// Class CPA_Grid

#ifndef __CPA_GRID_HPP__
#define __CPA_GRID_HPP__

#ifdef ACTIVE_EDITOR

class DEV_MultiDevice3D;
class DEV_SingleDevice3D;
class CPA_SuperObject;

#include "mth.h"
#include "GLD.h"
// ALX
//#include "CPACont.hpp"
// End ALX

//**************************************
/*#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
*///**************************************
// Keyboard entry ID
#define KA_ID_NAVMODE			10
#define KA_ID_LEFT				11
#define KA_ID_RIGHT				12
#define KA_ID_UP				13
#define KA_ID_DOWN				14



class /*CPA_EXPORT*/ CPA_Grid : public CPA_Contact
{
// Constructor/Destructor
//-----------------------
public:
    CPA_Grid(CPA_KeyActionConfiguration *p_oKeyboard, DEV_MultiDevice3D *p_oDevice = NULL);

// Member variables
//-----------------
private:
    DEV_MultiDevice3D      *m_p_oMultiDevice;     // Single device associate with contact

    MTH_tdxReal            m_xMaxSphereBoxRadius;  // The max radius of sphere box of module
    MTH_tdxReal            m_xGridSquareSize;      // The size of a square
    MTH_tdxReal            m_xFirstCenterX;        // Distance from center of grid to center of first object in X
    MTH_tdxReal            m_xFirstCenterZ;        // Distance from center of grid to center of first object in Z
    MTH_tdxReal            m_xLastCenterX;         // Distance from center of grid to center of last object in X
    MTH_tdxReal            m_xLastCenterZ;         // Distance from center of grid to center of last object in Z
    BOOL                   m_bShowSelection;       // There's a selection ?
    BOOL                   m_bShowGrid;            // Grid is visible ?
    short                  m_wNbOfRows;            // Number of rows in grid
    short                  m_wNbOfColumns;         // Number of columns in grid

	CPA_KeyActionConfiguration	* m_p_oKeyboard;
	BOOL						  m_bNavigationMode;

public:
    // override
//  BOOL _OnCommand(UINT);
//  BOOL _OnUpdateCommandUI(CCmdUI *);
    BOOL _OnKeyDown(UINT, UINT, UINT);
//  BOOL _OnKeyUp(UINT, UINT, UINT);
//  BOOL _OnMouseMove(UINT, tdstMousePos *);
//  BOOL _OnLButtonDblClk(UINT, tdstMousePos *, ACP_tdxIndex, HIE_tdstPickInfo *);
    BOOL _OnLButtonDown(UINT, tdstMousePos *, ACP_tdxIndex, HIE_tdstPickInfo *);
//  BOOL _OnLButtonUp(UINT, tdstMousePos *);
//  BOOL _OnRButtonDblClk(UINT, tdstMousePos *, ACP_tdxIndex, HIE_tdstPickInfo *);
//  BOOL _OnRButtonDown(UINT, tdstMousePos *, ACP_tdxIndex, HIE_tdstPickInfo *);
//  BOOL _OnRButtonUp(UINT, tdstMousePos *);
//  BOOL _OnDragDropEnd(WPARAM wParam, LPARAM lParam);
//  BOOL _OnDragDropMove(WPARAM wParam, LPARAM lParam);
//  BOOL _OnDragDropLooseFocus(WPARAM wParam, LPARAM lParam);
//  BOOL _OnDragDropGainFocus(WPARAM wParam, LPARAM lParam);
    void    fn_vAddObjectsToDraw(GLD_tdstViewportAttributes *, GLI_tdxHandleToLight, DEV_ViewPort *);
// owner methods
    void    m_fn_vSetMultiDevice     (DEV_MultiDevice3D *_p_oMulti)     { m_p_oMultiDevice = _p_oMulti; }
// ALX
    DEV_MultiDevice3D *m_fn_p_oGetMultiDevice ()                        { return m_p_oMultiDevice; }
// End ALX
    BOOL                m_fn_bIsGridShowed             (void)                             { return m_bShowGrid; }
    BOOL                m_fn_bIsSelectionShowed        (void)                             { return m_bShowSelection; }
    void                m_fn_vShowGrid                 (void)                             { m_bShowGrid = TRUE; }
    void                m_fn_vHideGrid                 (void)                             { m_bShowGrid = FALSE; }
    void                m_fn_vShowSelection            (void)                             { m_bShowSelection = TRUE; }
    void                m_fn_vHideSelection            (void)                             { m_bShowSelection = FALSE; }
    void                m_fn_vPositionWorldOnGrid      (void);
    void                m_fn_vResetContent             (void);
    void                m_fn_vDisplay                  (GLD_tdstViewportAttributes *);
    void                m_fn_vCenterOnGrid             (void);
    void                m_fn_vCenterOnSuperObject      (CPA_SuperObject *_p_SprObj);
    CPA_SuperObject*    m_fn_p_oGetSuperObjectFromPos  (tdstMousePos *p_stPos);
protected:
    void        m_fn_vComputeObjectsPosition(void);
    void        m_fn_vConvertRowColumnTo3D(short _wRow, short _wColumn, MTH3D_tdstVector *_p_st3D);
    void        m_fn_vComputeMaxSphereBoxRadius(void);
    BOOL        m_fn_bGetSphereBoxCenter(CPA_SuperObject *_p_oSprObj, MTH3D_tdstVector *_p_stCenter);
    MTH_tdxReal m_fn_xGetSphereBoxRadius(CPA_SuperObject *_p_oSprObj);

    void    m_fn_vComputeFirstAndLastCenters(void);
    void    m_fn_vComputeRowColumn(void);
    void    m_fn_vCompute3DPosOfSuperObject(CPA_SuperObject *_p_SprObj,MTH_tdxReal *_p_xLeftX, MTH_tdxReal *_p_xLeftZ,
                                            MTH_tdxReal *_p_xRightX, MTH_tdxReal *_p_xRightZ,
                                            MTH_tdxReal *_p_xXL, MTH_tdxReal *_p_xZL);
    void    m_fn_vComputeGridPosOfSuperObject(CPA_SuperObject *_p_SprObj,short *_p_wRow,short *_p_wColumn);
    void    m_fn_vDisplayGrid(GLD_tdstViewportAttributes *);
    void    m_fn_vDisplaySelection(GLD_tdstViewportAttributes *);
    void    m_fn_vDrawOneLine(GLD_tdstViewportAttributes *_p_stViewAttrib, long lColor,
                              MTH3D_tdstVector *_p_stVxA, MTH3D_tdstVector *_p_stVxB,
                              MTH3D_tdstVector *_p_stDepl, ACP_tdxIndex _xNbLines);
    void    m_fn_vComputePickedSquare(GLI_tdst2DVertex *_p_st2DMousePos, short *_p_wRow, short *_p_wColumn);
    void    m_fn_vGetPosOnGridPlane(GLD_tdhDevice hDev, GLD_tdhViewport hVp, GLI_tdst2DVertex *_p_st2DMousePos,
                                    MTH3D_tdstVector *p_stDstVertex);
};

#endif //ACTIVE_EDITOR
#endif //__CPA_GRID_HPP__