// The one and only file to be touched to accomodate this editor with your project
////////////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include <limits.h>
#include <float.h>

#include "EditMDef.hpp"

#include "EMECDoc.hpp"
#include "EMECAllo.hpp"
#include "EMECDtMd.hpp"
#include "EMECFlds.hpp"
#include "EMECClBk.hpp"
#include "EMECCStr.hpp"
#include "_Minterf.hpp"

//External Modules
#include "ErO.h"
#include "CTL.h"
//End of External Modules

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//**********************************************************************************************
void CPA_Meca_MyDocument::m_fn_vFillCardsTypeList()
{
	CPA_Meca_CardType *pclCardType;

	/// For Controls
	CTL_fn_vSetDefaultCallBackFunctionWhenControlMustBeDisplayed(TME_fn_bControlCanBeDisplayedCallBack);
	/// End of  'For Controls'

	///////// Adds a Card Type ///////////															
	pclCardType = m_clCardTypeList.m_fn_pclAddElement("Camera Cards", DNM_eCamera);
	/// Defines it ///
	pclCardType->m_p_fn_vUnallocate = &fn_vUnalloc6;
	pclCardType->m_p_fn_vFill = &fn_vFillCard6;
	pclCardType->m_p_fn_vSave = &fn_vSaveCard6;
	pclCardType->m_fn_vSetFileName("Camera.mec");
	pclCardType->m_fn_vSetActionName(C_SectionIdCardCamera);

	//+++++++++++++++++++++++++++++++ Describes the Card Type +++++++++++++++++++++++++++++++
	pclCardType->m_fn_vAddDecimalControl(-FLT_MAX, FLT_MAX, EDMEC_FLOAT, EDMEC_READ_WRITE, "Linear Speed");
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	pclCardType->m_fn_vAddDecimalControl( -FLT_MAX, FLT_MAX, EDMEC_FLOAT, EDMEC_READ_WRITE, "Angular Delta (rad/s)");
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	pclCardType->m_fn_vAddDecimalControl(-FLT_MAX, FLT_MAX, EDMEC_FLOAT, EDMEC_READ_WRITE, "Speeding Up (m/s)");
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


	///////// Base ///////////															
	pclCardType = m_clCardTypeList.m_fn_pclAddElement("Base Cards", DNM_eBase);
	/// Defines it ///
	pclCardType->m_p_fn_vUnallocate = &fn_vUnallocRay2Egypte1;
	pclCardType->m_p_fn_vFill = &fn_vFillCardRay2Egypte1;
	pclCardType->m_p_fn_vSave = &fn_vSaveCardRay2Egypte1;
	pclCardType->m_fn_vSetFileName("Base.mec");
	pclCardType->m_fn_vSetActionName(C_SectionIdCardBase);

	//+++++++++++++++++++++++++++++++ Describes the Card Type +++++++++++++++++++++++++++++++
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Animation);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Collide);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Gravity);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Tilt);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Gi);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_OnGround);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Climb);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Spider);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Shoot);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Swim);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_CollisionControl);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_KeepSpeedZ);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_SpeedLimit);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Inertia);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Stream);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_StickOnPlatform);
	pclCardType->m_fn_vAddBooleanControl(EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Scale);


	pclCardType->m_fn_vAddDecimalControl(-100, 100, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_GravityFactor);
	pclCardType->m_fn_vAddDecimalControl(-100, 100, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Slide);
	pclCardType->m_fn_vAddDecimalControl(-100, 100, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_Rebound);
	pclCardType->m_fn_vAddDecimalControl(-90, 90, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_SlopeLimit);
	pclCardType->m_fn_vAddDecimalControl(-10, 10, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_InertiaFactorX);
	pclCardType->m_fn_vAddDecimalControl(-10, 10, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_InertiaFactorY);
	pclCardType->m_fn_vAddDecimalControl(-10, 10, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_InertiaFactorZ);
	pclCardType->m_fn_vAddDecimalControl(-10, 10, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_TiltIntensity);
	pclCardType->m_fn_vAddDecimalControl(-10, 10, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_TiltInertia);
	pclCardType->m_fn_vAddDecimalControl(-10, 10, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_TiltOrigin);
	pclCardType->m_fn_vAddDecimalControl(-100, 100, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_MaxSpeed + " x");
	pclCardType->m_fn_vAddDecimalControl(-100, 100, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_MaxSpeed + " y");
	pclCardType->m_fn_vAddDecimalControl(-100, 100, EDMEC_FLOAT, EDMEC_READ_WRITE,g_c_cs_FieldName_Base_MaxSpeed + " z");

	/// For Controls
	CTL_fn_vSetDefaultCallBackFunctionWhenControlMustBeDisplayed(NULL);
	/// End of  'For Controls'
}

#define TME_M_ADD_OWNER_DATA(a) \
	a->m_pub_fn_pclAddOwnerData((void *)pclCard, TME_g_c_cs_DataOwnerData_ParentCard);


//**********************************************************************************************
void fn_vFillCard6(CPA_Meca_Card *pclCard)
{
	if ( !pclCard->m_bDataCreated )
	{
		/// For Controls
		CTL_fn_vSetDefaultCallBackFunctionWhenDataHasChanged(TME_fn_vCallBackWhenADataHasChanged);
		/// End of  'For Controls'

		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, "Linear Speed"));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, "Angular Delta (rad/s)"));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, "Speeding Up (m/s)"));
		
		pclCard->m_bDataCreated = TRUE;
	
		/// For Controls
		CTL_fn_vSetDefaultCallBackFunctionWhenDataHasChanged(NULL);
		/// End of  'For Controls'
	}

	if ( pclCard->m_fn_pvGetBaseAddress() == NULL )
	{	
		POSITION pos = pclCard->m_clDataList.GetHeadPosition();
		while ( pos != NULL )
			(pclCard->m_clDataList.GetNext(pos))->m_fn_vSetMotorDataPtr(NULL);
	}
	else
	{
		POSITION pos = pclCard->m_clDataList.GetHeadPosition();
  		
		//Gets the struct
		DNM_stMecCameraIdCard	* pStruct = (DNM_stMecCameraIdCard *)pclCard->m_fn_pvGetBaseAddress();

		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xLinearSpeed)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xAngularSpeed)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xSpeedingUp)));

		ERROR_ASSERT(pos == NULL);
	}
}



void fn_vFillCardRay2Egypte1(CPA_Meca_Card *pclCard)
{
	if ( !pclCard->m_bDataCreated )
	{
		/// For Controls
		CTL_fn_vSetDefaultCallBackFunctionWhenDataHasChanged(TME_fn_vCallBackWhenADataHasChanged);
		/// End of  'For Controls'

		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0001, g_c_cs_FieldName_Base_Animation));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0002, g_c_cs_FieldName_Base_Collide));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0004, g_c_cs_FieldName_Base_Gravity));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0008, g_c_cs_FieldName_Base_Tilt));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0010, g_c_cs_FieldName_Base_Gi));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0020, g_c_cs_FieldName_Base_OnGround));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0040, g_c_cs_FieldName_Base_Climb));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0080, g_c_cs_FieldName_Base_Spider));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0001, g_c_cs_FieldName_Base_Shoot));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0002, g_c_cs_FieldName_Base_Swim));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0002, g_c_cs_FieldName_Base_CollisionControl));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0004, g_c_cs_FieldName_Base_KeepSpeedZ));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0008, g_c_cs_FieldName_Base_SpeedLimit));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0010, g_c_cs_FieldName_Base_Inertia));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0020, g_c_cs_FieldName_Base_Stream));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0040, g_c_cs_FieldName_Base_StickOnPlatform));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddBitFieldBooleanData(0x0080, g_c_cs_FieldName_Base_Scale));

		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_GravityFactor));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_Slide));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_Rebound));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_SlopeLimit));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_InertiaFactorX));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_InertiaFactorY));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_InertiaFactorZ));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_TiltIntensity));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_TiltInertia));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_TiltOrigin));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_MaxSpeed + " x" ));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_MaxSpeed + " y" ));
		TME_M_ADD_OWNER_DATA(pclCard->m_clDataList.m_fn_pclAddDecimalData(EDMEC_FLOAT, g_c_cs_FieldName_Base_MaxSpeed + " z" ));

		pclCard->m_bDataCreated = TRUE;


		/// For Controls
		CTL_fn_vSetDefaultCallBackFunctionWhenDataHasChanged(NULL);
		/// End of  'For Controls'
	}

	if ( pclCard->m_fn_pvGetBaseAddress() == NULL )
	{	
		POSITION pos = pclCard->m_clDataList.GetHeadPosition();
		while ( pos != NULL )
			(pclCard->m_clDataList.GetNext(pos))->m_fn_vSetMotorDataPtr(NULL);
	}
	else
	{
		POSITION pos = pclCard->m_clDataList.GetHeadPosition();
  		
		//Gets the struct
		DNM_tdstMecBaseIdCard	*pStruct = (DNM_tdstMecBaseIdCard *)pclCard->m_fn_pvGetBaseAddress();
		
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->ulFlags)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 2);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr(((char *)(&(pStruct->ulFlags))) + 1);

		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xGravity)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xSlide)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xRebound)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xSlopeLimit)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xInertiaX)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xInertiaY)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xInertiaZ)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xTiltIntensity)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xTiltInertia)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_xTiltOrigin)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_stMaxSpeed.xX)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_stMaxSpeed.xY)));
		pclCard->m_clDataList.GetNext(pos)->m_fn_vSetMotorDataPtr((void *)(&(pStruct->m_stMaxSpeed.xZ)));

		ERROR_ASSERT(pos == NULL);

	}
}

//**********************************************************************************************
//Constructs the objects representing the enum definitions
void CPA_Meca_MyDocument::m_fn_vConstructListOfEnumDescriptors()
{

}


