// Header for the definition of the class representing a mini-structure
// (Base class)	 (actors datas)
//////////////////////////////////////////////////////////////////////
#ifndef _CPACMSTA_HPP_
#define _CPACMSTA_HPP_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "EDACMStr.hpp"		//for tdeMiniStructureState
#include "EDACDef.hpp"		//for CAR_EDIT_TDSTACTOR
#include "EDACWatc.hpp"

class EdActors_EditorActor;

//#####################################################################

class EdActors_ActorMiniStructure
{
public:
	EdActors_ActorMiniStructure(CString);
	~EdActors_ActorMiniStructure();

//---------------------------------------
//Attributes
public:
	//The current state of the MS
	tdeMiniStructureState m_tdeState;

	//The list of data
	CTL_Editor_DataList *m_pclDataList;
 
	//Indicates if datas have been created or not
	BOOL m_bDataCreated;

	//Indicates if datas have been initialized or not
	BOOL m_bDataInitialized;

	//Pointer on Allocation function (motor function)
 	void (*m_td_pfn_vAllocationFunction)(CAR_EDIT_TDSTACTOR *pclMotorActor);

	//Pointer on Unallocation function (motor function)
 	void (*m_td_pfn_vUnallocationFunction)(CAR_EDIT_TDSTACTOR *pclMotorActor);

	//Pointer on Allocation function (motor function)
	void (*m_td_pfn_vFillFunction)(EdActors_EditorActor *, EdActors_ActorMiniStructure *);
	
	//Special function, called at Instanciation when the corresponding
	//MS is allocated in base Model
	void (*m_td_pfn_vInstanciationSpecialFunction)(EdActors_ActorMiniStructure *);

	//Special Function, called before Allocation
	void (*m_td_pfn_vBeforeAllocationSpecialFunction)(EdActors_ActorMiniStructure *);

	//Special Function, called after Allocation
	void (*m_td_pfn_vAfterAllocationSpecialFunction)(EdActors_ActorMiniStructure *);

	//Parent Actor
	EdActors_EditorActor *m_pclParentActor;

	//Parent (Control) MS
	EdActors_MiniStructure *m_pclParentMS;

	//For Undo / Redo
	BOOL m_bIsReallyAllocated;

protected:

private:
	//Saving (Scripts)
	CString m_csScriptName;

	//Pointer on the base Address of the MS
	void *m_pvBaseAddress;

	//For Undo / Redo
	void *m_pvKeptAddress;

	OAC_tdstWatchField m_pri_tdstWatchField;

//---------------------------------------
//Functions
public:
	BOOL m_fn_bAllocate(BOOL bCanBeUndone = FALSE);
	BOOL m_fn_bUnallocate(BOOL bCanBeUndone = FALSE);

	BOOL m_fn_bIsAllocated();
	BOOL m_fn_bCanBeUnallocated();
	BOOL m_fn_bIsOpen();
	BOOL m_fn_bCallSpecialFunction();

	//Saving (Scripts)
	CString m_fn_csGetScriptName();
	void m_fn_vSetScriptName(CString);

	//Pointer on the base Address of the MS
	void *m_fn_pvGetBaseAddress();
	void m_fn_vSetBaseAddress(void *);

	//To init all data in the AMS
	void m_pub_fn_vInitializeAllData();

	//To get all motor Data	
	void m_pub_fn_vGetAllMotorData();

	OAC_tdstWatchField *m_pub_fn_p_tdstGetWatchField();

protected:

private:
	BOOL m_fn_bRealAllocate();

	//For Undo / Redo
	void m_fn_vUnrealUnallocate();
	void m_fn_vUnrealAllocate();

public:
	//Saving
	BOOL m_fn_bSaveMS(SCRIPT_tdstSaveFile *, CString);
	static SCR_tde_Anl_ReturnValue m_fn_tdeCallBackLoad(SCR_tdst_File_Description *_p_stFile,
																											char *_p_szName,
																											char *_ap_szParams[],
																											SCR_tde_Anl_Action _eAction);

friend class EdActors_ActorMSAllocateModif;
friend class EdActors_ActorMSUnallocateModif;
friend class EdActors_EditorActorModel;
};

//##################################################################"
class EdActors_ActorMSAllocateModif : public CPA_Modif
{
public:
	//Constructor
	EdActors_ActorMSAllocateModif(EdActors_ActorMiniStructure *pclAMS);

	//Destructor
	~EdActors_ActorMSAllocateModif();

	BOOL Do();
	BOOL Undo();

	//Members
private:
	EdActors_ActorMiniStructure *m_pclAMS;

};

//##################################################################"
class EdActors_ActorMSUnallocateModif : public CPA_Modif
{
public:
	//Constructor
	EdActors_ActorMSUnallocateModif(EdActors_ActorMiniStructure *pclAMS);

	//Destructor
	~EdActors_ActorMSUnallocateModif();

	BOOL Do();
	BOOL Undo();

	//Members
private:
	EdActors_ActorMiniStructure *m_pclAMS;

};

//#####################################################################

// Definition of the class for the list of mini-structures
class EdActors_ActorMiniStructureList : public CList<EdActors_ActorMiniStructure *, EdActors_ActorMiniStructure *>
{
public:
	EdActors_ActorMiniStructureList(CString csScriptName);
	~EdActors_ActorMiniStructureList();

	EdActors_ActorMiniStructure* m_fn_pclAddElement(CString csScriptName);

	void m_fn_vEmptyList();

private:
	CString m_csGroupScriptName;

public:
	CString m_fn_csGetGroupScriptName();

	EdActors_ActorMiniStructure *m_fn_pclGetAMSFromName(CString);

	void m_pub_fn_vGetAllMotorData();
};

//#####################################################################

// Definition of the class for the list of mini-structures lists (!!!)
class EdActors_AMSListList : public CList<EdActors_ActorMiniStructureList *, EdActors_ActorMiniStructureList *>
{
public:
	EdActors_AMSListList();
	~EdActors_AMSListList();

	EdActors_ActorMiniStructureList* m_fn_pclAddList(CString csScriptName);

	EdActors_ActorMiniStructureList *m_fn_pclGetListFromIndex(unsigned char ucIndex);
	char m_fn_cGetIndexFromList(EdActors_ActorMiniStructureList *);
	char m_fn_cGetIndexFromAMS(EdActors_ActorMiniStructure *);

	EdActors_ActorMiniStructure *m_fn_pclGetAMSFromName(CString);
	CTL_Editor_Data *m_fn_pclGetDataFromName(CString _csName);
};


#endif //_CPACMSTA_HPP_

