// Implementation file for the definition of a characteristic base type
////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"

#include "Data\CTL_Dat.hpp"

#include "Others\CTL_Pub.hpp"
#include "Others\CTL_Pri.hpp"

//External Modules
#include "CTL_ErO.hpp"
//End of External Modules

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

//Constructor / Destructor
//************************************************************************
CTL_Editor_Data::CTL_Editor_Data(CTL_tdeEditorDataType _tdeType,
																 CString _csDataName,
																 CTL_Editor_DataList *_pclParentList,
																 CTL_Editor_Data *_pclCurrentBaseData /*= NULL*/,
																 long _lUSerDefinedDataType /*= 0*/)
{
	m_pro_tdeDataType = _tdeType;

	m_pro_pvMotorData = NULL;
	m_pri_pclParentList = _pclParentList;

	m_pro_bDataHasChanged = TRUE;

	m_pro_csDataName = _csDataName;

	//Sets Initial and Current Data links
	m_pclAssociatedCurrentData = NULL;
	m_pclAssociatedInitialData = NULL;

	m_pro_pclParentControl = NULL;

	//If a current data corresponds to 'this' data, sets 'this' as the
	// initial data of the other
	if ( _pclCurrentBaseData != NULL )
	{
		m_fn_vSetAssociatedCurrentData(_pclCurrentBaseData);
		m_pclAssociatedCurrentData->m_fn_vSetAssociatedInitialData(this);
	}

	m_pro_lUSerDefinedDataType = _lUSerDefinedDataType;

	//CallBack functions
	m_pro_td_p_fn_vDataHasChangedCallBack = CTL_g_p_fnDefaultCallBack_DataHasChanged;
	m_pro_td_p_fn_vDataHasChangedSpecialCallBack = NULL;

	m_pro_td_p_fn_vDataModifWhenRead = NULL;
	m_pro_td_p_fn_vDataModifWhenWrite = NULL;

	m_pro_td_p_fn_bDataMustBeRead = NULL;
	m_pro_td_p_fn_bDataMustBeWritten = NULL;
}

//************************************************************************
CTL_Editor_Data::~CTL_Editor_Data()
{
	// Removes from Watch Window if necessary
//	if	(		(g_pclInterface->m_pclWatchWindow != NULL)
//			&&	(m_bIsInWatch)
//			)
//		g_pclInterface->m_pclWatchWindow->m_fn_vRemoveValue(this);
}

//Member functions

//**************************************************************************************
//Function called to Init the data
void CTL_Editor_Data::m_fn_vInitData()
{

}

// BEGIN ROMTEAM Cristi Petrescu 98-11-
#include "scr.h"
#include "ai/aibase/gsparam.h"
// END ROMTEAM Cristi Petrescu 98-11-
//************************************************************************
void CTL_Editor_Data::m_fn_vSetMotorDataPtr(void *p_vMotorData)
{
	// BEGIN ROMTEAM Cristi Petrescu 98-11-
	tduGetSetParam *p_TMotorData = (tduGetSetParam *)p_vMotorData;
	// END ROMTEAM Cristi Petrescu 98-11-
	m_pro_pvMotorData = p_vMotorData;
}

//************************************************************************
void *CTL_Editor_Data::m_fn_pvGetMotorDataPtr()
{
	return m_pro_pvMotorData;
}

//*********************************************************************************
CTL_OwnerData *CTL_Editor_Data::m_pub_fn_pclAddOwnerData(void *_pvDataPtr,
																												 CString _csName)
{
	return m_pri_clListOfOwnerData.m_pub_fn_pclAddOwnerData(_pvDataPtr, _csName);
}

//*********************************************************************************
CTL_OwnerData *CTL_Editor_Data::m_pub_fn_pclAddOwnerData(long _lData,
																												 CString _csName)
{
	return m_pri_clListOfOwnerData.m_pub_fn_pclAddOwnerData(_lData, _csName);
}

//*********************************************************************************
CTL_OwnerData *CTL_Editor_Data::m_pub_fn_pclGetOwnerDataWithName(CString _csSearchedName)
{
	return m_pri_clListOfOwnerData.m_pub_fn_pclFindOwnerDataWithName(_csSearchedName);
}

//*********************************************************************************
//Parent List of Data
CTL_Editor_DataList *CTL_Editor_Data::m_pub_fn_pclGetParentList()
{
	return m_pri_pclParentList;
}

//*********************************************************************************
//User Defined Data type
long CTL_Editor_Data::m_pub_fn_lGetUSerDefinedDataType()
{
	return m_pro_lUSerDefinedDataType;
}

//************************************************************************
CStringList *CTL_Editor_Data::m_fn_pcslFormatDataValueString()
{
	m_csStringList.RemoveAll();
	m_csStringList.AddTail("NO APPROPRIATE SAVING FOR THIS DATA !");
	
	return &m_csStringList;
}

//************************************************************************
//Returns the name of the Data
CString CTL_Editor_Data::m_pub_fn_csGetDataName()
{
	return m_pro_csDataName;
}

//************************************************************************
//Get/Set for the Parent Control
CTL_Editor_Control *CTL_Editor_Data::m_pub_fn_pclGetParentControl()
{
	return m_pro_pclParentControl;
}

//************************************************************************
void CTL_Editor_Data::m_pub_fn_vSetParentControl(CTL_Editor_Control *_pclParentControl)
{
	m_pro_pclParentControl = _pclParentControl;
}

//************************************************************************
//Get/Set for the pointer on motor's data
void *CTL_Editor_Data::m_pub_fn_pvGetMotorData()
{
	return m_pro_pvMotorData;
}

//************************************************************************
void CTL_Editor_Data::m_pub_fn_vSetMotorData(void *_p_vMotorData)
{
	m_pro_pvMotorData = _p_vMotorData;
}

//************************************************************************
//Indicates wether current value is different from the old one or not
// (used during motor run)
BOOL CTL_Editor_Data::m_pub_fn_bGetDataHasChanged()
{
	return m_pro_bDataHasChanged;
}	 

//************************************************************************
void CTL_Editor_Data::m_pub_fn_vSetDataHasChanged(BOOL _bNewSate)
{
	m_pro_bDataHasChanged = _bNewSate;
}

//************************************************************************
CTL_tdeEditorDataType CTL_Editor_Data::m_pub_fn_tdeGetDataType()
{
	return m_pro_tdeDataType;
}

//Link between initial and current Data
//The associated current Data
//************************************************************************
BOOL CTL_Editor_Data::m_fn_bHasACurrentData()
{
	return ( m_pclAssociatedCurrentData != NULL );
}

//************************************************************************
CTL_Editor_Data *CTL_Editor_Data::m_fn_pclGetAssociatedCurrentData()
{
	return m_pclAssociatedCurrentData;
}

//************************************************************************
void CTL_Editor_Data::m_fn_vSetAssociatedCurrentData(CTL_Editor_Data *pclData)
{
	ERROR_ASSERT( m_pro_tdeDataType == pclData->m_pro_tdeDataType );
	m_pclAssociatedCurrentData = pclData;
}

//The associated Initial Data
//************************************************************************
BOOL CTL_Editor_Data::m_fn_bHasAnInitialData()
{
	return ( m_pclAssociatedInitialData != NULL );
}

//************************************************************************
CTL_Editor_Data *CTL_Editor_Data::m_fn_pclGetAssociatedInitialData()
{
	return m_pclAssociatedInitialData;
}

//************************************************************************
void CTL_Editor_Data::m_fn_vSetAssociatedInitialData(CTL_Editor_Data *pclData)
{	
	//This must be already done
	ERROR_ASSERT( pclData->m_pclAssociatedCurrentData == this );
	ERROR_ASSERT( m_pro_tdeDataType == pclData->m_pro_tdeDataType );
	m_pclAssociatedInitialData = pclData;
}

//************************************************************************
//Set : CallBack function : called when Data has changed
void CTL_Editor_Data::m_pub_fn_vSetDataChangedCallBackFunction(CTL_td_p_fn_vCallBackWhenDataHasChanged _td_p_fn_vDataHasChangedCallBack)
{
	ERROR_ASSERT( m_pro_td_p_fn_vDataHasChangedCallBack == NULL );

	m_pro_td_p_fn_vDataHasChangedCallBack = _td_p_fn_vDataHasChangedCallBack;
}

//************************************************************************
//Set : CallBack function : called when Data has changed (specific for one type of Data)
void CTL_Editor_Data::m_pub_fn_vSetDataChangedSpecialCallBackFunction(CTL_td_p_fn_vCallBackWhenDataHasChanged _td_p_fn_vDataHasChangedSpecialCallBack)
{
	ERROR_ASSERT( m_pro_td_p_fn_vDataHasChangedSpecialCallBack == NULL );

	m_pro_td_p_fn_vDataHasChangedSpecialCallBack = _td_p_fn_vDataHasChangedSpecialCallBack;
}

//**************************************************************************************
void CTL_Editor_Data::m_fn_vDataHasBeenChanged(CTL_tdeUpdateReason _eReason,
																							 long _lUserDefinedReason /*= 0*/)
{
	if ( m_pro_td_p_fn_vDataHasChangedCallBack != NULL )
		m_pro_td_p_fn_vDataHasChangedCallBack(this, _eReason, _lUserDefinedReason);
	if ( m_pro_td_p_fn_vDataHasChangedSpecialCallBack != NULL )
		m_pro_td_p_fn_vDataHasChangedSpecialCallBack(this, _eReason, _lUserDefinedReason);
}

//Modification Functions
//************************************************************************
void CTL_Editor_Data::m_pub_fn_vSetModificationFunctionWhenRead(CTL_tdp_fn_vDataModificationFunction p_fn_vDataModifWhenRead)
{
	ERROR_ASSERT( m_pro_td_p_fn_vDataModifWhenRead == NULL );

	m_pro_td_p_fn_vDataModifWhenRead = p_fn_vDataModifWhenRead;
}

//************************************************************************
void CTL_Editor_Data::m_pub_fn_vSetModificationFunctionWhenWrite(CTL_tdp_fn_vDataModificationFunction p_fn_vDataModifWhenWrite)
{
	ERROR_ASSERT( m_pro_td_p_fn_vDataModifWhenWrite == NULL );

	m_pro_td_p_fn_vDataModifWhenWrite = p_fn_vDataModifWhenWrite;
}

//************************************************************************
//When Data must be Read or Write
void CTL_Editor_Data::m_pub_fn_vSetDataMustBeRead_CallBack(CTL_td_p_fn_bCallBackWhenDataMustBeReadOrWritten _p_fn_CallBack)
{
	ERROR_ASSERT( m_pro_td_p_fn_bDataMustBeRead == NULL );

	m_pro_td_p_fn_bDataMustBeRead = _p_fn_CallBack;
}

//************************************************************************
void CTL_Editor_Data::m_pub_fn_vSetDataMustBeWritten_CallBack(CTL_td_p_fn_bCallBackWhenDataMustBeReadOrWritten _p_fn_CallBack)
{
	ERROR_ASSERT( m_pro_td_p_fn_bDataMustBeWritten == NULL );

	m_pro_td_p_fn_bDataMustBeWritten = _p_fn_CallBack;
}


