/*
------------------------------------------------------------------------------------------
HEADER FILE FOR :
  Definition of (way) editor object : bezier curves.
------------------------------------------------------------------------------------------
File Name :
 Ed_Bez.h
------------------------------------------------------------------------------------------
Creation :
  * Date : 
   February 20, 1997
  * Author : 
   Albert PAIS
------------------------------------------------------------------------------------------
Contents :
  This file defines structures and functions for the bezier curve used by
  the (way) editor
------------------------------------------------------------------------------------------
Remarks :
  Code comes from old bezier.h made by Yann Le Tensorer (January-February 1997)
------------------------------------------------------------------------------------------
See Also :
  Mth_Bezier.h/.c for mathematical bezier curve definition and implementation.
------------------------------------------------------------------------------------------
Modification :
  * Date : 
  * Author : 
  * Modify :
------------------------------------------------------------------------------------------
*/


#if !defined(__EDIBEZ_TYPES__)
#define __EDIBEZ_TYPES__

#if !defined(ONLY_TYPES)
#define EDIBEZ_UNDEF
#define ONLY_TYPES
#endif /* !ONLY_TYPES */

/*
------------------------------------------------------------------------------------------
INCLUDE FILES :
------------------------------------------------------------------------------------------
*/

/*
----------------------------------------
File Name :
  mth3d.h
----------------------------------------
Required for :
  Definition of standard 3d mathematic
  objects
----------------------------------------
*/
#include "mth.h"

/*
----------------------------------------
File Name :
  acp_base.h
----------------------------------------
Required for :
  Definition of standard CPA objects
----------------------------------------
*/
#include "acp_base.h"
/*
----------------------------------------
File Name :
  gld.h
----------------------------------------
Required for :
  Graphic Library for Display
----------------------------------------
*/
#include "gld.h"

#if defined(EDIBEZ_UNDEF)
#undef ONLY_TYPES
#undef EDIBEZ_UNDEF
#endif /* !EDIBEZ_UNDEF */

/*
------------------------------------------------------------------------------------------
TYPE AND STRUCTURE DEFINITION :
------------------------------------------------------------------------------------------
*/


void fn_vJustToLinkBez (void);

/*
----------------------------------------
Type definition :
 The bezier object for (way) editor
----------------------------------------
  * Structure Name : 
    EDWAY_tdstBezierObject_
  * Type def :
    EDWAY_tdstBezierObject
  * Handles :
    EDWAY_tdhBezierObject
----------------------------------------
Creation Date : 
  February 20,1997
Author : 
  Albert PAIS
----------------------------------------
Members :
  * Type    : MTH3D_tdhBezierCurve
    Name    : m_hBezierCurve
    Meaning : A handle on the mathematical
              bezier curve associated
  * Type    : ACP_tdxHandleOfObject
    Name    : m_hGeometricObject
    Meaning : A handle on a geometric
              object
  * Type    : ACP_tdxHandleOfElement
    Name    : m_hLineElement
    Meaning : A handle on a line element
              object
  * Type    : long
    Name    : m_lColor
    Meaning : Color of the curve (24bit)
  * Type    : GLD_tdstViewportAttributes
    Name    : m_pstViewPortAttributes
    Meaning : pointer on the view port
              attributes
  * Type    : MTH3D_tdstVector
    Name    : m_dstListOfPoints
    Meaning : Dynamic array on the
              points of the bezier curve
              in case mode=C_ucModeNoObject
  * Type    : ACP_tdstDynaParam
    Name    : m_pstDynaParams
    Meaning : A pointer on the dynamic
              params associated
  * Type    : unsigned char
    Name    : m_ucObjectMode
    Meaning : the object mode :
              C_ucModeNoObject or C_ucModeRealObject
---------------------------------------
*/
#ifdef _EDWAY_BEZ_FRIEND_
typedef struct EDWAY_tdstBezierObject_
{
	MTH3D_tdhBezierCurve m_hBezierCurve;
	ACP_tdxHandleOfObject m_hGeometricObject;
	ACP_tdxHandleOfElement m_hLineElement;
	long m_lColor;
	GLD_tdstViewportAttributes	*m_pstViewPortAttributes;
	MTH3D_tdstVector **m_pdstListOfPoints;
	ACP_tdstDynaParam *m_pstDynaParams;
	unsigned char m_ucObjectMode;
} EDWAY_tdstBezierObject;
#endif /* _EDWAY_BEZ_FRIEND_ */
typedef struct EDWAY_tdstBezierObject_* EDWAY_tdhBezierObject;

#endif /* !__EDIBEZ_TYPES__ */

#if !defined(ONLY_TYPES)

#if !defined(__EDIBEZ_VARS__)
#define __EDIBEZ_VARS__

#undef EXTERN
#undef extern
#if !defined(GLOBALS)
#define EXTERN extern
#else /* !GLOBALS */
#define EXTERN
#endif /* !GLOBALS */

/*
------------------------------------------------------------------------------------------
VARIABLE DECLARATION :
 <type> <variable name>
 #if defined(GLOBALS)
 = <initial values>
 #endif
 ;
------------------------------------------------------------------------------------------
*/


/*
------------------------------------------------------------------------------------------
MACROS-CONSTANT DECLARATION:
------------------------------------------------------------------------------------------
*/
/* Invalid handle :*/
#define EDWAY_C_hInvalidBezierObject ((EDWAY_tdhBezierObject)NULL)
/* no geometric object created : */ 
#define EDWAY_C_ucModeNoObject	0
/* a geometric object is created */
#define EDWAY_C_ucModeRealObject	1

#undef extern
#endif /* !__EDIBEZ_VARS__ */

#if !defined (__EDIBEZ_PROTOS__)
#define __EDIBEZ_PROTOS__



/*
------------------------------------------------------------------------------------------
MACROS-FUNCTIONS DECLARATION:
------------------------------------------------------------------------------------------
*/
#ifdef _EDWAY_BEZ_FRIEND_
#define EDWAY_M_vBezierObjectGetPointerParam(_hBezObj,_pxPointer,_SlotName)\
 (*(_pxPointer) = (_hBezObj)->m_st##_SlotName##)
#define EDWAY_M_xBezierObjectGetScalarParam(_hBezObj,_Prefix,_SlotName)\
 ((_hBezObj)->m_##_Prefix## ##_SlotName##)
#define EDWAY_M_vBezierObjectSetPointerParam(_hBezObj,_pxPointer,_SlotName)\
 ((_hBezObj)->m_st##_SlotName## = *(_pxPointer))
#define EDWAY_M_vBezierObjectSetScalarParam(_hBezObj,_xScalar,_Prefix,_SlotName)\
 ((_hBezObj)->m_##_Prefix## ##_SlotName## = (_xScalar))

#define EDWAY_M_uwBezierObjectSizeOf()\
 ((unsigned short)(sizeof(struct EDWAY_tdstBezierObject_)))

#else /* _EDWAY_BEZ_FRIEND_ */

#define EDWAY_M_vBezierObjectGetPointerParam(_hBezObj,_pxPointer,_SlotName)\
 (EDWAY_fnv_BezierObject_Get##_SlotName##(_hBezObj,_pxPointer))
#define EDWAY_M_xBezierObjectGetScalarParam(_hBezObj,_Prefix,_SlotName)\
 (EDWAY_fn##_Prefix##_BezierObject_Get##_SlotName##(_hBezObj))
#define EDWAY_M_vBezierObjectSetPointerParam(_hBezObj,_pxPointer,_SlotName)\
 (EDWAY_fnv_BezierObject_Set##_SlotName##(_hBezObj,_pxPointer))
#define EDWAY_M_vBezierObjectSetScalarParam(_hBezObj,_xScalar,_Prefix,_SlotName)\
 (EDWAY_fnv_BezierObject_Set##_SlotName##(_hBezObj,_xScalar))

#define EDWAY_M_uwBezierObjectSizeOf()\
 EDWAY_fnuw_BezierObject_SizeOf()

#endif /* _EDWAY_BEZ_FRIEND_ */

#define EDWAY_M_hBezierObjectGetBezierCurve(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,h,BezierCurve)
#define EDWAY_M_hBezierObjectGetGeometricObject(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,h,GeometricObject)
#define EDWAY_M_hBezierObjectGetLineElement(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,h,LineElement)
#define EDWAY_M_lBezierObjectGetColor(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,l,Color)
#define EDWAY_M_pstBezierObjectGetViewPortAttributes(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,pst,ViewPortAttributes)
#define EDWAY_M_dstBezierObjectGetListOfPoints(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,dst,ListOfPoints)
#define EDWAY_M_pstBezierObjectGetDynaParams(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,pst,DynaParams)
#define EDWAY_M_ucBezierObjectGetObjectMode(_hBezObjCon)\
 EDWAY_M_xBezierObjectGetScalarParam(_hBezObjCon,uc,ObjectMode)

#define EDWAY_M_vBezierObjectSetBezierCurve(_hBezObjCon,_hBezCur)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_hBezCur,h,BezierCurve)
#define EDWAY_M_vBezierObjectSetGeometricObject(_hBezObjCon,_hGeoObj)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_hGeoObj,h,GeometricObject)
#define EDWAY_M_vBezierObjectSetLineElement(_hBezObjCon,_LinEle)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_LinEle,h,LineElement)
#define EDWAY_M_vBezierObjectSetColor(_hBezObjCon,_lCol)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_lCol,l,Color)
#define EDWAY_M_vBezierObjectSetViewPortAttributes(_hBezObjCon,_pstViePorAtt)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_pstViePorAtt,pst,ViewPortAttributes)
#define EDWAY_M_vBezierObjectSetListOfPoints(_hBezObjCon,_dstLisOfPts)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_dstLisOfPts,dst,ListOfPoints)
#define EDWAY_M_vBezierObjectSetDynaParams(_hBezObjCon,_pstDynPar)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_pstDynPar,pst,DynaParams)
#define EDWAY_M_vBezierObjectSetObjectMode(_hBezObjCon,_ucObjMod)\
 EDWAY_M_vBezierObjectSetScalarParam(_hBezObjCon,_ucObjMod,uc,ObjectMode)

/*
------------------------------------------------------------------------------------------
FUNCTIONS DECLARATION:
------------------------------------------------------------------------------------------
*/


EDWAY_tdhBezierObject EDWAY_fnh_BezierObject_CreateStructure(void);
void EDWAY_fnv_BezierObject_DestroyStructure(EDWAY_tdhBezierObject);
/* Creation :*/
void EDWAY_fnv_BezierObject_Create
(EDWAY_tdhBezierObject,unsigned char,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*,unsigned char,ACP_tdstDynaParam*, MTH3D_tdstVector** pdstListOfPoints);

void EDWAY_fnv_BezierObject_CreateWithCurve
( 
	EDWAY_tdhBezierObject	_hBezierObject, 
	MTH3D_tdhBezierCurve	_hBezierCurve,
	unsigned char			_ucObjectMode,
	ACP_tdstDynaParam*		_pstDynaParams,
	MTH3D_tdstVector** pdstListOfPoints
);

void EDWAY_fnv_BezierObject_Free(EDWAY_tdhBezierObject);

unsigned short EDWAY_fnuw_BezierObject_SizeOf(void);

/* computing points :*/
void EDWAY_fnv_BezierObject_Calculate
(EDWAY_tdhBezierObject);

/* Getting fields values :*/
MTH3D_tdhBezierCurve EDWAY_fnh_BezierObject_GetBezierCurve(EDWAY_tdhBezierObject);
ACP_tdxHandleOfObject EDWAY_fnh_BezierObject_GetGeometricObject(EDWAY_tdhBezierObject);
ACP_tdxHandleOfElement EDWAY_fnh_BezierObject_GetLineElement(EDWAY_tdhBezierObject);
long EDWAY_fnl_BezierObject_GetColor(EDWAY_tdhBezierObject);
GLD_tdstViewportAttributes* EDWAY_fnpst_BezierObject_GetViewPortAttributes(EDWAY_tdhBezierObject);
MTH3D_tdstVector* EDWAY_fndst_BezierObject_GetListOfPoints(EDWAY_tdhBezierObject);
ACP_tdstDynaParam* EDWAY_fnpst_BezierObject_GetDynaParams(EDWAY_tdhBezierObject);
unsigned char EDWAY_fnuc_BezierObject_GetObjectMode(EDWAY_tdhBezierObject);

/* changing (and only changing) fields value */
void EDWAY_fnv_BezierObject_SetBezierCurve(EDWAY_tdhBezierObject,MTH3D_tdhBezierCurve);
void EDWAY_fnv_BezierObject_SetGeometricObject(EDWAY_tdhBezierObject,ACP_tdxHandleOfObject);
void EDWAY_fnv_BezierObject_SetLineElement(EDWAY_tdhBezierObject,ACP_tdxHandleOfElement);
void EDWAY_fnv_BezierObject_SetColor(EDWAY_tdhBezierObject,long);
void EDWAY_fnv_BezierObject_SetViewPortAttributes(EDWAY_tdhBezierObject,GLD_tdstViewportAttributes*);
void EDWAY_fnv_BezierObject_SetListOfPoints(EDWAY_tdhBezierObject,MTH3D_tdstVector*);
void EDWAY_fnv_BezierObject_SetDynaParams(EDWAY_tdhBezierObject,ACP_tdstDynaParam *);
void EDWAY_fnv_BezierObject_SetObjectMode(EDWAY_tdhBezierObject,unsigned char);

/* Changing fields value and reflect back consequences : */
ACP_tdxBool EDWAY_fnb_BezierObject_ChangeSamplingRate(EDWAY_tdhBezierObject,unsigned char);

void EDWAY_fnv_BezierObject_ChangeParams
(EDWAY_tdhBezierObject	,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*);

void  EDWAY_fnv_BezierObject_GetParams
(EDWAY_tdhBezierObject	,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*);

/* retrieving speed :*/
MTH_tdxReal fn_xBezierObject_GetSpeed
(EDWAY_tdhBezierObject,unsigned char);

/* retrieving point */
void EDWAY_fnv_BezierObject_GetPoint
(EDWAY_tdhBezierObject,unsigned char,MTH3D_tdstVector*);

/* drawing the bezier object */
void EDWAY_fnv_BezierObject_Draw(EDWAY_tdhBezierObject);


#endif /* !__EDIBEZ_PROTOS__ */

#endif /* !ONLY_TYPES */