/*
///////////////////////////////////////////////////////////////////////////////////////////////////
// Description : LinkDia.cpp
//   
// Dialog edition the ways
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// 
//					
///////////////////////////////////////////////////////////////////////////////////////////////////
// Creation date: 21 jan 1997                        Author: J Thénoz
///////////////////////////////////////////////////////////////////////////////////////////////////
// Modification date:			                      Author: 
// 
//
// 
//
///////////////////////////////////////////////////////////////////////////////////////////////////
*/

//ANNECY Shaitan Nettoyage (12/05/98) {
/*

#include "stdafx.h"
#include "acp_base.h"
#include "resource.h"
#include "incitf.h"
#include "incgam.h"
#include "incai.h"
#include "incGli.h"
#include "WpObj.hpp"
#include "WayObj.hpp"
#include "LinkObj.hpp"
#include "LinkDia.hpp"
#include "LkBezDia.h"
#include "x:/cpa/main/inc/_EditId.h"
#include "tut.h"



/////////////////////////////////////////////////////////////////////////////
// DiaLink

IMPLEMENT_DYNCREATE(DiaLink, CFormView)

DiaLink::DiaLink()
	: CFormView(DiaLink::IDD)
{
	//{{AFX_DATA_INIT(DiaLink)
	m_szLinkName = _T("");
	m_oSpeedMode = _T("");
	m_fSpeed1 = 0.0f;
	m_fSpeed2 = 0.0f;
	m_fSpeed3 = 0.0f;
	//}}AFX_DATA_INIT
	m_poLink = NULL;
	m_pSpecificDialog = NULL;
}

DiaLink::~DiaLink()
{
}

void DiaLink::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DiaLink)
	DDX_CBString(pDX, IDC_LINK_COMBO, m_szLinkName);
	DDV_MaxChars(pDX, m_szLinkName, 15);
	DDX_CBString(pDX, IDC_LINK_SPEED_COMBO, m_oSpeedMode);
	DDV_MaxChars(pDX, m_oSpeedMode, 15);
	DDX_Text(pDX, IDC_LINK_SPEED1_EDIT, m_fSpeed1);
	DDV_MinMaxFloat(pDX, m_fSpeed1, 0.f, 9999.99f);
	DDX_Text(pDX, IDC_LINK_SPEED2_EDIT, m_fSpeed2);
	DDV_MinMaxFloat(pDX, m_fSpeed2, 0.f, 9999.99f);
	DDX_Text(pDX, IDC_LINK_SPEED3_EDIT, m_fSpeed3);
	DDV_MinMaxFloat(pDX, m_fSpeed3, 0.f, 9999.99f);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DiaLink, CFormView)
	//{{AFX_MSG_MAP(DiaLink)
	ON_CBN_SELCHANGE(IDC_LINK_COMBO, OnSelchangeLinkCombo)
	ON_CBN_SELCHANGE(IDC_LINK_SPEED_COMBO, OnSelchangeLinkSpeedCombo)
	ON_EN_KILLFOCUS(IDC_LINK_SPEED1_EDIT, OnKillfocusLinkSpeed1Edit)
	ON_EN_KILLFOCUS(IDC_LINK_SPEED2_EDIT, OnKillfocusLinkSpeed2Edit)
	ON_EN_KILLFOCUS(IDC_LINK_SPEED3_EDIT, OnKillfocusLinkSpeed3Edit)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


void DiaLink::fn_vInitDialog (void)
{
	POSITION xPos;
	tdst_LinkObject* pstDefLink;
	
	CComboBox* pComboLink = (CComboBox*) GetDlgItem (IDC_LINK_COMBO);
	CComboBox* pComboSpeed = (CComboBox*) GetDlgItem (IDC_LINK_SPEED_COMBO);
	
	for ( pstDefLink=Link::fn_pGetListObject()->GetHeadElement(xPos); pstDefLink; pstDefLink=Link::fn_pGetListObject()->GetNextElement(xPos) )
		pComboLink->AddString (pstDefLink->szName);
	pComboLink->EnableWindow (FALSE);
	pComboSpeed->AddString ("none");
	pComboSpeed->AddString ("constant");
	pComboSpeed->AddString ("linear");
	pComboSpeed->AddString ("sinus");
	GetDlgItem (IDC_LINK_SPEED_GROUPBOX)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED_COMBO)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED1_STATIC)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED2_STATIC)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED3_STATIC)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED1_EDIT)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED2_EDIT)->EnableWindow (FALSE);
	GetDlgItem (IDC_LINK_SPEED3_EDIT)->EnableWindow (FALSE);
}

void DiaLink::fn_vEdit (Link* poLink)
{
	if (m_poLink==poLink) return;
	
	// Aspect of the dialog
	if (!m_poLink && poLink) 
	{
		GetDlgItem (IDC_LINK_COMBO)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED_GROUPBOX)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED_COMBO)->EnableWindow (TRUE);
	}
	else if (m_poLink && !poLink) 
	{
		GetDlgItem (IDC_LINK_COMBO)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED_GROUPBOX)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED_COMBO)->EnableWindow (FALSE);
	}
	
	if (m_poLink) m_poLink->fn_vStopEdit ();
	m_poLink=poLink;
	if (m_poLink) m_poLink->fn_vStartEdit ();
	
	if (m_poLink)
	{
		ACP_tdstDynaParam stDynParam;
		WP_fnv_Link_GetDynamicParameter ( (WP_tdhLink)(m_poLink->GetEngineStruct()), &stDynParam );

		unsigned char ucDynamicType;
		float dSpeed1, dSpeed2, dSpeed3;
		GetParent()->SetWindowText ( "" );
		m_szLinkName = m_poLink->fn_pGetName ();
	
		fn_vDynamicObject_GetParams( &stDynParam, &ucDynamicType, &dSpeed1, &dSpeed2, &dSpeed3);

		m_fSpeed1 = dSpeed1;
		m_fSpeed2 = dSpeed2;
		m_fSpeed3 = dSpeed3;
		
		switch (ucDynamicType)
		{
			case C_ucNone :		m_oSpeedMode = CString ("none");		break;
			case C_ucConst :	m_oSpeedMode = CString ("constant");	break;
			case C_ucLinear :	m_oSpeedMode = CString ("linear");		break;
			case C_ucSinus :	m_oSpeedMode = CString ("sinus");		break;
			default:			ucDynamicType=C_ucNone;
								m_oSpeedMode = CString ("none");
								break;
		}
		UpdateData (FALSE);
		fn_vDrawDynParamDialog ();
		fn_vChangeDialog ();
	}
	else
	{
		GetParent()->SetWindowText ( "no link to edit" );
		m_szLinkName = "";
		m_oSpeedMode = CString ("");
	
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED1_EDIT)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED2_EDIT)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED3_EDIT)->EnableWindow (FALSE);
		UpdateData (FALSE);
	}
	GetParent()->GetParent()->RedrawWindow (NULL, NULL, RDW_INVALIDATE|RDW_FRAME);
}



/////////////////////////////////////////////////////////////////////////////
// DiaLink diagnostics

#ifdef _DEBUG
void DiaLink::AssertValid() const
{
	CFormView::AssertValid();
}

void DiaLink::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// DiaLink message handlers

void DiaLink::OnSelchangeLinkCombo(void) 
{
	UpdateData (TRUE);
	Way* poParentWay = (Way*) (((CPA_SuperObject*)(m_poLink->GetSuperObject())->GetParent())->GetObject());
	Link* pNewLink = Link::CloneLink ( poParentWay, m_poLink, m_szLinkName );
	poParentWay->fn_bChangeLink ( m_poLink, pNewLink );
	m_poLink = pNewLink;
	fn_vChangeDialog ();
}

void DiaLink::fn_vChangeDialog (void)
{
	RECT stRect;
	GetDlgItem (IDC_DYNAMIC_DIALOG)->GetWindowRect( &stRect );
	ScreenToClient( &stRect ) ;
	
	if (m_pSpecificDialog)
	{
		m_poLink->fn_vFreeSpecificDialog (m_pSpecificDialog);
		delete m_pSpecificDialog;
	}
	m_pSpecificDialog = m_poLink->fn_pGetSpecificDialog (this);
	if (m_pSpecificDialog) m_pSpecificDialog->MoveWindow( &stRect, TRUE );
}


//--------------------------- Dynamic Param Edition
void DiaLink::fn_vSetDynParam (void)
{
	ACP_tdstDynaParam stDynParam;
	WP_fnv_Link_GetDynamicParameter ( (WP_tdhLink)(m_poLink->GetEngineStruct()), &stDynParam );

	WP_tde_ucConnectionDynamicType eConnectionType;
	unsigned char ucDynamicType;

	UpdateData (TRUE);

	if ( m_oSpeedMode=="none" )				{ ucDynamicType=C_ucNone; eConnectionType=WP_ConDynType_ucNone; }
	else if ( m_oSpeedMode=="constant" )	{ ucDynamicType=C_ucConst; eConnectionType=WP_ConDynType_ucConstant; }
	else if ( m_oSpeedMode=="linear" )		{ ucDynamicType=C_ucLinear; eConnectionType=WP_ConDynType_ucLinear; }
	else if ( m_oSpeedMode=="sinus" )		{ ucDynamicType=C_ucSinus; eConnectionType=WP_ConDynType_ucSinus; }

	fn_vDynamicObject_ChangeParams(	&stDynParam, ucDynamicType, m_fSpeed1, m_fSpeed2, m_fSpeed3);
	WP_fnv_Link_SetDynamicParameter ( (WP_tdhLink)(m_poLink->GetEngineStruct()), &stDynParam );
	
	WP_fnv_Link_SetConnectionDynamicType ( (WP_tdhLink)(m_poLink->GetEngineStruct()), eConnectionType );
	
	m_poLink->fn_vWayNotifySave ();
}


void DiaLink::fn_vDrawDynParamDialog (void)
{
	UpdateData (TRUE);
	
	if ( m_oSpeedMode=="none" )
	{
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED1_EDIT)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED2_EDIT)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED3_EDIT)->EnableWindow (FALSE);
	}

	else if ( m_oSpeedMode=="constant" )
	{
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->SetWindowText( "speed" );
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED1_EDIT)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED2_EDIT)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED3_EDIT)->EnableWindow (FALSE);
	}

	else if ( m_oSpeedMode=="linear" )
	{
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->SetWindowText( "start speed" );
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->SetWindowText( "end speed" );
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->SetWindowText( "" );
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->EnableWindow (FALSE);
		GetDlgItem (IDC_LINK_SPEED1_EDIT)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED2_EDIT)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED3_EDIT)->EnableWindow (FALSE);
	}

	else if ( m_oSpeedMode=="sinus" )
	{
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->SetWindowText( "start angle" );
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->SetWindowText( "end angle" );
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->SetWindowText( "max speed" );
		GetDlgItem (IDC_LINK_SPEED1_STATIC)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED2_STATIC)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED3_STATIC)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED1_EDIT)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED2_EDIT)->EnableWindow (TRUE);
		GetDlgItem (IDC_LINK_SPEED3_EDIT)->EnableWindow (TRUE);
	}


}


void DiaLink::OnSelchangeLinkSpeedCombo() 
{
	fn_vDrawDynParamDialog ();
	fn_vSetDynParam ();
}


void DiaLink::OnKillfocusLinkSpeed1Edit() 
{
	fn_vSetDynParam ();
}

void DiaLink::OnKillfocusLinkSpeed2Edit() 
{
	fn_vSetDynParam ();
}

void DiaLink::OnKillfocusLinkSpeed3Edit() 
{
	fn_vSetDynParam ();
}

BOOL DiaLink::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_LinkDialog" , TUT_e_Window);
	TUT_M_vRegisterControlID (IDC_LINK_COMBO,"OWP_LinkTypeCombo",TUT_e_ComboBox);
	TUT_M_vRegisterControlID (IDC_LINK_SPEED_COMBO,"OWP_LinkSpeedCombo",TUT_e_ComboBox);
	TUT_M_vRegisterControlID (IDC_LINK_SPEED1_EDIT,"OWP_LinkSpeed1Edit",TUT_e_TextEdit);
	TUT_M_vRegisterControlID (IDC_LINK_SPEED2_EDIT,"OWP_LinkSpeed2Edit",TUT_e_TextEdit);
	TUT_M_vRegisterControlID (IDC_LINK_SPEED3_EDIT,"OWP_LinkSpeed3Edit",TUT_e_TextEdit);

	return bCreate;
}


void DiaLink::OnDestroy() 
{
	TUT_M_vGetTutDll ();
	TUT_M_vUnregisterControl (m_hWnd);
	TUT_M_vUnregisterControlID (IDC_LINK_COMBO);
	TUT_M_vUnregisterControlID (IDC_LINK_SPEED_COMBO);
	TUT_M_vUnregisterControlID (IDC_LINK_SPEED1_EDIT);
	TUT_M_vUnregisterControlID (IDC_LINK_SPEED2_EDIT);
	TUT_M_vUnregisterControlID (IDC_LINK_SPEED3_EDIT);
}

*/
//ENDANNECY Shaitan Nettoyage }
