reman3/Rayman_X/cpa/tempgrp/Ctl/Src/Data/CTL_DatI.cpp

189 lines
6.2 KiB
C++

// Implementation file for the definition of an integer characteristic
///////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "Data\CTL_DatI.hpp"
#include "Controls\CTL_Ctl.hpp"
#include "Others\CTL_Pub.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_IntegerData::CTL_Editor_IntegerData(char cDataSize,
BOOL bSigned,
CString csScriptName,
CTL_Editor_DataList *_pclParentList,
CTL_Editor_Data *pclCurrentBaseData /*= NULL*/)
: CTL_Editor_Data(CTL_DATA_TYPE__INTEGER,
csScriptName,
_pclParentList,
pclCurrentBaseData)
{
m_cDataSize = cDataSize;
m_bSigned = bSigned;
m_lCurrentValue = 0;
}
//************************************************************************************
CTL_Editor_IntegerData::~CTL_Editor_IntegerData()
{
}
//Member functions
//**************************************************************************************
//Function called to Init the data
void CTL_Editor_IntegerData::m_fn_vInitData()
{
}
//************************************************************************************
//Function called to read associated motor's data
void CTL_Editor_IntegerData::m_fn_vGetMotorData()
{
BOOL bMustReadData = TRUE;
if ( m_pro_td_p_fn_bDataMustBeRead != NULL )
bMustReadData &= m_pro_td_p_fn_bDataMustBeRead(this);
if ( bMustReadData )
{
m_lCurrentValue = 0;
CTL_fn_vGetMemory(m_pub_fn_pvGetMotorData(), &m_lCurrentValue, m_cDataSize);
//Calls Modification function if needed
if ( m_pro_td_p_fn_vDataModifWhenRead != NULL )
m_pro_td_p_fn_vDataModifWhenRead(this);
}
}
//************************************************************************************
//Function called to update associated motor's data
void CTL_Editor_IntegerData::m_fn_vUpdateMotorData(CTL_tdeUpdateReason eReason,
long _lUserDefinedReason /*= 0*/)
{
BOOL bMustWriteData = TRUE;
if ( m_pro_td_p_fn_bDataMustBeWritten != NULL )
bMustWriteData &= m_pro_td_p_fn_bDataMustBeWritten(this);
if ( bMustWriteData )
{
//Calls Modification function if needed
if ( m_pro_td_p_fn_vDataModifWhenWrite != NULL )
m_pro_td_p_fn_vDataModifWhenWrite(this);
CTL_fn_vSetMemory(m_pub_fn_pvGetMotorData(), &m_lCurrentValue, m_cDataSize);
//Calls Modification function if needed
if ( m_pro_td_p_fn_vDataModifWhenRead != NULL )
m_pro_td_p_fn_vDataModifWhenRead(this);
//Special changes
m_fn_vDataHasBeenChanged(eReason, _lUserDefinedReason);
}
}
//************************************************************************
//Function called to update data with another one
void CTL_Editor_IntegerData::m_fn_vUpdateData(CTL_Editor_Data *pclSourceData,
CTL_tdeUpdateReason eReason,
long _lUserDefinedReason /*= 0*/)
{
ERROR_ASSERT(pclSourceData->m_pub_fn_tdeGetDataType() == m_pub_fn_tdeGetDataType());
m_cDataSize = ((CTL_Editor_IntegerData *)pclSourceData)->m_cDataSize;
m_bSigned = ((CTL_Editor_IntegerData *)pclSourceData)->m_bSigned;
m_lCurrentValue = ((CTL_Editor_IntegerData *)pclSourceData)->m_lCurrentValue;
m_fn_vUpdateMotorData(eReason, _lUserDefinedReason);
}
//************************************************************************
//Function called to get a string representing the value of the data
CStringList *CTL_Editor_IntegerData::m_fn_pcslFormatDataValueString()
{
m_csStringList.RemoveAll();
CString csStringToReturn;
csStringToReturn.Format("%ld", m_lCurrentValue);
m_csStringList.AddTail(csStringToReturn);
return &m_csStringList;
}
//************************************************************************
//Function called to set the value of the data acoording to a string representing it
void CTL_Editor_IntegerData::m_fn_vSetValueWithString(CStringList *pcslValueStringList)
{
ERROR_ASSERT(pcslValueStringList->GetCount() == 1);
CString csValueString = pcslValueStringList->GetHead();
m_lCurrentValue = atoi(LPCTSTR(csValueString));
m_fn_vUpdateMotorData();
}
//************************************************************************
//Function called to look if data has been modified (by motor for example)
void CTL_Editor_IntegerData::m_fn_vLookIfDataHasBeenModified()
{
m_fn_vGetMotorData();
m_pub_fn_vSetDataHasChanged(m_lCurrentValue != m_lOldValue);
if ( m_pub_fn_bGetDataHasChanged() )
m_lOldValue = m_lCurrentValue;
}
//Undo
//************************************************************************
//Function called to save the current Value (for Undo)
void CTL_Editor_IntegerData::m_fn_vKeepCurrentValue()
{
m_lKeepedValueForUndo = m_lCurrentValue;
}
//************************************************************************
//Function called to validate Undo for the current change
void CTL_Editor_IntegerData::m_fn_vRegisterUndoAction()
{
/* if ( m_lKeepedValueForUndo != m_lCurrentValue )
{
EdActors_ActorIntegerDataModif *pclModif = new EdActors_ActorIntegerDataModif(this,
m_lKeepedValueForUndo,
m_lCurrentValue);
m_pclParentActor->m_clUndoManager.AskFor(pclModif);
}
*/}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : mfn_bEqualsModifiedDataOldValue
// Date : 98/06/24
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description :
// Author : Stegaru Cristian - CPA
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CTL_Editor_IntegerData::mfn_bEqualsModifiedDataOldValue (CTL_Editor_Data *pModifiedData)
{
ASSERT (pModifiedData);
ERROR_ASSERT(pModifiedData->m_pub_fn_tdeGetDataType() == m_pub_fn_tdeGetDataType());
return m_lCurrentValue == ((CTL_Editor_IntegerData *)pModifiedData)->m_lOldValue;
}