/*=============================================================================
 *
 *  Filename:                   CPAZnAtv.hpp
 *  Version:            2.0     (VSS5)
 *  Date:				30/12/96
 *  Author:             Marc Trabucato
 *
 *  Description:                description of CPA_ZonesActivating class
 *                          &&  description of CPA_ZonesActivatingList class
 *
 * version with engine struct link
 *===========================================================================*/
 
#ifndef __CPAZNACT_HPP__
#define __CPAZNACT_HPP__
 
/******************************************/
#if _MSC_VER >= 1000
#pragma once
#endif
/******************************************/
 
#include <afxtempl.h>
 
class CPA_State;
class CPA_MainWorld;
class CPA_Family;
class CPA_ZonesActivatingList;
class CPA_tdoNameList;
 
/*=============================================================================
 *
 * local structures
 *
 *===========================================================================*/
 
typedef struct tdstLoadInfo_
{
	CPA_tdoNameList *m_p_oNameList;
	char *m_szName;
} tdstLoadInfo;
 
typedef struct tdstZAUsed_
{
    CPA_ZonesActivatingList *p_oZAList;
    CPA_State *p_oState;
} tdstZAUsed;
 
/*=============================================================================
 *
 *  Description:                description of CPA_ZdxIndex class
 *                              an index
 *===========================================================================*/
class CPA_ZdxIndex : public CPA_EdElement<CPA_ZdxIndex,ZDX_tdxHandleToZdxIndexList,LST2_M_StaticAnchorTo(ZDX_tdxHandleToZdxIndexList)*>
{
public:
    CPA_ZdxIndex(ZDX_tdxHandleToZdxIndexList _hEngineStruct = NULL);
    ~CPA_ZdxIndex();
 
    static void Init();
    void mfn_vSetIndex(unsigned short usIndex);
    unsigned short mfn_usGetIndex(void);
};
 
/*=============================================================================
 *
 *  Description:                description of CPA_ZonesActivating class
te *                              a list of index : (actived zones from one list during one state)
 *===========================================================================*/
 
class CPA_ZonesActivating : public CPA_SaveObject, public CPA_EdMot<ZDX_tdxHandleToZoneSetList>
{
public:
    CPA_EdList<CPA_ZdxIndex,ZDX_tdxHandleToZdxIndexList,LST2_M_StaticAnchorTo(ZDX_tdxHandleToZdxIndexList)*> m_oListOfZDxNameIdx;
    CPA_List<tdstZAUsed>   m_oListOfZAListUsing;
public:
    /* constructor/destructor*/
    /* to create new ZA*/
    CPA_ZonesActivating(CPA_EditorBase *_p_oDLL, CPA_BaseObject *_p_oOwnerNamesList, CString _csName = "");
    /* to use an existing engine ZA*/
    CPA_ZonesActivating(CPA_EditorBase *_p_oDLL, CPA_BaseObject *_p_oOwnerNamesList, CString _csName,
                        ZDX_tdxHandleToZoneSetList hZdxIndexList);
    ~CPA_ZonesActivating();
 
    /* overload methods*/
    long                GetDataType         ( void )    { return 0; }
    void*               GetData             ( void )    { return (void*)GetStruct(); }
    tdeMissingCriteria  fn_eCheckUnicity    ( const CString csNewName );
    /* new methods*/
    static void Init();
    static void fn_vCallBackSave( SCR_tdst_File_Description *_p_stFile, char *_p_szSectionName,
                                  void *_p_vData, SCR_tde_Ntfy_Action _eAction);
 
	CPA_ZonesActivating *mfn_p_oDuplicateZA	(void);
    CPA_ZonesActivating *mfn_p_oGetDefaultZA(void);
    /* set function*/
    void mfn_vSetZoneActivation	(unsigned short _usZoneIndex, BOOL _bActivation);
    void mfn_vRemoveZone        (unsigned short _usZoneIndex);
    void mfn_vInsertZone        (unsigned short _usZoneIndex);
	/* coherence methods*/
    void mfn_vUsedByZAList      (CPA_ZonesActivatingList *_p_oZAList, CPA_State *_p_oState);
    void mfn_vDontUsedByZAList  (CPA_ZonesActivatingList *_p_oZAList, CPA_State *_p_oState);
 
protected:
    void            SetStruct                   (ZDX_tdxHandleToZoneSetList hZdxIndexList);
    POSITION        mfn_xGetPosZoneActivation   (unsigned short _usZoneIndex);
    POSITION        mfn_xGetZAListPos           (CPA_ZonesActivatingList *_p_oZAList, CPA_State *_p_oState);
};
 
 /*=============================================================================
 *
 *  Description:                description of CPA_ActivationState class
 *                              a couple << state , ZA >>
 *===========================================================================*/
 
class CPA_ActivationState : public CPA_SectionObject,
                            public CPA_EdElement<CPA_ActivationState,ZDX_tdxHandleToZoneSetEncapsulation,LST2_M_StaticAnchorTo(ZDX_tdxHandleToZoneSetEncapsulation)*>
{
private:
    CPA_ZonesActivatingList *m_p_oZAList;
    CPA_State               *m_p_oState;
    CPA_ZonesActivating     *m_p_oZA;
public:
    CPA_ActivationState (CPA_ZonesActivatingList *_p_oZAList, CPA_State *_p_oState, CPA_ZonesActivating *_p_oZA, BOOL _bSectionExists);
    CPA_ActivationState (CPA_ZonesActivatingList *_p_oZAList, ZDX_tdxHandleToZoneSetEncapsulation _hZoneSetEncapsulation = NULL);
    CPA_ActivationState (CPA_ActivationState &_r_oSource);
 
    void mfn_vSetZA     (CPA_ZonesActivating *_p_oZA);
    BOOL mfn_bUpdate    (CPA_ZonesActivating *_p_oDefaultZA);
 
    CPA_State               *mfn_p_oGetState    (void);
    CPA_ZonesActivating     *mfn_p_oGetZA       (void);
    CPA_ZonesActivatingList *mfn_p_oGetZAList   (void);
 
    void mfn_vComputeReferencedSectionName( char * _p_szSectionName, CPA_State *_p_oState );
 
    static void	Init				( void );
    static void fn_vCallBackSave    ( SCR_tdst_File_Description *_p_stFile, char *_p_szSectionName,
                                      void *_p_vData, SCR_tde_Ntfy_Action _eAction);
protected:
	void mfn_vInitZA	(void);
	void mfn_vInitState	(void);
};
 
 /*=============================================================================
 *
 *  Description:                description of CPA_ZonesActivatingList class
 *                              a list of CPA_ActivationState ( couple << state , ZA >> )
 *===========================================================================*/
 
class CPA_ZonesActivatingList : public CPA_SaveObject, public CPA_EdMot<ZDX_tdxHandleToCsaList>
{
private:
    BOOL                    m_bMustBeUpdated;
    CPA_SectionObject       *m_p_oSectionFile;
public:
    CPA_EdList<CPA_ActivationState,ZDX_tdxHandleToZoneSetEncapsulation,LST2_M_StaticAnchorTo(ZDX_tdxHandleToZoneSetEncapsulation)*> m_oListOfZAState;
	CPA_List<CPA_ActivationState> m_oListOfUnusedZAState;
/* methods*/
public:
    /* constructor/destructor*/
    CPA_ZonesActivatingList(CPA_EditorBase *_p_oDLL, CPA_BaseObject *_p_oOwnerNamesList, CString _csName = "",
                            ZDX_tdxHandleToCsaList _hEngineCsaList = NULL);
    ~CPA_ZonesActivatingList();
 
    /* overloaded methods*/
    /*void    *GetEngineStruct           ( void )         { return GetStruct(); }*/
    long                GetDataType         ( void )    { return 0; }
    void*               GetData             ( void )    { return (void*)GetStruct(); }
    tdeMissingCriteria  fn_eCheckUnicity    ( const CString csNewName );
    void                fn_vNotifySave      ( void );
    void                fn_vNotifyUnSave    ( void );
    void                fn_vNotifyRename    ( void );
    void                fn_vNotifyRestore   ( void );
    void                fn_vUpdateReference ( CPA_SaveObject *_p_oObject );
    /* new methods*/
    static void Init                ( void );
    static void fn_vCallBackSave    ( SCR_tdst_File_Description *_p_stFile, char *_p_szSectionName,
                                      void *_p_vData, SCR_tde_Ntfy_Action _eAction);
 
	CPA_ZonesActivatingList *mfn_p_oDuplicateZAList();
    /* get functions*/
    CPA_tdoNameList *mfn_p_oGetZDxNameList  (void)      { return (CPA_tdoNameList *)GetOwner(); }
    int              mfn_iGetNbZDxNames     (void);
    /**/
    void                 mfn_vFillZAList            (void);
    void                 mfn_vZARenamed             (CPA_ZonesActivating *_p_oZA);
    void                 mfn_vStateRenamed          (CPA_State *_p_oState);
	void				 mfn_vSetZAFromState		(CPA_ZonesActivating *_p_oZA, CPA_State *_p_oState);
    void                 mfn_vRemoveState           (CPA_State *_p_oState);
    CPA_ZonesActivating *mfn_p_oGetZAFromState      (CPA_State *_p_oState);
    void                 mfn_vUpdateEditorList      (void);
    void                 mfn_vMustBeUpdated         (void)      { m_bMustBeUpdated = TRUE; }
    BOOL                 mfn_bUpdate						(void);
	/**/
protected:
    void				 SetStruct							(ZDX_tdxHandleToCsaList hCsaList);
    CPA_ZonesActivating *mfn_p_oGetZAWithEngineZdxIndexList (LST2_M_StaticAnchorDeclaration(ZDX_tdxHandleToZdxIndexList) hEngineZdxIndexListList, BOOL _bUseEngine = TRUE);
    CPA_ActivationState *mfn_p_oGetActivationStateFromState (CPA_State *_p_oState, BOOL _bWithUnused = FALSE);
    POSITION             mfn_xGetPosActivationStateFromState(CPA_State *_p_oState);
    POSITION             mfn_xGetPosUnusedActivationStateFromState(CPA_State *_p_oState);
	void				 mfn_vInsertActivationState(CPA_ActivationState *_p_oStZA, BOOL _bEngine = TRUE);
};
 
#endif  /* __CPAZNACT_HPP__*/
