/*=========================================================================
* 
* SECmodif.cpp :  Implementation of Editor Modifications  
* 
*
* Version			1.0
* Creation date		
* Revision date
*
* Shaitan
*=======================================================================*/

#include "stdafx.h"
#include "acp_base.h"
#define ENV_FRIEND
#define SCTFriend

#include "SECmodif.hpp"

#include "SECdSel.hpp"
#include "SEClDias.hpp"
//Shaitan Clean Env
//#include "SEClEnvs.hpp"
//#include "SECdEnv.hpp"
//#include "SECdEnvs.hpp"
//#include "SECdSrfs.hpp"

#undef SCTFriend
#undef ENV_FRIEND

//#################################################################################
// class SECT_ModifSectorLinks 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifSectorLinks::SECT_ModifSectorLinks(Sector_Interface *pInterface, tdeSectModifType eModifType, 
											   CPA_SuperObject *pEditedSector, CPA_SuperObject *pSectorToAdd, 
											   tdeTypeList eListToUpdate)
		: CPA_Modif(TYPE_SECTORLINKS, "SectorLinks", FALSE)
{
	Sector_Object			*pSector;
	tdeTypeList				eList;
	int						iList;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pEditedSector = pEditedSector;
	m_pSectorToAdd = pSectorToAdd;
	m_eCurrentEditMode = m_pSectorInterface->GetEditMode();
	// get corresponding parameters
	pSector = (Sector_Object *) m_pEditedSector->GetObject();

	// init arrays
	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		m_aElements[iList] = NULL;
		m_aSymElems[iList] = NULL;
		m_aHadSymElem[iList] = FALSE;
	}
	// init element for single modif
	if (eListToUpdate != E_NoActiveList)
	{
		// init unique element
		if (m_eModifType == E_mt_DelSectorInList)
			m_aElements[eListToUpdate] = pSector->GetCurrentList(eListToUpdate)->GetElementWithSector(m_pSectorToAdd);
		else
			m_aElements[eListToUpdate] = pSector->GetNewElement(eListToUpdate, m_pSectorToAdd);
	}
	// init elements for multiple modif
	else
	{
		for (iList = 0; iList < C_NumberOfLists; iList++)
		{
			eList = (tdeTypeList) iList;
			if (m_pSectorInterface->GetListActivity(eList))
			{
				// init element
				if (m_eModifType == E_mt_DelSectorInList)
					m_aElements[eList] = pSector->GetCurrentList(eList)->GetElementWithSector(m_pSectorToAdd);
				else
					m_aElements[eList] = pSector->GetNewElement(eList, m_pSectorToAdd);
			}
		}
	}

	// init for symetric
	m_bSymetric = m_pSectorInterface->fn_bSymetricMode();
	if (m_bSymetric)
		fn_vInitSymetricLinks();
}


SECT_ModifSectorLinks::~SECT_ModifSectorLinks (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifSectorLinks::Do (void)
{
	SECT_ListBase			*pCurrentList;
	Sector_Object			*pSectObject;
	tdeTypeList				eList;
	int						iList;

	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// get edited sector
	pSectObject = (Sector_Object *) m_pEditedSector->GetObject();

	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		eList = (tdeTypeList) iList;
		if (m_aElements[eList] != NULL)
		{
			// get current list
			pCurrentList = pSectObject->GetCurrentList(eList);
			// add sector in list
			if (m_eModifType == E_mt_AddSectorInList)
			{
				pSectObject->fn_bAddSectorInList(m_aElements[eList], eList);
				m_bAdded = TRUE;
			}
			// remove sector in list
			else if (pCurrentList->GetElementWithSector(m_pSectorToAdd))
			{
				pSectObject->fn_bRemoveSectorInList(m_aElements[eList], eList);
				m_bAdded = FALSE;
			}
		}
	}

	// if necessary, update symetric link
	if (m_bSymetric)
		fn_vUpdateSymetricLinks(TRUE);
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifSectorLinks::Undo (void)
{
	SECT_ListBase		*pCurrentList;
	Sector_Object		*pSectObject;
	tdeTypeList				eList;
	int						iList;

	// update editor mode
	fn_vReinitEditorState();
	// get edited sector
	pSectObject = (Sector_Object *) m_pEditedSector->GetObject();

	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		eList = (tdeTypeList) iList;
		if (m_aElements[eList] != NULL)
		{
			// get current list
			pCurrentList = pSectObject->GetCurrentList(eList);
			// add sector in list
			if (m_eModifType == E_mt_DelSectorInList)
			{
				// add sector
				pSectObject->fn_bAddSectorInList(m_aElements[eList], eList);
				m_bAdded = TRUE;
			}
			// remove sector in list
			else if (pCurrentList->GetElementWithSector(m_pSectorToAdd))
			{
				pSectObject->fn_bRemoveSectorInList(m_aElements[eList], eList);
				m_bAdded = FALSE;
			}
		}
	}

	// if necessary, update symetric link
	if (m_bSymetric)
		fn_vUpdateSymetricLinks(FALSE);
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}

/*===========================================================================
		Init Symetric Links
=========================================================================*/
void SECT_ModifSectorLinks::fn_vInitSymetricLinks (void)
{
	SECT_ListBase			*pCurrentList;
	Sector_Object			*pSectObject;

	// get parameters
	pSectObject = (Sector_Object *) m_pSectorToAdd->GetObject();

	// graphic link
	if (m_aElements[E_Graphic] != NULL)
	{
		// get current list
		pCurrentList = pSectObject->GetCurrentList(E_Graphic);
		// get corresponding element
		m_aSymElems[E_Graphic] = pCurrentList->GetElementWithSector(m_pEditedSector);
		m_aHadSymElem[E_Graphic] = (m_aSymElems[E_Graphic] != NULL);
		
		// if necessary, create it
		if (m_eModifType == E_mt_AddSectorInList)
		{
			// if necessary, create it
			if (!m_aSymElems[E_Graphic])
				m_aSymElems[E_Graphic] = new SECT_GraphicElement(m_pEditedSector, pSectObject);
			// update graphic level
			((SECT_GraphicElement *) m_aElements[E_Graphic])->SetGraphicLevel(((SECT_GraphicElement *) m_aSymElems[E_Graphic])->GetGraphicLevel());
			// update graphic mode
			((SECT_GraphicElement *) m_aElements[E_Graphic])->SetGraphicMode(((SECT_GraphicElement *) m_aSymElems[E_Graphic])->GetGraphicMode());
		}
	}

	// collision link
	if (m_aElements[E_Collision] != NULL)
	{
		// get current list
		pCurrentList = pSectObject->GetCurrentList(E_Collision);
		// get corresponding element
		m_aSymElems[E_Collision] = pCurrentList->GetElementWithSector(m_pEditedSector);
		m_aHadSymElem[E_Collision] = (m_aSymElems[E_Collision] != NULL);
		
		// if necessary, create it
		if (m_eModifType == E_mt_AddSectorInList)
		{
			// if necessary, create it
			if (!m_aSymElems[E_Collision])
				m_aSymElems[E_Collision] = new SECT_CollisionElement(m_pEditedSector, pSectObject);
		}
	}

	// activity link
	if (m_aElements[E_Activity] != NULL)
	{
		// get current list
		pCurrentList = pSectObject->GetCurrentList(E_Activity);
		// get corresponding element
		m_aSymElems[E_Activity] = pCurrentList->GetElementWithSector(m_pEditedSector);
		m_aHadSymElem[E_Activity] = (m_aSymElems[E_Activity] != NULL);
		
		// if necessary, create it
		if (m_eModifType == E_mt_AddSectorInList)
		{
			// if necessary, create it
			if (!m_aSymElems[E_Activity])
				m_aSymElems[E_Activity] = new SECT_ActivityElement(m_pEditedSector, pSectObject);
		}
	}
	
	// sound link
	if (m_aElements[E_Sound] != NULL)
	{
		// get current list
		pCurrentList = pSectObject->GetCurrentList(E_Sound);
		// get corresponding element
		m_aSymElems[E_Sound] = pCurrentList->GetElementWithSector(m_pEditedSector);
		m_aHadSymElem[E_Sound] = (m_aSymElems[E_Sound] != NULL);
		
		// if necessary, create it
		if (m_eModifType == E_mt_AddSectorInList)
		{
			// if necessary, create it
			if (!m_aSymElems[E_Sound])
				m_aSymElems[E_Sound] = new SECT_SoundElement(m_pEditedSector, pSectObject);
			// update parameter
			((SECT_SoundElement *) m_aElements[E_Sound])->SetSoundLevel(((SECT_SoundElement *) m_aSymElems[E_Sound])->GetSoundLevel());
		}
	}

	// sound event link
	if (m_aElements[E_SoundEvent] != NULL)
	{
		// get current list
		pCurrentList = pSectObject->GetCurrentList(E_SoundEvent);
		// get corresponding element
		m_aSymElems[E_SoundEvent] = pCurrentList->GetElementWithSector(m_pEditedSector);
		m_aHadSymElem[E_SoundEvent] = (m_aSymElems[E_SoundEvent] != NULL);
		
		// if necessary, create it
		if (m_eModifType == E_mt_AddSectorInList)
		{
			// if necessary, create it
			if (!m_aSymElems[E_SoundEvent])
				m_aSymElems[E_SoundEvent] = new SECT_SoundElement(m_pEditedSector, pSectObject);
			// update parameter
			((SECT_SoundEventElement *) m_aElements[E_SoundEvent])->fn_vCopyMissingSoundEvents((SECT_SoundEventElement *) m_aSymElems[E_SoundEvent], FALSE);
		}
	}
}

/*===========================================================================
		Update Symetric Links
=========================================================================*/
void SECT_ModifSectorLinks::fn_vUpdateSymetricLinks (BOOL bDo)
{
	SECT_ListBase		*pCurrentList;
	Sector_Object		*pSectObject;
	tdeTypeList			eList;
	int					iList;

	// get parameters
	pSectObject = (Sector_Object *) m_pSectorToAdd->GetObject();

	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		// get current list
		eList = (tdeTypeList) iList;
		if (m_aSymElems[eList] != NULL)
		{
			pCurrentList = pSectObject->GetCurrentList(eList);
			// update link
			switch (m_eModifType)
			{
				case E_mt_AddSectorInList:
					if (bDo)
						pSectObject->fn_bAddSectorInList(m_aSymElems[eList], eList);
					else if (!m_aHadSymElem[eList])
						pSectObject->fn_bRemoveSectorInList(m_aSymElems[eList], eList);
					break;

				case E_mt_DelSectorInList:
					if (bDo)
						pSectObject->fn_bRemoveSectorInList(m_aSymElems[eList], eList);
					else if (m_aHadSymElem[eList])
						pSectObject->fn_bAddSectorInList(m_aSymElems[eList], eList);
			}
			if (g_bCanSave)
				m_aSymElems[eList]->fn_vWriteSection();
		}
	}
}


/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifSectorLinks::fn_vReinitEditorState (void)
{
	int						iList;

	// set editor mode
	m_pSectorInterface->SetEditMode(m_eCurrentEditMode, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
	// list mode => update current list
	if (m_eCurrentEditMode == E_em_EditList)
	{
		m_pSectorInterface->SetListActivity(E_NoActiveList, FALSE, FALSE);
		for (iList = 0; iList < C_NumberOfLists; iList++)
		{		
			if (m_aElements[(tdeTypeList) iList] != NULL)
				m_pSectorInterface->SetListActivity((tdeTypeList) iList, TRUE, FALSE);
		}
	}
	// sector mode => update selected sector
	else if (m_eCurrentEditMode == E_em_EditSector)
		m_pSectorInterface->fn_vSelectNewSector(m_pSectorToAdd, FALSE, FALSE);
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifSectorLinks::fn_vUpdateEditorState (void)
{
	SECT_DialogBase *pSingleList;
	SECT_ListBase	*pCurrentList;
	tdeTypeList		eList;
	int				iList;
	
	// update drawing
	if (m_eCurrentEditMode == E_em_EditList)
	{
		m_pSectorInterface->fn_vSetRecursiveColor(m_pSectorToAdd, (m_bAdded) ? C_ColorShow : C_NoColor);
		m_pSectorInterface->GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
	}
	else if (m_eCurrentEditMode == E_em_EditSector)
		m_pSectorInterface->GetDialogSel()->fn_vReinitDialog(m_pSectorToAdd, m_pEditedSector);

	// update dialogs
	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		eList = (tdeTypeList) iList;
		// get parameters
		pSingleList = m_pSectorInterface->GetSingleList(eList);
		pCurrentList = ((Sector_Object *) m_pEditedSector->GetObject())->GetCurrentList(eList);

		if (m_eCurrentEditMode == E_em_EditList)
			pSingleList->fn_vInitSectorList(pCurrentList);
		else if (m_eCurrentEditMode == E_em_EditSector)
		{
			pSingleList->fn_vInitSectorList(pCurrentList);
			pSingleList->fn_vUpdateSelection(m_pSectorToAdd);
		}
	}

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Sector Links Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Sector Links Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}


//#################################################################################
// class SECT_ModifFullLinks 
//#################################################################################

/*===========================================================================
		Save Link
=========================================================================*/
SECT_SaveFullLink::SECT_SaveFullLink (Sector_Object *pSector, SECT_ElementBase *pElement, tdeTypeList eList)
{
	// save parameters
	m_pSector = pSector;
	m_eListToUpdate = eList;
	// create corresponding element
	m_pElement = pElement;
}

SECT_SaveFullLink::~SECT_SaveFullLink (void)
{

}

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifFullLink::SECT_ModifFullLink (Sector_Interface *pInterface, tdeSectModifType eModifType, 
										CPA_SuperObject *pEditedSector, tdeTypeList eListToUpdate)
		: CPA_Modif(TYPE_FULLLINK, "FullLink", FALSE)
{
	CPA_BaseObjectList	*pListSector;
	SECT_ElementBase	*pElement;
	CPA_BaseObject		*pElem;
	SECT_ListBase		*pCurrentList;
	Sector_Object		*pSector, *pSectObj;
	Position			Pos;
	POSITION			pos;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pEditedSector = pEditedSector;
	m_eListToUpdate = eListToUpdate;
	// get corresponding parameters
	pSector = (Sector_Object *) m_pEditedSector->GetObject();
	pCurrentList = pSector->GetCurrentList(m_eListToUpdate);
	pListSector = m_pSectorInterface->GetBaseObjectList(C_szSectorTypeName);
	if (m_eModifType == E_mt_AddFullLink)
	{
		for (pElem = pListSector->GetHeadElement(Pos); pElem;
			 pElem = pListSector->GetNextElement(Pos))
		{
			// get sector
			pSectObj = (Sector_Object *) pElem;
			// check if element exists
			if (pSectObj != pSector)
				pElement = pCurrentList->GetElementWithSector(pSectObj->GetSuperObject());
			if ((!pElement)&&(pSectObj != pSector))
			{
				// create element
				pElement = pSector->GetNewElement(m_eListToUpdate, pSectObj->GetSuperObject());
				// add it to the list
				m_oListOfSectors.AddTail(pElement);
			}
		}
	}
	if (m_eModifType == E_mt_DelFullLink)
	{
		for (pElement = pCurrentList->GetHeadElementBase(pos); pElement;
			 pElement = pCurrentList->GetNextElementBase(pos))
			m_oListOfSectors.AddTail(pElement);
	}
	// init for symetric
	m_bSymetric = m_pSectorInterface->fn_bSymetricMode();
	if (m_bSymetric)
		fn_vInitSymetricLinks();
}


SECT_ModifFullLink::~SECT_ModifFullLink (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifFullLink::Do (void)
{
	SECT_ElementBase	*pElem;
	Sector_Object		*pSector;
	POSITION			pos;

	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// get current list
	pSector = (Sector_Object *) m_pEditedSector->GetObject();
	// add sectors in list
	for (pElem = m_oListOfSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListOfSectors.GetNextElement(pos))
	{
		if (m_eModifType == E_mt_AddFullLink)
			pSector->fn_bAddSectorInList(pElem, m_eListToUpdate);
		if (m_eModifType == E_mt_DelFullLink)
			pSector->fn_bRemoveSectorInList(pElem, m_eListToUpdate);
	}
	// if necessary, update symetric link
	if (m_bSymetric)
		fn_vUpdateSymetricLinks(m_eModifType == E_mt_AddFullLink);
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifFullLink::Undo (void)
{
	SECT_ElementBase	*pElem;
	Sector_Object		*pSector;
	POSITION			pos;

	// update editor mode
	fn_vReinitEditorState();
	// get current list
	pSector = (Sector_Object *) m_pEditedSector->GetObject();
	// add sector in list
	for (pElem = m_oListOfSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListOfSectors.GetNextElement(pos))
	{
		if (m_eModifType == E_mt_AddFullLink)
			pSector->fn_bRemoveSectorInList(pElem, m_eListToUpdate);
		if (m_eModifType == E_mt_DelFullLink)
			pSector->fn_bAddSectorInList(pElem, m_eListToUpdate);
	}

	// if necessary, update symetric link
	if (m_bSymetric)
		fn_vUpdateSymetricLinks(m_eModifType == E_mt_DelFullLink);
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}

/*===========================================================================
		Init Symetric Links
=========================================================================*/
void SECT_ModifFullLink::fn_vInitSymetricLinks (void)
{
	CPA_BaseObjectList	*pListSector;
	SECT_SaveFullLink	*pSaveLink;
	SECT_ElementBase	*pElement;
	CPA_BaseObject		*pElem;
	SECT_ListBase		*pCurrentList;
	Sector_Object		*pSector;
	Position			Pos;
	
	// check all sectors
	pListSector = m_pSectorInterface->GetBaseObjectList(C_szSectorTypeName);
	for (pElem = pListSector->GetHeadElement(Pos); pElem;
		 pElem = pListSector->GetNextElement(Pos))
	{
		// get sector
		pSector = (Sector_Object *) pElem;
		pCurrentList = pSector->GetCurrentList(m_eListToUpdate);
		// check if element exists
		pElement = pCurrentList->GetElementWithSector(m_pEditedSector);
		if ((m_eModifType == E_mt_AddFullLink)&&(pElement == NULL))
		{
			pElement = pSector->GetNewElement(m_eListToUpdate, m_pEditedSector);
			pSaveLink = new SECT_SaveFullLink(pSector, pElement, m_eListToUpdate);
			m_oListOfSymetrics.AddTail(pSaveLink);
		}
		if ((m_eModifType == E_mt_DelFullLink)&&(pElement != NULL))
		{
			pSaveLink = new SECT_SaveFullLink(pSector, pElement, m_eListToUpdate);
			m_oListOfSymetrics.AddTail(pSaveLink);
		}
	}
}

/*===========================================================================
		Update Symetric Links
=========================================================================*/
void SECT_ModifFullLink::fn_vUpdateSymetricLinks (BOOL bDo)
{
	SECT_SaveFullLink	*pSaveLink;
	POSITION			pos;

	for (pSaveLink = m_oListOfSymetrics.GetHeadElement(pos); pSaveLink;
		 pSaveLink = m_oListOfSymetrics.GetNextElement(pos))
	{
		if (bDo)
			pSaveLink->m_pSector->fn_bAddSectorInList(pSaveLink->m_pElement, m_eListToUpdate);
		else
			pSaveLink->m_pSector->fn_bRemoveSectorInList(pSaveLink->m_pElement, m_eListToUpdate);
	}
}


/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifFullLink::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditSector, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
	// sector mode => update selected sector
	m_pSectorInterface->fn_vSelectNewSector(NULL, FALSE, FALSE);
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifFullLink::fn_vUpdateEditorState (void)
{
	SECT_DialogBase *pSingleList;
	SECT_ListBase	*pCurrentList;
	
	// get parameters
	pSingleList = m_pSectorInterface->GetSingleList(m_eListToUpdate);
	pCurrentList = ((Sector_Object *) m_pEditedSector->GetObject())->GetCurrentList(m_eListToUpdate);

	m_pSectorInterface->GetDialogSel()->fn_vReinitDialog(NULL, m_pEditedSector);
	pSingleList->fn_vInitSectorList(pCurrentList);
	pSingleList->fn_vUpdateSelection(NULL);

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Full Link Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Full Link Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}

//#################################################################################
// class SECT_ModifSectorParams 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifSectorParams::SECT_ModifSectorParams  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
											    tdeTypeList eListToUpdate, SECT_ElementBase *pElem, 
												int iNewValue, SECT_SoundEvent *pSoundEvent)
		: CPA_Modif(TYPE_SECTORPARAMS, "SectorParams", FALSE)
{
	SECT_ElementBase	*pSymElem;
	Sector_Object		*pSector;
	
	// init parent editor
	m_pSectorInterface = pInterface;
	m_pEditedSector = pInterface->GetEditedSector();
	m_pSelectedSector = pElem->GetSector();
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_iNewValue = iNewValue;
	m_pSoundEvent = pSoundEvent;
	m_pElementToUpdate = pElem;
	m_eListToUpdate = eListToUpdate;
	m_bSymetricLink = m_pSectorInterface->fn_bSymetricMode();
	// save parameters
	if (m_pSelectedSector)
	{
		pSector = (Sector_Object *) m_pSelectedSector->GetObject();
		pSymElem = pSector->GetCurrentList(eListToUpdate)->GetElementWithSector(m_pEditedSector);

		switch (m_eModifType)
		{
			case E_mt_ChangeLevelOfDetail:
				m_iOldValue = ((SECT_GraphicElement *) pElem)->GetGraphicLevel();
				if (m_bSymetricLink)
					m_iOldSymetric = ((SECT_GraphicElement *) pSymElem)->GetGraphicLevel();
				break;
			case E_mt_ChangeGraphicMode:
				m_iOldValue = ((SECT_GraphicElement *) pElem)->GetGraphicMode();
				if (m_bSymetricLink)
					m_iOldSymetric = ((SECT_GraphicElement *) pSymElem)->GetGraphicMode();
				break;
			case E_mt_ChangeSoundVolume:
				m_iOldValue = ((SECT_SoundElement *) pElem)->GetSoundLevel();
				if (m_bSymetricLink)
					m_iOldSymetric = ((SECT_SoundElement *) pSymElem)->GetSoundLevel();
				break;
			case E_mt_AddSoundEvent:
			case E_mt_DelSoundEvent:
				m_iOldValue = -1;
				break;
		}
	}
}


SECT_ModifSectorParams::~SECT_ModifSectorParams (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifSectorParams::Do (void)
{
	SECT_ElementBase	*pElem = NULL;
	Sector_Object		*pSectObject;

	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// if necessary, update symetric link
	if ((m_bSymetricLink)&&(m_pSelectedSector))
	{
		pSectObject = (Sector_Object *) m_pSelectedSector->GetObject();
		pElem = pSectObject->GetCurrentList(m_eListToUpdate)->GetElementWithSector(m_pEditedSector);
	}
	// get current list
	switch (m_eModifType)
	{
		case E_mt_ChangeLevelOfDetail:
			// update level
			((SECT_GraphicElement *) m_pElementToUpdate)->SetGraphicLevel(m_iNewValue);
			// update symetric link
			if (pElem)
				((SECT_GraphicElement *) pElem)->SetGraphicLevel(m_iNewValue);
			break;
		case E_mt_ChangeGraphicMode:
			// update level
			((SECT_GraphicElement *) m_pElementToUpdate)->SetGraphicMode(m_iNewValue);
			// update symetric link
			if (pElem)
				((SECT_GraphicElement *) pElem)->SetGraphicMode(m_iNewValue);
			break;
		case E_mt_ChangeSoundVolume:
			// update level
			((SECT_SoundElement *) m_pElementToUpdate)->SetSoundLevel(m_iNewValue);
			// update symetric link
			if (pElem)
				((SECT_SoundElement *) pElem)->SetSoundLevel(m_iNewValue);
			break;
		case E_mt_AddSoundEvent:
			// add sound event
			pSectObject = (Sector_Object *) m_pEditedSector->GetObject();
			pSectObject->GetSoundEventList()->fn_bAddAnElement(m_pSelectedSector, m_pSoundEvent);
			// update symetric link
			if ((m_bSymetricLink)&&(m_pSelectedSector))
			{
				pSectObject = (Sector_Object *) m_pSelectedSector->GetObject();
				pSectObject->GetSoundEventList()->fn_bAddAnElement(m_pEditedSector, m_pSoundEvent);
			}
			break;

		case E_mt_DelSoundEvent:
			// add sound event
			pSectObject = (Sector_Object *) m_pEditedSector->GetObject();
			pSectObject->GetSoundEventList()->fn_bRemoveAnElement(m_pSelectedSector, m_pSoundEvent);
			// update symetric link
			if ((m_bSymetricLink)&&(m_pSelectedSector))
			{
				pSectObject = (Sector_Object *) m_pSelectedSector->GetObject();
				pSectObject->GetSoundEventList()->fn_bRemoveAnElement(m_pEditedSector, m_pSoundEvent);
			}
			break;
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifSectorParams::Undo (void)
{
	SECT_ElementBase	*pElem = NULL;
	Sector_Object		*pSectObject;

	// update editor mode
	fn_vReinitEditorState();
	// if necessary, update symetric link
	if ((m_bSymetricLink)&&(m_pSelectedSector))
	{
		pSectObject = (Sector_Object *) m_pSelectedSector->GetObject();
		pElem = pSectObject->GetCurrentList(m_eListToUpdate)->GetElementWithSector(m_pEditedSector);
	}
	// get current list
	switch (m_eModifType)
	{
		case E_mt_ChangeLevelOfDetail:
			// set level
			((SECT_GraphicElement *) m_pElementToUpdate)->SetGraphicLevel(m_iOldValue);
			// update symetric link
			if (pElem)
				((SECT_GraphicElement *) pElem)->SetGraphicLevel(m_iOldSymetric);
			break;
		case E_mt_ChangeGraphicMode:
			// set level
			((SECT_GraphicElement *) m_pElementToUpdate)->SetGraphicMode(m_iOldValue);
			// update symetric link
			if (pElem)
				((SECT_GraphicElement *) pElem)->SetGraphicMode(m_iOldSymetric);
			break;
		case E_mt_ChangeSoundVolume:
			// set level
			((SECT_SoundElement *) m_pElementToUpdate)->SetSoundLevel(m_iOldValue);
			// update symetric link
			if (pElem)
				((SECT_SoundElement *) pElem)->SetSoundLevel(m_iOldSymetric);
			break;
		case E_mt_AddSoundEvent:
			// add sound event
			pSectObject = (Sector_Object *) m_pEditedSector->GetObject();
			pSectObject->GetSoundEventList()->fn_bRemoveAnElement(m_pSelectedSector, m_pSoundEvent);
			// update symetric link
			if ((m_bSymetricLink)&&(m_pSelectedSector))
			{
				pSectObject = (Sector_Object *) m_pSelectedSector->GetObject();
				pSectObject->GetSoundEventList()->fn_bRemoveAnElement(m_pEditedSector, m_pSoundEvent);
			}
			break;

		case E_mt_DelSoundEvent:
			// add sound event
			pSectObject = (Sector_Object *) m_pEditedSector->GetObject();
			pSectObject->GetSoundEventList()->fn_bAddAnElement(m_pSelectedSector, m_pSoundEvent);
			// update symetric link
			if ((m_bSymetricLink)&&(m_pSelectedSector))
			{
				pSectObject = (Sector_Object *) m_pSelectedSector->GetObject();
				pSectObject->GetSoundEventList()->fn_bAddAnElement(m_pEditedSector, m_pSoundEvent);
			}
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}

/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifSectorParams::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditSector, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
	// update selected sector
	m_pSectorInterface->fn_vSelectNewSector(m_pSelectedSector, FALSE, FALSE);
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifSectorParams::fn_vUpdateEditorState (void)
{
	SECT_DialogBase *pSingleList;
	SECT_ListBase	*pCurrentList;
	
	// reinit selection dialog
	if (!m_bFirstTime)
		m_pSectorInterface->GetDialogSel()->fn_vReinitDialog(m_pSelectedSector, m_pEditedSector);
	// reinit corresponding list dialog
	switch (m_eModifType)
	{
		case E_mt_ChangeLevelOfDetail:
		case E_mt_ChangeGraphicMode:
			pSingleList = m_pSectorInterface->GetSingleList(E_Graphic);
			pCurrentList = ((Sector_Object *) m_pEditedSector->GetObject())->GetCurrentList(E_Graphic);
			break;
		case E_mt_ChangeSoundVolume:
			pSingleList = m_pSectorInterface->GetSingleList(E_Sound);
			pCurrentList = ((Sector_Object *) m_pEditedSector->GetObject())->GetCurrentList(E_Sound);
			break;
		case E_mt_AddSoundEvent:
		case E_mt_DelSoundEvent:
			pSingleList = m_pSectorInterface->GetSingleList(E_SoundEvent);
			pCurrentList = ((Sector_Object *) m_pEditedSector->GetObject())->GetCurrentList(E_SoundEvent);
			break;
	}
	pSingleList->fn_vInitSectorList(pCurrentList);
	pSingleList->fn_vUpdateSelection(m_pSelectedSector);

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Link parameters Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Link parameters Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}



//#################################################################################
// class SECT_ModifEnvAndSrf 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifEnvAndSrf::SECT_ModifEnvAndSrf  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
										   CPA_SuperObject *pEditedSector, long lNumEnvElem,
										   SECT_Environment	*pNewEnv, SECT_Surface *pNewSurf)
		: CPA_Modif(TYPE_ENVANDSRF, "EnvAndSrf", FALSE)
{
	Sector_Object *pSectObj;
	// init parent editor
	m_pSectorInterface = pInterface;
	m_pEditedSector = pEditedSector;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	pSectObj = (Sector_Object *) m_pEditedSector->GetObject();
	switch (m_eModifType)
	{
		case E_mt_AddEnvAndSrf:
			m_pNewEnvElem = new SECT_EnvElem(pNewEnv, pSectObj);
			m_pNewSurfElem = new SECT_SurfElem(pNewSurf, pSectObj);
			m_pOldEnvElem = NULL;
			m_pOldSurfElem = NULL;
			break;
		case E_mt_DelEnvAndSrf:
			m_pOldEnvElem = pSectObj->GetEnvironment(lNumEnvElem);
			m_pOldSurfElem = pSectObj->GetSurface(lNumEnvElem);
			if (!m_pOldSurfElem)
				m_pOldSurfElem = pSectObj->GetSurface(lNumEnvElem-1);
			m_pNewEnvElem = NULL;
			m_pNewSurfElem = NULL;
	}
}
*/


/*
SECT_ModifEnvAndSrf::~SECT_ModifEnvAndSrf (void) 
{ 
}
*/


/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifEnvAndSrf::Do (void)
{
	Sector_Object *pSectObj;
	
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update list
	pSectObj = (Sector_Object *) m_pEditedSector->GetObject();
	if (m_eModifType == E_mt_AddEnvAndSrf)
		pSectObj->fn_bAddEnvironmentElement(m_pNewEnvElem, m_pNewSurfElem);
	else if (m_eModifType == E_mt_DelEnvAndSrf)
		pSectObj->fn_bDelEnvironmentElement(m_pOldEnvElem, m_pOldSurfElem);
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifEnvAndSrf::Undo (void)
{
	Sector_Object *pSectObj;
	
	// update editor mode
	fn_vReinitEditorState();
	// update list
	pSectObj = (Sector_Object *) m_pEditedSector->GetObject();
	if (m_eModifType == E_mt_AddEnvAndSrf)
		pSectObj->fn_bDelEnvironmentElement(m_pNewEnvElem, m_pNewSurfElem);
	else if (m_eModifType == E_mt_DelEnvAndSrf)
		pSectObj->fn_bAddEnvironmentElement(m_pOldEnvElem, m_pOldSurfElem);
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifEnvAndSrf::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifEnvAndSrf::fn_vUpdateEditorState (void)
{
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Env&Srf Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Env&Srf Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/


//#################################################################################
// class SECT_ModifEnvElem 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifEnvElem::SECT_ModifEnvElem  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
									   SECT_EnvElem *pEnvElem, SECT_Environment *pNewEnv,
									   long lNumEnvElem)
		: CPA_Modif(TYPE_MODIFENV, "ChangeEnv", FALSE)
{
	// init parent editor
	m_pSectorInterface = pInterface;
	m_pEditedSector = m_pSectorInterface->GetEditedSector();
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_lNumEnvElem = lNumEnvElem;
	m_pEnvElem = pEnvElem;
	m_pOldEnv = pEnvElem->GetEnvironment();
	m_pNewEnv = pNewEnv;
}


SECT_ModifEnvElem::~SECT_ModifEnvElem (void) 
{ 
}
*/


/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifEnvElem::Do (void)
{
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update environment
	if (m_eModifType == E_mt_ChangeEnv)
		m_pEnvElem->SetEnvironment(m_pNewEnv);
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifEnvElem::Undo (void)
{
	// update editor mode
	fn_vReinitEditorState();
	// update environment 
	if (m_eModifType == E_mt_ChangeEnv)
		m_pEnvElem->SetEnvironment(m_pOldEnv);
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifEnvElem::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifEnvElem::fn_vUpdateEditorState (void)
{
	// reinit envlist
	if (!m_bFirstTime)
		m_pSectorInterface->GetDialogEnvList()->fn_vInitEnvElem(m_lNumEnvElem);
	
	// status bar
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Environment Element Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Environment Element Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/


//#################################################################################
// class SECT_ModifSurfElem 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifSurfElem::SECT_ModifSurfElem  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
										 SECT_SurfElem *pSurfElem, SECT_Surface *pNewSurf, 
										 long lNumEnvElem)
		: CPA_Modif(TYPE_MODIFSRF, "ChangeSurf", FALSE)
{
	// init parent editor
	m_pSectorInterface = pInterface;
	m_pEditedSector = m_pSectorInterface->GetEditedSector();
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_lOldNum = lNumEnvElem;
	m_pSurfElem = pSurfElem;
	m_pOldSurf = pSurfElem->GetSurface();
	m_pNewSurf = pNewSurf;
}


SECT_ModifSurfElem::~SECT_ModifSurfElem (void) 
{ 
}
*/


/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifSurfElem::Do (void)
{
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update surface
	if (m_eModifType == E_mt_ChangeSrf)
	{
		m_pSurfElem->SetSurface(m_pNewSurf);
		m_lNewNum = m_pSurfElem->GetOwnerSector()->fn_lUpdateEnvironmentElement(m_lOldNum);
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifSurfElem::Undo (void)
{
	// update editor mode
	fn_vReinitEditorState();
	// update surface
	if (m_eModifType == E_mt_ChangeSrf)
	{
		m_pSurfElem->SetSurface(m_pOldSurf);
		m_lOldNum = m_pSurfElem->GetOwnerSector()->fn_lUpdateEnvironmentElement(m_lNewNum);
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifSurfElem::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifSurfElem::fn_vUpdateEditorState (void)
{
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Surface Element Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Surface Element Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/

//#################################################################################
// class SECT_ModifSrfParams
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifSrfParams::SECT_ModifSrfParams  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
										   SECT_Surface *pSurface, MTH_tdxReal xNewHeight)
		: CPA_Modif(TYPE_SRFPARAMS, "ModifSrf", FALSE)
{
	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pSurface = pSurface;
	m_xNewHeight = xNewHeight;
	m_xOldHeight = pSurface->GetHeight();
}


SECT_ModifSrfParams::~SECT_ModifSrfParams (void) 
{ 
}
*/

/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifSrfParams::Do (void)
{
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update surface
	if (m_eModifType == E_mt_ChangeSrfHeight)
	{
		m_pSurface->SetHeight(m_xNewHeight);
		m_pSectorInterface->fn_vUpdateHeightIndex(m_pSurface);
		m_pSectorInterface->fn_vUpdateAllSurfaceList(m_pSurface);
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifSrfParams::Undo (void)
{
	// update editor mode
	fn_vReinitEditorState();
	// update surface
	if (m_eModifType == E_mt_ChangeSrfHeight)
	{
		m_pSurface->SetHeight(m_xOldHeight);
		m_pSectorInterface->fn_vUpdateHeightIndex(m_pSurface);
		m_pSectorInterface->fn_vUpdateAllSurfaceList(m_pSurface);
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifSrfParams::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifSrfParams::fn_vUpdateEditorState (void)
{
	if (!m_bFirstTime)
	{
		// cancel envelem selection
		m_pSectorInterface->GetDialogEnvList()->fn_vInitEnvList(m_pSectorInterface->GetEditedSector());
		// select environment
		m_pSectorInterface->GetDialogSrf()->fn_vInitSurfListBox();
		m_pSectorInterface->GetDialogSrf()->fn_vSelectSurf(m_pSurface);
	}

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Surface Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Surface Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/

//#################################################################################
// class SECT_ModifEnvParams
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifEnvParams::SECT_ModifEnvParams  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
										   SECT_Environment *pEnvironment, SECT_MecEnvironment *pNewMecEnv, 
										   SECT_VisEnvironment *pNewVisEnv, SECT_SndEnvironment *pNewSndEnv)
		: CPA_Modif(TYPE_ENVPARAMS, "ModifEnv", FALSE)
{
	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pEnvironment = pEnvironment;
	m_pNewMecEnv = pNewMecEnv;
	m_pOldMecEnv = pEnvironment->GetMecEnvironment();
	m_pNewVisEnv = pNewVisEnv;
	m_pOldVisEnv = pEnvironment->GetVisEnvironment();
	m_pNewSndEnv = pNewSndEnv;
	m_pOldSndEnv = pEnvironment->GetSndEnvironment();
}


SECT_ModifEnvParams::~SECT_ModifEnvParams (void) 
{ 
}
*/

/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifEnvParams::Do (void)
{
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update list
	if (m_eModifType == E_mt_ChangeMecEnv)
		m_pEnvironment->SetMecEnvironment(m_pNewMecEnv);
	else if (m_eModifType == E_mt_ChangeVisEnv)
		m_pEnvironment->SetVisEnvironment(m_pNewVisEnv);
	else if (m_eModifType == E_mt_ChangeSndEnv)
		m_pEnvironment->SetSndEnvironment(m_pNewSndEnv);
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifEnvParams::Undo (void)
{
	// update editor mode
	fn_vReinitEditorState();
	// update list
	if (m_eModifType == E_mt_ChangeMecEnv)
		m_pEnvironment->SetMecEnvironment(m_pOldMecEnv);
	else if (m_eModifType == E_mt_ChangeVisEnv)
		m_pEnvironment->SetVisEnvironment(m_pOldVisEnv);
	else if (m_eModifType == E_mt_ChangeSndEnv)
		m_pEnvironment->SetSndEnvironment(m_pOldSndEnv);
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifEnvParams::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifEnvParams::fn_vUpdateEditorState (void)
{
	if (!m_bFirstTime)
	{
		// cancel envelem selection
		m_pSectorInterface->GetDialogEnvList()->fn_vInitEnvElem(-1);
		// select environment
		m_pSectorInterface->GetDialogEnvs()->fn_vSelectEnv(m_pEnvironment);
	}

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Env parameters Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Env parameters Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/


//#################################################################################
// class SECT_ModifMecEnvParams
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifMecEnvParams::SECT_ModifMecEnvParams  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
												 SECT_MecEnvironment *pMecEnv, CString csName, 
												 MTH_tdxReal xGravity, DNM_tdstVector *pVertical, 
												 MTH_tdxReal xViscosity, MTH_tdxReal xDensity, 
												 MTH_tdxReal xLevel, DNM_tdstVector *pStream, 
												 CString csVolumic)
		: CPA_Modif(TYPE_MECENV, "ModifMecEnv", FALSE)
{
	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pMecEnv = pMecEnv;
	// init name
	m_csOldName = m_pMecEnv->GetName();
	m_csNewName = csName;
	// init gravity
	m_xOldGravity = (float) m_pMecEnv->GetGravity();
	m_xNewGravity = (float) xGravity;
	m_stOldVertical = *(m_pMecEnv->GetVertical());
	m_stNewVertical = *pVertical;
	// init fluid
	m_xOldViscosity = (float) m_pMecEnv->GetFluidViscosity();
	m_xNewViscosity = (float) xViscosity;
	m_xOldDensity = (float) m_pMecEnv->GetFluidDensity();
	m_xNewDensity = (float) xDensity;
	m_xOldLevel = (float) m_pMecEnv->GetFluidLevel();
	m_xNewLevel = (float) xLevel;
	m_stOldStream = *(m_pMecEnv->GetFluidStream());
	m_stNewStream = *pStream;
	// init volumic
	m_csOldVolumic = m_pMecEnv->GetVolumicEnvironment();
	m_csNewVolumic = csVolumic;
}


SECT_ModifMecEnvParams::~SECT_ModifMecEnvParams (void) 
{ 
}

*/
/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifMecEnvParams::Do (void)
{
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update mec env
	if (m_eModifType == E_tm_ModifMecEnv)
	{
		// name
		if (m_pMecEnv->GetName() != m_csNewName)
			m_pMecEnv->fn_eRename(m_csNewName);
		// gravity
		m_pMecEnv->SetGravity(m_xNewGravity);
		m_pMecEnv->SetVertical(&m_stNewVertical);
		// fluid
		m_pMecEnv->SetFluidViscosity(m_xNewViscosity);
		m_pMecEnv->SetFluidDensity(m_xNewDensity);
		m_pMecEnv->SetFluidLevel(m_xNewLevel);
		m_pMecEnv->SetFluidStream(&m_stNewStream);
		// volumic
		m_pMecEnv->SetVolumicEnvironment(m_csNewVolumic);
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/
/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifMecEnvParams::Undo (void)
{
	// update editor mode
	fn_vReinitEditorState();
	// update mec env
	if (m_eModifType == E_tm_ModifMecEnv)
	{
		// name
		if (m_pMecEnv->GetName() != m_csOldName)
			m_pMecEnv->fn_eRename(m_csOldName);
		// gravity
		m_pMecEnv->SetGravity(m_xOldGravity);
		m_pMecEnv->SetVertical(&m_stOldVertical);
		// fluid
		m_pMecEnv->SetFluidViscosity(m_xOldViscosity);
		m_pMecEnv->SetFluidDensity(m_xOldDensity);
		m_pMecEnv->SetFluidLevel(m_xOldLevel);
		m_pMecEnv->SetFluidStream(&m_stOldStream);
		// volumic
		m_pMecEnv->SetVolumicEnvironment(m_csOldVolumic);
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/
/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifMecEnvParams::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
}
*/
/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifMecEnvParams::fn_vUpdateEditorState (void)
{
	if (!m_bFirstTime)
	{
		// cancel envelem selection
		m_pSectorInterface->GetDialogEnvList()->fn_vInitEnvElem(-1);
		// cancel environment
		m_pSectorInterface->GetDialogEnvs()->fn_vSelectEnv(NULL);
		// select mecenv
		m_pSectorInterface->GetDialogEnv()->fn_vSelectMechanic(m_pMecEnv);
	}

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Mec Environment Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Mec Environment Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/


//#################################################################################
// class SECT_ModifVisEnvParams
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifVisEnvParams::SECT_ModifVisEnvParams  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
												 SECT_VisEnvironment *pVisEnv, CString csName, 
												 MTH_tdxReal xNear, MTH_tdxReal xFar, 
												 MTH_tdxReal xBlendNear, MTH_tdxReal xBlendFar, 
												 MTH_tdxReal xInfinite, GLI_tdstColor *pColor)
		: CPA_Modif(TYPE_MECENV, "ModifMecEnv", FALSE)
{
	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pVisEnv = pVisEnv;
	// init name
	m_csOldName = m_pVisEnv->GetName();
	m_csNewName = csName;
	// init parameters
	m_xOldNear = (float) m_pVisEnv->GetFogNear();
	m_xNewNear = (float) xNear;
	m_xOldFar = (float) m_pVisEnv->GetFogFar();
	m_xNewFar = (float) xFar;
	m_xOldBlendNear = (float) m_pVisEnv->GetFogBlendNear();
	m_xNewBlendNear = (float) xBlendNear;
	m_xOldBlendFar = (float) m_pVisEnv->GetFogBlendFar();
	m_xNewBlendFar = (float) xBlendFar;
	m_xOldInfinite = (float) m_pVisEnv->GetFogInfinite();
	m_xNewInfinite = (float) xInfinite;
	// init color
	m_stOldColor.xR = m_pVisEnv->GetFogColor()->xR;
	m_stOldColor.xG = m_pVisEnv->GetFogColor()->xG;
	m_stOldColor.xB = m_pVisEnv->GetFogColor()->xB;
	m_stNewColor.xR = pColor->xR;
	m_stNewColor.xG = pColor->xG;
	m_stNewColor.xB = pColor->xB;
}


SECT_ModifVisEnvParams::~SECT_ModifVisEnvParams (void) 
{ 
}
*/

/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifVisEnvParams::Do (void)
{
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update mec env
	if (m_eModifType == E_tm_ModifVisEnv)
	{
		// name
		if (m_pVisEnv->GetName() != m_csNewName)
			m_pVisEnv->fn_eRename(m_csNewName);
		// parameters
		m_pVisEnv->SetFogNear(m_xNewNear);
		m_pVisEnv->SetFogFar(m_xNewFar);
		m_pVisEnv->SetFogBlendNear(m_xNewBlendNear);
		m_pVisEnv->SetFogBlendFar(m_xNewBlendFar);
		m_pVisEnv->SetFogInfinite(m_xNewInfinite);
		// color
		m_pVisEnv->SetFogColor(&m_stNewColor);
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/
/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifVisEnvParams::Undo (void)
{
	// update editor mode
	fn_vReinitEditorState();
	// update mec env
	if (m_eModifType == E_tm_ModifVisEnv)
	{
		// name
		if (m_pVisEnv->GetName() != m_csOldName)
			m_pVisEnv->fn_eRename(m_csOldName);
		// gravity
		m_pVisEnv->SetFogNear(m_xOldNear);
		m_pVisEnv->SetFogFar(m_xOldFar);
		m_pVisEnv->SetFogBlendNear(m_xOldBlendNear);
		m_pVisEnv->SetFogBlendFar(m_xOldBlendFar);
		m_pVisEnv->SetFogInfinite(m_xOldInfinite);
		// color
		m_pVisEnv->SetFogColor(&m_stOldColor);
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/
/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifVisEnvParams::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
}
*/
/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifVisEnvParams::fn_vUpdateEditorState (void)
{
	if (!m_bFirstTime)
	{
		// cancel envelem selection
		m_pSectorInterface->GetDialogEnvList()->fn_vInitEnvElem(-1);
		// cancel environment
		m_pSectorInterface->GetDialogEnvs()->fn_vSelectEnv(NULL);
		// select mecenv
		m_pSectorInterface->GetDialogEnv()->fn_vSelectVisual(m_pVisEnv);
	}

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Visula Environment Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Visual Environment Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/


//#################################################################################
// class SECT_SaveEnvList 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_SaveEnvList::SECT_SaveEnvList (Sector_Object *pSector)
{
	SECT_Environment	*pEnv;
	SECT_Surface		*pSurf;
	SECT_SurfElem		*pSurfElem;
	SECT_EnvElem		*pEnvElem;
	long				lNumEnv, lNumSurf;

	// init sector
	m_pSector = pSector;
	// init envlist
	m_oListEnv.RemoveAll();
	for (lNumEnv = 0; lNumEnv < pSector->GetNbEnvironments(); lNumEnv++)
	{
		// get environment
		pEnvElem = pSector->GetEnvironment(lNumEnv);
		pEnv = pEnvElem->GetEnvironment();
		// add it to the list
		m_oListEnv.AddTail(pEnv);
	}
	// init srf list
	m_oListSrf.RemoveAll();
	for (lNumSurf = 0; lNumSurf < pSector->GetNbSurfaces(); lNumSurf++)
	{
		// get surface
		pSurfElem = pSector->GetSurface(lNumSurf);
		pSurf = pSurfElem->GetSurface();
		// add it to the list
		m_oListSrf.AddTail(pSurf);
	}
}

SECT_SaveEnvList::~SECT_SaveEnvList (void)
{

}
*/

//#################################################################################
// class SECT_ModifApplyToSectors 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifApplyToSectors::SECT_ModifApplyToSectors  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
													 CPA_SuperObject *pModel, CPA_List<CPA_SuperObject> *pListSectors)
		: CPA_Modif(TYPE_APPLY, "Apply", FALSE)
{
	CPA_BaseObjectList	*pListObject;
	CPA_SuperObject		*pSector;
	CPA_BaseObject		*pElem;
	Sector_Object		*pSectObj;
	SECT_Environment	*pEnv;
	SECT_Surface		*pSurf;
	SECT_SurfElem		*pSurfElem;
	SECT_EnvElem		*pEnvElem;
	Position			pos;
	POSITION			Pos;
	long				lNumEnv, lNumSurf;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_oListSectors.RemoveAll();
	// All sectors
	if (!pListSectors)
	{
		pListObject = m_pSectorInterface->GetBaseObjectList(C_szSectorTypeName);
		// for all sectors in ReachableObjectList
		for (pElem = pListObject->GetHeadElement(pos); pElem;
			 pElem = pListObject->GetNextElement(pos))
		{
			// apply same environment
			pSectObj = (Sector_Object *) pElem;
			m_oListSectors.AddTail(new SECT_SaveEnvList(pSectObj));
		}
	}
	// Selected sectors
	else
	{
		// for all sectors in select list
		for (pSector = pListSectors->GetHeadElement(Pos); pSector;
			 pSector = pListSectors->GetNextElement(Pos))
		{
			// apply same environment
			pSectObj = (Sector_Object *) pSector->GetObject();
			m_oListSectors.AddTail(new SECT_SaveEnvList(pSectObj));
		}
	}
	// Model
	m_pModel = pModel;
	pSectObj = (Sector_Object *) pModel->GetObject();
	// init envlist
	m_oListEnv.RemoveAll();
	for (lNumEnv = 0; lNumEnv < pSectObj->GetNbEnvironments(); lNumEnv++)
	{
		// get environment
		pEnvElem = pSectObj->GetEnvironment(lNumEnv);
		pEnv = pEnvElem->GetEnvironment();
		// add it to the list
		m_oListEnv.AddTail(pEnv);
	}
	// init srf list
	m_oListSrf.RemoveAll();
	for (lNumSurf = 0; lNumSurf < pSectObj->GetNbSurfaces(); lNumSurf++)
	{
		// get surface
		pSurfElem = pSectObj->GetSurface(lNumSurf);
		pSurf = pSurfElem->GetSurface();
		// add it to the list
		m_oListSrf.AddTail(pSurf);
	}
}


SECT_ModifApplyToSectors::~SECT_ModifApplyToSectors (void) 
{ 
}
*/

/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifApplyToSectors::Do (void)
{
	SECT_SaveEnvList	*pElem;
	Sector_Object		*pSectObj;
	POSITION			pos;
	
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update sectors
	for (pElem = m_oListSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListSectors.GetNextElement(pos))
	{
		pSectObj = pElem->m_pSector;
		pSectObj->fn_vApplySameEnvironment(&m_oListEnv, &m_oListSrf);
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifApplyToSectors::Undo (void)
{
	SECT_SaveEnvList	*pElem;
	Sector_Object		*pSectObj;
	POSITION			pos;
	
	// update editor mode
	fn_vReinitEditorState();
	// update sectors
	for (pElem = m_oListSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListSectors.GetNextElement(pos))
	{
		pSectObj = pElem->m_pSector;
		pSectObj->fn_vApplySameEnvironment(&pElem->m_oListEnv, &pElem->m_oListSrf);
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifApplyToSectors::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pModel)
		m_pSectorInterface->fn_vReinitEditor(m_pModel);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifApplyToSectors::fn_vUpdateEditorState (void)
{
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Apply Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Apply Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/



//#################################################################################
// class SECT_SaveSectorLinks
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_SaveSectorLinks::SECT_SaveSectorLinks (CPA_SuperObject *pSector, CPA_SuperObject *pModel, tdeTypeList eList)
{
	SECT_ElementBase		*pElem, *pEditElem;
	Sector_Object			*pEditSector;
	
	// init params
	m_iOldParam = m_iNewParam = -1;
	m_iOldMode = m_iNewMode = -1;
	m_pNewElement = m_pOldElement = NULL;
	// get corresponding element
	m_pSector = (Sector_Object *) pSector->GetObject();
	pElem = m_pSector->GetCurrentList(eList)->GetElementWithSector(pModel);
	pEditSector = (Sector_Object *) pModel->GetObject();
	pEditElem = pEditSector->GetCurrentList(eList)->GetElementWithSector(pSector);
	// init parameters
	switch (eList)
	{
		case E_Graphic:
			// save new value
			m_iNewParam = ((SECT_GraphicElement *) pEditElem)->GetGraphicLevel();
			m_iNewMode = ((SECT_GraphicElement *) pEditElem)->GetGraphicMode();
			if (!pElem)
			{
				m_pNewElement = m_pSector->GetNewElement(E_Graphic, pModel);
				((SECT_GraphicElement *) m_pNewElement)->SetGraphicLevel(m_iNewParam);
				((SECT_GraphicElement *) m_pNewElement)->SetGraphicMode(m_iNewMode);
			}
			else
			{
				m_iOldParam = ((SECT_GraphicElement *) pElem)->GetGraphicLevel();
				m_iOldMode = ((SECT_GraphicElement *) pElem)->GetGraphicMode();
			}
			break;

		case E_Sound:
			// save new value
			m_iNewParam = ((SECT_SoundElement *) pEditElem)->GetSoundLevel();
			if (!pElem)
			{
				m_pNewElement = m_pSector->GetNewElement(E_Sound, pModel);
				((SECT_SoundElement *) m_pNewElement)->SetSoundLevel(m_iNewParam);
			}
			else
				m_iOldParam = ((SECT_SoundElement *) pElem)->GetSoundLevel();
			break;

		case E_Collision:
			// save new value
			if (!pElem)
				m_pNewElement = m_pSector->GetNewElement(E_Collision, pModel);
			break;

		case E_Activity:
			// save new value
			if (!pElem)
				m_pNewElement = m_pSector->GetNewElement(E_Activity, pModel);
			break;

		case E_SoundEvent:
			// create copy of new one
			m_pNewElement = m_pSector->GetNewElement(E_SoundEvent, pModel);
			((SECT_SoundEventElement *)m_pNewElement)->fn_vCopyMissingSoundEvents((SECT_SoundEventElement *)pEditElem);
			// create copy of old one
			if (pElem)
			{
				m_pOldElement = m_pSector->GetNewElement(E_SoundEvent, pModel);
				((SECT_SoundEventElement *)m_pOldElement)->fn_vCopyMissingSoundEvents((SECT_SoundEventElement *)pElem);
			}
	}
}

SECT_SaveSectorLinks::~SECT_SaveSectorLinks (void)
{

}


//#################################################################################
// class SECT_ModifSymetricLinks 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifSymetricLinks::SECT_ModifSymetricLinks  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
												   CPA_SuperObject *pModel, tdeTypeList eList)
		: CPA_Modif(TYPE_SYMETRICLINKS, "SymetricLinks", FALSE)
{
	SECT_SaveSectorLinks	*pSave;
	CPA_SuperObject			*pSector;
	SECT_ElementBase		*pSectElem;
	SECT_ListBase			*pCurrentList;
	POSITION				pos;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_eCurrentEditMode = m_pSectorInterface->GetEditMode();
	m_pModel = pModel;
	m_eListToUpdate = eList;
	m_oListSectors.RemoveAll();
	// fill list with all sectors
	pCurrentList = ((Sector_Object *) pModel->GetObject())->GetCurrentList(eList);
	for (pSectElem = pCurrentList->GetHeadElementBase(pos); pSectElem;
		 pSectElem = pCurrentList->GetNextElementBase(pos))
	{
		// get corresponding sector
		pSector = pSectElem->GetSector();
		// build new save element and add it to the list
		if (pSector)
		{
			pSave = new SECT_SaveSectorLinks(pSector, m_pModel, m_eListToUpdate);
			m_oListSectors.AddTail(pSave);
		}
	}
}


SECT_ModifSymetricLinks::~SECT_ModifSymetricLinks (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifSymetricLinks::Do (void)
{
	SECT_SaveSectorLinks	*pElem;
	SECT_ElementBase		*pSectElem;
	Sector_Object			*pSectObj;
	POSITION				pos;
	
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update sectors
	for (pElem = m_oListSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListSectors.GetNextElement(pos))
	{
		pSectObj = pElem->m_pSector;
		// sound event => non standard
		if (m_eListToUpdate == E_SoundEvent)
		{
			pSectElem = pSectObj->GetSoundEventList()->GetElementWithSector(m_pModel);
			if (pSectElem)
				pSectObj->fn_bRemoveSectorInList(pSectElem, E_SoundEvent);
		}
		// add link
		if (pElem->m_pNewElement)
			pSectObj->fn_bAddSectorInList(pElem->m_pNewElement, m_eListToUpdate);
		// update param
		pSectElem = pSectObj->GetCurrentList(m_eListToUpdate)->GetElementWithSector(m_pModel);
		switch (m_eListToUpdate)
		{
			case E_Graphic:
				((SECT_GraphicElement *) pSectElem)->SetGraphicLevel(pElem->m_iNewParam);
				((SECT_GraphicElement *) pSectElem)->SetGraphicMode(pElem->m_iNewMode);
				break;
			case E_Sound:
				((SECT_SoundElement *) pSectElem)->SetSoundLevel(pElem->m_iNewParam);
				break;
		}
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifSymetricLinks::Undo (void)
{
	SECT_SaveSectorLinks	*pElem;
	SECT_ElementBase		*pSectElem;
	Sector_Object			*pSectObj;
	POSITION				pos;
	
	// update editor mode
	fn_vReinitEditorState();
	// update sectors
	for (pElem = m_oListSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListSectors.GetNextElement(pos))
	{
		pSectObj = pElem->m_pSector;
		if (pElem->m_pNewElement)
			pSectObj->fn_bRemoveSectorInList(pElem->m_pNewElement, m_eListToUpdate);
		// update param
		pSectElem = pSectObj->GetCurrentList(m_eListToUpdate)->GetElementWithSector(m_pModel);
		switch (m_eListToUpdate)
		{
			case E_Graphic:
				if (pSectElem)
				{
					((SECT_GraphicElement *) pSectElem)->SetGraphicLevel(pElem->m_iOldParam);
					((SECT_GraphicElement *) pSectElem)->SetGraphicMode(pElem->m_iOldMode);
				}
				break;
			case E_Sound:
				if (pSectElem)
					((SECT_SoundElement *) pSectElem)->SetSoundLevel(pElem->m_iOldParam);
				break;
			case E_SoundEvent:
				if (pElem->m_pOldElement)
					pSectObj->fn_bAddSectorInList(pElem->m_pOldElement, m_eListToUpdate);
				break;
		}
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}

/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifSymetricLinks::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(m_eCurrentEditMode, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pModel)
		m_pSectorInterface->fn_vReinitEditor(m_pModel);
	// if necessary, reinit list
	if (m_eCurrentEditMode == E_em_EditList)
	{
		m_pSectorInterface->SetListActivity(E_NoActiveList, FALSE, FALSE);
		m_pSectorInterface->SetListActivity(m_eListToUpdate, TRUE, FALSE);
	}
	// else cancel selection
	else
		m_pSectorInterface->fn_vSelectNewSector(m_pModel, FALSE, FALSE);
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifSymetricLinks::fn_vUpdateEditorState (void)
{
	// update drawing
	m_pSectorInterface->GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
	// update status bar
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Symetric Links Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Symetric Links Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}


//#################################################################################
// class SECT_ModifSymetricSelect
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifSymetricSelect::SECT_ModifSymetricSelect  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
													 CPA_SuperObject *pEditedSector, CPA_SuperObject *pSelectedSector)
		: CPA_Modif(TYPE_SYMETRICSELECT, "SymetricSelect", FALSE)
{
	SECT_ElementBase		*pEditElem;
	SECT_ElementBase		*pSelectElem;
	Sector_Object			*pEditSector;
	Sector_Object			*pSelectSector;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pEditedSector = pEditedSector;
	m_pSelectedSector = pSelectedSector;
	m_pNewSoundElement = NULL;
	m_pNewGraphicElement = NULL;
	m_pNewActivityElement = NULL;
	m_pNewCollisionElement = NULL;
	m_pNewSndEvtElement = NULL;
	m_pOldSndEvtElement = NULL;
	m_iNewGraphic = m_iOldGraphic = -1;
	m_iNewGMode = m_iOldGMode = -1;
	m_iNewSound = m_iOldSound = -1;

	// get parameters
	pEditSector = (Sector_Object *) m_pEditedSector->GetObject();
	pSelectSector = (Sector_Object *) pSelectedSector->GetObject();
	// graphic
	pEditElem = pEditSector->GetGraphicList()->GetElementWithSector(m_pSelectedSector);
	if (pEditElem)
	{
		// get value
		m_iNewGraphic = ((SECT_GraphicElement *) pEditElem)->GetGraphicLevel();
		m_iNewGMode = ((SECT_GraphicElement *) pEditElem)->GetGraphicMode();
		pSelectElem = pSelectSector->GetGraphicList()->GetElementWithSector(m_pEditedSector);
		if (!pSelectElem)
		{
			m_pNewGraphicElement = (SECT_GraphicElement *) pSelectSector->GetNewElement(E_Graphic, m_pEditedSector);
			m_pNewGraphicElement->SetGraphicLevel(m_iNewGraphic);
			m_pNewGraphicElement->SetGraphicMode(m_iNewGMode);
		}
		else
		{
			m_iOldGraphic = ((SECT_GraphicElement *) pSelectElem)->GetGraphicLevel();
			m_iOldGMode = ((SECT_GraphicElement *) pSelectElem)->GetGraphicMode();
		}
	}
	// sound
	pEditElem = pEditSector->GetSoundList()->GetElementWithSector(m_pSelectedSector);
	if (pEditElem)
	{
		// get value
		m_iNewSound = ((SECT_SoundElement *) pEditElem)->GetSoundLevel();
		pSelectElem = pSelectSector->GetSoundList()->GetElementWithSector(m_pEditedSector);
		if (!pSelectElem)
		{
			m_pNewSoundElement = (SECT_SoundElement *) pSelectSector->GetNewElement(E_Sound, m_pEditedSector);
			m_pNewSoundElement->SetSoundLevel(m_iNewSound);
		}
		else
			m_iOldSound = ((SECT_SoundElement *) pSelectElem)->GetSoundLevel();
	}
	// collision
	pEditElem = pEditSector->GetCollisionList()->GetElementWithSector(m_pSelectedSector);
	if (pEditElem)
	{
		pSelectElem = pSelectSector->GetCollisionList()->GetElementWithSector(m_pEditedSector);
		if (!pSelectElem)
			m_pNewCollisionElement = (SECT_CollisionElement *) pSelectSector->GetNewElement(E_Collision, m_pEditedSector);
	}
	// activity
	pEditElem = pEditSector->GetActivityList()->GetElementWithSector(m_pSelectedSector);
	if (pEditElem)
	{
		pSelectElem = pSelectSector->GetActivityList()->GetElementWithSector(m_pEditedSector);
		if (!pSelectElem)
			m_pNewActivityElement = (SECT_ActivityElement *) pSelectSector->GetNewElement(E_Activity, m_pEditedSector);
	}
	// sound event
	pEditElem = pEditSector->GetSoundEventList()->GetElementWithSector(m_pSelectedSector);
	if (pEditElem)
	{
		// create copy of new one
		m_pNewSndEvtElement = (SECT_SoundEventElement *) pSelectSector->GetNewElement(E_SoundEvent, m_pEditedSector);
		m_pNewSndEvtElement->fn_vCopyMissingSoundEvents((SECT_SoundEventElement *)pEditElem);
		// create copy of old one
		pSelectElem = pSelectSector->GetSoundEventList()->GetElementWithSector(m_pEditedSector);
		if (pSelectElem)
		{
			m_pOldSndEvtElement = (SECT_SoundEventElement *)pSelectSector->GetNewElement(E_SoundEvent, m_pEditedSector);
			m_pOldSndEvtElement->fn_vCopyMissingSoundEvents((SECT_SoundEventElement *)pSelectElem);
		}
	}
}


SECT_ModifSymetricSelect::~SECT_ModifSymetricSelect (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifSymetricSelect::Do (void)
{
	SECT_ElementBase		*pElem;
	Sector_Object			*pSector;
	
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update parameters
	pSector = (Sector_Object *) m_pSelectedSector->GetObject();
	// graphic
	if (m_pNewGraphicElement)
		pSector->fn_bAddSectorInList(m_pNewGraphicElement, E_Graphic);
	else if (m_iNewGraphic != -1)
	{
		pElem = pSector->GetGraphicList()->GetElementWithSector(m_pEditedSector);
		((SECT_GraphicElement *) pElem)->SetGraphicLevel(m_iNewGraphic);
		((SECT_GraphicElement *) pElem)->SetGraphicMode(m_iNewGMode);
	}
	// collision
	if (m_pNewCollisionElement)
		pSector->fn_bAddSectorInList(m_pNewCollisionElement, E_Collision);
	// activity
	if (m_pNewActivityElement)
		pSector->fn_bAddSectorInList(m_pNewActivityElement, E_Activity);
	// sound
	if (m_pNewSoundElement)
		pSector->fn_bAddSectorInList(m_pNewSoundElement, E_Sound);
	else if (m_iNewSound != -1)
	{
		pElem = pSector->GetSoundList()->GetElementWithSector(m_pEditedSector);
		((SECT_SoundElement *) pElem)->SetSoundLevel(m_iNewSound);
	}
	// sound event
	if (m_pNewSndEvtElement)
	{
		pElem = pSector->GetSoundEventList()->GetElementWithSector(m_pEditedSector);
		if (pElem)
			pSector->fn_bRemoveSectorInList(pElem, E_SoundEvent);
		pSector->fn_bAddSectorInList(m_pNewSndEvtElement, E_SoundEvent);
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifSymetricSelect::Undo (void)
{
	SECT_ElementBase		*pElem;
	Sector_Object			*pSector;
	
	// update editor mode
	fn_vReinitEditorState();
	// update parameters
	pSector = (Sector_Object *) m_pSelectedSector->GetObject();
	// graphic
	if (m_pNewGraphicElement)
		pSector->fn_bRemoveSectorInList(m_pNewGraphicElement, E_Graphic);
	else if (m_iOldGraphic != -1)
	{
		pElem = pSector->GetGraphicList()->GetElementWithSector(m_pEditedSector);
		((SECT_GraphicElement *) pElem)->SetGraphicLevel(m_iOldGraphic);
		((SECT_GraphicElement *) pElem)->SetGraphicMode(m_iOldGMode);
	}
	// collision
	if (m_pNewCollisionElement)
		pSector->fn_bRemoveSectorInList(m_pNewCollisionElement, E_Collision);
	// activity
	if (m_pNewActivityElement)
		pSector->fn_bRemoveSectorInList(m_pNewActivityElement, E_Activity);
	// sound
	if (m_pNewSoundElement)
		pSector->fn_bRemoveSectorInList(m_pNewSoundElement, E_Sound);
	else if (m_iOldSound != -1)
	{
		pElem = pSector->GetSoundList()->GetElementWithSector(m_pEditedSector);
		((SECT_SoundElement *) pElem)->SetSoundLevel(m_iOldSound);
	}
	// sound event
	if (m_pNewSndEvtElement)
	{
		pSector->fn_bRemoveSectorInList(m_pNewSndEvtElement, E_SoundEvent);
		if (m_pOldSndEvtElement)
			pSector->fn_bAddSectorInList(m_pOldSndEvtElement, E_SoundEvent);
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}

/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifSymetricSelect::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditSector, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
	// if necessary, reinit selection
	m_pSectorInterface->fn_vSelectNewSector(m_pSelectedSector, FALSE, FALSE);
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifSymetricSelect::fn_vUpdateEditorState (void)
{
	// update drawing
	m_pSectorInterface->GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
	// update status bar
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Symetric Links Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Symetric Links Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}


//#################################################################################
// class SECT_ModifVirtualSector 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifVirtualSector::SECT_ModifVirtualSector (Sector_Interface *pInterface, tdeSectModifType eModifType,
												   CPA_SuperObject *pEditedSector, BOOL bNewStatus)
		: CPA_Modif(TYPE_VIRTUALSTATUS, "VirtualStatus", FALSE)
{
	Sector_Object	*pSector;
	// init parent editor
	m_pSectorInterface = pInterface;
	m_pEditedSector = pEditedSector;
	m_bNewStatus = bNewStatus;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	pSector = (Sector_Object *) m_pEditedSector->GetObject();
	m_pBorder = (!m_bNewStatus) ? pSector->GetBorder() : NULL;
	// init modif type
	m_eModifType = eModifType;
}


SECT_ModifVirtualSector::~SECT_ModifVirtualSector (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifVirtualSector::Do (void)
{
	Sector_Object	*pSector;
	
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update parameters
	pSector = (Sector_Object *) m_pEditedSector->GetObject();
	// if necessary, update borders
	if (m_pSectorInterface->fn_bDisplayBorders() && m_bNewStatus)
		m_pSectorInterface->fn_vDisplayBorder(pSector, !m_bNewStatus, FALSE);
	// update state
	pSector->fn_vSetVirtual(m_bNewStatus, m_pBorder);
	if (m_bFirstTime && !m_bNewStatus)
		m_pBorder = pSector->GetBorder();
	// if necessary, update borders
	if (m_pSectorInterface->fn_bDisplayBorders() && !m_bNewStatus)
		m_pSectorInterface->fn_vDisplayBorder(pSector, !m_bNewStatus, FALSE);
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifVirtualSector::Undo (void)
{
	Sector_Object			*pSector;
	
	// update editor mode
	fn_vReinitEditorState();
	// update parameters
	pSector = (Sector_Object *) m_pEditedSector->GetObject();
	// if necessary, update borders
	if (m_pSectorInterface->fn_bDisplayBorders() && !m_bNewStatus)
		m_pSectorInterface->fn_vDisplayBorder(pSector, m_bNewStatus, FALSE);
	pSector->fn_vSetVirtual(!m_bNewStatus, m_pBorder);
	// if necessary, update borders
	if (m_pSectorInterface->fn_bDisplayBorders() && m_bNewStatus)
		m_pSectorInterface->fn_vDisplayBorder(pSector, m_bNewStatus, FALSE);
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}

/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifVirtualSector::fn_vReinitEditorState (void)
{
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifVirtualSector::fn_vUpdateEditorState (void)
{
	// update edited sector
	m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Virtual Status Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Virtual Status Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}



//#################################################################################
// class SECT_SaveInitEnv 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_SaveInitEnv::SECT_SaveInitEnv (Sector_Object *pSector, SECT_Environment *pInitEnv)
{
	SECT_Environment	*pEnv;
	SECT_EnvElem		*pEnvElem;
	long				lNumEnv, iInd;

	// init sector
	m_pSector = pSector;
	m_lNbEnv = 0;
	// init envlist
	for (iInd = 0; iInd < C_lMaxEnvironments; iInd++)
		m_aNumEnv[iInd] = -1;

	// get environment to replace
	for (lNumEnv = 0; lNumEnv < pSector->GetNbEnvironments(); lNumEnv++)
	{
		// get environment
		pEnvElem = pSector->GetEnvironment(lNumEnv);
		pEnv = pEnvElem->GetEnvironment();
		// add it to the list
		if (pEnv == pInitEnv)
			m_aNumEnv[m_lNbEnv++] = lNumEnv;
	}
}

SECT_SaveInitEnv::~SECT_SaveInitEnv (void)
{

}
*/

//#################################################################################
// class SECT_ModifReplaceEnvironment 
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
/*
SECT_ModifReplaceEnvironment::SECT_ModifReplaceEnvironment  (Sector_Interface *pInterface, tdeSectModifType eModifType, 
															 SECT_Environment *pInitEnv, SECT_Environment *pNewEnv,
															 CPA_List<CPA_SuperObject> *pListSectors)
		: CPA_Modif(TYPE_REPLACE, "Replace", FALSE)
{
	CPA_BaseObjectList	*pListObject;
	CPA_SuperObject		*pSector;
	CPA_BaseObject		*pElem;
	Sector_Object		*pSectObj;
	Position			pos;
	POSITION			Pos;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_pEditedSector = pInterface->GetEditedSector();
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_pInitEnv = pInitEnv;
	m_pNewEnv = pNewEnv;
	m_oListSectors.RemoveAll();
	// All sectors
	if (!pListSectors)
	{
		pListObject = m_pSectorInterface->GetBaseObjectList(C_szSectorTypeName);
		// for all sectors in ReachableObjectList
		for (pElem = pListObject->GetHeadElement(pos); pElem;
			 pElem = pListObject->GetNextElement(pos))
		{
			// apply same environment
			pSectObj = (Sector_Object *) pElem;
			m_oListSectors.AddTail(new SECT_SaveInitEnv(pSectObj, pInitEnv));
		}
	}
	// Selected sectors
	else
	{
		// for all sectors in select list
		for (pSector = pListSectors->GetHeadElement(Pos); pSector;
			 pSector = pListSectors->GetNextElement(Pos))
		{
			// apply same environment
			pSectObj = (Sector_Object *) pSector->GetObject();
			m_oListSectors.AddTail(new SECT_SaveInitEnv(pSectObj, pInitEnv));
		}
	}
}


SECT_ModifReplaceEnvironment::~SECT_ModifReplaceEnvironment (void) 
{ 
}
*/


/*===========================================================================
		Do
=========================================================================*/
/*
BOOL SECT_ModifReplaceEnvironment::Do (void)
{
	SECT_SaveInitEnv	*pElem;
	Sector_Object		*pSectObj;
	SECT_EnvElem		*pEnvElem;
	POSITION			pos;
	long				iInd;
	
	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// update sectors
	for (pElem = m_oListSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListSectors.GetNextElement(pos))
	{
		pSectObj = pElem->m_pSector;
		for (iInd = 0; iInd < pElem->m_lNbEnv; iInd++)
		{
			pEnvElem = pSectObj->GetEnvironment(pElem->m_aNumEnv[iInd]);
			pEnvElem->SetEnvironment(m_pNewEnv);
		}
	}
	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}
*/

/*===========================================================================
		Undo
=========================================================================*/
/*
BOOL SECT_ModifReplaceEnvironment::Undo (void)
{
	SECT_SaveInitEnv	*pElem;
	Sector_Object		*pSectObj;
	SECT_EnvElem		*pEnvElem;
	POSITION			pos;
	long				iInd;
	
	// update editor mode
	fn_vReinitEditorState();
	// update sectors
	for (pElem = m_oListSectors.GetHeadElement(pos); pElem;
		 pElem = m_oListSectors.GetNextElement(pos))
	{
		pSectObj = pElem->m_pSector;
		for (iInd = 0; iInd < pElem->m_lNbEnv; iInd++)
		{
			pEnvElem = pSectObj->GetEnvironment(pElem->m_aNumEnv[iInd]);
			pEnvElem->SetEnvironment(m_pInitEnv);
		}
	}
	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}
*/

/*===========================================================================
		ReinitEditor
=========================================================================*/
/*
void SECT_ModifReplaceEnvironment::fn_vReinitEditorState (void)
{
	// set editor mode
	m_pSectorInterface->SetEditMode(E_em_EditEnv, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
}
*/

/*===========================================================================
		UpdateEditor
=========================================================================*/
/*
void SECT_ModifReplaceEnvironment::fn_vUpdateEditorState (void)
{
	// update env list
	m_pSectorInterface->GetDialogEnvList()->fn_vInitEnvList(m_pEditedSector);
	
	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Replace Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Replace Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}
*/



//#################################################################################
// class SECT_ModifCopyList
//#################################################################################

/*===========================================================================
		Constructor
=========================================================================*/
SECT_ModifCopyList::SECT_ModifCopyList(Sector_Interface *pInterface, tdeSectModifType eModifType, 
									   CPA_List<CPA_SuperObject> *pCopyOfSectorList, 
									   tdeTypeList eListToUpdate)
		: CPA_Modif(TYPE_COPYLIST, "CopyList", FALSE)
{
	CPA_SuperObject			*pSector;
	Sector_Object			*pSectObj;
	Sector_Object			*pSymSectObj;
	tdeTypeList				eList;
	POSITION				pos;
	int						iList;

	// init parent editor
	m_pSectorInterface = pInterface;
	m_bFirstTime = TRUE;
	m_bDone = FALSE;
	// init modif type
	m_eModifType = eModifType;
	// Init parameters
	m_eCurrentEditMode = m_pSectorInterface->GetEditMode();
	m_pEditedSector = m_pSectorInterface->GetEditedSector();
	m_bSymetric = m_pSectorInterface->fn_bSymetricMode();
	// get corresponding parameters
	pSectObj = (Sector_Object *) m_pEditedSector->GetObject();

	// init arrays
	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		m_aListOfElements[iList].RemoveAll();
		m_aListOfSymElems[iList].RemoveAll();
	}
	// init element for single modif
	if (eListToUpdate != E_NoActiveList)
	{
		for (pSector = pCopyOfSectorList->GetHeadElement(pos); pSector;
			 pSector = pCopyOfSectorList->GetNextElement(pos))
		{
			if (pSector != m_pEditedSector)
			{
				if (!pSectObj->GetCurrentList(eListToUpdate)->GetElementWithSector(pSector))
					m_aListOfElements[eListToUpdate].AddTail(pSectObj->GetNewElement(eListToUpdate, pSector));
				if (m_bSymetric)
				{
					pSymSectObj = (Sector_Object *) pSector->GetObject();
					if (!pSymSectObj->GetCurrentList(eListToUpdate)->GetElementWithSector(m_pEditedSector))
						m_aListOfSymElems[eListToUpdate].AddTail(pSymSectObj->GetNewElement(eListToUpdate, m_pEditedSector));
				}
			}
		}
	}
	// init elements for multiple modif
	else
	{
		for (iList = 0; iList < C_NumberOfLists; iList++)
		{
			eList = (tdeTypeList) iList;
			if (m_pSectorInterface->GetListActivity(eList))
			{
				for (pSector = pCopyOfSectorList->GetHeadElement(pos); pSector;
					 pSector = pCopyOfSectorList->GetNextElement(pos))
				{
					if (pSector != m_pEditedSector)
					{
						if (!pSectObj->GetCurrentList(eList)->GetElementWithSector(pSector))
							m_aListOfElements[eList].AddTail(pSectObj->GetNewElement(eList, pSector));
						if (m_bSymetric)
						{
							pSymSectObj = (Sector_Object *) pSector->GetObject();
							if (!pSymSectObj->GetCurrentList(eList)->GetElementWithSector(m_pEditedSector))
								m_aListOfSymElems[eList].AddTail(pSymSectObj->GetNewElement(eList, m_pEditedSector));
						}
					}
				}
			}
		}
	}
}


SECT_ModifCopyList::~SECT_ModifCopyList (void) 
{ 
}


/*===========================================================================
		Do
=========================================================================*/
BOOL SECT_ModifCopyList::Do (void)
{
	SECT_ElementBase		*pElem;
	SECT_ListBase			*pCurrentList;
	Sector_Object			*pSectObject;
	tdeTypeList				eList;
	POSITION				pos;
	int						iList;

	// if redo, update editor mode
	if (!m_bFirstTime)
		fn_vReinitEditorState();
	// get edited sector
	pSectObject = (Sector_Object *) m_pEditedSector->GetObject();

	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		eList = (tdeTypeList) iList;
		if (m_aListOfElements[eList].GetCount() > 0)
		{
			// get current list
			pCurrentList = pSectObject->GetCurrentList(eList);
			// add elements in list
			for (pElem = m_aListOfElements[eList].GetHeadElement(pos); pElem;
				 pElem = m_aListOfElements[eList].GetNextElement(pos))
				pSectObject->fn_bAddSectorInList(pElem, eList);
			// add symetric elements in list
			if (m_bSymetric)
			{
				for (pElem = m_aListOfSymElems[eList].GetHeadElement(pos); pElem;
					 pElem = m_aListOfSymElems[eList].GetNextElement(pos))
					pElem->GetOwnerSector()->fn_bAddSectorInList(pElem, eList);
			}
		}
	}

	// update editor
	m_bDone = TRUE;
	fn_vUpdateEditorState();
	// update flag
	m_bFirstTime = FALSE;
	return TRUE;
}

/*===========================================================================
		Undo
=========================================================================*/
BOOL SECT_ModifCopyList::Undo (void)
{
	SECT_ElementBase		*pElem;
	SECT_ListBase			*pCurrentList;
	Sector_Object			*pSectObject;
	tdeTypeList				eList;
	POSITION				pos;
	int						iList;

	// update editor mode
	fn_vReinitEditorState();
	// get edited sector
	pSectObject = (Sector_Object *) m_pEditedSector->GetObject();

	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		eList = (tdeTypeList) iList;
		if (m_aListOfElements[eList].GetCount() > 0)
		{
			// get current list
			pCurrentList = pSectObject->GetCurrentList(eList);
			// remove elements in list
			for (pElem = m_aListOfElements[eList].GetHeadElement(pos); pElem;
				 pElem = m_aListOfElements[eList].GetNextElement(pos))
				pSectObject->fn_bRemoveSectorInList(pElem, eList);
			// remove symetric elements in list
			if (m_bSymetric)
			{
				for (pElem = m_aListOfSymElems[eList].GetHeadElement(pos); pElem;
					 pElem = m_aListOfSymElems[eList].GetNextElement(pos))
					pElem->GetOwnerSector()->fn_bRemoveSectorInList(pElem, eList);
			}
		}
	}

	// update editor
	m_bDone = FALSE;
	fn_vUpdateEditorState();
	return TRUE;
}


/*===========================================================================
		ReinitEditor
=========================================================================*/
void SECT_ModifCopyList::fn_vReinitEditorState (void)
{
	int						iList;

	// set editor mode
	m_pSectorInterface->SetEditMode(m_eCurrentEditMode, FALSE);
	// update edited sector
	if (m_pSectorInterface->GetEditedSector() != m_pEditedSector)
		m_pSectorInterface->fn_vReinitEditor(m_pEditedSector);
	// list mode => update current list
	if (m_eCurrentEditMode == E_em_EditList)
	{
		m_pSectorInterface->SetListActivity(E_NoActiveList, FALSE, FALSE);
		for (iList = 0; iList < C_NumberOfLists; iList++)
		{		
			if (m_aListOfElements[(tdeTypeList) iList].GetCount() > 0)
				m_pSectorInterface->SetListActivity((tdeTypeList) iList, TRUE, FALSE);
		}
	}
	// sector mode => update selected sector
	else if (m_eCurrentEditMode == E_em_EditSector)
		m_pSectorInterface->fn_vSelectNewSector(m_pEditedSector, FALSE, FALSE);
}

/*===========================================================================
		UpdateEditor
=========================================================================*/
void SECT_ModifCopyList::fn_vUpdateEditorState (void)
{
	SECT_DialogBase *pSingleList;
	SECT_ListBase	*pCurrentList;
	tdeTypeList		eList;
	int				iList;
	
	// update drawing
	if (m_eCurrentEditMode == E_em_EditList)
		m_pSectorInterface->fn_vShowAllSectors();
	else if (m_eCurrentEditMode == E_em_EditSector)
		m_pSectorInterface->GetDialogSel()->fn_vReinitDialog(m_pEditedSector, m_pEditedSector);

	// update dialogs
	for (iList = 0; iList < C_NumberOfLists; iList++)
	{
		eList = (tdeTypeList) iList;
		// get parameters
		pSingleList = m_pSectorInterface->GetSingleList(eList);
		pCurrentList = ((Sector_Object *) m_pEditedSector->GetObject())->GetCurrentList(eList);
		pSingleList->fn_vInitSectorList(pCurrentList);
	}
	
	m_pSectorInterface->GetDialogList()->fn_vUpdateSelection(E_lrm_ReinitList);

	if (m_bDone)
		M_GetMainWnd()->UpdateStatus("Modif Sector Links Done", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	else
		M_GetMainWnd()->UpdateStatus("Modif Sector Links Undone", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}


