// rotdia.cpp : implementation file
//
//ANNECY Shaitan Nettoyage (12/05/98) {
/*

#include "stdafx.h"
#include "acp_base.h"
#include "resource.h"
#include "rotdia.hpp"

#include "incitf.h"
#include "incgam.h"
#include "incai.h"
#include "WPObj.hpp"
#include "WayObj.hpp"
#include "LinkObj.hpp"
#include "WPDia.hpp"
#include "WayDia.hpp"
#include "Inter.hpp"
#include "x:\cpa\main\inc\_editid.h"

#include "tut.h"


/////////////////////////////////////////////////////////////////////////////
// RotationDia

IMPLEMENT_DYNCREATE(RotationDia, CFormView)

RotationDia::RotationDia()
	: CFormView(RotationDia::IDD)
{
	//{{AFX_DATA_INIT(RotationDia)
	m_fTwist1 = 0.0f;
	m_fTwist2 = 0.0f;
	m_lTwistLap = 0;
	m_lxLap = 0;
	m_lyLap = 0;
	//}}AFX_DATA_INIT

	m_poLink = NULL;
	m_bFocusTwist1 = FALSE;
	m_bFocusTwist2 = FALSE;
	m_bFocusTwistLap = FALSE;
	m_bFocusXLap = FALSE;
	m_bFocusYLap = FALSE;
}

RotationDia::~RotationDia()
{
}

void RotationDia::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(RotationDia)
	DDX_Text(pDX, IDC_TWIST1_EDIT, m_fTwist1);
	DDV_MinMaxFloat(pDX, m_fTwist1, 0.f, 360.f);
	DDX_Text(pDX, IDC_TWIST2_EDIT, m_fTwist2);
	DDV_MinMaxFloat(pDX, m_fTwist2, 0.f, 360.f);
	DDX_Text(pDX, IDC_ORIENT_LAP_TWIST_EDIT, m_lTwistLap);
	DDX_Text(pDX, IDC_ORIENT_LAP_X_EDIT, m_lxLap);
	DDX_Text(pDX, IDC_ORIENT_LAP_Y_EDIT, m_lyLap);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(RotationDia, CFormView)
	//{{AFX_MSG_MAP(RotationDia)
	ON_EN_KILLFOCUS(IDC_ORIENT_LAP_TWIST_EDIT, OnKillfocusOrientLapTwistEdit)
	ON_EN_KILLFOCUS(IDC_ORIENT_LAP_X_EDIT, OnKillfocusOrientLapXEdit)
	ON_EN_KILLFOCUS(IDC_ORIENT_LAP_Y_EDIT, OnKillfocusOrientLapYEdit)
	ON_BN_CLICKED(IDC_ORIENT_TWIST_DIRECT_RADIO, OnOrientTwistDirectRadio)
	ON_BN_CLICKED(IDC_ORIENT_TWIST_INDIRECT_RADIO, OnOrientTwistIndirectRadio)
	ON_BN_CLICKED(IDC_ORIENT_X_DIRECT_RADIO, OnOrientXDirectRadio)
	ON_BN_CLICKED(IDC_ORIENT_X_INDIRECT_RADIO, OnOrientXIndirectRadio)
	ON_BN_CLICKED(IDC_ORIENT_Y_DIRECT_RADIO, OnOrientYDirectRadio)
	ON_BN_CLICKED(IDC_ORIENT_Y_INDIRECT_RADIO, OnOrientYIndirectRadio)
	ON_EN_KILLFOCUS(IDC_TWIST1_EDIT, OnKillfocusTwist1Edit)
	ON_EN_KILLFOCUS(IDC_TWIST2_EDIT, OnKillfocusTwist2Edit)
	ON_EN_SETFOCUS(IDC_ORIENT_LAP_TWIST_EDIT, OnSetfocusOrientLapTwistEdit)
	ON_EN_SETFOCUS(IDC_ORIENT_LAP_X_EDIT, OnSetfocusOrientLapXEdit)
	ON_EN_SETFOCUS(IDC_ORIENT_LAP_Y_EDIT, OnSetfocusOrientLapYEdit)
	ON_EN_SETFOCUS(IDC_TWIST1_EDIT, OnSetfocusTwist1Edit)
	ON_EN_SETFOCUS(IDC_TWIST2_EDIT, OnSetfocusTwist2Edit)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// RotationDia message handlers

void RotationDia::fn_vInitDialog ( void )
{
	fn_vActivateWindow (FALSE);
	GetParent()->SetWindowText ( "no orientation to edit" );
}

void RotationDia::fn_vEdit (Link* poLink)
{
	BOOL bRedraw=FALSE;
	
	if (!m_poLink && poLink) 
	{
		fn_vActivateWindow (TRUE);
		GetParent()->SetWindowText ( "Orientation" );
		bRedraw=TRUE;
	}


	else if (m_poLink && !poLink) 
	{
		fn_vActivateWindow (FALSE);
		GetParent()->SetWindowText ( "no orientation to edit" );
		bRedraw=TRUE;
	}
	
	m_poLink = poLink;
	if (m_poLink)
	{
		CheckRadioButton( IDC_ORIENT_X_DIRECT_RADIO, IDC_ORIENT_X_INDIRECT_RADIO, m_poLink->fn_bIsXDirectOrientation() ?  IDC_ORIENT_X_DIRECT_RADIO :  IDC_ORIENT_X_INDIRECT_RADIO  );
		CheckRadioButton( IDC_ORIENT_Y_DIRECT_RADIO, IDC_ORIENT_Y_INDIRECT_RADIO, m_poLink->fn_bIsYDirectOrientation() ?  IDC_ORIENT_Y_DIRECT_RADIO :  IDC_ORIENT_Y_INDIRECT_RADIO  );
		CheckRadioButton( IDC_ORIENT_TWIST_DIRECT_RADIO, IDC_ORIENT_TWIST_INDIRECT_RADIO, m_poLink->fn_bIsZDirectOrientation() ?  IDC_ORIENT_TWIST_DIRECT_RADIO :  IDC_ORIENT_TWIST_INDIRECT_RADIO  );

		m_lxLap = m_poLink->fn_lGetNbLapXOrientation();
		m_lyLap = m_poLink->fn_lGetNbLapYOrientation();
		m_lTwistLap = m_poLink->fn_lGetNbLapZOrientation();
		m_fTwist1 = m_poLink->fn_xGetFirstTwistOrientation () * 180. / MTH_C_Pi;
		m_fTwist2 = m_poLink->fn_xGetSecondTwistOrientation () * 180. / MTH_C_Pi;
		m_fTwist1 = ((long) (m_fTwist1*10.f+0.5f))/10.f;
		m_fTwist2 = ((long) (m_fTwist2*10.f+0.5f))/10.f;
	}
	UpdateData (FALSE);	

	if (bRedraw) GetParent()->GetParent()->RedrawWindow (NULL, NULL, RDW_INVALIDATE|RDW_FRAME);
}

//--------------------------- On Command -> to capture end of edition in edit dialogs
BOOL RotationDia::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	if (wParam==1)
	{
		if (m_bFocusTwist1) 
		{
			OnKillfocusTwist1Edit();
			m_bFocusTwist1=TRUE;
		}
		if (m_bFocusTwist2) 
		{
			OnKillfocusTwist2Edit();
			m_bFocusTwist2=TRUE;
		}
		if (m_bFocusTwistLap)
		{
			OnKillfocusOrientLapTwistEdit();
			m_bFocusTwistLap=TRUE;
		}
		if (m_bFocusXLap)
		{
			OnKillfocusOrientLapXEdit();
			m_bFocusXLap=TRUE;
		}
		if (m_bFocusYLap)
		{
			OnKillfocusOrientLapYEdit();
			m_bFocusYLap=TRUE;
		}

		return TRUE;
	}


	return CFormView::OnCommand(wParam, lParam);
}



//--------------------------- Lap edition
void RotationDia::OnKillfocusOrientLapTwistEdit() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetNbLapZOrientation ( m_lTwistLap );
	m_bFocusTwistLap=FALSE;
}

void RotationDia::OnKillfocusOrientLapXEdit() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetNbLapXOrientation ( m_lxLap );
	m_bFocusXLap=FALSE;
}

void RotationDia::OnKillfocusOrientLapYEdit() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetNbLapYOrientation ( m_lyLap );
	m_bFocusYLap=FALSE;
}


//--------------------------- Direct/Indirect Orientation 
void RotationDia::OnOrientTwistDirectRadio() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetZDirectOrientation (TRUE);	
}

void RotationDia::OnOrientTwistIndirectRadio() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetZDirectOrientation (FALSE);	
}

void RotationDia::OnOrientXDirectRadio() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetXDirectOrientation (TRUE);	
}

void RotationDia::OnOrientXIndirectRadio() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetXDirectOrientation (FALSE);	
}

void RotationDia::OnOrientYDirectRadio() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetYDirectOrientation (TRUE);	
}

void RotationDia::OnOrientYIndirectRadio() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetYDirectOrientation (FALSE);	
}


//---------------------------- Twist edition
void RotationDia::OnKillfocusTwist1Edit() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetFirstTwistOrientation (m_fTwist1*MTH_C_Pi/180.f);
	m_bFocusTwist1=FALSE;
}

void RotationDia::OnKillfocusTwist2Edit() 
{
	UpdateData (TRUE);
	m_poLink->fn_vSetSecondTwistOrientation (m_fTwist2*MTH_C_Pi/180.f);
	m_bFocusTwist2=FALSE;
}


//---------------- Edit dialog have focus
void RotationDia::OnSetfocusOrientLapTwistEdit() 
{
	m_bFocusTwistLap=TRUE;
}

void RotationDia::OnSetfocusOrientLapXEdit() 
{
	m_bFocusXLap=TRUE;
}

void RotationDia::OnSetfocusOrientLapYEdit() 
{
	m_bFocusYLap=TRUE;	
}

void RotationDia::OnSetfocusTwist1Edit() 
{
	m_bFocusTwist1=TRUE;
}

void RotationDia::OnSetfocusTwist2Edit() 
{
	m_bFocusTwist2=TRUE;
}

void RotationDia::fn_vActivateWindow (BOOL bActivate)
{
	GetDlgItem (IDC_ORIENT_LAP_TWIST_EDIT)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_LAP_X_EDIT)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_LAP_Y_EDIT)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_TWIST_DIRECT_RADIO)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_TWIST_INDIRECT_RADIO)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_X_DIRECT_RADIO)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_X_INDIRECT_RADIO)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_Y_DIRECT_RADIO)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_Y_INDIRECT_RADIO)->EnableWindow (bActivate);
	GetDlgItem (IDC_TWIST1_EDIT)->EnableWindow (bActivate);
	GetDlgItem (IDC_TWIST2_EDIT)->EnableWindow (bActivate);
	GetDlgItem (IDC_LAP_X_STATIC)->EnableWindow (bActivate);
	GetDlgItem (IDC_LAP_Y_STATIC)->EnableWindow (bActivate);
	GetDlgItem (IDC_LAP_TWIST_STATIC)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_TWIST_STATIC)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_X_STATIC)->EnableWindow (bActivate);
	GetDlgItem (IDC_ORIENT_Y_STATIC)->EnableWindow (bActivate);
	GetDlgItem (IDC_TWIST_STATIC)->EnableWindow (bActivate);
}

BOOL RotationDia::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_RotationDialog" , TUT_e_Window);
	TUT_M_vRegisterControlID (IDC_ORIENT_LAP_TWIST_EDIT,"OWP_RotationTwistEdit",TUT_e_TextEdit);
	TUT_M_vRegisterControlID (IDC_ORIENT_LAP_X_EDIT,"OWP_RotationXLapEdit",TUT_e_TextEdit);
	TUT_M_vRegisterControlID (IDC_ORIENT_LAP_Y_EDIT,"OWP_RotationYLapEdit",TUT_e_TextEdit);
	TUT_M_vRegisterControlID (IDC_ORIENT_TWIST_DIRECT_RADIO,"OWP_RotationTwistDirect",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_ORIENT_TWIST_INDIRECT_RADIO,"OWP_RotationTwistIndirect",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_ORIENT_X_DIRECT_RADIO,"OWP_RotationXDirect",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_ORIENT_X_INDIRECT_RADIO,"OWP_RotationXIndirect",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_ORIENT_Y_DIRECT_RADIO,"OWP_RotationYDirect",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_ORIENT_Y_INDIRECT_RADIO,"OWP_RotationYIndirect",TUT_e_Button);
	TUT_M_vRegisterControlID (IDC_TWIST1_EDIT,"OWP_RotationTwist1Edit",TUT_e_TextEdit);
	TUT_M_vRegisterControlID (IDC_TWIST2_EDIT,"OWP_RotationTwist2Edit",TUT_e_TextEdit);

	return bCreate;
}

void RotationDia::OnDestroy() 
{
	CFormView::OnDestroy();
	TUT_M_vGetTutDll ();
	TUT_M_vUnregisterControl (m_hWnd);
	TUT_M_vUnregisterControlID (IDC_ORIENT_LAP_TWIST_EDIT);
	TUT_M_vUnregisterControlID (IDC_ORIENT_LAP_X_EDIT);
	TUT_M_vUnregisterControlID (IDC_ORIENT_LAP_Y_EDIT);
	TUT_M_vUnregisterControlID (IDC_ORIENT_TWIST_DIRECT_RADIO);
	TUT_M_vUnregisterControlID (IDC_ORIENT_TWIST_INDIRECT_RADIO);
	TUT_M_vUnregisterControlID (IDC_ORIENT_X_DIRECT_RADIO);
	TUT_M_vUnregisterControlID (IDC_ORIENT_X_INDIRECT_RADIO);
	TUT_M_vUnregisterControlID (IDC_ORIENT_Y_INDIRECT_RADIO);
	TUT_M_vUnregisterControlID (IDC_ORIENT_Y_INDIRECT_RADIO);
	TUT_M_vUnregisterControlID (IDC_TWIST1_EDIT);
	TUT_M_vUnregisterControlID (IDC_TWIST1_EDIT);
}
*/
//ENDANNECY Shaitan Nettoyage }
