480 lines
13 KiB
C++
480 lines
13 KiB
C++
// Implementation for the definition of the class representing a Mechanical Card
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
#include "StdAfx.h"
|
|
|
|
#include "_MecCard.hpp"
|
|
|
|
#include "_Minterf.hpp"
|
|
#include "EMECStrg.hpp"
|
|
#include "EMECVwMn.hpp"
|
|
|
|
#include "Dpt.h"
|
|
#include "ErO.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
//***************************************************************************
|
|
CPA_Meca_Card::CPA_Meca_Card( CString csName,
|
|
CPA_Meca_CardType *pclCardType,
|
|
CString csEngineFileName,
|
|
CString csEngineActionName,
|
|
void *pvBaseAddress,
|
|
BOOL bCanbBeLoaded /*= FALSE*/)
|
|
|
|
: CPA_SaveObject( g_pclInterface,
|
|
g_c_csMecaCardTypeName,
|
|
E_ss_Responsible)
|
|
{
|
|
//Internal inits
|
|
m_pri_bIsNotified = FALSE;
|
|
|
|
//Section object
|
|
SetSectionData(this);
|
|
SetCallBackSave(s_m_fn_vCallBackSaveMecaCard);
|
|
SetDataPath(fn_szGetMechanicsDataPath());
|
|
|
|
m_pub_fn_vSetCompleteFileName(csEngineFileName);
|
|
m_pub_fn_vSetActionName(csEngineActionName);
|
|
|
|
SetReferencedSectionName(m_pri_fn_csComputeReferencedSectionName());
|
|
|
|
//Base objet
|
|
fn_bSetOwner(NULL);
|
|
|
|
//Name
|
|
if ( fn_eRename(csName) != E_mc_None )
|
|
SetDefaultValidName();
|
|
|
|
fn_vUpdateSectionName();
|
|
|
|
if ( pvBaseAddress != NULL )
|
|
SetExistingSection(TRUE);
|
|
else
|
|
{
|
|
if ( bCanbBeLoaded )
|
|
SetExistingSection(TRUE);
|
|
else
|
|
SetExistingSection(FALSE);
|
|
}
|
|
|
|
if ( !fn_bSectionExists() )
|
|
fn_vNotifySave();
|
|
|
|
//Specific Inits
|
|
m_pclCardType = pclCardType;
|
|
|
|
m_bDataCreated = FALSE;
|
|
|
|
//Allocates the structure
|
|
if ( pvBaseAddress == NULL )
|
|
{
|
|
if ( !bCanbBeLoaded )
|
|
m_fn_vSetBaseAddress( DNM_fn_xIdentityCardCreate(m_pclCardType->m_fn_tdeGetMotorID()) );
|
|
}
|
|
else
|
|
//There is an exiting Card (loaded by Motor)
|
|
m_fn_vSetBaseAddress( pvBaseAddress );
|
|
|
|
if ( !bCanbBeLoaded )
|
|
{
|
|
//Calls the filling function
|
|
ERROR_ASSERT( m_pclCardType->m_p_fn_vFill != NULL );
|
|
m_pclCardType->m_p_fn_vFill(this);
|
|
|
|
//Updates Editor values with motor ones
|
|
m_pri_fn_vGetAllMotorValues();
|
|
}
|
|
}
|
|
|
|
//***************************************************************************
|
|
CPA_Meca_Card::~CPA_Meca_Card()
|
|
{
|
|
//Unallocates the structure
|
|
ERROR_ASSERT( m_pclCardType->m_p_fn_vUnallocate != NULL );
|
|
m_pclCardType->m_p_fn_vUnallocate(this);
|
|
}
|
|
|
|
//***************************************************************************
|
|
void *CPA_Meca_Card::GetEngineStruct()
|
|
{
|
|
return m_fn_pvGetBaseAddress();
|
|
}
|
|
|
|
//***************************************************************************
|
|
void *CPA_Meca_Card::m_fn_pvGetBaseAddress()
|
|
{
|
|
return m_pvBaseAddress;
|
|
}
|
|
|
|
//***************************************************************************
|
|
void CPA_Meca_Card::m_fn_vSetBaseAddress(void *pvNewAddress)
|
|
{
|
|
//Base Object
|
|
fn_vUpdateData(pvNewAddress);
|
|
|
|
//Internal
|
|
m_pvBaseAddress = pvNewAddress;
|
|
}
|
|
|
|
//***************************************************************************
|
|
CString CPA_Meca_Card::m_fn_csGetCardName()
|
|
{
|
|
return CString(GetName());
|
|
}
|
|
|
|
//***************************************************************************
|
|
void CPA_Meca_Card::m_fn_vSetCardName(CString csNewName)
|
|
{
|
|
fn_eRename(csNewName);
|
|
}
|
|
|
|
//***************************************************************************
|
|
CPA_Meca_CardType *CPA_Meca_Card::m_fn_pclGetCardType()
|
|
{
|
|
return m_pclCardType;
|
|
}
|
|
|
|
//***************************************************************************
|
|
void CPA_Meca_Card::m_fn_pclSetCardType(CPA_Meca_CardType *pclNewType)
|
|
{
|
|
m_pclCardType = pclNewType;
|
|
}
|
|
|
|
//***************************************************************************
|
|
void CPA_Meca_Card::m_pri_fn_vGetAllMotorValues()
|
|
{
|
|
POSITION pos = m_clDataList.GetHeadPosition();
|
|
while ( pos != NULL )
|
|
m_clDataList.GetNext(pos)->m_fn_vGetMotorData();
|
|
}
|
|
|
|
//******************************************************************************
|
|
CString CPA_Meca_Card::m_pri_fn_csComputeReferencedSectionName()
|
|
{
|
|
CString csReferencedSectioName;
|
|
|
|
csReferencedSectioName = m_pub_fn_csGetReferencedFileName() + '^' + m_pub_fn_csGetActionName() + ':' + GetName();
|
|
|
|
return csReferencedSectioName;
|
|
}
|
|
|
|
//******************************************************************************
|
|
//Not to be used ...
|
|
CString CPA_Meca_Card::m_pri_fn_csComputeCompleteSectionName()
|
|
{
|
|
CString csCompleteSectioName;
|
|
|
|
CString csFileName /*= GetFileName()*/;
|
|
//Adds the Path to the file name
|
|
short wIndex = csFileName.ReverseFind('\\');
|
|
|
|
//If no Path is present
|
|
if ( wIndex == -1 )
|
|
{
|
|
//Security...
|
|
if ( csFileName == "NoFileName" )
|
|
{
|
|
csFileName = m_pclCardType->m_fn_csGetFileName();
|
|
// SetActionName(m_pclCardType->m_fn_csGetActionName());
|
|
}
|
|
|
|
csFileName = "GameData\\World\\Libraries\\Mechanics\\" + csFileName;
|
|
// SetFileName(csFileName);
|
|
}
|
|
|
|
// csCompleteSectioName = GetFileName() + '^' + GetActionName() + ':' + GetName();
|
|
|
|
return csCompleteSectioName;
|
|
}
|
|
|
|
//For Save
|
|
//******************************************************************************
|
|
/*void CPA_Meca_Card::fn_vNotify(SCR_tde_Ntfy_Action _eAction)
|
|
{
|
|
|
|
switch( _eAction )
|
|
{
|
|
case SCR_EA_Ntfy_RebuildSection:
|
|
case SCR_EA_Ntfy_ModifySection:
|
|
case SCR_EA_Ntfy_AddSection:
|
|
SCR_fn_v_SvL1_RegisterNotify( (char*)LPCTSTR(GetCompleteSectionName()),
|
|
s_m_fn_vCallBackSaveMecaCard,
|
|
(void *)this,
|
|
_eAction);
|
|
break ;
|
|
|
|
case SCR_EA_Ntfy_DeleteSection:
|
|
SCR_fn_v_SvL1_RegisterNotify( (char*)LPCTSTR(GetCompleteSectionName()),
|
|
NULL,
|
|
(void *)this,
|
|
_eAction);
|
|
break ;
|
|
}
|
|
}
|
|
*/
|
|
|
|
//******************************************************************************
|
|
CString CPA_Meca_Card::m_pub_fn_csGetActionName()
|
|
{
|
|
return m_pri_csActionName;
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::m_pub_fn_vSetActionName(CString csNewName)
|
|
{
|
|
m_pri_csActionName = csNewName;
|
|
}
|
|
|
|
//******************************************************************************
|
|
CString CPA_Meca_Card::m_pub_fn_csGetCompleteFileName()
|
|
{
|
|
return m_pri_csCompleteFileName;
|
|
}
|
|
|
|
//******************************************************************************
|
|
CString CPA_Meca_Card::m_pub_fn_csGetReferencedFileName()
|
|
{
|
|
return m_pri_csReferencedFileName;
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::m_pub_fn_vSetCompleteFileName(CString csNewName)
|
|
{
|
|
m_pri_csCompleteFileName = csNewName;
|
|
|
|
short wIndexInString = csNewName.ReverseFind('\\');
|
|
if ( wIndexInString != -1 )
|
|
m_pri_csReferencedFileName = csNewName.Right(csNewName.GetLength() - wIndexInString - 1);
|
|
else
|
|
m_pri_csReferencedFileName = m_pri_csCompleteFileName;
|
|
}
|
|
|
|
//******************************************************************************
|
|
BOOL CPA_Meca_Card::m_pub_fn_bIsNotified()
|
|
{
|
|
return m_pri_bIsNotified;
|
|
}
|
|
|
|
//Notifications
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::fn_vNotifySave()
|
|
{
|
|
CPA_SaveObject::fn_vNotifySave();
|
|
|
|
//Marks the Card
|
|
if ( !m_pri_bIsNotified )
|
|
{
|
|
m_pri_bIsNotified = TRUE;
|
|
g_pclInterface->m_clDocument.m_pclControlView->m_fn_vUpdateCardsName();
|
|
}
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::fn_vNotifyUnSave()
|
|
{
|
|
CPA_SaveObject::fn_vNotifyUnSave();
|
|
|
|
//Marks the Card
|
|
if ( m_pri_bIsNotified )
|
|
{
|
|
m_pri_bIsNotified = FALSE;
|
|
g_pclInterface->m_clDocument.m_pclControlView->m_fn_vUpdateCardsName();
|
|
}
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::fn_vNotifyRestore()
|
|
{
|
|
CPA_SaveObject::fn_vNotifyRestore();
|
|
|
|
//Marks the Card
|
|
if ( !m_pri_bIsNotified )
|
|
{
|
|
m_pri_bIsNotified = TRUE;
|
|
g_pclInterface->m_clDocument.m_pclControlView->m_fn_vUpdateCardsName();
|
|
}
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::fn_vNotifyRename()
|
|
{
|
|
CPA_SaveObject::fn_vNotifyRename();
|
|
|
|
//Marks the Card
|
|
if ( !m_pri_bIsNotified )
|
|
{
|
|
m_pri_bIsNotified = TRUE;
|
|
g_pclInterface->m_clDocument.m_pclControlView->m_fn_vUpdateCardsName();
|
|
}
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CPA_Meca_Card::s_m_fn_vCallBackSaveMecaCard( SCR_tdst_File_Description *_p_stFile,
|
|
char *_p_szSectionName,
|
|
void *_p_vData,
|
|
SCR_tde_Ntfy_Action _eAction)
|
|
{
|
|
CPA_Meca_Card *p_clMecaCard = (CPA_Meca_Card *)_p_vData ;
|
|
|
|
ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors,"Saving a Mechanical Card",
|
|
"CPA_Meca_Card::s_m_fn_vCallBackSaveMecaCard(...)",
|
|
E_ERROR_GRAVITY_FATAL,
|
|
"Pointer on Card is NULL ; Card could not be saved.");
|
|
ERROR_ASSERT( p_clMecaCard != NULL );
|
|
|
|
if ( p_clMecaCard != NULL )
|
|
{
|
|
switch ( _eAction )
|
|
{
|
|
case SCR_EA_Ntfy_AddSection:
|
|
case SCR_EA_Ntfy_AddOrModifySection:
|
|
case SCR_EA_Ntfy_AddOrRebuildSection:
|
|
case SCR_EA_Ntfy_RebuildSection:
|
|
case SCR_EA_Ntfy_ModifySection:
|
|
//Saves Mecanichal Card
|
|
p_clMecaCard->m_fn_vSaveMecaCard(_p_stFile, _eAction);
|
|
p_clMecaCard->m_pri_bIsNotified = FALSE;
|
|
p_clMecaCard->fn_vSectionSaved();
|
|
break ;
|
|
|
|
case SCR_EA_Ntfy_DeleteIfExists:
|
|
case SCR_EA_Ntfy_DeleteSection:
|
|
p_clMecaCard->fn_vSectionDeleted();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//******************************************************************************
|
|
BOOL CPA_Meca_Card::m_fn_bLoadIfUnloaded()
|
|
{
|
|
if ( !fn_bIsAvailable() )
|
|
{
|
|
//Loads the corresponding section
|
|
CString csSectionName = GetCompleteSectionName();
|
|
|
|
SCR_tdst_Cxt_Values *p_stValues;
|
|
p_stValues = SCR_fnp_st_RdL0_AnalyseSection((char *)LPCTSTR(csSectionName),
|
|
SCR_CDF_uw_Anl_Normal);
|
|
|
|
//Displays the last loaded Actor
|
|
void *pvBaseAddress = (void *)p_stValues->a_ulValues[0];
|
|
m_fn_vSetBaseAddress(pvBaseAddress);
|
|
|
|
//Calls the filling function
|
|
ERROR_ASSERT( m_pclCardType->m_p_fn_vFill != NULL );
|
|
m_pclCardType->m_p_fn_vFill(this);
|
|
|
|
// update parameter
|
|
DNM_tdstMecBaseIdCard *pMecCard = (DNM_tdstMecBaseIdCard *)m_fn_pvGetBaseAddress();
|
|
DNM_M_vBaseIdCardSetSlopeLimit ( pMecCard, MTH_M_xRadToDeg ( MTH_M_xATan (DNM_M_xBaseIdCardGetSlopeLimit(pMecCard))) );
|
|
|
|
//Updates Editor values with motor ones
|
|
m_pri_fn_vGetAllMotorValues();
|
|
|
|
SetAvailable(TRUE);
|
|
|
|
//Edits
|
|
g_pclInterface->m_clDocument.m_fn_vEditCard(this);
|
|
|
|
m_pclCardType->m_bAtLeastOneCardOfTheCardTypeHasBeenLoaded = TRUE;
|
|
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
//**************************************************************************************
|
|
//Virtual functions
|
|
//**************************************************************************************
|
|
|
|
//**************************************************************************************
|
|
long CPA_Meca_Card::GetDataType(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
//**************************************************************************************
|
|
void *CPA_Meca_Card::GetData(void)
|
|
{
|
|
return m_fn_pvGetBaseAddress();
|
|
}
|
|
|
|
//**************************************************************************************
|
|
BOOL CPA_Meca_Card::fn_bCanBeNotified(void)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
//**************************************************************************************
|
|
//** CPA_Meca_CardList class ***********************************************************
|
|
//**************************************************************************************
|
|
|
|
CPA_Meca_CardList::CPA_Meca_CardList()
|
|
{
|
|
|
|
}
|
|
|
|
//**************************************************************************************
|
|
CPA_Meca_CardList::~CPA_Meca_CardList()
|
|
{
|
|
m_fn_vEmptyList();
|
|
}
|
|
|
|
//**************************************************************************************
|
|
CPA_Meca_Card* CPA_Meca_CardList::m_fn_pclAddElement( CString csName,
|
|
CPA_Meca_CardType *pclCardType,
|
|
void *pvBaseAddress,
|
|
CString csFileName /*= ""*/,
|
|
CString csSectionName /*= ""*/,
|
|
BOOL bCanbBeLoaded /*= FALSE*/)
|
|
{
|
|
CPA_Meca_Card *pclNewElement = new CPA_Meca_Card( csName,
|
|
pclCardType,
|
|
csFileName,
|
|
csSectionName,
|
|
pvBaseAddress,
|
|
bCanbBeLoaded);
|
|
|
|
AddTail(pclNewElement);
|
|
|
|
return pclNewElement;
|
|
}
|
|
|
|
//**************************************************************************************
|
|
void CPA_Meca_CardList::m_fn_vEmptyList()
|
|
{
|
|
POSITION pos = GetHeadPosition();
|
|
while( pos != NULL )
|
|
delete (GetNext(pos));
|
|
|
|
RemoveAll();
|
|
}
|
|
|
|
//**************************************************************************************
|
|
//Returns the first available (i.e. loaded) Card in the List
|
|
CPA_Meca_Card *CPA_Meca_CardList::m_pub_fn_pclGetFirstAvailableCard()
|
|
{
|
|
CPA_Meca_Card *pclCurrentCard;
|
|
BOOL bFound = FALSE;
|
|
|
|
POSITION pos = GetHeadPosition();
|
|
while ( (pos != NULL) && (!bFound) )
|
|
{
|
|
pclCurrentCard = GetNext(pos);
|
|
|
|
bFound = pclCurrentCard->fn_bIsAvailable();
|
|
}
|
|
|
|
if ( bFound )
|
|
return pclCurrentCard;
|
|
else
|
|
return NULL;
|
|
}
|