// Dlg_Windows.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "Dlg_Windows.h"
#include "SAPP1Dlg.h"

// CDlg_Windows dialog

IMPLEMENT_DYNAMIC(CDlg_Windows, CDialog)
CDlg_Windows::CDlg_Windows(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_Windows::IDD, pParent)
	, str_editWinNArea(_T(""))
	, str_editWinNEArea(_T(""))
	, str_editWinEArea(_T(""))
	, str_editWinSEArea(_T(""))
	, str_editWinSArea(_T(""))
	, str_editWinSWArea(_T(""))
	, str_editWinWArea(_T(""))
	, str_editWinNWArea(_T(""))
	, str_editRooflightsArea(_T(""))
	, str_editWinNSolTran(_T(""))
	, str_editWinNESolTran(_T(""))
	, str_editWinESolTran(_T(""))
	, str_editWinSESolTran(_T(""))
	, str_editWinSSolTran(_T(""))
	, str_editWinSWSolTran(_T(""))
	, str_editWinWSolTran(_T(""))
	, str_editWinNWSolTran(_T(""))
	, str_editRooflightsSolTran(_T(""))
	, str_editWinNFrameFact(_T(""))
	, str_editWinNEFrameFact(_T(""))
	, str_editWinEFrameFact(_T(""))
	, str_editWinSEFrameFact(_T(""))
	, str_editWinSFrameFact(_T(""))
	, str_editWinSWFrameFact(_T(""))
	, str_editWinWFrameFact(_T(""))
	, str_editWinNWFrameFact(_T(""))
	, str_editRoofLightsFrameFact(_T(""))
	, str_comboOvershading(_T(""))
	, str_comboGlazing(_T(""))
	, str_editLEL(_T(""))
{
}

CDlg_Windows::~CDlg_Windows()
{
}

void CDlg_Windows::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, m_editWinNArea);
	DDX_Control(pDX, IDC_EDIT2, m_editWinNEArea);
	DDX_Control(pDX, IDC_EDIT3, m_editWinEArea);
	DDX_Control(pDX, IDC_EDIT4, m_editWinSEArea);
	DDX_Control(pDX, IDC_EDIT5, m_editWinSArea);
	DDX_Control(pDX, IDC_EDIT6, m_editWinSWArea);
	DDX_Control(pDX, IDC_EDIT7, m_editWinWArea);
	DDX_Control(pDX, IDC_EDIT8, m_editWinNWArea);
	DDX_Control(pDX, IDC_EDIT9, m_editRooflightsArea);
	DDX_Control(pDX, IDC_EDIT10, m_editWinNSolTran);
	DDX_Control(pDX, IDC_EDIT11, m_editWinNESolTran);
	DDX_Control(pDX, IDC_EDIT12, m_editWinESolTran);
	DDX_Control(pDX, IDC_EDIT13, m_editWinSESolTran);
	DDX_Control(pDX, IDC_EDIT14, m_editWinSSolTran);
	DDX_Control(pDX, IDC_EDIT15, m_editWinSWSolTran);
	DDX_Control(pDX, IDC_EDIT16, m_editWinWSolTran);
	DDX_Control(pDX, IDC_EDIT17, m_editWinNWSolTran);
	DDX_Control(pDX, IDC_EDIT18, m_editRooflightsSolTran);
	DDX_Control(pDX, IDC_EDIT19, m_editWinNFrameFact);
	DDX_Control(pDX, IDC_EDIT20, m_editWinNEFrameFact);
	DDX_Control(pDX, IDC_EDIT21, m_editWinEFrameFact);
	DDX_Control(pDX, IDC_EDIT22, m_editWinSEFrameFact);
	DDX_Control(pDX, IDC_EDIT23, m_editWinSWFrameFact);
	DDX_Control(pDX, IDC_EDIT25, m_editWinSFrameFact);
	DDX_Control(pDX, IDC_EDIT26, m_editWinWFrameFact);
	DDX_Control(pDX, IDC_EDIT27, m_editWinNWFrameFact);
	DDX_Control(pDX, IDC_EDIT28, m_editRoofLightsFrameFact);
	DDX_Control(pDX, IDC_COMBO1, m_comboOvershading);
	DDX_Control(pDX, IDC_COMBO2, m_comboGlazing);
	DDX_Text(pDX, IDC_EDIT1, str_editWinNArea);
	DDX_Text(pDX, IDC_EDIT2, str_editWinNEArea);
	DDX_Text(pDX, IDC_EDIT3, str_editWinEArea);
	DDX_Text(pDX, IDC_EDIT4, str_editWinSEArea);
	DDX_Text(pDX, IDC_EDIT5, str_editWinSArea);
	DDX_Text(pDX, IDC_EDIT6, str_editWinSWArea);
	DDX_Text(pDX, IDC_EDIT7, str_editWinWArea);
	DDX_Text(pDX, IDC_EDIT8, str_editWinNWArea);
	DDX_Text(pDX, IDC_EDIT9, str_editRooflightsArea);
	DDX_Text(pDX, IDC_EDIT10, str_editWinNSolTran);
	DDX_Text(pDX, IDC_EDIT11, str_editWinNESolTran);
	DDX_Text(pDX, IDC_EDIT12, str_editWinESolTran);
	DDX_Text(pDX, IDC_EDIT13, str_editWinSESolTran);
	DDX_Text(pDX, IDC_EDIT14, str_editWinSSolTran);
	DDX_Text(pDX, IDC_EDIT15, str_editWinSWSolTran);
	DDX_Text(pDX, IDC_EDIT16, str_editWinWSolTran);
	DDX_Text(pDX, IDC_EDIT17, str_editWinNWSolTran);
	DDX_Text(pDX, IDC_EDIT18, str_editRooflightsSolTran);
	DDX_Text(pDX, IDC_EDIT19, str_editWinNFrameFact);
	DDX_Text(pDX, IDC_EDIT20, str_editWinNEFrameFact);
	DDX_Text(pDX, IDC_EDIT21, str_editWinEFrameFact);
	DDX_Text(pDX, IDC_EDIT22, str_editWinSEFrameFact);
	DDX_Text(pDX, IDC_EDIT25, str_editWinSFrameFact);
	DDX_Text(pDX, IDC_EDIT23, str_editWinSWFrameFact);
	DDX_Text(pDX, IDC_EDIT26, str_editWinWFrameFact);
	DDX_Text(pDX, IDC_EDIT27, str_editWinNWFrameFact);
	DDX_Text(pDX, IDC_EDIT28, str_editRoofLightsFrameFact);
	DDX_CBString(pDX, IDC_COMBO1, str_comboOvershading);
	DDX_CBString(pDX, IDC_COMBO2, str_comboGlazing);
	DDX_Control(pDX, IDC_EDIT_LEL, m_editLEL);
	DDX_Text(pDX, IDC_EDIT_LEL, str_editLEL);
	DDX_Control(pDX, IDC_STATIC_window, m_labelWindowProperties);
	DDX_Control(pDX, IDC_STATIC_lel, m_labelLEL1);
}

BEGIN_MESSAGE_MAP(CDlg_Windows, CDialog)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, OnEnChangeEdit2)
	ON_EN_CHANGE(IDC_EDIT3, OnEnChangeEdit3)
	ON_EN_CHANGE(IDC_EDIT4, OnEnChangeEdit4)
	ON_EN_CHANGE(IDC_EDIT5, OnEnChangeEdit5)
	ON_EN_CHANGE(IDC_EDIT6, OnEnChangeEdit6)
	ON_EN_CHANGE(IDC_EDIT7, OnEnChangeEdit7)
	ON_EN_CHANGE(IDC_EDIT8, OnEnChangeEdit8)
	ON_EN_CHANGE(IDC_EDIT9, OnEnChangeEdit9)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
	ON_CBN_SELCHANGE(IDC_COMBO2, OnCbnSelchangeCombo2)
	ON_EN_CHANGE(IDC_EDIT10, OnEnChangeEdit10)
	ON_EN_CHANGE(IDC_EDIT11, OnEnChangeEdit11)
	ON_EN_CHANGE(IDC_EDIT12, OnEnChangeEdit12)
	ON_EN_CHANGE(IDC_EDIT13, OnEnChangeEdit13)
	ON_EN_CHANGE(IDC_EDIT14, OnEnChangeEdit14)
	ON_EN_CHANGE(IDC_EDIT15, OnEnChangeEdit15)
	ON_EN_CHANGE(IDC_EDIT16, OnEnChangeEdit16)
	ON_EN_CHANGE(IDC_EDIT17, OnEnChangeEdit17)
	ON_EN_CHANGE(IDC_EDIT18, OnEnChangeEdit18)
	ON_EN_CHANGE(IDC_EDIT19, OnEnChangeEdit19)
	ON_EN_CHANGE(IDC_EDIT20, OnEnChangeEdit20)
	ON_EN_CHANGE(IDC_EDIT21, OnEnChangeEdit21)
	ON_EN_CHANGE(IDC_EDIT22, OnEnChangeEdit22)
	ON_EN_CHANGE(IDC_EDIT25, OnEnChangeEdit25)
	ON_EN_CHANGE(IDC_EDIT23, OnEnChangeEdit23)
	ON_EN_CHANGE(IDC_EDIT26, OnEnChangeEdit26)
	ON_EN_CHANGE(IDC_EDIT27, OnEnChangeEdit27)
	ON_EN_CHANGE(IDC_EDIT28, OnEnChangeEdit28)
	ON_EN_CHANGE(IDC_EDIT_LEL, OnEnChangeEditLel)
END_MESSAGE_MAP()

// CDlg_Windows message handlers

BOOL CDlg_Windows::OnInitDialog()
{
	CDialog::OnInitDialog();

	//---------------------------------------------------
	// LABELS
	//---------------------------------------------------
	CFont *m_Font1 = new CFont;
	m_Font1->CreatePointFont(90, "Arial Bold");

	m_labelWindowProperties.SetTextColor(NAVYBLUE);	
	m_labelLEL1.SetTextColor(NAVYBLUE);

	//---------------------------------------------------
	// OVERSHADING COMBO
	//---------------------------------------------------
	m_comboOvershading.InsertString(0,"Very little");
	m_comboOvershading.InsertString(1,"Average");
	m_comboOvershading.InsertString(2,"More than average");
	m_comboOvershading.InsertString(3,"Heavy");

	//---------------------------------------------------
	// GLAZING COMBO
	//---------------------------------------------------
	m_comboGlazing.InsertString(0,"Single");
	m_comboGlazing.InsertString(1,"Double");
	m_comboGlazing.InsertString(2,"Triple");

	if(file_new_selected ==true)
	{
		SetAllValuesToDefault();
	}

	DisplayValuesForWindowsDlg();
		
	return TRUE;
}

void CDlg_Windows::DisplayValuesForWindowsDlg()
{
	totalGlzArea = (winNArea  * winNFrameFactor) +
				   (winNEArea * winNEFrameFactor)+
				   (winEArea  * winEFrameFactor) +
				   (winSEArea * winSEFrameFactor)+
				   (winSArea  * winSFrameFactor) +
			       (winSWArea * winSWFrameFactor)+
				   (winWArea  * winWFrameFactor) +
				   (winNWArea * winNWFrameFactor)+
				   (rooflightsArea * rooflightsFrameFactor) ;

	TFA = storey1Area +
		  storey2Area +
		  storey3Area +
		  storey4Area +
		  storey5Area +
		  storey6Area;

	if(TFA_from_HEM == true)
	{
		TFA = TFAfromHEM;
	}

	totalGlzArea = totalGlzArea / TFA;

	str_editWinNArea.Format("%.2f", winNArea);
	str_editWinNEArea.Format("%.2f",winNEArea);
	str_editWinEArea.Format("%.2f", winEArea);
	str_editWinSEArea.Format("%.2f",winSEArea);
	str_editWinSArea.Format("%.2f", winSArea);
	str_editWinSWArea.Format("%.2f",winSWArea);
	str_editWinWArea.Format("%.2f", winWArea);
	str_editWinNWArea.Format("%.2f",winNWArea);
	str_editRooflightsArea.Format("%.2f",rooflightsArea);

	str_editWinNSolTran.Format("%.2f", winNSolTrans);
	str_editWinNESolTran.Format("%.2f",winNESolTrans);
	str_editWinESolTran.Format("%.2f", winESolTrans);
	str_editWinSESolTran.Format("%.2f",winSESolTrans);
	str_editWinSSolTran.Format("%.2f", winSSolTrans);
	str_editWinSWSolTran.Format("%.2f",winSWSolTrans);
	str_editWinWSolTran.Format("%.2f", winWSolTrans);
	str_editWinNWSolTran.Format("%.2f",winNWSolTrans);
	str_editRooflightsSolTran.Format("%.2f",rooflightsSolTrans);

	str_editWinNFrameFact.Format("%.2f",winNFrameFactor);
	str_editWinNEFrameFact.Format("%.2f",winNEFrameFactor);
	str_editWinEFrameFact.Format("%.2f",winEFrameFactor);
	str_editWinSEFrameFact.Format("%.2f",winSEFrameFactor);
	str_editWinSFrameFact.Format("%.2f",winSFrameFactor);
	str_editWinSWFrameFact.Format("%.2f",winSWFrameFactor);
	str_editWinWFrameFact.Format("%.2f",winWFrameFactor);
	str_editWinNWFrameFact.Format("%.2f",winNWFrameFactor);
	str_editRoofLightsFrameFact.Format("%.2f",rooflightsFrameFactor);
	
	str_comboOvershading.Format("%s",winOvershading);
	str_comboGlazing.Format("%s",winGlazing);

	str_editLEL.Format("%.2f",fractionLEL);
	UpdateData(FALSE);
}

void CDlg_Windows::ReadInputsFromWindowsDlg()
{
	UpdateData(TRUE);

	winNArea  = atof(str_editWinNArea);
	winNEArea = atof(str_editWinNEArea);
	winEArea  = atof(str_editWinEArea);
	winSEArea = atof(str_editWinSEArea);
	winSArea  = atof(str_editWinSArea);
	winSWArea = atof(str_editWinSWArea);
	winWArea  = atof(str_editWinWArea);
	winNWArea = atof(str_editWinNWArea);
	rooflightsArea= atof(str_editRooflightsArea);

	winNSolTrans  = atof(str_editWinNSolTran);
	winNESolTrans = atof(str_editWinNESolTran);
	winESolTrans  = atof(str_editWinESolTran);
	winSESolTrans = atof(str_editWinSESolTran);
	winSSolTrans  = atof(str_editWinSSolTran);
	winSWSolTrans = atof(str_editWinSWSolTran);
	winWSolTrans  = atof(str_editWinWSolTran);
	winNWSolTrans = atof(str_editWinNWSolTran);
	rooflightsSolTrans= atof(str_editRooflightsSolTran);

	winNFrameFactor  = atof(str_editWinNFrameFact);
	winNEFrameFactor = atof(str_editWinNEFrameFact);
	winEFrameFactor  = atof(str_editWinEFrameFact);
	winSEFrameFactor = atof(str_editWinSEFrameFact);
	winSFrameFactor  = atof(str_editWinSFrameFact);
	winSWFrameFactor  = atof(str_editWinSWFrameFact);
	winWFrameFactor  = atof(str_editWinWFrameFact);
	winNWFrameFactor  = atof(str_editWinNWFrameFact);
	rooflightsFrameFactor  = atof(str_editRoofLightsFrameFact);

	winOvershading = str_comboOvershading;
	winGlazing     = str_comboGlazing;	
	fractionLEL    = atof(str_editLEL);
}

void CDlg_Windows::OnEnChangeEdit1()
{
	ReadInputsFromWindowsDlg();

	// Check limit
	isCheckRange_winNArea = true;
}

void CDlg_Windows::OnEnChangeEdit2()
{
	ReadInputsFromWindowsDlg();

	// Check limit
	isCheckRange_winNEArea = true;	
}

void CDlg_Windows::OnEnChangeEdit3()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_winEArea = true;
}

void CDlg_Windows::OnEnChangeEdit4()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_winSEArea = true;
}

void CDlg_Windows::OnEnChangeEdit5()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_winSArea = true;
}

void CDlg_Windows::OnEnChangeEdit6()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_winSWArea = true;
}

void CDlg_Windows::OnEnChangeEdit7()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_winWArea = true;	
}

void CDlg_Windows::OnEnChangeEdit8()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_winNWArea = true;	
}

void CDlg_Windows::OnEnChangeEdit9()
{
	ReadInputsFromWindowsDlg();
	// Check limit
	isCheckRange_rooflightsArea = true;
}

void CDlg_Windows::OnCbnSelchangeCombo1()
{
	ReadInputsFromWindowsDlg();
}

void CDlg_Windows::OnCbnSelchangeCombo2()
{
	ReadInputsFromWindowsDlg();
}

void CDlg_Windows::OnEnChangeEdit10()
{
	ReadInputsFromWindowsDlg();

	// Check limit
	isCheckRange_winNSolTrans = true;
}

void CDlg_Windows::OnEnChangeEdit11()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winNESolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit12()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winESolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit13()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winSESolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit14()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winSSolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit15()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winSWSolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit16()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winWSolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit17()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winNWSolTrans = true;	
}

void CDlg_Windows::OnEnChangeEdit18()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_rooflightsSolTrans = true;
}

void CDlg_Windows::OnEnChangeEdit19()
{
	ReadInputsFromWindowsDlg();

	// Check limit
	isCheckRange_winNFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit20()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winNEFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit21()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winEFrameFactor = true;	
}

void CDlg_Windows::OnEnChangeEdit22()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winSEFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit25()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winSFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit23()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winSWFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit26()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winWFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit27()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_winNWFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEdit28()
{
	ReadInputsFromWindowsDlg();
	
	// Check limit
	isCheckRange_rooflightsFrameFactor = true;
}

void CDlg_Windows::OnEnChangeEditLel()
{
	ReadInputsFromWindowsDlg();

	// Check limit
	isCheckRange_fractionLEL = true;
}

BOOL CDlg_Windows::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)
	{
		if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
			pMsg->wParam=NULL ;
	} 

	return CDialog::PreTranslateMessage(pMsg);
}

