// PortPropertiesDialog.cpp : implementation file
//

#include "stdafx.h"
#include "DiagramEng.h"
#include "PortPropertiesDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPortPropertiesDialog dialog


CPortPropertiesDialog::CPortPropertiesDialog(int sign_flag, CWnd* pParent /*=NULL*/)
//CPortPropertiesDialog::CPortPropertiesDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CPortPropertiesDialog::IDD, pParent)
{
	// Init.
	m_iSignFlag = sign_flag;

	//{{AFX_DATA_INIT(CPortPropertiesDialog)
	m_dPortPositionAngle = 0.0;
	m_iPortSignMultiplication = -1;
	m_iPortSignAddition = -1;
	m_iPortArrowDirection = -1;
	//}}AFX_DATA_INIT
}


void CPortPropertiesDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPortPropertiesDialog)
	DDX_Text(pDX, ID_PORT_PROPS_DLG_ANGLE, m_dPortPositionAngle);
	DDX_Radio(pDX, ID_PORT_PROPS_DLG_RB_MULT, m_iPortSignMultiplication);
	DDX_Radio(pDX, ID_PORT_PROPS_DLG_RB_ADD, m_iPortSignAddition);
	DDX_Radio(pDX, ID_PORT_PROPS_DLG_RB_LEFT, m_iPortArrowDirection);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPortPropertiesDialog, CDialog)
	//{{AFX_MSG_MAP(CPortPropertiesDialog)
	ON_BN_CLICKED(ID_PORT_PROPS_DLG_BTN_OK, OnPortPropertiesDlgBtnOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPortPropertiesDialog message handlers

void CPortPropertiesDialog::OnPortPropertiesDlgBtnOk() 
{
	// TODO: Add your control notification handler code here
	
	// DiagramEng (start)

	//AfxMessageBox("\n CPortPropertiesDialog::OnPortPropertiesDlgBtnOk()\n", MB_OK, 0);

	// Update variable values with the Dlg Wnd control values
	UpdateData(TRUE);

	// Close the dialog wnd with OnOK()
	OnOK();

	// DiagramEng (end)
}

BOOL CPortPropertiesDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	// DiagramEng (start)
	if(m_iSignFlag == 0)
	{
		// Disable all sign-based controls
		GetDlgItem(ID_PORT_PROPS_DLG_GB_SIGN)->EnableWindow(FALSE);		// sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_GB_MULT)->EnableWindow(FALSE);		// mult/divide sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_MULT)->EnableWindow(FALSE);		// mult sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_DIVIDE)->EnableWindow(FALSE);	// divide sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_GB_ADD)->EnableWindow(FALSE);		// add/subtract sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_ADD)->EnableWindow(FALSE);		// add sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_SUBTRACT)->EnableWindow(FALSE);	// subtract sign radio button
	}
	else if(m_iSignFlag == 1)
	{
		// Enable all Multiplication sign-based controls
		GetDlgItem(ID_PORT_PROPS_DLG_GB_SIGN)->EnableWindow(TRUE);		// sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_GB_MULT)->EnableWindow(TRUE);		// mult/divide sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_MULT)->EnableWindow(TRUE);		// mult sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_DIVIDE)->EnableWindow(TRUE);	// divide sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_GB_ADD)->EnableWindow(FALSE);		// add/subtract sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_ADD)->EnableWindow(FALSE);		// add sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_SUBTRACT)->EnableWindow(FALSE);	// subtract sign radio button
	}
	else if(m_iSignFlag == 2)
	{
		// Enable all Addition sign-based controls
		GetDlgItem(ID_PORT_PROPS_DLG_GB_SIGN)->EnableWindow(TRUE);		// sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_GB_MULT)->EnableWindow(FALSE);		// mult/divide sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_MULT)->EnableWindow(FALSE);		// mult sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_DIVIDE)->EnableWindow(FALSE);	// divide sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_GB_ADD)->EnableWindow(TRUE);		// add/subtract sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_ADD)->EnableWindow(TRUE);		// add sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_SUBTRACT)->EnableWindow(TRUE);	// subtract sign radio button
	}
	else if(m_iSignFlag == 3)
	{
		// Enable all sign-based controls
		GetDlgItem(ID_PORT_PROPS_DLG_GB_SIGN)->EnableWindow(TRUE);		// sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_GB_MULT)->EnableWindow(TRUE);		// mult/divide sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_MULT)->EnableWindow(TRUE);		// mult sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_DIVIDE)->EnableWindow(TRUE);	// divide sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_GB_ADD)->EnableWindow(TRUE);		// add/subtract sign group box	
		GetDlgItem(ID_PORT_PROPS_DLG_RB_ADD)->EnableWindow(TRUE);		// add sign radio button
		GetDlgItem(ID_PORT_PROPS_DLG_RB_SUBTRACT)->EnableWindow(TRUE);	// subtract sign radio button
	}

	// DiagramEng (end)
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
