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

446 lines
15 KiB
C++

// propert.cpp : implementation file
//
#include "stdafx.h"
#include "acp_base.h"
#include "caminter.hpp"
#include "camera.hpp"
#include "propert.hpp"
#define M_GetDLL(Camera) ((Camera_Interface*)((Camera)->GetEditor()))
#define M_GetAxisCombo() ((CComboBox*)GetDlgItem(IDC_COMBO_AXIS))
#define C_PI (float)3.14159265
/////////////////////////////////////////////////////////////////////////////
// Properties dialog
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
Properties::Properties(Camera* p_oCamera, CWnd* pParent /*=NULL*/)
: CDialog(Properties::IDD, pParent)
{
//{{AFX_DATA_INIT(Properties)
m_iRotationAxis = -1;
m_iTranslationAxis = -1;
m_iRotationStep = -1;
m_csRotationValue = _T("");
m_csTranslationValue = _T("");
m_iTranslationStep = -1;
m_bPrivilegeMode = FALSE;
//}}AFX_DATA_INIT
m_p_oCamera = p_oCamera;
m_bWantToOpenMore = FALSE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Properties)
DDX_Radio(pDX, IDC_RB_ROTATIONAXIS, m_iRotationAxis);
DDX_Radio(pDX, IDC_RB_TRANSLATIONAXIS, m_iTranslationAxis);
DDX_Radio(pDX, IDC_RB_ROTATIONSTEP, m_iRotationStep);
DDX_Text(pDX, IDC_ROTVALUE, m_csRotationValue);
DDX_Text(pDX, IDC_TRANSVALUE, m_csTranslationValue);
DDX_Radio(pDX, IDC_RB_TRANSLATIONSTEP, m_iTranslationStep);
DDX_Check(pDX, IDC_CHK_PRIVILEGE, m_bPrivilegeMode);
//}}AFX_DATA_MAP
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BEGIN_MESSAGE_MAP(Properties, CDialog)
//{{AFX_MSG_MAP(Properties)
ON_EN_KILLFOCUS(IDC_TRANSVALUE, OnKillfocusTransvalue)
ON_EN_KILLFOCUS(IDC_ROTVALUE, OnKillfocusRotvalue)
ON_BN_CLICKED(IDC_RB_ROTATIONSTEP, OnRbRotationStep)
ON_BN_CLICKED(IDC_RB_TRANSLATIONSTEP, OnRbTranslationStep)
ON_BN_CLICKED(IDC_BT_MORE, OnBtMore)
ON_BN_CLICKED(IDC_10M, OnRbTranslationStep)
ON_BN_CLICKED(IDC_1M, OnRbTranslationStep)
ON_BN_CLICKED(IDC_50CM, OnRbTranslationStep)
ON_BN_CLICKED(IDC_PION16, OnRbRotationStep)
ON_BN_CLICKED(IDC_PION32, OnRbRotationStep)
ON_BN_CLICKED(IDC_PION8, OnRbRotationStep)
ON_BN_DOUBLECLICKED(IDC_10M, OnOK)
ON_BN_DOUBLECLICKED(IDC_1M, OnOK)
ON_BN_DOUBLECLICKED(IDC_50CM, OnOK)
ON_BN_DOUBLECLICKED(IDC_PION16, OnOK)
ON_BN_DOUBLECLICKED(IDC_PION32, OnOK)
ON_BN_DOUBLECLICKED(IDC_PION8, OnOK)
ON_BN_DOUBLECLICKED(IDC_RB_ROTATIONAXIS, OnOK)
ON_BN_DOUBLECLICKED(IDC_RB_ROTATIONSTEP, OnOK)
ON_BN_DOUBLECLICKED(IDC_RB_TRANSLATIONAXIS, OnOK)
ON_BN_DOUBLECLICKED(IDC_RB_TRANSLATIONSTEP, OnOK)
ON_BN_DOUBLECLICKED(IDC_ROTWORLD, OnOK)
ON_BN_DOUBLECLICKED(IDC_TRANSWORLD, OnOK)
ON_BN_CLICKED(IDC_CHK_PRIVILEGE, OnChkPrivilege)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Properties message handlers
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL Properties::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_RBUTTONDOWN)
{
OnOK();
return 1;
}
return CDialog::PreTranslateMessage(pMsg);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL Properties::OnInitDialog()
{
POINT stPoint;
float fTransValue;
float fRotValue;
tdeDisplayReferential eDisplayMode;
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_ROTATIONAXIS)->EnableWindow(FALSE);
GetDlgItem(IDC_ROTWORLD)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_TRANSLATIONAXIS)->EnableWindow(FALSE);
GetDlgItem(IDC_TRANSWORLD)->EnableWindow(FALSE);
}
else
m_bPrivilegeMode = FALSE;
// update drawing
UpdateData(FALSE);
eDisplayMode = M_GetDLL(m_p_oCamera) -> GetReferentialDisplayMode();
if( eDisplayMode == DisplayNone )
M_GetAxisCombo() -> SelectString(-1,"No");
else if( eDisplayMode == DisplayDownLeft )
M_GetAxisCombo() -> SelectString(-1,"Down Left");
else if( eDisplayMode == DisplayDownRight)
M_GetAxisCombo() -> SelectString(-1,"Down Right");
GetCursorPos(&stPoint);
SetWindowPos(&wndTop,stPoint.x,stPoint.y+10,40,100,SWP_NOSIZE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::OnKillfocusTransvalue()
{
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)
m_csTranslationValue = csOldValue;
// update drawing
UpdateData(FALSE);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::OnKillfocusRotvalue()
{
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)
m_csRotationValue = csOldValue;
// update drawing
UpdateData(FALSE);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::OnRbTranslationStep()
{
// get the new button value
UpdateData(TRUE);
// update the control value
UpdateTransText();
// update drawing of dialog
UpdateData(FALSE);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::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 Properties::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 Properties::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 Properties::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 Properties::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) < 1e-5)
m_iTranslationStep = 1;
else if (fabs(fTransValue - 100) < 1e-5)
m_iTranslationStep = 3;
else
m_iTranslationStep = -1;
return TRUE;
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::OnOK()
{
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);
if (m_fTransValue == 0.0)
m_fTransValue = 0.001;
// Axis Display
int iIndex = M_GetAxisCombo() -> GetCurSel();
if( iIndex != CB_ERR )
{
CString csText;
M_GetAxisCombo() -> GetLBText( iIndex, csText );
if( csText == "No" )
M_GetDLL(m_p_oCamera) -> SetReferentialDisplayMode( DisplayNone );
else if( csText == "Down Left" )
M_GetDLL(m_p_oCamera) -> SetReferentialDisplayMode( DisplayDownLeft );
else if( csText == "Down Right" )
M_GetDLL(m_p_oCamera) -> SetReferentialDisplayMode( DisplayDownRight );
}
CDialog::OnOK();
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::DoUpdate()
{
M_GetDLL(m_p_oCamera)->SetTranslationStep(m_fTransValue);
M_GetDLL(m_p_oCamera)->SetRotationStep(m_fRotValue);
m_p_oCamera->SetRotationAxisSystem(m_eRotationAxis);
m_p_oCamera->SetTranslationAxisSystem(m_eTranslationAxis);
m_p_oCamera->SetPrivilegeMode(m_bPrivilegeMode);
}
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Properties::OnBtMore()
{
m_bWantToOpenMore = TRUE;
OnOK();
}
void Properties::OnChkPrivilege()
{
UpdateData(TRUE);
if (m_bPrivilegeMode)
{
m_iRotationAxis = 0;
m_iTranslationAxis = 0;
GetDlgItem(IDC_RB_ROTATIONAXIS)->EnableWindow(FALSE);
GetDlgItem(IDC_ROTWORLD)->EnableWindow(FALSE);
GetDlgItem(IDC_RB_TRANSLATIONAXIS)->EnableWindow(FALSE);
GetDlgItem(IDC_TRANSWORLD)->EnableWindow(FALSE);
}
else
{
GetDlgItem(IDC_RB_ROTATIONAXIS)->EnableWindow(TRUE);
GetDlgItem(IDC_ROTWORLD)->EnableWindow(TRUE);
GetDlgItem(IDC_RB_TRANSLATIONAXIS)->EnableWindow(TRUE);
GetDlgItem(IDC_TRANSWORLD)->EnableWindow(TRUE);
}
UpdateData(FALSE);
// TODO: Add your control notification handler code here
}