reman3/Rayman_X/cpa/tempgrp/OCA/src/pagegeneral.cpp

447 lines
14 KiB
C++

// pagegeneral.cpp : implementation file
//
#include "stdafx.h"
#include "acp_base.h"
#include "camresrc.h"
#include "pagegeneral.hpp"
#include "caminter.hpp"
#include "camera.hpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define M_GetDLL(Camera) ((Camera_Interface*)((Camera)->GetEditor()))
#define C_PI (float)3.14159265
/////////////////////////////////////////////////////////////////////////////
// PageGeneral dialog
PageGeneral::PageGeneral(Camera *p_oCamera)
: PageBase(PageGeneral::IDD)
{
//{{AFX_DATA_INIT(PageGeneral)
m_iTranslationAxis = -1;
m_iRotationAxis = -1;
m_csRotationValue = _T("");
m_csTranslationValue = _T("");
m_iTranslationStep = -1;
m_iRotationStep = -1;
m_bPrivilegeMode = FALSE;
//}}AFX_DATA_INIT
m_lIDofCurrentEdit = NULL;
m_p_oCamera = p_oCamera;
}
void PageGeneral::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(PageGeneral)
DDX_Radio(pDX, IDC_RB_TRANSAXISCAMERA, m_iTranslationAxis);
DDX_Radio(pDX, IDC_RB_ROTAXISCAMERA, m_iRotationAxis);
DDX_Text(pDX, IDC_EDIT_ROTVALUE, m_csRotationValue);
DDX_Text(pDX, IDC_EDIT_TRANSVALUE, m_csTranslationValue);
DDX_Radio(pDX, IDC_RB_10CM, m_iTranslationStep);
DDX_Radio(pDX, IDC_RB_PION4, m_iRotationStep);
DDX_Check(pDX, IDC_CHK_PRIVILEGEMODE, m_bPrivilegeMode);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(PageGeneral, CDialog)
//{{AFX_MSG_MAP(PageGeneral)
ON_EN_SETFOCUS(IDC_EDIT_ROTVALUE, OnSetfocusEditRotvalue)
ON_EN_KILLFOCUS(IDC_EDIT_ROTVALUE, OnKillfocusEditRotvalue)
ON_EN_KILLFOCUS(IDC_EDIT_TRANSVALUE, OnKillfocusEditTransvalue)
ON_EN_SETFOCUS(IDC_EDIT_TRANSVALUE, OnSetfocusEditTransvalue)
ON_BN_CLICKED(IDC_BT_RETURN, OnBtReturn)
ON_BN_CLICKED(IDC_RB_10CM, OnRbTranslationStep)
ON_BN_CLICKED(IDC_RB_PION4, OnRbRotationStep)
ON_BN_CLICKED(IDC_RB_10M, OnRbTranslationStep)
ON_BN_CLICKED(IDC_RB_1M, OnRbTranslationStep)
ON_BN_CLICKED(IDC_RB_50CM, OnRbTranslationStep)
ON_BN_CLICKED(IDC_RB_PION8, OnRbRotationStep)
ON_BN_CLICKED(IDC_RB_PION16, OnRbRotationStep)
ON_BN_CLICKED(IDC_RB_PION32, OnRbRotationStep)
ON_BN_CLICKED(IDC_CHK_PRIVILEGEMODE, OnChkPrivilegemode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// PageGeneral message handlers
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL PageGeneral::OnInitDialog()
{
float fTransValue;
float fRotValue;
CDialog::OnInitDialog();
// get the current translation and rotation step
fTransValue = M_GetDLL(m_p_oCamera)->GetTranslationStep();
fRotValue = M_GetDLL(m_p_oCamera)->GetRotationStep() * 180 / C_PI;
// init the edit dialog values (and update the radiobuttons)
VERIFY(UpdateTransRadioButtons(fTransValue));
VERIFY(UpdateRotRadioButtons(fRotValue));
// init the translation and rotation axis
if (m_p_oCamera->GetRotationAxisSystem() == CameraCoordinates)
m_iRotationAxis = 0; //camera
else
m_iRotationAxis = 1; //world
if (m_p_oCamera->GetTranslationAxisSystem() == CameraCoordinates)
m_iTranslationAxis = 0; //camera
else
m_iTranslationAxis = 1; //world
if (m_p_oCamera->IsInPrivilegeMode())
{
m_iRotationAxis = 0;
m_iTranslationAxis = 0;
m_bPrivilegeMode = TRUE;
GetDlgItem(IDC_RB_ROTAXISCAMERA)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_ROTAXISWORLD)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_TRANSAXISCAMERA)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_TRANSAXISWORLD)->EnableWindow(FALSE);
}
else
m_bPrivilegeMode = FALSE;
// update drawing
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnKillfocusEditTransvalue()
{
CString csOldValue;
// translate old value into float and save it
csOldValue = m_csTranslationValue;
// get the new text value
UpdateData(TRUE);
// update radio buttons
if (UpdateTransRadioButtons() == FALSE)
{
// value is not good, put back the old one
m_csTranslationValue = csOldValue;
UpdateData(FALSE);
// and give back the focus to the window
GetDlgItem(IDC_EDIT_TRANSVALUE)->SetFocus();
}
else
{
// update drawing
UpdateData(FALSE);
m_lIDofCurrentEdit = NULL;
}
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnSetfocusEditTransvalue()
{
m_lIDofCurrentEdit = IDC_EDIT_TRANSVALUE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnKillfocusEditRotvalue()
{
CString csOldValue;
// translate old value into float and save it
csOldValue = m_csRotationValue;
// get the new text value
UpdateData(TRUE);
// update radio buttons
if (UpdateRotRadioButtons() == FALSE)
{
// value is not good, put back the old one
m_csRotationValue = csOldValue;
UpdateData(FALSE);
// and give back the focus to the window
GetDlgItem(IDC_EDIT_ROTVALUE)->SetFocus();
}
else
{
// update drawing
UpdateData(FALSE);
m_lIDofCurrentEdit = NULL;
}
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnSetfocusEditRotvalue()
{
m_lIDofCurrentEdit = IDC_EDIT_ROTVALUE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnRbTranslationStep()
{
// get the new button value
UpdateData(TRUE);
// update the control value
UpdateTransText();
// update drawing of dialog
UpdateData(FALSE);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnRbRotationStep()
{
// get the new button value
UpdateData(TRUE);
// update the control value
UpdateRotText();
// update drawing of dialog
UpdateData(FALSE);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
// update translation value text control according to selected radio button
void PageGeneral::UpdateTransText()
{
switch(m_iTranslationStep)
{
case 0:
m_csTranslationValue.Format("%.3f",0.1);
break;
case 1:
m_csTranslationValue.Format("%.3f",1.0);
break;
case 2:
m_csTranslationValue.Format("%.3f",10.0);
break;
case 3:
m_csTranslationValue.Format("%.3f",100.0);
break;
default:
m_csTranslationValue = "";
break;
}
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
// update rotation value text control according to selected radio button
void PageGeneral::UpdateRotText()
{
switch(m_iRotationStep)
{
case 0:
m_csRotationValue.Format("%.3f",180.0/4.0);
break;
case 1:
m_csRotationValue.Format("%.3f",180.0/8.0);
break;
case 2:
m_csRotationValue.Format("%.3f",180.0/16.0);
break;
case 3:
m_csRotationValue.Format("%.3f",180.0/32.0);
break;
default:
m_csRotationValue = "";
break;
}
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
// update rotation radio buttons according to parameter.
BOOL PageGeneral::UpdateRotRadioButtons(float fRotValue)
{
if (fRotValue != -1)
{
// a value was given, take it
if (fRotValue <= 0) return FALSE;
m_csRotationValue.Format("%.3f",fRotValue);
}
else
{
// no initial value given, take the current one
fRotValue = (float) atof(m_csRotationValue);
if (fRotValue <= 0) return FALSE;
}
if (fabs(fRotValue - 45) < 1e-5)
m_iRotationStep = 0;
else if (fabs(fRotValue - 22.5) < 1e-5)
m_iRotationStep = 1;
else if (fabs(fRotValue - 11.25) < 1e-5)
m_iRotationStep = 2;
else if (fabs(fRotValue - 5.625) < 1e-5)
m_iRotationStep = 3;
else
m_iRotationStep = -1;
return TRUE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
// update translation radio buttons according to parameter.
BOOL PageGeneral::UpdateTransRadioButtons(float fTransValue)
{
if (fTransValue != -1)
{
// a value was given, take it
if (fTransValue <= 0) return FALSE;
m_csTranslationValue.Format("%.3f",fTransValue);
}
else
{
// no initial value given, take the current one
fTransValue = (float) atof(m_csTranslationValue);
if (fTransValue <= 0) return FALSE;
}
if (fabs(fTransValue - 10) < 1e-5)
m_iTranslationStep = 2;
else if (fabs(fTransValue - 0.1) < 1e-5)
m_iTranslationStep = 0;
else if (fabs(fTransValue - 1.0) < 1e-5)
m_iTranslationStep = 1;
else if (fabs(fTransValue - 100) < 1e-5)
m_iTranslationStep = 3;
else
m_iTranslationStep = -1;
return TRUE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::MakeChangesAvailable()
{
UpdateData(TRUE);
m_eRotationAxis = (m_iRotationAxis == 0) ? CameraCoordinates : WorldCoordinates;
m_eTranslationAxis = (m_iTranslationAxis == 0) ? CameraCoordinates : WorldCoordinates;
m_fRotValue = (float) (atof(m_csRotationValue) * C_PI / 180.0);
m_fTransValue = (float) atof(m_csTranslationValue);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL PageGeneral::IsPageValid()
{
// check translation value
if (((float) atof(m_csTranslationValue)) <= 0)
return FALSE;
// check rotation value
if (((float) atof(m_csRotationValue)) <= 0)
return FALSE;
// check both radiobuttons
if (m_iTranslationAxis == -1)
return FALSE;
if (m_iRotationAxis == -1)
return FALSE;
return TRUE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::DoUpdate()
{
m_p_oCamera->SetRotationAxisSystem(m_eRotationAxis);
m_p_oCamera->SetTranslationAxisSystem(m_eTranslationAxis);
M_GetDLL(m_p_oCamera)->SetRotationStep(m_fRotValue);
M_GetDLL(m_p_oCamera)->SetTranslationStep(m_fTransValue);
m_p_oCamera->SetPrivilegeMode(m_bPrivilegeMode);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnBtReturn()
{
// if an edit had the focus, put the focus on the hidden button
// to be sure to call the killfocus function for the dialog
if (m_lIDofCurrentEdit != NULL)
{
GetDlgItem(IDC_BT_RETURN)->SetFocus();
return;
}
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void PageGeneral::OnChkPrivilegemode()
{
UpdateData(TRUE);
if (m_bPrivilegeMode)
{
m_iRotationAxis = 0;
m_iTranslationAxis = 0;
GetDlgItem(IDC_RB_ROTAXISCAMERA)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_ROTAXISWORLD)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_TRANSAXISCAMERA)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_TRANSAXISWORLD)->EnableWindow(FALSE);
}
else
{
GetDlgItem(IDC_RB_ROTAXISCAMERA)->EnableWindow(TRUE);
GetDlgItem(IDC_RB_ROTAXISWORLD)->EnableWindow(TRUE);
GetDlgItem(IDC_RB_TRANSAXISCAMERA)->EnableWindow(TRUE);
GetDlgItem(IDC_RB_TRANSAXISWORLD)->EnableWindow(TRUE);
}
UpdateData(FALSE);
}