/*
------------------------------------------------------------------------------------------
HEADER FILE FOR :
  Definition of (way) editor object : circle arc curves.
------------------------------------------------------------------------------------------
File Name :
 Edi_CiAr.h
------------------------------------------------------------------------------------------
Creation :
  * Date : 
   February 25, 1997
  * Author : 
   Albert PAIS
------------------------------------------------------------------------------------------
Contents :
  This file defines structures and functions for the circle arc curve used by
  the (way) editor
------------------------------------------------------------------------------------------
Remarks :
  Code comes from old circlway.h made by Yann Le Tensorer (January-February 1997)
------------------------------------------------------------------------------------------
See Also :
  Mth_CiAr.h/.c for mathematical circle arc curve definition and implementation.
------------------------------------------------------------------------------------------
Modification :
  * Date : 
  * Author : 
  * Modify :
------------------------------------------------------------------------------------------
*/
#if !defined(__EDICIAR_TYPES__)
#define __EDICIAR_TYPES__

#if !defined(ONLY_TYPES)
#define EDICIAR_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(EDICIAR_UNDEF)
#undef ONLY_TYPES
#undef EDICIAR_UNDEF
#endif /* !EDICIAR_UNDEF */

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

void JustToLinkCiAr (void);



/*
----------------------------------------
Type definition :
 The circle arc object for (way) editor
----------------------------------------
  * Structure Name : 
    EDWAY_tdstCircleArcObject_
  * Type def :
    EDWAY_tdstCircleArcObject
  * Handles :
    EDWAY_tdhCircleArcObject
----------------------------------------
Creation Date : 
  February 25,1997
Author : 
  Albert PAIS
----------------------------------------
Members :
  * Type    : MTH3D_tdhCircleArcCurve
    Name    : m_hCircleArcCurve
    Meaning : A handle on the mathematical
              circle arc 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 circle arc curve
              in case mode=C_ucModeNoObject
  * Type    : ACP_tdstDynaParam
    Name    : m_pstDynaParams
    Meaning : A pointer on the dynamic
              params associated
  * Type    : MTH3D_tdstMatrix
    Name    : m_stLocalRepere
    Meaning : The local repere
  * Type    : MTH3D_tdstMatrix
    Name    : m_stInvLocalRepere
    Meaning : The inverse matrix of the 
              local repere
  * Type    : MTH3D_tdstVector
    Name    : m_stLocalStartPoint
    Meaning : The starting point
              in the local repere
  * Type    : MTH3D_tdstVector
    Name    : m_stLocalEndPoint
    Meaning : The ending point
              in the local repere
  * Type    : MTH_tdxReal
    Name    : m_xMainAngle
    Meaning : The angle between OA,OB,
              O stands for the center
              A stands for the starting point
              B stands for the ending point
  * Type    : unsigned char
    Name    : m_ucObjectMode
    Meaning : the object mode :
              C_ucModeNoObject or C_ucModeRealObject
---------------------------------------
*/
#ifdef _EDWAY_CIRCLEARC_FRIEND_
typedef struct EDWAY_tdstCircleArcObject_
{
 MTH3D_tdhCircleArcCurve m_hCircleArcCurve;
	
 ACP_tdxHandleOfObject m_hGeometricObject;
	ACP_tdxHandleOfElement m_hLineElement;
	long m_lColor;
	GLD_tdstViewportAttributes	*m_pstViewPortAttributes;
//	MTH3D_tdstVector *m_dstListOfPoints;
	MTH3D_tdstVector** m_pdstListOfPoints;

	ACP_tdstDynaParam *m_pstDynaParams;
 
 MTH3D_tdstMatrix m_stLocalRepere;
 MTH3D_tdstMatrix m_stInvLocalRepere;
 MTH3D_tdstVector m_stLocalStartPoint;
 MTH3D_tdstVector m_stLocalEndPoint;
 MTH_tdxReal m_xMainAngle;
	
 unsigned char m_ucObjectMode;
} EDWAY_tdstCircleArcObject;
#endif /* _EDWAY_CIRCLEARC_FRIEND_ */
typedef struct EDWAY_tdstCircleArcObject_* EDWAY_tdhCircleArcObject;

#endif /* !__EDICIAR_TYPES__ */

#if !defined(ONLY_TYPES)

#if !defined(__EDICIAR_VARS__)
#define __EDICIAR_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_hInvalidCircleArcObject ((EDWAY_tdhCircleArcObject)0)
/* no geometric object created : */ 
#define EDWAY_C_ucModeNoObject	((unsigned char)0)
/* a geometric object is created */
#define EDWAY_C_ucModeRealObject	((unsigned char)1)

#undef extern
#endif /* !__EDICIAR_VARS__ */

#if !defined (__EDICIAR_PROTOS__)
#define __EDICIAR_PROTOS__

/*
------------------------------------------------------------------------------------------
MACROS-FUNCTIONS DECLARATION:
------------------------------------------------------------------------------------------
*/
#ifdef _EDWAY_CIRCLEARC_FRIEND_
#define EDWAY_M_vCircleArcObjectGetPointerParam(_hCirArcObj,_pxPointer,_SlotName)\
 (*(_pxPointer) = (_hCirArcObj)->m_st##_SlotName##)
#define EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcObj,_Prefix,_SlotName)\
 ((_hCirArcObj)->m_##_Prefix## ##_SlotName##)
#define EDWAY_M_vCircleArcObjectSetPointerParam(_hCirArcObj,_pxPointer,_SlotName)\
 ((_hCirArcObj)->m_st##_SlotName## = *(_pxPointer))
#define EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcObj,_xScalar,_Prefix,_SlotName)\
 ((_hCirArcObj)->m_##_Prefix## ##_SlotName## = (_xScalar))

#define EDWAY_M_uwCircleArcObjectSizeOf()\
 ((unsigned short)(sizeof(struct EDWAY_tdstCircleArcObject_)))

/* Only defined for friend!!!!! */
/* not very clean, but efficient :*/
#define EDWAY_M_pstCircleArcObjectGetLocalRepere(_hCirArcObj)\
 (&(EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcObj,st,LocalRepere)))
#define EDWAY_M_pstCircleArcObjectGetInvLocalRepere(_hCirArcObj)\
 (&(EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcObj,st,InvLocalRepere)))
#define EDWAY_M_pstCircleArcObjectGetLocalStartPoint(_hCirArcObj)\
 (&(EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcObj,st,LocalStartPoint)))
#define EDWAY_M_pstCircleArcObjectGetLocalEndPoint(_hCirArcObj)\
 (&(EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcObj,st,LocalEndPoint)))

#else /* _EDWAY_CIRCLEARC_FRIEND_ */
#define EDWAY_M_vCircleArcObjectGetPointerParam(_hCirArcObj,_pxPointer,_SlotName)\
 (EDWAY_fnv_CircleArcObject_Get##_SlotName##(_hCirArcObj,_pxPointer))
#define EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcObj,_Prefix,_SlotName)\
 (EDWAY_fn##_Prefix##_CircleArcObject_Get##_SlotName##(_hCirArcObj))
#define EDWAY_M_vCircleArcObjectSetPointerParam(_hCirArcObj,_pxPointer,_SlotName)\
 (EDWAY_fnv_CircleArcObject_Set##_SlotName##(_hCirArcObj,_pxPointer))
#define EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcObj,_xScalar,_Prefix,_SlotName)\
 (EDWAY_fnv_CircleArcObject_Set##_SlotName##(_hCirArcObj,_xScalar))

#define EDWAY_M_uwCircleArcObjectSizeOf()\
 EDWAY_fnuw_CircleArcObject_SizeOf()

#endif /* _EDWAY_CIRCLEARC_FRIEND_ */

#define EDWAY_M_hCircleArcObjectGetCircleArcCurve(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,h,CircleArcCurve)
#define EDWAY_M_hCircleArcObjectGetGeometricObject(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,h,GeometricObject)
#define EDWAY_M_hCircleArcObjectGetLineElement(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,h,LineElement)
#define EDWAY_M_lCircleArcObjectGetColor(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,l,Color)
#define EDWAY_M_pstCircleArcObjectGetViewPortAttributes(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,pst,ViewPortAttributes)
#define EDWAY_M_dstCircleArcObjectGetListOfPoints(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,dst,ListOfPoints)
#define EDWAY_M_pstCircleArcObjectGetDynaParams(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,pst,DynaParams)
#define EDWAY_M_vCircleArcObjectGetLocalRepere(_hCirArcCon,_pstLocRep)\
 EDWAY_M_vCircleArcObjectGetPointerParam(_hCirArcCon,_pstLocRep,LocalRepere)
#define EDWAY_M_vCircleArcObjectGetInvLocalRepere(_hCirArcCon,_pstInvLocRep)\
 EDWAY_M_vCircleArcObjectGetPointerParam(_hCirArcCon,_pstInvLocRep,InvLocalRepere)
#define EDWAY_M_vCircleArcObjectGetLocalStartPoint(_hCirArcCon,_pstLocStaPoi)\
 EDWAY_M_vCircleArcObjectGetPointerParam(_hCirArcCon,_pstLocStaPoi,LocalStartPoint)
#define EDWAY_M_vCircleArcObjectGetLocalEndPoint(_hCirArcCon,_pstLocEndPoi)\
 EDWAY_M_vCircleArcObjectGetPointerParam(_hCirArcCon,_pstLocEndPoi,LocalEndPoint)
#define EDWAY_M_xCircleArcObjectGetMainAngle(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,x,MainAngle)
#define EDWAY_M_ucCircleArcObjectGetObjectMode(_hCirArcCon)\
 EDWAY_M_xCircleArcObjectGetScalarParam(_hCirArcCon,uc,ObjectMode)

#define EDWAY_M_vCircleArcObjectSetCircleArcCurve(_hCirArcCon,_hCirArcCur)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_hCirArcCur,h,CircleArcCurve)
#define EDWAY_M_vCircleArcObjectSetGeometricObject(_hCirArcCon,_hGeoObj)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_hGeoObj,h,GeometricObject)
#define EDWAY_M_vCircleArcObjectSetLineElement(_hCirArcCon,_LinEle)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_LinEle,h,LineElement)
#define EDWAY_M_vCircleArcObjectSetColor(_hCirArcCon,_lCol)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_lCol,l,Color)
#define EDWAY_M_vCircleArcObjectSetViewPortAttributes(_hCirArcCon,_pstViePorAtt)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_pstViePorAtt,pst,ViewPortAttributes)
#define EDWAY_M_vCircleArcObjectSetListOfPoints(_hCirArcCon,_dstLisOfPts)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_dstLisOfPts,dst,ListOfPoints)
#define EDWAY_M_vCircleArcObjectSetDynaParams(_hCirArcCon,_pstDynPar)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_pstDynPar,pst,DynaParams)
#define EDWAY_M_vCircleArcObjectSetLocalRepere(_hCirArcCon,_pstLocRep)\
 EDWAY_M_vCircleArcObjectSetPointerParam(_hCirArcCon,_pstLocRep,LocalRepere)
#define EDWAY_M_vCircleArcObjectSetInvLocalRepere(_hCirArcCon,_pstInvLocRep)\
 EDWAY_M_vCircleArcObjectSetPointerParam(_hCirArcCon,_pstInvLocRep,InvLocalRepere)
#define EDWAY_M_vCircleArcObjectSetLocalStartPoint(_hCirArcCon,_pstLocStaPoi)\
 EDWAY_M_vCircleArcObjectSetPointerParam(_hCirArcCon,_pstLocStaPoi,LocalStartPoint)
#define EDWAY_M_vCircleArcObjectSetLocalEndPoint(_hCirArcCon,_pstLocEndPoi)\
 EDWAY_M_vCircleArcObjectSetPointerParam(_hCirArcCon,_pstLocEndPoi,LocalEndPoint)
#define EDWAY_M_vCircleArcObjectSetMainAngle(_hCirArcCon,_xNewMainAng)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_xNewMainAng,x,MainAngle)
#define EDWAY_M_vCircleArcObjectSetObjectMode(_hCirArcCon,_ucObjMod)\
 EDWAY_M_vCircleArcObjectSetScalarParam(_hCirArcCon,_ucObjMod,uc,ObjectMode)

/*
------------------------------------------------------------------------------------------
FUNCTIONS DECLARATION:
------------------------------------------------------------------------------------------
*/
/* creation and destruction of the structure */
EDWAY_tdhCircleArcObject EDWAY_fnh_CircleArcObject_CreateSturcture(void);
void EDWAY_fnv_CircleArcObject_DestroyStructure(EDWAY_tdhCircleArcObject);

/* Creation :*/
void EDWAY_fnv_CircleArcObject_Create
(EDWAY_tdhCircleArcObject,unsigned char,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*,unsigned char,ACP_tdstDynaParam*,MTH3D_tdstVector** pdstListOfPoints);

void EDWAY_fnv_CircleArcObject_CreateFromCurve
(
	EDWAY_tdhCircleArcObject	_hCircleArcObject,
	MTH3D_tdhCircleArcCurve		_hCircleArcCurve,
	unsigned char				_ucObjectMode,
	ACP_tdstDynaParam*			_pstDynaParams,
	MTH3D_tdstVector**			pdstListOfPoints
);

void EDWAY_fnv_CircleArcObject_Free(EDWAY_tdhCircleArcObject);

/* computing points :*/
void EDWAY_fnv_CircleArcObject_Calculate
(EDWAY_tdhCircleArcObject);

/* getting the size of the structure :*/
unsigned short EDWAY_fnuw_CircleArcObject_SizeOf(void);

/* Getting fields values :*/
MTH3D_tdhCircleArcCurve EDWAY_fnh_CircleArcObject_GetCircleArcCurve(EDWAY_tdhCircleArcObject);
ACP_tdxHandleOfObject EDWAY_fnh_CircleArcObject_GetGeometricObject(EDWAY_tdhCircleArcObject);
ACP_tdxHandleOfElement EDWAY_fnh_CircleArcObject_GetLineElement(EDWAY_tdhCircleArcObject);
long EDWAY_fnl_CircleArcObject_GetColor(EDWAY_tdhCircleArcObject);
GLD_tdstViewportAttributes* EDWAY_fnpst_CircleArcObject_GetViewPortAttributes(EDWAY_tdhCircleArcObject);
MTH3D_tdstVector* EDWAY_fndst_CircleArcObject_GetListOfPoints(EDWAY_tdhCircleArcObject);
ACP_tdstDynaParam* EDWAY_fnpst_CircleArcObject_GetDynaParams(EDWAY_tdhCircleArcObject);
void EDWAY_fnv_CircleArcObject_GetLocalRepere(EDWAY_tdhCircleArcObject,MTH3D_tdstMatrix*);
void EDWAY_fnv_CircleArcObject_GetInvLocalRepere(EDWAY_tdhCircleArcObject,MTH3D_tdstMatrix*);
void EDWAY_fnv_CircleArcObject_GetLocalStartPoint(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*);
void EDWAY_fnv_CircleArcObject_GetLocalEndPoint(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*);
MTH_tdxReal EDWAY_fnx_CircleArcObject_GetMainAngle(EDWAY_tdhCircleArcObject);
unsigned char EDWAY_fnuc_CircleArcObject_GetObjectMode(EDWAY_tdhCircleArcObject);

/* changing (and only changing) fields value */
void EDWAY_fnv_CircleArcObject_SetCircleArcCurve(EDWAY_tdhCircleArcObject,MTH3D_tdhCircleArcCurve);
void EDWAY_fnv_CircleArcObject_SetGeometricObject(EDWAY_tdhCircleArcObject,ACP_tdxHandleOfObject);
void EDWAY_fnv_CircleArcObject_SetLineElement(EDWAY_tdhCircleArcObject,ACP_tdxHandleOfElement);
void EDWAY_fnv_CircleArcObject_SetColor(EDWAY_tdhCircleArcObject,long);
void EDWAY_fnv_CircleArcObject_SetViewPortAttributes(EDWAY_tdhCircleArcObject,GLD_tdstViewportAttributes*);
void EDWAY_fnv_CircleArcObject_SetListOfPoints(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*);
void EDWAY_fnv_CircleArcObject_SetDynaParams(EDWAY_tdhCircleArcObject,ACP_tdstDynaParam *);
void EDWAY_fnv_CircleArcObject_SetLocalRepere(EDWAY_tdhCircleArcObject,MTH3D_tdstMatrix*);
void EDWAY_fnv_CircleArcObject_SetInvLocalRepere(EDWAY_tdhCircleArcObject,MTH3D_tdstMatrix*);
void EDWAY_fnv_CircleArcObject_SetLocalStartPoint(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*);
void EDWAY_fnv_CircleArcObject_SetLocalEndPoint(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*);
void EDWAY_fnv_CircleArcObject_SetMainAngle(EDWAY_tdhCircleArcObject,MTH_tdxReal);
void EDWAY_fnv_CircleArcObject_SetObjectMode(EDWAY_tdhCircleArcObject,unsigned char);

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

void EDWAY_fnv_CircleArcObject_ChangeParams
(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*);

void  EDWAY_fnv_CircleArcObject_GetParams
(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*,MTH3D_tdstVector*,MTH3D_tdstVector*);

/* retrieving speed :*/
MTH_tdxReal fn_xCircleArcObject_GetSpeed
(EDWAY_tdhCircleArcObject,unsigned char);

/* retrieving point */
void EDWAY_fnv_CircleArcObject_GetPoint
(EDWAY_tdhCircleArcObject,unsigned char,MTH3D_tdstVector*);

/* drawing the circle arc object */
void EDWAY_fnv_CircleArcObject_Draw(EDWAY_tdhCircleArcObject);

void EDWAY_fnv_CircleArcObject_GlobalToLocal(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*,MTH3D_tdstVector*);
void EDWAY_fnv_CircleArcObject_LocalToGlobal(EDWAY_tdhCircleArcObject,MTH3D_tdstVector*,MTH3D_tdstVector*);

#endif /* !__EDICIAR_PROTOS__ */

#endif /* !ONLY_TYPES */