/*
 =======================================================================================
  Name        : TPG_OSrc.cpp
 
  Author      : vincent lhullier            Date :20/03/98
 
  Description : implementation of editor ParticleSource object class
 =======================================================================================
 */

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include "StdAfx.h"

#include "TPG_OSys.hpp"

#include "_Minterf.hpp"
#include "TPG_Strg.hpp"
#include "TPG_ClBk.hpp"

#include "PRT.h"
#include "GAM.h"
#include "MTH.h"
#include "ErO.h"
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

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

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


//////////////////////////////////////
// Constructor and Destructor
//////////////////////////////////////
CPA_PartGen_Source::CPA_PartGen_Source(CString _csName ) : CPA_SaveObject( g_pclInterface, g_C_csPartGenSourceName, E_ss_Responsible )
{
	SetSectionData( this );
	SetCallBackSave( m_s_fn_vCallBackSaveSource );
	SetDataPath( C_szEffectPath );

	if ( fn_eRename(_csName) != E_mc_None )
	SetDefaultValidName();

	fn_vUpdateSectionName();
	SetExistingSection( FALSE );

	PRT_fn_vCreateParticlesSource( &m_pri_p_stPrtSrc );
	fn_vUpdateData( (void*) m_pri_p_stPrtSrc );

	//m_pri_hGameMaterial = NULL;
	//m_pri_hSprite = NULL;

	m_pri_fn_vFillDataList();
}
																			 
CPA_PartGen_Source::CPA_PartGen_Source(CString _csName, PRT_tdstParticlesSource* _p_stPrtSrc, BOOL _bIsLoaded ) : CPA_SaveObject( g_pclInterface, g_C_csPartGenSourceName, E_ss_Responsible )
{
	SetSectionData( this );
	SetCallBackSave( m_s_fn_vCallBackSaveSource );
	SetDataPath( C_szEffectPath );

	if ( fn_eRename(_csName) != E_mc_None )
	SetDefaultValidName();

	fn_vUpdateSectionName();
	SetExistingSection( TRUE );

	SetAvailable( _bIsLoaded );

	fn_vUpdateData( (void*) _p_stPrtSrc );
	m_pri_p_stPrtSrc = _p_stPrtSrc;
	
	//m_pri_hGameMaterial = NULL;
	//m_pri_hSprite = NULL;

	if( _bIsLoaded )
	{
		//m_pri_fn_vSetInternalParticle();
		m_pri_fn_vFillDataList();
	}
}

CPA_PartGen_Source::~CPA_PartGen_Source()
{
	fn_vNotifyUnSave();
}


void CPA_PartGen_Source::m_pub_fn_vSetSource( PRT_tdstParticlesSource *_p_stPrtSrc )
{
	fn_vUpdateData( (void*)_p_stPrtSrc );
	m_pri_p_stPrtSrc = _p_stPrtSrc;
	SetAvailable( TRUE );

	//m_pri_fn_vSetInternalParticle();
	m_pri_fn_vFillDataList();
}

////////////////////////////////////
// Virtual functions
long CPA_PartGen_Source::GetDataType( void )
{
	return( 0 );
}

void* CPA_PartGen_Source::GetData( void )
{
	return (void*) m_pri_p_stPrtSrc;
}

CString CPA_PartGen_Source::fn_csComputeReferencedSectionName(const CString _csNewName)
{
	CString csResult = "generators.prt^";
	csResult += C_SectionParticleSource;
	csResult += ":";
	return( csResult + _csNewName );
}


//*************************************************
// Load if necessary
BOOL CPA_PartGen_Source::m_pub_fn_vLoadIfUnloaded()
{
	if ( !fn_bIsAvailable() )
	{
		SCR_tdst_Cxt_Values *p_stValues;
		p_stValues = SCR_fnp_st_RdL0_AnalyseSection((char *)LPCTSTR(GetReferencedSectionName()), SCR_CDF_uw_Anl_Normal);

		m_pri_p_stPrtSrc = (PRT_tdstParticlesSource *) p_stValues->a_ulValues[0];
		fn_vUpdateData( (void*) m_pri_p_stPrtSrc );
		SetAvailable(TRUE);

		//m_pri_fn_vSetInternalParticle();
		m_pri_fn_vFillDataList();
		return TRUE;
	}
	return FALSE;
}

///////////////////////////
//  Source via Generator
///////////////////////////
/*
CString CPA_PartGen_Source::m_pri_fn_csGetSourceReferencedSectionName()
{
	CString csResult = "Generators.prt^";
	csResult += C_SectionParticleSource;
	csResult += ":";
	csResult += GetName();
	return (csResult + "Source");
}
*/

///////////////////////////////////////////////////////
// Generation Mode and parameters
void CPA_PartGen_Source::m_pub_fn_vSetGenerationMode( short _wIndex )
{
	PRT_M_vSetGenerationModeParticlesSource( m_pri_p_stPrtSrc, (unsigned char)_wIndex );
	fn_vNotifySave();
}

long CPA_PartGen_Source::m_pub_fn_lGetGenerationMode()
{
	return (long) m_pri_p_stPrtSrc->ucGenerationMode;
}

/*
void CPA_PartGen_Source::m_pub_fn_vSetGenerationProba( double _dValue )
{
	PRT_M_vSetGenerationProbabilityParticlesSource( m_pri_p_stPrtSrc, MTH_M_xDoubleToReal(_dValue) );
	fn_vNotifySave();
}
*/

double CPA_PartGen_Source::m_pub_fn_dGetGenerationProba()
{
	return MTH_M_xRealToDouble( m_pri_p_stPrtSrc->xGenerationProbability );
}

/*
void CPA_PartGen_Source::m_pub_fn_vSetNbNoGeneration( long _lValue )
{
	ACP_tdxIndex xNbGeneration = m_pri_p_stPrtSrc->xNbFramesTotal - m_pri_p_stPrtSrc->xNbFramesNoGeneration;
	PRT_M_vSetNbFramesCrenelParticlesSource( m_pri_p_stPrtSrc, (ACP_tdxIndex)_lValue, xNbGeneration );
	fn_vNotifySave();
}
*/

long CPA_PartGen_Source::m_pub_fn_lGetNbNoGeneration()
{
	return (long) m_pri_p_stPrtSrc->xNbFramesNoGeneration;
}

/*
void CPA_PartGen_Source::m_pub_fn_vSetNbGeneration( long _lValue )
{
	ACP_tdxIndex xNbNoGeneration = m_pri_p_stPrtSrc->xNbFramesNoGeneration;
	PRT_M_vSetNbFramesCrenelParticlesSource( m_pri_p_stPrtSrc, xNbNoGeneration, (ACP_tdxIndex)_lValue );
	fn_vNotifySave();
}
*/

long CPA_PartGen_Source::m_pub_fn_lGetNbGeneration()
{
	return (long)(m_pri_p_stPrtSrc->xNbFramesTotal - m_pri_p_stPrtSrc->xNbFramesNoGeneration);
}

///////////////////////////////////////////////////////
// Nb Particles to Generate Mode and parameters
void CPA_PartGen_Source::m_pub_fn_vSetNbGenerateMode( short _wIndex )
{
	PRT_M_vSetNbParticlesToGenerateModeParticlesSource( m_pri_p_stPrtSrc, (unsigned char)_wIndex );
	fn_vNotifySave();
}

long CPA_PartGen_Source::m_pub_fn_lGetNbGenerateMode()
{
	return (long) m_pri_p_stPrtSrc->ucNbParticlesToGenerateMode;
}

/*void CPA_PartGen_Source::m_pub_fn_vSetNbToGenerate( long _lValue )
{
	PRT_M_vSetNbParticlesToGenerateParticlesSource( m_pri_p_stPrtSrc, (ACP_tdxIndex)_lValue );
	fn_vNotifySave();
}*/

long CPA_PartGen_Source::m_pub_fn_lGetNbToGenerate()
{
	return (long)(m_pri_p_stPrtSrc->xNbParticlesToGenerate);
}

/*void CPA_PartGen_Source::m_pub_fn_vSetNbMax( long _lValue )
{
	ACP_tdxIndex xMin = m_pri_p_stPrtSrc->xNbMin;
	PRT_M_vSetNbMinMaxParticlesSource( m_pri_p_stPrtSrc, xMin, (ACP_tdxIndex)_lValue );
	fn_vNotifySave();
}*/

long CPA_PartGen_Source::m_pub_fn_lGetNbMax()
{
	return (long)(m_pri_p_stPrtSrc->xNbMax);
}

/*void CPA_PartGen_Source::m_pub_fn_vSetNbMin( long _lValue )
{
	ACP_tdxIndex xMax = m_pri_p_stPrtSrc->xNbMax;
	PRT_M_vSetNbMinMaxParticlesSource( m_pri_p_stPrtSrc, (ACP_tdxIndex)_lValue, xMax );
	fn_vNotifySave();
}*/

long CPA_PartGen_Source::m_pub_fn_lGetNbMin()
{
	return (long)(m_pri_p_stPrtSrc->xNbMin);
}


/////////////////////////////////////////////////////
// Geometry Mode and parameters
void CPA_PartGen_Source::m_pub_fn_vSetGeometryMode( short _wIndex )
{
	PRT_M_vSetGeometryModeParticlesSource( m_pri_p_stPrtSrc, (unsigned char)_wIndex );
	fn_vNotifySave();
}

long CPA_PartGen_Source::m_pub_fn_lGetGeometryMode()
{
	return (long)m_pri_p_stPrtSrc->ucGeometryMode;
}

/*void CPA_PartGen_Source::m_pub_fn_vSetSrcPt1( double _dX, double _dY, double _dZ )
{
	MTH3D_tdstVector stVector;
	MTH3D_M_vSetVectorElements( &stVector, MTH_M_xDoubleToReal(_dX), MTH_M_xDoubleToReal(_dY), MTH_M_xDoubleToReal(_dZ) );
  PRT_fn_vSetQuadParticlesSource
		( 
			m_pri_p_stPrtSrc,
			&stVector,
			&(m_pri_p_stPrtSrc->stVertex2),
			&(m_pri_p_stPrtSrc->stVertex3)
		);
	fn_vNotifySave();
}*/

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt1X()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetXofVector( &((m_pri_p_stPrtSrc)->stVertex1 )) );
}

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt1Y()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetYofVector( &((m_pri_p_stPrtSrc)->stVertex1 )) );
}

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt1Z()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetZofVector( &((m_pri_p_stPrtSrc)->stVertex1 )) );
}

/*void CPA_PartGen_Source::m_pub_fn_vSetSrcPt2( double _dX, double _dY, double _dZ )
{
	MTH3D_tdstVector stVector;
	MTH3D_M_vSetVectorElements( &stVector, MTH_M_xDoubleToReal(_dX), MTH_M_xDoubleToReal(_dY), MTH_M_xDoubleToReal(_dZ) );
  PRT_fn_vSetQuadParticlesSource
		( 
			m_pri_p_stPrtSrc,
			&(m_pri_p_stPrtSrc->stVertex1),
			&stVector,
			&(m_pri_p_stPrtSrc->stVertex3)
		);
	fn_vNotifySave();
}*/

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt2X()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetXofVector( &((m_pri_p_stPrtSrc)->stVertex2 )) );
}

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt2Y()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetYofVector( &((m_pri_p_stPrtSrc)->stVertex2 )) );
}

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt2Z()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetZofVector( &((m_pri_p_stPrtSrc)->stVertex2 )) );
}

/*void CPA_PartGen_Source::m_pub_fn_vSetSrcPt3( double _dX, double _dY, double _dZ )
{
	MTH3D_tdstVector stVector;
	MTH3D_M_vSetVectorElements( &stVector, MTH_M_xDoubleToReal(_dX), MTH_M_xDoubleToReal(_dY), MTH_M_xDoubleToReal(_dZ) );
  PRT_fn_vSetQuadParticlesSource
		( 
			m_pri_p_stPrtSrc,
			&(m_pri_p_stPrtSrc->stVertex1),
			&(m_pri_p_stPrtSrc->stVertex2),
			&stVector
		);
	fn_vNotifySave();
}*/

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt3X()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetXofVector( &((m_pri_p_stPrtSrc)->stVertex3 )) );
}

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt3Y()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetYofVector( &((m_pri_p_stPrtSrc)->stVertex3 )) );
}

double CPA_PartGen_Source::m_pub_fn_dGetSrcPt3Z()
{
	return MTH_M_xRealToDouble( MTH3D_M_xGetZofVector( &((m_pri_p_stPrtSrc)->stVertex3 )) );
}


/////////////////////////////////////////////////
// Link Mode
void CPA_PartGen_Source::m_pub_fn_vSetLinkMode( short _wIndex )
{
	PRT_M_vSetLinkModeParticlesSource( m_pri_p_stPrtSrc, (unsigned char)_wIndex );
	fn_vNotifySave();
}

long CPA_PartGen_Source::m_pub_fn_lGetLinkMode()
{
	return (long)m_pri_p_stPrtSrc->ucLinkMode;
}


//////////////////////////////////////////////
// Speed and Range
void CPA_PartGen_Source::m_pub_fn_vSetSpeed( double _dSpeed )
{
	PRT_M_vSetSpeedParticlesSource( m_pri_p_stPrtSrc, MTH_M_xDoubleToReal(_dSpeed) );
	fn_vNotifySave();
}

double CPA_PartGen_Source::m_pub_fn_dGetSpeed()
{
	return MTH_M_xRealToDouble( m_pri_p_stPrtSrc->xSpeed );
}

void CPA_PartGen_Source::m_pub_fn_vSetSpeedRange( double _dSpeedRange )
{
	PRT_M_vSetSpeedRangeParticlesSource( m_pri_p_stPrtSrc, MTH_M_xDoubleToReal(_dSpeedRange) );
	fn_vNotifySave();
}

double CPA_PartGen_Source::m_pub_fn_dGetSpeedRange()
{
	return MTH_M_xRealToDouble( m_pri_p_stPrtSrc->xSpeedRange );
}




/////////////////////////////////////////////////
// Point, Segment and Sprite
/*
long CPA_PartGen_Source::m_pub_fn_lGetParticlesType()
{
	return (long)m_pri_p_stSystem->xParticlesType;
}

void CPA_PartGen_Source::m_pub_fn_vSetObjectPoint( GMT_tdxHandleToGameMaterial _hGameMaterial )
{
	PRT_fn_vCreatePointParticles( m_pri_p_stSystem, _hGameMaterial );
}

GMT_tdxHandleToGameMaterial CPA_PartGen_Source::m_pub_fn_hGetPointGameMaterial()
{
	return GEO_xGetGameMaterialOfElementPoints(m_pri_p_stSystem->hParticlesSystemObject,0);
}

void CPA_PartGen_Source::m_pub_fn_vSetObjectSegment( GMT_tdxHandleToGameMaterial _hGameMaterial )
{
	PRT_fn_vCreateSegmentParticles( m_pri_p_stSystem, _hGameMaterial );
	//fn_vNotifySave();
}

GMT_tdxHandleToGameMaterial CPA_PartGen_Source::m_pub_fn_hGetSegmentGameMaterial()
{
	GMT_tdxHandleToGameMaterial hGameMaterial;
	GEO_xGetGameMaterialOfElementLines(m_pri_p_stSystem->hParticlesSystemObject,0, 0, &hGameMaterial);
	return hGameMaterial;
}

void CPA_PartGen_Source::m_pub_fn_vSetObjectSprite( ACP_tdxHandleOfSprite _hSprite )
{
	PRT_fn_vCreateSpriteParticles( m_pri_p_stSystem, _hSprite );
	//fn_vNotifySave();
}

ACP_tdxHandleOfSprite CPA_PartGen_Source::m_pub_fn_hGetSprite()
{
	ACP_tdxHandleOfSprite hSprite;
	GEO_vGetHandleOfIndexedSprite(m_pri_p_stSystem->hParticlesSystemObject, 0, 0, &hSprite );
	return hSprite;
}
*/
/*
void CPA_PartGen_Source::m_pri_fn_vSetInternalParticle()
{
	ACP_tdxIndex xType = m_pri_p_stSystem->xParticlesType;
	switch( xType )
		{
		case PRT_C_xPointParticles:
			m_pri_hGameMaterial = GEO_xGetGameMaterialOfElementPoints(m_pri_p_stSystem->hParticlesSystemObject,0);
			break;

		case PRT_C_xSegmentParticles:
			GEO_xGetGameMaterialOfElementLines(m_pri_p_stSystem->hParticlesSystemObject,0, 0, &m_pri_hGameMaterial);
			break;

		case PRT_C_xSpriteParticles:
			GEO_vGetHandleOfIndexedSprite(m_pri_p_stSystem->hParticlesSystemObject, 0, 0, &m_pri_hSprite );
			break;
		}
}
*/

//****************************************************
// Gets name of the associated object using link table
/*CString CPA_PartGen_Source::m_pub_fn_csGetObjectName()
{
	CString csObjectName = "";
	SCR_tdst_Link_Table *p_stLinkTable = NULL;
	SCR_tdst_Link_Value *p_stValue = NULL;
	unsigned long ulValue = 0;

	long lIndex = m_pub_fn_lGetParticlesType();
	switch( lIndex )
		{
		case PRT_C_xPointParticles:
			p_stLinkTable = GMT_fn_p_stGetLinkTable();
			ulValue = (unsigned long)m_pub_fn_hGetPointGameMaterial();
			break;

		case PRT_C_xSegmentParticles:
			p_stLinkTable = GMT_fn_p_stGetLinkTable();
			ulValue = (unsigned long)m_pub_fn_hGetSegmentGameMaterial();
			break;
			
		case PRT_C_xSpriteParticles:
			p_stLinkTable = GLI_p_stGetLinkTableOfSprite();
			ulValue = (unsigned long)m_pub_fn_hGetSprite();
			break;
		}
	
	//*** finds the entry *****
	if( p_stLinkTable != NULL )
		p_stValue = SCR_fnp_st_Link_SearchValue( p_stLinkTable, ulValue );

	//*** gets the name of the entry ******************************************************
	if( p_stValue != NULL && SCR_M_e_Link_GetState(p_stValue) == SCR_ELS_Link_Initialized )
		{
			csObjectName = SCR_M_p_sz_Link_GetKey(p_stValue);
			
			char a_256cFileName[256];
			char a_256cActionName[256];
			char a_256cName[256];
			SCR_fn_v_RdL0_SplitSectionName((char *)LPCTSTR(csObjectName), a_256cFileName, a_256cActionName, a_256cName);

			csObjectName = a_256cName;
		}

	return csObjectName;
}
*/
/////////////////////////////////////////////////
// Nb particles
/*long CPA_PartGen_Source::m_pub_fn_lGetNbParticles()
{
	return (long)m_pri_p_stSystem->xNbParticles;
}
*/

///////////////////////////////////////////////////
// CallBack and Function for save
void CPA_PartGen_Source::m_s_fn_vCallBackSaveSource( SCR_tdst_File_Description *_p_stFile, char *_p_szSectionName, void *_p_vData, SCR_tde_Ntfy_Action _eAction )
{
	ERROR_PREPARE_M
		(
			g_c_csPartGenModuleNameForErrors,
			"Saving a generator",
			"CPA_PartGen_Source::m_s_fn_vCallBackSaveSystem",
			E_ERROR_GRAVITY_FATAL,
			"trying to save a NULL system"
		);
		
	CPA_PartGen_Source *p_oPrtSrc = (CPA_PartGen_Source*) _p_vData;
	CString csHeaderName = C_SectionParticleSource;

	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:

			csHeaderName += ":";
			csHeaderName += p_oPrtSrc->GetName();

			SCR_M_SvL0_SaveBeginSection( _p_stFile, M_MAKECHAR(csHeaderName), SCR_CC_C_Cfg_EOL );
			p_oPrtSrc->m_pri_fn_vSaveSource( _p_stFile );
			SCR_M_SvL0_SaveEndSection( _p_stFile, SCR_CC_C_Cfg_EOL );
		
			p_oPrtSrc->fn_vSectionSaved();
			break;

		case SCR_EA_Ntfy_DeleteIfExists:
		case SCR_EA_Ntfy_DeleteSection:
			p_oPrtSrc->fn_vSectionDeleted();
			break;
	}
}

void CPA_PartGen_Source::m_pri_fn_vSaveSource( SCR_tdst_File_Description *_p_stFile )
{
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	long					lIndex;
	CTL_Editor_EnumElement	*p_clEnumElement;
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	
	// generation mode and its optional parameters
	lIndex = m_pub_fn_lGetGenerationMode();
	p_clEnumElement = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_GenerationMode" )->m_fn_pclGetElementFromEnumIndex( lIndex );
	SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcGenerationMode, SCR_CC_C_Cfg_NoChar );
	SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 1, M_MAKECHAR(p_clEnumElement->m_pub_fn_csGetAdditionalString()) );
	switch( lIndex )
	{
		case PRT_C_ucProbabilistGeneration:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcGenerationProbability, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 2, "%.3f", m_pub_fn_dGetGenerationProba() );
			break;
		case PRT_C_ucCrenelGeneration:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcCrenelGeneration, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 3, "%d,%d", m_pub_fn_lGetNbNoGeneration(), m_pub_fn_lGetNbGeneration() );
			break;
	}

	// nb particles to generate mode
	lIndex = m_pub_fn_lGetNbGenerateMode();
	p_clEnumElement = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_NbParticlesMode" )->m_fn_pclGetElementFromEnumIndex( lIndex );
	SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcNbParticlesToGenerateMode, SCR_CC_C_Cfg_NoChar );
	SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 1, M_MAKECHAR(p_clEnumElement->m_pub_fn_csGetAdditionalString()) );
	switch( lIndex )
	{
		case PRT_C_ucConstantNb:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcNbParticlesToGenerate, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 2, "%d", m_pub_fn_lGetNbToGenerate() );
			break;
		case PRT_C_ucProbabilistNb:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcNbMinMax, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 3, "%d,%d", m_pub_fn_lGetNbMin(), m_pub_fn_lGetNbMax() );
			break;
	}

	// generation source geometry mode
	lIndex = m_pub_fn_lGetGeometryMode();
	p_clEnumElement = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_GeometryMode" )->m_fn_pclGetElementFromEnumIndex( lIndex );
	SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcGeometryMode, SCR_CC_C_Cfg_NoChar );
	SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 1, M_MAKECHAR(p_clEnumElement->m_pub_fn_csGetAdditionalString()) );
	switch( lIndex )
	{
		case PRT_C_ucQuad:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcQuad, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP
				( 
					_p_stFile, SCR_EF_SvL0_Scanf, 10, "%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f",
					m_pub_fn_dGetSrcPt1X(), m_pub_fn_dGetSrcPt1Y(), m_pub_fn_dGetSrcPt1Z(),
					m_pub_fn_dGetSrcPt2X(), m_pub_fn_dGetSrcPt2Y(), m_pub_fn_dGetSrcPt2Z(),
					m_pub_fn_dGetSrcPt3X(), m_pub_fn_dGetSrcPt3Y(), m_pub_fn_dGetSrcPt3Z() 
				);
			break;
		case PRT_C_ucPoint:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcPoint, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP
				( 
					_p_stFile, SCR_EF_SvL0_Scanf, 4, "%.3f,%.3f,%.3f",
					m_pub_fn_dGetSrcPt1X(), m_pub_fn_dGetSrcPt1Y(), m_pub_fn_dGetSrcPt1Z() 
				);
			break;
		}

	// link mode
	lIndex = m_pub_fn_lGetLinkMode();
	p_clEnumElement = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_LinkMode" )->m_fn_pclGetElementFromEnumIndex( lIndex );
	SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcLinkMode, SCR_CC_C_Cfg_NoChar );
	SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 1, M_MAKECHAR(p_clEnumElement->m_pub_fn_csGetAdditionalString()) );

	// speed and speed range
	SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcSpeedAndRange, SCR_CC_C_Cfg_NoChar );
	SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 3, "%.3f,%.3f", m_pub_fn_dGetSpeed(), m_pub_fn_dGetSpeedRange() );

	// life mode
	lIndex = (long) m_pri_p_stPrtSrc->ucLifeMode;
	switch (m_pri_p_stPrtSrc->ucLifeMode)
	{
		case PRT_C_ucNoLifeTime:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcNoLifeTime, SCR_CC_C_Cfg_EOL );
			break;
		case PRT_C_ucConstantLifeTime:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcConstantLifeTime, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 2, "%.3f", m_pri_p_stPrtSrc->xMinTime );
			break;
		case PRT_C_ucProbabilistLifeTime:
			SCR_M_SvL0_SaveEntry( _p_stFile, C_EntryPrtSrcProbabilistLifeTime, SCR_CC_C_Cfg_NoChar );
			SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 3, "%.3f, %.3f", m_pri_p_stPrtSrc->xMinTime, m_pri_p_stPrtSrc->xMaxTime );
			break;
	}
}


void CPA_PartGen_Source::m_pri_fn_vFillDataList()
{
	CTL_Editor_Data *p_clData = NULL;
	CTL_Editor_EnumDescriptor *p_clEnumDescriptor = NULL;

	//*** Generation Mode ***********************
	p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_GenerationMode" );
	p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Generation Mode" );
	p_clData->m_fn_vSetMotorDataPtr( (void*) &m_pri_p_stPrtSrc->ucGenerationMode );
	p_clData->m_pub_fn_vSetDataChangedSpecialCallBackFunction( g_fn_vCallBackDataChangedSpecialDisplayGenerator );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//****** Probability *****************************
	p_clData = m_pub_clDataList.m_fn_pclAddDecimalData( sizeof(MTH_tdxReal), "Probability" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xGenerationProbability) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stPrtSrc->ucGenerationMode), "GenerationMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );
	
	//****** Nb Frames No generation ********************
	p_clData = m_pub_clDataList.m_fn_pclAddIntegerData( sizeof(ACP_tdxIndex), TPG_UNSIGNED, "Nb Frames No Generation" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xNbFramesNoGeneration) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) m_pri_p_stPrtSrc, "PrtSrc" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) &(m_pri_p_stPrtSrc->ucGenerationMode), "GenerationMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );
	
	//****** Nb Frames generation *****************
	p_clData = m_pub_clDataList.m_fn_pclAddIntegerData( sizeof(ACP_tdxIndex), TPG_UNSIGNED, "Nb Frames Generation" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xNbFramesTotal) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) &m_pri_p_stPrtSrc->ucGenerationMode, "GenerationMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) &m_pri_p_stPrtSrc->xNbFramesNoGeneration, "NbFramesNoGeneration" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) m_pri_p_stPrtSrc, "PrtSrc" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*) this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );
	p_clData->m_pub_fn_vSetModificationFunctionWhenRead( g_fn_vModificationReadSourceNbFramesGeneration );
	p_clData->m_pub_fn_vSetModificationFunctionWhenWrite( g_fn_vModificationWriteSourceNbFramesGeneration );

	//*** Nb particles to generate mode ********************
	p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_NbParticlesMode" );
	p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Nb Particles to Generate Mode" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->ucNbParticlesToGenerateMode) );
	p_clData->m_pub_fn_vSetDataChangedSpecialCallBackFunction( g_fn_vCallBackDataChangedSpecialDisplayGenerator );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//****** Constant ********************************
	p_clData = m_pub_clDataList.m_fn_pclAddIntegerData( sizeof(ACP_tdxIndex), TPG_UNSIGNED, "Nb Particles" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xNbParticlesToGenerate) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stPrtSrc->ucNbParticlesToGenerateMode), "NbParticlesMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );
	//****** Probabilist *****************************
	p_clData = m_pub_clDataList.m_fn_pclAddIntegerData( sizeof(ACP_tdxIndex), TPG_UNSIGNED, "Nb Particles min" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xNbMin) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stPrtSrc->ucNbParticlesToGenerateMode), "NbParticlesMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	p_clData = m_pub_clDataList.m_fn_pclAddIntegerData( sizeof(ACP_tdxIndex), TPG_UNSIGNED, "Nb Particles max" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xNbMax) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stPrtSrc->ucNbParticlesToGenerateMode), "NbParticlesMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//*** Geometry mode ************************************
	p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_GeometryMode" );
	p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Geometry Mode" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->ucGeometryMode) );
	p_clData->m_pub_fn_vSetDataChangedSpecialCallBackFunction( g_fn_vCallBackDataChangedSpecialDisplayGenerator );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//****** Point **********************************
	p_clData = m_pub_clDataList.m_fn_pclAddVectorData( sizeof(MTH_tdxReal), "Point 1" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->stVertex1) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//****** Quad ***********************************
	p_clData = m_pub_clDataList.m_fn_pclAddVectorData( sizeof(MTH_tdxReal), "Point 2" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->stVertex2) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stPrtSrc->ucGeometryMode), "GeometryMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	p_clData = m_pub_clDataList.m_fn_pclAddVectorData( sizeof(MTH_tdxReal), "Point 3" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->stVertex3) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stPrtSrc->ucGeometryMode), "GeometryMode" );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//*** Link Mode *********************************
	p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_LinkMode" );
	p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Link Mode" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->ucLinkMode) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//*** Speed and Range ****************************
	p_clData = m_pub_clDataList.m_fn_pclAddDecimalData( sizeof(MTH_tdxReal), "Speed" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xSpeed) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	p_clData = m_pub_clDataList.m_fn_pclAddDecimalData( sizeof(MTH_tdxReal), "Speed Range" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->xSpeedRange) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//*** Life Mode
	p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "Source_LifeMode" );
	p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Life Mode" );
	p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stPrtSrc->ucLifeMode) );
	p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );
	p_clData->m_pub_fn_vSetDataChangedSpecialCallBackFunction( g_fn_vCallBackDataChangedSpecialDisplayGenerator );

	//*** data for constant life time
	p_clData = m_pub_clDataList.m_fn_pclAddDecimalData( sizeof(MTH_tdxReal), "LifeTime" );
	p_clData->m_fn_vSetMotorDataPtr		( (void*) &m_pri_p_stPrtSrc->xMinTime );
	p_clData->m_pub_fn_pclAddOwnerData	( (void*) &m_pri_p_stPrtSrc->ucLifeMode, "LifeMode" );
	p_clData->m_pub_fn_pclAddOwnerData	( (void*) this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	//*** data for probabilist life time
	p_clData = m_pub_clDataList.m_fn_pclAddDecimalData( sizeof(MTH_tdxReal), "Min Life Time" );
	p_clData->m_fn_vSetMotorDataPtr		( (void*) &m_pri_p_stPrtSrc->xMinTime );
	p_clData->m_pub_fn_pclAddOwnerData	( (void*) &m_pri_p_stPrtSrc->ucLifeMode, "LifeMode" );
	p_clData->m_pub_fn_pclAddOwnerData	( (void*) this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );

	p_clData = m_pub_clDataList.m_fn_pclAddDecimalData( sizeof(MTH_tdxReal), "Max Life Time" );
	p_clData->m_fn_vSetMotorDataPtr		( (void*) &m_pri_p_stPrtSrc->xMaxTime );
	p_clData->m_pub_fn_pclAddOwnerData	( (void*) &m_pri_p_stPrtSrc->ucLifeMode, "LifeMode" );
	p_clData->m_pub_fn_pclAddOwnerData	( (void*) this, "EditedSource" );
	p_clData->m_pub_fn_vSetDataChangedCallBackFunction( fn_vCBPrtSrcDataChanged );
}


CPA_PartGen_MyDocument * CPA_PartGen_Source::m_pub_fn_p_clGetDocument()
{
	return g_pclInterface->m_pub_fn_p_clGetDocument();
}