//ROMTEAM Networks (Gabriela Dumitrascu 25/02/98)

///////////////////////////////////////////////////////////////////////////////////////////////////
// Description : NtwDia.cpp
//   
// Definition of the waypoint editors ,implementation file
///////////////////////////////////////////////////////////////////////////////////////////////////
// inherit from  :	CFormView
///////////////////////////////////////////////////////////////////////////////////////////////////
// Creation date: 1998-02-25                        Author: CPA2 Gabriela Dumitrascu
///////////////////////////////////////////////////////////////////////////////////////////////////
// Modification date:			                      Author: 
///////////////////////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "acp_base.h"
#include "resource.h"
#include "incitf.h"
#include "incai.h"
#include "WPObj.hpp"
//ANNECY Shaitan Nettoyage (12/05/98) {
/*
#include "WayObj.hpp"
#include "LinkObj.hpp"
#include "WayDia.hpp"
*/
//ENDANNECY Shaitan Nettoyage }
#include "NtwObj.hpp"
#include "WPDia.hpp"
#include "ntwdia.hpp"
// Shaitan Correction {
#include "ntwmod.hpp"
//End Shaitan Correction }
#include "Inter.hpp"
#include "IsoWPDia.hpp"
#include "x:\cpa\main\inc\_EditId.h"
#include "tut.h"

/////////////////////////////////////////////////////////////////////////////
// NtwDia


IMPLEMENT_DYNCREATE(NtwDia, CFormView)

NtwDia::NtwDia(CWnd* pParent)
	: CFormView(NtwDia::IDD)
{
	//{{AFX_DATA_INIT(NtwDia)
// Shaitan NewParam {
//	m_lWeight = 0;
//End Shaitan NewParam }
	m_EditWP = _T("");
	//}}AFX_DATA_INIT
// Shaitan Correction {
	m_iSelectedGraph = -1;
	m_iSelectedNode = -1;
	m_iSelectedConnection = -1;
	m_bInitialised = FALSE;
//End Shaitan Correction }
}

void NtwDia::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);

	DDX_Control(pDX, IDC_CONNECT_LIST, m_ConnectList);
	DDX_Control(pDX, IDC_NTW_WP, m_WPList);
	DDX_Control(pDX, IDC_GRAPH_NAME, m_GraphNameList);
	DDX_Control(pDX, IDC_CONNECT_SYMETRIC, m_Symetric);

	//{{AFX_DATA_MAP(NtwDia)
// Shaitan NewParam {
//	DDX_Text(pDX, IDC_WEIGHT, m_lWeight);
//End Shaitan NewParam }
	//}}AFX_DATA_MAP

// Shaitan Correction {
	if (pDX->m_bSaveAndValidate)
	{
		DDX_CBString(pDX, IDC_GRAPH_NAME, m_EditGraph);
		DDV_MaxChars(pDX, m_EditGraph, 30);
		DDX_CBString(pDX, IDC_NTW_WP, m_EditWP);
		DDV_MaxChars(pDX, m_EditWP, 30);
		// Save from dlg controls.
		int iGraph = m_GraphNameList.GetCurSel();
		if (iGraph == LB_ERR)
			return;
//		Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
/*
		if (m_hSelArc)
		{
			WPARC_fn_lSetValuation(m_hSelArc, m_lWeight);
			pGraph->fn_vNotifySave();
			for (int i = 0, iMask = 1, iCapacity = 0; i < 32; i++, iMask <<= 1)
			{
				if (((CButton*)GetDlgItem(IDC_CAPACITY1 + i))->GetCheck() == 1)
					iCapacity |= iMask;
			}
			WPARC_fn_lSetCapacity(m_hSelArc, iCapacity);
			pGraph->fn_vNotifySave();

			Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
		}
*/
	}
	else
	{
// Shaitan NewParam {
//		int iCapacity = 0;
//End Shaitan NewParam }
		
		// Load in dlg controls.
		if (m_GraphNameList.GetCurSel() == LB_ERR)
		{
			m_EditGraph = "";
			DDX_CBString(pDX, IDC_GRAPH_NAME, m_EditGraph);
			DDV_MaxChars(pDX, m_EditGraph, 30);
		}
		if (m_WPList.GetCurSel() == LB_ERR)
		{
			m_EditWP = "";
			DDX_CBString(pDX, IDC_NTW_WP, m_EditWP);
			DDV_MaxChars(pDX, m_EditWP, 30);
		}
// Shaitan NewParam {
/*
//		m_lWeight = m_hSelArc ? WPARC_fn_lGetValuation(m_hSelArc) : 0;
		int iGraph = m_GraphNameList.GetCurSel();
		int iNode = m_WPList.GetCurSel();
		int iConnect = m_ConnectList.GetCurSel();
		if ((iGraph == LB_ERR) || (iNode == LB_ERR) || (iConnect == LB_ERR))
			m_lWeight = 0;
		else
		{
			Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
			WayPoint *pSrcNode = (WayPoint *) m_WPList.GetItemData(iNode);
			WayPoint *pDstNode = (WayPoint *) m_ConnectList.GetItemData(iConnect);
			m_lWeight = pGraph->GetConnectionWeight(pSrcNode, pDstNode);
			iCapacity = pGraph->GetConnectionCapacity(pSrcNode, pDstNode);
		}

		DDX_Text(pDX, IDC_WEIGHT, m_lWeight);
		DDX_Text(pDX, IDC_NTW_TYPE, m_lType);
//		int iCapacity = m_hSelArc ? WPARC_fn_lGetCapacity(m_hSelArc) : 0;
		for (int i = 0, iMask = 1; i < 32; i++, iMask <<= 1)
			((CButton*)GetDlgItem(IDC_CAPACITY1 + i))->SetCheck((iCapacity & iMask) ? 1 : 0);
*/
//End Shaitan NewParam }
	}
}


BEGIN_MESSAGE_MAP(NtwDia, CFormView)
	//{{AFX_MSG_MAP(NtwDia)
	ON_WM_DESTROY()
	ON_CBN_SELCHANGE(IDC_GRAPH_NAME, OnSelchangeGraphName)
	ON_CBN_SELCHANGE(IDC_NTW_WP, OnSelchangeNtwWp)
// Shaitan Correction {
	ON_CBN_DBLCLK(IDC_NTW_WP, OnDblClkNtwWp)
	ON_BN_CLICKED(IDC_GRAPH_RENAME, OnChangeGraphName)
//End Shaitan Correction }
	ON_LBN_SELCHANGE(IDC_CONNECT_LIST, OnSelchangeConnectList)
	ON_BN_CLICKED(IDC_GRAPH_INSERT, OnGraphInsert)
	ON_BN_CLICKED(IDC_GRAPH_DELETE, OnGraphDelete)
	ON_BN_CLICKED(IDC_CONNECT_DELETE, OnConnectDelete)
	ON_BN_CLICKED(IDC_CONNECT_INSERT, OnConnectInsert)
	ON_BN_CLICKED(IDC_WP_INSERT, OnWpInsert)
	ON_BN_CLICKED(IDC_WP_DELETE, OnWpDelete)
// Shaitan NewParam {
	ON_BN_CLICKED(IDC_WP_EDIT, OnEditNode)
	ON_BN_CLICKED(IDC_CONNECT_EDIT, OnEditConnect)
//	ON_BN_CLICKED(IDC_DEFAULT_WEIGHT, OnDefaultWeight)
	ON_BN_CLICKED(IDC_CONNECT_ALLDEFAULT, OnDefaultAllWeights)
	ON_BN_CLICKED(IDC_CONNECT_EDITALL, OnEditAllConnects)
	ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
//	ON_EN_KILLFOCUS(IDC_WEIGHT, OnChangeWeight)
/*
	ON_BN_CLICKED(IDC_CAPACITY1, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY2, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY3, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY4, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY5, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY6, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY7, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY8, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY9, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY10, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY11, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY12, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY13, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY14, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY15, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY16, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY17, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY18, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY19, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY20, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY21, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY22, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY23, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY24, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY25, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY26, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY27, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY28, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY29, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY30, OnCapacity)	
	ON_BN_CLICKED(IDC_CAPACITY31, OnCapacity)
	ON_BN_CLICKED(IDC_CAPACITY32, OnCapacity)
*/
//End Shaitan NewParam }
// Shaitan Correction  {
	ON_WM_SIZE()
//End Shaitan Correction }
	ON_BN_CLICKED(IDC_CONNECT_SYMETRIC, OnSymetric)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// NtwDia diagnostics


/////////////////////////////////////////////////////////////////////////////
// NtwDia message handlers

void NtwDia::fn_vInitDialog ()
{
	fn_vRefreshDialog();
}

void NtwDia::fn_vRefreshDialog()
{
// Shaitan NewParam {
   GetDlgItem (IDC_GRAPH_NAME)->EnableWindow (TRUE);
	GetDlgItem (IDC_GRAPH_INSERT)->EnableWindow (TRUE);
	GetDlgItem (IDC_GRAPH_DELETE)->EnableWindow (FALSE);
	GetDlgItem (IDC_GRAPH_RENAME)->EnableWindow (FALSE);

	GetDlgItem (IDC_NTW_WP)->EnableWindow (TRUE);		
	GetDlgItem (IDC_WP_INSERT)->EnableWindow (FALSE);
	GetDlgItem (IDC_WP_DELETE)->EnableWindow (FALSE);
	GetDlgItem (IDC_WP_EDIT)->EnableWindow (FALSE);
	
	GetDlgItem (IDC_CONNECT_LIST)->EnableWindow (TRUE);
	GetDlgItem (IDC_CONNECT_INSERT)->EnableWindow (FALSE);
	GetDlgItem (IDC_CONNECT_DELETE)->EnableWindow (FALSE);
	GetDlgItem (IDC_CONNECT_EDIT)->EnableWindow (FALSE);

/*
	GetDlgItem (IDC_WEIGHT)->EnableWindow (TRUE);
	for (int i = 0; i < 32; i++)
		GetDlgItem (IDC_CAPACITY1 + i)->EnableWindow (TRUE);

	m_hSelArc = NULL;
*/
//End Shaitan NewParam }

// Shaitan Correction {
//	m_status = statusReady;
//End Shaitan Correction }

	UpdateData(FALSE);
// Shaitan Correction {
	m_bInitialised = TRUE;

	m_Symetric.SetCheck(Graph::GetInterface()->fn_bGetSymetricMode());

//	fn_vRefreshGraphList();
	fn_vRefreshGraphList(NULL);
//End Shaitan Correction }
}

// Shaitan Correction {
/*
void NtwDia::fn_vRefreshGraphList(int iGraph, int iNode, int iArc)
{
	POSITION lPos;
	m_GraphNameList.ResetContent();
	for (Graph* poGraph = Graph::ms_oListOfGraph.GetHeadElement(lPos); poGraph; poGraph= Graph::ms_oListOfGraph.GetNextElement(lPos))
		m_GraphNameList.AddString(poGraph->GetEngineStruct()->m_szNameOfGraph);
	m_GraphNameList.SetCurSel(iArc);
	fn_vRefreshWPList(m_GraphNameList.GetCurSel(), iNode, iArc);
}

void NtwDia::fn_vRefreshWPList(int iGraph, int iNode, int iArc)
{
	m_GraphNameList.SetCurSel(iGraph);
	m_WPList.ResetContent();
	if (iGraph != LB_ERR)
	{
		Graph *poGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
		for (int i = 0; i < poGraph->fn_iGetNumberOfNodes(); i++)
			m_WPList.AddString(Graph::GetWaypoint(poGraph->fn_hGetWayPointOfNode(i))->GetName());
		m_WPList.SetCurSel(iNode);
	}
	fn_vRefreshConnectList(m_GraphNameList.GetCurSel(), m_WPList.GetCurSel(), iArc);
}

void NtwDia::fn_vRefreshConnectList(int iGraph, int iNode, int iArc)
{
	m_GraphNameList.SetCurSel(iGraph);
	m_WPList.SetCurSel(iNode);
	m_ConnectList.ResetContent();
	if (iGraph != LB_ERR && iNode != LB_ERR)
	{
		Graph *poGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
		WP_tdhGraphNode hNode = poGraph->fn_hGetNode(iNode);
		for (int i = 0; i < poGraph->fn_iGetNumberOfArcs(hNode); i++)
			m_ConnectList.AddString(Graph::GetWaypoint(poGraph->fn_hGetArc(hNode, i)->m_hNode->m_hWayPoint)->GetName());
		m_ConnectList.SetCurSel(iArc);
	}
	OnSelchangeConnectList();
}
*/

/*
void NtwDia::fn_vMove ( MTH3D_tdstVector* pstTranslation)
{

	Graph::GetInterface()->GetInterface()->fn_vUpdatePositions();

	POSITION pos;
	for(CPA_SuperObject *poTangent = ms_oListOfArrows.GetHeadElement(pos); poTangent; poTangent = ms_oListOfArrows.GetNextElement(pos))
	{
		Connection* pConnection = (Connection*)poTangent->GetObject();
		Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(pConnection->m_iGraph);
		WP_tdhGraphNode hNode = pGraph->fn_hGetNode(pConnection->m_iNode);
		WayPoint* wpSrc = Graph::GetWaypoint(hNode->m_hWayPoint);
		WP_tdHandleOfArc hArc = pGraph->fn_hGetArc(hNode, pConnection->m_iArc);
		WayPoint* wpDst = Graph::GetWaypoint(hArc->m_hNode->m_hWayPoint);

		GEO_tdxHandleToMatrix hLocalMatrix = HIE_fn_hGetSuperObjectMatrix ( poTangent->GetStruct());

		// compute arrow direction
		MTH3D_tdstVector vertex1, vertex2;
		WP_fnv_WayPoint_ComputeLocation((WP_tdhWayPoint)wpSrc->GetEngineStruct(), &vertex1);
		WP_fnv_WayPoint_ComputeLocation((WP_tdhWayPoint)wpDst->GetEngineStruct(), &vertex2);
		MTH3D_M_vSubVector( &vertex2,&vertex2,&vertex1 );
		MTH_tdxReal dist = MTH3D_M_xNormVector(&vertex2);
		vertex2.xZ = -vertex2.xZ;

		// compute rotation matrix
		MTH3D_M_vNormalizeVector(&vertex2,&vertex2);
		MTH_tdxReal cx = MTH3D_M_xGetXofVector(&vertex2);
		MTH_tdxReal cy = MTH3D_M_xGetYofVector(&vertex2);
		MTH_tdxReal cz = MTH3D_M_xGetZofVector(&vertex2);
		MTH_tdxReal d  = (float)sqrt(cx * cx + cy * cy);

		MTH3D_tdstMatrix stRotZMatrix;
		MTH3D_M_vSetVectorElements(&stRotZMatrix.stCol_0, cy/d, -cx/d, 0);
		MTH3D_M_vSetVectorElements(&stRotZMatrix.stCol_1, cx/d,  cy/d, 0);
		MTH3D_M_vSetVectorElements(&stRotZMatrix.stCol_2,    0,     0, 1);
		MTH3D_tdstMatrix stRotXMatrix;
		MTH3D_M_vSetVectorElements(&stRotXMatrix.stCol_0, 1,  0,  0);
		MTH3D_M_vSetVectorElements(&stRotXMatrix.stCol_1, 0, cz,  d);
		MTH3D_M_vSetVectorElements(&stRotXMatrix.stCol_2, 0, -d, cz);
		MTH3D_M_vMulMatrixMatrix(&stRotXMatrix, &stRotZMatrix, &stRotXMatrix);
		MTH3D_M_vInverMatrix(&stRotZMatrix, &stRotZMatrix);
		MTH3D_M_vMulMatrixMatrix(&stRotXMatrix, &stRotXMatrix, &stRotZMatrix);

		MTH3D_tdstVector vertexZ;
		MTH3D_M_vSetVectorElements(&vertexZ, 0, 0, 1);
		MTH3D_M_vMulMatrixVector(&vertexZ, &stRotXMatrix, &vertexZ);
		if (vertex2.xX * vertexZ.xX > 0)
			MTH3D_M_vMulScalarVector(&stRotXMatrix.stCol_0, -1, &stRotXMatrix.stCol_0);
		if (vertex2.xY * vertexZ.xY > 0)
			MTH3D_M_vMulScalarVector(&stRotXMatrix.stCol_1, -1, &stRotXMatrix.stCol_1);
		if (vertex2.xZ * vertexZ.xZ > 0)
			MTH3D_M_vMulScalarVector(&stRotXMatrix.stCol_2, -1, &stRotXMatrix.stCol_2);

		POS_fn_vSetRotationMatrix(hLocalMatrix , &stRotXMatrix.stCol_0, &stRotXMatrix.stCol_1, &stRotXMatrix.stCol_2);
		POS_fn_vNormalizeMatrix(hLocalMatrix);

		// Translate arrow to waypoint
		MTH3D_tdstVector stTransVect;
		MTH3D_M_vSetVectorElements(&stTransVect, vertex2.xX * dist, vertex2.xY * dist, -vertex2.xZ * dist);
		POS_fn_vSetTranslationVector(hLocalMatrix, &stTransVect);

		// scale the arrow.
		MTH3D_tdstMatrix stScaleMatrix;
		MTH3D_M_vSetVectorElements(&stScaleMatrix.stCol_0, 0.3f,    0,         0);
		MTH3D_M_vSetVectorElements(&stScaleMatrix.stCol_1,    0, 0.3f,         0);
		MTH3D_M_vSetVectorElements(&stScaleMatrix.stCol_2,    0,    0,    dist/1.2f);
		POS_fn_vSetScaleMatrix(hLocalMatrix , &stScaleMatrix.stCol_0, &stScaleMatrix.stCol_1, &stScaleMatrix.stCol_2);

		GLI_xComputeTransformMatrix (hLocalMatrix);
//		Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	}
}
*/

/*
CPA_SuperObject* NtwDia::fn_pCreateConnection(int iGraph, int iNode, int iArc)
{
	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);
	WayPoint* wpSrc = Graph::GetWaypoint(hNode->m_hWayPoint);
	WP_tdHandleOfArc hArc = pGraph->fn_hGetArc(hNode, iArc);
	WayPoint* wpDst = Graph::GetWaypoint(hArc->m_hNode->m_hWayPoint);

	// create the connection arrow
	CPA_SuperObject* poTangent = Graph::GetInterface()->fn_pGetNewConnectionGraphicObject(iGraph, iNode, iArc);
	poTangent->SetSuperObjectOwner (wpSrc->GetSuperObject());	
	wpSrc->GetSuperObject()->AddTail (poTangent);

	GEO_tdxHandleToMatrix hLocalMatrix = HIE_fn_hGetSuperObjectMatrix ( poTangent->GetStruct());

	// compute arrow direction
	MTH3D_tdstVector vertex1, vertex2;
	WP_fnv_WayPoint_ComputeLocation((WP_tdhWayPoint)wpSrc->GetEngineStruct(), &vertex1);
	WP_fnv_WayPoint_ComputeLocation((WP_tdhWayPoint)wpDst->GetEngineStruct(), &vertex2);
	MTH3D_M_vSubVector( &vertex2,&vertex2,&vertex1 );
	MTH_tdxReal dist = MTH3D_M_xNormVector(&vertex2);
	vertex2.xZ = -vertex2.xZ;

	// compute rotation matrix
	MTH3D_M_vNormalizeVector(&vertex2,&vertex2);
	MTH_tdxReal cx = MTH3D_M_xGetXofVector(&vertex2);
	MTH_tdxReal cy = MTH3D_M_xGetYofVector(&vertex2);
	MTH_tdxReal cz = MTH3D_M_xGetZofVector(&vertex2);
	MTH_tdxReal d  = (float)sqrt(cx * cx + cy * cy);

	MTH3D_tdstMatrix stRotZMatrix;
	MTH3D_M_vSetVectorElements(&stRotZMatrix.stCol_0, cy/d, -cx/d, 0);
	MTH3D_M_vSetVectorElements(&stRotZMatrix.stCol_1, cx/d,  cy/d, 0);
	MTH3D_M_vSetVectorElements(&stRotZMatrix.stCol_2,    0,     0, 1);
	MTH3D_tdstMatrix stRotXMatrix;
	MTH3D_M_vSetVectorElements(&stRotXMatrix.stCol_0, 1,  0,  0);
	MTH3D_M_vSetVectorElements(&stRotXMatrix.stCol_1, 0, cz,  d);
	MTH3D_M_vSetVectorElements(&stRotXMatrix.stCol_2, 0, -d, cz);
	MTH3D_M_vMulMatrixMatrix(&stRotXMatrix, &stRotZMatrix, &stRotXMatrix);
	MTH3D_M_vInverMatrix(&stRotZMatrix, &stRotZMatrix);
	MTH3D_M_vMulMatrixMatrix(&stRotXMatrix, &stRotXMatrix, &stRotZMatrix);

	MTH3D_tdstVector vertexZ;
	MTH3D_M_vSetVectorElements(&vertexZ, 0, 0, 1);
	MTH3D_M_vMulMatrixVector(&vertexZ, &stRotXMatrix, &vertexZ);
	if (vertex2.xX * vertexZ.xX > 0)
		MTH3D_M_vMulScalarVector(&stRotXMatrix.stCol_0, -1, &stRotXMatrix.stCol_0);
	if (vertex2.xY * vertexZ.xY > 0)
		MTH3D_M_vMulScalarVector(&stRotXMatrix.stCol_1, -1, &stRotXMatrix.stCol_1);
	if (vertex2.xZ * vertexZ.xZ > 0)
		MTH3D_M_vMulScalarVector(&stRotXMatrix.stCol_2, -1, &stRotXMatrix.stCol_2);

	POS_fn_vSetRotationMatrix(hLocalMatrix , &stRotXMatrix.stCol_0, &stRotXMatrix.stCol_1, &stRotXMatrix.stCol_2);
	POS_fn_vNormalizeMatrix(hLocalMatrix);

		// Translate arrow to waypoint
		MTH3D_tdstVector stTransVect;
	MTH3D_M_vSetVectorElements(&stTransVect, vertex2.xX * dist, vertex2.xY * dist, -vertex2.xZ * dist);
		POS_fn_vSetTranslationVector(hLocalMatrix, &stTransVect);

	// scale the arrow.
	MTH3D_tdstMatrix stScaleMatrix;
	MTH3D_M_vSetVectorElements(&stScaleMatrix.stCol_0, 0.3f,    0,         0);
	MTH3D_M_vSetVectorElements(&stScaleMatrix.stCol_1,    0, 0.3f,         0);
	MTH3D_M_vSetVectorElements(&stScaleMatrix.stCol_2,    0,    0,    dist/1.2f);
	POS_fn_vSetScaleMatrix(hLocalMatrix , &stScaleMatrix.stCol_0, &stScaleMatrix.stCol_1, &stScaleMatrix.stCol_2);

	GLI_xComputeTransformMatrix (hLocalMatrix);
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	return poTangent;
}
*/

/*
void NtwDia::fn_vDeleteConnection(Connection* pConnection)
{
	OnConnectDelete();
}
*/

/*
void NtwDia::fn_vDeleteWP()
{
	OnWpDelete();
}
*/

/*
void NtwDia::fn_vDestroyAllArrows()
{
	Graph::GetInterface()->GetInterface()->fn_vCancelCurrentSelection(FALSE);
	while (!ms_oListOfArrows.IsEmpty())
	{
		CPA_SuperObject *pArrow = (CPA_SuperObject*)ms_oListOfArrows.RemoveHead();
		pArrow->IsolateChild();
		pArrow->fn_vUpdateValidity(FALSE);
		Graph::GetInterface()->M_GetWorld()->fn_vUpdateListObjects(pArrow, E_lum_Delete);
		delete pArrow;
	}
}
*/

/*
BOOL NtwDia::fn_bSetCrtConnection(Connection* poConnection)
{
	fn_vRefreshWPList(poConnection->m_iGraph, poConnection->m_iNode, poConnection->m_iArc);
	return TRUE;
}
*/

/*
BOOL NtwDia::fn_bSetCrtWaypoint(WayPoint* poWayPoint)
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return FALSE;
	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	if (!pGraph->fn_bHasNode(poWayPoint))
		return FALSE;

	switch(m_status)
	{
	case statusReady:
	m_WPList.SetCurSel(pGraph->fn_iGetNodeOfWayPoint((WP_tdhWayPoint)poWayPoint->GetEngineStruct()));
	OnSelchangeNtwWp();
		break;

	case statusNextWP:
		{
			int iNodeSrc = m_WPList.GetCurSel();
			if (iNodeSrc != LB_ERR)
			{
				WP_tdhGraphNode hNodeSrc = pGraph->fn_hGetNode(iNodeSrc);
				WayPoint* pSrcNode = Graph::GetWaypoint(hNodeSrc->m_hWayPoint);
				int iNodeDst = pGraph->fn_iGetNodeOfWayPoint((WP_tdhWayPoint)poWayPoint->GetEngineStruct());
				WP_tdhGraphNode hNodeDst = pGraph->fn_hGetNode(iNodeDst);
				pGraph->fn_vAddArcToNode(hNodeSrc, hNodeDst);
				m_status = statusReady;
				fn_bSetCrtWaypoint(poWayPoint);
				CPA_SuperObject* poArrow = fn_pCreateConnection(iGraph, iNodeSrc, pGraph->fn_iGetArcOfNode(hNodeSrc, hNodeDst));
				ms_oListOfArrows.AddTail(poArrow);
				fn_bSetCrtConnection((Connection*)poArrow->GetObject());

			}
		}
		break;
	case statusPreviousWP:
		{
			int iNodeDst = m_WPList.GetCurSel();
			if (iNodeDst != LB_ERR)
			{
				WP_tdhGraphNode hNodeDst = pGraph->fn_hGetNode(iNodeDst);
				WayPoint* pDstNode = Graph::GetWaypoint(hNodeDst->m_hWayPoint);
				int iNodeSrc = pGraph->fn_iGetNodeOfWayPoint((WP_tdhWayPoint)poWayPoint->GetEngineStruct());
				WP_tdhGraphNode hNodeSrc = pGraph->fn_hGetNode(iNodeSrc);
				pGraph->fn_vAddArcToNode(hNodeSrc, hNodeDst);
				m_status = statusReady;
				fn_bSetCrtWaypoint(poWayPoint);
				CPA_SuperObject* poArrow = fn_pCreateConnection(iGraph, iNodeSrc, pGraph->fn_iGetArcOfNode(hNodeSrc, hNodeDst));
				ms_oListOfArrows.AddTail(poArrow);
				fn_bSetCrtConnection((Connection*)poArrow->GetObject());

			}
		}
		break;
	}
	return TRUE;
}
*/

/*
void NtwDia::fn_vShowOutLinks ()
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	int iNode = m_WPList.GetCurSel();
	if (iNode != LB_ERR)
	{
		fn_vDestroyAllArrows();

		WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);
		WayPoint* pSrcNode = Graph::GetWaypoint(hNode->m_hWayPoint);
		for (int i = 0; i < pGraph->fn_iGetNumberOfArcs(hNode); i++)
		{
			WP_tdHandleOfArc hArc = pGraph->fn_hGetArc(hNode, i);
			WayPoint* pDstNode = Graph::GetWaypoint(hArc->m_hNode->m_hWayPoint);
			CPA_SuperObject* poArrow = fn_pCreateConnection(iGraph, iNode, i);
			ms_oListOfArrows.AddTail(poArrow);
		}
		Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	}
}
*/
/*
void NtwDia::fn_vShowInLinks ()
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	int iNode = m_WPList.GetCurSel();
	if (iNode != LB_ERR)
	{
		fn_vDestroyAllArrows();

		WP_tdhGraphNode hDstNode = pGraph->fn_hGetNode(iNode);
		WayPoint* pDstNode = Graph::GetWaypoint(hDstNode->m_hWayPoint);
		for (int i = 0; i < pGraph->fn_iGetNumberOfNodes(); i++)
		{
			WP_tdhGraphNode hSrcNode = pGraph->fn_hGetNode(i);
			WayPoint* pSrcNode = Graph::GetWaypoint(hSrcNode->m_hWayPoint);
			if (hSrcNode != hDstNode && pGraph->fn_bNodeHasArc(hSrcNode, hDstNode))
			{
				CPA_SuperObject* poArrow = fn_pCreateConnection(iGraph, i, pGraph->fn_iGetArcOfNode(hSrcNode, hDstNode));
				ms_oListOfArrows.AddTail(poArrow);
			}
		}
		Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	}
}
*/
/*
void NtwDia::fn_vShowAllLinks ()
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
	fn_vDestroyAllArrows();

	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	for (int iNode = 0; iNode < pGraph->fn_iGetNumberOfNodes(); iNode++)
	{
		WP_tdhGraphNode hSrcNode = pGraph->fn_hGetNode(iNode);
		WayPoint* pSrcNode = Graph::GetWaypoint(hSrcNode->m_hWayPoint);
		for (int iArc = 0; iArc < pGraph->fn_iGetNumberOfArcs(hSrcNode); iArc++)
		{
			WP_tdHandleOfArc hArc = pGraph->fn_hGetArc(hSrcNode, iArc);
			WayPoint* pDstNode = Graph::GetWaypoint(hArc->m_hNode->m_hWayPoint);
			CPA_SuperObject* poArrow = fn_pCreateConnection(iGraph, iNode, iArc);
			ms_oListOfArrows.AddTail(poArrow);
		}
	}
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
}
*/

/*
void NtwDia::fn_vDefineNextWP()
{
	fn_vDestroyAllArrows();
	m_status = statusNextWP;
}
*/
/*
void NtwDia::fn_vDefinePreviousWP()
{
	fn_vDestroyAllArrows();
	m_status = statusPreviousWP;
}
*/

/*
BOOL NtwDia::fn_bAddOrDeleteWaypoint(WayPoint* poWayPoint)
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return FALSE;
	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);

	if (poWayPoint->fn_bIsAlone() && !pGraph->fn_bHasNode(poWayPoint))
	{
		pGraph->fn_vAddNode(poWayPoint);
		int iNode = pGraph->fn_iGetNodeOfWayPoint((WP_tdhWayPoint)poWayPoint->GetEngineStruct());
		m_WPList.AddString(poWayPoint->GetName());
		m_WPList.SetCurSel(iNode);
	}
	else
	{
		int iNode = pGraph->fn_iGetNodeOfWayPoint((WP_tdhWayPoint)poWayPoint->GetEngineStruct());
		pGraph->fn_bRemoveNode(poWayPoint);
		m_WPList.DeleteString(iNode);
	}
	OnSelchangeNtwWp();
	pGraph->fn_vNotifySave();
	return TRUE;
}
*/
/*
void NtwDia::fn_vCancelDisplayLinks()
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
	fn_vDestroyAllArrows();
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
}
*/

/*
void NtwDia::fn_vShowAllWP ()
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;

	GEO_tdstColor stColorIT;
	stColorIT.xR = 0.f;
	stColorIT.xG = 0.f;
	stColorIT.xB = 0.8f;
	stColorIT.xA = 1.f;
	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	for (int iNode = 0; iNode < pGraph->fn_iGetNumberOfNodes(); iNode++)
	{
		WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);
		WayPoint* pNode = Graph::GetWaypoint(hNode->m_hWayPoint);
		Symbolical3D* poWPObject = (Symbolical3D*)pNode->GetSuperObject()->GetObject();
		for(int i = 0; i < 4; i++)
			GEO_vSetPointReceivedLightIntensityOfObject (poWPObject->GetStruct(), &stColorIT, i);
			// d_stListOfPointsReceivedLightIntensity + i = &stColorIT;
//		Graph::GetInterface()->fn_vInitGameMaterial(poWPObject, poWPObject->GetHElement(), stColorIT.xR, stColorIT.xG, stColorIT.xB);

		GMT_tdxHandleToGameMaterial hGameMaterial = GMT_fn_hCreateGameMaterial();
		ACP_tdxHandleOfMaterial hMaterial;
		GLI_xCreateMaterial ( &hMaterial ) ;
		GMT_fn_vSetVisualMaterial (hGameMaterial, hMaterial);
		GLI_xSetMaterialAmbientCoef ( hMaterial, &stColorIT);
		GLI_xSetMaterialType ( hMaterial, C_lGouraudElement );
		poWPObject->fn_vSetEngineGameMaterial  (poWPObject->GetHElement(), 0, hGameMaterial );

	}

	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);

}
*/
//End Shaitan Correction }

void NtwDia::OnGraphInsert() 
{
//	UpdateData(TRUE);

	HINSTANCE hOldInst = AfxGetResourceHandle();
	AfxSetResourceHandle(Graph::GetInterface()->GetDLLIdentity()->hModule);

	NtwCreationDialog oDialog("NewGraph", this, NULL);
	oDialog.DoModal();

	AfxSetResourceHandle(hOldInst);

// Shaitan Correction {
/*	
	if (m_EditGraph != "" && m_GraphNameList.FindStringExact(-1, m_EditGraph) == LB_ERR)
	{
		Graph * pGraph = new Graph(Graph::GetInterface(), m_EditGraph);
		m_EditGraph = pGraph->GetName();
		m_GraphNameList.SetEditSel (0,-1);
		m_GraphNameList.AddString (m_EditGraph);
		m_GraphNameList.SetCurSel(m_GraphNameList.GetCount() - 1);
		fn_vRefreshWPList(m_GraphNameList.GetCurSel());
	}
*/
//End Shaitan Correction }
	m_GraphNameList.SetFocus();
}

void NtwDia::OnGraphDelete() 
{
	UpdateData(TRUE);

	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
	
// Shaitan NewParam {
//	m_hSelArc = NULL;
//End Shaitan NewParam }
// Shaitan Correction {
//	delete Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
//	m_GraphNameList.DeleteString (iGraph);
//	fn_vRefreshWPList(m_GraphNameList.GetCurSel());
	DeleteGraph *pModif = new DeleteGraph((Graph*) m_GraphNameList.GetItemData(iGraph));
	Graph::GetInterface()->GetInterface()->GetMultiDevice()->GetEditManager()->AskFor(pModif);
	fn_vRefreshGraphList(NULL);
	Graph::GetInterface()->fn_vSelectGraph(NULL);
//End Shaitan Correction }
}

void NtwDia::OnSelchangeGraphName() 
{
	UpdateData(TRUE);
// Shaitan Correction {
//	fn_vRefreshWPList(m_GraphNameList.GetCurSel());
	int iGraph = m_GraphNameList.GetCurSel();
	Graph::GetInterface()->fn_vSelectGraph((iGraph != LB_ERR) ? (Graph *)m_GraphNameList.GetItemData(iGraph) : NULL);
//End Shaitan Correction }
}

	
// Shaitan Correction {
void NtwDia::OnChangeGraphName() 
{
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;

	Graph * pGraph = (Graph *) m_GraphNameList.GetItemData(iGraph);

	HINSTANCE hOldInst = AfxGetResourceHandle();
	AfxSetResourceHandle(Graph::GetInterface()->GetDLLIdentity()->hModule);

	NtwCreationDialog oDialog(pGraph->GetName(), this, pGraph);
	int iResult = oDialog.DoModal();

	AfxSetResourceHandle(hOldInst);

	if (iResult == IDOK)
		MessageBox ("All the AI referencing this graph will become invalid.\nDon't forget to update the name in all concerned AI" , "WARNING !", MB_OK|MB_ICONEXCLAMATION  );

	m_GraphNameList.SetCurSel(iGraph);
	m_GraphNameList.SetFocus();
}
//End Shaitan Correction }

void NtwDia::OnWpInsert() 
{
	UpdateData(TRUE);
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
	
// Shaitan Correction {
//	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
//End Shaitan Correction }

	IsoWPDia dlg;
	POSITION lPos;
	for (WayPoint* poWP = WayPoint::ms_oListOfWaypoint.GetHeadElement(lPos); poWP; poWP = WayPoint::ms_oListOfWaypoint.GetNextElement(lPos))
	{
		if (poWP->fn_bIsAlone() && !pGraph->fn_bHasNode(poWP))
			dlg.m_oListOfWP.AddTail(poWP);
	}
	if (dlg.DoModal() == IDOK)
	{
// Shaitan Correction {
		BOOL pBlock = FALSE;
		
		for (WayPoint* poWP = dlg.m_oListOfSelWP.GetHeadElement(lPos); poWP; poWP = dlg.m_oListOfSelWP.GetNextElement(lPos))
		{
			pGraph->fn_vAddNode(poWP, pBlock);
			pBlock = TRUE;
//			m_WPList.AddString(poWP->GetName());
		}
//		fn_vRefreshConnectList(m_GraphNameList.GetCurSel(), m_WPList.GetCurSel());
//		pGraph->fn_vNotifySave();
//End Shaitan Correction }
	}
}

void NtwDia::OnWpDelete() 
{
	UpdateData(TRUE);
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	if (iGraph == LB_ERR || iNode == LB_ERR)
		return;
// Shaitan Correction {
//	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
// Shaitan NewParam {
//	m_hSelArc = NULL;
//End Shaitan NewParam }
/*	
	POSITION pos, pos1;
	CPA_List<void> oDelList;
	for(CPA_SuperObject *poObj = ms_oListOfArrows.GetHeadElement(pos); poObj; poObj = ms_oListOfArrows.GetNextElement(pos))
	{
		Connection* pConnection = (Connection*)poObj->GetObject();
		if (pConnection->m_iGraph != iGraph)
			continue;
		if (pConnection->m_iNode == iNode)
			oDelList.AddTail(pos);
		else
		{
			WP_tdhGraphNode hSrcNode = pGraph->fn_hGetNode(pConnection->m_iNode);
			WP_tdhGraphNode hDstNode = pGraph->fn_hGetArc(hSrcNode, pConnection->m_iArc)->m_hNode;
			int iDstNode = pGraph->fn_iGetNodeOfWayPoint(hDstNode->m_hWayPoint);
			if (iDstNode == iNode)
				oDelList.AddTail(pos);
		}
	}

	for(poObj = ms_oListOfArrows.GetHeadElement(pos); poObj; poObj = ms_oListOfArrows.GetNextElement(pos))
	{
		Connection* pConnection = (Connection*)poObj->GetObject();
		if (pConnection->m_iGraph != iGraph)
			continue;

		WP_tdhGraphNode hSrcNode = pGraph->fn_hGetNode(pConnection->m_iNode);
		WP_tdhGraphNode hDstNode = pGraph->fn_hGetArc(hSrcNode, pConnection->m_iArc)->m_hNode;
		int iDstNode = pGraph->fn_iGetNodeOfWayPoint(hDstNode->m_hWayPoint);
		if (iDstNode == iNode)
		{
			for(CPA_SuperObject *poObj1 = ms_oListOfArrows.GetHeadElement(pos1); poObj1; poObj1 = ms_oListOfArrows.GetNextElement(pos1))
			{
				Connection* pConnection1 = (Connection*)poObj1->GetObject();
				if (pConnection1->m_iNode == pConnection->m_iNode && pConnection1->m_iArc > pConnection->m_iArc)
					pConnection1->m_iArc--;
			}
		}

		if (pConnection->m_iNode > iNode)
			pConnection->m_iNode--;
	}

	for(pos1 = (POSITION)oDelList.GetHeadElement(pos); pos1; pos1 = (POSITION)oDelList.GetNextElement(pos))
	{
		CPA_SuperObject *poObjDel = ms_oListOfArrows.GetAt(pos1);
		ms_oListOfArrows.RemoveAt(pos1);
		poObjDel->IsolateChild();
		poObjDel->fn_vUpdateValidity(FALSE);
		Graph::GetInterface()->M_GetWorld()->fn_vUpdateListObjects(poObjDel, E_lum_Delete);
	}
*/
//	pGraph->fn_bRemoveNode(iNode);
	pGraph->fn_bRemoveNode(iNode, FALSE);
/*
	m_WPList.DeleteString(iNode);
	fn_vRefreshConnectList(m_GraphNameList.GetCurSel(), m_WPList.GetCurSel());
	pGraph->fn_vNotifySave();
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
*/
//End Shaitan Correction }
}

void NtwDia::OnSelchangeNtwWp() 
{
	UpdateData(TRUE);
// Shaitan Correction {
//	fn_vRefreshConnectList(m_GraphNameList.GetCurSel(), m_WPList.GetCurSel());
	int iNode = m_WPList.GetCurSel();
	WayPoint *pNode = (iNode != LB_ERR) ? (WayPoint *) m_WPList.GetItemData(iNode) : NULL;
	Graph::GetInterface()->fn_vSetDisplayedWaypoint(pNode);
//End Shaitan Correction }
}


void NtwDia::OnConnectInsert() 
{
	UpdateData(TRUE);

	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	if (iGraph == LB_ERR || iNode == LB_ERR)
		return;
	
// Shaitan Correction {
//	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
//End Shaitan Correction }
	WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);

	IsoWPDia dlg;
	for (int i  = 0; i < pGraph->fn_iGetNumberOfNodes(); i++)
	{
		if (hNode != pGraph->fn_hGetNode(i) && !pGraph->fn_bNodeHasArc(hNode, pGraph->fn_hGetNode(i)))
			dlg.m_oListOfWP.AddTail(Graph::GetWaypoint(pGraph->fn_hGetNode(i)->m_hWayPoint));
	}
	if (dlg.DoModal() == IDOK)
	{
		POSITION lPos;
// Shaitan Correction {
		BOOL pBlock = FALSE;
		for (WayPoint* poWP = dlg.m_oListOfSelWP.GetHeadElement(lPos); poWP; poWP = dlg.m_oListOfSelWP.GetNextElement(lPos))
		{
			WP_tdhGraphNode hDstNode = pGraph->fn_hGetNode(pGraph->fn_iGetNodeOfWayPoint((WP_tdhWayPoint)poWP->GetEngineStruct()));
			pGraph->fn_vAddArcToNode(hNode, hDstNode, pBlock);
			if (Graph::GetInterface()->fn_bGetSymetricMode())
				pGraph->fn_vAddArcToNode(hDstNode, hNode, TRUE);
			pBlock = TRUE;
//			m_ConnectList.AddString(poWP->GetName());
		}
//		pGraph->fn_vNotifySave();
//End Shaitan Correction }
	}

	UpdateData(FALSE);
}

void NtwDia::OnConnectDelete() 
{
	UpdateData(TRUE);

	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	int iArc = m_ConnectList.GetCurSel();
	if (iGraph == LB_ERR || iNode == LB_ERR || iArc == LB_ERR)
		return;

// Shaitan Correction {
//	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
	WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);

	pGraph->fn_vRemoveArcOfNode(hNode, iArc, FALSE);
	if (Graph::GetInterface()->fn_bGetSymetricMode())
	{
		WP_tdhGraphNode hDstNode = pGraph->fn_hGetArc(hNode, iArc)->m_hNode;
		int iDstArc = pGraph->fn_iGetArcOfNode(hDstNode, hNode);
		if (iDstArc != -1)
			pGraph->fn_vRemoveArcOfNode(hDstNode, iDstArc, TRUE);
	}

	CPA_SuperObject *pSupObj = Graph::GetInterface()->GetInterface()->GetCurrentWorld()->GetSingleSelection();
	Graph::GetInterface()->GetInterface()->fn_vRemoveSelectedObject(pSupObj, FALSE);
//	m_ConnectList.DeleteString(iArc);

// Shaitan NewParam {
//	m_hSelArc = NULL;
//End Shaitan NewParam }
	UpdateData(FALSE);
//	pGraph->fn_vNotifySave();
/*
	POSITION pos, posDel = NULL;
	for(CPA_SuperObject *poObj = ms_oListOfArrows.GetHeadElement(pos), *poObjDel = NULL; poObj; poObj = ms_oListOfArrows.GetNextElement(pos))
	{
		Connection* pConnection = (Connection*)poObj->GetObject();
		if (pConnection->m_iGraph == iGraph && pConnection->m_iNode == iNode)
		{
			if (pConnection->m_iArc == iArc)
			{
				posDel = pos;
				poObjDel = poObj;
			}
			else if (pConnection->m_iArc > iArc)
				pConnection->m_iArc--;
		}
	}
	if (posDel)
		ms_oListOfArrows.RemoveAt(posDel);
	if (poObjDel)
	{
		poObjDel->IsolateChild();
		poObjDel->fn_vUpdateValidity(FALSE);
		Graph::GetInterface()->M_GetWorld()->fn_vUpdateListObjects(poObjDel, E_lum_Delete);
//		delete poObjDel;
	}
	Graph::GetInterface()->GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
*/
//End Shaitan Correction }
}

void NtwDia::OnSelchangeConnectList() 
{
	// Save the old selected arc params.
	UpdateData(TRUE);
	// Load the new	selected arc params.
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	int iArc = m_ConnectList.GetCurSel();
// Shaitan NewParam {
//	m_hSelArc = NULL;
//End Shaitan NewParam }
	if (iGraph != LB_ERR && iNode != LB_ERR && iArc != LB_ERR)
	{
// Shaitan Correction {
//		Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
		// get parameters
		Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
		WayPoint *pNode = (WayPoint *) m_WPList.GetItemData(iNode);
		WayPoint *pDest = (WayPoint *) m_ConnectList.GetItemData(iArc);
		// select connection in 3D view
		CPA_SuperObject * pConnection = pGraph->GetGraphicConnection(pNode, pDest);
		Graph::GetInterface()->GetInterface()->fn_bSelectObject(pConnection, FALSE);
		// update dialog parameters
		WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);
// Shaitan NewParam {
//		m_hSelArc = pGraph->fn_hGetArc(hNode, iArc);
//End Shaitan NewParam }
		m_iSelectedConnection = iArc;
	}

// Shaitan NewParam {
	// update controls state
	GetDlgItem (IDC_CONNECT_DELETE)->EnableWindow (m_iSelectedConnection != LB_ERR);
	GetDlgItem (IDC_CONNECT_EDIT)->EnableWindow (m_iSelectedConnection != LB_ERR);
//End Shaitan NewParam }

	UpdateData(FALSE);
//End Shaitan Correction }
}


// Shaitan NewParam {
void NtwDia::OnEditNode() 
{
	// get current selection
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	if (iGraph == LB_ERR || iNode == LB_ERR)
		return;

	// get parameters
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
	WayPoint* pNode = (WayPoint*) m_WPList.GetItemData(iNode);

	HINSTANCE hOldInst = AfxGetResourceHandle();
	AfxSetResourceHandle(Graph::GetInterface()->GetDLLIdentity()->hModule);

	NtwParameterDialog oDialog(this, pGraph, pNode);
	oDialog.DoModal();

	AfxSetResourceHandle(hOldInst);
}

void NtwDia::OnEditConnect() 
{
	// get current selection
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	int iArc = m_ConnectList.GetCurSel();
	if (iGraph == LB_ERR || iNode == LB_ERR || iArc == LB_ERR)
		return;

	// get parameters
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
	WayPoint* pSrcNode = (WayPoint*) m_WPList.GetItemData(iNode);
	WayPoint* pDstNode = (WayPoint*) m_ConnectList.GetItemData(iArc);

	HINSTANCE hOldInst = AfxGetResourceHandle();
	AfxSetResourceHandle(Graph::GetInterface()->GetDLLIdentity()->hModule);

	NtwParameterDialog oDialog(this, pGraph, pSrcNode, pDstNode);
	oDialog.DoModal();

	AfxSetResourceHandle(hOldInst);
}
/*
void NtwDia::OnDefaultWeight() 
{
	UpdateData(TRUE);
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	int iArc = m_ConnectList.GetCurSel();
	if (iGraph == LB_ERR || iNode == LB_ERR || iArc == LB_ERR)
		return;
// Shaitan Correction {
//	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
//End Shaitan Correction }
	WP_tdhGraphNode hNode = pGraph->fn_hGetNode(iNode);
	pGraph->fn_vSetDefaultArcWeight(hNode, iArc);
	UpdateData(FALSE);
// Shaitan Correction {
//	pGraph->fn_vNotifySave();
//End Shaitan Correction }
}
*/
//End Shaitan NewParam }

void NtwDia::OnDefaultAllWeights() 
{
	UpdateData(TRUE);
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;
// Shaitan Correction {
//	Graph* pGraph = Graph::ms_oListOfGraph.FindElementFromIndex(iGraph);
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
//End Shaitan Correction }
	pGraph->fn_vSetDefaultAllArcsWeight();
	UpdateData(FALSE);
// Shaitan Correction {
//	pGraph->fn_vNotifySave();
//End Shaitan Correction }
}

// Shaitan NewParam {
void NtwDia::OnEditAllConnects() 
{
	// get current selection
	int iGraph = m_GraphNameList.GetCurSel();
	if (iGraph == LB_ERR)
		return;

	// get parameters
	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);

	HINSTANCE hOldInst = AfxGetResourceHandle();
	AfxSetResourceHandle(Graph::GetInterface()->GetDLLIdentity()->hModule);

	NtwParameterDialog oDialog(this, pGraph, NULL, NULL, TRUE);
	oDialog.DoModal();

	AfxSetResourceHandle(hOldInst);
}

/*
void NtwDia::OnCapacity()
{
// Shaitan Correction {
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	int iConnect = m_ConnectList.GetCurSel();

	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
	WayPoint *pSrcNode = (WayPoint *) m_WPList.GetItemData(iNode);
	WayPoint *pDstNode = (WayPoint *) m_ConnectList.GetItemData(iConnect);

	for (int i = 0, iMask = 1, iCapacity = 0; i < 32; i++, iMask <<= 1)
	{
		if (((CButton*)GetDlgItem(IDC_CAPACITY1 + i))->GetCheck() == 1)
			iCapacity |= iMask;
	}
	pGraph->SetConnectionCapacity(pSrcNode, pDstNode, iCapacity);
	pGraph->fn_vNotifySave();
//End Shaitan Correction }
}

void NtwDia::OnChangeWeight()
{
	UpdateData(TRUE);
// Shaitan Correction {
	int iGraph = m_GraphNameList.GetCurSel();
	int iNode = m_WPList.GetCurSel();
	int iConnect = m_ConnectList.GetCurSel();

	Graph* pGraph = (Graph*) m_GraphNameList.GetItemData(iGraph);
	WayPoint *pSrcNode = (WayPoint *) m_WPList.GetItemData(iNode);
	WayPoint *pDstNode = (WayPoint *) m_ConnectList.GetItemData(iConnect);

	pGraph->SetConnectionWeight(pSrcNode, pDstNode, m_lWeight);
	pGraph->fn_vNotifySave();
// End Shaitan Correction }
}

*/
//End Shaitan NewParam }

void NtwDia::OnDefault()
{
	UpdateData(TRUE);
}


BOOL NtwDia::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{

	BOOL bCreate = CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
	TUT_M_vGetTutDll ();
	TUT_M_vRegisterControl (m_hWnd , "OWP_GraphDialog" , TUT_e_Window);
	TUT_M_vRegisterControlID (IDC_GRAPH_NAME,"OWP_GraphCombo",TUT_e_ComboBox);
	TUT_M_vRegisterControlID (IDC_GRAPH_INSERT,"OWP_GraphInsert",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_GRAPH_DELETE,"OWP_GraphDelete",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_NTW_WP,"OWP_GraphWayPointsCombo",TUT_e_ComboBox);
	TUT_M_vRegisterControlID (IDC_WP_INSERT,"OWP_WpAdd",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_WP_DELETE,"OWP_WpDel",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_CONNECT_LIST,"OWP_ConnectCombo",TUT_e_ListBox);
	TUT_M_vRegisterControlID (IDC_CONNECT_INSERT,"OWP_ConnectAdd",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_CONNECT_DELETE,"OWP_ConnectDel",TUT_e_Button);
// Shaitan NewParam {
//	TUT_M_vRegisterControlID (IDC_WEIGHT,"OWP_WeightEdit",TUT_e_TextEdit);
//	TUT_M_vRegisterControlID (IDC_DEFAULT_WEIGHT,"OWP_DefaultWeight",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_DEFAULT_ALL_WEIGHTS,"OWP_DefaultAllWeights",TUT_e_Button);
/*
	char szOWP_Capacity[20];
	for (int i = 0; i < 32; i++)
	{
		sprintf(szOWP_Capacity, "OWP_Capacity%i", i);
		TUT_M_vRegisterControlID (IDC_CAPACITY1 + i, szOWP_Capacity, TUT_e_Button);
	}
*/
//End Shaitan NewParam }
	return bCreate;
  
}
 
void NtwDia::OnDestroy() 
{
	TUT_M_vGetTutDll ();
	TUT_M_vUnregisterControl (m_hWnd);
	TUT_M_vUnregisterControlID (IDC_GRAPH_NAME);
	TUT_M_vUnregisterControlID (IDC_GRAPH_INSERT);
	TUT_M_vUnregisterControlID (IDC_GRAPH_DELETE);
	TUT_M_vUnregisterControlID (IDC_NTW_WP);
	TUT_M_vUnregisterControlID (IDC_WP_INSERT);
	TUT_M_vUnregisterControlID (IDC_WP_DELETE);
	TUT_M_vUnregisterControlID (IDC_CONNECT_LIST);
	TUT_M_vUnregisterControlID (IDC_CONNECT_INSERT);
	TUT_M_vUnregisterControlID (IDC_CONNECT_DELETE);
// Shaitan NewParam {
//	TUT_M_vUnregisterControlID (IDC_WEIGHT);
//	TUT_M_vUnregisterControlID (IDC_DEFAULT_WEIGHT);
	TUT_M_vUnregisterControlID (IDC_DEFAULT_ALL_WEIGHTS);
//	for (int i = 0; i < 32; i++)
//		TUT_M_vUnregisterControlID (IDC_CAPACITY1 + i);
//End Shaitan NewParam }
}

//ENDROMTEAM Networks (Gabriela Dumitrascu)

// Shaitan Correction {
int NtwDia::GetIndexOfGraph	(Graph *pGraph)
{
	int iGraph;

	for (iGraph = 0; iGraph < m_GraphNameList.GetCount(); iGraph++)
	{
		if (m_GraphNameList.GetItemData(iGraph) == (DWORD) pGraph)
			return iGraph;
	}

	return LB_ERR;
}

int NtwDia::GetIndexOfNode (WayPoint *pNode)
{
	int iNode;
	
	for (iNode = 0; iNode < m_WPList.GetCount(); iNode++) 
	{
		if (m_WPList.GetItemData(iNode) == (DWORD) pNode)
			return iNode;
	}

	return LB_ERR;
}

int NtwDia::GetIndexOfConnection (WayPoint *pDstNode)
{
	int iConnect;
	
	for (iConnect = 0; iConnect < m_ConnectList.GetCount(); iConnect++) 
	{
		if (m_ConnectList.GetItemData(iConnect) == (DWORD) pDstNode)
			return iConnect;
	}

	return LB_ERR;
}
	

void NtwDia::fn_vSelectGraph (Graph *pGraph)
{
	BOOL	bFound = FALSE;
	int		iGraph = 0;
	
	// search list of graph
	iGraph = GetIndexOfGraph(pGraph);

	// if graph is already selected, no change
	if (iGraph == m_iSelectedGraph)
		return;

	// select graph
	if (iGraph != LB_ERR)
		m_GraphNameList.SetCurSel(iGraph);

	m_iSelectedGraph = iGraph;

// Shaitan NewParam {
	// update controls state
	GetDlgItem (IDC_GRAPH_DELETE)->EnableWindow (iGraph != LB_ERR);
	GetDlgItem (IDC_GRAPH_RENAME)->EnableWindow (iGraph != LB_ERR);

	GetDlgItem (IDC_WP_INSERT)->EnableWindow (iGraph != LB_ERR);
	GetDlgItem (IDC_WP_DELETE)->EnableWindow (FALSE);
	GetDlgItem (IDC_WP_EDIT)->EnableWindow (FALSE);
	
	GetDlgItem (IDC_CONNECT_INSERT)->EnableWindow (FALSE);
	GetDlgItem (IDC_CONNECT_DELETE)->EnableWindow (FALSE);
	GetDlgItem (IDC_CONNECT_EDIT)->EnableWindow (FALSE);
//End Shaitan NewParam }

	// refresh node list
	fn_vRefreshNodeList(pGraph, NULL);
}

void NtwDia::fn_vSelectNode (Graph *pGraph, WayPoint *pNode)
{
	BOOL bFound = FALSE;
	int  iNode = 0;
	
	// if necessary, update selected graph
	fn_vSelectGraph(pGraph);
	
	// search list of node
	iNode = GetIndexOfNode(pNode);

	// if node is already selected, no change
	if (iNode == m_iSelectedNode)
		return;

	// update node
	if (iNode != LB_ERR)
		m_WPList.SetCurSel(iNode);

	m_iSelectedNode = iNode;

// Shaitan NewParam {
	// update controls state
	GetDlgItem (IDC_WP_DELETE)->EnableWindow (iNode != LB_ERR);
	GetDlgItem (IDC_WP_EDIT)->EnableWindow (iNode != LB_ERR);
	
	GetDlgItem (IDC_CONNECT_INSERT)->EnableWindow (iNode != LB_ERR);
	GetDlgItem (IDC_CONNECT_DELETE)->EnableWindow (FALSE);
	GetDlgItem (IDC_CONNECT_EDIT)->EnableWindow (FALSE);
//End Shaitan NewParam }

	// refresh connect list
	fn_vRefreshConnectList(pGraph, pNode, NULL);

	Graph::GetInterface()->fn_vSetDisplayedWaypoint(pNode);
}

void NtwDia::fn_vSelectConnection (Graph *pGraph, WayPoint *pSrcWaypoint, WayPoint *pDstWaypoint)
{
	BOOL bFound = FALSE;
	int  iConnect = 0;
	
	// if necessary, update selected graph
	fn_vSelectNode(pGraph, pSrcWaypoint);
	
	// search list of connection
	iConnect = GetIndexOfConnection(pDstWaypoint);
	
	// update connection
	if (iConnect != LB_ERR)
		m_ConnectList.SetCurSel(iConnect);

	m_iSelectedConnection = iConnect;
	
	// update connection parameters
	OnSelchangeConnectList();
}


void NtwDia::fn_vRefreshGraphList (Graph *pGraph)
{
	POSITION	pos;
	Graph		*poGraph;
	int			iIndex;

	// RAZ
	m_GraphNameList.ResetContent();
	
	// fill the list
	for (poGraph = Graph::ms_oListOfGraph.GetHeadElement(pos); poGraph; 
		 poGraph= Graph::ms_oListOfGraph.GetNextElement(pos))
	{
		iIndex = m_GraphNameList.AddString(poGraph->GetEngineStruct()->m_szNameOfGraph);
		m_GraphNameList.SetItemData(iIndex, (DWORD)poGraph);
	}

	// update selection
	fn_vRefreshNodeList(pGraph, NULL);
}

void NtwDia::fn_vRefreshNodeList (Graph *pGraph, WayPoint *pNode)
{
	WayPoint *pWP;
	int iNode, iIndex;
	
	// update current graph
	fn_vSelectGraph(pGraph);

	// RAZ
	m_WPList.ResetContent();
	// update list
	if (pGraph != NULL)
	{
		for (iNode = 0; iNode < pGraph->fn_iGetNumberOfNodes(); iNode++)
		{
			pWP = Graph::GetWaypoint(pGraph->fn_hGetWayPointOfNode(iNode));
			iIndex = m_WPList.AddString(pWP->GetName());
			m_WPList.SetItemData(iIndex, (DWORD)pWP);
		}
	}
	// update selection
	fn_vRefreshConnectList(pGraph, pNode, NULL);
}

void NtwDia::fn_vRefreshConnectList (Graph *pGraph, WayPoint *pSrcWaypoint, WayPoint *pDstWaypoint)
{
	WP_tdhGraphNode	hNode;
	WayPoint		*pWP;
	int				iConnect, iIndex;
	
	// update current graph and node
	fn_vSelectNode(pGraph, pSrcWaypoint);

	// RAZ
	m_ConnectList.ResetContent();
	// update list
	if ((pGraph != NULL) && (pSrcWaypoint != NULL))
	{
		hNode = pGraph->fn_hGetNode(pGraph->fn_iGetNodeOfWayPoint(pSrcWaypoint->GetStruct()));
		for (iConnect = 0; iConnect < pGraph->fn_iGetNumberOfArcs(hNode); iConnect++)
		{
			pWP = Graph::GetWaypoint(pGraph->fn_hGetArc(hNode, iConnect)->m_hNode->m_hWayPoint);
			iIndex = m_ConnectList.AddString(pWP->GetName());
			m_ConnectList.SetItemData(iIndex, (DWORD)pWP);
		}
	}
	fn_vSelectConnection(pGraph, pSrcWaypoint, pDstWaypoint);
}

void NtwDia::OnDblClkNtwWp (void)
{
	// get parameters
	int iNode = m_WPList.GetCurSel();
	WayPoint *pNode = (iNode != LB_ERR) ? (WayPoint *) m_WPList.GetItemData(iNode) : NULL;
	if (!pNode)
		return;
	
	// select and center
	Graph::GetInterface()->GetInterface()->fn_bSelectObject(pNode->GetSuperObject(), TRUE);
	Graph::GetInterface()->fn_vSetDisplayedWaypoint(pNode);
}

void NtwDia::OnSize(UINT nType, int cx, int cy)
{
	RECT	WindowPosition;
	int		cwx, cwy, iGroupSize, iComboSize;
	int		iFixedHeight = 90;
	int		iMinimalHeight = 260;
	int		iFixedWidth = 100;
	int		iMinimalWidth = 100;

	if (m_bInitialised)
	{
		GetWindowRect(&WindowPosition);
		cwx = WindowPosition.right - WindowPosition.left - 10;
		cwy = WindowPosition.bottom - WindowPosition.top - 10;

		if (cwy < iFixedHeight + iMinimalHeight)
			cwy = iFixedHeight + iMinimalHeight;
		if (cwx < iMinimalWidth)
			cwx = iMinimalWidth;

		iGroupSize = (cwy - iFixedHeight) / 3;
		iComboSize = iGroupSize - 15;

		// Graph
		GetDlgItem(IDC_STATIC_GRAPH)->MoveWindow(5, 5, cwx, 17);
		GetDlgItem(IDC_GRAPH_NAME)->MoveWindow(5, 20, cwx - 55, iComboSize);
		GetDlgItem(IDC_GRAPH_INSERT)->MoveWindow(cwx - 45, 20, 40, 20);
		GetDlgItem(IDC_GRAPH_RENAME)->MoveWindow(cwx - 45, 45, 40, 20);
		GetDlgItem(IDC_GRAPH_DELETE)->MoveWindow(cwx - 45, 70, 40, 20);
// Shaitan NewParam {
		// Node
		GetDlgItem(IDC_STATIC_NODE)->MoveWindow(5, iGroupSize + 5, 40, 17);
		GetDlgItem(IDC_NTW_WP)->MoveWindow(5, iGroupSize + 20, cwx - 55, iComboSize);
		GetDlgItem(IDC_WP_INSERT)->MoveWindow(cwx - 45, iGroupSize + 20, 40, 20);
		GetDlgItem(IDC_WP_EDIT)  ->MoveWindow(cwx - 45, iGroupSize + 45, 40, 20);
		GetDlgItem(IDC_WP_DELETE)->MoveWindow(cwx - 45, iGroupSize + 70, 40, 20);
		// Connection
		GetDlgItem(IDC_STATIC_LINK)->MoveWindow(5, 2*iGroupSize + 5, cwx, 17);
		GetDlgItem(IDC_CONNECT_LIST)->MoveWindow(5, 2*iGroupSize + 20, cwx - 55, iComboSize);
		GetDlgItem(IDC_CONNECT_INSERT)->MoveWindow(cwx - 45, 2*iGroupSize + 20, 40, 20);
		GetDlgItem(IDC_CONNECT_EDIT)  ->MoveWindow(cwx - 45, 2*iGroupSize + 45, 40, 20);
		GetDlgItem(IDC_CONNECT_DELETE)->MoveWindow(cwx - 45, 2*iGroupSize + 70, 40, 20);
/*
		// Capacity
		GetDlgItem(IDC_STATIC_CAPACITY)->MoveWindow(5, 3*iGroupSize + 10, 170, 100);
		// line 1
		GetDlgItem(IDC_CAPACITY1)->MoveWindow(15, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY2)->MoveWindow(35, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY3)->MoveWindow(55, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY4)->MoveWindow(75, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY5)->MoveWindow(95, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY6)->MoveWindow(115, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY7)->MoveWindow(135, 3*iGroupSize + 30, 15,15);
		GetDlgItem(IDC_CAPACITY8)->MoveWindow(155, 3*iGroupSize + 30, 15,15);
		// line 2
		GetDlgItem(IDC_CAPACITY9)->MoveWindow(15, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY10)->MoveWindow(35, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY11)->MoveWindow(55, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY12)->MoveWindow(75, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY13)->MoveWindow(95, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY14)->MoveWindow(115, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY15)->MoveWindow(135, 3*iGroupSize + 50, 15,15);
		GetDlgItem(IDC_CAPACITY16)->MoveWindow(155, 3*iGroupSize + 50, 15,15);
		// line 3
		GetDlgItem(IDC_CAPACITY17)->MoveWindow(15, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY18)->MoveWindow(35, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY19)->MoveWindow(55, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY20)->MoveWindow(75, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY21)->MoveWindow(95, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY22)->MoveWindow(115, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY23)->MoveWindow(135, 3*iGroupSize + 70, 15,15);
		GetDlgItem(IDC_CAPACITY24)->MoveWindow(155, 3*iGroupSize + 70, 15,15);
		// line 4
		GetDlgItem(IDC_CAPACITY25)->MoveWindow(15, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY26)->MoveWindow(35, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY27)->MoveWindow(55, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY28)->MoveWindow(75, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY29)->MoveWindow(95, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY30)->MoveWindow(115, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY31)->MoveWindow(135, 3*iGroupSize + 90, 15,15);
		GetDlgItem(IDC_CAPACITY32)->MoveWindow(155, 3*iGroupSize + 90, 15,15);
		// Weight
		GetDlgItem(IDC_STATIC_WEIGHT)->MoveWindow(5, 3*iGroupSize + 115, 170, 40);
		GetDlgItem(IDC_WEIGHT)->MoveWindow(10, 3*iGroupSize + 130, 40, 20);
		GetDlgItem(IDC_DEFAULT_WEIGHT)->MoveWindow(55, 3*iGroupSize + 130, 50, 20);
*/
		GetDlgItem(IDC_CONNECT_EDITALL)->MoveWindow(5, 3*iGroupSize + 10, cwx, 17);
		GetDlgItem(IDC_CONNECT_ALLDEFAULT)->MoveWindow(5, 3*iGroupSize + 35, cwx, 17);
		GetDlgItem(IDC_CONNECT_SYMETRIC)->MoveWindow(cwx/2 - 40, 3*iGroupSize + 60, 80, 20);
//End Shaitan NewParam }
	}
	return;
}

//End Shaitan Correction }


void NtwDia::OnSymetric (void)
{
	Graph::GetInterface()->fn_vSetSymetricMode(m_Symetric.GetCheck());
}

// Shaitan Correction {
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// NtwCreationDialog dialog
BEGIN_MESSAGE_MAP(NtwCreationDialog, CDialog)
	//{{AFX_MSG_MAP(NtwCreationDialog)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//****************************************************************************
NtwCreationDialog::NtwCreationDialog (CString csDefaultName, NtwDia *pParentDialog, Graph *pGraph, CWnd* pParent /*=NULL*/)
	: CDialog(NtwCreationDialog::IDD, &g_oBaseFrame)
{
	m_pParentDialog = pParentDialog;
	m_pEditedGraph = pGraph;
	
	//{{AFX_DATA_INIT(NtwCreationDialog)
	m_csNewName = csDefaultName;
	//}}AFX_DATA_INIT
}

//****************************************************************************
void NtwCreationDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(NtwCreationDialog)
	DDX_Text(pDX, IDC_GRAPH_NAME, m_csNewName);
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// NtwCreationDialog message handlers

//****************************************************************************
BOOL NtwCreationDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	if (m_pEditedGraph)
		SetWindowText("Rename Graph");
	else
		SetWindowText("Create New Graph");

	//////////////
	//Registers for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vRegisterControlID(IDC_GRAPH_NAME, "OWP_Creation_GraphName", TUT_e_TextEdit);
	TUT_M_vRegisterControlID(IDOK, "OWP_Creation_OKButton", TUT_e_Button);
	TUT_M_vRegisterControlID(IDCANCEL, "OOWP_Creation_CancelButton", TUT_e_Button);

	//End of Registers for TUT Module
	//////////////
	
	return TRUE;  
}

//****************************************************************************
void NtwCreationDialog::OnDestroy() 
{
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControlID(IDC_GRAPH_NAME);
	TUT_M_vUnregisterControlID(IDOK);
	TUT_M_vUnregisterControlID(IDCANCEL);
	
	//End of UnRegisters for TUT Module
	//////////////

	CDialog::OnDestroy();
}

//****************************************************************************
void NtwCreationDialog::OnOK() 
{
	UpdateData(TRUE);

	// create the graph
	if (!m_pEditedGraph)
	{
		Graph * pGraph = new Graph(Graph::GetInterface(), m_csNewName);
		m_pParentDialog->fn_vRefreshGraphList(NULL);
		Graph::GetInterface()->fn_vSelectGraph(pGraph); 
	}
	// rename the graph
	else
	{
		RenameGraph *pModif = new RenameGraph(m_pEditedGraph, m_csNewName);
		Graph::GetInterface()->GetInterface()->GetMultiDevice()->GetEditManager()->AskFor(pModif);
		m_pParentDialog->fn_vRefreshGraphList(m_pEditedGraph);
	}
	
	EndDialog(IDOK);
}
//End Shaitan Correction }

// Shaitan NewParam {
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// NtwCreationDialog dialog
BEGIN_MESSAGE_MAP(NtwParameterDialog, CDialog)
	//{{AFX_MSG_MAP(NtwParameterDialog)
	ON_BN_CLICKED(IDC_DEFAULT_WEIGHT, OnDefaultWeight)
	ON_BN_CLICKED(IDC_EDIT_OKNEXT, OnNextOK)
	ON_BN_CLICKED(IDC_EDIT_OKPREV, OnPrevOK)
	ON_BN_CLICKED(IDC_EDIT_CANCELNEXT, OnNextCancel)
	ON_BN_CLICKED(IDC_EDIT_CANCELPREV, OnPrevCancel)
	ON_BN_CLICKED(IDC_EDIT_OKNEXTNODE, OnNextWPOK)
	ON_BN_CLICKED(IDC_EDIT_OKPREVNODE, OnPrevWPOK)
	ON_BN_CLICKED(IDC_EDIT_CANCELNEXTNODE, OnNextWPCancel)
	ON_BN_CLICKED(IDC_EDIT_CANCELPREVNODE, OnPrevWPCancel)
	ON_BN_CLICKED(IDC_EDIT_SYMETRIC, OnSymetric)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//****************************************************************************
NtwParameterDialog::NtwParameterDialog (NtwDia *pParentDialog, Graph *pGraph, WayPoint *pSrcNode, WayPoint *pDstNode/* = NULL*/, BOOL bAll/* = FALSE*/,CWnd* pParent/* = NULL */)
	: CDialog(NtwParameterDialog::IDD, &g_oBaseFrame)
{
	m_pParentDialog = pParentDialog;
	m_pEditedGraph = pGraph;
	m_pSrcNode = pSrcNode;
	m_pDstNode = pDstNode;
	m_bEditConnection = ((pDstNode != NULL) || (bAll == TRUE));
	m_bAll = bAll;
	m_bSymetric = FALSE;
	
	//{{AFX_DATA_INIT(NtwParameterDialog)

	//}}AFX_DATA_INIT
}

//****************************************************************************
void NtwParameterDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(NtwParameterDialog)
	DDX_Control(pDX, IDC_EDIT_WEIGHT, m_cEditWeight);
	DDX_Control(pDX, IDC_STATIC_WEIGHT, m_cStaticWeight);
	DDX_Control(pDX, IDC_DEFAULT_WEIGHT, m_cDefaultWeight);
	DDX_Control(pDX, IDC_STATIC_CAPACITY, m_cStaticType);
	DDX_Control(pDX, IDC_EDIT_OKNEXT, m_cNextOK);
	DDX_Control(pDX, IDC_EDIT_OKPREV, m_cPrevOK);
	DDX_Control(pDX, IDC_EDIT_CANCELNEXT, m_cNextCancel);
	DDX_Control(pDX, IDC_EDIT_CANCELPREV, m_cPrevCancel);
	DDX_Control(pDX, IDC_EDIT_OKNEXTNODE, m_cNextWPOK);
	DDX_Control(pDX, IDC_EDIT_OKPREVNODE, m_cPrevWPOK);
	DDX_Control(pDX, IDC_EDIT_CANCELNEXTNODE, m_cNextWPCancel);
	DDX_Control(pDX, IDC_EDIT_CANCELPREVNODE, m_cPrevWPCancel);
	DDX_Control(pDX, IDC_STATIC_NODE, m_cStaticNode);
	DDX_Control(pDX, IDC_STATIC_LINK, m_cStaticLink);
	DDX_Control(pDX, IDC_EDIT_SYMETRIC, m_cSymetric);
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// NtwCreationDialog message handlers

//****************************************************************************
BOOL NtwParameterDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// init for mode
	if (!m_bEditConnection)
	{
		// update text
		SetWindowText("Edit Node Parameters");
		m_cStaticType.SetWindowText("Type");
		// disable weight edition
		m_cEditWeight.EnableWindow(FALSE);
		m_cStaticWeight.EnableWindow(FALSE);
		m_cDefaultWeight.EnableWindow(FALSE);
		// hide weight controls
		m_cEditWeight.ShowWindow(SW_HIDE);
		m_cStaticWeight.ShowWindow(SW_HIDE);
		m_cDefaultWeight.ShowWindow(SW_HIDE);
		// init prev / next controls
		m_cNextOK.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevOK.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
		m_cNextCancel.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevCancel.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
		// init prev / next state
		m_cNextOK.ShowWindow(SW_SHOW);
		m_cPrevOK.ShowWindow(SW_SHOW);
		m_cNextCancel.ShowWindow(SW_SHOW);
		m_cPrevCancel.ShowWindow(SW_SHOW);
		m_cStaticNode.ShowWindow(SW_SHOW);
		// init prev / next controls
		m_cNextWPOK.EnableWindow(FALSE);
		m_cPrevWPOK.EnableWindow(FALSE);
		m_cNextWPCancel.EnableWindow(FALSE);
		m_cPrevWPCancel.EnableWindow(FALSE);
		// init prev / next state
		m_cNextWPOK.ShowWindow(SW_HIDE);
		m_cPrevWPOK.ShowWindow(SW_HIDE);
		m_cNextWPCancel.ShowWindow(SW_HIDE);
		m_cPrevWPCancel.ShowWindow(SW_HIDE);
		m_cStaticLink.ShowWindow(SW_HIDE);
		// symetric
		m_cSymetric.EnableWindow(FALSE);
		m_cSymetric.ShowWindow(SW_HIDE);
	}
	else if (!m_bAll)
	{
		// update text
		SetWindowText("Edit Connection Parameters");
		m_cStaticType.SetWindowText("Capacity");
		// enable weight edition
		m_cEditWeight.EnableWindow(TRUE);
		m_cStaticWeight.EnableWindow(TRUE);
		m_cDefaultWeight.EnableWindow(TRUE);
		// show weight controls
		m_cEditWeight.ShowWindow(SW_SHOW);
		m_cStaticWeight.ShowWindow(SW_SHOW);
		m_cDefaultWeight.ShowWindow(SW_SHOW);
		// init prev / next controls
		m_cNextOK.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevOK.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
		m_cNextCancel.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevCancel.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
		// init prev / next state
		m_cNextOK.ShowWindow(SW_SHOW);
		m_cPrevOK.ShowWindow(SW_SHOW);
		m_cNextCancel.ShowWindow(SW_SHOW);
		m_cPrevCancel.ShowWindow(SW_SHOW);
		m_cStaticNode.ShowWindow(SW_SHOW);
		// init prev / next controls
		m_cNextWPOK.EnableWindow(m_pEditedGraph->GetNextConnection(m_pSrcNode, m_pDstNode) != NULL);
		m_cPrevWPOK.EnableWindow(m_pEditedGraph->GetPrevConnection(m_pSrcNode, m_pDstNode) != NULL);
		m_cNextWPCancel.EnableWindow(m_pEditedGraph->GetNextConnection(m_pSrcNode, m_pDstNode) != NULL);
		m_cPrevWPCancel.EnableWindow(m_pEditedGraph->GetPrevConnection(m_pSrcNode, m_pDstNode) != NULL);
		// init prev / next state
		m_cNextWPOK.ShowWindow(SW_SHOW);
		m_cPrevWPOK.ShowWindow(SW_SHOW);
		m_cNextWPCancel.ShowWindow(SW_SHOW);
		m_cPrevWPCancel.ShowWindow(SW_SHOW);
		m_cStaticLink.ShowWindow(SW_SHOW);
		// symetric
		m_cSymetric.EnableWindow(TRUE);
		m_cSymetric.ShowWindow(SW_SHOW);
	}
	else 
	{
		// update text
		SetWindowText("Edit All Connections");
		m_cStaticType.SetWindowText("Capacity");
		// disable weight edition
		m_cEditWeight.EnableWindow(FALSE);
		m_cStaticWeight.EnableWindow(FALSE);
		m_cDefaultWeight.EnableWindow(FALSE);
		// hide weight controls
		m_cEditWeight.ShowWindow(SW_HIDE);
		m_cStaticWeight.ShowWindow(SW_HIDE);
		m_cDefaultWeight.ShowWindow(SW_HIDE);
		// init prev / next controls
		m_cNextOK.EnableWindow(FALSE);
		m_cPrevOK.EnableWindow(FALSE);
		m_cNextCancel.EnableWindow(FALSE);
		m_cPrevCancel.EnableWindow(FALSE);
		// init prev / next state
		m_cNextOK.ShowWindow(SW_HIDE);
		m_cPrevOK.ShowWindow(SW_HIDE);
		m_cNextCancel.ShowWindow(SW_HIDE);
		m_cPrevCancel.ShowWindow(SW_HIDE);
		m_cStaticNode.ShowWindow(SW_HIDE);
		// init prev / next controls
		m_cNextWPOK.EnableWindow(FALSE);
		m_cPrevWPOK.EnableWindow(FALSE);
		m_cNextWPCancel.EnableWindow(FALSE);
		m_cPrevWPCancel.EnableWindow(FALSE);
		// init prev / next state
		m_cNextWPOK.ShowWindow(SW_HIDE);
		m_cPrevWPOK.ShowWindow(SW_HIDE);
		m_cNextWPCancel.ShowWindow(SW_HIDE);
		m_cPrevWPCancel.ShowWindow(SW_HIDE);
		m_cStaticLink.ShowWindow(SW_HIDE);
		// symetric
		m_cSymetric.EnableWindow(FALSE);
		m_cSymetric.ShowWindow(SW_HIDE);
	}
	// init values of controls
	fn_vInitParameters();
	
	return TRUE;  
}

//****************************************************************************
void NtwParameterDialog::OnDefaultWeight() 
{
	long lWeight;
	char szWeight[10];
	
	lWeight = m_pEditedGraph->fn_lGetDefaultArcWeight(m_pSrcNode, m_pDstNode);
	sprintf(szWeight, "%ld", lWeight);
	m_cEditWeight.SetWindowText(szWeight);
}

//****************************************************************************
void NtwParameterDialog::OnDestroy() 
{
	CDialog::OnDestroy();
}

//****************************************************************************
void NtwParameterDialog::OnPrevOK()
{
	WayPoint *pNewSrcNode, *pNewDstNode;
	
	UpdateData(TRUE);
	
	// apply modifs
	fn_vApplyModifications();
	// update state
	m_bSymetric = FALSE;

	// select previous connection or node
	if (m_bEditConnection)
	{
		// select previous node
		pNewSrcNode = m_pEditedGraph->GetPrevNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
		// select last connection
		pNewDstNode = m_pEditedGraph->GetPrevConnection(m_pSrcNode, NULL);
		m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
		m_pDstNode = pNewDstNode;
	}
	else
	{
		pNewSrcNode = m_pEditedGraph->GetPrevNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
	}

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnPrevCancel()
{
	WayPoint *pNewSrcNode, *pNewDstNode;
	
	// update state
	m_bSymetric = FALSE;

	// select previous connection or node
	if (m_bEditConnection)
	{
		// select previous node
		pNewSrcNode = m_pEditedGraph->GetPrevNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
		// select last connection
		pNewDstNode = m_pEditedGraph->GetPrevConnection(m_pSrcNode, NULL);
		m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
		m_pDstNode = pNewDstNode;
	}
	else
	{
		pNewSrcNode = m_pEditedGraph->GetPrevNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
	}

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnNextOK()
{
	WayPoint *pNewSrcNode, *pNewDstNode;
	
	UpdateData(TRUE);
	
	// apply modifs
	fn_vApplyModifications();
	// update state
	m_bSymetric = FALSE;

	// select next connection or node
	if (m_bEditConnection)
	{
		// select next node
		pNewSrcNode = m_pEditedGraph->GetNextNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
		// select first connection
		pNewDstNode = m_pEditedGraph->GetNextConnection(m_pSrcNode, NULL);
		m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
		m_pDstNode = pNewDstNode;
	}
	else
	{
		pNewSrcNode = m_pEditedGraph->GetNextNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
	}

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnNextCancel()
{
	WayPoint *pNewSrcNode, *pNewDstNode;

	// update state
	m_bSymetric = FALSE;

	// select next connection or node
	if (m_bEditConnection)
	{
		// select next node
		pNewSrcNode = m_pEditedGraph->GetNextNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
		// select first connection
		pNewDstNode = m_pEditedGraph->GetNextConnection(m_pSrcNode, NULL);
		m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
		m_pDstNode = pNewDstNode;
	}
	else
	{
		pNewSrcNode = m_pEditedGraph->GetNextNode(m_pSrcNode);
		m_pParentDialog->fn_vSelectNode(m_pEditedGraph, pNewSrcNode);
		m_pSrcNode = pNewSrcNode;
	}

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnPrevWPOK()
{
	WayPoint *pNewDstNode;
	
	UpdateData(TRUE);
	
	// apply modifs
	fn_vApplyModifications();
	// update state
	m_bSymetric = FALSE;

	// get previous connection
	pNewDstNode = m_pEditedGraph->GetPrevConnection(m_pSrcNode, m_pDstNode);
	m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
	m_pDstNode = pNewDstNode;

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnPrevWPCancel()
{
	WayPoint *pNewDstNode;
	
	// update state
	m_bSymetric = FALSE;

	// get previous connection
	pNewDstNode = m_pEditedGraph->GetPrevConnection(m_pSrcNode, m_pDstNode);
	m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
	m_pDstNode = pNewDstNode;

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnNextWPOK()
{
	WayPoint *pNewDstNode;
	
	UpdateData(TRUE);
	
	// apply modifs
	fn_vApplyModifications();
	// update state
	m_bSymetric = FALSE;

	// get next connection
	pNewDstNode = m_pEditedGraph->GetNextConnection(m_pSrcNode, m_pDstNode);
	m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
	m_pDstNode = pNewDstNode;

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnNextWPCancel()
{
	WayPoint *pNewDstNode;

	// update state
	m_bSymetric = FALSE;

	// get next connection
	pNewDstNode = m_pEditedGraph->GetNextConnection(m_pSrcNode, m_pDstNode);
	m_pParentDialog->fn_vSelectConnection(m_pEditedGraph, m_pSrcNode, pNewDstNode);
	m_pDstNode = pNewDstNode;

	// init values of controls
	fn_vUpdateButtons();
	fn_vInitParameters();
}

//****************************************************************************
void NtwParameterDialog::OnOK() 
{
	UpdateData(TRUE);

	// apply modifs
	fn_vApplyModifications();
	
	EndDialog(IDOK);
}

//****************************************************************************
void NtwParameterDialog::OnSymetric() 
{
	m_bSymetric = TRUE;
}

//****************************************************************************
void NtwParameterDialog::fn_vInitParameters (void)
{
	long	lCapacity, lType;
	long	lWeight;
	int		iCapa, iType, iMask;
	char	szWeight[10];
	
	// init for mode
	if (!m_bEditConnection)
	{
		// init capacity
		lType = m_pEditedGraph->GetNodeType(m_pSrcNode);
		for (iType = 0, iMask = 1; iType < 32; iType++, iMask <<= 1)
			((CButton*)GetDlgItem(IDC_CAPACITY1 + iType))->SetCheck((lType & iMask) ? 1 : 0);

		// init node text
		m_cStaticNode.SetWindowText(m_pSrcNode->GetName());

	}
	else if (!m_bAll)
	{
		// init node text
		m_cStaticNode.SetWindowText(m_pSrcNode->GetName());

		if (m_pDstNode)
		{
			// update state
			for (iCapa = 0; iCapa < 32; iCapa++)
				GetDlgItem(IDC_CAPACITY1 + iCapa)->EnableWindow(TRUE);
			m_cEditWeight.EnableWindow(TRUE);
			m_cDefaultWeight.EnableWindow(TRUE);
			m_cSymetric.EnableWindow(TRUE);
			// init capacity
			lCapacity = m_pEditedGraph->GetConnectionCapacity(m_pSrcNode, m_pDstNode);
			for (iCapa = 0, iMask = 1; iCapa < 32; iCapa++, iMask <<= 1)
				((CButton*)GetDlgItem(IDC_CAPACITY1 + iCapa))->SetCheck((lCapacity & iMask) ? 1 : 0);
			// init weight
			lWeight = m_pEditedGraph->GetConnectionWeight(m_pSrcNode, m_pDstNode);
			sprintf(szWeight, "%ld", lWeight);
			m_cEditWeight.SetWindowText(szWeight);
			// init link text
			m_cStaticLink.SetWindowText(m_pDstNode->GetName());
		}
		else
		{
			// update state
			for (iCapa = 0; iCapa < 32; iCapa++)
				GetDlgItem(IDC_CAPACITY1 + iCapa)->EnableWindow(FALSE);
			m_cEditWeight.EnableWindow(FALSE);
			m_cDefaultWeight.EnableWindow(FALSE);
			m_cSymetric.EnableWindow(FALSE);
			// init link text
			m_cStaticLink.SetWindowText("");
		}
	}
	else
	{
		for (iCapa = 0; iCapa < 32; iCapa++)
			((CButton*)GetDlgItem(IDC_CAPACITY1 + iCapa))->SetCheck(FALSE);
	}
}


//****************************************************************************
void NtwParameterDialog::fn_vApplyModifications ()
{
	long	lCapacity, lType;
	long	lWeight;
	int		iCapa, iType, iMask;
	char	szWeight[10];
	
	// connection edition
	if (!m_bEditConnection)
	{
		// get type
		for (iType = 0, iMask = 1, lType = 0; iType < 32; iType++, iMask <<= 1)
		{
			if (((CButton*)GetDlgItem(IDC_CAPACITY1 + iType))->GetCheck() == 1)
				lType |= iMask;
		}
		// set node type
		m_pEditedGraph->SetNodeType(m_pSrcNode, lType);
	}
	// node edition
	else if (!m_bAll)
	{
		if (!m_pDstNode)
			return;
		
		// symetric : create connection if necessary
		if (m_bSymetric)
		{
			if (m_pEditedGraph->GetGraphicConnection(m_pDstNode, m_pSrcNode) == NULL)
				m_pEditedGraph->fn_vAddArcToNode(m_pDstNode, m_pSrcNode, FALSE, FALSE);
		}

		// get capacity
		for (iCapa = 0, iMask = 1, lCapacity = 0; iCapa < 32; iCapa++, iMask <<= 1)
		{
			if (((CButton*)GetDlgItem(IDC_CAPACITY1 + iCapa))->GetCheck() == 1)
				lCapacity |= iMask;
		}
		// set connection capacity
		m_pEditedGraph->SetConnectionCapacity(m_pSrcNode, m_pDstNode, lCapacity);
		if (m_bSymetric || Graph::GetInterface()->fn_bGetSymetricMode())
			m_pEditedGraph->SetConnectionCapacity(m_pDstNode, m_pSrcNode, lCapacity);

		// get weight
		m_cEditWeight.GetWindowText(szWeight, 10);
		lWeight = atol(szWeight);
		m_pEditedGraph->SetConnectionWeight(m_pSrcNode, m_pDstNode, lWeight);
		if (m_bSymetric || Graph::GetInterface()->fn_bGetSymetricMode())
			m_pEditedGraph->SetConnectionWeight(m_pDstNode, m_pSrcNode, lWeight);
	}
	// edit all capacities
	else
	{
		// get capacity
		for (iCapa = 0, iMask = 1, lCapacity = 0; iCapa < 32; iCapa++, iMask <<= 1)
		{
			if (((CButton*)GetDlgItem(IDC_CAPACITY1 + iCapa))->GetCheck() == 1)
				lCapacity |= iMask;
		}
		// set capacity for all arcs
		m_pEditedGraph->fn_vSetAllArcsCapacity(lCapacity);
	}
}

void NtwParameterDialog::fn_vUpdateButtons (void)
{
	// select next connection or node
	if (!m_bEditConnection)
	{
		m_cNextOK.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevOK.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
		m_cNextCancel.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevCancel.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);

		m_cNextWPOK.EnableWindow(FALSE);
		m_cPrevWPOK.EnableWindow(FALSE);
		m_cNextWPCancel.EnableWindow(FALSE);
		m_cPrevWPCancel.EnableWindow(FALSE);
	}
	else if (!m_bAll)
	{
		m_cNextWPOK.EnableWindow(m_pEditedGraph->GetNextConnection(m_pSrcNode, m_pDstNode) != NULL);
		m_cPrevWPOK.EnableWindow(m_pEditedGraph->GetPrevConnection(m_pSrcNode, m_pDstNode) != NULL);
		m_cNextWPCancel.EnableWindow(m_pEditedGraph->GetNextConnection(m_pSrcNode, m_pDstNode) != NULL);
		m_cPrevWPCancel.EnableWindow(m_pEditedGraph->GetPrevConnection(m_pSrcNode, m_pDstNode) != NULL);

		m_cNextOK.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevOK.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
		m_cNextCancel.EnableWindow(m_pEditedGraph->GetNextNode(m_pSrcNode) != NULL);
		m_cPrevCancel.EnableWindow(m_pEditedGraph->GetPrevNode(m_pSrcNode) != NULL);
	}
	else
	{
		m_cNextOK.EnableWindow(FALSE);
		m_cPrevOK.EnableWindow(FALSE);
		m_cNextCancel.EnableWindow(FALSE);
		m_cPrevCancel.EnableWindow(FALSE);

		m_cNextWPOK.EnableWindow(FALSE);
		m_cPrevWPOK.EnableWindow(FALSE);
		m_cNextWPCancel.EnableWindow(FALSE);
		m_cPrevWPCancel.EnableWindow(FALSE);
	}
}
//End Shaitan NewParam }
